Blame SOURCES/lvm2-2_02_181-lvconvert-restrict-command-matching-for-no-option-va.patch

5e29a5
 lib/commands/toolcontext.h |  1 +
5e29a5
 tools/command-lines.in     |  2 +-
5e29a5
 tools/lvmcmdline.c         | 14 ++++++++++++++
5e29a5
 3 files changed, 16 insertions(+), 1 deletion(-)
5e29a5
5e29a5
diff --git a/lib/commands/toolcontext.h b/lib/commands/toolcontext.h
5e29a5
index bc05736..da5d582 100644
5e29a5
--- a/lib/commands/toolcontext.h
5e29a5
+++ b/lib/commands/toolcontext.h
5e29a5
@@ -95,6 +95,7 @@ struct cmd_context {
5e29a5
 	char **argv;
5e29a5
 	struct arg_values *opt_arg_values;
5e29a5
 	struct dm_list arg_value_groups;
5e29a5
+	int opt_count; /* total number of options (beginning with - or --) */
5e29a5
 
5e29a5
 	/*
5e29a5
 	 * Position args remaining after command name
5e29a5
diff --git a/tools/command-lines.in b/tools/command-lines.in
5e29a5
index 9d407d0..b7aefa3 100644
5e29a5
--- a/tools/command-lines.in
5e29a5
+++ b/tools/command-lines.in
5e29a5
@@ -700,7 +700,7 @@ RULE: all and lv_is_converting
5e29a5
 # for compat since this was how it used to be done.
5e29a5
 lvconvert LV_mirror_raid
5e29a5
 OO: OO_LVCONVERT
5e29a5
-ID: lvconvert_start_poll
5e29a5
+ID: lvconvert_plain
5e29a5
 DESC: Poll LV to continue conversion (also see --startpoll)
5e29a5
 DESC: or waits till conversion/mirror syncing is finished
5e29a5
 FLAGS: SECONDARY_SYNTAX
5e29a5
diff --git a/tools/lvmcmdline.c b/tools/lvmcmdline.c
5e29a5
index 0600b1c..c62a66e 100644
5e29a5
--- a/tools/lvmcmdline.c
5e29a5
+++ b/tools/lvmcmdline.c
5e29a5
@@ -119,6 +119,7 @@ static const struct command_function _command_functions[CMD_COUNT] = {
5e29a5
 
5e29a5
 	/* lvconvert utility to trigger polling on an LV. */
5e29a5
 	{ lvconvert_start_poll_CMD, lvconvert_start_poll_cmd },
5e29a5
+	{ lvconvert_plain_CMD, lvconvert_start_poll_cmd },
5e29a5
 
5e29a5
 	/* lvconvert utilities for creating/maintaining thin and cache objects. */
5e29a5
 	{ lvconvert_to_thinpool_CMD,			lvconvert_to_pool_cmd },
5e29a5
@@ -1579,6 +1580,17 @@ static struct command *_find_command(struct cmd_context *cmd, const char *path,
5e29a5
 		if (arg_is_set(cmd, help_ARG) || arg_is_set(cmd, help2_ARG) || arg_is_set(cmd, longhelp_ARG) || arg_is_set(cmd, version_ARG))
5e29a5
 			return &commands[i];
5e29a5
 
5e29a5
+		/*
5e29a5
+		 * The 'lvconvert LV' cmd def matches any lvconvert cmd which throws off
5e29a5
+		 * nearest-command partial-match suggestions.  Make it a special case so
5e29a5
+		 * that it won't be used as a close match.  If the command has any option
5e29a5
+		 * set (other than -v), don't attempt to match it to 'lvconvert LV'.
5e29a5
+		 */
5e29a5
+		if (commands[i].command_enum == lvconvert_plain_CMD) {
5e29a5
+			if (cmd->opt_count - cmd->opt_arg_values[verbose_ARG].count)
5e29a5
+				continue;
5e29a5
+		}
5e29a5
+
5e29a5
 		match_required = 0;	/* required parameters that match */
5e29a5
 		match_ro = 0;		/* required opt_args that match */
5e29a5
 		match_rp = 0;		/* required pos_args that match */
5e29a5
@@ -2097,6 +2109,8 @@ static int _process_command_line(struct cmd_context *cmd, int *argc, char ***arg
5e29a5
 		if (goval == '?')
5e29a5
 			return 0;
5e29a5
 
5e29a5
+		cmd->opt_count++;
5e29a5
+
5e29a5
 		/*
5e29a5
 		 * translate the option value used by getopt into the enum
5e29a5
 		 * value (e.g. foo_ARG) from the args array.