[PATCH 13/15] qemu: enable basic qcow2 data-file feature support

Nikolai Barybin via Devel posted 15 patches 1 year, 2 months ago
[PATCH 13/15] qemu: enable basic qcow2 data-file feature support
Posted by Nikolai Barybin via Devel 1 year, 2 months ago
- propogate data-file to cmdline
- determine data-file within disk chain
- enable live disk insertion

Signed-off-by: Nikolai Barybin <nikolai.barybin@virtuozzo.com>
---
 src/qemu/qemu_block.c   | 14 ++++++++++++++
 src/qemu/qemu_command.c |  5 +++++
 src/qemu/qemu_domain.c  | 14 +++++++++++++-
 3 files changed, 32 insertions(+), 1 deletion(-)

diff --git a/src/qemu/qemu_block.c b/src/qemu/qemu_block.c
index 3c1305ec84..1915d5f5fd 100644
--- a/src/qemu/qemu_block.c
+++ b/src/qemu/qemu_block.c
@@ -1302,6 +1302,13 @@ qemuBlockStorageSourceGetFormatQcow2Props(virStorageSource *src,
                               NULL) < 0)
         return -1;
 
+    if (src->dataFileStore) {
+        if (virJSONValueObjectAdd(&props,
+                                  "s:data-file", qemuBlockStorageSourceGetEffectiveNodename(src->dataFileStore),
+                                  NULL) < 0)
+        return -1;
+    }
+
     return 0;
 }
 
@@ -1859,6 +1866,13 @@ qemuBlockStorageSourceChainDetachPrepareBlockdev(virStorageSource *src)
             return NULL;
 
         VIR_APPEND_ELEMENT(data->srcdata, data->nsrcdata, backend);
+
+        if (n->dataFileStore) {
+            if (!(backend = qemuBlockStorageSourceDetachPrepare(n->dataFileStore)))
+                return NULL;
+
+            VIR_APPEND_ELEMENT(data->srcdata, data->nsrcdata, backend);
+        }
     }
 
     return g_steal_pointer(&data);
diff --git a/src/qemu/qemu_command.c b/src/qemu/qemu_command.c
index f4430275dc..cdc80cee73 100644
--- a/src/qemu/qemu_command.c
+++ b/src/qemu/qemu_command.c
@@ -11018,6 +11018,11 @@ qemuBuildStorageSourceChainAttachPrepareBlockdev(virStorageSource *top)
         if (qemuBuildStorageSourceChainAttachPrepareBlockdevOne(data, n,
                                                                 n->backingStore) < 0)
             return NULL;
+
+        if (n->dataFileStore &&
+            qemuBuildStorageSourceChainAttachPrepareBlockdevOne(data, n->dataFileStore,
+                                                                n->dataFileStore->backingStore) < 0)
+            return NULL;
     }
 
     return g_steal_pointer(&data);
diff --git a/src/qemu/qemu_domain.c b/src/qemu/qemu_domain.c
index 393c7dcac1..d0700db3be 100644
--- a/src/qemu/qemu_domain.c
+++ b/src/qemu/qemu_domain.c
@@ -6242,9 +6242,17 @@ qemuDomainDetermineDiskChain(virQEMUDriver *driver,
                                     true) < 0)
         return -1;
 
+    if (src->dataFileStore &&
+        qemuDomainPrepareStorageSource(src->dataFileStore, vm, disk, cfg) < 0)
+        return -1;
+
     for (n = src->backingStore; virStorageSourceIsBacking(n); n = n->backingStore) {
         if (qemuDomainPrepareStorageSource(n, vm, disk, cfg) < 0)
             return -1;
+
+        if (n->dataFileStore &&
+            qemuDomainPrepareStorageSource(n->dataFileStore, vm, disk, cfg) < 0)
+            return -1;
     }
 
     if (qemuDomainStorageSourceValidateDepth(disksrc, 0, disk->dst) < 0)
@@ -9438,7 +9446,7 @@ qemuDomainPrepareDiskSourceData(virDomainDiskDef *disk,
         return;
 
     /* transfer properties valid only for the top level image */
-    if (src == disk->src)
+    if (src == disk->src || src == disk->src->dataFileStore)
         src->detect_zeroes = disk->detect_zeroes;
 
     /* transfer properties valid for the full chain */
@@ -9667,6 +9675,10 @@ qemuDomainPrepareDiskSourceBlockdev(virDomainDiskDef *disk,
     for (n = disk->src; virStorageSourceIsBacking(n); n = n->backingStore) {
         if (qemuDomainPrepareStorageSourceBlockdev(disk, n, priv, cfg) < 0)
             return -1;
+
+        if (n->dataFileStore &&
+            qemuDomainPrepareStorageSourceBlockdev(disk, n->dataFileStore, priv, cfg) < 0)
+            return -1;
     }
 
     return 0;
-- 
2.43.5
Re: [PATCH 13/15] qemu: enable basic qcow2 data-file feature support
Posted by Peter Krempa 1 year, 2 months ago
On Wed, Nov 20, 2024 at 18:48:48 +0300, Nikolai Barybin via Devel wrote:
> - propogate data-file to cmdline
> - determine data-file within disk chain
> - enable live disk insertion
> 
> Signed-off-by: Nikolai Barybin <nikolai.barybin@virtuozzo.com>
> ---
>  src/qemu/qemu_block.c   | 14 ++++++++++++++
>  src/qemu/qemu_command.c |  5 +++++
>  src/qemu/qemu_domain.c  | 14 +++++++++++++-
>  3 files changed, 32 insertions(+), 1 deletion(-)

We need to also forbid formatting of qcow2 images if 'data-file' woudl
be requested by the user until it'll be implemented. Given that it's not
really necessary I'll be adding

@@ -2589,6 +2603,12 @@ qemuBlockStorageSourceCreateFormat(virDomainObj *vm,
     if (qemuBlockStorageSourceIsRaw(src))
         return 0;

+    if (src->dataFileStore) {
+        virReportError(VIR_ERR_OPERATION_UNSUPPORTED, "%s",
+                       _("creation of storage images with <dataStore> feature is not supported"));
+        return -1;
+    }
+


> diff --git a/src/qemu/qemu_command.c b/src/qemu/qemu_command.c
> index f4430275dc..cdc80cee73 100644
> --- a/src/qemu/qemu_command.c
> +++ b/src/qemu/qemu_command.c
> @@ -11018,6 +11018,11 @@ qemuBuildStorageSourceChainAttachPrepareBlockdev(virStorageSource *top)
>          if (qemuBuildStorageSourceChainAttachPrepareBlockdevOne(data, n,
>                                                                  n->backingStore) < 0)
>              return NULL;
> +
> +        if (n->dataFileStore &&
> +            qemuBuildStorageSourceChainAttachPrepareBlockdevOne(data, n->dataFileStore,
> +                                                                n->dataFileStore->backingStore) < 0)

It makes no sense to pass  n->dataFileStore->backingStore. Instead I'll
explain why we're not doing that in a comment.


> +            return NULL;
>      }
>  
>      return g_steal_pointer(&data);
> diff --git a/src/qemu/qemu_domain.c b/src/qemu/qemu_domain.c
> index 393c7dcac1..d0700db3be 100644
> --- a/src/qemu/qemu_domain.c
> +++ b/src/qemu/qemu_domain.c
> @@ -6242,9 +6242,17 @@ qemuDomainDetermineDiskChain(virQEMUDriver *driver,
>                                      true) < 0)
>          return -1;
>  
> +    if (src->dataFileStore &&
> +        qemuDomainPrepareStorageSource(src->dataFileStore, vm, disk, cfg) < 0)
> +        return -1;

This requires explanation otherwise it looks misplaced here.

> +
>      for (n = src->backingStore; virStorageSourceIsBacking(n); n = n->backingStore) {
>          if (qemuDomainPrepareStorageSource(n, vm, disk, cfg) < 0)
>              return -1;

Reviewed-by: Peter Krempa <pkrempa@redhat.com>