If we are the last one to use pr-manager object we need to remove
it and also kill the qemu-pr-helper process.
Signed-off-by: Michal Privoznik <mprivozn(a)redhat.com>
---
src/qemu/qemu_hotplug.c | 56 +++++++++++++++++++++++++++++++++++++++++++++++++
1 file changed, 56 insertions(+)
diff --git a/src/qemu/qemu_hotplug.c b/src/qemu/qemu_hotplug.c
index 2e736873d1..e9dd8a4532 100644
--- a/src/qemu/qemu_hotplug.c
+++ b/src/qemu/qemu_hotplug.c
@@ -3824,6 +3824,49 @@ static bool qemuIsMultiFunctionDevice(virDomainDefPtr def,
}
+static int
+qemuDomainDiskNeedRemovePR(virDomainObjPtr vm,
+ virDomainDiskDefPtr disk,
+ char **aliasret,
+ bool *stopDaemon)
+{
+ qemuDomainObjPrivatePtr priv = vm->privateData;
+ size_t i;
+
+ *aliasret = NULL;
+ *stopDaemon = false;
+
+ if (!virStoragePRDefIsEnabled(disk->src->pr))
+ return 0;
+
+ if (!virStoragePRDefIsManaged(disk->src->pr)) {
+ *aliasret = qemuDomainGetUnmanagedPRAlias(disk);
+ return *aliasret ? 0 : -1;
+ }
+
+ for (i = 0; i < vm->def->ndisks; i++) {
+ const virDomainDiskDef *domainDisk = vm->def->disks[i];
+
+ if (domainDisk == disk)
+ continue;
+
+ if (virStoragePRDefIsManaged(domainDisk->src->pr))
+ break;
+ }
+
+ if (i != vm->def->ndisks)
+ return 0;
+
+ if (VIR_STRDUP(*aliasret, qemuDomainGetManagedPRAlias()) < 0)
+ return -1;
+
+ if (priv->prDaemonRunning)
+ *stopDaemon = true;
+
+ return 0;
+}
+
+
static int
qemuDomainRemoveDiskDevice(virQEMUDriverPtr driver,
virDomainObjPtr vm,
@@ -3837,6 +3880,8 @@ qemuDomainRemoveDiskDevice(virQEMUDriverPtr driver,
char *drivestr;
char *objAlias = NULL;
char *encAlias = NULL;
+ char *prmgrAlias = NULL;
+ bool stopPRDaemon = false;
VIR_DEBUG("Removing disk %s from domain %p %s",
disk->info.alias, vm, vm->def->name);
@@ -3874,6 +3919,9 @@ qemuDomainRemoveDiskDevice(virQEMUDriverPtr driver,
}
}
+ if (qemuDomainDiskNeedRemovePR(vm, disk, &prmgrAlias, &stopPRDaemon) < 0)
+ return -1;
+
qemuDomainObjEnterMonitor(driver, vm);
qemuMonitorDriveDel(priv->mon, drivestr);
@@ -3889,6 +3937,11 @@ qemuDomainRemoveDiskDevice(virQEMUDriverPtr driver,
ignore_value(qemuMonitorDelObject(priv->mon, encAlias));
VIR_FREE(encAlias);
+ /* If it fails, then so be it - it was a best shot */
+ if (prmgrAlias)
+ ignore_value(qemuMonitorDelObject(priv->mon, prmgrAlias));
+ VIR_FREE(prmgrAlias);
+
if (disk->src->haveTLS)
ignore_value(qemuMonitorDelObject(priv->mon, disk->src->tlsAlias));
@@ -3907,6 +3960,9 @@ qemuDomainRemoveDiskDevice(virQEMUDriverPtr driver,
}
}
+ if (stopPRDaemon)
+ qemuProcessKillPRDaemon(vm);
+
qemuDomainReleaseDeviceAddress(vm, &disk->info, src);
if (qemuSecurityRestoreDiskLabel(driver, vm, disk) < 0)
--
2.16.1