]> xenbits.xensource.com Git - libvirt.git/commitdiff
qemuDomainBlockResize: Implement VIR_DOMAIN_BLOCK_RESIZE_CAPACITY
authorPeter Krempa <pkrempa@redhat.com>
Wed, 13 Dec 2023 14:44:36 +0000 (15:44 +0100)
committerPeter Krempa <pkrempa@redhat.com>
Thu, 14 Dec 2023 15:11:07 +0000 (16:11 +0100)
Resizing of block-backed storage requires the user to pass the exact
capacity of the device. Implement code which will query it instead so
the user doesn't need to do that.

Closes: https://gitlab.com/libvirt/libvirt/-/issues/449
Signed-off-by: Peter Krempa <pkrempa@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
src/qemu/qemu_driver.c

index 7f719c33de63979bd958fb4bf1ae746a5991c6eb..db99d471d49ae23f3eee0995bae565b49ad03416 100644 (file)
@@ -9246,7 +9246,8 @@ qemuDomainBlockResize(virDomainPtr dom,
     const char *nodename = NULL;
     virDomainDiskDef *disk = NULL;
 
-    virCheckFlags(VIR_DOMAIN_BLOCK_RESIZE_BYTES, -1);
+    virCheckFlags(VIR_DOMAIN_BLOCK_RESIZE_BYTES |
+                  VIR_DOMAIN_BLOCK_RESIZE_CAPACITY, -1);
 
     /* We prefer operating on bytes.  */
     if ((flags & VIR_DOMAIN_BLOCK_RESIZE_BYTES) == 0) {
@@ -9292,6 +9293,25 @@ qemuDomainBlockResize(virDomainPtr dom,
         goto endjob;
     }
 
+    if (flags & VIR_DOMAIN_BLOCK_RESIZE_CAPACITY) {
+        g_autoptr(virQEMUDriverConfig) cfg = virQEMUDriverGetConfig(priv->driver);
+
+        if (!qemuBlockStorageSourceIsRaw(disk->src) ||
+            !virStorageSourceIsBlockLocal(disk->src)) {
+            virReportError(VIR_ERR_OPERATION_UNSUPPORTED, "%s",
+                           _("block resize to full capacity supported only with 'raw' local block-based disks"));
+            goto endjob;
+        }
+
+        if (qemuDomainStorageUpdatePhysical(cfg, vm, disk->src) < 0) {
+            virReportError(VIR_ERR_OPERATION_FAILED,
+                           _("failed to update capacity of '%1$s'"), disk->src->path);
+            goto endjob;
+        }
+
+        size = disk->src->physical;
+    }
+
     /* qcow2 and qed must be sized on 512 byte blocks/sectors,
      * so adjust size if necessary to round up.
      */