qemuProcessHandleBlockThreshold: Report correct indexes

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' events 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 index 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 <pkrempa@redhat.com>
Reviewed-by: Eric Blake <eblake@redhat.com>
This commit is contained in:
Peter Krempa 2020-07-15 11:51:17 +02:00
parent 48b7c33cc7
commit c414ab00e2

View File

@ -1497,10 +1497,10 @@ qemuProcessHandleBlockThreshold(qemuMonitorPtr mon G_GNUC_UNUSED,
void *opaque) void *opaque)
{ {
virQEMUDriverPtr driver = opaque; virQEMUDriverPtr driver = opaque;
virObjectEventPtr event = NULL; virObjectEventPtr eventSource = NULL;
virObjectEventPtr eventDevice = NULL;
virDomainDiskDefPtr disk; virDomainDiskDefPtr disk;
virStorageSourcePtr src; virStorageSourcePtr src;
unsigned int idx;
const char *path = NULL; const char *path = NULL;
virObjectLock(vm); virObjectLock(vm);
@ -1509,18 +1509,28 @@ qemuProcessHandleBlockThreshold(qemuMonitorPtr mon G_GNUC_UNUSED,
"threshold '%llu' exceeded by '%llu'", "threshold '%llu' exceeded by '%llu'",
nodename, vm, vm->def->name, threshold, excess); nodename, vm, vm->def->name, threshold, excess);
if ((disk = qemuDomainDiskLookupByNodename(vm->def, nodename, &src, &idx))) { if ((disk = qemuDomainDiskLookupByNodename(vm->def, nodename, &src, NULL))) {
g_autofree char *dev = NULL;
if (virStorageSourceIsLocalStorage(src)) if (virStorageSourceIsLocalStorage(src))
path = src->path; path = src->path;
if ((dev = qemuDomainDiskBackingStoreGetName(disk, idx))) if (src == disk->src) {
event = virDomainEventBlockThresholdNewFromObj(vm, dev, path, g_autofree char *dev = qemuDomainDiskBackingStoreGetName(disk, 0);
threshold, excess);
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); virObjectUnlock(vm);
virObjectEventStateQueue(driver->domainEventState, event); virObjectEventStateQueue(driver->domainEventState, eventDevice);
virObjectEventStateQueue(driver->domainEventState, eventSource);
return 0; return 0;
} }