[libvirt] [PATCH] qemu: Fix detaching from persistent def in qemuDomainDetachDeviceAliasLiveAndConfig

Peter Krempa posted 1 patch 5 years, 10 months ago
Patches applied successfully (tree, apply log)
git fetch https://github.com/patchew-project/libvirt tags/patchew/27b7304476d2991402277e7985b7f0f5cb385d5a.1528184299.git.pkrempa@redhat.com
Test syntax-check failed
src/qemu/qemu_driver.c | 7 +++----
1 file changed, 3 insertions(+), 4 deletions(-)
[libvirt] [PATCH] qemu: Fix detaching from persistent def in qemuDomainDetachDeviceAliasLiveAndConfig
Posted by Peter Krempa 5 years, 10 months ago
The code that detaches the device from persistent definition copies the
persistent definition first so that it can easily be rolled back. The
actual detaching is then made in the copy which is assigned back on
success (if the live operation succeeded as well).

This is not the case in qemuDomainDetachDeviceAliasLiveAndConfig where
the definition was copied and put back, but the detaching happened from
the other object which was overwritten.

Signed-off-by: Peter Krempa <pkrempa@redhat.com>
---
 src/qemu/qemu_driver.c | 7 +++----
 1 file changed, 3 insertions(+), 4 deletions(-)

diff --git a/src/qemu/qemu_driver.c b/src/qemu/qemu_driver.c
index c200c5a63d..b7b318896f 100644
--- a/src/qemu/qemu_driver.c
+++ b/src/qemu/qemu_driver.c
@@ -8822,14 +8822,13 @@ qemuDomainDetachDeviceAliasLiveAndConfig(virQEMUDriverPtr driver,
     if (persistentDef) {
         virDomainDeviceDef dev;

-        vmdef = virDomainObjCopyPersistentDef(vm, caps, driver->xmlopt);
-        if (!vmdef)
+        if (!(vmdef = virDomainObjCopyPersistentDef(vm, caps, driver->xmlopt)))
             goto cleanup;

-        if (virDomainDefFindDevice(persistentDef, alias, &dev, true) < 0)
+        if (virDomainDefFindDevice(vmdef, alias, &dev, true) < 0)
             goto cleanup;

-        if (qemuDomainDetachDeviceConfig(persistentDef, &dev, caps,
+        if (qemuDomainDetachDeviceConfig(vmdef, &dev, caps,
                                          parse_flags, driver->xmlopt) < 0)
             goto cleanup;
     }
-- 
2.16.2

--
libvir-list mailing list
libvir-list@redhat.com
https://www.redhat.com/mailman/listinfo/libvir-list
Re: [libvirt] [PATCH] qemu: Fix detaching from persistent def in qemuDomainDetachDeviceAliasLiveAndConfig
Posted by Michal Privoznik 5 years, 10 months ago
On 06/05/2018 09:38 AM, Peter Krempa wrote:
> The code that detaches the device from persistent definition copies the
> persistent definition first so that it can easily be rolled back. The
> actual detaching is then made in the copy which is assigned back on
> success (if the live operation succeeded as well).
> 
> This is not the case in qemuDomainDetachDeviceAliasLiveAndConfig where
> the definition was copied and put back, but the detaching happened from
> the other object which was overwritten.
> 
> Signed-off-by: Peter Krempa <pkrempa@redhat.com>
> ---
>  src/qemu/qemu_driver.c | 7 +++----
>  1 file changed, 3 insertions(+), 4 deletions(-)
> 
> diff --git a/src/qemu/qemu_driver.c b/src/qemu/qemu_driver.c
> index c200c5a63d..b7b318896f 100644
> --- a/src/qemu/qemu_driver.c
> +++ b/src/qemu/qemu_driver.c
> @@ -8822,14 +8822,13 @@ qemuDomainDetachDeviceAliasLiveAndConfig(virQEMUDriverPtr driver,
>      if (persistentDef) {
>          virDomainDeviceDef dev;
> 
> -        vmdef = virDomainObjCopyPersistentDef(vm, caps, driver->xmlopt);
> -        if (!vmdef)
> +        if (!(vmdef = virDomainObjCopyPersistentDef(vm, caps, driver->xmlopt)))
>              goto cleanup;
> 
> -        if (virDomainDefFindDevice(persistentDef, alias, &dev, true) < 0)
> +        if (virDomainDefFindDevice(vmdef, alias, &dev, true) < 0)
>              goto cleanup;
> 
> -        if (qemuDomainDetachDeviceConfig(persistentDef, &dev, caps,
> +        if (qemuDomainDetachDeviceConfig(vmdef, &dev, caps,
>                                           parse_flags, driver->xmlopt) < 0)
>              goto cleanup;
>      }
> 

Ooops, yes. ACK.

Michal

--
libvir-list mailing list
libvir-list@redhat.com
https://www.redhat.com/mailman/listinfo/libvir-list