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: Jiri Denemark <jdenemar@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
This commit is contained in:
Jiri Denemark 2018-03-15 18:06:01 +01:00
parent bf856b6054
commit abe06c279b
5 changed files with 85 additions and 57 deletions

View 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;
}

View 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);

View File

@ -679,7 +679,7 @@ struct _qemuMonitorMigrationParams {
};
int qemuMonitorGetMigrationParams(qemuMonitorPtr mon,
qemuMonitorMigrationParamsPtr params);
virJSONValuePtr *params);
int qemuMonitorSetMigrationParams(qemuMonitorPtr mon,
qemuMonitorMigrationParamsPtr params);

View 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);

View 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);