[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]

[libvirt] [PATCH 4/4] qemu_monitor_json: Follow refactor



This is going to be squashed into previous commit.

Signed-off-by: Michal Privoznik <mprivozn redhat com>
---
 src/qemu/qemu_monitor_json.c | 212 +++++++++++++++++++------------------------
 1 file changed, 95 insertions(+), 117 deletions(-)

diff --git a/src/qemu/qemu_monitor_json.c b/src/qemu/qemu_monitor_json.c
index c99d300..74d6346 100644
--- a/src/qemu/qemu_monitor_json.c
+++ b/src/qemu/qemu_monitor_json.c
@@ -5197,7 +5197,7 @@ int qemuMonitorJSONGetKVMState(qemuMonitorPtr mon,
                                bool *enabled,
                                bool *present)
 {
-    int ret;
+    int ret = -1;
     virJSONValuePtr cmd = NULL;
     virJSONValuePtr reply = NULL;
     virJSONValuePtr data = NULL;
@@ -5208,20 +5208,17 @@ int qemuMonitorJSONGetKVMState(qemuMonitorPtr mon,
     if (!(cmd = qemuMonitorJSONMakeCommand("query-kvm", 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 (!(data = virJSONValueObjectGetObject(reply, "return"))) {
         virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
                        _("query-kvm reply was missing return data"));
@@ -5247,7 +5244,7 @@ int qemuMonitorJSONGetKVMState(qemuMonitorPtr mon,
 int qemuMonitorJSONGetObjectTypes(qemuMonitorPtr mon,
                                   char ***types)
 {
-    int ret;
+    int ret = -1;
     virJSONValuePtr cmd;
     virJSONValuePtr reply = NULL;
     virJSONValuePtr data;
@@ -5260,15 +5257,11 @@ int qemuMonitorJSONGetObjectTypes(qemuMonitorPtr mon,
     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",
@@ -5316,7 +5309,7 @@ int qemuMonitorJSONGetObjectListPaths(qemuMonitorPtr mon,
                                       const char *path,
                                       qemuMonitorJSONListPathPtr **paths)
 {
-    int ret;
+    int ret = -1;
     virJSONValuePtr cmd;
     virJSONValuePtr reply = NULL;
     virJSONValuePtr data;
@@ -5331,15 +5324,11 @@ int qemuMonitorJSONGetObjectListPaths(qemuMonitorPtr mon,
                                            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",
@@ -5416,7 +5405,7 @@ int qemuMonitorJSONGetObjectProperty(qemuMonitorPtr mon,
                                      const char *property,
                                      qemuMonitorJSONObjectPropertyPtr prop)
 {
-    int ret;
+    int ret = -1;
     virJSONValuePtr cmd;
     virJSONValuePtr reply = NULL;
     virJSONValuePtr data;
@@ -5428,15 +5417,11 @@ int qemuMonitorJSONGetObjectProperty(qemuMonitorPtr mon,
                                            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");
 
@@ -5508,9 +5493,9 @@ int qemuMonitorJSONSetObjectProperty(qemuMonitorPtr mon,
     virJSONValuePtr reply = NULL;
 
     switch ((qemuMonitorJSONObjectPropertyType) prop->type) {
-    /* Simple cases of boolean, int, long, uint, ulong, double, and string
-     * will receive return value as part of {"return": xxx} statement
-     */
+        /* Simple cases of boolean, int, long, uint, ulong, double, and string
+         * will receive return value as part of {"return": xxx} statement
+         */
     case QEMU_MONITOR_OBJECT_PROPERTY_BOOLEAN:
         MAKE_SET_CMD("b:value", prop->val.b);
         break;
@@ -5542,9 +5527,13 @@ int qemuMonitorJSONSetObjectProperty(qemuMonitorPtr mon,
     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);
@@ -5558,7 +5547,7 @@ int qemuMonitorJSONGetObjectProps(qemuMonitorPtr mon,
                                   const char *type,
                                   char ***props)
 {
-    int ret;
+    int ret = -1;
     virJSONValuePtr cmd;
     virJSONValuePtr reply = NULL;
     virJSONValuePtr data;
@@ -5573,21 +5562,17 @@ int qemuMonitorJSONGetObjectProps(qemuMonitorPtr mon,
                                            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"));
@@ -5634,7 +5619,6 @@ char *
 qemuMonitorJSONGetTargetArch(qemuMonitorPtr mon)
 {
     char *ret = NULL;
-    int rv;
     const char *arch;
     virJSONValuePtr cmd;
     virJSONValuePtr reply = NULL;
@@ -5643,12 +5627,10 @@ qemuMonitorJSONGetTargetArch(qemuMonitorPtr mon)
     if (!(cmd = qemuMonitorJSONMakeCommand("query-target", NULL)))
         return NULL;
 
-    rv = qemuMonitorJSONCommand(mon, cmd, &reply);
+    if (qemuMonitorJSONCommand(mon, cmd, &reply) < 0)
+        goto cleanup;
 
-    if (rv == 0)
-        rv = qemuMonitorJSONCheckError(cmd, reply);
-
-    if (rv < 0)
+    if (qemuMonitorJSONCheckError(cmd, reply) < 0)
         goto cleanup;
 
     if (!(data = virJSONValueObjectGetObject(reply, "return"))) {
@@ -5676,7 +5658,7 @@ int
 qemuMonitorJSONGetMigrationCapabilities(qemuMonitorPtr mon,
                                         char ***capabilities)
 {
-    int ret;
+    int ret = -1;
     virJSONValuePtr cmd;
     virJSONValuePtr reply = NULL;
     virJSONValuePtr caps;
@@ -5690,19 +5672,17 @@ qemuMonitorJSONGetMigrationCapabilities(qemuMonitorPtr mon,
                                            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",
@@ -5802,7 +5782,7 @@ qemuMonitorJSONSetMigrationCapability(qemuMonitorPtr mon,
 
     caps = NULL;
 
-    if ((ret = qemuMonitorJSONCommand(mon, cmd, &reply)) < 0)
+    if (qemuMonitorJSONCommand(mon, cmd, &reply) < 0)
         goto cleanup;
 
     ret = qemuMonitorJSONCheckError(cmd, reply);
@@ -5835,7 +5815,7 @@ int
 qemuMonitorJSONGetGICCapabilities(qemuMonitorPtr mon,
                                   virGICCapability **capabilities)
 {
-    int ret;
+    int ret = -1;
     virJSONValuePtr cmd;
     virJSONValuePtr reply = NULL;
     virJSONValuePtr caps;
@@ -5849,22 +5829,20 @@ qemuMonitorJSONGetGICCapabilities(qemuMonitorPtr mon,
                                            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",
@@ -6033,11 +6011,14 @@ qemuMonitorJSONNBDServerAdd(qemuMonitorPtr mon,
                                            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;
@@ -6054,11 +6035,14 @@ qemuMonitorJSONNBDServerStop(qemuMonitorPtr mon)
                                            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;
@@ -6069,7 +6053,7 @@ static int
 qemuMonitorJSONGetStringArray(qemuMonitorPtr mon, const char *qmpCmd,
                               char ***array)
 {
-    int ret;
+    int ret = -1;
     virJSONValuePtr cmd;
     virJSONValuePtr reply = NULL;
     virJSONValuePtr data;
@@ -6082,20 +6066,17 @@ qemuMonitorJSONGetStringArray(qemuMonitorPtr mon, const char *qmpCmd,
     if (!(cmd = qemuMonitorJSONMakeCommand(qmpCmd, 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 (!(data = virJSONValueObjectGetArray(reply, "return"))) {
         virReportError(VIR_ERR_INTERNAL_ERROR,
                        _("%s reply was missing return data"),
@@ -6331,11 +6312,14 @@ qemuMonitorJSONDetachCharDev(qemuMonitorPtr mon,
                                            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;
@@ -6575,11 +6559,14 @@ qemuMonitorJSONRTCResetReinjection(qemuMonitorPtr mon)
                                            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;
@@ -6608,15 +6595,11 @@ qemuMonitorJSONGetIOThreads(qemuMonitorPtr mon,
     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",
@@ -6700,22 +6683,17 @@ qemuMonitorJSONGetMemoryDeviceInfo(qemuMonitorPtr mon,
     if (!(cmd = qemuMonitorJSONMakeCommand("query-memory-devices", NULL)))
         return -1;
 
-    ret = qemuMonitorJSONCommand(mon, cmd, &reply);
+    if (qemuMonitorJSONCommand(mon, cmd, &reply) < 0)
+        goto cleanup;
 
-    if (ret == 0) {
-        if (qemuMonitorJSONHasError(reply, "CommandNotFound")) {
-            ret = -2;
-            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"));
-- 
2.8.1


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]