From d47bfb1b56938a1b76584695662b72381f550a05 Mon Sep 17 00:00:00 2001
Message-Id: <d47bfb1b56938a1b76584695662b72381f550a05.1425657843.git.jen@redhat.com>
In-Reply-To: <f6cf12f0d166001c7958ddc904eff181f03da5e4.1425657843.git.jen@redhat.com>
References: <f6cf12f0d166001c7958ddc904eff181f03da5e4.1425657843.git.jen@redhat.com>
From: Kevin Wolf <kwolf@redhat.com>
Date: Mon, 3 Mar 2014 14:54:07 +0100
Subject: [CHANGE 10/11] qemu-img convert: Fix progress output
To: rhvirt-patches@redhat.com,
    jen@redhat.com

Initialise progress output only when the -p and -q options have already
been parsed, otherwise it's always disabled.

Reported-by: Peter Lieven <pl@kamp.de>
Signed-off-by: Kevin Wolf <kwolf@redhat.com>
Reviewed-by: Eric Blake <eblake@redhat.com>
(cherry picked from commit 64bb01aa35a24bea7ad0a1a8713991bab5020d12)

Conflicts:
	qemu-img.c

Conflicts because RHEL 6 doesn't support the -s and -l option for using
an internal snapshot as the source, nor -q for quiet.

Signed-off-by: Kevin Wolf <kwolf@redhat.com>
Signed-off-by: Jeff E. Nelson <jen@redhat.com>
---
 qemu-img.c | 18 ++++++++++--------
 1 file changed, 10 insertions(+), 8 deletions(-)

diff --git a/qemu-img.c b/qemu-img.c
index f5fe2da..96bb5ce 100644
--- a/qemu-img.c
+++ b/qemu-img.c
@@ -1120,9 +1120,6 @@ 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";
@@ -1155,17 +1152,17 @@ static int img_convert(int argc, char **argv)
             error_report("qemu-img: option -e is deprecated, please use \'-o "
                   "encryption\' instead!");
             ret = -1;
-            goto out;
+            goto fail_getopt;
         case '6':
             error_report("qemu-img: option -6 is deprecated, please use \'-o "
                   "compat6\' instead!");
             ret = -1;
-            goto out;
+            goto fail_getopt;
         case 'o':
             if (!is_valid_option_list(optarg)) {
                 error_report("Invalid option list: %s", optarg);
                 ret = -1;
-                goto out;
+                goto fail_getopt;
             }
             if (!options) {
                 options = g_strdup(optarg);
@@ -1183,7 +1180,7 @@ static int img_convert(int argc, char **argv)
             if (sval < 0 || *end) {
                 error_report("Invalid minimum zero buffer size for sparse output specified");
                 ret = -1;
-                goto out;
+                goto fail_getopt;
             }
 
             min_sparse = sval / BDRV_SECTOR_SIZE;
@@ -1201,6 +1198,9 @@ static int img_convert(int argc, char **argv)
         }
     }
 
+    /* Initialize before goto out */
+    qemu_progress_init(progress, 1.0);
+
     bs_n = argc - optind - 1;
     out_filename = bs_n >= 1 ? argv[argc - 1] : NULL;
 
@@ -1523,7 +1523,6 @@ out:
     free_option_parameters(create_options);
     free_option_parameters(param);
     qemu_vfree(buf);
-    g_free(options);
     if (out_bs) {
         bdrv_delete(out_bs);
     }
@@ -1535,6 +1534,9 @@ out:
         }
         qemu_free(bs);
     }
+fail_getopt:
+    g_free(options);
+
     if (ret) {
         return 1;
     }
-- 
2.1.0

