From 54c627842150df7083a28a3d5964c29d7a02979a Mon Sep 17 00:00:00 2001 Message-Id: <54c627842150df7083a28a3d5964c29d7a02979a.1425657843.git.jen@redhat.com> In-Reply-To: References: From: Kevin Wolf Date: Fri, 21 Feb 2014 16:24:05 +0100 Subject: [CHANGE 08/11] qemu-img convert: Support multiple -o options To: rhvirt-patches@redhat.com, jen@redhat.com Instead of ignoring all option values but the last one, multiple -o options now have the same meaning as having a single option with all settings in the order of their respective -o options. Signed-off-by: Kevin Wolf Reviewed-by: Jeff Cody Reviewed-by: Eric Blake (cherry picked from commit 2dc8328b4c6aba60f4ad543186f4e8aec2e9287e) Conflicts: qemu-img.c Conflicts because RHEL 6 doesn't support the -s and -l option for using an internal snapshot as the source. Signed-off-by: Kevin Wolf Signed-off-by: Jeff E. Nelson --- qemu-img.c | 31 +++++++++++++++++++++++-------- 1 file changed, 23 insertions(+), 8 deletions(-) diff --git a/qemu-img.c b/qemu-img.c index ffd32b7..495aa1f 100644 --- a/qemu-img.c +++ b/qemu-img.c @@ -1116,6 +1116,9 @@ static int img_convert(int argc, char **argv) char *options = NULL; int min_sparse = 8; /* Need at least 4k of zeros for sparse detection */ + /* Initialize before goto out */ + qemu_progress_init(progress, 1.0); + fmt = NULL; out_fmt = "raw"; cache = "unsafe"; @@ -1147,13 +1150,26 @@ static int img_convert(int argc, char **argv) case 'e': error_report("qemu-img: option -e is deprecated, please use \'-o " "encryption\' instead!"); - return 1; + ret = -1; + goto out; case '6': error_report("qemu-img: option -6 is deprecated, please use \'-o " "compat6\' instead!"); - return 1; + ret = -1; + goto out; case 'o': - options = optarg; + if (!is_valid_option_list(optarg)) { + error_report("Invalid option list: %s", optarg); + ret = -1; + goto out; + } + if (!options) { + options = g_strdup(optarg); + } else { + char *old_options = options; + options = g_strdup_printf("%s,%s", options, optarg); + g_free(old_options); + } break; case 'S': { @@ -1162,7 +1178,8 @@ static int img_convert(int argc, char **argv) sval = strtosz_suffix(optarg, &end, STRTOSZ_DEFSUFFIX_B); if (sval < 0 || *end) { error_report("Invalid minimum zero buffer size for sparse output specified"); - return 1; + ret = -1; + goto out; } min_sparse = sval / BDRV_SECTOR_SIZE; @@ -1187,10 +1204,7 @@ static int img_convert(int argc, char **argv) out_filename = argv[argc - 1]; - /* Initialize before goto out */ - qemu_progress_init(progress, 1.0); - - if (options && !strcmp(options, "?")) { + if (options && has_help_option(options)) { ret = print_block_option_help(out_filename, out_fmt); goto out; } @@ -1504,6 +1518,7 @@ out: free_option_parameters(create_options); free_option_parameters(param); qemu_vfree(buf); + g_free(options); if (out_bs) { bdrv_delete(out_bs); } -- 2.1.0