[PATCH] qemu: Add support for 'VIR_DOMAIN_BLOCK_RESIZE_CAPACITY' with qcow2 using the 'data-file' feature

Peter Krempa via Devel posted 1 patch 4 days, 2 hours ago
Failed in applying to current master (apply log)
src/qemu/qemu_driver.c | 49 ++++++++++++++++++++++++++----------------
1 file changed, 30 insertions(+), 19 deletions(-)
[PATCH] qemu: Add support for 'VIR_DOMAIN_BLOCK_RESIZE_CAPACITY' with qcow2 using the 'data-file' feature
Posted by Peter Krempa via Devel 4 days, 2 hours ago
From: Peter Krempa <pkrempa@redhat.com>

If a qcow2 image uses a 'data-file' on a local block device we can still
honour VIR_DOMAIN_BLOCK_RESIZE_CAPACITY but use the capacity of the
data-file instead.

The code is modified to first pick the virStorageSource which we'll
probe for size based on the config of the VM and uses to determine the
new size.

Resolves: https://redhat.atlassian.net/browse/RHEL-155809
Signed-off-by: Peter Krempa <pkrempa@redhat.com>
---
 src/qemu/qemu_driver.c | 49 ++++++++++++++++++++++++++----------------
 1 file changed, 30 insertions(+), 19 deletions(-)

diff --git a/src/qemu/qemu_driver.c b/src/qemu/qemu_driver.c
index b5ea0086b9..997dbf986c 100644
--- a/src/qemu/qemu_driver.c
+++ b/src/qemu/qemu_driver.c
@@ -9446,6 +9446,7 @@ qemuDomainBlockResize(virDomainPtr dom,
     const char *nodename = NULL;
     virDomainDiskDef *disk = NULL;
     virDomainDiskDef *persistDisk = NULL;
+    virStorageSource *size_src = NULL;

     virCheckFlags(VIR_DOMAIN_BLOCK_RESIZE_BYTES |
                   VIR_DOMAIN_BLOCK_RESIZE_CAPACITY |
@@ -9495,36 +9496,46 @@ qemuDomainBlockResize(virDomainPtr dom,
         goto endjob;
     }

-    /* The physical capacity is needed both when automatic sizing is requested
-     * and when a slice is used on top of a block device.
+    /* When resizing to capacity (or when resizing a device with a storage slice
+     * -> effectively removing the slice) it's possible that we're dealing with
+     * a qcow2 image using the 'data-file' feature in which case we want to use
+     * the size of the data file. Similarly all limitations about the support of
+     * VIR_DOMAIN_BLOCK_RESIZE_CAPACITY are based on the actual 'data-file'
+     * which stores the actual blocks and thus represents the capacity.
      */
-    if (virStorageSourceIsBlockLocal(disk->src) &&
-        ((flags & VIR_DOMAIN_BLOCK_RESIZE_CAPACITY) ||
-         disk->src->sliceStorage)) {
+    if ((flags & VIR_DOMAIN_BLOCK_RESIZE_CAPACITY) || disk->src->sliceStorage) {
         g_autoptr(virQEMUDriverConfig) cfg = virQEMUDriverGetConfig(priv->driver);

-        if (qemuDomainStorageUpdatePhysical(cfg, vm, disk->src) < 0) {
-            virReportError(VIR_ERR_OPERATION_FAILED,
-                           _("failed to update capacity of '%1$s'"), disk->src->path);
-            goto endjob;
+        if (disk->src->dataFileStore)
+            size_src = disk->src->dataFileStore;
+        else
+            size_src = disk->src;
+
+        if (flags & VIR_DOMAIN_BLOCK_RESIZE_CAPACITY) {
+            if (!qemuBlockStorageSourceIsRaw(size_src) ||
+                !virStorageSourceIsBlockLocal(size_src)) {
+                virReportError(VIR_ERR_OPERATION_UNSUPPORTED, "%s",
+                               _("block resize to full capacity supported only with 'raw' or local block-based disks"));
+                goto endjob;
+            }
         }

+        if (virStorageSourceIsBlockLocal(size_src)) {
+            if (qemuDomainStorageUpdatePhysical(cfg, vm, size_src) < 0) {
+                virReportError(VIR_ERR_OPERATION_FAILED,
+                               _("failed to update capacity of '%1$s'"), size_src->path);
+                goto endjob;
+            }
+        }
     }

     if (flags & VIR_DOMAIN_BLOCK_RESIZE_CAPACITY) {
-        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 (size == 0) {
-            size = disk->src->physical;
-        } else if (size != disk->src->physical) {
+            size = size_src->physical;
+        } else if (size != size_src->physical) {
             virReportError(VIR_ERR_INVALID_ARG,
                            _("Requested resize to '%1$llu' but device size is '%2$llu'"),
-                           size, disk->src->physical);
+                           size, size_src->physical);
             goto endjob;
         }
     }
-- 
2.53.0
Re: [PATCH] qemu: Add support for 'VIR_DOMAIN_BLOCK_RESIZE_CAPACITY' with qcow2 using the 'data-file' feature
Posted by Michal Prívozník via Devel 4 days, 2 hours ago
On 4/15/26 10:19, Peter Krempa via Devel wrote:
> From: Peter Krempa <pkrempa@redhat.com>
> 
> If a qcow2 image uses a 'data-file' on a local block device we can still
> honour VIR_DOMAIN_BLOCK_RESIZE_CAPACITY but use the capacity of the
> data-file instead.
> 
> The code is modified to first pick the virStorageSource which we'll
> probe for size based on the config of the VM and uses to determine the
> new size.
> 
> Resolves: https://redhat.atlassian.net/browse/RHEL-155809
> Signed-off-by: Peter Krempa <pkrempa@redhat.com>
> ---
>  src/qemu/qemu_driver.c | 49 ++++++++++++++++++++++++++----------------
>  1 file changed, 30 insertions(+), 19 deletions(-)
> 

Reviewed-by: Michal Privoznik <mprivozn@redhat.com>

Michal