]> git.ipfire.org Git - thirdparty/libvirt.git/commitdiff
storage: Ensure 'qemu-img resize' size arg is a 512 multiple
authorChristophe Fergeau <cfergeau@redhat.com>
Tue, 14 May 2013 13:48:21 +0000 (15:48 +0200)
committerCole Robinson <crobinso@redhat.com>
Wed, 12 Jun 2013 19:11:45 +0000 (15:11 -0400)
qemu-img resize will fail with "The new size must be a multiple of 512"
if libvirt doesn't round it first.
This fixes rhbz#951495

Signed-off-by: Christophe Fergeau <cfergeau@redhat.com>
(cherry picked from commit 9a8f39d097448b2b43c4a05d0edc213eacfc9ea6)

src/internal.h
src/libvirt.c
src/storage/storage_backend_fs.c

index 8037a4ae847ef4e4b3a750aee81dfe8f443b7a45..b8ca20a13f144e26e9869f343c7ea86f125344b1 100644 (file)
 /* divide value by size, rounding up */
 # define VIR_DIV_UP(value, size) (((value) + (size) - 1) / (size))
 
+/* round up value to the closest multiple of size */
+# define VIR_ROUND_UP(value, size) (VIR_DIV_UP(value, size) * (size))
+
 
 # if WITH_DTRACE_PROBES
 #  ifndef LIBVIRT_PROBES_H
index 68d1bad8f9bf1cd335dbe37a38515c6aac313a36..d84dc81187be99a7e1c7ae6cff6b3af18f339eb9 100644 (file)
@@ -13870,7 +13870,8 @@ error:
  * Changes the capacity of the storage volume @vol to @capacity. The
  * operation will fail if the new capacity requires allocation that would
  * exceed the remaining free space in the parent pool.  The contents of
- * the new capacity will appear as all zero bytes.
+ * the new capacity will appear as all zero bytes. The capacity value will
+ * be rounded to the granularity supported by the hypervisor.
  *
  * Normally, the operation will attempt to affect capacity with a minimum
  * impact on allocation (that is, the default operation favors a sparse
index 205d3ed7e1113b609e5c78620d8568ba937e6dd6..527e26139e30d2864ee60c928465736dc0b5b290 100644 (file)
@@ -1232,6 +1232,10 @@ virStorageBackendFilesystemResizeQemuImg(const char *path,
         return -1;
     }
 
+    /* Round capacity as qemu-img resize errors out on sizes which are not
+     * a multiple of 512 */
+    capacity = VIR_ROUND_UP(capacity, 512);
+
     cmd = virCommandNew(img_tool);
     virCommandAddArgList(cmd, "resize", path, NULL);
     virCommandAddArgFormat(cmd, "%llu", capacity);