]> xenbits.xensource.com Git - people/aperard/libvirt.git/commitdiff
qemu: tighten semantics of 'size' when resizing block devices
authorDaniel P. Berrangé <berrange@redhat.com>
Wed, 3 Jan 2024 16:36:45 +0000 (16:36 +0000)
committerDaniel P. Berrangé <berrange@redhat.com>
Tue, 9 Jan 2024 11:57:13 +0000 (11:57 +0000)
When VIR_DOMAIN_BLOCK_RESIZE_CAPACITY is set, the 'size' parameter
is currently ignored. Since applications must none the less pass a
value for this parameter, it is preferrable to declare some explicit
semantics for it.

This declare that the parameter must be 0, or the exact size of the
underlying block device. The latter gives the management application
the ability to sanity check that the block device size matches what
they think it should be.

Reviewed-by: Peter Krempa <pkrempa@redhat.com>
Signed-off-by: Daniel P. Berrangé <berrange@redhat.com>
src/libvirt-domain.c
src/qemu/qemu_driver.c

index 94e5672ed8b51181bec45c3150bc6dbd8fa52e39..83abad251e333f258aa74b18f9b1a77af11ab2ae 100644 (file)
@@ -6389,8 +6389,9 @@ virDomainBlockPeek(virDomainPtr dom,
  * to the next alignment boundary.
  *
  * If @flag contains VIR_DOMAIN_BLOCK_RESIZE_CAPACITY (since 10.0.0) the
- * hypervisor will resize the guest block device to fully fill the source,
- * ignoring @size. This is possible only for image formats with no metadata
+ * hypervisor will resize the guest block device to fully fill the source.
+ * @size must be either set to zero, or to the exact size of the block
+ * device source. This is possible only for image formats with no metadata
  * ('raw') and for source devices with limited capacity such as block devices.
  *
  * The @disk parameter is either an unambiguous source name of the
index ee7774f1151f16aa6d15f4c7503ec9a07b20ac56..448e6b159198de4344082d78dfdd1f116e126222 100644 (file)
@@ -9324,7 +9324,14 @@ qemuDomainBlockResize(virDomainPtr dom,
             goto endjob;
         }
 
-        size = disk->src->physical;
+        if (size == 0) {
+            size = disk->src->physical;
+        } else if (size != disk->src->physical) {
+            virReportError(VIR_ERR_INVALID_ARG,
+                           _("Requested resize to '%1$llu' but device size is '%2$llu'"),
+                           size, disk->src->physical);
+            goto endjob;
+        }
     }
 
     /* qcow2 and qed must be sized on 512 byte blocks/sectors,