render / rpms / libvirt

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