Re: [PATCH] Send event on persistent config modification
On 10/19/23 16:20, Fima Shevrin wrote: > 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 > --- > src/qemu/qemu_driver.c | 25 - > 1 file changed, 24 insertions(+), 1 deletion(-) > > diff --git a/src/qemu/qemu_driver.c b/src/qemu/qemu_driver.c > index 43d96739d5..86da8da777 100644 > --- a/src/qemu/qemu_driver.c > +++ b/src/qemu/qemu_driver.c > @@ -7209,6 +7209,7 @@ qemuDomainAttachDeviceLiveAndConfig(virDomainObj *vm, > unsigned int flags) > { > qemuDomainObjPrivate *priv = vm->privateData; > +virObjectEvent *event = NULL; > g_autoptr(virDomainDef) vmdef = NULL; > g_autoptr(virQEMUDriverConfig) cfg = NULL; > g_autoptr(virDomainDeviceDef) devConf = NULL; > @@ -7292,6 +7293,12 @@ qemuDomainAttachDeviceLiveAndConfig(virDomainObj *vm, > return -1; > > virDomainObjAssignDef(vm, , 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); Yeah, this is definitely better, but we have a more specific event: VIR_DOMAIN_EVENT_ID_DEVICE_ADDED (virDomainEventDeviceAddedNewFromObj()). Simirarly, we do have VIR_DOMAIN_EVENT_ID_DEVICE_REMOVED (virDomainEventDeviceRemovedNewFromObj()). OTOH, both events assume device alias to be present (which is usually not the case for inactive XML (except for user defined device aliases)). In the end, your change makes sense. Reviewed-by: Michal Privoznik and pushed. Congratulations on your first libvirt contribution! Michal
[PATCH] 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 --- src/qemu/qemu_driver.c | 25 - 1 file changed, 24 insertions(+), 1 deletion(-) diff --git a/src/qemu/qemu_driver.c b/src/qemu/qemu_driver.c index 43d96739d5..86da8da777 100644 --- a/src/qemu/qemu_driver.c +++ b/src/qemu/qemu_driver.c @@ -7209,6 +7209,7 @@ qemuDomainAttachDeviceLiveAndConfig(virDomainObj *vm, unsigned int flags) { qemuDomainObjPrivate *priv = vm->privateData; +virObjectEvent *event = NULL; g_autoptr(virDomainDef) vmdef = NULL; g_autoptr(virQEMUDriverConfig) cfg = NULL; g_autoptr(virDomainDeviceDef) devConf = NULL; @@ -7292,6 +7293,12 @@ qemuDomainAttachDeviceLiveAndConfig(virDomainObj *vm, return -1; virDomainObjAssignDef(vm, , 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; @@ -7348,6 +7355,7 @@ qemuDomainUpdateDeviceFlags(virDomainPtr dom, virQEMUDriver *driver = dom->conn->privateData; virDomainObj *vm = NULL; qemuDomainObjPrivate *priv; +virObjectEvent *event = NULL; g_autoptr(virDomainDef) vmdef = NULL; g_autoptr(virDomainDeviceDef) dev_config = NULL; g_autoptr(virDomainDeviceDef) dev_live = NULL; @@ -7419,8 +7427,16 @@ qemuDomainUpdateDeviceFlags(virDomainPtr dom, /* Finally, if no error until here, we can save config. */ if (flags & VIR_DOMAIN_AFFECT_CONFIG) { ret = virDomainDefSave(vmdef, driver->xmlopt, cfg->configDir); -if (!ret) +if (!ret) { virDomainObjAssignDef(vm, , 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: @@ -7438,6 +7454,7 @@ qemuDomainDetachDeviceLiveAndConfig(virQEMUDriver *driver, unsigned int flags) { qemuDomainObjPrivate *priv = vm->privateData; +virObjectEvent *event = NULL; g_autoptr(virQEMUDriverConfig) cfg = NULL; g_autoptr(virDomainDeviceDef) dev_config = NULL; g_autoptr(virDomainDeviceDef) dev_live = NULL; @@ -7495,6 +7512,12 @@ qemuDomainDetachDeviceLiveAndConfig(virQEMUDriver *driver, return -1; virDomainObjAssignDef(vm, , 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; -- 2.39.3
libvirt patch in master, [PATCH] Send event on persistent config modification
>From 32dbfbf9857ea72b69ea175ea7f8b21210f4e5d2 Mon Sep 17 00:00:00 2001 From: Efim Shevrin Date: Tue, 10 May 2022 17:03:11 +0300 Subject: [PATCH] Send event on persistent config modification Libvirt is not sending events in case of a device update, thus any services listening to events are unaware of the changes.This patch suggests to send event in case of a persistent config modification, it should keep subscribed services in sync with VM configuration. Signed-off-by: Efim Shevrin --- src/qemu/qemu_driver.c | 11 ++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/src/qemu/qemu_driver.c b/src/qemu/qemu_driver.c index e3582f62a7..6008a4c8f3 100644 --- a/src/qemu/qemu_driver.c +++ b/src/qemu/qemu_driver.c @@ -7942,6 +7942,7 @@ static int qemuDomainUpdateDeviceFlags(virDomainPtr dom, virQEMUDriver *driver = dom->conn->privateData; virDomainObj *vm = NULL; qemuDomainObjPrivate *priv; +virObjectEvent *event = NULL; g_autoview.settings().get('font_face')ptr(virDomainDef) vmdef = NULL; g_autoptr(virDomainDeviceDef) dev = NULL; virDomainDeviceDef *dev_copy = NULL; @@ -8019,8 +8020,16 @@ static int qemuDomainUpdateDeviceFlags(virDomainPtr dom, /* Finally, if no error until here, we can save config. */ if (flags & VIR_DOMAIN_AFFECT_CONFIG) { ret = virDomainDefSave(vmdef, driver->xmlopt, cfg->configDir); -if (!ret) +if (!ret) { virDomainObjAssignDef(vm, , 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: -- 2.31.1