[PATCH v2] qemuDomainDiskChangeSupported: Add missing iothreads check

Peter Krempa posted 1 patch 2 weeks, 4 days ago
src/qemu/qemu_domain.c | 46 ++++++++++++++++++++++++++++++++++++++++++
1 file changed, 46 insertions(+)
[PATCH v2] qemuDomainDiskChangeSupported: Add missing iothreads check
Posted by Peter Krempa 2 weeks, 4 days ago
From: Adam Julis <ajulis@redhat.com>

GSList of iothreads is not allowed to be changed while the
virtual machine is running.

Resolves: https://issues.redhat.com/browse/RHEL-23607
Signed-off-by: Adam Julis <ajulis@redhat.com>
Signed-off-by: Peter Krempa <pkrempa@redhat.com>
---

Changes to v1:
 - extrac to separate function
 - improve readability of loops and handling of error
 - fix possibility of infinitely looping if first queue of both queue
   lists matches

 src/qemu/qemu_domain.c | 46 ++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 46 insertions(+)

diff --git a/src/qemu/qemu_domain.c b/src/qemu/qemu_domain.c
index 66ab4baa8b..153bd56e86 100644
--- a/src/qemu/qemu_domain.c
+++ b/src/qemu/qemu_domain.c
@@ -6591,6 +6591,49 @@ qemuDomainStorageSourceAccessAllow(virQEMUDriver *driver,
 }


+static bool
+qemuDomainDiskChangeSupportedIothreads(virDomainDiskDef *disk,
+                                       virDomainDiskDef *orig_disk)
+{
+    GSList *old = orig_disk->iothreads;
+    GSList *new = disk->iothreads;
+
+    while (true) {
+        virDomainDiskIothreadDef *old_def;
+        virDomainDiskIothreadDef *new_def;
+        size_t i;
+
+        /* match - both empty or both at the end */
+        if (!old && !new)
+            return true;
+
+        /* mismatched length of lists */
+        if (!old || !new)
+            goto fail;
+
+        old_def = old->data;
+        new_def = new->data;
+
+        if (old_def->id != new_def->id ||
+            old_def->nqueues != new_def->nqueues)
+            goto fail;
+
+        for (i = 0; i < old_def->nqueues; i++) {
+            if (old_def->queues[i] != new_def->queues[i])
+                goto fail;
+        }
+
+        new = new->next;
+        old = old->next;
+    }
+
+ fail:
+    virReportError(VIR_ERR_OPERATION_UNSUPPORTED, "%s",
+                   _("cannot modify field '<iothreads>' (or it's parts) of the disk"));
+    return false;
+}
+
+
 /*
  * Makes sure the @disk differs from @orig_disk only by the source
  * path and nothing else.  Fields that are being checked and the
@@ -6735,6 +6778,9 @@ qemuDomainDiskChangeSupported(virDomainDiskDef *disk,
     CHECK_EQ(discard, "discard", true);
     CHECK_EQ(iothread, "iothread", true);

+    if (!qemuDomainDiskChangeSupportedIothreads(disk, orig_disk))
+        return false;
+
     CHECK_STREQ_NULLABLE(domain_name,
                          "backenddomain");

-- 
2.47.0
Re: [PATCH v2] qemuDomainDiskChangeSupported: Add missing iothreads check
Posted by Michal Prívozník 2 weeks, 3 days ago
On 11/18/24 16:45, Peter Krempa wrote:
> From: Adam Julis <ajulis@redhat.com>
> 
> GSList of iothreads is not allowed to be changed while the
> virtual machine is running.
> 
> Resolves: https://issues.redhat.com/browse/RHEL-23607
> Signed-off-by: Adam Julis <ajulis@redhat.com>
> Signed-off-by: Peter Krempa <pkrempa@redhat.com>
> ---
> 
> Changes to v1:
>  - extrac to separate function
>  - improve readability of loops and handling of error
>  - fix possibility of infinitely looping if first queue of both queue
>    lists matches
> 
>  src/qemu/qemu_domain.c | 46 ++++++++++++++++++++++++++++++++++++++++++
>  1 file changed, 46 insertions(+)

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

Michal