]> git.ipfire.org Git - thirdparty/libvirt.git/commitdiff
qemuProcessHandleBlockThreshold: Report correct indexes
authorPeter Krempa <pkrempa@redhat.com>
Wed, 15 Jul 2020 09:51:17 +0000 (11:51 +0200)
committerPeter Krempa <pkrempa@redhat.com>
Tue, 21 Jul 2020 07:52:46 +0000 (09:52 +0200)
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>
src/qemu/qemu_process.c

index 31a8090a991e70ea9d6b38395299d60a95f4d1e5..8660cc4c8f1cecd58781fc9840b75bfae6b791f6 100644 (file)
@@ -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;
 }