From: Michal Privoznik <mprivozn@redhat.com>
When a device is detached from a running guest we ought to emit the
VIR_DOMAIN_EVENT_ID_DEVICE_REMOVED event.
Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
---
src/ch/ch_hotplug.c | 15 +++++++++++++--
1 file changed, 13 insertions(+), 2 deletions(-)
diff --git a/src/ch/ch_hotplug.c b/src/ch/ch_hotplug.c
index e7734e2ff0..b953fe4c6c 100644
--- a/src/ch/ch_hotplug.c
+++ b/src/ch/ch_hotplug.c
@@ -267,12 +267,15 @@ chDomainRemoveDevice(virDomainObj *vm,
static int
-chDomainDetachDeviceLive(virDomainObj *vm,
+chDomainDetachDeviceLive(virCHDriver *driver,
+ virDomainObj *vm,
virDomainDeviceDef *match)
{
virDomainDeviceDef detach = { .type = match->type };
virDomainDeviceInfo *info = NULL;
virCHDomainObjPrivate *priv = vm->privateData;
+ virObjectEvent *event = NULL;
+ g_autofree char *alias = NULL;
switch (match->type) {
case VIR_DOMAIN_DEVICE_DISK:
@@ -339,6 +342,11 @@ chDomainDetachDeviceLive(virDomainObj *vm,
return -1;
}
+ /* Save the alias to use when sending a DEVICE_REMOVED event after all
+ * other tear down is complete.
+ */
+ alias = g_strdup(info->alias);
+
if (virCHMonitorRemoveDevice(priv->monitor, info->alias) < 0) {
virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
_("Invalid response from CH. Disk removal failed."));
@@ -348,6 +356,9 @@ chDomainDetachDeviceLive(virDomainObj *vm,
if (chDomainRemoveDevice(vm, &detach) < 0)
return -1;
+ event = virDomainEventDeviceRemovedNewFromObj(vm, alias);
+ virObjectEventStateQueue(driver->domainEventState, event);
+
return 0;
}
@@ -386,7 +397,7 @@ chDomainDetachDeviceLiveAndUpdateConfig(virCHDriver *driver,
return -1;
}
- if (chDomainDetachDeviceLive(vm, dev_live) < 0) {
+ if (chDomainDetachDeviceLive(driver, vm, dev_live) < 0) {
virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
_("Could detach device"));
return -1;
--
2.49.1