int
qemuMonitorJSONSetCapabilities(qemuMonitorPtr mon)
{
- int ret;
+ int ret = -1;
virJSONValuePtr cmd = qemuMonitorJSONMakeCommand("qmp_capabilities", 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;
int
qemuMonitorJSONStopCPUs(qemuMonitorPtr mon)
{
- int ret;
+ int ret = -1;
virJSONValuePtr cmd = qemuMonitorJSONMakeCommand("stop", 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;
bool *running,
virDomainPausedReason *reason)
{
- int ret;
+ int ret = -1;
const char *status;
virJSONValuePtr cmd;
virJSONValuePtr reply = NULL;
if (!(cmd = qemuMonitorJSONMakeCommand("query-status", 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 qemuMonitorJSONSystemPowerdown(qemuMonitorPtr mon)
{
- int ret;
+ int ret = -1;
virJSONValuePtr cmd = qemuMonitorJSONMakeCommand("system_powerdown", 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;
virDomainNetInterfaceLinkState state)
{
- int ret;
+ int ret = -1;
virJSONValuePtr reply = NULL;
virJSONValuePtr cmd = qemuMonitorJSONMakeCommand("set_link",
"s:name", name,
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);
-
return ret;
}
int qemuMonitorJSONSystemReset(qemuMonitorPtr mon)
{
- int ret;
+ int ret = -1;
virJSONValuePtr cmd = qemuMonitorJSONMakeCommand("system_reset", 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;
int qemuMonitorJSONGetCPUInfo(qemuMonitorPtr mon,
int **pids)
{
- int ret;
+ int ret = -1;
virJSONValuePtr cmd = qemuMonitorJSONMakeCommand("query-cpus",
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 = qemuMonitorJSONExtractCPUInfo(reply, pids);
+ if (qemuMonitorJSONCheckError(cmd, reply) < 0)
+ goto cleanup;
+ ret = qemuMonitorJSONExtractCPUInfo(reply, pids);
+ cleanup:
virJSONValueFree(cmd);
virJSONValueFree(reply);
return ret;
int qemuMonitorJSONGetVirtType(qemuMonitorPtr mon,
virDomainVirtType *virtType)
{
- int ret;
+ int ret = -1;
virJSONValuePtr cmd = qemuMonitorJSONMakeCommand("query-kvm",
NULL);
virJSONValuePtr reply = NULL;
+ virJSONValuePtr data;
+ bool val = false;
*virtType = VIR_DOMAIN_VIRT_QEMU;
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) {
- virJSONValuePtr data;
- bool val = false;
- if (!(data = virJSONValueObjectGetObject(reply, "return"))) {
- virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
- _("info kvm reply was missing return data"));
- ret = -1;
- goto cleanup;
- }
+ 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) {
- virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
- _("info kvm reply missing 'enabled' field"));
- ret = -1;
- goto cleanup;
- }
- if (val)
- *virtType = VIR_DOMAIN_VIRT_KVM;
+ if (virJSONValueObjectGetBoolean(data, "enabled", &val) < 0) {
+ virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
+ _("info kvm reply missing 'enabled' field"));
+ goto cleanup;
}
+ if (val)
+ *virtType = VIR_DOMAIN_VIRT_KVM;
+
+ ret = 0;
cleanup:
virJSONValueFree(cmd);
virJSONValueFree(reply);
qemuMonitorJSONGetBalloonInfo(qemuMonitorPtr mon,
unsigned long long *currmem)
{
- int ret;
+ int ret = -1;
+ virJSONValuePtr data;
+ unsigned long long mem;
virJSONValuePtr cmd = qemuMonitorJSONMakeCommand("query-balloon",
NULL);
virJSONValuePtr reply = NULL;
if (!cmd)
return -1;
- ret = qemuMonitorJSONCommand(mon, cmd, &reply);
-
- if (ret == 0) {
- /* See if balloon soft-failed */
- if (qemuMonitorJSONHasError(reply, "DeviceNotActive") ||
- qemuMonitorJSONHasError(reply, "KVMMissingCap"))
- goto cleanup;
-
- /* See if any other fatal error occurred */
- ret = qemuMonitorJSONCheckError(cmd, reply);
+ if (qemuMonitorJSONCommand(mon, cmd, &reply) < 0)
+ goto cleanup;
- /* Success */
- if (ret == 0) {
- virJSONValuePtr data;
- unsigned long long mem;
+ /* See if balloon soft-failed */
+ if (qemuMonitorJSONHasError(reply, "DeviceNotActive") ||
+ qemuMonitorJSONHasError(reply, "KVMMissingCap")) {
+ ret = 0;
+ goto cleanup;
+ }
- if (!(data = virJSONValueObjectGetObject(reply, "return"))) {
- virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
- _("info balloon reply was missing return data"));
- ret = -1;
- goto cleanup;
- }
+ /* See if any other fatal error occurred */
+ if (qemuMonitorJSONCheckError(cmd, reply) < 0)
+ goto cleanup;
- if (virJSONValueObjectGetNumberUlong(data, "actual", &mem) < 0) {
- virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
- _("info balloon reply was missing balloon data"));
- ret = -1;
- goto cleanup;
- }
+ /* Success */
+ if (!(data = virJSONValueObjectGetObject(reply, "return"))) {
+ virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
+ _("info balloon reply was missing return data"));
+ goto cleanup;
+ }
- *currmem = (mem/1024);
- ret = 1;
- }
+ if (virJSONValueObjectGetNumberUlong(data, "actual", &mem) < 0) {
+ virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
+ _("info balloon reply was missing balloon data"));
+ goto cleanup;
}
+ *currmem = (mem/1024);
+ ret = 1;
cleanup:
virJSONValueFree(cmd);
virJSONValueFree(reply);
virDomainMemoryStatPtr stats,
unsigned int nr_stats)
{
- int ret;
+ int ret = -1;
virJSONValuePtr cmd = NULL;
virJSONValuePtr reply = NULL;
virJSONValuePtr data;
NULL)))
goto cleanup;
- if ((ret = qemuMonitorJSONCommand(mon, cmd, &reply)) < 0)
+ if (qemuMonitorJSONCommand(mon, cmd, &reply) < 0)
goto cleanup;
if ((data = virJSONValueObjectGetObject(reply, "error"))) {
}
}
- if ((ret = qemuMonitorJSONCheckError(cmd, reply)) < 0)
+ if (qemuMonitorJSONCheckError(cmd, reply) < 0)
goto cleanup;
if (!(data = virJSONValueObjectGetObject(reply, "return"))) {
VIR_DOMAIN_MEMORY_STAT_UNUSED, 1024);
GET_BALLOON_STATS("stat-total-memory",
VIR_DOMAIN_MEMORY_STAT_AVAILABLE, 1024);
-
-
+ ret = got;
cleanup:
virJSONValueFree(cmd);
virJSONValueFree(reply);
-
- if (got > 0)
- ret = got;
-
return ret;
}
#undef GET_BALLOON_STATS
int qemuMonitorJSONGetBlockInfo(qemuMonitorPtr mon,
virHashTablePtr table)
{
- int ret;
+ int ret = -1;
size_t i;
virJSONValuePtr cmd = qemuMonitorJSONMakeCommand("query-block",
if (!cmd)
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 (!(devices = virJSONValueObjectGetArray(reply, "return"))) {
virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
}
ret = 0;
-
cleanup:
virJSONValueFree(cmd);
virJSONValueFree(reply);
const char *device,
unsigned long long size)
{
- int ret;
+ int ret = -1;
virJSONValuePtr cmd;
virJSONValuePtr reply = NULL;
if (!cmd)
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 (qemuMonitorJSONCheckError(cmd, reply) < 0)
+ goto cleanup;
+
+ ret = 0;
cleanup:
virJSONValueFree(cmd);
virJSONValueFree(reply);
int qemuMonitorJSONSetVNCPassword(qemuMonitorPtr mon,
const char *password)
{
- int ret;
+ int ret = -1;
virJSONValuePtr cmd = qemuMonitorJSONMakeCommand("change",
"s:device", "vnc",
"s:target", "password",
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 *password,
const char *action_if_connected)
{
- int ret;
+ int ret = -1;
virJSONValuePtr cmd = qemuMonitorJSONMakeCommand("set_password",
"s:protocol", protocol,
"s:password", password,
if (!cmd)
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 (qemuMonitorJSONCheckError(cmd, reply) < 0)
+ goto cleanup;
+
+ ret = 0;
cleanup:
virJSONValueFree(cmd);
virJSONValueFree(reply);
const char *protocol,
const char *expire_time)
{
- int ret;
+ int ret = -1;
virJSONValuePtr cmd = qemuMonitorJSONMakeCommand("expire_password",
"s:protocol", protocol,
"s:time", expire_time,
if (!cmd)
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 (qemuMonitorJSONCheckError(cmd, reply) < 0)
+ goto cleanup;
+
+ ret = 0;
cleanup:
virJSONValueFree(cmd);
virJSONValueFree(reply);
qemuMonitorJSONSetBalloon(qemuMonitorPtr mon,
unsigned long long newmem)
{
- int ret;
+ int ret = -1;
virJSONValuePtr cmd = qemuMonitorJSONMakeCommand("balloon",
"U:value", newmem * 1024,
NULL);
if (!cmd)
return -1;
- ret = qemuMonitorJSONCommand(mon, cmd, &reply);
-
- if (ret == 0) {
- /* See if balloon soft-failed */
- if (qemuMonitorJSONHasError(reply, "DeviceNotActive") ||
- qemuMonitorJSONHasError(reply, "KVMMissingCap"))
- goto cleanup;
-
- /* See if any other fatal error occurred */
- ret = qemuMonitorJSONCheckError(cmd, reply);
+ if (qemuMonitorJSONCommand(mon, cmd, &reply) < 0)
+ goto cleanup;
- /* Real success */
- if (ret == 0)
- ret = 1;
+ /* See if balloon soft-failed */
+ if (qemuMonitorJSONHasError(reply, "DeviceNotActive") ||
+ qemuMonitorJSONHasError(reply, "KVMMissingCap")) {
+ ret = 0;
+ goto cleanup;
}
+ /* See if any other fatal error occurred */
+ if (qemuMonitorJSONCheckError(cmd, reply) < 0)
+ goto cleanup;
+
+ /* Real success */
+ ret = 1;
cleanup:
virJSONValueFree(cmd);
virJSONValueFree(reply);