1
0
mirror of git://sourceware.org/git/lvm2.git synced 2025-04-01 18:50:41 +03:00

o Changed the macro name in args.h from 'xx' to 'arg'

o  There is now a _default_debug, and _default_verbose level, when
   using lvm interactively -vv and -dd switches just effect the current
   command.

o  Added a --quiet switch which sets both verbose and debug to zero.
This commit is contained in:
Joe Thornber 2001-12-17 16:58:17 +00:00
parent b897fe6700
commit a89ce91089
3 changed files with 113 additions and 83 deletions

View File

@ -8,61 +8,62 @@
* Put all long args that don't have a
* corresponding short option first ...
*/
xx(version_ARG, '\0', "version", NULL)
arg(version_ARG, '\0', "version", NULL)
arg(quiet_ARG, '\0', "quiet", NULL)
/*
* ... and now the short args.
*/
xx(available_ARG, 'a', "available", yes_no_arg)
xx(all_ARG, 'a', "all", NULL)
xx(autobackup_ARG, 'A', "autobackup", yes_no_arg)
xx(activevolumegroups_ARG, 'A', "activevolumegroups", NULL)
xx(blockdevice_ARG, 'b', "blockdevice", NULL)
xx(chunksize_ARG, 'c', "chunksize", size_arg)
xx(colon_ARG, 'c', "colon", NULL)
xx(contiguous_ARG, 'C', "contiguous", yes_no_arg)
xx(debug_ARG, 'd', "debug", NULL)
xx(disk_ARG, 'D', "disk", NULL)
xx(exported_ARG, 'e', "exported", NULL)
xx(physicalextent_ARG, 'E', "physicalextent", NULL)
xx(file_ARG, 'f', "file", NULL)
xx(force_ARG, 'f', "force", NULL)
xx(full_ARG, 'f', "full", NULL)
xx(help_ARG, 'h', "help", NULL)
xx(stripesize_ARG, 'I', "stripesize", size_arg)
xx(stripes_ARG, 'i', "stripes", int_arg)
xx(iop_version_ARG, 'i', "iop_version", NULL)
xx(logicalvolume_ARG, 'l', "logicalvolume", int_arg)
xx(maxlogicalvolumes_ARG, 'l', "maxlogicalvolumes", int_arg)
xx(extents_ARG, 'l', "extents", int_arg_with_sign)
xx(lvmpartition_ARG, 'l', "lvmpartition", NULL)
xx(list_ARG, 'l', "list", NULL)
xx(size_ARG, 'L', "size", size_arg)
xx(logicalextent_ARG, 'L', "logicalextent", int_arg_with_sign)
xx(maps_ARG, 'm', "maps", NULL)
xx(name_ARG, 'n', "name", string_arg)
xx(oldpath_ARG, 'n', "oldpath", NULL)
xx(nofsck_ARG, 'n', "nofsck", NULL)
xx(novolumegroup_ARG, 'n', "novolumegroup", NULL)
xx(permission_ARG, 'p', "permission", permission_arg)
xx(maxphysicalvolumes_ARG, 'p', "maxphysicalvolumes", int_arg)
xx(physicalvolume_ARG, 'P', "physicalvolume", NULL)
xx(readahead_ARG, 'r', "readahead", int_arg)
xx(reset_ARG, 'R', "reset", NULL)
xx(physicalextentsize_ARG, 's', "physicalextentsize", size_arg)
xx(stdin_ARG, 's', "stdin", NULL)
xx(snapshot_ARG, 's', "snapshot", NULL)
xx(short_ARG, 's', "short", NULL)
xx(test_ARG, 't', "test", NULL)
xx(uuid_ARG, 'u', "uuid", NULL)
xx(uuidlist_ARG, 'U', "uuidlist", NULL)
xx(verbose_ARG, 'v', "verbose", NULL)
xx(volumegroup_ARG, 'V', "volumegroup", NULL)
xx(allocation_ARG, 'x', "allocation", yes_no_arg)
xx(yes_ARG, 'y', "yes", NULL)
xx(zero_ARG, 'Z', "zero", yes_no_arg)
xx(suspend_ARG, 'z', "suspend", NULL)
arg(available_ARG, 'a', "available", yes_no_arg)
arg(all_ARG, 'a', "all", NULL)
arg(autobackup_ARG, 'A', "autobackup", yes_no_arg)
arg(activevolumegroups_ARG, 'A', "activevolumegroups", NULL)
arg(blockdevice_ARG, 'b', "blockdevice", NULL)
arg(chunksize_ARG, 'c', "chunksize", size_arg)
arg(colon_ARG, 'c', "colon", NULL)
arg(contiguous_ARG, 'C', "contiguous", yes_no_arg)
arg(debug_ARG, 'd', "debug", NULL)
arg(disk_ARG, 'D', "disk", NULL)
arg(exported_ARG, 'e', "exported", NULL)
arg(physicalextent_ARG, 'E', "physicalextent", NULL)
arg(file_ARG, 'f', "file", NULL)
arg(force_ARG, 'f', "force", NULL)
arg(full_ARG, 'f', "full", NULL)
arg(help_ARG, 'h', "help", NULL)
arg(stripesize_ARG, 'I', "stripesize", size_arg)
arg(stripes_ARG, 'i', "stripes", int_arg)
arg(iop_version_ARG, 'i', "iop_version", NULL)
arg(logicalvolume_ARG, 'l', "logicalvolume", int_arg)
arg(maxlogicalvolumes_ARG, 'l', "maxlogicalvolumes", int_arg)
arg(extents_ARG, 'l', "extents", int_arg_with_sign)
arg(lvmpartition_ARG, 'l', "lvmpartition", NULL)
arg(list_ARG, 'l', "list", NULL)
arg(size_ARG, 'L', "size", size_arg)
arg(logicalextent_ARG, 'L', "logicalextent", int_arg_with_sign)
arg(maps_ARG, 'm', "maps", NULL)
arg(name_ARG, 'n', "name", string_arg)
arg(oldpath_ARG, 'n', "oldpath", NULL)
arg(nofsck_ARG, 'n', "nofsck", NULL)
arg(novolumegroup_ARG, 'n', "novolumegroup", NULL)
arg(permission_ARG, 'p', "permission", permission_arg)
arg(maxphysicalvolumes_ARG, 'p', "maxphysicalvolumes", int_arg)
arg(physicalvolume_ARG, 'P', "physicalvolume", NULL)
arg(readahead_ARG, 'r', "readahead", int_arg)
arg(reset_ARG, 'R', "reset", NULL)
arg(physicalextentsize_ARG, 's', "physicalextentsize", size_arg)
arg(stdin_ARG, 's', "stdin", NULL)
arg(snapshot_ARG, 's', "snapshot", NULL)
arg(short_ARG, 's', "short", NULL)
arg(test_ARG, 't', "test", NULL)
arg(uuid_ARG, 'u', "uuid", NULL)
arg(uuidlist_ARG, 'U', "uuidlist", NULL)
arg(verbose_ARG, 'v', "verbose", NULL)
arg(volumegroup_ARG, 'V', "volumegroup", NULL)
arg(allocation_ARG, 'x', "allocation", yes_no_arg)
arg(yes_ARG, 'y', "yes", NULL)
arg(zero_ARG, 'Z', "zero", yes_no_arg)
arg(suspend_ARG, 'z', "suspend", NULL)
/* this should always be last */
xx(ARG_COUNT, '-', "", NULL)
arg(ARG_COUNT, '-', "", NULL)

View File

@ -1,21 +1,7 @@
/*
* Copyright (C) 2001 Sistina Software
*
* LVM is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2, or (at your option)
* any later version.
*
* LVM is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with LVM; see the file COPYING. If not, write to
* the Free Software Foundation, 59 Temple Place - Suite 330,
* Boston, MA 02111-1307, USA.
* Copyright (C) 2001 Sistina Software (UK) Limited.
*
* This file is released under the GPL.
*/
#include "tools.h"
@ -41,9 +27,9 @@
/* define exported table of valid switches */
struct arg the_args[ARG_COUNT + 1] = {
#define xx(a, b, c, d) {b, "--" c, d, 0, NULL},
#define arg(a, b, c, d) {b, "--" c, d, 0, NULL},
#include "args.h"
#undef xx
#undef arg
};
@ -64,7 +50,20 @@ static int _dump_filter;
static int _interactive;
static FILE *_log;
static int _debug_level;
/*
* Both verbose have a global setting which comes
* from the command line that invoked the shell,
* or the config file. These are the 'default'
* variables. In addition people may set a level
* for a single command.
*/
static int _default_debug;
static int _debug;
static int _default_verbose;
static int _verbose;
/*
* The lvm_system_dir contains:
@ -296,7 +295,8 @@ static void register_commands()
{
#define xx(a, b, c...) register_command(# a, a, b, ## c, \
debug_ARG, help_ARG, suspend_ARG, \
version_ARG, verbose_ARG, -1);
version_ARG, verbose_ARG, \
quiet_ARG, -1);
#include "commands.h"
#undef xx
}
@ -453,6 +453,7 @@ static int process_command_line(struct command *com, int *argc, char ***argv)
}
if (a->fn) {
if (!optarg) {
log_error("Option requires argument.");
return 0;
@ -461,7 +462,8 @@ static int process_command_line(struct command *com, int *argc, char ***argv)
a->value = optarg;
if (!a->fn(a)) {
log_error("Invalid argument %s", optarg);
log_error("Invalid argument %s",
optarg);
return 0;
}
}
@ -502,10 +504,27 @@ static int process_common_commands(struct command *com)
if (arg_count(suspend_ARG))
kill(getpid(), SIGSTOP);
l = arg_count(debug_ARG);
init_debug(l ? l : _debug_level);
/*
* debug
*/
_debug = _default_debug;
if (arg_count(debug_ARG))
_debug = arg_count(debug_ARG);
/*
* verbose
*/
_verbose = _default_verbose;
if (arg_count(verbose_ARG))
_verbose = arg_count(verbose_ARG);
if (arg_count(quiet_ARG)) {
_debug = 0;
_verbose = 0;
}
init_verbose(arg_count(verbose_ARG));
if ((l = arg_count(test_ARG))) {
log_error("Test mode. Metadata will NOT be updated.");
@ -578,8 +597,18 @@ static int run_command(int argc, char **argv)
if ((ret = process_common_commands(the_command)))
return ret;
init_debug(_debug);
init_verbose(_verbose);
ret = the_command->fn(argc, argv);
/*
* set the debug and verbose levels back
* to the global default.
*/
init_debug(_default_debug);
init_verbose(_default_verbose);
/*
* free off any memory the command used.
*/
@ -588,6 +617,7 @@ static int run_command(int argc, char **argv)
if (ret == EINVALID_CMD_LINE && !_interactive)
usage(the_command->name);
return ret;
}
@ -624,7 +654,6 @@ static void __init_log(struct config_file *cf)
char *open_mode = "a";
const char *log_file = find_config_str(cf->root, "log/file", '/', 0);
int verbose_level;
if (find_config_int(cf->root, "log/overwrite", '/', 0))
open_mode = "w";
@ -637,11 +666,11 @@ static void __init_log(struct config_file *cf)
init_log(_log);
}
_debug_level = find_config_int(cf->root, "log/level", '/', 0);
init_debug(_debug_level);
_default_debug = find_config_int(cf->root, "log/level", '/', 0);
init_debug(_default_debug);
verbose_level = find_config_int(cf->root, "log/verbose", '/', 0);
init_verbose(verbose_level);
_default_verbose = find_config_int(cf->root, "log/verbose", '/', 0);
init_verbose(_default_verbose);
}
static int dev_cache_setup(struct config_file *cf)

View File

@ -57,9 +57,9 @@ typedef int (*command_fn)(int argc, char **argv);
/* define the enums for the command line switches */
enum {
#define xx(a, b, c, d) a ,
#define arg(a, b, c, d) a ,
#include "args.h"
#undef xx
#undef arg
};
typedef enum {
@ -67,7 +67,7 @@ typedef enum {
SIGN_PLUS = 1,
SIGN_MINUS = 2
} sign_t;
/* a global table of possible arguments */
struct arg {
char short_arg;