qemu: Send event on persistent config modification

Currently, libvirt doesn't send events when devices are attached,
detached or updated. Thus, any services that listen to events are
unaware of the change to persistent config.

Signed-off-by: Fima Shevrin <efim.shevrin@virtuozzo.com>
Reviewed-by: Michal Privoznik <mprivozn@redhat.com>
This commit is contained in:
Fima Shevrin 2023-10-19 17:20:36 +03:00 committed by Michal Privoznik
parent a97b428208
commit bc06cfa1cd

View File

@ -7209,6 +7209,7 @@ qemuDomainAttachDeviceLiveAndConfig(virDomainObj *vm,
unsigned int flags) unsigned int flags)
{ {
qemuDomainObjPrivate *priv = vm->privateData; qemuDomainObjPrivate *priv = vm->privateData;
virObjectEvent *event = NULL;
g_autoptr(virDomainDef) vmdef = NULL; g_autoptr(virDomainDef) vmdef = NULL;
g_autoptr(virQEMUDriverConfig) cfg = NULL; g_autoptr(virQEMUDriverConfig) cfg = NULL;
g_autoptr(virDomainDeviceDef) devConf = NULL; g_autoptr(virDomainDeviceDef) devConf = NULL;
@ -7292,6 +7293,12 @@ qemuDomainAttachDeviceLiveAndConfig(virDomainObj *vm,
return -1; return -1;
virDomainObjAssignDef(vm, &vmdef, false, NULL); virDomainObjAssignDef(vm, &vmdef, false, NULL);
/* Event sending if persistent config has changed */
event = virDomainEventLifecycleNewFromObj(vm,
VIR_DOMAIN_EVENT_DEFINED,
VIR_DOMAIN_EVENT_DEFINED_UPDATED);
virObjectEventStateQueue(driver->domainEventState, event);
} }
return 0; return 0;
@ -7348,6 +7355,7 @@ qemuDomainUpdateDeviceFlags(virDomainPtr dom,
virQEMUDriver *driver = dom->conn->privateData; virQEMUDriver *driver = dom->conn->privateData;
virDomainObj *vm = NULL; virDomainObj *vm = NULL;
qemuDomainObjPrivate *priv; qemuDomainObjPrivate *priv;
virObjectEvent *event = NULL;
g_autoptr(virDomainDef) vmdef = NULL; g_autoptr(virDomainDef) vmdef = NULL;
g_autoptr(virDomainDeviceDef) dev_config = NULL; g_autoptr(virDomainDeviceDef) dev_config = NULL;
g_autoptr(virDomainDeviceDef) dev_live = NULL; g_autoptr(virDomainDeviceDef) dev_live = NULL;
@ -7419,8 +7427,16 @@ qemuDomainUpdateDeviceFlags(virDomainPtr dom,
/* Finally, if no error until here, we can save config. */ /* Finally, if no error until here, we can save config. */
if (flags & VIR_DOMAIN_AFFECT_CONFIG) { if (flags & VIR_DOMAIN_AFFECT_CONFIG) {
ret = virDomainDefSave(vmdef, driver->xmlopt, cfg->configDir); ret = virDomainDefSave(vmdef, driver->xmlopt, cfg->configDir);
if (!ret) if (!ret) {
virDomainObjAssignDef(vm, &vmdef, false, NULL); virDomainObjAssignDef(vm, &vmdef, false, NULL);
/* Event sending if persistent config has changed */
event = virDomainEventLifecycleNewFromObj(vm,
VIR_DOMAIN_EVENT_DEFINED,
VIR_DOMAIN_EVENT_DEFINED_UPDATED);
virObjectEventStateQueue(driver->domainEventState, event);
}
} }
endjob: endjob:
@ -7438,6 +7454,7 @@ qemuDomainDetachDeviceLiveAndConfig(virQEMUDriver *driver,
unsigned int flags) unsigned int flags)
{ {
qemuDomainObjPrivate *priv = vm->privateData; qemuDomainObjPrivate *priv = vm->privateData;
virObjectEvent *event = NULL;
g_autoptr(virQEMUDriverConfig) cfg = NULL; g_autoptr(virQEMUDriverConfig) cfg = NULL;
g_autoptr(virDomainDeviceDef) dev_config = NULL; g_autoptr(virDomainDeviceDef) dev_config = NULL;
g_autoptr(virDomainDeviceDef) dev_live = NULL; g_autoptr(virDomainDeviceDef) dev_live = NULL;
@ -7495,6 +7512,12 @@ qemuDomainDetachDeviceLiveAndConfig(virQEMUDriver *driver,
return -1; return -1;
virDomainObjAssignDef(vm, &vmdef, false, NULL); virDomainObjAssignDef(vm, &vmdef, false, NULL);
/* Event sending if persistent config has changed */
event = virDomainEventLifecycleNewFromObj(vm,
VIR_DOMAIN_EVENT_DEFINED,
VIR_DOMAIN_EVENT_DEFINED_UPDATED);
virObjectEventStateQueue(driver->domainEventState, event);
} }
return 0; return 0;