const char *dev_name,
bool force)
{
- int ret;
+ int ret = -1;
virJSONValuePtr cmd = qemuMonitorJSONMakeCommand("eject",
"s:device", dev_name,
"b:force", force ? 1 : 0,
if (!cmd)
return -1;
- ret = qemuMonitorJSONCommand(mon, cmd, &reply);
+ if (qemuMonitorJSONCommand(mon, cmd, &reply) < 0)
+ goto cleanup;
- if (ret == 0)
- ret = qemuMonitorJSONCheckError(cmd, reply);
+ if (qemuMonitorJSONCheckError(cmd, reply) < 0)
+ goto cleanup;
+ ret = 0;
+ cleanup:
virJSONValueFree(cmd);
virJSONValueFree(reply);
return ret;
const char *newmedia,
const char *format)
{
- int ret;
+ int ret = -1;
virJSONValuePtr cmd;
virJSONValuePtr reply = NULL;
if (!cmd)
return -1;
- ret = qemuMonitorJSONCommand(mon, cmd, &reply);
+ if (qemuMonitorJSONCommand(mon, cmd, &reply) < 0)
+ goto cleanup;
- if (ret == 0)
- ret = qemuMonitorJSONCheckError(cmd, reply);
+ if (qemuMonitorJSONCheckError(cmd, reply) < 0)
+ goto cleanup;
+ ret = 0;
+ cleanup:
virJSONValueFree(cmd);
virJSONValueFree(reply);
return ret;
size_t length,
const char *path)
{
- int ret;
+ int ret = -1;
virJSONValuePtr cmd = qemuMonitorJSONMakeCommand(cmdtype,
"U:val", offset,
"u:size", length,
if (!cmd)
return -1;
- ret = qemuMonitorJSONCommand(mon, cmd, &reply);
+ if (qemuMonitorJSONCommand(mon, cmd, &reply) < 0)
+ goto cleanup;
- if (ret == 0)
- ret = qemuMonitorJSONCheckError(cmd, reply);
+ if (qemuMonitorJSONCheckError(cmd, reply) < 0)
+ goto cleanup;
+ ret = 0;
+ cleanup:
virJSONValueFree(cmd);
virJSONValueFree(reply);
return ret;
int qemuMonitorJSONSetMigrationSpeed(qemuMonitorPtr mon,
unsigned long bandwidth)
{
- int ret;
+ int ret = -1;
virJSONValuePtr cmd;
virJSONValuePtr reply = NULL;
cmd = qemuMonitorJSONMakeCommand("migrate_set_speed",
if (!cmd)
return -1;
- ret = qemuMonitorJSONCommand(mon, cmd, &reply);
+ if (qemuMonitorJSONCommand(mon, cmd, &reply) < 0)
+ goto cleanup;
- if (ret == 0)
- ret = qemuMonitorJSONCheckError(cmd, reply);
+ if (qemuMonitorJSONCheckError(cmd, reply) < 0)
+ goto cleanup;
+ ret = 0;
+ cleanup:
virJSONValueFree(cmd);
virJSONValueFree(reply);
return ret;
int qemuMonitorJSONSetMigrationDowntime(qemuMonitorPtr mon,
unsigned long long downtime)
{
- int ret;
+ int ret = -1;
virJSONValuePtr cmd;
virJSONValuePtr reply = NULL;
if (!cmd)
return -1;
- ret = qemuMonitorJSONCommand(mon, cmd, &reply);
+ if (qemuMonitorJSONCommand(mon, cmd, &reply) < 0)
+ goto cleanup;
- if (ret == 0)
- ret = qemuMonitorJSONCheckError(cmd, reply);
+ if (qemuMonitorJSONCheckError(cmd, reply) < 0)
+ goto cleanup;
+ ret = 0;
+ cleanup:
virJSONValueFree(cmd);
virJSONValueFree(reply);
return ret;
qemuMonitorJSONGetMigrationCacheSize(qemuMonitorPtr mon,
unsigned long long *cacheSize)
{
- int ret;
+ int ret = -1;
virJSONValuePtr cmd;
virJSONValuePtr reply = NULL;
if (!cmd)
return -1;
- ret = qemuMonitorJSONCommand(mon, cmd, &reply);
-
- if (ret == 0)
- ret = qemuMonitorJSONCheckError(cmd, reply);
+ if (qemuMonitorJSONCommand(mon, cmd, &reply) < 0)
+ goto cleanup;
- if (ret < 0)
+ if (qemuMonitorJSONCheckError(cmd, reply) < 0)
goto cleanup;
- ret = virJSONValueObjectGetNumberUlong(reply, "return", cacheSize);
- if (ret < 0) {
+ if (virJSONValueObjectGetNumberUlong(reply, "return", cacheSize) < 0) {
virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
_("query-migrate-cache-size reply was missing "
"'return' data"));
qemuMonitorJSONSetMigrationCacheSize(qemuMonitorPtr mon,
unsigned long long cacheSize)
{
- int ret;
+ int ret = -1;
virJSONValuePtr cmd;
virJSONValuePtr reply = NULL;
if (!cmd)
return -1;
- ret = qemuMonitorJSONCommand(mon, cmd, &reply);
+ if (qemuMonitorJSONCommand(mon, cmd, &reply) < 0)
+ goto cleanup;
- if (ret == 0)
- ret = qemuMonitorJSONCheckError(cmd, reply);
+ if (qemuMonitorJSONCheckError(cmd, reply) < 0)
+ goto cleanup;
+ ret = 0;
+ cleanup:
virJSONValueFree(cmd);
virJSONValueFree(reply);
return ret;
if (!(cmd = qemuMonitorJSONMakeCommand("query-migrate-parameters", NULL)))
return -1;
- if ((ret = qemuMonitorJSONCommand(mon, cmd, &reply)) < 0)
+ if (qemuMonitorJSONCommand(mon, cmd, &reply) < 0)
goto cleanup;
- if ((ret = qemuMonitorJSONCheckError(cmd, reply)) < 0)
+ if (qemuMonitorJSONCheckError(cmd, reply) < 0)
goto cleanup;
result = virJSONValueObjectGet(reply, "return");
goto cleanup;
args = NULL;
- if ((ret = qemuMonitorJSONCommand(mon, cmd, &reply)) < 0)
+ if (qemuMonitorJSONCommand(mon, cmd, &reply) < 0)
goto cleanup;
- ret = qemuMonitorJSONCheckError(cmd, reply);
+ if (qemuMonitorJSONCheckError(cmd, reply) < 0)
+ goto cleanup;
+ ret = 0;
cleanup:
virJSONValueFree(cmd);
virJSONValueFree(args);
int qemuMonitorJSONGetMigrationStats(qemuMonitorPtr mon,
qemuMonitorMigrationStatsPtr stats)
{
- int ret;
+ int ret = -1;
virJSONValuePtr cmd = qemuMonitorJSONMakeCommand("query-migrate",
NULL);
virJSONValuePtr reply = NULL;
if (!cmd)
return -1;
- ret = qemuMonitorJSONCommand(mon, cmd, &reply);
+ if (qemuMonitorJSONCommand(mon, cmd, &reply) < 0)
+ goto cleanup;
- if (ret == 0)
- ret = qemuMonitorJSONCheckError(cmd, reply);
+ if (qemuMonitorJSONCheckError(cmd, reply) < 0)
+ goto cleanup;
- if (ret == 0 &&
- qemuMonitorJSONGetMigrationStatsReply(reply, stats) < 0)
- ret = -1;
+ if (qemuMonitorJSONGetMigrationStatsReply(reply, stats) < 0)
+ goto cleanup;
+ ret = 0;
+ cleanup:
if (ret < 0)
memset(stats, 0, sizeof(*stats));
virJSONValueFree(cmd);
unsigned int flags,
const char *uri)
{
- int ret;
+ int ret = -1;
virJSONValuePtr cmd =
qemuMonitorJSONMakeCommand("migrate",
"b:detach", flags & QEMU_MONITOR_MIGRATE_BACKGROUND ? 1 : 0,
if (!cmd)
return -1;
- ret = qemuMonitorJSONCommand(mon, cmd, &reply);
+ if (qemuMonitorJSONCommand(mon, cmd, &reply) < 0)
+ goto cleanup;
- if (ret == 0)
- ret = qemuMonitorJSONCheckError(cmd, reply);
+ if (qemuMonitorJSONCheckError(cmd, reply) < 0)
+ goto cleanup;
+ ret = 0;
+ cleanup:
virJSONValueFree(cmd);
virJSONValueFree(reply);
return ret;
int qemuMonitorJSONMigrateCancel(qemuMonitorPtr mon)
{
- int ret;
+ int ret = -1;
virJSONValuePtr cmd = qemuMonitorJSONMakeCommand("migrate_cancel", NULL);
virJSONValuePtr reply = NULL;
if (!cmd)
return -1;
- ret = qemuMonitorJSONCommand(mon, cmd, &reply);
+ if (qemuMonitorJSONCommand(mon, cmd, &reply) < 0)
+ goto cleanup;
- if (ret == 0)
- ret = qemuMonitorJSONCheckError(cmd, reply);
+ if (qemuMonitorJSONCheckError(cmd, reply) < 0)
+ goto cleanup;
+ ret = 0;
+ cleanup:
virJSONValueFree(cmd);
virJSONValueFree(reply);
return ret;
qemuMonitorJSONGetDumpGuestMemoryCapability(qemuMonitorPtr mon,
const char *capability)
{
- int ret;
+ int ret = -1;
virJSONValuePtr cmd;
virJSONValuePtr reply = NULL;
virJSONValuePtr caps;
NULL)))
return -1;
- ret = qemuMonitorJSONCommand(mon, cmd, &reply);
+ if (qemuMonitorJSONCommand(mon, cmd, &reply) < 0)
+ goto cleanup;
- if (ret == 0) {
- if (qemuMonitorJSONHasError(reply, "CommandNotFound"))
- goto cleanup;
- ret = qemuMonitorJSONCheckError(cmd, reply);
+ if (qemuMonitorJSONHasError(reply, "CommandNotFound")) {
+ ret = 0;
+ goto cleanup;
}
- if (ret < 0)
+ if (qemuMonitorJSONCheckError(cmd, reply) < 0)
goto cleanup;
- ret = -1;
-
if (!(caps = virJSONValueObjectGetObject(reply, "return"))) {
virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
_("missing dump guest memory capabilities"));
ret = 1;
goto cleanup;
}
-
- ret = 0;
}
+ ret = 0;
cleanup:
virJSONValueFree(cmd);
virJSONValueFree(reply);
const char *protocol,
const char *dumpformat)
{
- int ret;
+ int ret = -1;
virJSONValuePtr cmd = NULL;
virJSONValuePtr reply = NULL;
if (!cmd)
return -1;
- ret = qemuMonitorJSONCommand(mon, cmd, &reply);
+ if (qemuMonitorJSONCommand(mon, cmd, &reply) < 0)
+ goto cleanup;
- if (ret == 0)
- ret = qemuMonitorJSONCheckError(cmd, reply);
+ if (qemuMonitorJSONCheckError(cmd, reply) < 0)
+ goto cleanup;
+ ret = 0;
+ cleanup:
virJSONValueFree(cmd);
virJSONValueFree(reply);
return ret;
if (!cmd)
return -1;
- ret = qemuMonitorJSONCommand(mon, cmd, &reply);
+ if (qemuMonitorJSONCommand(mon, cmd, &reply) < 0)
+ goto cleanup;
- if (ret == 0)
- ret = qemuMonitorJSONCheckError(cmd, reply);
+ if (qemuMonitorJSONCheckError(cmd, reply) < 0)
+ goto cleanup;
+ ret = 0;
+ cleanup:
virJSONValueFree(cmd);
virJSONValueFree(reply);
return ret;
const char *fdname,
int fd)
{
- int ret;
+ int ret = -1;
virJSONValuePtr cmd = qemuMonitorJSONMakeCommand("getfd",
"s:fdname", fdname,
NULL);
if (!cmd)
return -1;
- ret = qemuMonitorJSONCommandWithFd(mon, cmd, fd, &reply);
+ if (qemuMonitorJSONCommandWithFd(mon, cmd, fd, &reply) < 0)
+ goto cleanup;
- if (ret == 0)
- ret = qemuMonitorJSONCheckError(cmd, reply);
+ if (qemuMonitorJSONCheckError(cmd, reply) < 0)
+ goto cleanup;
+ ret = 0;
+ cleanup:
virJSONValueFree(cmd);
virJSONValueFree(reply);
return ret;
int qemuMonitorJSONCloseFileHandle(qemuMonitorPtr mon,
const char *fdname)
{
- int ret;
+ int ret = -1;
virJSONValuePtr cmd = qemuMonitorJSONMakeCommand("closefd",
"s:fdname", fdname,
NULL);
if (!cmd)
return -1;
- ret = qemuMonitorJSONCommand(mon, cmd, &reply);
+ if (qemuMonitorJSONCommand(mon, cmd, &reply) < 0)
+ goto cleanup;
- if (ret == 0)
- ret = qemuMonitorJSONCheckError(cmd, reply);
+ if (qemuMonitorJSONCheckError(cmd, reply) < 0)
+ goto cleanup;
+ ret = 0;
+ cleanup:
virJSONValueFree(cmd);
virJSONValueFree(reply);
return ret;
int
qemuMonitorJSONRemoveFd(qemuMonitorPtr mon, int fdset, int fd)
{
- int ret;
+ int ret = -1;
virJSONValuePtr cmd = qemuMonitorJSONMakeCommand("remove-fd",
"i:fdset-id", fdset,
fd < 0 ? NULL : "i:fd",
if (!cmd)
return -1;
- ret = qemuMonitorJSONCommand(mon, cmd, &reply);
+ if (qemuMonitorJSONCommand(mon, cmd, &reply) < 0)
+ goto cleanup;
- if (ret == 0)
- ret = qemuMonitorJSONCheckError(cmd, reply);
+ if (qemuMonitorJSONCheckError(cmd, reply) < 0)
+ goto cleanup;
+ ret = 0;
+ cleanup:
virJSONValueFree(cmd);
virJSONValueFree(reply);
return ret;
goto cleanup;
args = NULL; /* obj owns reference to args now */
- ret = qemuMonitorJSONCommand(mon, cmd, &reply);
+ if (qemuMonitorJSONCommand(mon, cmd, &reply) < 0)
+ goto cleanup;
- if (ret == 0)
- ret = qemuMonitorJSONCheckError(cmd, reply);
+ if (qemuMonitorJSONCheckError(cmd, reply) < 0)
+ goto cleanup;
+ ret = 0;
cleanup:
virJSONValueFree(args);
virJSONValueFree(cmd);
int qemuMonitorJSONRemoveNetdev(qemuMonitorPtr mon,
const char *alias)
{
- int ret;
+ int ret = -1;
virJSONValuePtr cmd = qemuMonitorJSONMakeCommand("netdev_del",
"s:id", alias,
NULL);
if (!cmd)
return -1;
- ret = qemuMonitorJSONCommand(mon, cmd, &reply);
+ if (qemuMonitorJSONCommand(mon, cmd, &reply) < 0)
+ goto cleanup;
- if (ret == 0)
- ret = qemuMonitorJSONCheckError(cmd, reply);
+ if (qemuMonitorJSONCheckError(cmd, reply) < 0)
+ goto cleanup;
+ ret = 0;
+ cleanup:
virJSONValueFree(cmd);
virJSONValueFree(reply);
return ret;
virHashTablePtr info)
{
- int ret;
+ int ret = -1;
virJSONValuePtr cmd = qemuMonitorJSONMakeCommand("query-chardev",
NULL);
virJSONValuePtr reply = NULL;
if (!cmd)
return -1;
- ret = qemuMonitorJSONCommand(mon, cmd, &reply);
-
- if (ret == 0)
- ret = qemuMonitorJSONCheckError(cmd, reply);
+ if (qemuMonitorJSONCommand(mon, cmd, &reply) < 0)
+ goto cleanup;
- if (ret == 0)
- ret = qemuMonitorJSONExtractChardevInfo(reply, info);
+ if (qemuMonitorJSONCheckError(cmd, reply) < 0)
+ goto cleanup;
+ ret = qemuMonitorJSONExtractChardevInfo(reply, info);
+ cleanup:
virJSONValueFree(cmd);
virJSONValueFree(reply);
return ret;
int qemuMonitorJSONDelDevice(qemuMonitorPtr mon,
const char *devalias)
{
- int ret;
+ int ret = -1;
virJSONValuePtr cmd;
virJSONValuePtr reply = NULL;
if (!cmd)
return -1;
- ret = qemuMonitorJSONCommand(mon, cmd, &reply);
+ if (qemuMonitorJSONCommand(mon, cmd, &reply) < 0)
+ goto cleanup;
- if (ret == 0)
- ret = qemuMonitorJSONCheckError(cmd, reply);
+ if (qemuMonitorJSONCheckError(cmd, reply) < 0)
+ goto cleanup;
+ ret = 0;
+ cleanup:
virJSONValueFree(cmd);
virJSONValueFree(reply);
return ret;
goto cleanup;
args = NULL; /* obj owns reference to args now */
- ret = qemuMonitorJSONCommand(mon, cmd, &reply);
+ if (qemuMonitorJSONCommand(mon, cmd, &reply) < 0)
+ goto cleanup;
- if (ret == 0)
- ret = qemuMonitorJSONCheckError(cmd, reply);
+ if (qemuMonitorJSONCheckError(cmd, reply) < 0)
+ goto cleanup;
+ ret = 0;
cleanup:
virJSONValueFree(args);
virJSONValueFree(cmd);
if (!cmd)
goto cleanup;
- /* @props is part of @cmd now. Avoid double free */
+ /* @props is part of @cmd now. Avoid double free */
props = NULL;
- ret = qemuMonitorJSONCommand(mon, cmd, &reply);
+ if (qemuMonitorJSONCommand(mon, cmd, &reply) < 0)
+ goto cleanup;
- if (ret == 0)
- ret = qemuMonitorJSONCheckError(cmd, reply);
+ if (qemuMonitorJSONCheckError(cmd, reply) < 0)
+ goto cleanup;
+ ret = 0;
cleanup:
virJSONValueFree(cmd);
virJSONValueFree(reply);
int qemuMonitorJSONDelObject(qemuMonitorPtr mon,
const char *objalias)
{
- int ret;
+ int ret = -1;
virJSONValuePtr cmd;
virJSONValuePtr reply = NULL;
if (!cmd)
return -1;
- ret = qemuMonitorJSONCommand(mon, cmd, &reply);
+ if (qemuMonitorJSONCommand(mon, cmd, &reply) < 0)
+ goto cleanup;
- if (ret == 0)
- ret = qemuMonitorJSONCheckError(cmd, reply);
+ if (qemuMonitorJSONCheckError(cmd, reply) < 0)
+ goto cleanup;
+ ret = 0;
+ cleanup:
virJSONValueFree(cmd);
virJSONValueFree(reply);
return ret;
const char *alias,
const char *passphrase)
{
- int ret;
+ int ret = -1;
virJSONValuePtr cmd;
virJSONValuePtr reply = NULL;
char *drive;
if (!cmd)
return -1;
- ret = qemuMonitorJSONCommand(mon, cmd, &reply);
+ if (qemuMonitorJSONCommand(mon, cmd, &reply) < 0)
+ goto cleanup;
- if (ret == 0)
- ret = qemuMonitorJSONCheckError(cmd, reply);
+ if (qemuMonitorJSONCheckError(cmd, reply) < 0)
+ goto cleanup;
+ ret = 0;
+ cleanup:
virJSONValueFree(cmd);
virJSONValueFree(reply);
return ret;
if (!cmd)
return -1;
- if ((ret = qemuMonitorJSONCommand(mon, cmd, &reply)) < 0)
+ if (qemuMonitorJSONCommand(mon, cmd, &reply) < 0)
goto cleanup;
- ret = qemuMonitorJSONCheckError(cmd, reply);
+ if (qemuMonitorJSONCheckError(cmd, reply) < 0)
+ goto cleanup;
+
+ ret = 0;
cleanup:
virJSONValueFree(cmd);
virJSONValueFree(reply);
if (!cmd)
goto cleanup;
- if ((ret = qemuMonitorJSONCommand(mon, cmd, &reply)) < 0)
+ if (qemuMonitorJSONCommand(mon, cmd, &reply) < 0)
goto cleanup;
- ret = qemuMonitorJSONCheckError(cmd, reply);
+ if (qemuMonitorJSONCheckError(cmd, reply) < 0)
+ goto cleanup;
+ ret = 0;
cleanup:
virJSONValueFree(cmd);
virJSONValueFree(reply);
if (!cmd)
return -1;
- if ((ret = qemuMonitorJSONCommand(mon, cmd, &reply)) < 0)
+ if (qemuMonitorJSONCommand(mon, cmd, &reply) < 0)
goto cleanup;
if (!top && !base) {
/* Normally we always specify top and base; but omitting them
}
goto cleanup;
}
- ret = qemuMonitorJSONCheckError(cmd, reply);
+ if (qemuMonitorJSONCheckError(cmd, reply) < 0)
+ goto cleanup;
+
+ ret = 0;
cleanup:
virJSONValueFree(cmd);
virJSONValueFree(reply);
qemuMonitorJSONDrivePivot(qemuMonitorPtr mon,
const char *device)
{
- int ret;
+ int ret = -1;
virJSONValuePtr cmd;
virJSONValuePtr reply = NULL;
if (!cmd)
return -1;
- if ((ret = qemuMonitorJSONCommand(mon, cmd, &reply)) < 0)
+ if (qemuMonitorJSONCommand(mon, cmd, &reply) < 0)
goto cleanup;
- ret = qemuMonitorJSONCheckError(cmd, reply);
+ if (qemuMonitorJSONCheckError(cmd, reply) < 0)
+ goto cleanup;
+
+ ret = 0;
cleanup:
virJSONValueFree(cmd);
virJSONValueFree(reply);
cleanup:
virJSONValueFree(cmd);
virJSONValueFree(reply);
-
return ret;
}
int qemuMonitorJSONInjectNMI(qemuMonitorPtr mon)
{
- int ret;
+ int ret = -1;
virJSONValuePtr cmd;
virJSONValuePtr reply = NULL;
if (!cmd)
return -1;
- if ((ret = qemuMonitorJSONCommand(mon, cmd, &reply)) < 0)
+ if (qemuMonitorJSONCommand(mon, cmd, &reply) < 0)
goto cleanup;
if (qemuMonitorJSONHasError(reply, "CommandNotFound")) {
VIR_DEBUG("inject-nmi command not found, trying HMP");
- ret = qemuMonitorTextInjectNMI(mon);
+ if (qemuMonitorTextInjectNMI(mon) < 0)
+ goto cleanup;
} else {
- ret = qemuMonitorJSONCheckError(cmd, reply);
+ if (qemuMonitorJSONCheckError(cmd, reply) < 0)
+ goto cleanup;
}
+ ret = 0;
cleanup:
virJSONValueFree(cmd);
virJSONValueFree(reply);
/* @keys is part of @cmd now. Avoid double free */
keys = NULL;
- if ((ret = qemuMonitorJSONCommand(mon, cmd, &reply)) < 0)
+ if (qemuMonitorJSONCommand(mon, cmd, &reply) < 0)
goto cleanup;
if (qemuMonitorJSONHasError(reply, "CommandNotFound")) {
VIR_DEBUG("send-key command not found, trying HMP");
- ret = qemuMonitorTextSendKey(mon, holdtime, keycodes, nkeycodes);
+ if (qemuMonitorTextSendKey(mon, holdtime, keycodes, nkeycodes) < 0)
+ goto cleanup;
} else {
- ret = qemuMonitorJSONCheckError(cmd, reply);
+ if (qemuMonitorJSONCheckError(cmd, reply) < 0)
+ goto cleanup;
}
+ ret = 0;
cleanup:
virJSONValueFree(cmd);
virJSONValueFree(reply);
int qemuMonitorJSONScreendump(qemuMonitorPtr mon,
const char *file)
{
- int ret;
+ int ret = -1;
virJSONValuePtr cmd, reply = NULL;
cmd = qemuMonitorJSONMakeCommand("screendump",
if (!cmd)
return -1;
- ret = qemuMonitorJSONCommand(mon, cmd, &reply);
+ if (qemuMonitorJSONCommand(mon, cmd, &reply) < 0)
+ goto cleanup;
- if (ret == 0)
- ret = qemuMonitorJSONCheckError(cmd, reply);
+ if (qemuMonitorJSONCheckError(cmd, reply) < 0)
+ goto cleanup;
+ ret = 0;
+ cleanup:
virJSONValueFree(cmd);
virJSONValueFree(reply);
return ret;
const char *fdname,
bool skipauth)
{
- int ret;
+ int ret = -1;
virJSONValuePtr cmd, reply = NULL;
cmd = qemuMonitorJSONMakeCommand("add_client",
if (!cmd)
return -1;
- ret = qemuMonitorJSONCommand(mon, cmd, &reply);
+ if (qemuMonitorJSONCommand(mon, cmd, &reply) < 0)
+ goto cleanup;
- if (ret == 0)
- ret = qemuMonitorJSONCheckError(cmd, reply);
+ if (qemuMonitorJSONCheckError(cmd, reply) < 0)
+ goto cleanup;
+ ret = 0;
+ cleanup:
virJSONValueFree(cmd);
virJSONValueFree(reply);
return ret;
if (!cmd)
return -1;
- ret = qemuMonitorJSONCommand(mon, cmd, &result);
+ if (qemuMonitorJSONCommand(mon, cmd, &result) < 0)
+ goto cleanup;
- if (ret == 0 && virJSONValueObjectHasKey(result, "error")) {
+ if (virJSONValueObjectHasKey(result, "error")) {
if (qemuMonitorJSONHasError(result, "DeviceNotActive"))
virReportError(VIR_ERR_OPERATION_INVALID,
_("No active operation on device: %s"), device);
else
virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
_("Unexpected error"));
- ret = -1;
+ goto cleanup;
}
+ ret = 0;
+ cleanup:
virJSONValueFree(cmd);
virJSONValueFree(result);
return ret;
if (!cmd)
return -1;
- ret = qemuMonitorJSONCommand(mon, cmd, &result);
+ if (qemuMonitorJSONCommand(mon, cmd, &result) < 0)
+ goto cleanup;
- if (ret == 0 && virJSONValueObjectHasKey(result, "error")) {
+ if (virJSONValueObjectHasKey(result, "error")) {
if (qemuMonitorJSONHasError(result, "DeviceNotActive"))
virReportError(VIR_ERR_OPERATION_INVALID,
_("No active operation on device: %s"), device);
else
virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
_("Unexpected error"));
- ret = -1;
+ goto cleanup;
}
- if (ret == 0)
- ret = qemuMonitorJSONBlockIoThrottleInfo(result, device, reply, supportMaxOptions);
-
+ ret = qemuMonitorJSONBlockIoThrottleInfo(result, device, reply, supportMaxOptions);
+ cleanup:
virJSONValueFree(cmd);
virJSONValueFree(result);
return ret;
if (!cmd)
return -1;
- ret = qemuMonitorJSONCommand(mon, cmd, &reply);
+ if (qemuMonitorJSONCommand(mon, cmd, &reply) < 0)
+ goto cleanup;
- if (ret == 0)
- ret = qemuMonitorJSONCheckError(cmd, reply);
+ if (qemuMonitorJSONCheckError(cmd, reply) < 0)
+ goto cleanup;
+ ret = 0;
+ cleanup:
virJSONValueFree(cmd);
virJSONValueFree(reply);
return ret;
int *micro,
char **package)
{
- int ret;
+ int ret = -1;
virJSONValuePtr cmd;
virJSONValuePtr reply = NULL;
virJSONValuePtr data;
if (!(cmd = qemuMonitorJSONMakeCommand("query-version", NULL)))
return -1;
- ret = qemuMonitorJSONCommand(mon, cmd, &reply);
-
- if (ret == 0)
- ret = qemuMonitorJSONCheckError(cmd, reply);
-
- if (ret < 0)
+ if (qemuMonitorJSONCommand(mon, cmd, &reply) < 0)
goto cleanup;
- ret = -1;
+ if (qemuMonitorJSONCheckError(cmd, reply) < 0)
+ goto cleanup;
if (!(data = virJSONValueObjectGetObject(reply, "return"))) {
virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
int qemuMonitorJSONGetMachines(qemuMonitorPtr mon,
qemuMonitorMachineInfoPtr **machines)
{
- int ret;
+ int ret = -1;
virJSONValuePtr cmd;
virJSONValuePtr reply = NULL;
virJSONValuePtr data;
if (!(cmd = qemuMonitorJSONMakeCommand("query-machines", NULL)))
return -1;
- ret = qemuMonitorJSONCommand(mon, cmd, &reply);
-
- if (ret == 0)
- ret = qemuMonitorJSONCheckError(cmd, reply);
-
- if (ret < 0)
+ if (qemuMonitorJSONCommand(mon, cmd, &reply) < 0)
goto cleanup;
- ret = -1;
+ if (qemuMonitorJSONCheckError(cmd, reply) < 0)
+ goto cleanup;
if (!(data = virJSONValueObjectGetArray(reply, "return"))) {
virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
int qemuMonitorJSONGetCPUDefinitions(qemuMonitorPtr mon,
char ***cpus)
{
- int ret;
+ int ret = -1;
virJSONValuePtr cmd;
virJSONValuePtr reply = NULL;
virJSONValuePtr data;
if (!(cmd = qemuMonitorJSONMakeCommand("query-cpu-definitions", NULL)))
return -1;
- ret = qemuMonitorJSONCommand(mon, cmd, &reply);
+ if (qemuMonitorJSONCommand(mon, cmd, &reply) < 0)
+ goto cleanup;
- if (ret == 0) {
- /* Urgh, some QEMU architectures have the query-cpu-definitions
- * command, but return 'GenericError' with string "Not supported",
- * instead of simply omitting the command entirely :-(
- */
- if (qemuMonitorJSONHasError(reply, "GenericError")) {
- ret = 0;
- goto cleanup;
- }
- ret = qemuMonitorJSONCheckError(cmd, reply);
+ /* Urgh, some QEMU architectures have the query-cpu-definitions
+ * command, but return 'GenericError' with string "Not supported",
+ * instead of simply omitting the command entirely :-(
+ */
+ if (qemuMonitorJSONHasError(reply, "GenericError")) {
+ ret = 0;
+ goto cleanup;
}
- if (ret == 0)
- ret = qemuMonitorJSONCheckError(cmd, reply);
-
- if (ret < 0)
+ if (qemuMonitorJSONCheckError(cmd, reply) < 0)
goto cleanup;
- ret = -1;
-
if (!(data = virJSONValueObjectGetArray(reply, "return"))) {
virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
_("query-cpu-definitions reply was missing return data"));
int qemuMonitorJSONGetCommands(qemuMonitorPtr mon,
char ***commands)
{
- int ret;
+ int ret = -1;
virJSONValuePtr cmd;
virJSONValuePtr reply = NULL;
virJSONValuePtr data;
if (!(cmd = qemuMonitorJSONMakeCommand("query-commands", NULL)))
return -1;
- ret = qemuMonitorJSONCommand(mon, cmd, &reply);
-
- if (ret == 0)
- ret = qemuMonitorJSONCheckError(cmd, reply);
-
- if (ret < 0)
+ if (qemuMonitorJSONCommand(mon, cmd, &reply) < 0)
goto cleanup;
- ret = -1;
+ if (qemuMonitorJSONCheckError(cmd, reply) < 0)
+ goto cleanup;
if (!(data = virJSONValueObjectGetArray(reply, "return"))) {
virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
int qemuMonitorJSONGetEvents(qemuMonitorPtr mon,
char ***events)
{
- int ret;
+ int ret = -1;
virJSONValuePtr cmd;
virJSONValuePtr reply = NULL;
virJSONValuePtr data;
if (!(cmd = qemuMonitorJSONMakeCommand("query-events", NULL)))
return -1;
- ret = qemuMonitorJSONCommand(mon, cmd, &reply);
+ if (qemuMonitorJSONCommand(mon, cmd, &reply) < 0)
+ goto cleanup;
- if (ret == 0) {
- if (qemuMonitorJSONHasError(reply, "CommandNotFound")) {
- ret = 0;
- goto cleanup;
- }
- ret = qemuMonitorJSONCheckError(cmd, reply);
+ if (qemuMonitorJSONHasError(reply, "CommandNotFound")) {
+ ret = 0;
+ goto cleanup;
}
- if (ret < 0)
+ if (qemuMonitorJSONCheckError(cmd, reply) < 0)
goto cleanup;
- ret = -1;
-
if (!(data = virJSONValueObjectGetArray(reply, "return"))) {
virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
_("query-events reply was missing return data"));
char ***params,
bool *found)
{
- int ret;
+ int ret = -1;
virJSONValuePtr cmd = NULL;
virJSONValuePtr reply = NULL;
virJSONValuePtr data = NULL;
NULL)))
return -1;
- ret = qemuMonitorJSONCommand(mon, cmd, &reply);
+ if (qemuMonitorJSONCommand(mon, cmd, &reply) < 0)
+ goto cleanup;
- if (ret == 0) {
- if (qemuMonitorJSONHasError(reply, "CommandNotFound"))
- goto cleanup;
- ret = qemuMonitorJSONCheckError(cmd, reply);
+ if (qemuMonitorJSONHasError(reply, "CommandNotFound")) {
+ ret = 0;
+ goto cleanup;
}
- if (ret < 0)
+ if (qemuMonitorJSONCheckError(cmd, reply) < 0)
goto cleanup;
if (virJSONValueObjectRemoveKey(reply, "return", &array) <= 0) {
qemuMonitorSetOptions(mon, array);
}
- ret = -1;
-
if ((n = virJSONValueArraySize(array)) < 0) {
virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
_("query-command-line-options reply data was not "
bool *enabled,
bool *present)
{
- int ret;
+ int ret = -1;
virJSONValuePtr cmd = NULL;
virJSONValuePtr reply = NULL;
virJSONValuePtr data = NULL;
if (!(cmd = qemuMonitorJSONMakeCommand("query-kvm", NULL)))
return -1;
- ret = qemuMonitorJSONCommand(mon, cmd, &reply);
-
- if (ret == 0) {
- if (qemuMonitorJSONHasError(reply, "CommandNotFound"))
- goto cleanup;
+ if (qemuMonitorJSONCommand(mon, cmd, &reply) < 0)
+ goto cleanup;
- ret = qemuMonitorJSONCheckError(cmd, reply);
+ if (qemuMonitorJSONHasError(reply, "CommandNotFound")) {
+ ret = 0;
+ goto cleanup;
}
- if (ret < 0)
+ if (qemuMonitorJSONCheckError(cmd, reply) < 0)
goto cleanup;
- ret = -1;
-
if (!(data = virJSONValueObjectGetObject(reply, "return"))) {
virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
_("query-kvm reply was missing return data"));
int qemuMonitorJSONGetObjectTypes(qemuMonitorPtr mon,
char ***types)
{
- int ret;
+ int ret = -1;
virJSONValuePtr cmd;
virJSONValuePtr reply = NULL;
virJSONValuePtr data;
if (!(cmd = qemuMonitorJSONMakeCommand("qom-list-types", NULL)))
return -1;
- ret = qemuMonitorJSONCommand(mon, cmd, &reply);
-
- if (ret == 0)
- ret = qemuMonitorJSONCheckError(cmd, reply);
-
- if (ret < 0)
+ if (qemuMonitorJSONCommand(mon, cmd, &reply) < 0)
goto cleanup;
- ret = -1;
+ if (qemuMonitorJSONCheckError(cmd, reply) < 0)
+ goto cleanup;
if (!(data = virJSONValueObjectGetArray(reply, "return"))) {
virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
const char *path,
qemuMonitorJSONListPathPtr **paths)
{
- int ret;
+ int ret = -1;
virJSONValuePtr cmd;
virJSONValuePtr reply = NULL;
virJSONValuePtr data;
NULL)))
return -1;
- ret = qemuMonitorJSONCommand(mon, cmd, &reply);
-
- if (ret == 0)
- ret = qemuMonitorJSONCheckError(cmd, reply);
-
- if (ret < 0)
+ if (qemuMonitorJSONCommand(mon, cmd, &reply) < 0)
goto cleanup;
- ret = -1;
+ if (qemuMonitorJSONCheckError(cmd, reply) < 0)
+ goto cleanup;
if (!(data = virJSONValueObjectGetArray(reply, "return"))) {
virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
const char *property,
qemuMonitorJSONObjectPropertyPtr prop)
{
- int ret;
+ int ret = -1;
virJSONValuePtr cmd;
virJSONValuePtr reply = NULL;
virJSONValuePtr data;
NULL)))
return -1;
- ret = qemuMonitorJSONCommand(mon, cmd, &reply);
-
- if (ret == 0)
- ret = qemuMonitorJSONCheckError(cmd, reply);
-
- if (ret < 0)
+ if (qemuMonitorJSONCommand(mon, cmd, &reply) < 0)
goto cleanup;
- ret = -1;
+ if (qemuMonitorJSONCheckError(cmd, reply) < 0)
+ goto cleanup;
data = virJSONValueObjectGet(reply, "return");
if (!cmd)
return -1;
- if ((ret = qemuMonitorJSONCommand(mon, cmd, &reply)) == 0)
- ret = qemuMonitorJSONCheckError(cmd, reply);
+ if (qemuMonitorJSONCommand(mon, cmd, &reply) < 0)
+ goto cleanup;
+ if (qemuMonitorJSONCheckError(cmd, reply) < 0)
+ goto cleanup;
+
+ ret = 0;
cleanup:
virJSONValueFree(cmd);
virJSONValueFree(reply);
const char *type,
char ***props)
{
- int ret;
+ int ret = -1;
virJSONValuePtr cmd;
virJSONValuePtr reply = NULL;
virJSONValuePtr data;
NULL)))
return -1;
- ret = qemuMonitorJSONCommand(mon, cmd, &reply);
+ if (qemuMonitorJSONCommand(mon, cmd, &reply) < 0)
+ goto cleanup;
- if (ret == 0 &&
- qemuMonitorJSONHasError(reply, "DeviceNotFound")) {
+ if (qemuMonitorJSONHasError(reply, "DeviceNotFound")) {
+ ret = 0;
goto cleanup;
}
- if (ret == 0)
- ret = qemuMonitorJSONCheckError(cmd, reply);
-
- if (ret < 0)
+ if (qemuMonitorJSONCheckError(cmd, reply) < 0)
goto cleanup;
- ret = -1;
-
if (!(data = virJSONValueObjectGetArray(reply, "return"))) {
virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
_("device-list-properties reply was missing return data"));
qemuMonitorJSONGetTargetArch(qemuMonitorPtr mon)
{
char *ret = NULL;
- int rv;
const char *arch;
virJSONValuePtr cmd;
virJSONValuePtr reply = NULL;
if (!(cmd = qemuMonitorJSONMakeCommand("query-target", NULL)))
return NULL;
- rv = qemuMonitorJSONCommand(mon, cmd, &reply);
-
- if (rv == 0)
- rv = qemuMonitorJSONCheckError(cmd, reply);
+ if (qemuMonitorJSONCommand(mon, cmd, &reply) < 0)
+ goto cleanup;
- if (rv < 0)
+ if (qemuMonitorJSONCheckError(cmd, reply) < 0)
goto cleanup;
if (!(data = virJSONValueObjectGetObject(reply, "return"))) {
qemuMonitorJSONGetMigrationCapabilities(qemuMonitorPtr mon,
char ***capabilities)
{
- int ret;
+ int ret = -1;
virJSONValuePtr cmd;
virJSONValuePtr reply = NULL;
virJSONValuePtr caps;
NULL)))
return -1;
- ret = qemuMonitorJSONCommand(mon, cmd, &reply);
+ if (qemuMonitorJSONCommand(mon, cmd, &reply) < 0)
+ goto cleanup;
- if (ret == 0) {
- if (qemuMonitorJSONHasError(reply, "CommandNotFound"))
- goto cleanup;
- ret = qemuMonitorJSONCheckError(cmd, reply);
+ if (qemuMonitorJSONHasError(reply, "CommandNotFound")) {
+ ret = 0;
+ goto cleanup;
}
- if (ret < 0)
+ if (qemuMonitorJSONCheckError(cmd, reply) < 0)
goto cleanup;
- ret = -1;
-
if (!(caps = virJSONValueObjectGetArray(reply, "return")) ||
(n = virJSONValueArraySize(caps)) < 0) {
virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
caps = NULL;
- if ((ret = qemuMonitorJSONCommand(mon, cmd, &reply)) < 0)
+ if (qemuMonitorJSONCommand(mon, cmd, &reply) < 0)
goto cleanup;
- ret = qemuMonitorJSONCheckError(cmd, reply);
+ if (qemuMonitorJSONCheckError(cmd, reply) < 0)
+ goto cleanup;
+ ret = 0;
cleanup:
virJSONValueFree(caps);
virJSONValueFree(cap);
qemuMonitorJSONGetGICCapabilities(qemuMonitorPtr mon,
virGICCapability **capabilities)
{
- int ret;
+ int ret = -1;
virJSONValuePtr cmd;
virJSONValuePtr reply = NULL;
virJSONValuePtr caps;
NULL)))
return -1;
- ret = qemuMonitorJSONCommand(mon, cmd, &reply);
+ if (qemuMonitorJSONCommand(mon, cmd, &reply) < 0)
+ goto cleanup;
- if (ret == 0) {
- /* If the 'query-gic-capabilities' QMP command was not available
- * we simply successfully return zero capabilities.
- * This is the case for QEMU <2.6 and all non-ARM architectures */
- if (qemuMonitorJSONHasError(reply, "CommandNotFound"))
- goto cleanup;
- ret = qemuMonitorJSONCheckError(cmd, reply);
+ /* If the 'query-gic-capabilities' QMP command was not available
+ * we simply successfully return zero capabilities.
+ * This is the case for QEMU <2.6 and all non-ARM architectures */
+ if (qemuMonitorJSONHasError(reply, "CommandNotFound")) {
+ ret = 0;
+ goto cleanup;
}
- if (ret < 0)
+ if (qemuMonitorJSONCheckError(cmd, reply) < 0)
goto cleanup;
- ret = -1;
-
if (!(caps = virJSONValueObjectGetArray(reply, "return")) ||
(n = virJSONValueArraySize(caps)) < 0) {
virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
NULL)))
return ret;
- ret = qemuMonitorJSONCommand(mon, cmd, &reply);
+ if (qemuMonitorJSONCommand(mon, cmd, &reply) < 0)
+ goto cleanup;
- if (ret == 0)
- ret = qemuMonitorJSONCheckError(cmd, reply);
+ if (qemuMonitorJSONCheckError(cmd, reply) < 0)
+ goto cleanup;
+ ret = 0;
+ cleanup:
virJSONValueFree(cmd);
virJSONValueFree(reply);
return ret;
NULL)))
return ret;
- ret = qemuMonitorJSONCommand(mon, cmd, &reply);
+ if (qemuMonitorJSONCommand(mon, cmd, &reply) < 0)
+ goto cleanup;
- if (ret == 0)
- ret = qemuMonitorJSONCheckError(cmd, reply);
+ if (qemuMonitorJSONCheckError(cmd, reply) < 0)
+ goto cleanup;
+ ret = 0;
+ cleanup:
virJSONValueFree(cmd);
virJSONValueFree(reply);
return ret;
qemuMonitorJSONGetStringArray(qemuMonitorPtr mon, const char *qmpCmd,
char ***array)
{
- int ret;
+ int ret = -1;
virJSONValuePtr cmd;
virJSONValuePtr reply = NULL;
virJSONValuePtr data;
if (!(cmd = qemuMonitorJSONMakeCommand(qmpCmd, NULL)))
return -1;
- ret = qemuMonitorJSONCommand(mon, cmd, &reply);
-
- if (ret == 0) {
- if (qemuMonitorJSONHasError(reply, "CommandNotFound"))
- goto cleanup;
+ if (qemuMonitorJSONCommand(mon, cmd, &reply) < 0)
+ goto cleanup;
- ret = qemuMonitorJSONCheckError(cmd, reply);
+ if (qemuMonitorJSONHasError(reply, "CommandNotFound")) {
+ ret = 0;
+ goto cleanup;
}
- if (ret < 0)
+ if (qemuMonitorJSONCheckError(cmd, reply) < 0)
goto cleanup;
- ret = -1;
-
if (!(data = virJSONValueObjectGetArray(reply, "return"))) {
virReportError(VIR_ERR_INTERNAL_ERROR,
_("%s reply was missing return data"),
NULL)))
return ret;
- ret = qemuMonitorJSONCommand(mon, cmd, &reply);
+ if (qemuMonitorJSONCommand(mon, cmd, &reply) < 0)
+ goto cleanup;
- if (ret == 0)
- ret = qemuMonitorJSONCheckError(cmd, reply);
+ if (qemuMonitorJSONCheckError(cmd, reply) < 0)
+ goto cleanup;
+ ret = 0;
+ cleanup:
virJSONValueFree(cmd);
virJSONValueFree(reply);
return ret;
NULL)))
return ret;
- ret = qemuMonitorJSONCommand(mon, cmd, &reply);
+ if (qemuMonitorJSONCommand(mon, cmd, &reply) < 0)
+ goto cleanup;
- if (ret == 0)
- ret = qemuMonitorJSONCheckError(cmd, reply);
+ if (qemuMonitorJSONCheckError(cmd, reply) < 0)
+ goto cleanup;
+ ret = 0;
+ cleanup:
virJSONValueFree(cmd);
virJSONValueFree(reply);
return ret;
if (!(cmd = qemuMonitorJSONMakeCommand("query-iothreads", NULL)))
return ret;
- ret = qemuMonitorJSONCommand(mon, cmd, &reply);
-
- if (ret == 0)
- ret = qemuMonitorJSONCheckError(cmd, reply);
-
- if (ret < 0)
+ if (qemuMonitorJSONCommand(mon, cmd, &reply) < 0)
goto cleanup;
- ret = -1;
+ if (qemuMonitorJSONCheckError(cmd, reply) < 0)
+ goto cleanup;
if (!(data = virJSONValueObjectGetArray(reply, "return"))) {
virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
if (!(cmd = qemuMonitorJSONMakeCommand("query-memory-devices", NULL)))
return -1;
- ret = qemuMonitorJSONCommand(mon, cmd, &reply);
-
- if (ret == 0) {
- if (qemuMonitorJSONHasError(reply, "CommandNotFound")) {
- ret = -2;
- goto cleanup;
- }
+ if (qemuMonitorJSONCommand(mon, cmd, &reply) < 0)
+ goto cleanup;
- ret = qemuMonitorJSONCheckError(cmd, reply);
+ if (qemuMonitorJSONHasError(reply, "CommandNotFound")) {
+ ret = -2;
+ goto cleanup;
}
- if (ret < 0)
+ if (qemuMonitorJSONCheckError(cmd, reply) < 0)
goto cleanup;
- ret = -1;
-
if (!(data = virJSONValueObjectGetArray(reply, "return"))) {
virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
_("query-memory-devices reply was missing return data"));