mirror of
git://sourceware.org/git/lvm2.git
synced 2025-09-23 17:44:22 +03:00
Compare commits
1 Commits
dev-dct-cm
...
dev-dct-cm
Author | SHA1 | Date | |
---|---|---|---|
|
94ea57779a |
@@ -88,7 +88,6 @@ struct cmd_context {
|
||||
* Command line and arguments.
|
||||
*/
|
||||
const char *cmd_line;
|
||||
const char *name; /* needed before cmd->command is set */
|
||||
struct command *command;
|
||||
char **argv;
|
||||
struct arg_values *opt_arg_values;
|
||||
|
@@ -90,13 +90,7 @@
|
||||
#
|
||||
# "---" is like a comment line, used to separate text for readability
|
||||
#
|
||||
# ID: A unique string identifying the command. Two commands that do
|
||||
# the same thing, but are alternate syntaxes can share the same ID,
|
||||
# in which case the implementation would have to sort out which
|
||||
# args to look at for the required parameters. Or, the two commands
|
||||
# could use differnet IDs, in which case the implementation would
|
||||
# know where to look for each parameter.
|
||||
#
|
||||
# ID: A unique string identifying the command.
|
||||
# DESC: A description of the command.
|
||||
#
|
||||
|
||||
@@ -292,20 +286,14 @@ DESC: (variant, infers --type thin).
|
||||
|
||||
---
|
||||
|
||||
# FIXME: I don't think --zero applies when creating cache LV,
|
||||
# but it's used in a test. Should the test be fixed and
|
||||
# --zero removed here?
|
||||
|
||||
lvconvert --type cache --cachepool LV LV_linear_striped_raid_thinpool
|
||||
OO: --cache, --cachemode CacheMode, --cachepolicy String,
|
||||
--cachesettings String, --zero Bool, OO_LVCONVERT_POOL, OO_LVCONVERT
|
||||
OO: --cache, --cachepolicy String, --cachesettings String, OO_LVCONVERT_POOL, OO_LVCONVERT
|
||||
ID: lvconvert_to_cache_vol
|
||||
DESC: Convert LV to type cache.
|
||||
|
||||
# alternate form of lvconvert --type cache
|
||||
lvconvert --cache --cachepool LV LV_linear_striped_raid_thinpool
|
||||
OO: --type cache, --cachemode CacheMode, --cachepolicy String,
|
||||
--cachesettings String, --zero Bool, OO_LVCONVERT_POOL, OO_LVCONVERT
|
||||
OO: --type cache, --cachepolicy String, --cachesettings String, OO_LVCONVERT_POOL, OO_LVCONVERT
|
||||
ID: lvconvert_to_cache_vol
|
||||
DESC: Convert LV to type cache (variant, infers --type cache).
|
||||
|
||||
@@ -325,21 +313,15 @@ DESC: Convert LV to type thin-pool (variant, use --type thin-pool).
|
||||
|
||||
---
|
||||
|
||||
# FIXME: I don't think that --cachemode, --cachepolicy, --cachesettings
|
||||
# are meant to be used when creating a cache pool, but they are used
|
||||
# in one test. Should that test be fixed and these options removed?
|
||||
|
||||
lvconvert --type cache-pool LV_linear_striped_raid
|
||||
OO: OO_LVCONVERT_POOL, OO_LVCONVERT,
|
||||
--cachemode CacheMode, --cachepolicy String, --cachesettings String
|
||||
OO: OO_LVCONVERT_POOL, OO_LVCONVERT
|
||||
ID: lvconvert_to_cachepool
|
||||
DESC: Convert LV to type cache-pool.
|
||||
|
||||
# alternate form of lvconvert --type cache-pool
|
||||
# deprecated because of non-standard syntax (missing positional arg)
|
||||
lvconvert --cachepool LV_linear_striped_raid
|
||||
OO: --type cache-pool, OO_LVCONVERT_POOL, OO_LVCONVERT,
|
||||
--cachemode CacheMode, --cachepolicy String, --cachesettings String
|
||||
lvconvert --cachepool LV
|
||||
OO: OO_LVCONVERT_POOL, OO_LVCONVERT
|
||||
ID: lvconvert_to_cachepool
|
||||
DESC: Convert LV to type cache-pool (variant, use --type cache-pool).
|
||||
|
||||
@@ -608,7 +590,7 @@ DESC: (infers --type snapshot).
|
||||
---
|
||||
|
||||
lvcreate --type snapshot --size SizeMB --virtualsize SizeMB VG
|
||||
OO: --snapshot, --virtualoriginsize SizeMB, OO_LVCREATE
|
||||
OO: --virtualoriginsize SizeMB, OO_LVCREATE
|
||||
OP: PV ...
|
||||
ID: lvcreate_cow_snapshot_with_virtual_origin
|
||||
DESC: Create a sparse COW snapshot LV of a virtual origin LV.
|
||||
@@ -646,23 +628,16 @@ DESC: Create a cache pool (variant, infers --type cache-pool).
|
||||
---
|
||||
|
||||
lvcreate --type thin --virtualsize SizeMB --thinpool LV_thinpool
|
||||
OO: --thin, OO_LVCREATE_POOL, OO_LVCREATE_THIN, OO_LVCREATE
|
||||
OO: OO_LVCREATE_POOL, OO_LVCREATE_THIN, OO_LVCREATE
|
||||
ID: lvcreate_thin_vol
|
||||
DESC: Create a thin LV in a thin pool.
|
||||
|
||||
# alternate form of lvcreate --type thin
|
||||
lvcreate --virtualsize SizeMB --thinpool LV_thinpool
|
||||
OO: --type thin, --thin, OO_LVCREATE_THIN, OO_LVCREATE
|
||||
OO: --type thin, OO_LVCREATE_THIN, OO_LVCREATE
|
||||
ID: lvcreate_thin_vol
|
||||
DESC: Create a thin LV in a thin pool (variant, infers --type thin).
|
||||
|
||||
# alternate form of lvcreate --type thin
|
||||
lvcreate --virtualsize SizeMB LV_thinpool
|
||||
OO: --type thin, --thin, OO_LVCREATE_THIN, OO_LVCREATE
|
||||
ID: lvcreate_thin_vol
|
||||
DESC: Create a thin LV in the thin pool named in arg pos 1
|
||||
DESC: (variant, infers --type thin).
|
||||
|
||||
---
|
||||
|
||||
lvcreate --type thin LV_thin
|
||||
@@ -756,14 +731,14 @@ DESC: cache pool LV to use.
|
||||
---
|
||||
|
||||
lvcreate --type cache --size SizeMB --cachepool LV_cachepool
|
||||
OO: --cache, OO_LVCREATE_POOL, OO_LVCREATE_CACHE, OO_LVCREATE
|
||||
OO: OO_LVCREATE_POOL, OO_LVCREATE_CACHE, OO_LVCREATE
|
||||
OP: PV ...
|
||||
ID: lvcreate_cache_vol_with_new_origin
|
||||
DESC: Create a cache LV, first creating a new origin LV,
|
||||
DESC: then combining it with the existing cache pool in arg pos 1.
|
||||
|
||||
lvcreate --size SizeMB --cachepool LV_cachepool
|
||||
OO: --type cache, --cache, OO_LVCREATE_CACHE, OO_LVCREATE
|
||||
OO: --type cache, OO_LVCREATE_CACHE, OO_LVCREATE
|
||||
OP: PV ...
|
||||
ID: lvcreate_cache_vol_with_new_origin
|
||||
DESC: Create a cache LV, first creating a new origin LV,
|
||||
@@ -924,8 +899,8 @@ ID: pvck_general
|
||||
pvcreate PV ...
|
||||
OO: --dataalignment SizeKB, --dataalignmentoffset SizeKB, --bootloaderareasize SizeMB,
|
||||
--force, --test, --labelsector Number, --metadatatype MetadataType,
|
||||
--pvmetadatacopies Number, --metadatacopies MetadataCopies, --metadatasize SizeMB,
|
||||
--metadataignore Bool, --norestorefile, --setphysicalvolumesize SizeMB,
|
||||
--pvmetadatacopies Number, --metadatasize SizeMB, --metadataignore Bool,
|
||||
--norestorefile, --setphysicalvolumesize SizeMB,
|
||||
--reportformat String, --restorefile String, --uuidstr String, --zero Bool
|
||||
ID: pvcreate_general
|
||||
|
||||
@@ -983,7 +958,6 @@ ID: pvscan_cache
|
||||
vgcfgbackup
|
||||
OO: --file String, --foreign, --ignorelockingfailure, --partial, --readonly,
|
||||
--reportformat String
|
||||
OP: VG ...
|
||||
ID: vgcfgbackup_general
|
||||
|
||||
---
|
||||
|
@@ -1150,8 +1150,6 @@ void print_command_count(void)
|
||||
printf("#define COMMAND_COUNT %d\n", cmd_count);
|
||||
|
||||
printf("enum {\n");
|
||||
printf("\tno_CMD,\n"); /* enum value 0 is not used */
|
||||
|
||||
for (i = 0; i < cmd_count; i++) {
|
||||
cmd = &cmd_array[i];
|
||||
|
||||
|
@@ -1,8 +1,7 @@
|
||||
/* Do not edit. This file is generated by scripts/create-commands */
|
||||
/* using command definitions from scripts/command-lines.in */
|
||||
#define COMMAND_COUNT 147
|
||||
#define COMMAND_COUNT 146
|
||||
enum {
|
||||
no_CMD,
|
||||
lvchange_properties_CMD,
|
||||
lvchange_resync_CMD,
|
||||
lvchange_syncaction_CMD,
|
||||
|
File diff suppressed because it is too large
Load Diff
@@ -735,7 +735,7 @@ int readahead_arg(struct cmd_context *cmd __attribute__((unused)), struct arg_va
|
||||
*/
|
||||
int metadatacopies_arg(struct cmd_context *cmd, struct arg_values *av)
|
||||
{
|
||||
if (!strncmp(cmd->name, "vg", 2)) {
|
||||
if (!strncmp(cmd->command->name, "vg", 2)) {
|
||||
if (!strcasecmp(av->value, "all")) {
|
||||
av->ui_value = VGMETADATACOPIES_ALL;
|
||||
return 1;
|
||||
@@ -785,12 +785,6 @@ static void _set_valid_args_for_command_name(int ci)
|
||||
if (all_args[i]) {
|
||||
command_names[ci].valid_args[num_args] = _cmdline.arg_props[i].arg_enum;
|
||||
num_args++;
|
||||
|
||||
/* Automatically recognize --extents in addition to --size. */
|
||||
if (_cmdline.arg_props[i].arg_enum == size_ARG) {
|
||||
command_names[ci].valid_args[num_args] = extents_ARG;
|
||||
num_args++;
|
||||
}
|
||||
}
|
||||
}
|
||||
command_names[ci].num_args = num_args;
|
||||
@@ -813,9 +807,6 @@ static struct command_function *_find_command_function(int command_line_enum)
|
||||
{
|
||||
int i;
|
||||
|
||||
if (!command_line_enum)
|
||||
return NULL;
|
||||
|
||||
for (i = 0; i < COMMAND_ID_COUNT; i++) {
|
||||
if (command_functions[i].command_line_enum == command_line_enum)
|
||||
return &command_functions[i];
|
||||
@@ -861,6 +852,28 @@ void lvm_register_commands(void)
|
||||
_set_valid_args_for_command_name(i);
|
||||
}
|
||||
|
||||
/*
|
||||
* Match what the user typed with a one specific command definition/prototype
|
||||
* from commands[]. If nothing matches, it's not a valid command. The match
|
||||
* is based on command name, required opt args and required pos args.
|
||||
*
|
||||
* Find an entry in the commands array that matches based the arg values.
|
||||
*
|
||||
* If the cmd has opt or pos args set that are not accepted by command,
|
||||
* we can: silently ignore them, warn they are not being used, or fail.
|
||||
* Default should probably be to warn and continue.
|
||||
*
|
||||
* For each command[i], check how many required opt/pos args cmd matches.
|
||||
* Save the command[i] that matches the most.
|
||||
*
|
||||
* commands[i].cmd_flags & CMD_FLAG_ONE_REQUIRED_OPT means
|
||||
* any one item from commands[i].required_opt_args needs to be
|
||||
* set to match.
|
||||
*
|
||||
* required_pos_args[0].types & select_VAL means
|
||||
* cmd->argv[] in that pos can be NULL if arg_is_set(select_ARG)
|
||||
*/
|
||||
|
||||
static int _opt_equivalent_is_set(struct cmd_context *cmd, int opt)
|
||||
{
|
||||
if ((opt == mirrorlog_ARG) && arg_is_set(cmd, corelog_ARG))
|
||||
@@ -1164,28 +1177,6 @@ static void _print_description(int ci)
|
||||
log_print("%s", buf);
|
||||
}
|
||||
|
||||
/*
|
||||
* Match what the user typed with a one specific command definition/prototype
|
||||
* from commands[]. If nothing matches, it's not a valid command. The match
|
||||
* is based on command name, required opt args and required pos args.
|
||||
*
|
||||
* Find an entry in the commands array that matches based the arg values.
|
||||
*
|
||||
* If the cmd has opt or pos args set that are not accepted by command,
|
||||
* we can: silently ignore them, warn they are not being used, or fail.
|
||||
* Default should probably be to warn and continue.
|
||||
*
|
||||
* For each command[i], check how many required opt/pos args cmd matches.
|
||||
* Save the command[i] that matches the most.
|
||||
*
|
||||
* commands[i].cmd_flags & CMD_FLAG_ONE_REQUIRED_OPT means
|
||||
* any one item from commands[i].required_opt_args needs to be
|
||||
* set to match.
|
||||
*
|
||||
* required_pos_args[0].types & select_VAL means
|
||||
* cmd->argv[] in that pos can be NULL if arg_is_set(select_ARG)
|
||||
*/
|
||||
|
||||
static struct command *_find_command(struct cmd_context *cmd, const char *path, int *argc, char **argv)
|
||||
{
|
||||
const char *name;
|
||||
@@ -1353,19 +1344,12 @@ static struct command *_find_command(struct cmd_context *cmd, const char *path,
|
||||
return NULL;
|
||||
}
|
||||
|
||||
/* --extents is a special case which is accepted in place of --size */
|
||||
|
||||
if (!accepted && (i != extents_ARG)) {
|
||||
log_error("Invalid option for the specified command (%s %d): %s.",
|
||||
commands[best_i].command_line_id, best_i, arg_long_option_name(i));
|
||||
return NULL;
|
||||
#if 0
|
||||
if (!accepted) {
|
||||
log_warn("Ignoring option which is not used by the specified command: %s.",
|
||||
arg_long_option_name(i));
|
||||
/* clear so it can't be used when processing. */
|
||||
cmd->opt_arg_values[i].count = 0;
|
||||
cmd->opt_arg_values[i].value = NULL;
|
||||
#endif
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1399,7 +1383,7 @@ static struct command *_find_command(struct cmd_context *cmd, const char *path,
|
||||
}
|
||||
}
|
||||
out:
|
||||
log_debug("command line id: %s %d", commands[best_i].command_line_id, best_i);
|
||||
log_debug("command line id: %s (%d)", commands[best_i].command_line_id, best_i);
|
||||
|
||||
return &commands[best_i];
|
||||
}
|
||||
@@ -1574,7 +1558,8 @@ static int _find_arg(const char *cmd_name, int goval)
|
||||
return -1;
|
||||
}
|
||||
|
||||
static int _process_command_line(struct cmd_context *cmd, int *argc, char ***argv)
|
||||
static int _process_command_line(struct cmd_context *cmd, const char *cmd_name,
|
||||
int *argc, char ***argv)
|
||||
{
|
||||
char str[((ARG_COUNT + 1) * 2) + 1], *ptr = str;
|
||||
struct option opts[ARG_COUNT + 1], *o = opts;
|
||||
@@ -1586,7 +1571,7 @@ static int _process_command_line(struct cmd_context *cmd, int *argc, char ***arg
|
||||
int goval; /* the number returned from getopt_long identifying what it found */
|
||||
int i;
|
||||
|
||||
if (!(cname = _find_command_name(cmd->name)))
|
||||
if (!(cname = _find_command_name(cmd_name)))
|
||||
return_0;
|
||||
|
||||
if (!(cmd->opt_arg_values = dm_pool_zalloc(cmd->mem, sizeof(*cmd->opt_arg_values) * ARG_COUNT))) {
|
||||
@@ -1616,7 +1601,7 @@ static int _process_command_line(struct cmd_context *cmd, int *argc, char ***arg
|
||||
* translate the option value used by getopt into the enum
|
||||
* value (e.g. foo_ARG) from the args array.
|
||||
*/
|
||||
if ((arg_enum = _find_arg(cmd->name, goval)) < 0) {
|
||||
if ((arg_enum = _find_arg(cmd_name, goval)) < 0) {
|
||||
log_fatal("Unrecognised option.");
|
||||
return 0;
|
||||
}
|
||||
@@ -1889,9 +1874,9 @@ static int _get_settings(struct cmd_context *cmd)
|
||||
!_merge_synonym(cmd, raidwritebehind_ARG, writebehind_ARG))
|
||||
return EINVALID_CMD_LINE;
|
||||
|
||||
if ((!strncmp(cmd->name, "pv", 2) &&
|
||||
if ((!strncmp(cmd->command->name, "pv", 2) &&
|
||||
!_merge_synonym(cmd, metadatacopies_ARG, pvmetadatacopies_ARG)) ||
|
||||
(!strncmp(cmd->name, "vg", 2) &&
|
||||
(!strncmp(cmd->command->name, "vg", 2) &&
|
||||
!_merge_synonym(cmd, metadatacopies_ARG, vgmetadatacopies_ARG)))
|
||||
return EINVALID_CMD_LINE;
|
||||
|
||||
@@ -1902,7 +1887,7 @@ static int _get_settings(struct cmd_context *cmd)
|
||||
static int _process_common_commands(struct cmd_context *cmd)
|
||||
{
|
||||
if (arg_is_set(cmd, help_ARG) || arg_is_set(cmd, help2_ARG)) {
|
||||
_usage(cmd->name, arg_count(cmd, help_ARG));
|
||||
_usage(cmd->command->name, arg_count(cmd, help_ARG));
|
||||
|
||||
if (arg_count(cmd, help_ARG) < 2)
|
||||
log_print("(Use --help --help for usage notes.)");
|
||||
@@ -2215,6 +2200,7 @@ int lvm_run_command(struct cmd_context *cmd, int argc, char **argv)
|
||||
{
|
||||
struct dm_config_tree *config_string_cft, *config_profile_command_cft, *config_profile_metadata_cft;
|
||||
const char *reason = NULL;
|
||||
const char *cmd_name;
|
||||
int ret = 0;
|
||||
int locking_type;
|
||||
int monitoring;
|
||||
@@ -2228,7 +2214,7 @@ int lvm_run_command(struct cmd_context *cmd, int argc, char **argv)
|
||||
/* each command should start out with sigint flag cleared */
|
||||
sigint_clear();
|
||||
|
||||
cmd->name = strdup(argv[0]);
|
||||
cmd_name = strdup(argv[0]);
|
||||
|
||||
/* eliminate '-' from all options starting with -- */
|
||||
for (i = 1; i < argc; i++) {
|
||||
@@ -2267,7 +2253,7 @@ int lvm_run_command(struct cmd_context *cmd, int argc, char **argv)
|
||||
if (!(cmd->cmd_line = _copy_command_line(cmd, argc, argv)))
|
||||
return_ECMD_FAILED;
|
||||
|
||||
if (!_process_command_line(cmd, &argc, &argv)) {
|
||||
if (!_process_command_line(cmd, cmd_name, &argc, &argv)) {
|
||||
log_error("Error during parsing of command line.");
|
||||
return EINVALID_CMD_LINE;
|
||||
}
|
||||
@@ -2283,10 +2269,10 @@ int lvm_run_command(struct cmd_context *cmd, int argc, char **argv)
|
||||
|
||||
log_debug("Parsing: %s", cmd->cmd_line);
|
||||
|
||||
if (!(cmd->command = _find_command(cmd, cmd->name, &argc, argv)))
|
||||
return EINVALID_CMD_LINE;
|
||||
if (!(cmd->command = _find_command(cmd, cmd_name, &argc, argv)))
|
||||
return_ECMD_FAILED;
|
||||
|
||||
set_cmd_name(cmd->name);
|
||||
set_cmd_name(cmd_name);
|
||||
|
||||
if (arg_is_set(cmd, backgroundfork_ARG)) {
|
||||
if (!become_daemon(cmd, 1)) {
|
||||
|
Reference in New Issue
Block a user