render / rpms / libvirt

Forked from rpms/libvirt 7 months ago
Clone
2cf05b
From 1ad707f19e570b76c1f6517194d9cc86b084014d Mon Sep 17 00:00:00 2001
2cf05b
Message-Id: <1ad707f19e570b76c1f6517194d9cc86b084014d@dist-git>
2cf05b
From: Peter Krempa <pkrempa@redhat.com>
2cf05b
Date: Thu, 1 Dec 2022 17:02:42 +0100
2cf05b
Subject: [PATCH] qemuAgentGetDisks: Don't use virJSONValueObjectGetStringArray
2cf05b
 for optional data
2cf05b
2cf05b
The 'dependencies' field in the return data may be missing in some
2cf05b
cases. Historically 'virJSONValueObjectGetStringArray' didn't report
2cf05b
error in such case, but later refactor (commit 043b50b948ef3c2 ) added
2cf05b
an error in order to use it in other places too.
2cf05b
2cf05b
Unfortunately this results in the error log being spammed with an
2cf05b
irrelevant error in case when qemuAgentGetDisks is invoked on a VM
2cf05b
running windows.
2cf05b
2cf05b
Replace the use of virJSONValueObjectGetStringArray by fetching the
2cf05b
array first and calling virJSONValueArrayToStringList only when we have
2cf05b
an array.
2cf05b
2cf05b
Fixes: 043b50b948ef3c2a4adf5fa32a93ec2589851ac6
2cf05b
Resolves: https://bugzilla.redhat.com/show_bug.cgi?id=2149752
2cf05b
Signed-off-by: Peter Krempa <pkrempa@redhat.com>
2cf05b
Reviewed-by: Michal Privoznik <mprivozn@redhat.com>
2cf05b
(cherry picked from commit 3b576601dfb924bb518870a01de5d1a421cbb467)
2cf05b
---
2cf05b
 src/qemu/qemu_agent.c | 7 ++++++-
2cf05b
 1 file changed, 6 insertions(+), 1 deletion(-)
2cf05b
2cf05b
diff --git a/src/qemu/qemu_agent.c b/src/qemu/qemu_agent.c
2cf05b
index f33cd47078..8a55044c9e 100644
2cf05b
--- a/src/qemu/qemu_agent.c
2cf05b
+++ b/src/qemu/qemu_agent.c
2cf05b
@@ -2550,6 +2550,7 @@ int qemuAgentGetDisks(qemuAgent *agent,
2cf05b
     for (i = 0; i < ndata; i++) {
2cf05b
         virJSONValue *addr;
2cf05b
         virJSONValue *entry = virJSONValueArrayGet(data, i);
2cf05b
+        virJSONValue *dependencies;
2cf05b
         qemuAgentDiskInfo *disk;
2cf05b
 
2cf05b
         if (!entry) {
2cf05b
@@ -2575,7 +2576,11 @@ int qemuAgentGetDisks(qemuAgent *agent,
2cf05b
             goto error;
2cf05b
         }
2cf05b
 
2cf05b
-        disk->dependencies = virJSONValueObjectGetStringArray(entry, "dependencies");
2cf05b
+        if ((dependencies = virJSONValueObjectGetArray(entry, "dependencies"))) {
2cf05b
+            if (!(disk->dependencies = virJSONValueArrayToStringList(dependencies)))
2cf05b
+                goto error;
2cf05b
+        }
2cf05b
+
2cf05b
         disk->alias = g_strdup(virJSONValueObjectGetString(entry, "alias"));
2cf05b
         addr = virJSONValueObjectGetObject(entry, "address");
2cf05b
         if (addr) {
2cf05b
-- 
2cf05b
2.39.0
2cf05b