]> git.ipfire.org Git - thirdparty/libvirt.git/commitdiff
qemu: monitor: Use qemuMonitorJSONGetReply in conjunction with virJSONValueArrayToStr...
authorPeter Krempa <pkrempa@redhat.com>
Thu, 1 Dec 2022 16:19:50 +0000 (17:19 +0100)
committerPeter Krempa <pkrempa@redhat.com>
Fri, 2 Dec 2022 15:18:37 +0000 (16:18 +0100)
In two instances (qemuMonitorJSONGetStringListProperty,
qemuMonitorJSONGetStringArray) the return value is checked by
qemuMonitorJSONCheckReply and extracted by
virJSONValueObjectGetStringArray.

We can use qemuMonitorJSONGetReply which returns it directly and then
virJSONValueArrayToStringList to convert it without the additional
lookup.

Signed-off-by: Peter Krempa <pkrempa@redhat.com>
Reviewed-by: Michal Privoznik <mprivozn@redhat.com>
src/qemu/qemu_monitor_json.c

index 1deb755130c43caafd1e58b9c225ad3207fd4b31..39f313c2afe6fa7835719947b80c73b6553fb528 100644 (file)
@@ -5522,6 +5522,7 @@ qemuMonitorJSONGetStringListProperty(qemuMonitor *mon,
 {
     g_autoptr(virJSONValue) cmd = NULL;
     g_autoptr(virJSONValue) reply = NULL;
+    virJSONValue *data;
 
     *strList = NULL;
 
@@ -5534,10 +5535,10 @@ qemuMonitorJSONGetStringListProperty(qemuMonitor *mon,
     if (qemuMonitorJSONCommand(mon, cmd, &reply) < 0)
         return -1;
 
-    if (qemuMonitorJSONCheckReply(cmd, reply, VIR_JSON_TYPE_ARRAY) < 0)
+    if (!(data = qemuMonitorJSONGetReply(cmd, reply, VIR_JSON_TYPE_ARRAY)))
         return -1;
 
-    if (!(*strList = virJSONValueObjectGetStringArray(reply, "return")))
+    if (!(*strList = virJSONValueArrayToStringList(data)))
         return -1;
 
     return 0;
@@ -6297,6 +6298,7 @@ qemuMonitorJSONGetStringArray(qemuMonitor *mon,
 {
     g_autoptr(virJSONValue) cmd = NULL;
     g_autoptr(virJSONValue) reply = NULL;
+    virJSONValue *data;
 
     *array = NULL;
 
@@ -6309,10 +6311,10 @@ qemuMonitorJSONGetStringArray(qemuMonitor *mon,
     if (qemuMonitorJSONHasError(reply, "CommandNotFound"))
         return 0;
 
-    if (qemuMonitorJSONCheckReply(cmd, reply, VIR_JSON_TYPE_ARRAY) < 0)
+    if (!(data = qemuMonitorJSONGetReply(cmd, reply, VIR_JSON_TYPE_ARRAY)))
         return -1;
 
-    if (!(*array = virJSONValueObjectGetStringArray(reply, "return")))
+    if (!(*array = virJSONValueArrayToStringList(data)))
         return -1;
 
     return 0;