[libvirt] [PATCH 25/25] qemu: hotplug: Transfer ownership of backing chain to block job on disk unplug

Peter Krempa posted 25 patches 6 years, 7 months ago
[libvirt] [PATCH 25/25] qemu: hotplug: Transfer ownership of backing chain to block job on disk unplug
Posted by Peter Krempa 6 years, 7 months ago
When removing the disk fronted while any block job is still active we
need to transfer the ownership of the backing chain to the job itself as
the job still holds the reference to the chain members and thus attempts
to remove them would fail.

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

diff --git a/src/qemu/qemu_hotplug.c b/src/qemu/qemu_hotplug.c
index c50e41144e..7501ae5029 100644
--- a/src/qemu/qemu_hotplug.c
+++ b/src/qemu/qemu_hotplug.c
@@ -4228,8 +4228,15 @@ qemuDomainRemoveDiskDevice(virQEMUDriverPtr driver,
         if (VIR_STRDUP(corAlias, diskPriv->nodeCopyOnRead) < 0)
             goto cleanup;

-        if (!(diskBackend = qemuBlockStorageSourceChainDetachPrepareBlockdev(disk->src)))
-            goto cleanup;
+        if (diskPriv->blockjob) {
+            /* the block job keeps reference to the disk chain */
+            diskPriv->blockjob->disk = NULL;
+            virObjectUnref(diskPriv->blockjob);
+            diskPriv->blockjob = NULL;
+        } else {
+            if (!(diskBackend = qemuBlockStorageSourceChainDetachPrepareBlockdev(disk->src)))
+                goto cleanup;
+        }
     } else {
         char *driveAlias;

@@ -4252,7 +4259,8 @@ qemuDomainRemoveDiskDevice(virQEMUDriverPtr driver,
     if (corAlias)
         ignore_value(qemuMonitorDelObject(priv->mon, corAlias));

-    qemuBlockStorageSourceChainDetach(priv->mon, diskBackend);
+    if (diskBackend)
+        qemuBlockStorageSourceChainDetach(priv->mon, diskBackend);

     if (qemuDomainObjExitMonitor(driver, vm) < 0)
         goto cleanup;
@@ -4262,7 +4270,8 @@ qemuDomainRemoveDiskDevice(virQEMUDriverPtr driver,
     qemuDomainReleaseDeviceAddress(vm, &disk->info);

     /* tear down disk security access */
-    qemuDomainStorageSourceChainAccessRevoke(driver, vm, disk->src);
+    if (diskBackend)
+        qemuDomainStorageSourceChainAccessRevoke(driver, vm, disk->src);

     dev.type = VIR_DOMAIN_DEVICE_DISK;
     dev.data.disk = disk;
-- 
2.21.0

--
libvir-list mailing list
libvir-list@redhat.com
https://www.redhat.com/mailman/listinfo/libvir-list
Re: [libvirt] [PATCH 25/25] qemu: hotplug: Transfer ownership of backing chain to block job on disk unplug
Posted by Ján Tomko 6 years, 6 months ago
On Fri, Jul 12, 2019 at 06:06:06PM +0200, Peter Krempa wrote:
>When removing the disk fronted while any block job is still active we
>need to transfer the ownership of the backing chain to the job itself as
>the job still holds the reference to the chain members and thus attempts
>to remove them would fail.
>
>Signed-off-by: Peter Krempa <pkrempa@redhat.com>
>---
> src/qemu/qemu_hotplug.c | 17 +++++++++++++----
> 1 file changed, 13 insertions(+), 4 deletions(-)
>

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

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