master - fix command definition for pvchange -a
Gitweb: https://sourceware.org/git/?p=lvm2.git;a=commitdiff;h=e225bf59ffdad0de1bb976ffdb65d77979cb5381 Commit: e225bf59ffdad0de1bb976ffdb65d77979cb5381 Parent: b7850faba72a50e49783a3b01e6833fc1a99873b Author: David Teigland <[email protected]> AuthorDate: Mon Jun 10 11:35:26 2019 -0500 Committer: David Teigland <[email protected]> CommitterDate: Mon Jun 10 13:43:20 2019 -0500
fix command definition for pvchange -a
The -a was being included in the set of "one or more" options instead of an actual required option. Even though the cmd def was not implementing the restrictions correctly, the command internally was.
Adjust the cmd def code which did not support a command with some real required options and a set of "one or more" options.
--- tools/command-lines.in | 2 +- tools/command.c | 93 ++++++++++++++++++++++++++++++++++++++--------- tools/command.h | 12 ++++++- tools/lvchange.c | 4 +- tools/lvmcmdline.c | 30 ++++++++-------- 5 files changed, 104 insertions(+), 37 deletions(-)
tools/command-lines.in +1 -1
@@ -1404,7 +1404,7 @@ OO_PVCHANGE: --autobackup Bool, --force, --reportformat ReportFmt, --uuid OO_PVCHANGE_META: --allocatable Bool, --addtag Tag, --deltag Tag, --uuid, --metadataignore Bool -pvchange OO_PVCHANGE_META --all +pvchange --all OO_PVCHANGE_META OO: OO_PVCHANGE IO: --ignoreskippedcluster ID: pvchange_properties_all
tools/command.c +75 -18
191 lines not on this page · raw message
tools/command.h +11 -1
@@ -164,8 +164,16 @@ struct cmd_rule {/* * one or more from required_opt_args is required, * then the rest are optional. +* +* CMD_FLAG_ANY_REQUIRED_OPT: for lvchange/vgchange special case. +* The first ro_count entries of required_opt_args must be met +* (ro_count may be 0.) After this, one or more options must be +* set from the remaining required_opt_args. So, the first +* ro_count options in required_opt_args must match, and after +* that one or more of the remaining options in required_opt_args +* must match. */ -#define CMD_FLAG_ONE_REQUIRED_OPT 1/* lvchange/vgchage require one item from required_opt_args */ +#define CMD_FLAG_ANY_REQUIRED_OPT 1#define CMD_FLAG_SECONDARY_SYNTAX 2/* allows syntax variants to be suppressed in certain output */ #define CMD_FLAG_PREVIOUS_SYNTAX 4/* allows syntax variants to not be advertised in output */ #define CMD_FLAG_PARSE_ERROR 8/* error parsing command-lines.in def */
@@ -202,6 +210,8 @@ struct command {struct cmd_rule rules[CMD_MAX_RULES ]; +int any_ro_count; +int ro_count;int oo_count;int rp_count;
tools/lvchange.c +2 -2
@@ -1084,7 +1084,7 @@ static int _lvchange_properties_single(struct cmd_context *cmd,*/ /* First group of options which allow for one metadata commit/update for the whole group */ -for (i =0 ; i < cmd->command->ro_count; i++) { +for (i =0 ; i < cmd->command->ro_count + cmd->command->any_ro_count; i++) { opt_enum = cmd->command->required_opt_args[i].opt;if (!arg_is_set (cmd, opt_enum))
@@ -1206,7 +1206,7 @@ static int _lvchange_properties_single(struct cmd_context *cmd, return_ECMD_FAILED;/* Second group of options which need per option metadata commit+reload(s) */ -for (i =0 ; i < cmd->command->ro_count; i++) { +for (i =0 ; i < cmd->command->ro_count + cmd->command->any_ro_count; i++) { opt_enum = cmd->command->required_opt_args[i].opt;if (!arg_is_set (cmd, opt_enum))
tools/lvmcmdline.c +15 -15
@@ -1192,7 +1192,7 @@ static void _set_valid_args_for_command_name(int ci)if (strcmp (commands[i].name, command_names[ci].name))continue ; -for (ro =0 ; ro < commands[i].ro_count; ro++) { +for (ro =0 ; ro < (commands[i].ro_count + commands[i].any_ro_count); ro++) { opt_enum = commands[i].required_opt_args[ro].opt; all_args[opt_enum] =1 ;
@@ -1533,7 +1533,7 @@ static int _command_required_pos_matches(struct cmd_context *cmd, int ci, int rp* 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 +* commands[i].cmd_flags & CMD_FLAG_ANY_REQUIRED_OPT means * any one item from commands[i].required_opt_args needs to be * set to match. *
@@ -1551,7 +1551,7 @@ static struct command *_find_command(struct cmd_context *cmd, const char *path,const char *name;char opts_msg[MAX_OPTS_MSG ];char check_opts_msg[MAX_OPTS_MSG ]; -int match_required, match_ro, match_rp, match_type, match_unused, mismatch_required; +int match_required, match_ro, match_rp, match_any_ro, match_type, match_unused, mismatch_required;int best_i =0 , best_required =0 , best_type =0 , best_unused =0 ;int close_i =0 , close_ro =0 , close_type =0 ;int only_i =0 ;
@@ -1600,6 +1600,7 @@ static struct command *_find_command(struct cmd_context *cmd, const char *path, match_required =0 ;/* required parameters that match */ match_ro =0 ;/* required opt_args that match */ match_rp =0 ;/* required pos_args that match */ + match_any_ro =0 ; match_type =0 ;/* type arg matches */ match_unused =0 ;/* options set that are not accepted by command */ mismatch_required =0 ;/* required parameters that do not match */
@@ -1628,20 +1629,19 @@ static struct command *_find_command(struct cmd_context *cmd, const char *path, } } -/* -* Special case where missing required_opt_arg's does not matter -* if one required_opt_arg did match. -*/ -if (commands[i].cmd_flags &CMD_FLAG_ONE_REQUIRED_OPT ) { -if (match_ro) { -/* one or more of the required_opt_args is used */ - mismatch_required =0 ; - }else { -/* not even one of the required_opt_args is used */ - mismatch_required =1 ; +for (ro = commands[i].ro_count; ro < commands[i].ro_count + commands[i].any_ro_count; ro++) { +if (_command_required_opt_matches (cmd, i, ro)) { +/* log_warn("match %d any ro opt %d", i, commands[i].required_opt_args[ro].opt); */ + match_any_ro++; } } +if ((commands[i].cmd_flags &CMD_FLAG_ANY_REQUIRED_OPT ) && !match_any_ro) { +/* not even one of the any ro is used */ +/* log_warn("match %d not one from any", i); */ + mismatch_required =1 ; + } +/* match required_pos_args */ for (rp =0 ; rp < commands[i].rp_count; rp++) {
@@ -1697,7 +1697,7 @@ static struct command *_find_command(struct cmd_context *cmd, const char *path, accepted =0 ;/* NB in some cases required_opt_args are optional */ -for (j =0 ; j < commands[i].ro_count; j++) { +for (j =0 ; j < commands[i].ro_count + commands[i].any_ro_count; j++) {if (commands[i].required_opt_args[j].opt == opt_enum) { accepted =1 ;break ;