From: Michal Privoznik Date: Tue, 9 Sep 2025 14:00:37 +0000 (+0200) Subject: ch: Emit event on device attach X-Git-Tag: v11.8.0-rc1~37 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=f9c1b910bf5c38c94de260f90db4f3df4c36fe15;p=thirdparty%2Flibvirt.git ch: Emit event on device attach 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 Reviewed-by: Ján Tomko --- 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;