}
+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
{
qemuDomainObjPrivatePtr priv = vm->privateData;
bool xbzrleCacheSize_old = false;
+ virJSONValuePtr params = NULL;
int ret = -1;
+ int rc;
if (qemuDomainObjEnterMonitorAsync(driver, vm, asyncJob) < 0)
return -1;
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:
if (xbzrleCacheSize_old)
migParams->params.xbzrleCacheSize_set = true;
+ virJSONValueFree(params);
+
return ret;
}
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;
}
int qemuMonitorGetMigrationParams(qemuMonitorPtr mon,
virJSONValuePtr *params);
int qemuMonitorSetMigrationParams(qemuMonitorPtr mon,
- qemuMonitorMigrationParamsPtr params);
+ virJSONValuePtr params);
typedef enum {
QEMU_MONITOR_MIGRATION_STATUS_INACTIVE,
int
qemuMonitorJSONSetMigrationParams(qemuMonitorPtr mon,
- qemuMonitorMigrationParamsPtr params)
+ virJSONValuePtr params)
{
int ret = -1;
virJSONValuePtr cmd = NULL;
- virJSONValuePtr args = NULL;
virJSONValuePtr reply = NULL;
if (!(cmd = virJSONValueNewObject()))
"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;
ret = 0;
cleanup:
virJSONValueFree(cmd);
- virJSONValueFree(args);
+ virJSONValueFree(params);
virJSONValueFree(reply);
return ret;
}
int qemuMonitorJSONGetMigrationParams(qemuMonitorPtr mon,
virJSONValuePtr *params);
int qemuMonitorJSONSetMigrationParams(qemuMonitorPtr mon,
- qemuMonitorMigrationParamsPtr params);
+ virJSONValuePtr params);
int qemuMonitorJSONGetMigrationStats(qemuMonitorPtr mon,
qemuMonitorMigrationStatsPtr stats,