0a122b
From 6814f2b17eecd9ab6fde0fc38450632cae930a94 Mon Sep 17 00:00:00 2001
0a122b
From: Kevin Wolf <kwolf@redhat.com>
0a122b
Date: Tue, 25 Feb 2014 15:00:01 +0100
0a122b
Subject: [PATCH 3/7] qemu-img create: Support multiple -o options
0a122b
0a122b
RH-Author: Kevin Wolf <kwolf@redhat.com>
0a122b
Message-id: <1393340405-9936-3-git-send-email-kwolf@redhat.com>
0a122b
Patchwork-id: 57797
0a122b
O-Subject: [RHEL-7.0 qemu-kvm PATCH 2/6] qemu-img create: Support multiple -o options
0a122b
Bugzilla: 1065873
0a122b
RH-Acked-by: Juan Quintela <quintela@redhat.com>
0a122b
RH-Acked-by: Fam Zheng <famz@redhat.com>
0a122b
RH-Acked-by: Miroslav Rezanina <mrezanin@redhat.com>
0a122b
0a122b
If you specified multiple -o options for qemu-img create, it would
0a122b
silently ignore all but the last one. This patch fixes the problem.
0a122b
0a122b
Now multiple -o options has the same meaning as having a single option
0a122b
with all settings in the order of their respective -o options.
0a122b
0a122b
Signed-off-by: Kevin Wolf <kwolf@redhat.com>
0a122b
Reviewed-by: Jeff Cody <jcody@redhat.com>
0a122b
Reviewed-by: Eric Blake <eblake@redhat.com>
0a122b
(cherry picked from commit 77386bf6ebe67164a2d102b207fb3bc11af8c1e8)
0a122b
0a122b
Signed-off-by: Kevin Wolf <kwolf@redhat.com>
0a122b
---
0a122b
 qemu-img.c | 28 ++++++++++++++++++++++------
0a122b
 1 file changed, 22 insertions(+), 6 deletions(-)
0a122b
0a122b
Signed-off-by: Miroslav Rezanina <mrezanin@redhat.com>
0a122b
---
0a122b
 qemu-img.c |   28 ++++++++++++++++++++++------
0a122b
 1 files changed, 22 insertions(+), 6 deletions(-)
0a122b
0a122b
diff --git a/qemu-img.c b/qemu-img.c
0a122b
index bc48dc1..12bf996 100644
0a122b
--- a/qemu-img.c
0a122b
+++ b/qemu-img.c
0a122b
@@ -365,13 +365,23 @@ static int img_create(int argc, char **argv)
0a122b
         case 'e':
0a122b
             error_report("option -e is deprecated, please use \'-o "
0a122b
                   "encryption\' instead!");
0a122b
-            return 1;
0a122b
+            goto fail;
0a122b
         case '6':
0a122b
             error_report("option -6 is deprecated, please use \'-o "
0a122b
                   "compat6\' instead!");
0a122b
-            return 1;
0a122b
+            goto fail;
0a122b
         case 'o':
0a122b
-            options = optarg;
0a122b
+            if (!is_valid_option_list(optarg)) {
0a122b
+                error_report("Invalid option list: %s", optarg);
0a122b
+                goto fail;
0a122b
+            }
0a122b
+            if (!options) {
0a122b
+                options = g_strdup(optarg);
0a122b
+            } else {
0a122b
+                char *old_options = options;
0a122b
+                options = g_strdup_printf("%s,%s", options, optarg);
0a122b
+                g_free(old_options);
0a122b
+            }
0a122b
             break;
0a122b
         case 'q':
0a122b
             quiet = true;
0a122b
@@ -398,7 +408,7 @@ static int img_create(int argc, char **argv)
0a122b
                       "G or T suffixes for ");
0a122b
                 error_report("kilobytes, megabytes, gigabytes and terabytes.");
0a122b
             }
0a122b
-            return 1;
0a122b
+            goto fail;
0a122b
         }
0a122b
         img_size = (uint64_t)sval;
0a122b
     }
0a122b
@@ -406,7 +416,8 @@ static int img_create(int argc, char **argv)
0a122b
         help();
0a122b
     }
0a122b
 
0a122b
-    if (options && is_help_option(options)) {
0a122b
+    if (options && has_help_option(options)) {
0a122b
+        g_free(options);
0a122b
         return print_block_option_help(filename, fmt);
0a122b
     }
0a122b
 
0a122b
@@ -415,10 +426,15 @@ static int img_create(int argc, char **argv)
0a122b
     if (error_is_set(&local_err)) {
0a122b
         error_report("%s: %s", filename, error_get_pretty(local_err));
0a122b
         error_free(local_err);
0a122b
-        return 1;
0a122b
+        goto fail;
0a122b
     }
0a122b
 
0a122b
+    g_free(options);
0a122b
     return 0;
0a122b
+
0a122b
+fail:
0a122b
+    g_free(options);
0a122b
+    return 1;
0a122b
 }
0a122b
 
0a122b
 static void dump_json_image_check(ImageCheck *check, bool quiet)
0a122b
-- 
0a122b
1.7.1
0a122b