}
-int qemuMonitorJSONGetBlockInfo(qemuMonitorPtr mon,
- virHashTablePtr table)
+/* qemuMonitorJSONQueryBlock:
+ * @mon: Monitor pointer
+ *
+ * This helper will attempt to make a "query-block" call and check for
+ * errors before returning with the reply.
+ *
+ * Returns: NULL on error, reply on success
+ */
+static virJSONValuePtr
+qemuMonitorJSONQueryBlock(qemuMonitorPtr mon)
{
- int ret = -1;
- size_t i;
-
- virJSONValuePtr cmd = qemuMonitorJSONMakeCommand("query-block",
- NULL);
+ virJSONValuePtr cmd;
virJSONValuePtr reply = NULL;
- virJSONValuePtr devices;
+ virJSONValuePtr devices = NULL;
- if (!cmd)
- return -1;
-
- if (qemuMonitorJSONCommand(mon, cmd, &reply) < 0)
- goto cleanup;
+ if (!(cmd = qemuMonitorJSONMakeCommand("query-block", NULL)))
+ return NULL;
- if (qemuMonitorJSONCheckError(cmd, reply) < 0)
+ if (qemuMonitorJSONCommand(mon, cmd, &reply) < 0 ||
+ qemuMonitorJSONCheckError(cmd, reply) < 0)
goto cleanup;
- if (!(devices = virJSONValueObjectGetArray(reply, "return"))) {
+ if (!(devices = virJSONValueObjectStealArray(reply, "return"))) {
virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
- _("block info reply was missing device list"));
+ _("query-block reply was missing device list"));
goto cleanup;
}
+ cleanup:
+ virJSONValueFree(cmd);
+ virJSONValueFree(reply);
+ return devices;
+}
+
+
+int qemuMonitorJSONGetBlockInfo(qemuMonitorPtr mon,
+ virHashTablePtr table)
+{
+ int ret = -1;
+ size_t i;
+
+ virJSONValuePtr devices;
+
+ if (!(devices = qemuMonitorJSONQueryBlock(mon)))
+ return -1;
+
for (i = 0; i < virJSONValueArraySize(devices); i++) {
virJSONValuePtr dev = virJSONValueArrayGet(devices, i);
struct qemuDomainDiskInfo *info;
ret = 0;
cleanup:
- virJSONValueFree(cmd);
- virJSONValueFree(reply);
+ virJSONValueFree(devices);
return ret;
}
bool backingChain)
{
int ret = -1;
- int rc;
size_t i;
- virJSONValuePtr cmd;
- virJSONValuePtr reply = NULL;
virJSONValuePtr devices;
- if (!(cmd = qemuMonitorJSONMakeCommand("query-block", NULL)))
+ if (!(devices = qemuMonitorJSONQueryBlock(mon)))
return -1;
- if ((rc = qemuMonitorJSONCommand(mon, cmd, &reply)) < 0)
- goto cleanup;
-
- if (qemuMonitorJSONCheckError(cmd, reply) < 0)
- goto cleanup;
-
- if (!(devices = virJSONValueObjectGetArray(reply, "return"))) {
- virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
- _("query-block reply was missing device list"));
- goto cleanup;
- }
-
for (i = 0; i < virJSONValueArraySize(devices); i++) {
virJSONValuePtr dev = virJSONValueArrayGet(devices, i);
virJSONValuePtr inserted;
ret = 0;
cleanup:
- virJSONValueFree(cmd);
- virJSONValueFree(reply);
+ virJSONValueFree(devices);
return ret;
}
virStorageSourcePtr target)
{
char *ret = NULL;
- virJSONValuePtr cmd = NULL;
- virJSONValuePtr reply = NULL;
virJSONValuePtr devices;
size_t i;
- cmd = qemuMonitorJSONMakeCommand("query-block", NULL);
- if (!cmd)
+ if (!(devices = qemuMonitorJSONQueryBlock(mon)))
return NULL;
- if (qemuMonitorJSONCommand(mon, cmd, &reply) < 0)
- goto cleanup;
-
- if (!(devices = virJSONValueObjectGetArray(reply, "return"))) {
- virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
- _("block info reply was missing device list"));
- goto cleanup;
- }
for (i = 0; i < virJSONValueArraySize(devices); i++) {
virJSONValuePtr dev = virJSONValueArrayGet(devices, i);
device);
cleanup:
- virJSONValueFree(cmd);
- virJSONValueFree(reply);
+ virJSONValueFree(devices);
return ret;
}