]> git.ipfire.org Git - thirdparty/libvirt.git/commitdiff
qemu: hotplug: Transfer ownership of backing chain to block job on disk unplug
authorPeter Krempa <pkrempa@redhat.com>
Mon, 25 Mar 2019 15:30:28 +0000 (16:30 +0100)
committerPeter Krempa <pkrempa@redhat.com>
Thu, 18 Jul 2019 15:59:34 +0000 (17:59 +0200)
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>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
src/qemu/qemu_hotplug.c

index c50e41144e63da8ab68354f130778c976372cf0b..7501ae5029334b656a36d1b133cb1727e48f6bd6 100644 (file)
@@ -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;