[PATCH] virDomainMemoryDefValidate: Skip the same device on validation on memory device update

Michal Privoznik posted 1 patch 6 months, 2 weeks ago
Patches applied successfully (tree, apply log)
git fetch https://github.com/patchew-project/libvirt tags/patchew/d8b6e0755f6d3a98d5218a374fe3eef6e393ea7e.1697441754.git.mprivozn@redhat.com
src/conf/domain_validate.c | 15 +++++++++++++++
1 file changed, 15 insertions(+)
[PATCH] virDomainMemoryDefValidate: Skip the same device on validation on memory device update
Posted by Michal Privoznik 6 months, 2 weeks ago
In my recent commit of v9.8.0-rc1~7 I've introduced validation
wrt other memory devices. And mostly works, except when doing
memory device update ('virsh update-memory-device') because then
@mem is just parsed <memory/> device XML and thus its pointer is
not in the vm->def->mem, yet. Thus my algorithm which skips over
the same entry fails. Fortunately, we require full device XML on
device update and thus we can use device address and aliases to
detect duplicity.

Fixes: 3fd64fb0e236fc80ffa2cc977c0d471f11fc39bf
Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
---
 src/conf/domain_validate.c | 15 +++++++++++++++
 1 file changed, 15 insertions(+)

diff --git a/src/conf/domain_validate.c b/src/conf/domain_validate.c
index 6962fe76bf..bc3d00f89c 100644
--- a/src/conf/domain_validate.c
+++ b/src/conf/domain_validate.c
@@ -2387,6 +2387,21 @@ virDomainMemoryDefValidate(const virDomainMemoryDef *mem,
         if (other == mem)
             continue;
 
+        /* In case we're updating an existing memory device (e.g. virtio-mem),
+         * then pointers will be different. But addresses and aliases are the
+         * same. However, STREQ_NULLABLE() returns true if both strings are
+         * NULL which is not what we want. */
+        if (virDomainDeviceInfoAddressIsEqual(&other->info,
+                                              &mem->info)) {
+            continue;
+        }
+
+        if (mem->info.alias &&
+            STREQ_NULLABLE(other->info.alias,
+                           mem->info.alias)) {
+            continue;
+        }
+
         switch (other->model) {
         case VIR_DOMAIN_MEMORY_MODEL_NONE:
         case VIR_DOMAIN_MEMORY_MODEL_DIMM:
-- 
2.41.0
Re: [PATCH] virDomainMemoryDefValidate: Skip the same device on validation on memory device update
Posted by Ján Tomko 6 months, 2 weeks ago
On a Monday in 2023, Michal Privoznik wrote:
>In my recent commit of v9.8.0-rc1~7 I've introduced validation
>wrt other memory devices. And mostly works, except when doing
>memory device update ('virsh update-memory-device') because then
>@mem is just parsed <memory/> device XML and thus its pointer is
>not in the vm->def->mem, yet. Thus my algorithm which skips over
>the same entry fails. Fortunately, we require full device XML on
>device update and thus we can use device address and aliases to
>detect duplicity.
>
>Fixes: 3fd64fb0e236fc80ffa2cc977c0d471f11fc39bf
>Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
>---
> src/conf/domain_validate.c | 15 +++++++++++++++
> 1 file changed, 15 insertions(+)
>

Reviewed-by: Ján Tomko <jtomko@redhat.com>

Jano