render / rpms / libvirt

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