Just line in previous commit, if we are the last ones that are
using the pr-manager delete it and also kill the pr-helper
process.
Signed-off-by: Michal Privoznik <mprivozn(a)redhat.com>
---
src/qemu/qemu_domain.c | 19 +++++++++++++++++++
src/qemu/qemu_domain.h | 3 +++
src/qemu/qemu_hotplug.c | 22 ++++++++++++++++++++++
3 files changed, 44 insertions(+)
diff --git a/src/qemu/qemu_domain.c b/src/qemu/qemu_domain.c
index 3e05cf0f8..505e81784 100644
--- a/src/qemu/qemu_domain.c
+++ b/src/qemu/qemu_domain.c
@@ -11892,6 +11892,25 @@ qemuDomainCheckMigrationCapabilities(virQEMUDriverPtr driver,
}
+size_t
+qemuDomainGetPRDManagedCount(const virDomainDef *def)
+{
+ size_t i;
+ size_t nmanaged = 0;
+
+ for (i = 0; i < def->ndisks; i++) {
+ virDomainDiskDefPtr disk = def->disks[i];
+
+ if (!virStoragePRDefIsManaged(disk->src->pr))
+ continue;
+
+ nmanaged++;
+ }
+
+ return nmanaged;
+}
+
+
static int
qemuDomainPrepareDiskPRD(qemuDomainObjPrivatePtr priv,
virDomainDiskDefPtr disk)
diff --git a/src/qemu/qemu_domain.h b/src/qemu/qemu_domain.h
index 418b47153..c2f67f379 100644
--- a/src/qemu/qemu_domain.h
+++ b/src/qemu/qemu_domain.h
@@ -1007,6 +1007,9 @@ qemuDomainCheckMigrationCapabilities(virQEMUDriverPtr driver,
virDomainObjPtr vm,
qemuDomainAsyncJob asyncJob);
+size_t
+qemuDomainGetPRDManagedCount(const virDomainDef *def);
+
int
qemuDomainPrepareDiskSource(virDomainDiskDefPtr disk,
qemuDomainObjPrivatePtr priv,
diff --git a/src/qemu/qemu_hotplug.c b/src/qemu/qemu_hotplug.c
index 8cc0b631d..6fe23f618 100644
--- a/src/qemu/qemu_hotplug.c
+++ b/src/qemu/qemu_hotplug.c
@@ -400,6 +400,13 @@ qemuDestroyPRDefObject(virDomainObjPtr vm,
}
+static bool
+qemuDomainDiskNeedRemovePR(virDomainObjPtr vm)
+{
+ return qemuDomainGetPRDManagedCount(vm->def) == 1;
+}
+
+
/**
* qemuDomainAttachDiskGeneric:
*
@@ -3797,6 +3804,8 @@ qemuDomainRemoveDiskDevice(virQEMUDriverPtr driver,
char *drivestr;
char *objAlias = NULL;
char *encAlias = NULL;
+ const char *prAlias = NULL;
+ const char *prPath = NULL;
VIR_DEBUG("Removing disk %s from domain %p %s",
disk->info.alias, vm, vm->def->name);
@@ -3834,6 +3843,14 @@ qemuDomainRemoveDiskDevice(virQEMUDriverPtr driver,
}
}
+ if (qemuDomainDiskNeedRemovePR(vm)) {
+ qemuDomainStorageSourcePrivatePtr srcPriv;
+
+ srcPriv = QEMU_DOMAIN_STORAGE_SOURCE_PRIVATE(disk->src);
+ prAlias = srcPriv->prd->alias;
+ prPath = srcPriv->prd->path;
+ }
+
qemuDomainObjEnterMonitor(driver, vm);
qemuMonitorDriveDel(priv->mon, drivestr);
@@ -3849,6 +3866,9 @@ qemuDomainRemoveDiskDevice(virQEMUDriverPtr driver,
ignore_value(qemuMonitorDelObject(priv->mon, encAlias));
VIR_FREE(encAlias);
+ if (prAlias)
+ ignore_value(qemuMonitorDelObject(priv->mon, prAlias));
+
if (disk->src->haveTLS)
ignore_value(qemuMonitorDelObject(priv->mon, disk->src->tlsAlias));
@@ -3867,6 +3887,8 @@ qemuDomainRemoveDiskDevice(virQEMUDriverPtr driver,
}
}
+ qemuDestroyPRDefObject(vm, prAlias, prPath);
+
qemuDomainReleaseDeviceAddress(vm, &disk->info, src);
if (qemuSecurityRestoreDiskLabel(driver, vm, disk) < 0)
--
2.16.1