]> git.ipfire.org Git - thirdparty/libvirt.git/commitdiff
storage: Add --shrink to qemu-img command when shrinking vol
authorJohn Ferlan <jferlan@redhat.com>
Fri, 17 Aug 2018 19:53:29 +0000 (15:53 -0400)
committerJohn Ferlan <jferlan@redhat.com>
Fri, 24 Aug 2018 13:14:13 +0000 (09:14 -0400)
https://bugzilla.redhat.com/show_bug.cgi?id=1613746

When shrinking the capacity of a qcow2 or luks volume using
the qemu-img program, the --shrink qualifier must be added.

Signed-off-by: John Ferlan <jferlan@redhat.com>
Reviewed-by: Daniel P. Berrangé <berrange@redhat.com>
src/storage/storage_util.c

index c25929e0262dffa693b08fba07bb712bddc2fe59..595edad9e9a6ea48746a75e383c7e2fb917b00d3 100644 (file)
@@ -2294,12 +2294,12 @@ storageBackendResizeQemuImg(virStoragePoolObjPtr pool,
      * a multiple of 512 */
     capacity = VIR_ROUND_UP(capacity, 512);
 
-    cmd = virCommandNew(img_tool);
+    cmd = virCommandNewArgList(img_tool, "resize", NULL);
+    if (capacity < vol->target.capacity)
+        virCommandAddArg(cmd, "--shrink");
     if (!vol->target.encryption) {
-        virCommandAddArgList(cmd, "resize", vol->target.path, NULL);
+        virCommandAddArg(cmd, vol->target.path);
     } else {
-        virCommandAddArg(cmd, "resize");
-
         if (storageBackendCreateQemuImgSecretObject(cmd, secretPath,
                                                     secretAlias) < 0)
             goto cleanup;