[PATCH 06/10] qemuDomainBlockResize: Implement VIR_DOMAIN_BLOCK_RESIZE_CAPACITY

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



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@xxxxxxxxxx>
---
 src/qemu/qemu_driver.c | 22 +++++++++++++++++++++-
 1 file changed, 21 insertions(+), 1 deletion(-)

diff --git a/src/qemu/qemu_driver.c b/src/qemu/qemu_driver.c
index 7f719c33de..db99d471d4 100644
--- a/src/qemu/qemu_driver.c
+++ b/src/qemu/qemu_driver.c
@@ -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.
      */
-- 
2.43.0
_______________________________________________
Devel mailing list -- devel@xxxxxxxxxxxxxxxxx
To unsubscribe send an email to devel-leave@xxxxxxxxxxxxxxxxx




[Index of Archives]     [Virt Tools]     [Libvirt Users]     [Lib OS Info]     [Fedora Users]     [Fedora Desktop]     [Fedora SELinux]     [Big List of Linux Books]     [Yosemite News]     [KDE Users]     [Fedora Tools]

  Powered by Linux