1
0

qemu_monitor_json: Don't check existence of "return" object

Whenever qemuMonitorJSONCheckError returns 0, the "return" object is
guaranteed to exist. Thus virJSONValueObjectGetObject will never fail to
get it. On the other hand, virJSONValueObjectGetArray may fail since the
"return" object may not be an array.

Signed-off-by: Jiri Denemark <jdenemar@redhat.com>
This commit is contained in:
Jiri Denemark 2016-11-21 00:10:06 +01:00
parent 0a3f919972
commit 2e0d6cdec4

View File

@ -1219,11 +1219,7 @@ qemuMonitorJSONGetStatus(qemuMonitorPtr mon,
if (qemuMonitorJSONCheckError(cmd, reply) < 0) if (qemuMonitorJSONCheckError(cmd, reply) < 0)
goto cleanup; goto cleanup;
if (!(data = virJSONValueObjectGetObject(reply, "return"))) { data = virJSONValueObjectGetObject(reply, "return");
virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
_("query-status reply was missing return data"));
goto cleanup;
}
if (virJSONValueObjectGetBoolean(data, "running", running) < 0) { if (virJSONValueObjectGetBoolean(data, "running", running) < 0) {
virReportError(VIR_ERR_INTERNAL_ERROR, "%s", virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
@ -1443,12 +1439,7 @@ int qemuMonitorJSONGetVirtType(qemuMonitorPtr mon,
if (qemuMonitorJSONCheckError(cmd, reply) < 0) if (qemuMonitorJSONCheckError(cmd, reply) < 0)
goto cleanup; goto cleanup;
data = virJSONValueObjectGetObject(reply, "return");
if (!(data = virJSONValueObjectGetObject(reply, "return"))) {
virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
_("info kvm reply was missing return data"));
goto cleanup;
}
if (virJSONValueObjectGetBoolean(data, "enabled", &val) < 0) { if (virJSONValueObjectGetBoolean(data, "enabled", &val) < 0) {
virReportError(VIR_ERR_INTERNAL_ERROR, "%s", virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
@ -1609,12 +1600,7 @@ qemuMonitorJSONGetBalloonInfo(qemuMonitorPtr mon,
if (qemuMonitorJSONCheckError(cmd, reply) < 0) if (qemuMonitorJSONCheckError(cmd, reply) < 0)
goto cleanup; goto cleanup;
/* Success */ data = virJSONValueObjectGetObject(reply, "return");
if (!(data = virJSONValueObjectGetObject(reply, "return"))) {
virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
_("info balloon reply was missing return data"));
goto cleanup;
}
if (virJSONValueObjectGetNumberUlong(data, "actual", &mem) < 0) { if (virJSONValueObjectGetNumberUlong(data, "actual", &mem) < 0) {
virReportError(VIR_ERR_INTERNAL_ERROR, "%s", virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
@ -1715,11 +1701,7 @@ int qemuMonitorJSONGetMemoryStats(qemuMonitorPtr mon,
if (qemuMonitorJSONCheckError(cmd, reply) < 0) if (qemuMonitorJSONCheckError(cmd, reply) < 0)
goto cleanup; goto cleanup;
if (!(data = virJSONValueObjectGetObject(reply, "return"))) { data = virJSONValueObjectGetObject(reply, "return");
virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
_("qom-get reply was missing return data"));
goto cleanup;
}
if (!(statsdata = virJSONValueObjectGet(data, "stats"))) { if (!(statsdata = virJSONValueObjectGet(data, "stats"))) {
VIR_DEBUG("data does not include 'stats'"); VIR_DEBUG("data does not include 'stats'");
@ -2679,11 +2661,7 @@ qemuMonitorJSONGetMigrationStatsReply(virJSONValuePtr reply,
int rc; int rc;
double mbps; double mbps;
if (!(ret = virJSONValueObjectGetObject(reply, "return"))) { ret = virJSONValueObjectGetObject(reply, "return");
virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
_("info migration reply was missing return data"));
return -1;
}
if (!(statusstr = virJSONValueObjectGetString(ret, "status"))) { if (!(statusstr = virJSONValueObjectGetString(ret, "status"))) {
virReportError(VIR_ERR_INTERNAL_ERROR, "%s", virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
@ -2976,11 +2954,7 @@ qemuMonitorJSONGetDumpGuestMemoryCapability(qemuMonitorPtr mon,
if (qemuMonitorJSONCheckError(cmd, reply) < 0) if (qemuMonitorJSONCheckError(cmd, reply) < 0)
goto cleanup; goto cleanup;
if (!(caps = virJSONValueObjectGetObject(reply, "return"))) { caps = virJSONValueObjectGetObject(reply, "return");
virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
_("missing dump guest memory capabilities"));
goto cleanup;
}
if (!(formats = virJSONValueObjectGetArray(caps, "formats"))) { if (!(formats = virJSONValueObjectGetArray(caps, "formats"))) {
virReportError(VIR_ERR_INTERNAL_ERROR, "%s", virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
@ -3160,11 +3134,6 @@ qemuMonitorJSONAddFd(qemuMonitorPtr mon, int fdset, int fd, const char *name)
if (ret == 0) { if (ret == 0) {
virJSONValuePtr data = virJSONValueObjectGetObject(reply, "return"); virJSONValuePtr data = virJSONValueObjectGetObject(reply, "return");
if (!data) {
virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
_("missing return information"));
goto error;
}
if (virJSONValueObjectGetNumberInt(data, "fd", &ret) < 0) { if (virJSONValueObjectGetNumberInt(data, "fd", &ret) < 0) {
virReportError(VIR_ERR_INTERNAL_ERROR, "%s", virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
_("incomplete return information")); _("incomplete return information"));
@ -4745,11 +4714,7 @@ int qemuMonitorJSONGetVersion(qemuMonitorPtr mon,
if (qemuMonitorJSONCheckError(cmd, reply) < 0) if (qemuMonitorJSONCheckError(cmd, reply) < 0)
goto cleanup; goto cleanup;
if (!(data = virJSONValueObjectGetObject(reply, "return"))) { data = virJSONValueObjectGetObject(reply, "return");
virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
_("query-version reply was missing 'return' data"));
goto cleanup;
}
if (!(qemu = virJSONValueObjectGetObject(data, "qemu"))) { if (!(qemu = virJSONValueObjectGetObject(data, "qemu"))) {
virReportError(VIR_ERR_INTERNAL_ERROR, "%s", virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
@ -4815,13 +4780,8 @@ int qemuMonitorJSONGetMachines(qemuMonitorPtr mon,
if (qemuMonitorJSONCheckError(cmd, reply) < 0) if (qemuMonitorJSONCheckError(cmd, reply) < 0)
goto cleanup; goto cleanup;
if (!(data = virJSONValueObjectGetArray(reply, "return"))) { if (!(data = virJSONValueObjectGetArray(reply, "return")) ||
virReportError(VIR_ERR_INTERNAL_ERROR, "%s", (n = virJSONValueArraySize(data)) < 0) {
_("query-machines reply was missing return data"));
goto cleanup;
}
if ((n = virJSONValueArraySize(data)) < 0) {
virReportError(VIR_ERR_INTERNAL_ERROR, "%s", virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
_("query-machines reply data was not an array")); _("query-machines reply data was not an array"));
goto cleanup; goto cleanup;
@ -4925,13 +4885,8 @@ qemuMonitorJSONGetCPUDefinitions(qemuMonitorPtr mon,
if (qemuMonitorJSONCheckError(cmd, reply) < 0) if (qemuMonitorJSONCheckError(cmd, reply) < 0)
goto cleanup; goto cleanup;
if (!(data = virJSONValueObjectGetArray(reply, "return"))) { if (!(data = virJSONValueObjectGetArray(reply, "return")) ||
virReportError(VIR_ERR_INTERNAL_ERROR, "%s", (n = virJSONValueArraySize(data)) < 0) {
_("query-cpu-definitions reply was missing return data"));
goto cleanup;
}
if ((n = virJSONValueArraySize(data)) < 0) {
virReportError(VIR_ERR_INTERNAL_ERROR, "%s", virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
_("query-cpu-definitions reply data was not an array")); _("query-cpu-definitions reply data was not an array"));
goto cleanup; goto cleanup;
@ -4998,13 +4953,8 @@ int qemuMonitorJSONGetCommands(qemuMonitorPtr mon,
if (qemuMonitorJSONCheckError(cmd, reply) < 0) if (qemuMonitorJSONCheckError(cmd, reply) < 0)
goto cleanup; goto cleanup;
if (!(data = virJSONValueObjectGetArray(reply, "return"))) { if (!(data = virJSONValueObjectGetArray(reply, "return")) ||
virReportError(VIR_ERR_INTERNAL_ERROR, "%s", (n = virJSONValueArraySize(data)) < 0) {
_("query-commands reply was missing return data"));
goto cleanup;
}
if ((n = virJSONValueArraySize(data)) < 0) {
virReportError(VIR_ERR_INTERNAL_ERROR, "%s", virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
_("query-commands reply data was not an array")); _("query-commands reply data was not an array"));
goto cleanup; goto cleanup;
@ -5068,13 +5018,8 @@ int qemuMonitorJSONGetEvents(qemuMonitorPtr mon,
if (qemuMonitorJSONCheckError(cmd, reply) < 0) if (qemuMonitorJSONCheckError(cmd, reply) < 0)
goto cleanup; goto cleanup;
if (!(data = virJSONValueObjectGetArray(reply, "return"))) { if (!(data = virJSONValueObjectGetArray(reply, "return")) ||
virReportError(VIR_ERR_INTERNAL_ERROR, "%s", (n = virJSONValueArraySize(data)) < 0) {
_("query-events reply was missing return data"));
goto cleanup;
}
if ((n = virJSONValueArraySize(data)) < 0) {
virReportError(VIR_ERR_INTERNAL_ERROR, "%s", virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
_("query-events reply data was not an array")); _("query-events reply data was not an array"));
goto cleanup; goto cleanup;
@ -5258,11 +5203,7 @@ int qemuMonitorJSONGetKVMState(qemuMonitorPtr mon,
if (qemuMonitorJSONCheckError(cmd, reply) < 0) if (qemuMonitorJSONCheckError(cmd, reply) < 0)
goto cleanup; goto cleanup;
if (!(data = virJSONValueObjectGetObject(reply, "return"))) { data = virJSONValueObjectGetObject(reply, "return");
virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
_("query-kvm reply was missing return data"));
goto cleanup;
}
if (virJSONValueObjectGetBoolean(data, "enabled", enabled) < 0 || if (virJSONValueObjectGetBoolean(data, "enabled", enabled) < 0 ||
virJSONValueObjectGetBoolean(data, "present", present) < 0) { virJSONValueObjectGetBoolean(data, "present", present) < 0) {
@ -5302,13 +5243,8 @@ int qemuMonitorJSONGetObjectTypes(qemuMonitorPtr mon,
if (qemuMonitorJSONCheckError(cmd, reply) < 0) if (qemuMonitorJSONCheckError(cmd, reply) < 0)
goto cleanup; goto cleanup;
if (!(data = virJSONValueObjectGetArray(reply, "return"))) { if (!(data = virJSONValueObjectGetArray(reply, "return")) ||
virReportError(VIR_ERR_INTERNAL_ERROR, "%s", (n = virJSONValueArraySize(data)) < 0) {
_("qom-list-types reply was missing return data"));
goto cleanup;
}
if ((n = virJSONValueArraySize(data)) < 0) {
virReportError(VIR_ERR_INTERNAL_ERROR, "%s", virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
_("qom-list-types reply data was not an array")); _("qom-list-types reply data was not an array"));
goto cleanup; goto cleanup;
@ -5369,13 +5305,8 @@ int qemuMonitorJSONGetObjectListPaths(qemuMonitorPtr mon,
if (qemuMonitorJSONCheckError(cmd, reply) < 0) if (qemuMonitorJSONCheckError(cmd, reply) < 0)
goto cleanup; goto cleanup;
if (!(data = virJSONValueObjectGetArray(reply, "return"))) { if (!(data = virJSONValueObjectGetArray(reply, "return")) ||
virReportError(VIR_ERR_INTERNAL_ERROR, "%s", (n = virJSONValueArraySize(data)) < 0) {
_("qom-list reply was missing return data"));
goto cleanup;
}
if ((n = virJSONValueArraySize(data)) < 0) {
virReportError(VIR_ERR_INTERNAL_ERROR, "%s", virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
_("qom-list reply data was not an array")); _("qom-list reply data was not an array"));
goto cleanup; goto cleanup;
@ -5613,13 +5544,8 @@ int qemuMonitorJSONGetObjectProps(qemuMonitorPtr mon,
if (qemuMonitorJSONCheckError(cmd, reply) < 0) if (qemuMonitorJSONCheckError(cmd, reply) < 0)
goto cleanup; goto cleanup;
if (!(data = virJSONValueObjectGetArray(reply, "return"))) { if (!(data = virJSONValueObjectGetArray(reply, "return")) ||
virReportError(VIR_ERR_INTERNAL_ERROR, "%s", (n = virJSONValueArraySize(data)) < 0) {
_("device-list-properties reply was missing return data"));
goto cleanup;
}
if ((n = virJSONValueArraySize(data)) < 0) {
virReportError(VIR_ERR_INTERNAL_ERROR, "%s", virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
_("device-list-properties reply data was not an array")); _("device-list-properties reply data was not an array"));
goto cleanup; goto cleanup;
@ -5673,11 +5599,7 @@ qemuMonitorJSONGetTargetArch(qemuMonitorPtr mon)
if (qemuMonitorJSONCheckError(cmd, reply) < 0) if (qemuMonitorJSONCheckError(cmd, reply) < 0)
goto cleanup; goto cleanup;
if (!(data = virJSONValueObjectGetObject(reply, "return"))) { data = virJSONValueObjectGetObject(reply, "return");
virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
_("query-target reply was missing return data"));
goto cleanup;
}
if (!(arch = virJSONValueObjectGetString(data, "arch"))) { if (!(arch = virJSONValueObjectGetString(data, "arch"))) {
virReportError(VIR_ERR_INTERNAL_ERROR, "%s", virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
@ -6110,14 +6032,8 @@ qemuMonitorJSONGetStringArray(qemuMonitorPtr mon, const char *qmpCmd,
if (qemuMonitorJSONCheckError(cmd, reply) < 0) if (qemuMonitorJSONCheckError(cmd, reply) < 0)
goto cleanup; goto cleanup;
if (!(data = virJSONValueObjectGetArray(reply, "return"))) { if (!(data = virJSONValueObjectGetArray(reply, "return")) ||
virReportError(VIR_ERR_INTERNAL_ERROR, (n = virJSONValueArraySize(data)) < 0) {
_("%s reply was missing return data"),
qmpCmd);
goto cleanup;
}
if ((n = virJSONValueArraySize(data)) < 0) {
virReportError(VIR_ERR_INTERNAL_ERROR, virReportError(VIR_ERR_INTERNAL_ERROR,
_("%s reply data was not an array"), _("%s reply data was not an array"),
qmpCmd); qmpCmd);
@ -6329,15 +6245,9 @@ qemuMonitorJSONAttachCharDev(qemuMonitorPtr mon,
goto cleanup; goto cleanup;
if (chr->type == VIR_DOMAIN_CHR_TYPE_PTY) { if (chr->type == VIR_DOMAIN_CHR_TYPE_PTY) {
virJSONValuePtr data; virJSONValuePtr data = virJSONValueObjectGetObject(reply, "return");
const char *path; const char *path;
if (!(data = virJSONValueObjectGetObject(reply, "return"))) {
virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
_("chardev-add reply was missing return data"));
goto cleanup;
}
if (!(path = virJSONValueObjectGetString(data, "pty"))) { if (!(path = virJSONValueObjectGetString(data, "pty"))) {
virReportError(VIR_ERR_INTERNAL_ERROR, "%s", virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
_("chardev-add reply was missing pty path")); _("chardev-add reply was missing pty path"));
@ -6686,13 +6596,8 @@ qemuMonitorJSONGetIOThreads(qemuMonitorPtr mon,
if (qemuMonitorJSONCheckError(cmd, reply) < 0) if (qemuMonitorJSONCheckError(cmd, reply) < 0)
goto cleanup; goto cleanup;
if (!(data = virJSONValueObjectGetArray(reply, "return"))) { if (!(data = virJSONValueObjectGetArray(reply, "return")) ||
virReportError(VIR_ERR_INTERNAL_ERROR, "%s", (n = virJSONValueArraySize(data)) < 0) {
_("query-iothreads reply was missing return data"));
goto cleanup;
}
if ((n = virJSONValueArraySize(data)) < 0) {
virReportError(VIR_ERR_INTERNAL_ERROR, "%s", virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
_("query-iothreads reply data was not an array")); _("query-iothreads reply data was not an array"));
goto cleanup; goto cleanup;
@ -6780,13 +6685,8 @@ qemuMonitorJSONGetMemoryDeviceInfo(qemuMonitorPtr mon,
if (qemuMonitorJSONCheckError(cmd, reply) < 0) if (qemuMonitorJSONCheckError(cmd, reply) < 0)
goto cleanup; goto cleanup;
if (!(data = virJSONValueObjectGetArray(reply, "return"))) { if (!(data = virJSONValueObjectGetArray(reply, "return")) ||
virReportError(VIR_ERR_INTERNAL_ERROR, "%s", (n = virJSONValueArraySize(data)) < 0) {
_("query-memory-devices reply was missing return data"));
goto cleanup;
}
if ((n = virJSONValueArraySize(data)) < 0) {
virReportError(VIR_ERR_INTERNAL_ERROR, "%s", virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
_("query-memory-devices reply data was not an array")); _("query-memory-devices reply data was not an array"));
goto cleanup; goto cleanup;