[libvirt] [PATCH 02/12] qemu: Use macro for parsing string migration parameters

Jiri Denemark jdenemar at redhat.com
Thu Oct 26 22:03:51 UTC 2017


Signed-off-by: Jiri Denemark <jdenemar at redhat.com>
---
 src/qemu/qemu_monitor_json.c | 23 ++++++++++++-----------
 1 file changed, 12 insertions(+), 11 deletions(-)

diff --git a/src/qemu/qemu_monitor_json.c b/src/qemu/qemu_monitor_json.c
index 16554d5b2..cb0bb0d0d 100644
--- a/src/qemu/qemu_monitor_json.c
+++ b/src/qemu/qemu_monitor_json.c
@@ -2659,7 +2659,6 @@ qemuMonitorJSONGetMigrationParams(qemuMonitorPtr mon,
     virJSONValuePtr result;
     virJSONValuePtr cmd = NULL;
     virJSONValuePtr reply = NULL;
-    const char *tlsStr = NULL;
 
     memset(params, 0, sizeof(*params));
 
@@ -2688,29 +2687,31 @@ qemuMonitorJSONGetMigrationParams(qemuMonitorPtr mon,
 #define PARSE_INT(VAR, FIELD)                                               \
     PARSE_SET(virJSONValueObjectGetNumberInt, VAR, FIELD)
 
+#define PARSE_STR(VAR, FIELD)                                               \
+    do {                                                                    \
+        const char *str;                                                    \
+        if ((str = virJSONValueObjectGetString(result, FIELD))) {           \
+            if (VIR_STRDUP(params->VAR, str) < 0)                           \
+                goto cleanup;                                               \
+        }                                                                   \
+    } while (0)
+
     PARSE_INT(compressLevel, "compress-level");
     PARSE_INT(compressThreads, "compress-threads");
     PARSE_INT(decompressThreads, "decompress-threads");
     PARSE_INT(cpuThrottleInitial, "cpu-throttle-initial");
     PARSE_INT(cpuThrottleIncrement, "cpu-throttle-increment");
+    PARSE_STR(migrateTLSAlias, "tls-creds");
+    PARSE_STR(migrateTLSHostname, "tls-hostname");
 
 #undef PARSE_SET
 #undef PARSE_INT
+#undef PARSE_STR
 
     if (virJSONValueObjectGetNumberUlong(result, "downtime-limit",
                                          &params->downtimeLimit) == 0)
         params->downtimeLimit_set = true;
 
-    if ((tlsStr = virJSONValueObjectGetString(result, "tls-creds"))) {
-        if (VIR_STRDUP(params->migrateTLSAlias, tlsStr) < 0)
-            goto cleanup;
-    }
-
-    if ((tlsStr = virJSONValueObjectGetString(result, "tls-hostname"))) {
-        if (VIR_STRDUP(params->migrateTLSHostname, tlsStr) < 0)
-            goto cleanup;
-    }
-
     ret = 0;
  cleanup:
     virJSONValueFree(cmd);
-- 
2.14.3




More information about the libvir-list mailing list