]> git.ipfire.org Git - thirdparty/libvirt.git/commitdiff
qemu: Handle quirks of 'device' field of BLOCK_IO_ERROR event in monitor code
authorPeter Krempa <pkrempa@redhat.com>
Mon, 27 Jan 2025 12:03:58 +0000 (13:03 +0100)
committerPeter Krempa <pkrempa@redhat.com>
Tue, 4 Feb 2025 13:40:54 +0000 (14:40 +0100)
BLOCK_IO_ERROR's 'device' field is an empty string in case when it isn't
applicable as it was originally mandatory in the qemu API docs.

Move the logic that convert's empty string back to NULL from
'qemuProcessHandleIOError()' to 'qemuMonitorJSONHandleIOError()'

This also fixes a hypothetical NULL-dereference if qemu would indeed
report an IO error without the 'device' field present.

Signed-off-by: Peter Krempa <pkrempa@redhat.com>
Reviewed-by: Daniel P. Berrangé <berrange@redhat.com>
src/qemu/qemu_monitor_json.c
src/qemu/qemu_process.c

index 9f417d27c68e08c7e2428301ebcdbc1851ca7ed2..5ca76d2d80ef5f2e8aaa65f6b67e1444302d240d 100644 (file)
@@ -708,8 +708,15 @@ qemuMonitorJSONHandleIOError(qemuMonitor *mon, virJSONValue *data)
         action = "ignore";
     }
 
-    if ((device = virJSONValueObjectGetString(data, "device")) == NULL)
+    if ((device = virJSONValueObjectGetString(data, "device")) == NULL) {
         VIR_WARN("missing device in disk io error event");
+    } else {
+        /* 'device' was documented as mandatory in the qemu event, but later became
+         * optional, in which case an empty string is sent by qemu. Convert it back
+         * to NULL */
+        if (*device == '\0')
+            device = NULL;
+    }
 
     nodename = virJSONValueObjectGetString(data, "node-name");
 
index 34a755a49a0b56afa531e80f635d4b0da23f9ff9..edcd8ac3a84688eca8f4ebc2b2f93fa618ef8ac6 100644 (file)
@@ -840,9 +840,6 @@ qemuProcessHandleIOError(qemuMonitor *mon G_GNUC_UNUSED,
     virObjectLock(vm);
     priv = QEMU_DOMAIN_PRIVATE(vm);
 
-    if (*diskAlias == '\0')
-        diskAlias = NULL;
-
     if (diskAlias)
         disk = qemuProcessFindDomainDiskByAliasOrQOM(vm, diskAlias, NULL);
     else if (nodename)