qemu: Handle quirks of 'device' field of BLOCK_IO_ERROR event in monitor code

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>
This commit is contained in:
Peter Krempa 2025-01-27 13:03:58 +01:00
parent 22e90a3b17
commit 2f8359f827
2 changed files with 8 additions and 4 deletions

View 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");

View 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)