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

Nikolai Barybin via Devel posted 13 patches 1 year, 5 months ago
There is a newer version of this series
[PATCH v2 10/13] qemu: enable basic qcow2 data-file feature support
Posted by Nikolai Barybin via Devel 1 year, 5 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   |  7 +++++++
 src/qemu/qemu_command.c |  5 +++++
 src/qemu/qemu_domain.c  | 14 +++++++++++++-
 3 files changed, 25 insertions(+), 1 deletion(-)

diff --git a/src/qemu/qemu_block.c b/src/qemu/qemu_block.c
index 6e90bae9f2..5d2a638a56 100644
--- a/src/qemu/qemu_block.c
+++ b/src/qemu/qemu_block.c
@@ -1301,6 +1301,13 @@ qemuBlockStorageSourceGetFormatQcow2Props(virStorageSource *src,
                               NULL) < 0)
         return -1;
 
+    if (src->dataFileStore) {
+        if (virJSONValueObjectAdd(&props,
+                                  "s:data-file", src->dataFileStore->nodenameformat,
+                                  NULL) < 0)
+        return -1;
+    }
+
     return 0;
 }
 
diff --git a/src/qemu/qemu_command.c b/src/qemu/qemu_command.c
index 1b992d8eed..503374f470 100644
--- a/src/qemu/qemu_command.c
+++ b/src/qemu/qemu_command.c
@@ -11178,6 +11178,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 86362393e2..0555bc8cfd 100644
--- a/src/qemu/qemu_domain.c
+++ b/src/qemu/qemu_domain.c
@@ -8102,9 +8102,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)
@@ -11298,7 +11306,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 */
@@ -11527,6 +11535,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 v2 10/13] qemu: enable basic qcow2 data-file feature support
Posted by Peter Krempa 1 year, 3 months ago
On Sat, Sep 07, 2024 at 17:15:35 +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   |  7 +++++++
>  src/qemu/qemu_command.c |  5 +++++
>  src/qemu/qemu_domain.c  | 14 +++++++++++++-
>  3 files changed, 25 insertions(+), 1 deletion(-)
> 
> diff --git a/src/qemu/qemu_block.c b/src/qemu/qemu_block.c
> index 6e90bae9f2..5d2a638a56 100644
> --- a/src/qemu/qemu_block.c
> +++ b/src/qemu/qemu_block.c
> @@ -1301,6 +1301,13 @@ qemuBlockStorageSourceGetFormatQcow2Props(virStorageSource *src,
>                                NULL) < 0)
>          return -1;
>  
> +    if (src->dataFileStore) {
> +        if (virJSONValueObjectAdd(&props,
> +                                  "s:data-file", src->dataFileStore->nodenameformat,

You must not use the nodename* fields directly. In fact this doesn't
even work as raw files don't even have a 'format' node name any more.

This needs to be qemuBlockStorageSourceGetEffectiveNodename(src->dataFileStore)

> +                                  NULL) < 0)
> +        return -1;
> +    }
> +
>      return 0;
>  }
>  
> diff --git a/src/qemu/qemu_command.c b/src/qemu/qemu_command.c
> index 1b992d8eed..503374f470 100644
> --- a/src/qemu/qemu_command.c
> +++ b/src/qemu/qemu_command.c
> @@ -11178,6 +11178,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;
>      }
>  

Missing corresponding changes to
qemuBlockStorageSourceChainDetachPrepareBlockdev(), thus when
hot-unplugging a disk the data file will not be unplugged.


>      return g_steal_pointer(&data);


Possibly as a separata patch you'll also need to forbid image creation
with data file, e.g. when creating snapshots.
'qemuBlockStorageSourceCreate' is the function to consider.