From nobody Wed May 14 13:38:01 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 1523780570038481.44790197188; Sun, 15 Apr 2018 01:22:50 -0700 (PDT) Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.phx2.redhat.com [10.5.11.16]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id C1A4381DF6; Sun, 15 Apr 2018 08:22:48 +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 7ADF97DEFD; Sun, 15 Apr 2018 08:22:48 +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 007465BBF3; Sun, 15 Apr 2018 08:22:47 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.rdu2.redhat.com [10.11.54.5]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id w3BEgGwc008828 for ; Wed, 11 Apr 2018 10:42:16 -0400 Received: by smtp.corp.redhat.com (Postfix) id 86532946D5; 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 49558AB3E8 for ; Wed, 11 Apr 2018 14:42:16 +0000 (UTC) Received: by virval.usersys.redhat.com (Postfix, from userid 500) id E641F100B8A; Wed, 11 Apr 2018 16:42:10 +0200 (CEST) From: Jiri Denemark To: libvir-list@redhat.com Date: Wed, 11 Apr 2018 16:41:43 +0200 Message-Id: <744136462eb87fbf1602414e5a6aff211dbf40a0.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.79 on 10.11.54.5 X-loop: libvir-list@redhat.com Subject: [libvirt] [PATCH v2 53/73] qemu: Move migration parameters JSON formatting 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.16 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.25]); Sun, 15 Apr 2018 08:22:49 +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 one 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 | 68 +++++++++++++++++++++++++++++++- src/qemu/qemu_monitor.c | 35 ++++++++-------- src/qemu/qemu_monitor.h | 2 +- src/qemu/qemu_monitor_json.c | 56 ++------------------------ src/qemu/qemu_monitor_json.h | 2 +- 5 files changed, 90 insertions(+), 73 deletions(-) diff --git a/src/qemu/qemu_migration_params.c b/src/qemu/qemu_migration_par= ams.c index 845234c34b..560c2d3ea5 100644 --- a/src/qemu/qemu_migration_params.c +++ b/src/qemu/qemu_migration_params.c @@ -375,6 +375,61 @@ qemuMigrationParamsFromJSON(virJSONValuePtr params) } =20 =20 +static virJSONValuePtr +qemuMigrationParamsToJSON(qemuMigrationParamsPtr migParams) +{ + virJSONValuePtr params =3D NULL; + + if (!(params =3D virJSONValueNewObject())) + return NULL; + +#define APPEND(VALID, API, VAR, FIELD) \ + do { \ + if (VALID && API(params, FIELD, migParams->params.VAR) < 0) \ + goto error; \ + } while (0) + +#define APPEND_INT(VAR, FIELD) \ + APPEND(migParams->params.VAR ## _set, \ + virJSONValueObjectAppendNumberInt, VAR, FIELD) + +#define APPEND_STR(VAR, FIELD) \ + APPEND(migParams->params.VAR, \ + virJSONValueObjectAppendString, VAR, FIELD) + +#define APPEND_ULONG(VAR, FIELD) \ + APPEND(migParams->params.VAR ## _set, \ + virJSONValueObjectAppendNumberUlong, VAR, FIELD) + +#define APPEND_BOOL(VAR, FIELD) \ + APPEND(migParams->params.VAR ## _set, \ + virJSONValueObjectAppendBoolean, VAR, FIELD) + + APPEND_INT(compressLevel, "compress-level"); + APPEND_INT(compressThreads, "compress-threads"); + APPEND_INT(decompressThreads, "decompress-threads"); + APPEND_INT(cpuThrottleInitial, "cpu-throttle-initial"); + APPEND_INT(cpuThrottleIncrement, "cpu-throttle-increment"); + APPEND_STR(tlsCreds, "tls-creds"); + APPEND_STR(tlsHostname, "tls-hostname"); + APPEND_ULONG(maxBandwidth, "max-bandwidth"); + APPEND_ULONG(downtimeLimit, "downtime-limit"); + APPEND_BOOL(blockIncremental, "block-incremental"); + APPEND_ULONG(xbzrleCacheSize, "xbzrle-cache-size"); + +#undef APPEND +#undef APPEND_INT +#undef APPEND_STR +#undef APPEND_ULONG + + return params; + + error: + virJSONValueFree(params); + return NULL; +} + + /** * qemuMigrationParamsApply * @driver: qemu driver @@ -394,7 +449,9 @@ qemuMigrationParamsApply(virQEMUDriverPtr driver, { qemuDomainObjPrivatePtr priv =3D vm->privateData; bool xbzrleCacheSize_old =3D false; + virJSONValuePtr params =3D NULL; int ret =3D -1; + int rc; =20 if (qemuDomainObjEnterMonitorAsync(driver, vm, asyncJob) < 0) return -1; @@ -417,9 +474,16 @@ qemuMigrationParamsApply(virQEMUDriverPtr driver, migParams->params.xbzrleCacheSize_set =3D false; } =20 - if (qemuMonitorSetMigrationParams(priv->mon, &migParams->params) < 0) + if (!(params =3D qemuMigrationParamsToJSON(migParams))) goto cleanup; =20 + if (virJSONValueObjectKeysNumber(params) > 0) { + rc =3D qemuMonitorSetMigrationParams(priv->mon, params); + params =3D NULL; + if (rc < 0) + goto cleanup; + } + ret =3D 0; =20 cleanup: @@ -429,6 +493,8 @@ qemuMigrationParamsApply(virQEMUDriverPtr driver, if (xbzrleCacheSize_old) migParams->params.xbzrleCacheSize_set =3D true; =20 + virJSONValueFree(params); + return ret; } =20 diff --git a/src/qemu/qemu_monitor.c b/src/qemu/qemu_monitor.c index 411ce28787..641465f227 100644 --- a/src/qemu/qemu_monitor.c +++ b/src/qemu/qemu_monitor.c @@ -2642,29 +2642,28 @@ qemuMonitorGetMigrationParams(qemuMonitorPtr mon, return qemuMonitorJSONGetMigrationParams(mon, params); } =20 + +/** + * qemuMonitorSetMigrationParams: + * @mon: Pointer to the monitor object. + * @params: Migration parameters. + * + * The @params object is consumed and should not be referenced by the call= er + * after this function returns. + * + * Returns 0 on success, -1 on error. + */ int qemuMonitorSetMigrationParams(qemuMonitorPtr mon, - qemuMonitorMigrationParamsPtr params) + virJSONValuePtr params) { - VIR_DEBUG("compressLevel=3D%d:%d compressThreads=3D%d:%d " - "decompressThreads=3D%d:%d cpuThrottleInitial=3D%d:%d " - "cpuThrottleIncrement=3D%d:%d tlsCreds=3D%s tlsHostname=3D%s= " - "maxBandwidth=3D%d:%llu downtimeLimit=3D%d:%llu " - "blockIncremental=3D%d:%d xbzrleCacheSize=3D%d:%llu", - params->compressLevel_set, params->compressLevel, - params->compressThreads_set, params->compressThreads, - params->decompressThreads_set, params->decompressThreads, - params->cpuThrottleInitial_set, params->cpuThrottleInitial, - params->cpuThrottleIncrement_set, params->cpuThrottleIncreme= nt, - NULLSTR(params->tlsCreds), NULLSTR(params->tlsHostname), - params->maxBandwidth_set, params->maxBandwidth, - params->downtimeLimit_set, params->downtimeLimit, - params->blockIncremental_set, params->blockIncremental, - params->xbzrleCacheSize_set, params->xbzrleCacheSize); - - QEMU_CHECK_MONITOR_JSON(mon); + QEMU_CHECK_MONITOR_JSON_GOTO(mon, error); =20 return qemuMonitorJSONSetMigrationParams(mon, params); + + error: + virJSONValueFree(params); + return -1; } =20 =20 diff --git a/src/qemu/qemu_monitor.h b/src/qemu/qemu_monitor.h index 261f3192f5..fd3c767dcf 100644 --- a/src/qemu/qemu_monitor.h +++ b/src/qemu/qemu_monitor.h @@ -681,7 +681,7 @@ struct _qemuMonitorMigrationParams { int qemuMonitorGetMigrationParams(qemuMonitorPtr mon, virJSONValuePtr *params); int qemuMonitorSetMigrationParams(qemuMonitorPtr mon, - qemuMonitorMigrationParamsPtr params); + virJSONValuePtr params); =20 typedef enum { QEMU_MONITOR_MIGRATION_STATUS_INACTIVE, diff --git a/src/qemu/qemu_monitor_json.c b/src/qemu/qemu_monitor_json.c index 7de1ade28e..b00bca7d46 100644 --- a/src/qemu/qemu_monitor_json.c +++ b/src/qemu/qemu_monitor_json.c @@ -2807,11 +2807,10 @@ qemuMonitorJSONGetMigrationParams(qemuMonitorPtr mo= n, =20 int qemuMonitorJSONSetMigrationParams(qemuMonitorPtr mon, - qemuMonitorMigrationParamsPtr params) + virJSONValuePtr params) { int ret =3D -1; virJSONValuePtr cmd =3D NULL; - virJSONValuePtr args =3D NULL; virJSONValuePtr reply =3D NULL; =20 if (!(cmd =3D virJSONValueNewObject())) @@ -2821,56 +2820,9 @@ qemuMonitorJSONSetMigrationParams(qemuMonitorPtr mon, "migrate-set-parameters") < 0) goto cleanup; =20 - if (!(args =3D virJSONValueNewObject())) + if (virJSONValueObjectAppend(cmd, "arguments", params) < 0) goto cleanup; - -#define APPEND(VALID, API, VAR, FIELD) \ - do { \ - if (VALID && API(args, FIELD, params->VAR) < 0) \ - goto cleanup; \ - } while (0) - -#define APPEND_INT(VAR, FIELD) \ - APPEND(params->VAR ## _set, \ - virJSONValueObjectAppendNumberInt, VAR, FIELD) - -#define APPEND_STR(VAR, FIELD) \ - APPEND(params->VAR, \ - virJSONValueObjectAppendString, VAR, FIELD) - -#define APPEND_ULONG(VAR, FIELD) \ - APPEND(params->VAR ## _set, \ - virJSONValueObjectAppendNumberUlong, VAR, FIELD) - -#define APPEND_BOOL(VAR, FIELD) \ - APPEND(params->VAR ## _set, \ - virJSONValueObjectAppendBoolean, VAR, FIELD) - - APPEND_INT(compressLevel, "compress-level"); - APPEND_INT(compressThreads, "compress-threads"); - APPEND_INT(decompressThreads, "decompress-threads"); - APPEND_INT(cpuThrottleInitial, "cpu-throttle-initial"); - APPEND_INT(cpuThrottleIncrement, "cpu-throttle-increment"); - APPEND_STR(tlsCreds, "tls-creds"); - APPEND_STR(tlsHostname, "tls-hostname"); - APPEND_ULONG(maxBandwidth, "max-bandwidth"); - APPEND_ULONG(downtimeLimit, "downtime-limit"); - APPEND_BOOL(blockIncremental, "block-incremental"); - APPEND_ULONG(xbzrleCacheSize, "xbzrle-cache-size"); - -#undef APPEND -#undef APPEND_INT -#undef APPEND_STR -#undef APPEND_ULONG - - if (virJSONValueObjectKeysNumber(args) =3D=3D 0) { - ret =3D 0; - goto cleanup; - } - - if (virJSONValueObjectAppend(cmd, "arguments", args) < 0) - goto cleanup; - args =3D NULL; + params =3D NULL; =20 if (qemuMonitorJSONCommand(mon, cmd, &reply) < 0) goto cleanup; @@ -2881,7 +2833,7 @@ qemuMonitorJSONSetMigrationParams(qemuMonitorPtr mon, ret =3D 0; cleanup: virJSONValueFree(cmd); - virJSONValueFree(args); + virJSONValueFree(params); virJSONValueFree(reply); return ret; } diff --git a/src/qemu/qemu_monitor_json.h b/src/qemu/qemu_monitor_json.h index a52f0a1955..5ada38b9fa 100644 --- a/src/qemu/qemu_monitor_json.h +++ b/src/qemu/qemu_monitor_json.h @@ -137,7 +137,7 @@ int qemuMonitorJSONSetMigrationCacheSize(qemuMonitorPtr= mon, int qemuMonitorJSONGetMigrationParams(qemuMonitorPtr mon, virJSONValuePtr *params); int qemuMonitorJSONSetMigrationParams(qemuMonitorPtr mon, - qemuMonitorMigrationParamsPtr params= ); + virJSONValuePtr params); =20 int qemuMonitorJSONGetMigrationStats(qemuMonitorPtr mon, qemuMonitorMigrationStatsPtr stats, --=20 2.17.0 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list