From: Peter Krempa Date: Thu, 1 Dec 2022 15:43:18 +0000 (+0100) Subject: qemu: monitor: Use qemuMonitorJSONGetReply when the value is extracted directly X-Git-Tag: v9.0.0-rc1~250 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=80f1b8a5b0059ce28391b2ec7e872e9247729c80;p=thirdparty%2Flibvirt.git qemu: monitor: Use qemuMonitorJSONGetReply when the value is extracted directly Use qemuMonitorJSONGetReply in cases where qemuMonitorJSONCheckReply is followed by virJSONValueObjectGet*(reply, "return"). Signed-off-by: Peter Krempa Reviewed-by: Michal Privoznik --- diff --git a/src/qemu/qemu_monitor_json.c b/src/qemu/qemu_monitor_json.c index 79729e0a9a..47df4a5160 100644 --- a/src/qemu/qemu_monitor_json.c +++ b/src/qemu/qemu_monitor_json.c @@ -5267,6 +5267,7 @@ qemuMonitorJSONGetCommandLineOptions(qemuMonitor *mon) g_autoptr(GHashTable) ret = virHashNew(virJSONValueHashFree); g_autoptr(virJSONValue) cmd = NULL; g_autoptr(virJSONValue) reply = NULL; + virJSONValue *data; if (!(cmd = qemuMonitorJSONMakeCommand("query-command-line-options", NULL))) return NULL; @@ -5274,10 +5275,10 @@ qemuMonitorJSONGetCommandLineOptions(qemuMonitor *mon) if (qemuMonitorJSONCommand(mon, cmd, &reply) < 0) return NULL; - if (qemuMonitorJSONCheckReply(cmd, reply, VIR_JSON_TYPE_ARRAY) < 0) + if (!(data = qemuMonitorJSONGetReply(cmd, reply, VIR_JSON_TYPE_ARRAY))) return NULL; - if (virJSONValueArrayForeachSteal(virJSONValueObjectGetArray(reply, "return"), + if (virJSONValueArrayForeachSteal(data, qemuMonitorJSONGetCommandLineOptionsWorker, ret) < 0) return NULL; @@ -5673,6 +5674,7 @@ qemuMonitorJSONGetDeviceProps(qemuMonitor *mon, g_autoptr(GHashTable) props = virHashNew(virJSONValueHashFree); g_autoptr(virJSONValue) cmd = NULL; g_autoptr(virJSONValue) reply = NULL; + virJSONValue *data; if (!(cmd = qemuMonitorJSONMakeCommand("device-list-properties", "s:typename", device, @@ -5686,10 +5688,10 @@ qemuMonitorJSONGetDeviceProps(qemuMonitor *mon, if (qemuMonitorJSONHasError(reply, "DeviceNotFound")) return g_steal_pointer(&props); - if (qemuMonitorJSONCheckReply(cmd, reply, VIR_JSON_TYPE_ARRAY) < 0) + if (!(data = qemuMonitorJSONGetReply(cmd, reply, VIR_JSON_TYPE_ARRAY))) return NULL; - if (virJSONValueArrayForeachSteal(virJSONValueObjectGetArray(reply, "return"), + if (virJSONValueArrayForeachSteal(data, qemuMonitorJSONGetDevicePropsWorker, props) < 0) return NULL; @@ -8381,6 +8383,7 @@ qemuMonitorJSONGetCPUMigratable(qemuMonitor *mon, { g_autoptr(virJSONValue) cmd = NULL; g_autoptr(virJSONValue) reply = NULL; + virJSONValue *data; if (!(cmd = qemuMonitorJSONMakeCommand("qom-get", "s:path", cpuQOMPath, @@ -8394,11 +8397,10 @@ qemuMonitorJSONGetCPUMigratable(qemuMonitor *mon, if (qemuMonitorJSONHasError(reply, "GenericError")) return 1; - if (qemuMonitorJSONCheckReply(cmd, reply, VIR_JSON_TYPE_BOOLEAN) < 0) + if (!(data = qemuMonitorJSONGetReply(cmd, reply, VIR_JSON_TYPE_BOOLEAN))) return -1; - return virJSONValueGetBoolean(virJSONValueObjectGet(reply, "return"), - migratable); + return virJSONValueGetBoolean(data, migratable); }