提交 abe06c27 编写于 作者: J Jiri Denemark

qemu: Move migration parameters JSON parsing

We want to have all migration parameters parsing and formatting at once
place, i.e., in qemu_migration_params.c.
Signed-off-by: NJiri Denemark <jdenemar@redhat.com>
Reviewed-by: NJán Tomko <jtomko@redhat.com>
上级 bf856b60
......@@ -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;
}
......
......@@ -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);
......
......@@ -679,7 +679,7 @@ struct _qemuMonitorMigrationParams {
};
int qemuMonitorGetMigrationParams(qemuMonitorPtr mon,
qemuMonitorMigrationParamsPtr params);
virJSONValuePtr *params);
int qemuMonitorSetMigrationParams(qemuMonitorPtr mon,
qemuMonitorMigrationParamsPtr params);
......
......@@ -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);
......
......@@ -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);
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册