982648
From 4c301176e317d6809a8a39ab0ad971f5d2e1ff65 Mon Sep 17 00:00:00 2001
982648
Message-Id: <4c301176e317d6809a8a39ab0ad971f5d2e1ff65@dist-git>
982648
From: John Ferlan <jferlan@redhat.com>
982648
Date: Mon, 27 Aug 2018 08:23:52 -0400
982648
Subject: [PATCH] storage: Add --shrink to qemu-img command when shrinking vol
982648
MIME-Version: 1.0
982648
Content-Type: text/plain; charset=UTF-8
982648
Content-Transfer-Encoding: 8bit
982648
982648
https://bugzilla.redhat.com/show_bug.cgi?id=1613746
982648
982648
When shrinking the capacity of a qcow2 or luks volume using
982648
the qemu-img program, the --shrink qualifier must be added.
982648
982648
Signed-off-by: John Ferlan <jferlan@redhat.com>
982648
Reviewed-by: Daniel P. Berrangé <berrange@redhat.com>
982648
(cherry picked from commit b04d1b6a35f9fb826f7bb83fdac364a127ec75ca)
982648
https: //bugzilla.redhat.com/show_bug.cgi?id=1622534
982648
Reviewed-by: Erik Skultety <eskultet@redhat.com>
982648
---
982648
 src/storage/storage_util.c | 8 ++++----
982648
 1 file changed, 4 insertions(+), 4 deletions(-)
982648
982648
diff --git a/src/storage/storage_util.c b/src/storage/storage_util.c
982648
index a701a75702..5dc22d3182 100644
982648
--- a/src/storage/storage_util.c
982648
+++ b/src/storage/storage_util.c
982648
@@ -2287,12 +2287,12 @@ storageBackendResizeQemuImg(virStoragePoolObjPtr pool,
982648
      * a multiple of 512 */
982648
     capacity = VIR_ROUND_UP(capacity, 512);
982648
 
982648
-    cmd = virCommandNew(img_tool);
982648
+    cmd = virCommandNewArgList(img_tool, "resize", NULL);
982648
+    if (capacity < vol->target.capacity)
982648
+        virCommandAddArg(cmd, "--shrink");
982648
     if (!vol->target.encryption) {
982648
-        virCommandAddArgList(cmd, "resize", vol->target.path, NULL);
982648
+        virCommandAddArg(cmd, vol->target.path);
982648
     } else {
982648
-        virCommandAddArg(cmd, "resize");
982648
-
982648
         if (storageBackendCreateQemuImgSecretObject(cmd, secretPath,
982648
                                                     secretAlias) < 0)
982648
             goto cleanup;
982648
-- 
982648
2.18.0
982648