]> git.ipfire.org Git - thirdparty/libvirt.git/commitdiff
ch: Emit event on device attach
authorMichal Privoznik <mprivozn@redhat.com>
Tue, 9 Sep 2025 13:42:50 +0000 (15:42 +0200)
committerMichal Privoznik <mprivozn@redhat.com>
Fri, 12 Sep 2025 10:22:34 +0000 (12:22 +0200)
When a device is attached to a running guest we ought to emit the
VIR_DOMAIN_EVENT_ID_DEVICE_ADDED event.

Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
src/ch/ch_hotplug.c

index 0a55a5706902cf232e3a620d580e26823718b69e..e7734e2ff0e303ecd589b0ea2a384307fc21d65b 100644 (file)
@@ -52,23 +52,26 @@ chDomainAddDisk(virCHMonitor *mon,
 }
 
 static int
-chDomainAttachDeviceLive(virDomainObj *vm,
+chDomainAttachDeviceLive(virCHDriver *driver,
+                         virDomainObj *vm,
                          virDomainDeviceDef *dev)
 {
     int ret = -1;
     virCHDomainObjPrivate *priv = vm->privateData;
     virCHMonitor *mon = priv->monitor;
+    const char *alias = NULL;
 
     switch (dev->type) {
-    case VIR_DOMAIN_DEVICE_DISK: {
+    case VIR_DOMAIN_DEVICE_DISK:
         if (chDomainAddDisk(mon, vm, dev->data.disk) < 0) {
             break;
         }
 
+        alias = dev->data.disk->info.alias;
         dev->data.disk = NULL;
         ret = 0;
         break;
-    }
+
     case VIR_DOMAIN_DEVICE_NET:
     case VIR_DOMAIN_DEVICE_LEASE:
     case VIR_DOMAIN_DEVICE_FS:
@@ -104,6 +107,13 @@ chDomainAttachDeviceLive(virDomainObj *vm,
         break;
     }
 
+    if (alias) {
+        virObjectEvent *event;
+
+        event = virDomainEventDeviceAddedNewFromObj(vm, alias);
+        virObjectEventStateQueue(driver->domainEventState, event);
+    }
+
     return ret;
 }
 
@@ -148,7 +158,7 @@ chDomainAttachDeviceLiveAndUpdateConfig(virDomainObj *vm,
             return -1;
         }
 
-        if (chDomainAttachDeviceLive(vm, devLive) < 0) {
+        if (chDomainAttachDeviceLive(driver, vm, devLive) < 0) {
             virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
                         _("Failed to add device"));
             return -1;