diff --git a/src/qemu/qemu_migration_params.c b/src/qemu/qemu_migration_params.c index cadb402b0fa0d62ef4229e1f85c9d9b1a54bfa8a..845234c34bb7e7686047bc08070ea6a52289993f 100644 --- a/src/qemu/qemu_migration_params.c +++ b/src/qemu/qemu_migration_params.c @@ -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, ¶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 008d7c1ca960521a17a117aa14f45bf3dd0b13fb..716189b6292386927f40c1057173c4264888f95f 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 cc4a6647e6d008816516861eb2da17ae4bb85736..82ede6650519d0d07ea5605cfb3559485b3d7a2f 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 acc126629e7391e8b4136375c6886d2d09d01acc..7de1ade28ec6e9a009dbed910a08792674796e8e 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 a73e98815c4749ae6a5af9f8d110e02d17044fa6..a52f0a1955ef56870b161eea0870d94405aea130 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);