mirror of
https://gitlab.com/libvirt/libvirt.git
synced 2024-12-23 06:05:27 +00:00
qemu: Move migration parameters JSON formatting
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>
This commit is contained in:
parent
abe06c279b
commit
fa0a1467c5
@ -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;
|
||||
}
|
||||
|
||||
|
@ -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)
|
||||
virJSONValuePtr 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);
|
||||
QEMU_CHECK_MONITOR_JSON_GOTO(mon, error);
|
||||
|
||||
return qemuMonitorJSONSetMigrationParams(mon, params);
|
||||
|
||||
error:
|
||||
virJSONValueFree(params);
|
||||
return -1;
|
||||
}
|
||||
|
||||
|
||||
|
@ -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,
|
||||
|
@ -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()))
|
||||
if (virJSONValueObjectAppend(cmd, "arguments", params) < 0)
|
||||
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)
|
||||
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;
|
||||
}
|
||||
|
@ -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,
|
||||
|
Loading…
Reference in New Issue
Block a user