]> xenbits.xensource.com Git - libvirt.git/commitdiff
qemu: Move migration parameters JSON formatting
authorJiri Denemark <jdenemar@redhat.com>
Thu, 15 Mar 2018 19:24:05 +0000 (20:24 +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 one
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 845234c34bb7e7686047bc08070ea6a52289993f..560c2d3ea598e955536ebe1ba520eb0276ae164d 100644 (file)
@@ -375,6 +375,61 @@ qemuMigrationParamsFromJSON(virJSONValuePtr params)
 }
 
 
+static virJSONValuePtr
+qemuMigrationParamsToJSON(qemuMigrationParamsPtr migParams)
+{
+    virJSONValuePtr params = NULL;
+
+    if (!(params = virJSONValueNewObject()))
+        return NULL;
+
+#define APPEND(VALID, API, VAR, FIELD) \
+    do { \
+        if (VALID && API(params, FIELD, migParams->params.VAR) < 0) \
+            goto error; \
+    } while (0)
+
+#define APPEND_INT(VAR, FIELD) \
+    APPEND(migParams->params.VAR ## _set, \
+           virJSONValueObjectAppendNumberInt, VAR, FIELD)
+
+#define APPEND_STR(VAR, FIELD) \
+    APPEND(migParams->params.VAR, \
+           virJSONValueObjectAppendString, VAR, FIELD)
+
+#define APPEND_ULONG(VAR, FIELD) \
+    APPEND(migParams->params.VAR ## _set, \
+           virJSONValueObjectAppendNumberUlong, VAR, FIELD)
+
+#define APPEND_BOOL(VAR, FIELD) \
+    APPEND(migParams->params.VAR ## _set, \
+           virJSONValueObjectAppendBoolean, VAR, FIELD)
+
+    APPEND_INT(compressLevel, "compress-level");
+    APPEND_INT(compressThreads, "compress-threads");
+    APPEND_INT(decompressThreads, "decompress-threads");
+    APPEND_INT(cpuThrottleInitial, "cpu-throttle-initial");
+    APPEND_INT(cpuThrottleIncrement, "cpu-throttle-increment");
+    APPEND_STR(tlsCreds, "tls-creds");
+    APPEND_STR(tlsHostname, "tls-hostname");
+    APPEND_ULONG(maxBandwidth, "max-bandwidth");
+    APPEND_ULONG(downtimeLimit, "downtime-limit");
+    APPEND_BOOL(blockIncremental, "block-incremental");
+    APPEND_ULONG(xbzrleCacheSize, "xbzrle-cache-size");
+
+#undef APPEND
+#undef APPEND_INT
+#undef APPEND_STR
+#undef APPEND_ULONG
+
+    return params;
+
+ error:
+    virJSONValueFree(params);
+    return NULL;
+}
+
+
 /**
  * qemuMigrationParamsApply
  * @driver: qemu driver
@@ -394,7 +449,9 @@ qemuMigrationParamsApply(virQEMUDriverPtr driver,
 {
     qemuDomainObjPrivatePtr priv = vm->privateData;
     bool xbzrleCacheSize_old = false;
+    virJSONValuePtr params = NULL;
     int ret = -1;
+    int rc;
 
     if (qemuDomainObjEnterMonitorAsync(driver, vm, asyncJob) < 0)
         return -1;
@@ -417,9 +474,16 @@ qemuMigrationParamsApply(virQEMUDriverPtr driver,
         migParams->params.xbzrleCacheSize_set = false;
     }
 
-    if (qemuMonitorSetMigrationParams(priv->mon, &migParams->params) < 0)
+    if (!(params = qemuMigrationParamsToJSON(migParams)))
         goto cleanup;
 
+    if (virJSONValueObjectKeysNumber(params) > 0) {
+        rc = qemuMonitorSetMigrationParams(priv->mon, params);
+        params = NULL;
+        if (rc < 0)
+            goto cleanup;
+    }
+
     ret = 0;
 
  cleanup:
@@ -429,6 +493,8 @@ qemuMigrationParamsApply(virQEMUDriverPtr driver,
     if (xbzrleCacheSize_old)
         migParams->params.xbzrleCacheSize_set = true;
 
+    virJSONValueFree(params);
+
     return ret;
 }
 
index 716189b6292386927f40c1057173c4264888f95f..108d934444cfa63563e176c6b174c5f68f92b984 100644 (file)
@@ -2642,29 +2642,28 @@ qemuMonitorGetMigrationParams(qemuMonitorPtr mon,
     return qemuMonitorJSONGetMigrationParams(mon, params);
 }
 
+
+/**
+ * qemuMonitorSetMigrationParams:
+ * @mon: Pointer to the monitor object.
+ * @params: Migration parameters.
+ *
+ * The @params object is consumed and should not be referenced by the caller
+ * after this function returns.
+ *
+ * Returns 0 on success, -1 on error.
+ */
 int
 qemuMonitorSetMigrationParams(qemuMonitorPtr mon,
-                              qemuMonitorMigrationParamsPtr params)
-{
-    VIR_DEBUG("compressLevel=%d:%d compressThreads=%d:%d "
-              "decompressThreads=%d:%d cpuThrottleInitial=%d:%d "
-              "cpuThrottleIncrement=%d:%d tlsCreds=%s tlsHostname=%s "
-              "maxBandwidth=%d:%llu downtimeLimit=%d:%llu "
-              "blockIncremental=%d:%d xbzrleCacheSize=%d:%llu",
-              params->compressLevel_set, params->compressLevel,
-              params->compressThreads_set, params->compressThreads,
-              params->decompressThreads_set, params->decompressThreads,
-              params->cpuThrottleInitial_set, params->cpuThrottleInitial,
-              params->cpuThrottleIncrement_set, params->cpuThrottleIncrement,
-              NULLSTR(params->tlsCreds), NULLSTR(params->tlsHostname),
-              params->maxBandwidth_set, params->maxBandwidth,
-              params->downtimeLimit_set, params->downtimeLimit,
-              params->blockIncremental_set, params->blockIncremental,
-              params->xbzrleCacheSize_set, params->xbzrleCacheSize);
-
-    QEMU_CHECK_MONITOR_JSON(mon);
+                              virJSONValuePtr params)
+{
+    QEMU_CHECK_MONITOR_JSON_GOTO(mon, error);
 
     return qemuMonitorJSONSetMigrationParams(mon, params);
+
+ error:
+    virJSONValueFree(params);
+    return -1;
 }
 
 
index 82ede6650519d0d07ea5605cfb3559485b3d7a2f..73376a93eb7835d5f78c016e7a0313108882be9a 100644 (file)
@@ -681,7 +681,7 @@ struct _qemuMonitorMigrationParams {
 int qemuMonitorGetMigrationParams(qemuMonitorPtr mon,
                                   virJSONValuePtr *params);
 int qemuMonitorSetMigrationParams(qemuMonitorPtr mon,
-                                  qemuMonitorMigrationParamsPtr params);
+                                  virJSONValuePtr params);
 
 typedef enum {
     QEMU_MONITOR_MIGRATION_STATUS_INACTIVE,
index 7de1ade28ec6e9a009dbed910a08792674796e8e..b00bca7d46b5518648c450309b89a4dc0fd91f60 100644 (file)
@@ -2807,11 +2807,10 @@ qemuMonitorJSONGetMigrationParams(qemuMonitorPtr mon,
 
 int
 qemuMonitorJSONSetMigrationParams(qemuMonitorPtr mon,
-                                  qemuMonitorMigrationParamsPtr params)
+                                  virJSONValuePtr params)
 {
     int ret = -1;
     virJSONValuePtr cmd = NULL;
-    virJSONValuePtr args = NULL;
     virJSONValuePtr reply = NULL;
 
     if (!(cmd = virJSONValueNewObject()))
@@ -2821,56 +2820,9 @@ qemuMonitorJSONSetMigrationParams(qemuMonitorPtr mon,
                                        "migrate-set-parameters") < 0)
         goto cleanup;
 
-    if (!(args = virJSONValueNewObject()))
-        goto cleanup;
-
-#define APPEND(VALID, API, VAR, FIELD) \
-    do { \
-        if (VALID && API(args, FIELD, params->VAR) < 0) \
-            goto cleanup; \
-    } while (0)
-
-#define APPEND_INT(VAR, FIELD) \
-    APPEND(params->VAR ## _set, \
-           virJSONValueObjectAppendNumberInt, VAR, FIELD)
-
-#define APPEND_STR(VAR, FIELD) \
-    APPEND(params->VAR, \
-           virJSONValueObjectAppendString, VAR, FIELD)
-
-#define APPEND_ULONG(VAR, FIELD) \
-    APPEND(params->VAR ## _set, \
-           virJSONValueObjectAppendNumberUlong, VAR, FIELD)
-
-#define APPEND_BOOL(VAR, FIELD) \
-    APPEND(params->VAR ## _set, \
-           virJSONValueObjectAppendBoolean, VAR, FIELD)
-
-    APPEND_INT(compressLevel, "compress-level");
-    APPEND_INT(compressThreads, "compress-threads");
-    APPEND_INT(decompressThreads, "decompress-threads");
-    APPEND_INT(cpuThrottleInitial, "cpu-throttle-initial");
-    APPEND_INT(cpuThrottleIncrement, "cpu-throttle-increment");
-    APPEND_STR(tlsCreds, "tls-creds");
-    APPEND_STR(tlsHostname, "tls-hostname");
-    APPEND_ULONG(maxBandwidth, "max-bandwidth");
-    APPEND_ULONG(downtimeLimit, "downtime-limit");
-    APPEND_BOOL(blockIncremental, "block-incremental");
-    APPEND_ULONG(xbzrleCacheSize, "xbzrle-cache-size");
-
-#undef APPEND
-#undef APPEND_INT
-#undef APPEND_STR
-#undef APPEND_ULONG
-
-    if (virJSONValueObjectKeysNumber(args) == 0) {
-        ret = 0;
-        goto cleanup;
-    }
-
-    if (virJSONValueObjectAppend(cmd, "arguments", args) < 0)
+    if (virJSONValueObjectAppend(cmd, "arguments", params) < 0)
         goto cleanup;
-    args = NULL;
+    params = NULL;
 
     if (qemuMonitorJSONCommand(mon, cmd, &reply) < 0)
         goto cleanup;
@@ -2881,7 +2833,7 @@ qemuMonitorJSONSetMigrationParams(qemuMonitorPtr mon,
     ret = 0;
  cleanup:
     virJSONValueFree(cmd);
-    virJSONValueFree(args);
+    virJSONValueFree(params);
     virJSONValueFree(reply);
     return ret;
 }
index a52f0a1955ef56870b161eea0870d94405aea130..5ada38b9fa8a50468258e2e99c2f51d316072452 100644 (file)
@@ -137,7 +137,7 @@ int qemuMonitorJSONSetMigrationCacheSize(qemuMonitorPtr mon,
 int qemuMonitorJSONGetMigrationParams(qemuMonitorPtr mon,
                                       virJSONValuePtr *params);
 int qemuMonitorJSONSetMigrationParams(qemuMonitorPtr mon,
-                                      qemuMonitorMigrationParamsPtr params);
+                                      virJSONValuePtr params);
 
 int qemuMonitorJSONGetMigrationStats(qemuMonitorPtr mon,
                                      qemuMonitorMigrationStatsPtr stats,