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@xxxxxxxxxx> --- src/qemu/qemu_migration_params.c | 74 +++++++++++++++++++++++++++++--- src/qemu/qemu_monitor.c | 13 +++++- src/qemu/qemu_monitor.h | 2 +- src/qemu/qemu_monitor_json.c | 51 ++-------------------- src/qemu/qemu_monitor_json.h | 2 +- 5 files changed, 85 insertions(+), 57 deletions(-) diff --git a/src/qemu/qemu_migration_params.c b/src/qemu/qemu_migration_params.c index fd93d9cb39..6908aef24d 100644 --- a/src/qemu/qemu_migration_params.c +++ b/src/qemu/qemu_migration_params.c @@ -311,6 +311,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 @@ -524,28 +585,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, ¶ms->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; } diff --git a/src/qemu/qemu_monitor.c b/src/qemu/qemu_monitor.c index 18b54e2da8..411ce28787 100644 --- a/src/qemu/qemu_monitor.c +++ b/src/qemu/qemu_monitor.c @@ -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); diff --git a/src/qemu/qemu_monitor.h b/src/qemu/qemu_monitor.h index 2bb4dbc667..261f3192f5 100644 --- a/src/qemu/qemu_monitor.h +++ b/src/qemu/qemu_monitor.h @@ -679,7 +679,7 @@ struct _qemuMonitorMigrationParams { }; int qemuMonitorGetMigrationParams(qemuMonitorPtr mon, - qemuMonitorMigrationParamsPtr params); + virJSONValuePtr *params); int qemuMonitorSetMigrationParams(qemuMonitorPtr mon, qemuMonitorMigrationParamsPtr params); diff --git a/src/qemu/qemu_monitor_json.c b/src/qemu/qemu_monitor_json.c index acc126629e..7de1ade28e 100644 --- a/src/qemu/qemu_monitor_json.c +++ b/src/qemu/qemu_monitor_json.c @@ -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, ¶ms->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); diff --git a/src/qemu/qemu_monitor_json.h b/src/qemu/qemu_monitor_json.h index a73e98815c..a52f0a1955 100644 --- a/src/qemu/qemu_monitor_json.h +++ b/src/qemu/qemu_monitor_json.h @@ -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); -- 2.17.0 -- libvir-list mailing list libvir-list@xxxxxxxxxx https://www.redhat.com/mailman/listinfo/libvir-list