The index returned by qemuDomainDiskLookupByNodename is the position in the backing chain rather than the index we report in the XML.
Since with -blockdev they differ now and additionally the disk source also has an index we need to fix the 'threshold' evens we report: 1) If it's the top level image we must always trigger the event without any suffix as we did until now 2) We must report the correct index 3) We must report the correct index also for the top level image, when blockdev is used. This means that we need to potentially emit 2 events, one for the device without the index and then when blockdev is used and the top level image has an idex we must do it also with the index. This will fix it for blockdev cases, while also not removing previous semantics. https://bugzilla.redhat.com/show_bug.cgi?id=1857204 Signed-off-by: Peter Krempa <pkre...@redhat.com> --- src/qemu/qemu_process.c | 26 ++++++++++++++++++-------- 1 file changed, 18 insertions(+), 8 deletions(-) diff --git a/src/qemu/qemu_process.c b/src/qemu/qemu_process.c index 2ee778c606..9b6dc8e68b 100644 --- a/src/qemu/qemu_process.c +++ b/src/qemu/qemu_process.c @@ -1497,10 +1497,10 @@ qemuProcessHandleBlockThreshold(qemuMonitorPtr mon G_GNUC_UNUSED, void *opaque) { virQEMUDriverPtr driver = opaque; - virObjectEventPtr event = NULL; + virObjectEventPtr eventSource = NULL; + virObjectEventPtr eventDevice = NULL; virDomainDiskDefPtr disk; virStorageSourcePtr src; - unsigned int idx; const char *path = NULL; virObjectLock(vm); @@ -1509,18 +1509,28 @@ qemuProcessHandleBlockThreshold(qemuMonitorPtr mon G_GNUC_UNUSED, "threshold '%llu' exceeded by '%llu'", nodename, vm, vm->def->name, threshold, excess); - if ((disk = qemuDomainDiskLookupByNodename(vm->def, nodename, &src, &idx))) { - g_autofree char *dev = NULL; + if ((disk = qemuDomainDiskLookupByNodename(vm->def, nodename, &src, NULL))) { if (virStorageSourceIsLocalStorage(src)) path = src->path; - if ((dev = qemuDomainDiskBackingStoreGetName(disk, idx))) - event = virDomainEventBlockThresholdNewFromObj(vm, dev, path, - threshold, excess); + if (src == disk->src) { + g_autofree char *dev = qemuDomainDiskBackingStoreGetName(disk, 0); + + eventDevice = virDomainEventBlockThresholdNewFromObj(vm, dev, path, + threshold, excess); + } + + if (src->id != 0) { + g_autofree char *dev = qemuDomainDiskBackingStoreGetName(disk, src->id); + + eventSource = virDomainEventBlockThresholdNewFromObj(vm, dev, path, + threshold, excess); + } } virObjectUnlock(vm); - virObjectEventStateQueue(driver->domainEventState, event); + virObjectEventStateQueue(driver->domainEventState, eventDevice); + virObjectEventStateQueue(driver->domainEventState, eventSource); return 0; } -- 2.26.2