From nobody Wed May 14 17:20:09 2025 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of redhat.com designates 209.132.183.28 as permitted sender) client-ip=209.132.183.28; envelope-from=libvir-list-bounces@redhat.com; helo=mx1.redhat.com; Authentication-Results: mx.zohomail.com; spf=pass (zoho.com: domain of redhat.com designates 209.132.183.28 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=pass(p=none dis=none) header.from=redhat.com Return-Path: Received: from mx1.redhat.com (mx1.redhat.com [209.132.183.28]) by mx.zohomail.com with SMTPS id 1523457802246528.4527097992454; Wed, 11 Apr 2018 07:43:22 -0700 (PDT) Received: from smtp.corp.redhat.com (int-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.12]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 6E7AF1B6F; Wed, 11 Apr 2018 14:43:20 +0000 (UTC) Received: from colo-mx.corp.redhat.com (colo-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.21]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 3087A877B6; Wed, 11 Apr 2018 14:43:20 +0000 (UTC) Received: from lists01.pubmisc.prod.ext.phx2.redhat.com (lists01.pubmisc.prod.ext.phx2.redhat.com [10.5.19.33]) by colo-mx.corp.redhat.com (Postfix) with ESMTP id DA6915BBEB; Wed, 11 Apr 2018 14:43:19 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.rdu2.redhat.com [10.11.54.6]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id w3BEgGMY008861 for ; Wed, 11 Apr 2018 10:42:16 -0400 Received: by smtp.corp.redhat.com (Postfix) id 84202215CDCC; Wed, 11 Apr 2018 14:42:16 +0000 (UTC) Received: from virval.usersys.redhat.com (unknown [10.43.2.20]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 46E81215CDC8 for ; Wed, 11 Apr 2018 14:42:16 +0000 (UTC) Received: by virval.usersys.redhat.com (Postfix, from userid 500) id E2D52100B89; Wed, 11 Apr 2018 16:42:10 +0200 (CEST) From: Jiri Denemark To: libvir-list@redhat.com Date: Wed, 11 Apr 2018 16:41:42 +0200 Message-Id: <2f610891526247c8baa7b36531f454e231b66cc1.1523456480.git.jdenemar@redhat.com> In-Reply-To: References: In-Reply-To: References: Mail-Followup-To: libvir-list@redhat.com X-Scanned-By: MIMEDefang 2.78 on 10.11.54.6 X-loop: libvir-list@redhat.com Subject: [libvirt] [PATCH v2 52/73] qemu: Move migration parameters JSON parsing X-BeenThere: libvir-list@redhat.com X-Mailman-Version: 2.1.12 Precedence: junk List-Id: Development discussions about the libvirt library & tools List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Sender: libvir-list-bounces@redhat.com Errors-To: libvir-list-bounces@redhat.com X-Scanned-By: MIMEDefang 2.79 on 10.5.11.12 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.30]); Wed, 11 Apr 2018 14:43:21 +0000 (UTC) X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Type: text/plain; charset="utf-8" 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 Reviewed-by: J=EF=BF=BDn Tomko --- 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_par= ams.c index cadb402b0f..845234c34b 100644 --- a/src/qemu/qemu_migration_params.c +++ b/src/qemu/qemu_migration_params.c @@ -314,6 +314,67 @@ qemuMigrationParamsDump(qemuMigrationParamsPtr migPara= ms, } =20 =20 +static qemuMigrationParamsPtr +qemuMigrationParamsFromJSON(virJSONValuePtr params) +{ + qemuMigrationParamsPtr migParams =3D NULL; + + if (!(migParams =3D qemuMigrationParamsNew())) + return NULL; + + if (!params) + return migParams; + +#define PARSE_SET(API, VAR, FIELD) \ + do { \ + if (API(params, FIELD, &migParams->params.VAR) =3D=3D 0) \ + migParams->params.VAR ## _set =3D 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 =3D 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 =3D vm->privateData; - qemuMigrationParamsPtr params =3D NULL; + virJSONValuePtr jsonParams =3D NULL; int ret =3D -1; int rc; =20 *migParams =3D NULL; =20 - if (!(params =3D qemuMigrationParamsNew())) - return -1; - if (qemuDomainObjEnterMonitorAsync(driver, vm, asyncJob) < 0) goto cleanup; =20 - rc =3D qemuMonitorGetMigrationParams(priv->mon, ¶ms->params); + rc =3D qemuMonitorGetMigrationParams(priv->mon, &jsonParams); =20 if (qemuDomainObjExitMonitor(driver, vm) < 0 || rc < 0) goto cleanup; =20 - VIR_STEAL_PTR(*migParams, params); + if (!(*migParams =3D qemuMigrationParamsFromJSON(jsonParams))) + goto cleanup; + ret =3D 0; =20 cleanup: - qemuMigrationParamsFree(params); + virJSONValueFree(jsonParams); return ret; } =20 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, } =20 =20 +/** + * qemuMonitorGetMigrationParams: + * @mon: Pointer to the monitor object. + * @params: Where to store migration parameters. + * + * If QEMU does not support querying migration parameters, the function wi= ll + * set @params to NULL and return 0 (success). The caller is responsible f= or + * freeing @params. + * + * Returns 0 on success, -1 on error. + */ int qemuMonitorGetMigrationParams(qemuMonitorPtr mon, - qemuMonitorMigrationParamsPtr params) + virJSONValuePtr *params) { QEMU_CHECK_MONITOR_JSON(mon); =20 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 { }; =20 int qemuMonitorGetMigrationParams(qemuMonitorPtr mon, - qemuMonitorMigrationParamsPtr params); + virJSONValuePtr *params); int qemuMonitorSetMigrationParams(qemuMonitorPtr mon, qemuMonitorMigrationParamsPtr params); =20 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, =20 int qemuMonitorJSONGetMigrationParams(qemuMonitorPtr mon, - qemuMonitorMigrationParamsPtr params) + virJSONValuePtr *params) { int ret =3D -1; - virJSONValuePtr result; virJSONValuePtr cmd =3D NULL; virJSONValuePtr reply =3D NULL; =20 - memset(params, 0, sizeof(*params)); + *params =3D NULL; =20 if (!(cmd =3D qemuMonitorJSONMakeCommand("query-migrate-parameters", N= ULL))) return -1; @@ -2797,51 +2796,9 @@ qemuMonitorJSONGetMigrationParams(qemuMonitorPtr mon, if (qemuMonitorJSONCheckReply(cmd, reply, VIR_JSON_TYPE_OBJECT) < 0) goto cleanup; =20 - result =3D virJSONValueObjectGet(reply, "return"); - -#define PARSE_SET(API, VAR, FIELD) \ - do { \ - if (API(result, FIELD, ¶ms->VAR) =3D=3D 0) \ - params->VAR ## _set =3D 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 =3D 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 =3D virJSONValueObjectStealObject(reply, "return"); ret =3D 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); =20 int qemuMonitorJSONGetMigrationParams(qemuMonitorPtr mon, - qemuMonitorMigrationParamsPtr params= ); + virJSONValuePtr *params); int qemuMonitorJSONSetMigrationParams(qemuMonitorPtr mon, qemuMonitorMigrationParamsPtr params= ); =20 --=20 2.17.0 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list