From nobody Mon Feb 9 10:58:11 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 1500385854331984.1657909637208; Tue, 18 Jul 2017 06:50:54 -0700 (PDT) Received: from localhost ([::1]:56620 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dXSto-0000sY-TP for importer@patchew.org; Tue, 18 Jul 2017 09:50:52 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:33847) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dXSkv-0000BG-5H for qemu-devel@nongnu.org; Tue, 18 Jul 2017 09:41:46 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1dXSkt-0007TG-7X for qemu-devel@nongnu.org; Tue, 18 Jul 2017 09:41:41 -0400 Received: from mx1.redhat.com ([209.132.183.28]:44406) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1dXSkm-0007LL-Ek; Tue, 18 Jul 2017 09:41:32 -0400 Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.phx2.redhat.com [10.5.11.13]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 5EFB0C04D28B; Tue, 18 Jul 2017 13:41:31 +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 E35737F8C9; Tue, 18 Jul 2017 13:41:30 +0000 (UTC) Received: by blackfin.pond.sub.org (Postfix, from userid 1000) id 14C27113866D; Tue, 18 Jul 2017 15:41:27 +0200 (CEST) DMARC-Filter: OpenDMARC Filter v1.3.2 mx1.redhat.com 5EFB0C04D28B Authentication-Results: ext-mx07.extmail.prod.ext.phx2.redhat.com; dmarc=none (p=none dis=none) header.from=redhat.com Authentication-Results: ext-mx07.extmail.prod.ext.phx2.redhat.com; spf=pass smtp.mailfrom=armbru@redhat.com DKIM-Filter: OpenDKIM Filter v2.11.0 mx1.redhat.com 5EFB0C04D28B From: Markus Armbruster To: qemu-devel@nongnu.org Date: Tue, 18 Jul 2017 15:41:26 +0200 Message-Id: <1500385286-21142-11-git-send-email-armbru@redhat.com> In-Reply-To: <1500385286-21142-1-git-send-email-armbru@redhat.com> References: <1500385286-21142-1-git-send-email-armbru@redhat.com> X-Scanned-By: MIMEDefang 2.79 on 10.5.11.13 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.31]); Tue, 18 Jul 2017 13:41:31 +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] [PATCH for-2.10 10/10] migration: Use JSON null instead of "" to reset parameter to default 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: , Cc: kwolf@redhat.com, qemu-block@nongnu.org, quintela@redhat.com, dgilbert@redhat.com, mreitz@redhat.com 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" migrate-set-parameters sets migration parameters according to is arguments like this: * Present means "set the parameter to this value" * Absent means "leave the parameter unchanged" * Except for parameters tls_creds and tls_hostname, "" means "reset the parameter to its default value The first two are perfectly normal: presence of the parameter makes the command do something. The third one overloads the parameter with a second meaning. The overloading is *implicit*, i.e. it's not visible in the types. Works here, because "" is neither a valid TLS credentials ID, nor a valid host name. Pressing argument values the schema accepts, but are semantically invalid, into service to mean "reset to default" is not general, as suitable invalid values need not exist. I also find it ugly. To clean this up, we could add a separate flag argument to ask for "reset to default", or add a distinct value to @tls_creds and @tls_hostname. This commit implements the latter: add JSON null to the values of @tls_creds and @tls_hostname, deprecate "". Because we're so close to the 2.10 freeze, implement it in the stupidest way possible: have qmp_migrate_set_parameters() rewrite null to "" before anything else can see the null. The proper way to do it would be rewriting "" to null, but that requires fixing up code to work with null. Add TODO comments for that. Signed-off-by: Markus Armbruster Reviewed-by: Daniel P. Berrange Reviewed-by: Eric Blake --- hmp.c | 8 ++++++-- migration/migration.c | 18 ++++++++++++++++-- qapi-schema.json | 11 +++++++++-- 3 files changed, 31 insertions(+), 6 deletions(-) diff --git a/hmp.c b/hmp.c index 0a5de75..40ebeef 100644 --- a/hmp.c +++ b/hmp.c @@ -1541,11 +1541,15 @@ void hmp_migrate_set_parameter(Monitor *mon, const = QDict *qdict) break; case MIGRATION_PARAMETER_TLS_CREDS: p->has_tls_creds =3D true; - visit_type_str(v, param, &p->tls_creds, &err); + p->tls_creds =3D g_new0(StrOrNull, 1); + p->tls_creds->type =3D QTYPE_QSTRING; + visit_type_str(v, param, &p->tls_creds->u.s, &err); break; case MIGRATION_PARAMETER_TLS_HOSTNAME: p->has_tls_hostname =3D true; - visit_type_str(v, param, &p->tls_hostname, &err); + p->tls_hostname =3D g_new0(StrOrNull, 1); + p->tls_hostname->type =3D QTYPE_QSTRING; + visit_type_str(v, param, &p->tls_hostname->u.s, &err); break; case MIGRATION_PARAMETER_MAX_BANDWIDTH: p->has_max_bandwidth =3D true; diff --git a/migration/migration.c b/migration/migration.c index f6a9443..e2cfb99 100644 --- a/migration/migration.c +++ b/migration/migration.c @@ -703,6 +703,20 @@ void qmp_migrate_set_parameters(MigrateSetParameters *= params, Error **errp) "x_checkpoint_delay", "is invalid, it should be positive"); } + /* TODO Rewrite "" to null instead */ + if (params->has_tls_creds + && params->tls_creds->type =3D=3D QTYPE_QNULL) { + QDECREF(params->tls_creds->u.n); + params->tls_creds->type =3D QTYPE_QSTRING; + params->tls_creds->u.s =3D strdup(""); + } + /* TODO Rewrite "" to null instead */ + if (params->has_tls_hostname + && params->tls_hostname->type =3D=3D QTYPE_QNULL) { + QDECREF(params->tls_hostname->u.n); + params->tls_hostname->type =3D QTYPE_QSTRING; + params->tls_hostname->u.s =3D strdup(""); + } =20 /* * TODO if we fuse MigrateSetParameters back into @@ -726,11 +740,11 @@ void qmp_migrate_set_parameters(MigrateSetParameters = *params, Error **errp) } if (params->has_tls_creds) { g_free(s->parameters.tls_creds); - s->parameters.tls_creds =3D g_strdup(params->tls_creds); + s->parameters.tls_creds =3D g_strdup(params->tls_creds->u.s); } if (params->has_tls_hostname) { g_free(s->parameters.tls_hostname); - s->parameters.tls_hostname =3D g_strdup(params->tls_hostname); + s->parameters.tls_hostname =3D g_strdup(params->tls_hostname->u.s); } if (params->has_max_bandwidth) { s->parameters.max_bandwidth =3D params->max_bandwidth; diff --git a/qapi-schema.json b/qapi-schema.json index b5ec942..247af24 100644 --- a/qapi-schema.json +++ b/qapi-schema.json @@ -116,6 +116,13 @@ { 'command': 'qmp_capabilities' } =20 ## +# @StrOrNull: +## +{ 'alternate': 'StrOrNull', + 'data': { 's': 'str', + 'n': 'null' } } + +## # @LostTickPolicy: # # Policy for handling lost ticks in timer devices. @@ -1098,8 +1105,8 @@ '*decompress-threads': 'int', '*cpu-throttle-initial': 'int', '*cpu-throttle-increment': 'int', - '*tls-creds': 'str', - '*tls-hostname': 'str', + '*tls-creds': 'StrOrNull', + '*tls-hostname': 'StrOrNull', '*max-bandwidth': 'int', '*downtime-limit': 'int', '*x-checkpoint-delay': 'int', --=20 2.7.5