Replace usage of the following pattern with the new helper:
if (qemuMonitorJSONCheckReply(cmd, reply, VIR_JSON_TYPE_OBJECT) < 0)
return -1;
data = virJSONValueObjectGetObject(reply, "return");
Signed-off-by: Peter Krempa <pkrempa(a)redhat.com>
---
src/qemu/qemu_monitor_json.c | 52 +++++++++---------------------------
1 file changed, 13 insertions(+), 39 deletions(-)
diff --git a/src/qemu/qemu_monitor_json.c b/src/qemu/qemu_monitor_json.c
index e6cfaaf0e9..e3fe068c1b 100644
--- a/src/qemu/qemu_monitor_json.c
+++ b/src/qemu/qemu_monitor_json.c
@@ -1481,11 +1481,9 @@ qemuMonitorJSONGetStatus(qemuMonitor *mon,
if (qemuMonitorJSONCommand(mon, cmd, &reply) < 0)
return -1;
- if (qemuMonitorJSONCheckReply(cmd, reply, VIR_JSON_TYPE_OBJECT) < 0)
+ if (!(data = qemuMonitorJSONGetReply(cmd, reply, VIR_JSON_TYPE_OBJECT)))
return -1;
- data = virJSONValueObjectGetObject(reply, "return");
-
if (virJSONValueObjectGetBoolean(data, "running", running) < 0) {
virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
_("query-status reply was missing running state"));
@@ -1866,11 +1864,9 @@ qemuMonitorJSONGetBalloonInfo(qemuMonitor *mon,
}
/* See if any other fatal error occurred */
- if (qemuMonitorJSONCheckReply(cmd, reply, VIR_JSON_TYPE_OBJECT) < 0)
+ if (!(data = qemuMonitorJSONGetReply(cmd, reply, VIR_JSON_TYPE_OBJECT)))
return -1;
- data = virJSONValueObjectGetObject(reply, "return");
-
if (virJSONValueObjectGetNumberUlong(data, "actual", &mem) < 0) {
virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
_("info balloon reply was missing balloon data"));
@@ -1964,11 +1960,9 @@ qemuMonitorJSONGetMemoryStats(qemuMonitor *mon,
}
}
- if (qemuMonitorJSONCheckReply(cmd, reply, VIR_JSON_TYPE_OBJECT) < 0)
+ if (!(data = qemuMonitorJSONGetReply(cmd, reply, VIR_JSON_TYPE_OBJECT)))
return got;
- data = virJSONValueObjectGetObject(reply, "return");
-
if (!(statsdata = virJSONValueObjectGet(data, "stats"))) {
VIR_DEBUG("data does not include 'stats'");
return got;
@@ -3165,11 +3159,9 @@ qemuMonitorJSONGetMigrationBlockers(qemuMonitor *mon,
if (qemuMonitorJSONCommand(mon, cmd, &reply) < 0)
return -1;
- if (qemuMonitorJSONCheckReply(cmd, reply, VIR_JSON_TYPE_OBJECT) < 0)
+ if (!(data = qemuMonitorJSONGetReply(cmd, reply, VIR_JSON_TYPE_OBJECT)))
return -1;
- data = virJSONValueObjectGetObject(reply, "return");
-
if (!(jblockers = virJSONValueObjectGetArray(data, "blocked-reasons")))
return 0;
@@ -3244,11 +3236,9 @@ qemuMonitorJSONQueryDump(qemuMonitor *mon,
if (qemuMonitorJSONCommand(mon, cmd, &reply) < 0)
return -1;
- if (qemuMonitorJSONCheckReply(cmd, reply, VIR_JSON_TYPE_OBJECT) < 0)
+ if (!(result = qemuMonitorJSONGetReply(cmd, reply, VIR_JSON_TYPE_OBJECT)))
return -1;
- result = virJSONValueObjectGetObject(reply, "return");
-
return qemuMonitorJSONExtractDumpStats(result, stats);
}
@@ -3270,11 +3260,9 @@ qemuMonitorJSONGetDumpGuestMemoryCapability(qemuMonitor *mon,
if (qemuMonitorJSONCommand(mon, cmd, &reply) < 0)
return -1;
- if (qemuMonitorJSONCheckReply(cmd, reply, VIR_JSON_TYPE_OBJECT) < 0)
+ if (!(caps = qemuMonitorJSONGetReply(cmd, reply, VIR_JSON_TYPE_OBJECT)))
return -1;
- caps = virJSONValueObjectGetObject(reply, "return");
-
if (!(formats = virJSONValueObjectGetArray(caps, "formats"))) {
virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
_("missing supported dump formats"));
@@ -4656,11 +4644,9 @@ int qemuMonitorJSONGetVersion(qemuMonitor *mon,
if (qemuMonitorJSONCommand(mon, cmd, &reply) < 0)
return -1;
- if (qemuMonitorJSONCheckReply(cmd, reply, VIR_JSON_TYPE_OBJECT) < 0)
+ if (!(data = qemuMonitorJSONGetReply(cmd, reply, VIR_JSON_TYPE_OBJECT)))
return -1;
- data = virJSONValueObjectGetObject(reply, "return");
-
if (!(qemu = virJSONValueObjectGetObject(data, "qemu"))) {
virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
_("query-version reply was missing 'qemu'
data"));
@@ -5155,11 +5141,9 @@ qemuMonitorJSONGetCPUModelBaseline(qemuMonitor *mon,
if (qemuMonitorJSONCommand(mon, cmd, &reply) < 0)
return -1;
- if (qemuMonitorJSONCheckReply(cmd, reply, VIR_JSON_TYPE_OBJECT) < 0)
+ if (!(data = qemuMonitorJSONGetReply(cmd, reply, VIR_JSON_TYPE_OBJECT)))
return -1;
- data = virJSONValueObjectGetObject(reply, "return");
-
if (qemuMonitorJSONParseCPUModelData(data, "query-cpu-model-baseline",
false, &cpu_model, &cpu_props,
&cpu_name) < 0)
@@ -5322,11 +5306,9 @@ int qemuMonitorJSONGetKVMState(qemuMonitor *mon,
if (qemuMonitorJSONCommand(mon, cmd, &reply) < 0)
return -1;
- if (qemuMonitorJSONCheckReply(cmd, reply, VIR_JSON_TYPE_OBJECT) < 0)
+ if (!(data = qemuMonitorJSONGetReply(cmd, reply, VIR_JSON_TYPE_OBJECT)))
return -1;
- data = virJSONValueObjectGetObject(reply, "return");
-
if (virJSONValueObjectGetBoolean(data, "enabled", enabled) < 0 ||
virJSONValueObjectGetBoolean(data, "present", present) < 0) {
virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
@@ -5761,11 +5743,9 @@ qemuMonitorJSONGetTargetArch(qemuMonitor *mon)
if (qemuMonitorJSONCommand(mon, cmd, &reply) < 0)
return NULL;
- if (qemuMonitorJSONCheckReply(cmd, reply, VIR_JSON_TYPE_OBJECT) < 0)
+ if (!(data = qemuMonitorJSONGetReply(cmd, reply, VIR_JSON_TYPE_OBJECT)))
return NULL;
- data = virJSONValueObjectGetObject(reply, "return");
-
if (!(arch = virJSONValueObjectGetString(data, "arch"))) {
virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
_("query-target reply was missing arch data"));
@@ -7521,11 +7501,9 @@ qemuMonitorJSONGetRTCTime(qemuMonitor *mon,
if (qemuMonitorJSONCommand(mon, cmd, &reply) < 0)
return -1;
- if (qemuMonitorJSONCheckReply(cmd, reply, VIR_JSON_TYPE_OBJECT) < 0)
+ if (!(data = qemuMonitorJSONGetReply(cmd, reply, VIR_JSON_TYPE_OBJECT)))
return -1;
- data = virJSONValueObjectGet(reply, "return");
-
if (virJSONValueObjectGetNumberInt(data, "tm_year", &tm->tm_year)
< 0 ||
virJSONValueObjectGetNumberInt(data, "tm_mon", &tm->tm_mon) <
0 ||
virJSONValueObjectGetNumberInt(data, "tm_mday", &tm->tm_mday)
< 0 ||
@@ -7973,11 +7951,9 @@ qemuMonitorJSONGetSEVMeasurement(qemuMonitor *mon)
if (qemuMonitorJSONCommand(mon, cmd, &reply) < 0)
return NULL;
- if (qemuMonitorJSONCheckReply(cmd, reply, VIR_JSON_TYPE_OBJECT) < 0)
+ if (!(data = qemuMonitorJSONGetReply(cmd, reply, VIR_JSON_TYPE_OBJECT)))
return NULL;
- data = virJSONValueObjectGetObject(reply, "return");
-
if (!(tmp = virJSONValueObjectGetString(data, "data")))
return NULL;
@@ -8016,11 +7992,9 @@ qemuMonitorJSONGetSEVInfo(qemuMonitor *mon,
if (qemuMonitorJSONCommand(mon, cmd, &reply) < 0)
return -1;
- if (qemuMonitorJSONCheckReply(cmd, reply, VIR_JSON_TYPE_OBJECT) < 0)
+ if (!(data = qemuMonitorJSONGetReply(cmd, reply, VIR_JSON_TYPE_OBJECT)))
return -1;
- data = virJSONValueObjectGetObject(reply, "return");
-
if (virJSONValueObjectGetNumberUint(data, "api-major", apiMajor) < 0 ||
virJSONValueObjectGetNumberUint(data, "api-minor", apiMinor) < 0 ||
virJSONValueObjectGetNumberUint(data, "build-id", buildID) < 0 ||
--
2.38.1