qemuAgentGetDisks: Don't use virJSONValueObjectGetStringArray for optional data

The 'dependencies' field in the return data may be missing in some
cases. Historically 'virJSONValueObjectGetStringArray' didn't report
error in such case, but later refactor (commit 043b50b948 ) added
an error in order to use it in other places too.

Unfortunately this results in the error log being spammed with an
irrelevant error in case when qemuAgentGetDisks is invoked on a VM
running windows.

Replace the use of virJSONValueObjectGetStringArray by fetching the
array first and calling virJSONValueArrayToStringList only when we have
an array.

Fixes: 043b50b948
Resolves: https://bugzilla.redhat.com/show_bug.cgi?id=2149752
Signed-off-by: Peter Krempa <pkrempa@redhat.com>
Reviewed-by: Michal Privoznik <mprivozn@redhat.com>
This commit is contained in:
Peter Krempa 2022-12-01 17:02:42 +01:00
parent 6765bdeaf7
commit 3b576601df

View File

@ -2545,6 +2545,7 @@ int qemuAgentGetDisks(qemuAgent *agent,
for (i = 0; i < ndata; i++) {
virJSONValue *addr;
virJSONValue *entry = virJSONValueArrayGet(data, i);
virJSONValue *dependencies;
qemuAgentDiskInfo *disk;
if (!entry) {
@ -2570,7 +2571,11 @@ int qemuAgentGetDisks(qemuAgent *agent,
goto error;
}
disk->dependencies = virJSONValueObjectGetStringArray(entry, "dependencies");
if ((dependencies = virJSONValueObjectGetArray(entry, "dependencies"))) {
if (!(disk->dependencies = virJSONValueArrayToStringList(dependencies)))
goto error;
}
disk->alias = g_strdup(virJSONValueObjectGetString(entry, "alias"));
addr = virJSONValueObjectGetObject(entry, "address");
if (addr) {