]> xenbits.xensource.com Git - libvirt.git/commitdiff
qemu: Move migration parameters JSON parsing
authorJiri Denemark <jdenemar@redhat.com>
Thu, 15 Mar 2018 17:06:01 +0000 (18:06 +0100)
committerJiri Denemark <jdenemar@redhat.com>
Tue, 17 Apr 2018 08:46:23 +0000 (10:46 +0200)
We want to have all migration parameters parsing and formatting at once
place, i.e., in qemu_migration_params.c.

Signed-off-by: Jiri Denemark <jdenemar@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
src/qemu/qemu_migration_params.c
src/qemu/qemu_monitor.c
src/qemu/qemu_monitor.h
src/qemu/qemu_monitor_json.c
src/qemu/qemu_monitor_json.h

index cadb402b0fa0d62ef4229e1f85c9d9b1a54bfa8a..845234c34bb7e7686047bc08070ea6a52289993f 100644 (file)
@@ -314,6 +314,67 @@ qemuMigrationParamsDump(qemuMigrationParamsPtr migParams,
 }
 
 
+static qemuMigrationParamsPtr
+qemuMigrationParamsFromJSON(virJSONValuePtr params)
+{
+    qemuMigrationParamsPtr migParams = NULL;
+
+    if (!(migParams = qemuMigrationParamsNew()))
+        return NULL;
+
+    if (!params)
+        return migParams;
+
+#define PARSE_SET(API, VAR, FIELD) \
+    do { \
+        if (API(params, FIELD, &migParams->params.VAR) == 0) \
+            migParams->params.VAR ## _set = true; \
+    } while (0)
+
+#define PARSE_INT(VAR, FIELD) \
+    PARSE_SET(virJSONValueObjectGetNumberInt, VAR, FIELD)
+
+#define PARSE_ULONG(VAR, FIELD) \
+    PARSE_SET(virJSONValueObjectGetNumberUlong, VAR, FIELD)
+
+#define PARSE_BOOL(VAR, FIELD) \
+    PARSE_SET(virJSONValueObjectGetBoolean, VAR, FIELD)
+
+#define PARSE_STR(VAR, FIELD) \
+    do { \
+        const char *str; \
+        if ((str = virJSONValueObjectGetString(params, FIELD))) { \
+            if (VIR_STRDUP(migParams->params.VAR, str) < 0) \
+                goto error; \
+        } \
+    } 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(tlsCreds, "tls-creds");
+    PARSE_STR(tlsHostname, "tls-hostname");
+    PARSE_ULONG(maxBandwidth, "max-bandwidth");
+    PARSE_ULONG(downtimeLimit, "downtime-limit");
+    PARSE_BOOL(blockIncremental, "block-incremental");
+    PARSE_ULONG(xbzrleCacheSize, "xbzrle-cache-size");
+
+#undef PARSE_SET
+#undef PARSE_INT
+#undef PARSE_ULONG
+#undef PARSE_BOOL
+#undef PARSE_STR
+
+    return migParams;
+
+ error:
+    qemuMigrationParamsFree(migParams);
+    return NULL;
+}
+
+
 /**
  * qemuMigrationParamsApply
  * @driver: qemu driver
@@ -527,28 +588,27 @@ qemuMigrationParamsFetch(virQEMUDriverPtr driver,
                          qemuMigrationParamsPtr *migParams)
 {
     qemuDomainObjPrivatePtr priv = vm->privateData;
-    qemuMigrationParamsPtr params = NULL;
+    virJSONValuePtr jsonParams = NULL;
     int ret = -1;
     int rc;
 
     *migParams = NULL;
 
-    if (!(params = qemuMigrationParamsNew()))
-        return -1;
-
     if (qemuDomainObjEnterMonitorAsync(driver, vm, asyncJob) < 0)
         goto cleanup;
 
-    rc = qemuMonitorGetMigrationParams(priv->mon, &params->params);
+    rc = qemuMonitorGetMigrationParams(priv->mon, &jsonParams);
 
     if (qemuDomainObjExitMonitor(driver, vm) < 0 || rc < 0)
         goto cleanup;
 
-    VIR_STEAL_PTR(*migParams, params);
+    if (!(*migParams = qemuMigrationParamsFromJSON(jsonParams)))
+        goto cleanup;
+
     ret = 0;
 
  cleanup:
-    qemuMigrationParamsFree(params);
+    virJSONValueFree(jsonParams);
     return ret;
 }
 
index 008d7c1ca960521a17a117aa14f45bf3dd0b13fb..716189b6292386927f40c1057173c4264888f95f 100644 (file)
@@ -2622,9 +2622,20 @@ qemuMonitorSetMigrationCacheSize(qemuMonitorPtr mon,
 }
 
 
+/**
+ * qemuMonitorGetMigrationParams:
+ * @mon: Pointer to the monitor object.
+ * @params: Where to store migration parameters.
+ *
+ * If QEMU does not support querying migration parameters, the function will
+ * set @params to NULL and return 0 (success). The caller is responsible for
+ * freeing @params.
+ *
+ * Returns 0 on success, -1 on error.
+ */
 int
 qemuMonitorGetMigrationParams(qemuMonitorPtr mon,
-                              qemuMonitorMigrationParamsPtr params)
+                              virJSONValuePtr *params)
 {
     QEMU_CHECK_MONITOR_JSON(mon);
 
index cc4a6647e6d008816516861eb2da17ae4bb85736..82ede6650519d0d07ea5605cfb3559485b3d7a2f 100644 (file)
@@ -679,7 +679,7 @@ struct _qemuMonitorMigrationParams {
 };
 
 int qemuMonitorGetMigrationParams(qemuMonitorPtr mon,
-                                  qemuMonitorMigrationParamsPtr params);
+                                  virJSONValuePtr *params);
 int qemuMonitorSetMigrationParams(qemuMonitorPtr mon,
                                   qemuMonitorMigrationParamsPtr params);
 
index acc126629e7391e8b4136375c6886d2d09d01acc..7de1ade28ec6e9a009dbed910a08792674796e8e 100644 (file)
@@ -2774,14 +2774,13 @@ qemuMonitorJSONSetMigrationCacheSize(qemuMonitorPtr mon,
 
 int
 qemuMonitorJSONGetMigrationParams(qemuMonitorPtr mon,
-                                  qemuMonitorMigrationParamsPtr params)
+                                  virJSONValuePtr *params)
 {
     int ret = -1;
-    virJSONValuePtr result;
     virJSONValuePtr cmd = NULL;
     virJSONValuePtr reply = NULL;
 
-    memset(params, 0, sizeof(*params));
+    *params = NULL;
 
     if (!(cmd = qemuMonitorJSONMakeCommand("query-migrate-parameters", NULL)))
         return -1;
@@ -2797,51 +2796,9 @@ qemuMonitorJSONGetMigrationParams(qemuMonitorPtr mon,
     if (qemuMonitorJSONCheckReply(cmd, reply, VIR_JSON_TYPE_OBJECT) < 0)
         goto cleanup;
 
-    result = virJSONValueObjectGet(reply, "return");
-
-#define PARSE_SET(API, VAR, FIELD) \
-    do { \
-        if (API(result, FIELD, &params->VAR) == 0) \
-            params->VAR ## _set = true; \
-    } while (0)
-
-#define PARSE_INT(VAR, FIELD) \
-    PARSE_SET(virJSONValueObjectGetNumberInt, VAR, FIELD)
-
-#define PARSE_ULONG(VAR, FIELD) \
-    PARSE_SET(virJSONValueObjectGetNumberUlong, VAR, FIELD)
-
-#define PARSE_BOOL(VAR, FIELD) \
-    PARSE_SET(virJSONValueObjectGetBoolean, 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(tlsCreds, "tls-creds");
-    PARSE_STR(tlsHostname, "tls-hostname");
-    PARSE_ULONG(maxBandwidth, "max-bandwidth");
-    PARSE_ULONG(downtimeLimit, "downtime-limit");
-    PARSE_BOOL(blockIncremental, "block-incremental");
-    PARSE_ULONG(xbzrleCacheSize, "xbzrle-cache-size");
-
-#undef PARSE_SET
-#undef PARSE_INT
-#undef PARSE_ULONG
-#undef PARSE_BOOL
-#undef PARSE_STR
-
+    *params = virJSONValueObjectStealObject(reply, "return");
     ret = 0;
+
  cleanup:
     virJSONValueFree(cmd);
     virJSONValueFree(reply);
index a73e98815c4749ae6a5af9f8d110e02d17044fa6..a52f0a1955ef56870b161eea0870d94405aea130 100644 (file)
@@ -135,7 +135,7 @@ int qemuMonitorJSONSetMigrationCacheSize(qemuMonitorPtr mon,
                                          unsigned long long cacheSize);
 
 int qemuMonitorJSONGetMigrationParams(qemuMonitorPtr mon,
-                                      qemuMonitorMigrationParamsPtr params);
+                                      virJSONValuePtr *params);
 int qemuMonitorJSONSetMigrationParams(qemuMonitorPtr mon,
                                       qemuMonitorMigrationParamsPtr params);