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