From nobody Mon Feb 9 06:01:59 2026 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) client-ip=208.118.235.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; spf=pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org Return-Path: Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) by mx.zohomail.com with SMTPS id 1500409877067769.6070010321788; Tue, 18 Jul 2017 13:31:17 -0700 (PDT) Received: from localhost ([::1]:58481 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dXZ9G-0006xf-Ll for importer@patchew.org; Tue, 18 Jul 2017 16:31:14 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:58157) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dXZ7W-000574-Gq for qemu-devel@nongnu.org; Tue, 18 Jul 2017 16:29:27 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1dXZ7U-00018P-SA for qemu-devel@nongnu.org; Tue, 18 Jul 2017 16:29:26 -0400 Received: from mx1.redhat.com ([209.132.183.28]:60388) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1dXZ7U-00017l-KB for qemu-devel@nongnu.org; Tue, 18 Jul 2017 16:29:24 -0400 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 975917CE02 for ; Tue, 18 Jul 2017 20:29:23 +0000 (UTC) Received: from blackfin.pond.sub.org (ovpn-116-60.ams2.redhat.com [10.36.116.60]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 36AEF67CD9 for ; Tue, 18 Jul 2017 20:29:23 +0000 (UTC) Received: by blackfin.pond.sub.org (Postfix, from userid 1000) id 686581138650; Tue, 18 Jul 2017 22:29:20 +0200 (CEST) DMARC-Filter: OpenDMARC Filter v1.3.2 mx1.redhat.com 975917CE02 Authentication-Results: ext-mx04.extmail.prod.ext.phx2.redhat.com; dmarc=none (p=none dis=none) header.from=redhat.com Authentication-Results: ext-mx04.extmail.prod.ext.phx2.redhat.com; spf=pass smtp.mailfrom=armbru@redhat.com DKIM-Filter: OpenDKIM Filter v2.11.0 mx1.redhat.com 975917CE02 From: Markus Armbruster To: qemu-devel@nongnu.org Date: Tue, 18 Jul 2017 22:29:16 +0200 Message-Id: <1500409760-20730-7-git-send-email-armbru@redhat.com> In-Reply-To: <1500409760-20730-1-git-send-email-armbru@redhat.com> References: <1500409760-20730-1-git-send-email-armbru@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.28]); Tue, 18 Jul 2017 20:29:23 +0000 (UTC) X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 209.132.183.28 Subject: [Qemu-devel] [PULL 06/10] hmp: Clean up and simplify hmp_migrate_set_parameter() X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" The bulk of hmp_migrate_set_parameter()'s code sets one member of MigrationParameters according to the command's arguments. It uses a string visitor for integer and boolean members, but not for string and size members. It calls visit_type_bool() right away, but delays visit_type_int() some. The delaying requires a flag variable and a bit of trickery: we set all integer members instead of just the one we want, and rely on the has_FOOs to mask the unwanted ones. Clean this up as follows. Don't delay calling visit_type_int(). Use the string visitor for strings, too. This involves extra allocations and cleanup, but doing them is simpler and cleaner than avoiding them. Sadly, using the string visitor for sizes isn't possible, because it defaults to Bytes rather than Mebibytes. Add a comment explaining that. Signed-off-by: Markus Armbruster Reviewed-by: Daniel P. Berrange Reviewed-by: Dr. David Alan Gilbert Reviewed-by: Eric Blake --- hmp.c | 78 ++++++++++++++++++++++++++++-----------------------------------= ---- 1 file changed, 32 insertions(+), 46 deletions(-) diff --git a/hmp.c b/hmp.c index 6d32c40..2993586 100644 --- a/hmp.c +++ b/hmp.c @@ -1509,90 +1509,75 @@ void hmp_migrate_set_parameter(Monitor *mon, const = QDict *qdict) const char *param =3D qdict_get_str(qdict, "parameter"); const char *valuestr =3D qdict_get_str(qdict, "value"); Visitor *v =3D string_input_visitor_new(valuestr); + MigrationParameters *p =3D g_new0(MigrationParameters, 1); uint64_t valuebw =3D 0; - int64_t valueint =3D 0; - bool valuebool =3D false; Error *err =3D NULL; - bool use_int_value =3D false; int i, ret; =20 for (i =3D 0; i < MIGRATION_PARAMETER__MAX; i++) { if (strcmp(param, MigrationParameter_lookup[i]) =3D=3D 0) { - MigrationParameters p =3D { 0 }; switch (i) { case MIGRATION_PARAMETER_COMPRESS_LEVEL: - p.has_compress_level =3D true; - use_int_value =3D true; + p->has_compress_level =3D true; + visit_type_int(v, param, &p->compress_level, &err); break; case MIGRATION_PARAMETER_COMPRESS_THREADS: - p.has_compress_threads =3D true; - use_int_value =3D true; + p->has_compress_threads =3D true; + visit_type_int(v, param, &p->compress_threads, &err); break; case MIGRATION_PARAMETER_DECOMPRESS_THREADS: - p.has_decompress_threads =3D true; - use_int_value =3D true; + p->has_decompress_threads =3D true; + visit_type_int(v, param, &p->decompress_threads, &err); break; case MIGRATION_PARAMETER_CPU_THROTTLE_INITIAL: - p.has_cpu_throttle_initial =3D true; - use_int_value =3D true; + p->has_cpu_throttle_initial =3D true; + visit_type_int(v, param, &p->cpu_throttle_initial, &err); break; case MIGRATION_PARAMETER_CPU_THROTTLE_INCREMENT: - p.has_cpu_throttle_increment =3D true; - use_int_value =3D true; + p->has_cpu_throttle_increment =3D true; + visit_type_int(v, param, &p->cpu_throttle_increment, &err); break; case MIGRATION_PARAMETER_TLS_CREDS: - p.has_tls_creds =3D true; - p.tls_creds =3D (char *) valuestr; + p->has_tls_creds =3D true; + visit_type_str(v, param, &p->tls_creds, &err); break; case MIGRATION_PARAMETER_TLS_HOSTNAME: - p.has_tls_hostname =3D true; - p.tls_hostname =3D (char *) valuestr; + p->has_tls_hostname =3D true; + visit_type_str(v, param, &p->tls_hostname, &err); break; case MIGRATION_PARAMETER_MAX_BANDWIDTH: - p.has_max_bandwidth =3D true; + p->has_max_bandwidth =3D true; + /* + * Can't use visit_type_size() here, because it + * defaults to Bytes rather than Mebibytes. + */ ret =3D qemu_strtosz_MiB(valuestr, NULL, &valuebw); if (ret < 0 || valuebw > INT64_MAX || (size_t)valuebw !=3D valuebw) { error_setg(&err, "Invalid size %s", valuestr); - goto cleanup; + break; } - p.max_bandwidth =3D valuebw; + p->max_bandwidth =3D valuebw; break; case MIGRATION_PARAMETER_DOWNTIME_LIMIT: - p.has_downtime_limit =3D true; - use_int_value =3D true; + p->has_downtime_limit =3D true; + visit_type_int(v, param, &p->downtime_limit, &err); break; case MIGRATION_PARAMETER_X_CHECKPOINT_DELAY: - p.has_x_checkpoint_delay =3D true; - use_int_value =3D true; + p->has_x_checkpoint_delay =3D true; + visit_type_int(v, param, &p->x_checkpoint_delay, &err); break; case MIGRATION_PARAMETER_BLOCK_INCREMENTAL: - p.has_block_incremental =3D true; - visit_type_bool(v, param, &valuebool, &err); - if (err) { - goto cleanup; - } - p.block_incremental =3D valuebool; + p->has_block_incremental =3D true; + visit_type_bool(v, param, &p->block_incremental, &err); break; } =20 - if (use_int_value) { - visit_type_int(v, param, &valueint, &err); - if (err) { - goto cleanup; - } - /* Set all integers; only one has_FOO will be set, and - * the code ignores the remaining values */ - p.compress_level =3D valueint; - p.compress_threads =3D valueint; - p.decompress_threads =3D valueint; - p.cpu_throttle_initial =3D valueint; - p.cpu_throttle_increment =3D valueint; - p.downtime_limit =3D valueint; - p.x_checkpoint_delay =3D valueint; + if (err) { + goto cleanup; } =20 - qmp_migrate_set_parameters(&p, &err); + qmp_migrate_set_parameters(p, &err); break; } } @@ -1602,6 +1587,7 @@ void hmp_migrate_set_parameter(Monitor *mon, const QD= ict *qdict) } =20 cleanup: + qapi_free_MigrationParameters(p); visit_free(v); if (err) { error_report_err(err); --=20 2.7.5