}
+static int
+qemuMonitorJSONCheckReply(virJSONValuePtr cmd,
+ virJSONValuePtr reply,
+ virJSONType type)
+{
+ virJSONValuePtr data;
+
+ if (qemuMonitorJSONCheckError(cmd, reply) < 0)
+ return -1;
+
+ data = virJSONValueObjectGet(reply, "return");
+ if (virJSONValueGetType(data) != type) {
+ char *cmdstr = virJSONValueToString(cmd, false);
+ char *retstr = virJSONValueToString(data, false);
+
+ VIR_DEBUG("Unexpected return type %d (expecting %d) for command %s: %s",
+ virJSONValueGetType(data), type, cmdstr, retstr);
+ virReportError(VIR_ERR_INTERNAL_ERROR,
+ _("unexpected type returned by QEMU command '%s'"),
+ qemuMonitorJSONCommandName(cmd));
+
+ VIR_FREE(cmdstr);
+ VIR_FREE(retstr);
+ return -1;
+ }
+
+ return 0;
+}
+
+
static bool
qemuMonitorJSONErrorIsClass(virJSONValuePtr error,
const char *klass)
if (qemuMonitorJSONCommand(mon, cmd, &reply) < 0)
goto cleanup;
- if (qemuMonitorJSONCheckError(cmd, reply) < 0)
+ if (qemuMonitorJSONCheckReply(cmd, reply, VIR_JSON_TYPE_OBJECT) < 0)
goto cleanup;
data = virJSONValueObjectGetObject(reply, "return");
if (qemuMonitorJSONCommand(mon, cmd, &reply) < 0)
goto cleanup;
- if (qemuMonitorJSONCheckError(cmd, reply) < 0)
+ if (qemuMonitorJSONCheckReply(cmd, reply, VIR_JSON_TYPE_OBJECT) < 0)
goto cleanup;
data = virJSONValueObjectGetObject(reply, "return");
}
/* See if any other fatal error occurred */
- if (qemuMonitorJSONCheckError(cmd, reply) < 0)
+ if (qemuMonitorJSONCheckReply(cmd, reply, VIR_JSON_TYPE_OBJECT) < 0)
goto cleanup;
data = virJSONValueObjectGetObject(reply, "return");
}
}
- if (qemuMonitorJSONCheckError(cmd, reply) < 0)
+ if (qemuMonitorJSONCheckReply(cmd, reply, VIR_JSON_TYPE_OBJECT) < 0)
goto cleanup;
data = virJSONValueObjectGetObject(reply, "return");
return NULL;
if (qemuMonitorJSONCommand(mon, cmd, &reply) < 0 ||
- qemuMonitorJSONCheckError(cmd, reply) < 0)
+ qemuMonitorJSONCheckReply(cmd, reply, VIR_JSON_TYPE_ARRAY) < 0)
goto cleanup;
- if (!(devices = virJSONValueObjectStealArray(reply, "return"))) {
- virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
- _("query-block reply was missing device list"));
- goto cleanup;
- }
+ devices = virJSONValueObjectStealArray(reply, "return");
cleanup:
virJSONValueFree(cmd);
if (qemuMonitorJSONCommand(mon, cmd, &reply) < 0)
goto cleanup;
- if (qemuMonitorJSONCheckError(cmd, reply) < 0)
+ if (qemuMonitorJSONCheckReply(cmd, reply, VIR_JSON_TYPE_ARRAY) < 0)
goto cleanup;
- if (!(ret = virJSONValueObjectStealArray(reply, "return"))) {
- virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
- _("query-blockstats reply was missing device list"));
- goto cleanup;
- }
+ ret = virJSONValueObjectStealArray(reply, "return");
cleanup:
virJSONValueFree(cmd);
if (qemuMonitorJSONCommand(mon, cmd, &reply) < 0)
goto cleanup;
- if (qemuMonitorJSONCheckError(cmd, reply) < 0)
+ if (qemuMonitorJSONCheckReply(cmd, reply, VIR_JSON_TYPE_NUMBER) < 0)
goto cleanup;
if (virJSONValueObjectGetNumberUlong(reply, "return", cacheSize) < 0) {
virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
- _("query-migrate-cache-size reply was missing "
- "'return' data"));
+ _("invalid cache size in query-migrate-cache-size reply"));
goto cleanup;
}
goto cleanup;
}
- if (qemuMonitorJSONCheckError(cmd, reply) < 0)
+ if (qemuMonitorJSONCheckReply(cmd, reply, VIR_JSON_TYPE_OBJECT) < 0)
goto cleanup;
result = virJSONValueObjectGet(reply, "return");
if (qemuMonitorJSONCommand(mon, cmd, &reply) < 0)
goto cleanup;
- if (qemuMonitorJSONCheckError(cmd, reply) < 0)
+ if (qemuMonitorJSONCheckReply(cmd, reply, VIR_JSON_TYPE_OBJECT) < 0)
goto cleanup;
if (qemuMonitorJSONGetMigrationStatsReply(reply, stats, error) < 0)
if (qemuMonitorJSONCommand(mon, cmd, &reply) < 0)
goto cleanup;
- if (qemuMonitorJSONCheckError(cmd, reply) < 0)
+ if (qemuMonitorJSONCheckReply(cmd, reply, VIR_JSON_TYPE_OBJECT) < 0)
goto cleanup;
result = virJSONValueObjectGetObject(reply, "return");
goto cleanup;
}
- if (qemuMonitorJSONCheckError(cmd, reply) < 0)
+ if (qemuMonitorJSONCheckReply(cmd, reply, VIR_JSON_TYPE_OBJECT) < 0)
goto cleanup;
caps = virJSONValueObjectGetObject(reply, "return");
ret = -2;
goto cleanup;
}
- ret = qemuMonitorJSONCheckError(cmd, reply);
+ ret = qemuMonitorJSONCheckReply(cmd, reply, VIR_JSON_TYPE_OBJECT);
}
if (ret == 0) {
virJSONValuePtr data = virJSONValueObjectGetObject(reply, "return");
if (!fil)
goto cleanup;
- if (!(returnArray = virJSONValueObjectGetArray(msg, "return"))) {
- virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
- _("query-rx-filter reply was missing return data"));
- goto cleanup;
- }
+ returnArray = virJSONValueObjectGetArray(msg, "return");
+
if (!(entry = virJSONValueArrayGet(returnArray, 0))) {
virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
_("query -rx-filter return data missing array element"));
if (qemuMonitorJSONCommand(mon, cmd, &reply) < 0)
goto cleanup;
- if (qemuMonitorJSONCheckError(cmd, reply) < 0)
+ if (qemuMonitorJSONCheckReply(cmd, reply, VIR_JSON_TYPE_ARRAY) < 0)
goto cleanup;
if (qemuMonitorJSONQueryRxFilterParse(reply, filter) < 0)
size_t i;
qemuMonitorChardevInfoPtr entry = NULL;
- if (!(data = virJSONValueObjectGetArray(reply, "return"))) {
- virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
- _("character device reply was missing return data"));
- goto cleanup;
- }
+ data = virJSONValueObjectGetArray(reply, "return");
for (i = 0; i < virJSONValueArraySize(data); i++) {
virJSONValuePtr chardev = virJSONValueArrayGet(data, i);
if (qemuMonitorJSONCommand(mon, cmd, &reply) < 0)
goto cleanup;
- if (qemuMonitorJSONCheckError(cmd, reply) < 0)
+ if (qemuMonitorJSONCheckReply(cmd, reply, VIR_JSON_TYPE_ARRAY) < 0)
goto cleanup;
ret = qemuMonitorJSONExtractChardevInfo(reply, info);
if (qemuMonitorJSONCommand(mon, cmd, &reply) < 0)
goto cleanup;
- if (qemuMonitorJSONCheckError(cmd, reply) < 0)
+ if (qemuMonitorJSONCheckReply(cmd, reply, VIR_JSON_TYPE_OBJECT) < 0)
goto cleanup;
data = virJSONValueObjectGetObject(reply, "return");
if (qemuMonitorJSONCommand(mon, cmd, &reply) < 0)
goto cleanup;
- if (qemuMonitorJSONCheckError(cmd, reply) < 0)
+ if (qemuMonitorJSONCheckReply(cmd, reply, VIR_JSON_TYPE_ARRAY) < 0)
goto cleanup;
- if (!(data = virJSONValueObjectGetArray(reply, "return")) ||
- (n = virJSONValueArraySize(data)) < 0) {
- virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
- _("query-machines reply data was not an array"));
- goto cleanup;
- }
+ data = virJSONValueObjectGetArray(reply, "return");
+ n = virJSONValueArraySize(data);
/* null-terminated list */
if (VIR_ALLOC_N(infolist, n + 1) < 0)
goto cleanup;
}
- if (qemuMonitorJSONCheckError(cmd, reply) < 0)
+ if (qemuMonitorJSONCheckReply(cmd, reply, VIR_JSON_TYPE_ARRAY) < 0)
goto cleanup;
- if (!(data = virJSONValueObjectGetArray(reply, "return")) ||
- (n = virJSONValueArraySize(data)) < 0) {
- virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
- _("query-cpu-definitions reply data was not an array"));
- goto cleanup;
- }
+ data = virJSONValueObjectGetArray(reply, "return");
+ n = virJSONValueArraySize(data);
if (VIR_ALLOC_N(cpulist, n) < 0)
goto cleanup;
goto cleanup;
}
- if (qemuMonitorJSONCheckError(cmd, reply) < 0)
+ if (qemuMonitorJSONCheckReply(cmd, reply, VIR_JSON_TYPE_OBJECT) < 0)
goto cleanup;
data = virJSONValueObjectGetObject(reply, "return");
if (qemuMonitorJSONCommand(mon, cmd, &reply) < 0)
goto cleanup;
- if (qemuMonitorJSONCheckError(cmd, reply) < 0)
+ if (qemuMonitorJSONCheckReply(cmd, reply, VIR_JSON_TYPE_ARRAY) < 0)
goto cleanup;
- if (!(data = virJSONValueObjectGetArray(reply, "return")) ||
- (n = virJSONValueArraySize(data)) < 0) {
- virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
- _("query-commands reply data was not an array"));
- goto cleanup;
- }
+ data = virJSONValueObjectGetArray(reply, "return");
+ n = virJSONValueArraySize(data);
/* null-terminated list */
if (VIR_ALLOC_N(commandlist, n + 1) < 0)
goto cleanup;
}
- if (qemuMonitorJSONCheckError(cmd, reply) < 0)
+ if (qemuMonitorJSONCheckReply(cmd, reply, VIR_JSON_TYPE_ARRAY) < 0)
goto cleanup;
- if (!(data = virJSONValueObjectGetArray(reply, "return")) ||
- (n = virJSONValueArraySize(data)) < 0) {
- virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
- _("query-events reply data was not an array"));
- goto cleanup;
- }
+ data = virJSONValueObjectGetArray(reply, "return");
+ n = virJSONValueArraySize(data);
/* null-terminated list */
if (VIR_ALLOC_N(eventlist, n + 1) < 0)
goto cleanup;
}
- if (qemuMonitorJSONCheckError(cmd, reply) < 0)
+ if (qemuMonitorJSONCheckReply(cmd, reply, VIR_JSON_TYPE_OBJECT) < 0)
goto cleanup;
data = virJSONValueObjectGetObject(reply, "return");
if (qemuMonitorJSONCommand(mon, cmd, &reply) < 0)
goto cleanup;
- if (qemuMonitorJSONCheckError(cmd, reply) < 0)
+ if (qemuMonitorJSONCheckReply(cmd, reply, VIR_JSON_TYPE_ARRAY) < 0)
goto cleanup;
- if (!(data = virJSONValueObjectGetArray(reply, "return")) ||
- (n = virJSONValueArraySize(data)) < 0) {
- virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
- _("qom-list-types reply data was not an array"));
- goto cleanup;
- }
+ data = virJSONValueObjectGetArray(reply, "return");
+ n = virJSONValueArraySize(data);
/* null-terminated list */
if (VIR_ALLOC_N(typelist, n + 1) < 0)
if (qemuMonitorJSONCommand(mon, cmd, &reply) < 0)
goto cleanup;
- if (qemuMonitorJSONCheckError(cmd, reply) < 0)
+ if (qemuMonitorJSONCheckReply(cmd, reply, VIR_JSON_TYPE_ARRAY) < 0)
goto cleanup;
- if (!(data = virJSONValueObjectGetArray(reply, "return")) ||
- (n = virJSONValueArraySize(data)) < 0) {
- virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
- _("qom-list reply data was not an array"));
- goto cleanup;
- }
+ data = virJSONValueObjectGetArray(reply, "return");
+ n = virJSONValueArraySize(data);
/* null-terminated list */
if (VIR_ALLOC_N(pathlist, n + 1) < 0)
goto cleanup;
}
- if (qemuMonitorJSONCheckError(cmd, reply) < 0)
+ if (qemuMonitorJSONCheckReply(cmd, reply, VIR_JSON_TYPE_ARRAY) < 0)
goto cleanup;
- if (!(data = virJSONValueObjectGetArray(reply, "return")) ||
- (n = virJSONValueArraySize(data)) < 0) {
- virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
- _("device-list-properties reply data was not an array"));
- goto cleanup;
- }
+ data = virJSONValueObjectGetArray(reply, "return");
+ n = virJSONValueArraySize(data);
/* null-terminated list */
if (VIR_ALLOC_N(proplist, n + 1) < 0)
if (qemuMonitorJSONCommand(mon, cmd, &reply) < 0)
goto cleanup;
- if (qemuMonitorJSONCheckError(cmd, reply) < 0)
+ if (qemuMonitorJSONCheckReply(cmd, reply, VIR_JSON_TYPE_OBJECT) < 0)
goto cleanup;
data = virJSONValueObjectGetObject(reply, "return");
goto cleanup;
}
- if (qemuMonitorJSONCheckError(cmd, reply) < 0)
+ if (qemuMonitorJSONCheckReply(cmd, reply, VIR_JSON_TYPE_ARRAY) < 0)
goto cleanup;
- if (!(caps = virJSONValueObjectGetArray(reply, "return")) ||
- (n = virJSONValueArraySize(caps)) < 0) {
- virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
- _("missing migration capabilities"));
- goto cleanup;
- }
+ caps = virJSONValueObjectGetArray(reply, "return");
+ n = virJSONValueArraySize(caps);
if (VIR_ALLOC_N(list, n + 1) < 0)
goto cleanup;
goto cleanup;
}
- if (qemuMonitorJSONCheckError(cmd, reply) < 0)
+ if (qemuMonitorJSONCheckReply(cmd, reply, VIR_JSON_TYPE_ARRAY) < 0)
goto cleanup;
- if (!(caps = virJSONValueObjectGetArray(reply, "return")) ||
- (n = virJSONValueArraySize(caps)) < 0) {
- virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
- _("missing GIC capabilities"));
- goto cleanup;
- }
+ caps = virJSONValueObjectGetArray(reply, "return");
+ n = virJSONValueArraySize(caps);
/* If the returned array was empty we have to return successfully */
if (n == 0) {
goto cleanup;
}
- if (qemuMonitorJSONCheckError(cmd, reply) < 0)
+ if (qemuMonitorJSONCheckReply(cmd, reply, VIR_JSON_TYPE_ARRAY) < 0)
goto cleanup;
- if (!(data = virJSONValueObjectGetArray(reply, "return")) ||
- (n = virJSONValueArraySize(data)) < 0) {
- virReportError(VIR_ERR_INTERNAL_ERROR,
- _("%s reply data was not an array"),
- qmpCmd);
- goto cleanup;
- }
+ data = virJSONValueObjectGetArray(reply, "return");
+ n = virJSONValueArraySize(data);
/* null-terminated list */
if (VIR_ALLOC_N(list, n + 1) < 0)
if (qemuMonitorJSONCommand(mon, cmd, &reply) < 0)
goto cleanup;
- if (qemuMonitorJSONCheckError(cmd, reply) < 0)
- goto cleanup;
+ if (chr->type == VIR_DOMAIN_CHR_TYPE_PTY) {
+ if (qemuMonitorJSONCheckReply(cmd, reply, VIR_JSON_TYPE_OBJECT) < 0)
+ goto cleanup;
+ } else {
+ if (qemuMonitorJSONCheckError(cmd, reply) < 0)
+ goto cleanup;
+ }
if (chr->type == VIR_DOMAIN_CHR_TYPE_PTY) {
virJSONValuePtr data = virJSONValueObjectGetObject(reply, "return");
size_t i;
ssize_t n;
- if (!data || (n = virJSONValueArraySize(data)) < 0) {
- virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
- _("invalid array of CPUID features"));
- goto error;
- }
+ n = virJSONValueArraySize(data);
if (!(cpudata = virCPUDataNew(VIR_ARCH_X86_64)))
goto error;
if (qemuMonitorJSONCommand(mon, cmd, &reply) < 0)
goto cleanup;
- if (qemuMonitorJSONCheckError(cmd, reply))
+ if (qemuMonitorJSONCheckReply(cmd, reply, VIR_JSON_TYPE_ARRAY) < 0)
goto cleanup;
data = virJSONValueObjectGetArray(reply, "return");
}
}
- if (qemuMonitorJSONCheckError(cmd, reply))
+ if (qemuMonitorJSONCheckReply(cmd, reply, VIR_JSON_TYPE_ARRAY) < 0)
goto cleanup;
- if (!(data = virJSONValueObjectGetArray(reply, "return")) ||
- (n = virJSONValueArraySize(data)) < 0) {
- virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
- _("qom-list reply data was not an array"));
- goto cleanup;
- }
+ data = virJSONValueObjectGetArray(reply, "return");
+ n = virJSONValueArraySize(data);
for (i = 0; i < n; i++) {
virJSONValuePtr element = virJSONValueArrayGet(data, i);
if (qemuMonitorJSONCommand(mon, cmd, &reply) < 0)
goto cleanup;
- if (qemuMonitorJSONCheckError(cmd, reply) < 0)
+ if (qemuMonitorJSONCheckReply(cmd, reply, VIR_JSON_TYPE_ARRAY) < 0)
goto cleanup;
- if (!(data = virJSONValueObjectGetArray(reply, "return")) ||
- (n = virJSONValueArraySize(data)) < 0) {
- virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
- _("query-iothreads reply data was not an array"));
- goto cleanup;
- }
+ data = virJSONValueObjectGetArray(reply, "return");
+ n = virJSONValueArraySize(data);
/* null-terminated list */
if (VIR_ALLOC_N(infolist, n + 1) < 0)
goto cleanup;
}
- if (qemuMonitorJSONCheckError(cmd, reply) < 0)
+ if (qemuMonitorJSONCheckReply(cmd, reply, VIR_JSON_TYPE_ARRAY) < 0)
goto cleanup;
- if (!(data = virJSONValueObjectGetArray(reply, "return")) ||
- (n = virJSONValueArraySize(data)) < 0) {
- virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
- _("query-memory-devices reply data was not an array"));
- goto cleanup;
- }
+ data = virJSONValueObjectGetArray(reply, "return");
+ n = virJSONValueArraySize(data);
for (i = 0; i < n; i++) {
virJSONValuePtr elem = virJSONValueArrayGet(data, i);
if (qemuMonitorJSONCommand(mon, cmd, &reply) < 0)
goto cleanup;
- if (qemuMonitorJSONCheckError(cmd, reply) < 0)
+ if (qemuMonitorJSONCheckReply(cmd, reply, VIR_JSON_TYPE_OBJECT) < 0)
goto cleanup;
data = virJSONValueObjectGet(reply, "return");
if (qemuMonitorJSONCommand(mon, cmd, &reply) < 0)
goto cleanup;
- if (qemuMonitorJSONCheckError(cmd, reply) < 0)
+ if (qemuMonitorJSONCheckReply(cmd, reply, VIR_JSON_TYPE_ARRAY) < 0)
goto cleanup;
data = virJSONValueObjectGet(reply, "return");
-
- if ((ninfo = virJSONValueArraySize(data)) < 0) {
- virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
- _("query-hotpluggable-cpus reply is not an array"));
- goto cleanup;
- }
+ ninfo = virJSONValueArraySize(data);
if (VIR_ALLOC_N(info, ninfo) < 0)
goto cleanup;
if (qemuMonitorJSONCommand(mon, cmd, &reply) < 0)
goto cleanup;
- if (qemuMonitorJSONCheckError(cmd, reply) < 0)
+ if (qemuMonitorJSONCheckReply(cmd, reply, VIR_JSON_TYPE_ARRAY) < 0)
goto cleanup;
- if (!(ret = virJSONValueObjectStealArray(reply, "return")))
- virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
- _("query-qmp-schema reply is not an array"));
+ ret = virJSONValueObjectStealArray(reply, "return");
cleanup:
virJSONValueFree(cmd);
if (qemuMonitorJSONCommand(mon, cmd, &reply) < 0)
goto cleanup;
- if (qemuMonitorJSONCheckError(cmd, reply) < 0)
+ if (qemuMonitorJSONCheckReply(cmd, reply, VIR_JSON_TYPE_ARRAY) < 0)
goto cleanup;
ret = virJSONValueObjectStealArray(reply, "return");