From nobody Sun Apr 28 05:06:17 2024 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 1500410178905643.9304596371558; Tue, 18 Jul 2017 13:36:18 -0700 (PDT) Received: from localhost ([::1]:58505 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dXZE8-0003eA-Dv for importer@patchew.org; Tue, 18 Jul 2017 16:36:16 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:58153) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dXZ7W-000572-CE 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 1dXZ7T-00017N-BC for qemu-devel@nongnu.org; Tue, 18 Jul 2017 16:29:26 -0400 Received: from mx1.redhat.com ([209.132.183.28]:35318) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1dXZ7T-00016r-2B for qemu-devel@nongnu.org; Tue, 18 Jul 2017 16:29:23 -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 0CBB74A6E6 for ; Tue, 18 Jul 2017 20:29:22 +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 A0E377F384 for ; Tue, 18 Jul 2017 20:29:21 +0000 (UTC) Received: by blackfin.pond.sub.org (Postfix, from userid 1000) id 54FDE1138647; Tue, 18 Jul 2017 22:29:20 +0200 (CEST) DMARC-Filter: OpenDMARC Filter v1.3.2 mx1.redhat.com 0CBB74A6E6 Authentication-Results: ext-mx09.extmail.prod.ext.phx2.redhat.com; dmarc=none (p=none dis=none) header.from=redhat.com Authentication-Results: ext-mx09.extmail.prod.ext.phx2.redhat.com; spf=pass smtp.mailfrom=armbru@redhat.com DKIM-Filter: OpenDKIM Filter v2.11.0 mx1.redhat.com 0CBB74A6E6 From: Markus Armbruster To: qemu-devel@nongnu.org Date: Tue, 18 Jul 2017 22:29:11 +0200 Message-Id: <1500409760-20730-2-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.13 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.38]); Tue, 18 Jul 2017 20:29:22 +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 01/10] qapi: Separate type QNull from QObject 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" Signed-off-by: Markus Armbruster Reviewed-by: Eric Blake Reviewed-by: Daniel P. Berrange --- include/qapi/qmp/qobject.h | 10 +++++++--- qapi/qobject-output-visitor.c | 2 +- qobject/json-parser.c | 2 +- qobject/qnull.c | 8 +++++--- target/i386/cpu.c | 4 ++-- tests/check-qjson.c | 6 +++--- tests/check-qnull.c | 18 +++++++++--------- 7 files changed, 28 insertions(+), 22 deletions(-) diff --git a/include/qapi/qmp/qobject.h b/include/qapi/qmp/qobject.h index b8ddbca..3543b55 100644 --- a/include/qapi/qmp/qobject.h +++ b/include/qapi/qmp/qobject.h @@ -93,11 +93,15 @@ static inline QType qobject_type(const QObject *obj) return obj->type; } =20 -extern QObject qnull_; +typedef struct QNull { + QObject base; +} QNull; =20 -static inline QObject *qnull(void) +extern QNull qnull_; + +static inline QNull *qnull(void) { - qobject_incref(&qnull_); + QINCREF(&qnull_); return &qnull_; } =20 diff --git a/qapi/qobject-output-visitor.c b/qapi/qobject-output-visitor.c index 70be84c..398dcb5 100644 --- a/qapi/qobject-output-visitor.c +++ b/qapi/qobject-output-visitor.c @@ -190,7 +190,7 @@ static void qobject_output_type_any(Visitor *v, const c= har *name, static void qobject_output_type_null(Visitor *v, const char *name, Error *= *errp) { QObjectOutputVisitor *qov =3D to_qov(v); - qobject_output_add_obj(qov, name, qnull()); + qobject_output_add(qov, name, qnull()); } =20 /* Finish building, and return the root object. diff --git a/qobject/json-parser.c b/qobject/json-parser.c index 7a417f2..724ca24 100644 --- a/qobject/json-parser.c +++ b/qobject/json-parser.c @@ -445,7 +445,7 @@ static QObject *parse_keyword(JSONParserContext *ctxt) } else if (!strcmp(token->str, "false")) { return QOBJECT(qbool_from_bool(false)); } else if (!strcmp(token->str, "null")) { - return qnull(); + return QOBJECT(qnull()); } parse_error(ctxt, token, "invalid keyword '%s'", token->str); return NULL; diff --git a/qobject/qnull.c b/qobject/qnull.c index c124d05..69a21d1 100644 --- a/qobject/qnull.c +++ b/qobject/qnull.c @@ -14,7 +14,9 @@ #include "qemu-common.h" #include "qapi/qmp/qobject.h" =20 -QObject qnull_ =3D { - .type =3D QTYPE_QNULL, - .refcnt =3D 1, +QNull qnull_ =3D { + .base =3D { + .type =3D QTYPE_QNULL, + .refcnt =3D 1, + }, }; diff --git a/target/i386/cpu.c b/target/i386/cpu.c index c571772..10e8386 100644 --- a/target/i386/cpu.c +++ b/target/i386/cpu.c @@ -2394,7 +2394,7 @@ static QDict *x86_cpu_static_props(void) =20 d =3D qdict_new(); for (i =3D 0; props[i]; i++) { - qdict_put_obj(d, props[i], qnull()); + qdict_put(d, props[i], qnull()); } =20 for (w =3D 0; w < FEATURE_WORDS; w++) { @@ -2404,7 +2404,7 @@ static QDict *x86_cpu_static_props(void) if (!fi->feat_names[bit]) { continue; } - qdict_put_obj(d, fi->feat_names[bit], qnull()); + qdict_put(d, fi->feat_names[bit], qnull()); } } =20 diff --git a/tests/check-qjson.c b/tests/check-qjson.c index 53f2275..a3a97b0 100644 --- a/tests/check-qjson.c +++ b/tests/check-qjson.c @@ -1012,7 +1012,7 @@ static void keyword_literal(void) { QObject *obj; QBool *qbool; - QObject *null; + QNull *null; QString *str; =20 obj =3D qobject_from_json("true", &error_abort); @@ -1053,10 +1053,10 @@ static void keyword_literal(void) g_assert(qobject_type(obj) =3D=3D QTYPE_QNULL); =20 null =3D qnull(); - g_assert(null =3D=3D obj); + g_assert(QOBJECT(null) =3D=3D obj); =20 qobject_decref(obj); - qobject_decref(null); + QDECREF(null); } =20 typedef struct LiteralQDictEntry LiteralQDictEntry; diff --git a/tests/check-qnull.c b/tests/check-qnull.c index 8dd1c96..1ab7c98 100644 --- a/tests/check-qnull.c +++ b/tests/check-qnull.c @@ -24,14 +24,14 @@ static void qnull_ref_test(void) { QObject *obj; =20 - g_assert(qnull_.refcnt =3D=3D 1); - obj =3D qnull(); + g_assert(qnull_.base.refcnt =3D=3D 1); + obj =3D QOBJECT(qnull()); g_assert(obj); - g_assert(obj =3D=3D &qnull_); - g_assert(qnull_.refcnt =3D=3D 2); + g_assert(obj =3D=3D QOBJECT(&qnull_)); + g_assert(qnull_.base.refcnt =3D=3D 2); g_assert(qobject_type(obj) =3D=3D QTYPE_QNULL); qobject_decref(obj); - g_assert(qnull_.refcnt =3D=3D 1); + g_assert(qnull_.base.refcnt =3D=3D 1); } =20 static void qnull_visit_test(void) @@ -45,8 +45,8 @@ static void qnull_visit_test(void) * depend on layering violations to check qnull_ refcnt. */ =20 - g_assert(qnull_.refcnt =3D=3D 1); - obj =3D qnull(); + g_assert(qnull_.base.refcnt =3D=3D 1); + obj =3D QOBJECT(qnull()); v =3D qobject_input_visitor_new(obj); qobject_decref(obj); visit_type_null(v, NULL, &error_abort); @@ -55,11 +55,11 @@ static void qnull_visit_test(void) v =3D qobject_output_visitor_new(&obj); visit_type_null(v, NULL, &error_abort); visit_complete(v, &obj); - g_assert(obj =3D=3D &qnull_); + g_assert(obj =3D=3D QOBJECT(&qnull_)); qobject_decref(obj); visit_free(v); =20 - g_assert(qnull_.refcnt =3D=3D 1); + g_assert(qnull_.base.refcnt =3D=3D 1); } =20 int main(int argc, char **argv) --=20 2.7.5 From nobody Sun Apr 28 05:06:17 2024 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 1500409883400659.0295508422507; Tue, 18 Jul 2017 13:31:23 -0700 (PDT) Received: from localhost ([::1]:58482 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dXZ9M-00076F-RU for importer@patchew.org; Tue, 18 Jul 2017 16:31:20 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:58141) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dXZ7W-00056x-Ae for qemu-devel@nongnu.org; Tue, 18 Jul 2017 16:29:28 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1dXZ7T-00017V-DQ for qemu-devel@nongnu.org; Tue, 18 Jul 2017 16:29:26 -0400 Received: from mx1.redhat.com ([209.132.183.28]:59732) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1dXZ7T-00016x-5a for qemu-devel@nongnu.org; Tue, 18 Jul 2017 16:29:23 -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 38CEE8123D for ; Tue, 18 Jul 2017 20:29:22 +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 A216B7F8D5 for ; Tue, 18 Jul 2017 20:29:21 +0000 (UTC) Received: by blackfin.pond.sub.org (Postfix, from userid 1000) id 57E231138648; Tue, 18 Jul 2017 22:29:20 +0200 (CEST) DMARC-Filter: OpenDMARC Filter v1.3.2 mx1.redhat.com 38CEE8123D Authentication-Results: ext-mx01.extmail.prod.ext.phx2.redhat.com; dmarc=none (p=none dis=none) header.from=redhat.com Authentication-Results: ext-mx01.extmail.prod.ext.phx2.redhat.com; spf=pass smtp.mailfrom=armbru@redhat.com DKIM-Filter: OpenDKIM Filter v2.11.0 mx1.redhat.com 38CEE8123D From: Markus Armbruster To: qemu-devel@nongnu.org Date: Tue, 18 Jul 2017 22:29:12 +0200 Message-Id: <1500409760-20730-3-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.13 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.25]); Tue, 18 Jul 2017 20:29:22 +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 02/10] qapi: Use QNull for a more regular visit_type_null() 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" Make visit_type_null() take an @obj argument like its buddies. This helps keep the next commit simple. Signed-off-by: Markus Armbruster Reviewed-by: Eric Blake Reviewed-by: Daniel P. Berrange --- hw/ppc/spapr_drc.c | 7 ++++++- include/qapi/visitor-impl.h | 3 ++- include/qapi/visitor.h | 8 ++++---- qapi/qapi-clone-visitor.c | 5 +++-- qapi/qapi-dealloc-visitor.c | 6 +++++- qapi/qapi-visit-core.c | 7 ++++--- qapi/qobject-input-visitor.c | 6 +++++- qapi/qobject-output-visitor.c | 3 ++- qapi/string-input-visitor.c | 8 +++++++- qapi/string-output-visitor.c | 3 ++- qapi/trace-events | 2 +- target/ppc/translate_init.c | 10 +++++++++- tests/check-qnull.c | 9 +++++++-- tests/test-qobject-input-visitor.c | 13 +++++++++---- tests/test-qobject-output-visitor.c | 3 ++- 15 files changed, 68 insertions(+), 25 deletions(-) diff --git a/hw/ppc/spapr_drc.c b/hw/ppc/spapr_drc.c index f34355d..3920a5b 100644 --- a/hw/ppc/spapr_drc.c +++ b/hw/ppc/spapr_drc.c @@ -267,12 +267,17 @@ static void prop_get_fdt(Object *obj, Visitor *v, con= st char *name, void *opaque, Error **errp) { sPAPRDRConnector *drc =3D SPAPR_DR_CONNECTOR(obj); + QNull *null; Error *err =3D NULL; int fdt_offset_next, fdt_offset, fdt_depth; void *fdt; =20 if (!drc->fdt) { - visit_type_null(v, NULL, errp); + visit_type_null(v, NULL, &null, &err); + if (!err) { + QDECREF(null); + } + error_propagate(errp, err); return; } =20 diff --git a/include/qapi/visitor-impl.h b/include/qapi/visitor-impl.h index dcd656a..8ccb3b6 100644 --- a/include/qapi/visitor-impl.h +++ b/include/qapi/visitor-impl.h @@ -103,7 +103,8 @@ struct Visitor Error **errp); =20 /* Must be set to visit explicit null values. */ - void (*type_null)(Visitor *v, const char *name, Error **errp); + void (*type_null)(Visitor *v, const char *name, QNull **obj, + Error **errp); =20 /* Must be set for input visitors to visit structs, optional otherwise. The core takes care of the return type in the public interface. */ diff --git a/include/qapi/visitor.h b/include/qapi/visitor.h index 74768aa..fe9faf4 100644 --- a/include/qapi/visitor.h +++ b/include/qapi/visitor.h @@ -618,10 +618,10 @@ void visit_type_any(Visitor *v, const char *name, QOb= ject **obj, Error **errp); * @name expresses the relationship of the null value to its parent * container; see the general description of @name above. * - * Unlike all other visit_type_* functions, no obj parameter is - * needed; rather, this is a witness that an explicit null value is - * expected rather than any other type. + * @obj must be non-NULL. Input visitors set *@obj to the value; + * other visitors ignore *@obj. */ -void visit_type_null(Visitor *v, const char *name, Error **errp); +void visit_type_null(Visitor *v, const char *name, QNull **obj, + Error **errp); =20 #endif diff --git a/qapi/qapi-clone-visitor.c b/qapi/qapi-clone-visitor.c index ed16d3a..d8b6279 100644 --- a/qapi/qapi-clone-visitor.c +++ b/qapi/qapi-clone-visitor.c @@ -127,12 +127,13 @@ static void qapi_clone_type_number(Visitor *v, const = char *name, double *obj, /* Value was already cloned by g_memdup() */ } =20 -static void qapi_clone_type_null(Visitor *v, const char *name, Error **err= p) +static void qapi_clone_type_null(Visitor *v, const char *name, QNull **obj, + Error **errp) { QapiCloneVisitor *qcv =3D to_qcv(v); =20 assert(qcv->depth); - /* Nothing to do */ + *obj =3D qnull(); } =20 static void qapi_clone_free(Visitor *v) diff --git a/qapi/qapi-dealloc-visitor.c b/qapi/qapi-dealloc-visitor.c index fd6f9fb..ed70a01 100644 --- a/qapi/qapi-dealloc-visitor.c +++ b/qapi/qapi-dealloc-visitor.c @@ -103,8 +103,12 @@ static void qapi_dealloc_type_anything(Visitor *v, con= st char *name, } } =20 -static void qapi_dealloc_type_null(Visitor *v, const char *name, Error **e= rrp) +static void qapi_dealloc_type_null(Visitor *v, const char *name, + QNull **obj, Error **errp) { + if (obj) { + QDECREF(*obj); + } } =20 static void qapi_dealloc_free(Visitor *v) diff --git a/qapi/qapi-visit-core.c b/qapi/qapi-visit-core.c index 935a2c5..ed6d2af 100644 --- a/qapi/qapi-visit-core.c +++ b/qapi/qapi-visit-core.c @@ -325,10 +325,11 @@ void visit_type_any(Visitor *v, const char *name, QOb= ject **obj, Error **errp) error_propagate(errp, err); } =20 -void visit_type_null(Visitor *v, const char *name, Error **errp) +void visit_type_null(Visitor *v, const char *name, QNull **obj, + Error **errp) { - trace_visit_type_null(v, name); - v->type_null(v, name, errp); + trace_visit_type_null(v, name, obj); + v->type_null(v, name, obj, errp); } =20 static void output_type_enum(Visitor *v, const char *name, int *obj, diff --git a/qapi/qobject-input-visitor.c b/qapi/qobject-input-visitor.c index 35aff78..ee9e47d 100644 --- a/qapi/qobject-input-visitor.c +++ b/qapi/qobject-input-visitor.c @@ -587,11 +587,13 @@ static void qobject_input_type_any(Visitor *v, const = char *name, QObject **obj, *obj =3D qobj; } =20 -static void qobject_input_type_null(Visitor *v, const char *name, Error **= errp) +static void qobject_input_type_null(Visitor *v, const char *name, + QNull **obj, Error **errp) { QObjectInputVisitor *qiv =3D to_qiv(v); QObject *qobj =3D qobject_input_get_object(qiv, name, true, errp); =20 + *obj =3D NULL; if (!qobj) { return; } @@ -599,7 +601,9 @@ static void qobject_input_type_null(Visitor *v, const c= har *name, Error **errp) if (qobject_type(qobj) !=3D QTYPE_QNULL) { error_setg(errp, QERR_INVALID_PARAMETER_TYPE, full_name(qiv, name), "null"); + return; } + *obj =3D qnull(); } =20 static void qobject_input_type_size_keyval(Visitor *v, const char *name, diff --git a/qapi/qobject-output-visitor.c b/qapi/qobject-output-visitor.c index 398dcb5..d325163 100644 --- a/qapi/qobject-output-visitor.c +++ b/qapi/qobject-output-visitor.c @@ -187,7 +187,8 @@ static void qobject_output_type_any(Visitor *v, const c= har *name, qobject_output_add_obj(qov, name, *obj); } =20 -static void qobject_output_type_null(Visitor *v, const char *name, Error *= *errp) +static void qobject_output_type_null(Visitor *v, const char *name, + QNull **obj, Error **errp) { QObjectOutputVisitor *qov =3D to_qov(v); qobject_output_add(qov, name, qnull()); diff --git a/qapi/string-input-visitor.c b/qapi/string-input-visitor.c index 63ae115..67a0a4a 100644 --- a/qapi/string-input-visitor.c +++ b/qapi/string-input-visitor.c @@ -326,14 +326,20 @@ static void parse_type_number(Visitor *v, const char = *name, double *obj, *obj =3D val; } =20 -static void parse_type_null(Visitor *v, const char *name, Error **errp) +static void parse_type_null(Visitor *v, const char *name, QNull **obj, + Error **errp) { StringInputVisitor *siv =3D to_siv(v); =20 + *obj =3D NULL; + if (!siv->string || siv->string[0]) { error_setg(errp, QERR_INVALID_PARAMETER_TYPE, name ? name : "null", "null"); + return; } + + *obj =3D qnull(); } =20 static void string_input_free(Visitor *v) diff --git a/qapi/string-output-visitor.c b/qapi/string-output-visitor.c index af649e1..7ab6446 100644 --- a/qapi/string-output-visitor.c +++ b/qapi/string-output-visitor.c @@ -256,7 +256,8 @@ static void print_type_number(Visitor *v, const char *n= ame, double *obj, string_output_set(sov, g_strdup_printf("%f", *obj)); } =20 -static void print_type_null(Visitor *v, const char *name, Error **errp) +static void print_type_null(Visitor *v, const char *name, QNull **obj, + Error **errp) { StringOutputVisitor *sov =3D to_sov(v); char *out; diff --git a/qapi/trace-events b/qapi/trace-events index 3b57aba..9e9008a 100644 --- a/qapi/trace-events +++ b/qapi/trace-events @@ -31,4 +31,4 @@ visit_type_bool(void *v, const char *name, bool *obj) "v= =3D%p name=3D%s obj=3D%p" visit_type_str(void *v, const char *name, char **obj) "v=3D%p name=3D%s ob= j=3D%p" visit_type_number(void *v, const char *name, double *obj) "v=3D%p name=3D%= s obj=3D%p" visit_type_any(void *v, const char *name, void *obj) "v=3D%p name=3D%s obj= =3D%p" -visit_type_null(void *v, const char *name) "v=3D%p name=3D%s" +visit_type_null(void *v, const char *name, void *obj) "v=3D%p name=3D%s ob= j=3D%p" diff --git a/target/ppc/translate_init.c b/target/ppc/translate_init.c index 783bf98..65e7f34 100644 --- a/target/ppc/translate_init.c +++ b/target/ppc/translate_init.c @@ -8428,11 +8428,19 @@ POWERPC_FAMILY(POWER5P)(ObjectClass *oc, void *data) static void getset_compat_deprecated(Object *obj, Visitor *v, const char *= name, void *opaque, Error **errp) { + Error *err =3D NULL; + QNull *null; + if (!qtest_enabled()) { error_report("CPU 'compat' property is deprecated and has no effec= t; " "use max-cpu-compat machine property instead"); } - visit_type_null(v, name, NULL); + visit_type_null(v, name, &null, &err); + if (err) { + error_free(err); + return; + } + QDECREF(null); } =20 static PropertyInfo ppc_compat_deprecated_propinfo =3D { diff --git a/tests/check-qnull.c b/tests/check-qnull.c index 1ab7c98..5c6eb0a 100644 --- a/tests/check-qnull.c +++ b/tests/check-qnull.c @@ -38,6 +38,7 @@ static void qnull_visit_test(void) { QObject *obj; Visitor *v; + QNull *null; =20 /* * Most tests of interactions between QObject and visitors are in @@ -49,13 +50,17 @@ static void qnull_visit_test(void) obj =3D QOBJECT(qnull()); v =3D qobject_input_visitor_new(obj); qobject_decref(obj); - visit_type_null(v, NULL, &error_abort); + visit_type_null(v, NULL, &null, &error_abort); + g_assert(obj =3D=3D QOBJECT(&qnull_)); + QDECREF(null); visit_free(v); =20 + null =3D NULL; v =3D qobject_output_visitor_new(&obj); - visit_type_null(v, NULL, &error_abort); + visit_type_null(v, NULL, &null, &error_abort); visit_complete(v, &obj); g_assert(obj =3D=3D QOBJECT(&qnull_)); + QDECREF(null); qobject_decref(obj); visit_free(v); =20 diff --git a/tests/test-qobject-input-visitor.c b/tests/test-qobject-input-= visitor.c index 34bab8a..f98caf9 100644 --- a/tests/test-qobject-input-visitor.c +++ b/tests/test-qobject-input-visitor.c @@ -510,6 +510,7 @@ static void test_visitor_in_null(TestInputVisitorData *= data, { Visitor *v; Error *err =3D NULL; + QNull *null; char *tmp; =20 /* @@ -524,12 +525,15 @@ static void test_visitor_in_null(TestInputVisitorData= *data, v =3D visitor_input_test_init_full(data, false, "{ 'a': null, 'b': '' }"); visit_start_struct(v, NULL, NULL, 0, &error_abort); - visit_type_null(v, "a", &error_abort); - visit_type_null(v, "b", &err); + visit_type_null(v, "a", &null, &error_abort); + g_assert(qobject_type(QOBJECT(null)) =3D=3D QTYPE_QNULL); + QDECREF(null); + visit_type_null(v, "b", &null, &err); error_free_or_abort(&err); + g_assert(!null); visit_type_str(v, "c", &tmp, &err); - g_assert(!tmp); error_free_or_abort(&err); + g_assert(!tmp); visit_check_struct(v, &error_abort); visit_end_struct(v, NULL); } @@ -1087,6 +1091,7 @@ static void test_visitor_in_fail_struct_missing(TestI= nputVisitorData *data, Error *err =3D NULL; Visitor *v; QObject *any; + QNull *null; GenericAlternate *alt; bool present; int en; @@ -1120,7 +1125,7 @@ static void test_visitor_in_fail_struct_missing(TestI= nputVisitorData *data, error_free_or_abort(&err); visit_type_any(v, "any", &any, &err); error_free_or_abort(&err); - visit_type_null(v, "null", &err); + visit_type_null(v, "null", &null, &err); error_free_or_abort(&err); visit_start_list(v, "sub", NULL, 0, &error_abort); visit_start_struct(v, NULL, NULL, 0, &error_abort); diff --git a/tests/test-qobject-output-visitor.c b/tests/test-qobject-outpu= t-visitor.c index 749c540..8f1fcd4 100644 --- a/tests/test-qobject-output-visitor.c +++ b/tests/test-qobject-output-visitor.c @@ -445,11 +445,12 @@ static void test_visitor_out_alternate(TestOutputVisi= torData *data, static void test_visitor_out_null(TestOutputVisitorData *data, const void *unused) { + QNull *null =3D NULL; QDict *qdict; QObject *nil; =20 visit_start_struct(data->ov, NULL, NULL, 0, &error_abort); - visit_type_null(data->ov, "a", &error_abort); + visit_type_null(data->ov, "a", &null, &error_abort); visit_check_struct(data->ov, &error_abort); visit_end_struct(data->ov, NULL); qdict =3D qobject_to_qdict(visitor_get(data)); --=20 2.7.5 From nobody Sun Apr 28 05:06:17 2024 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 1500410018408887.9902975024726; Tue, 18 Jul 2017 13:33:38 -0700 (PDT) Received: from localhost ([::1]:58487 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dXZBZ-0000Sc-33 for importer@patchew.org; Tue, 18 Jul 2017 16:33:37 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:58144) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dXZ7W-00056z-At 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 1dXZ7T-00017I-Af for qemu-devel@nongnu.org; Tue, 18 Jul 2017 16:29:26 -0400 Received: from mx1.redhat.com ([209.132.183.28]:60352) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1dXZ7T-00016v-1y for qemu-devel@nongnu.org; Tue, 18 Jul 2017 16:29:23 -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 0FC3E7CE04 for ; Tue, 18 Jul 2017 20:29:22 +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 A511467CD9 for ; Tue, 18 Jul 2017 20:29:21 +0000 (UTC) Received: by blackfin.pond.sub.org (Postfix, from userid 1000) id 5A9A0113864A; Tue, 18 Jul 2017 22:29:20 +0200 (CEST) DMARC-Filter: OpenDMARC Filter v1.3.2 mx1.redhat.com 0FC3E7CE04 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 0FC3E7CE04 From: Markus Armbruster To: qemu-devel@nongnu.org Date: Tue, 18 Jul 2017 22:29:13 +0200 Message-Id: <1500409760-20730-4-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:22 +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 03/10] qapi: Introduce a first class 'null' type 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" I expect the 'null' type to be useful mostly for members of alternate types. Signed-off-by: Markus Armbruster Reviewed-by: Daniel P. Berrange Reviewed-by: Eric Blake Signed-off-by: Markus Armbruster --- docs/devel/qapi-code-gen.txt | 10 ++++++---- include/qapi/qmp/qobject.h | 4 ++-- include/qemu/typedefs.h | 1 + scripts/qapi.py | 5 ++++- tests/qapi-schema/qapi-schema-test.json | 3 ++- tests/qapi-schema/qapi-schema-test.out | 1 + tests/test-qobject-input-visitor.c | 5 +++++ tests/test-qobject-output-visitor.c | 10 ++++++++++ 8 files changed, 31 insertions(+), 8 deletions(-) diff --git a/docs/devel/qapi-code-gen.txt b/docs/devel/qapi-code-gen.txt index 52e3874..9903ac4 100644 --- a/docs/devel/qapi-code-gen.txt +++ b/docs/devel/qapi-code-gen.txt @@ -282,6 +282,7 @@ The following types are predefined, and map to C as fol= lows: size uint64_t like uint64_t, except StringInputVisitor accepts size suffixes bool bool JSON true or false + null QNull * JSON null any QObject * any JSON value QType QType JSON string matching enum QType values =20 @@ -536,10 +537,11 @@ can only express a choice between types represented d= ifferently in JSON. If a branch is typed as the 'bool' built-in, the alternate accepts true and false; if it is typed as any of the various numeric built-ins, it accepts a JSON number; if it is typed as a 'str' -built-in or named enum type, it accepts a JSON string; and if it is -typed as a complex type (struct or union), it accepts a JSON object. -Two different complex types, for instance, aren't permitted, because -both are represented as a JSON object. +built-in or named enum type, it accepts a JSON string; if it is typed +as the 'null' built-in, it accepts JSON null; and if it is typed as a +complex type (struct or union), it accepts a JSON object. Two +different complex types, for instance, aren't permitted, because both +are represented as a JSON object. =20 The example alternate declaration above allows using both of the following example objects: diff --git a/include/qapi/qmp/qobject.h b/include/qapi/qmp/qobject.h index 3543b55..eab29ed 100644 --- a/include/qapi/qmp/qobject.h +++ b/include/qapi/qmp/qobject.h @@ -93,9 +93,9 @@ static inline QType qobject_type(const QObject *obj) return obj->type; } =20 -typedef struct QNull { +struct QNull { QObject base; -} QNull; +}; =20 extern QNull qnull_; =20 diff --git a/include/qemu/typedefs.h b/include/qemu/typedefs.h index 2706aab..ba69bd8 100644 --- a/include/qemu/typedefs.h +++ b/include/qemu/typedefs.h @@ -87,6 +87,7 @@ typedef struct QEMUSGList QEMUSGList; typedef struct QEMUTimer QEMUTimer; typedef struct QEMUTimerListGroup QEMUTimerListGroup; typedef struct QObject QObject; +typedef struct QNull QNull; typedef struct RAMBlock RAMBlock; typedef struct Range Range; typedef struct SerialState SerialState; diff --git a/scripts/qapi.py b/scripts/qapi.py index 84e2eb4..8aa2775 100644 --- a/scripts/qapi.py +++ b/scripts/qapi.py @@ -20,6 +20,7 @@ import sys from ordereddict import OrderedDict =20 builtin_types =3D { + 'null': 'QTYPE_QNULL', 'str': 'QTYPE_QSTRING', 'int': 'QTYPE_QNUM', 'number': 'QTYPE_QNUM', @@ -1056,6 +1057,7 @@ class QAPISchemaType(QAPISchemaEntity): =20 def alternate_qtype(self): json2qtype =3D { + 'null': 'QTYPE_QNULL', 'string': 'QTYPE_QSTRING', 'number': 'QTYPE_QNUM', 'int': 'QTYPE_QNUM', @@ -1515,7 +1517,8 @@ class QAPISchema(object): ('uint64', 'int', 'uint64_t'), ('size', 'int', 'uint64_t'), ('bool', 'boolean', 'bool'), - ('any', 'value', 'QObject' + pointer_suffix)]: + ('any', 'value', 'QObject' + pointer_suffix), + ('null', 'null', 'QNull' + pointer_suffix)]: self._def_builtin_type(*t) self.the_empty_object_type =3D QAPISchemaObjectType( 'q_empty', None, None, None, [], None) diff --git a/tests/qapi-schema/qapi-schema-test.json b/tests/qapi-schema/qa= pi-schema-test.json index 91ffb26..c72dbd8 100644 --- a/tests/qapi-schema/qapi-schema-test.json +++ b/tests/qapi-schema/qapi-schema-test.json @@ -93,7 +93,8 @@ { 'struct': 'WrapAlternate', 'data': { 'alt': 'UserDefAlternate' } } { 'alternate': 'UserDefAlternate', - 'data': { 'udfu': 'UserDefFlatUnion', 'e': 'EnumOne', 'i': 'int' } } + 'data': { 'udfu': 'UserDefFlatUnion', 'e': 'EnumOne', 'i': 'int', + 'n': 'null' } } =20 { 'struct': 'UserDefC', 'data': { 'string1': 'str', 'string2': 'str' } } diff --git a/tests/qapi-schema/qapi-schema-test.out b/tests/qapi-schema/qap= i-schema-test.out index b88b8aa..3b1e908 100644 --- a/tests/qapi-schema/qapi-schema-test.out +++ b/tests/qapi-schema/qapi-schema-test.out @@ -64,6 +64,7 @@ alternate UserDefAlternate case udfu: UserDefFlatUnion case e: EnumOne case i: int + case n: null object UserDefB member intb: int optional=3DFalse member a-b: bool optional=3DTrue diff --git a/tests/test-qobject-input-visitor.c b/tests/test-qobject-input-= visitor.c index f98caf9..f451844 100644 --- a/tests/test-qobject-input-visitor.c +++ b/tests/test-qobject-input-visitor.c @@ -583,6 +583,11 @@ static void test_visitor_in_alternate(TestInputVisitor= Data *data, g_assert_cmpint(tmp->u.e, =3D=3D, ENUM_ONE_VALUE1); qapi_free_UserDefAlternate(tmp); =20 + v =3D visitor_input_test_init(data, "null"); + visit_type_UserDefAlternate(v, NULL, &tmp, &error_abort); + g_assert_cmpint(tmp->type, =3D=3D, QTYPE_QNULL); + qapi_free_UserDefAlternate(tmp); + v =3D visitor_input_test_init(data, "{'integer':1, 'string':'str', " "'enum1':'value1', 'boolean':true}"); visit_type_UserDefAlternate(v, NULL, &tmp, &error_abort); diff --git a/tests/test-qobject-output-visitor.c b/tests/test-qobject-outpu= t-visitor.c index 8f1fcd4..7eb1620 100644 --- a/tests/test-qobject-output-visitor.c +++ b/tests/test-qobject-output-visitor.c @@ -424,6 +424,16 @@ static void test_visitor_out_alternate(TestOutputVisit= orData *data, =20 visitor_reset(data); tmp =3D g_new0(UserDefAlternate, 1); + tmp->type =3D QTYPE_QNULL; + tmp->u.n =3D qnull(); + + visit_type_UserDefAlternate(data->ov, NULL, &tmp, &error_abort); + g_assert_cmpint(qobject_type(visitor_get(data)), =3D=3D, QTYPE_QNULL); + + qapi_free_UserDefAlternate(tmp); + + visitor_reset(data); + tmp =3D g_new0(UserDefAlternate, 1); tmp->type =3D QTYPE_QDICT; tmp->u.udfu.integer =3D 1; tmp->u.udfu.string =3D g_strdup("str"); --=20 2.7.5 From nobody Sun Apr 28 05:06:17 2024 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 1500409876040344.3877139075365; Tue, 18 Jul 2017 13:31:16 -0700 (PDT) Received: from localhost ([::1]:58480 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dXZ9F-0006sQ-H5 for importer@patchew.org; Tue, 18 Jul 2017 16:31:13 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:58146) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dXZ7W-000570-B1 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 1dXZ7T-000174-3Q for qemu-devel@nongnu.org; Tue, 18 Jul 2017 16:29:26 -0400 Received: from mx1.redhat.com ([209.132.183.28]:38456) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1dXZ7S-00016p-T7 for qemu-devel@nongnu.org; Tue, 18 Jul 2017 16:29:23 -0400 Received: from smtp.corp.redhat.com (int-mx04.intmail.prod.int.phx2.redhat.com [10.5.11.14]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id DD783A04EA for ; Tue, 18 Jul 2017 20:29:21 +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 A87E55F912 for ; Tue, 18 Jul 2017 20:29:21 +0000 (UTC) Received: by blackfin.pond.sub.org (Postfix, from userid 1000) id 5D45B113864C; Tue, 18 Jul 2017 22:29:20 +0200 (CEST) DMARC-Filter: OpenDMARC Filter v1.3.2 mx1.redhat.com DD783A04EA Authentication-Results: ext-mx02.extmail.prod.ext.phx2.redhat.com; dmarc=none (p=none dis=none) header.from=redhat.com Authentication-Results: ext-mx02.extmail.prod.ext.phx2.redhat.com; spf=pass smtp.mailfrom=armbru@redhat.com DKIM-Filter: OpenDKIM Filter v2.11.0 mx1.redhat.com DD783A04EA From: Markus Armbruster To: qemu-devel@nongnu.org Date: Tue, 18 Jul 2017 22:29:14 +0200 Message-Id: <1500409760-20730-5-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.14 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.26]); Tue, 18 Jul 2017 20:29:22 +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 04/10] tests/test-qobject-input-visitor: Drop redundant test 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" test_visitor_in_alternate() tests UserDefAlternate with inadmissible input. test_visitor_in_fail_alternate() does basically the same. Drop the former, keep the latter. Signed-off-by: Markus Armbruster Reviewed-by: Eric Blake Reviewed-by: Daniel P. Berrange --- tests/test-qobject-input-visitor.c | 6 ------ 1 file changed, 6 deletions(-) diff --git a/tests/test-qobject-input-visitor.c b/tests/test-qobject-input-= visitor.c index f451844..bcf0261 100644 --- a/tests/test-qobject-input-visitor.c +++ b/tests/test-qobject-input-visitor.c @@ -567,7 +567,6 @@ static void test_visitor_in_alternate(TestInputVisitorD= ata *data, const void *unused) { Visitor *v; - Error *err =3D NULL; UserDefAlternate *tmp; WrapAlternate *wrap; =20 @@ -599,11 +598,6 @@ static void test_visitor_in_alternate(TestInputVisitor= Data *data, g_assert_cmpint(tmp->u.udfu.u.value1.has_a_b, =3D=3D, false); qapi_free_UserDefAlternate(tmp); =20 - v =3D visitor_input_test_init(data, "false"); - visit_type_UserDefAlternate(v, NULL, &tmp, &err); - error_free_or_abort(&err); - qapi_free_UserDefAlternate(tmp); - v =3D visitor_input_test_init(data, "{ 'alt': 42 }"); visit_type_WrapAlternate(v, NULL, &wrap, &error_abort); g_assert_cmpint(wrap->alt->type, =3D=3D, QTYPE_QNUM); --=20 2.7.5 From nobody Sun Apr 28 05:06:17 2024 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 1500410326990593.6109433790041; Tue, 18 Jul 2017 13:38:46 -0700 (PDT) Received: from localhost ([::1]:58515 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dXZGW-0005aI-Gp for importer@patchew.org; Tue, 18 Jul 2017 16:38:44 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:58140) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dXZ7W-00056w-A0 for qemu-devel@nongnu.org; Tue, 18 Jul 2017 16:29:28 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1dXZ7U-00018G-R9 for qemu-devel@nongnu.org; Tue, 18 Jul 2017 16:29:26 -0400 Received: from mx1.redhat.com ([209.132.183.28]:45032) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1dXZ7U-00017h-IP for qemu-devel@nongnu.org; Tue, 18 Jul 2017 16:29:24 -0400 Received: from smtp.corp.redhat.com (int-mx04.intmail.prod.int.phx2.redhat.com [10.5.11.14]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 9250D61BBB 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 3420E5F912 for ; Tue, 18 Jul 2017 20:29:23 +0000 (UTC) Received: by blackfin.pond.sub.org (Postfix, from userid 1000) id 60CDC113864D; Tue, 18 Jul 2017 22:29:20 +0200 (CEST) DMARC-Filter: OpenDMARC Filter v1.3.2 mx1.redhat.com 9250D61BBB Authentication-Results: ext-mx10.extmail.prod.ext.phx2.redhat.com; dmarc=none (p=none dis=none) header.from=redhat.com Authentication-Results: ext-mx10.extmail.prod.ext.phx2.redhat.com; spf=pass smtp.mailfrom=armbru@redhat.com DKIM-Filter: OpenDKIM Filter v2.11.0 mx1.redhat.com 9250D61BBB From: Markus Armbruster To: qemu-devel@nongnu.org Date: Tue, 18 Jul 2017 22:29:15 +0200 Message-Id: <1500409760-20730-6-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.14 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.39]); 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 05/10] block: Use JSON null instead of "" to disable backing file 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" BlockdevRef is an alternate of BlockdevOptions (inline definition) and str (reference to an existing block device by name). BlockdevRef value "" is special: "no block device should be referenced." It's actually interpreted that way in just one place: optional member @backing of COW formats. Semantics: * Present means "use this block device" as backing storage * Absent means "default to the one stored in the image" * Except "" means "don't use backing storage at all" The first two are perfectly normal: when the parameter is absent, it defaults to an implied value, but the value's meaning is the same. 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 not a value block device ID. Pressing argument values the schema accepts, but are semantically invalid, into service to mean "do something else entirely" 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 suppress @backing, or add a distinct value to @backing. This commit implements the latter: add JSON null to the values of @backing, deprecate "". Because we're so close to the 2.10 freeze, implement it in the stupidest way possible: have qmp_blockdev_add() rewrite null to "" before anything else can see the null. Works, because BlockdevRef occurs only within arguments of blockdev-add. The proper way to do it would be rewriting "" to null, preferably in a cleaner way, but that requires fixing up code to work with null. Add a TODO comment for that. Signed-off-by: Markus Armbruster Reviewed-by: Daniel P. Berrange Acked-by: Kevin Wolf Reviewed-by: Eric Blake --- blockdev.c | 14 ++++++++++++++ qapi/block-core.json | 29 ++++++++++++++++++++++------- tests/qemu-iotests/085 | 2 +- tests/qemu-iotests/139 | 2 +- 4 files changed, 38 insertions(+), 9 deletions(-) diff --git a/blockdev.c b/blockdev.c index 9c6dd27..1c42699 100644 --- a/blockdev.c +++ b/blockdev.c @@ -3886,6 +3886,7 @@ void qmp_blockdev_add(BlockdevOptions *options, Error= **errp) QObject *obj; Visitor *v =3D qobject_output_visitor_new(&obj); QDict *qdict; + const QDictEntry *ent; Error *local_err =3D NULL; =20 visit_type_BlockdevOptions(v, NULL, &options, &local_err); @@ -3899,6 +3900,19 @@ void qmp_blockdev_add(BlockdevOptions *options, Erro= r **errp) =20 qdict_flatten(qdict); =20 + /* + * Rewrite "backing": null to "backing": "" + * TODO Rewrite "" to null instead, and perhaps not even here + */ + for (ent =3D qdict_first(qdict); ent; ent =3D qdict_next(qdict, ent)) { + char *dot =3D strrchr(ent->key, '.'); + + if (!strcmp(dot ? dot + 1 : ent->key, "backing") + && qobject_type(ent->value) =3D=3D QTYPE_QNULL) { + qdict_put(qdict, ent->key, qstring_new()); + } + } + if (!qdict_get_try_str(qdict, "node-name")) { error_setg(errp, "'node-name' must be specified for the root node"= ); goto fail; diff --git a/qapi/block-core.json b/qapi/block-core.json index c437aa5..4088041 100644 --- a/qapi/block-core.json +++ b/qapi/block-core.json @@ -2266,15 +2266,14 @@ # besides their data source and an optional backing file. # # @backing: reference to or definition of the backing file block -# device (if missing, taken from the image file content). It= is -# allowed to pass an empty string here in order to disable t= he -# default backing file. +# device, null disables the backing file entirely. +# Defaults to the backing file stored the image file. # # Since: 2.9 ## { 'struct': 'BlockdevOptionsGenericCOWFormat', 'base': 'BlockdevOptionsGenericFormat', - 'data': { '*backing': 'BlockdevRef' } } + 'data': { '*backing': 'BlockdevRefOrNull' } } =20 ## # @Qcow2OverlapCheckMode: @@ -3113,9 +3112,7 @@ # Reference to a block device. # # @definition: defines a new block device inline -# @reference: references the ID of an existing block device. An -# empty string means that no block device should be -# referenced. +# @reference: references the ID of an existing block device # # Since: 2.9 ## @@ -3124,6 +3121,24 @@ 'reference': 'str' } } =20 ## +# @BlockdevRefOrNull: +# +# Reference to a block device. +# +# @definition: defines a new block device inline +# @reference: references the ID of an existing block device. +# An empty string means that no block device should +# be referenced. Deprecated; use null instead. +# @null: No block device should be referenced (since 2.10) +# +# Since: 2.9 +## +{ 'alternate': 'BlockdevRefOrNull', + 'data': { 'definition': 'BlockdevOptions', + 'reference': 'str', + 'null': 'null' } } + +## # @blockdev-add: # # Creates a new block device. If the @id option is given at the top level,= a diff --git a/tests/qemu-iotests/085 b/tests/qemu-iotests/085 index b97adcd..76e10aa 100755 --- a/tests/qemu-iotests/085 +++ b/tests/qemu-iotests/085 @@ -106,7 +106,7 @@ function add_snapshot_image() snapshot_file=3D"${TEST_DIR}/${1}-${snapshot_virt0}" _make_test_img -b "${base_image}" "$size" mv "${TEST_IMG}" "${snapshot_file}" - do_blockdev_add "$1" "'backing': '', " "${snapshot_file}" + do_blockdev_add "$1" "'backing': null, " "${snapshot_file}" } =20 # ${1}: unique identifier for the snapshot filename diff --git a/tests/qemu-iotests/139 b/tests/qemu-iotests/139 index 175d8f0..b2f14db 100644 --- a/tests/qemu-iotests/139 +++ b/tests/qemu-iotests/139 @@ -69,7 +69,7 @@ class TestBlockdevDel(iotests.QMPTestCase): '-b', base_img, new_img, '1M') opts =3D {'driver': iotests.imgfmt, 'node-name': node, - 'backing': '', + 'backing': None, 'file': {'driver': 'file', 'filename': new_img}} result =3D self.vm.qmp('blockdev-add', conv_keys =3D False, **opts) --=20 2.7.5 From nobody Sun Apr 28 05:06:17 2024 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 From nobody Sun Apr 28 05:06:17 2024 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 1500409874819346.8170656361724; Tue, 18 Jul 2017 13:31:14 -0700 (PDT) Received: from localhost ([::1]:58479 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dXZ9E-0006qv-Oc for importer@patchew.org; Tue, 18 Jul 2017 16:31:12 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:58139) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dXZ7W-00056v-9o 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-00018U-SE for qemu-devel@nongnu.org; Tue, 18 Jul 2017 16:29:26 -0400 Received: from mx1.redhat.com ([209.132.183.28]:38510) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1dXZ7U-00017o-K6 for qemu-devel@nongnu.org; Tue, 18 Jul 2017 16:29:24 -0400 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 A3E88A04E8 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 42E5E77D4C for ; Tue, 18 Jul 2017 20:29:23 +0000 (UTC) Received: by blackfin.pond.sub.org (Postfix, from userid 1000) id 6F5571138651; Tue, 18 Jul 2017 22:29:20 +0200 (CEST) DMARC-Filter: OpenDMARC Filter v1.3.2 mx1.redhat.com A3E88A04E8 Authentication-Results: ext-mx02.extmail.prod.ext.phx2.redhat.com; dmarc=none (p=none dis=none) header.from=redhat.com Authentication-Results: ext-mx02.extmail.prod.ext.phx2.redhat.com; spf=pass smtp.mailfrom=armbru@redhat.com DKIM-Filter: OpenDKIM Filter v2.11.0 mx1.redhat.com A3E88A04E8 From: Markus Armbruster To: qemu-devel@nongnu.org Date: Tue, 18 Jul 2017 22:29:17 +0200 Message-Id: <1500409760-20730-8-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.12 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.26]); 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 07/10] migration: Clean up around tls_creds, tls_hostname 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" Optional MigrationParameters members tls_creds and tls_hostname can't actually be absent outside qmp_migrate_set_parameters() since commit 4af245d (v2.9.0). Note that commit 4af245d reverted the part of commit de63ab6 (v2.8.0) that made tls_creds and tls_hostname absent instead of "" in the value of query-migrate-parameters, even though commit de63ab6 called that a mistake. What a mess. Drop the redundant tests for presence, and update documentation. Signed-off-by: Markus Armbruster Reviewed-by: Daniel P. Berrange Reviewed-by: Eric Blake Reviewed-by: Dr. David Alan Gilbert --- hmp.c | 6 ++++-- migration/migration.c | 4 ++-- qapi-schema.json | 11 +++++------ 3 files changed, 11 insertions(+), 10 deletions(-) diff --git a/hmp.c b/hmp.c index 2993586..2b2db3c 100644 --- a/hmp.c +++ b/hmp.c @@ -313,12 +313,14 @@ void hmp_info_migrate_parameters(Monitor *mon, const = QDict *qdict) monitor_printf(mon, "%s: %" PRId64 "\n", MigrationParameter_lookup[MIGRATION_PARAMETER_CPU_THROTTLE_INC= REMENT], params->cpu_throttle_increment); + assert(params->has_tls_creds); monitor_printf(mon, "%s: '%s'\n", MigrationParameter_lookup[MIGRATION_PARAMETER_TLS_CREDS], - params->has_tls_creds ? params->tls_creds : ""); + params->tls_creds); + assert(params->has_tls_hostname); monitor_printf(mon, "%s: '%s'\n", MigrationParameter_lookup[MIGRATION_PARAMETER_TLS_HOSTNAME], - params->has_tls_hostname ? params->tls_hostname : ""); + params->tls_hostname); assert(params->has_max_bandwidth); monitor_printf(mon, "%s: %" PRId64 " bytes/second\n", MigrationParameter_lookup[MIGRATION_PARAMETER_MAX_BANDWIDTH], diff --git a/migration/migration.c b/migration/migration.c index a0db40d..bae9808 100644 --- a/migration/migration.c +++ b/migration/migration.c @@ -438,9 +438,9 @@ MigrationParameters *qmp_query_migrate_parameters(Error= **errp) params->cpu_throttle_initial =3D s->parameters.cpu_throttle_initial; params->has_cpu_throttle_increment =3D true; params->cpu_throttle_increment =3D s->parameters.cpu_throttle_incremen= t; - params->has_tls_creds =3D !!s->parameters.tls_creds; + params->has_tls_creds =3D true; params->tls_creds =3D g_strdup(s->parameters.tls_creds); - params->has_tls_hostname =3D !!s->parameters.tls_hostname; + params->has_tls_hostname =3D true; params->tls_hostname =3D g_strdup(s->parameters.tls_hostname); params->has_max_bandwidth =3D true; params->max_bandwidth =3D s->parameters.max_bandwidth; diff --git a/qapi-schema.json b/qapi-schema.json index 485767f..7b75cf1 100644 --- a/qapi-schema.json +++ b/qapi-schema.json @@ -1054,9 +1054,7 @@ # @MigrationParameters: # # Optional members can be omitted on input ('migrate-set-parameters') -# but most members will always be present on output -# ('query-migrate-parameters'), with the exception of tls-creds and -# tls-hostname. +# but members will always be present on output. # # @compress-level: compression level # @@ -1077,10 +1075,10 @@ # channel. On the outgoing side of the migration, the credenti= als # must be for a 'client' endpoint, while for the incoming side= the # credentials must be for a 'server' endpoint. Setting this -# will enable TLS for all migrations. The default is unset, -# resulting in unsecured migration at the QEMU level. (Since 2= .7) +# to a non-empty string enables TLS for all migrations. # An empty string means that QEMU will use plain text mode for -# migration, rather than TLS (Since 2.9) +# migration, rather than TLS (Since 2.7) +# Note: 2.8 reports this by omitting tls-creds instead. # # @tls-hostname: hostname of the target host for the migration. This # is required when using x509 based TLS credentials and the @@ -1090,6 +1088,7 @@ # certificate identity can be validated. (Since 2.7) # An empty string means that QEMU will use the hostname # associated with the migration URI, if any. (Since 2.9) +# Note: 2.8 reports this by omitting tls-hostname instead. # # @max-bandwidth: to set maximum speed for migration. maximum speed in # bytes per second. (Since 2.8) --=20 2.7.5 From nobody Sun Apr 28 05:06:17 2024 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 150041001962572.74251194692272; Tue, 18 Jul 2017 13:33:39 -0700 (PDT) Received: from localhost ([::1]:58488 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dXZBa-0000TU-Ea for importer@patchew.org; Tue, 18 Jul 2017 16:33:38 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:58142) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dXZ7W-00056y-B8 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-000189-PV for qemu-devel@nongnu.org; Tue, 18 Jul 2017 16:29:26 -0400 Received: from mx1.redhat.com ([209.132.183.28]:52358) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1dXZ7U-00017e-JT for qemu-devel@nongnu.org; Tue, 18 Jul 2017 16:29:24 -0400 Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.phx2.redhat.com [10.5.11.15]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 8479E3683C 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 4452761F52 for ; Tue, 18 Jul 2017 20:29:23 +0000 (UTC) Received: by blackfin.pond.sub.org (Postfix, from userid 1000) id 758121138657; Tue, 18 Jul 2017 22:29:20 +0200 (CEST) DMARC-Filter: OpenDMARC Filter v1.3.2 mx1.redhat.com 8479E3683C Authentication-Results: ext-mx06.extmail.prod.ext.phx2.redhat.com; dmarc=none (p=none dis=none) header.from=redhat.com Authentication-Results: ext-mx06.extmail.prod.ext.phx2.redhat.com; spf=pass smtp.mailfrom=armbru@redhat.com DKIM-Filter: OpenDKIM Filter v2.11.0 mx1.redhat.com 8479E3683C From: Markus Armbruster To: qemu-devel@nongnu.org Date: Tue, 18 Jul 2017 22:29:18 +0200 Message-Id: <1500409760-20730-9-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.15 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.30]); 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 08/10] migration: Add TODO comments on duplication of QAPI_CLONE() 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" qmp_query_migrate_parameters() and qmp_migrate_set_parameters() effectively duplicate QAPI_CLONE() inline. Add suitable TODO comments. Signed-off-by: Markus Armbruster Reviewed-by: Daniel P. Berrange Reviewed-by: Eric Blake --- migration/migration.c | 2 ++ 1 file changed, 2 insertions(+) diff --git a/migration/migration.c b/migration/migration.c index bae9808..d0a1d13 100644 --- a/migration/migration.c +++ b/migration/migration.c @@ -427,6 +427,7 @@ MigrationParameters *qmp_query_migrate_parameters(Error= **errp) MigrationParameters *params; MigrationState *s =3D migrate_get_current(); =20 + /* TODO use QAPI_CLONE() instead of duplicating it inline */ params =3D g_malloc0(sizeof(*params)); params->has_compress_level =3D true; params->compress_level =3D s->parameters.compress_level; @@ -703,6 +704,7 @@ void qmp_migrate_set_parameters(MigrationParameters *pa= rams, Error **errp) "is invalid, it should be positive"); } =20 + /* TODO use QAPI_CLONE() instead of duplicating it inline */ if (params->has_compress_level) { s->parameters.compress_level =3D params->compress_level; } --=20 2.7.5 From nobody Sun Apr 28 05:06:17 2024 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 1500410180868767.0378631107369; Tue, 18 Jul 2017 13:36:20 -0700 (PDT) Received: from localhost ([::1]:58507 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dXZEA-0003g8-Cp for importer@patchew.org; Tue, 18 Jul 2017 16:36:18 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:58163) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dXZ7W-000576-TA for qemu-devel@nongnu.org; Tue, 18 Jul 2017 16:29:28 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1dXZ7V-00018l-38 for qemu-devel@nongnu.org; Tue, 18 Jul 2017 16:29:26 -0400 Received: from mx1.redhat.com ([209.132.183.28]:60396) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1dXZ7U-00017w-PE for qemu-devel@nongnu.org; Tue, 18 Jul 2017 16:29:24 -0400 Received: from smtp.corp.redhat.com (int-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.11]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id C1CFA7CE0B 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 63AF9600CC for ; Tue, 18 Jul 2017 20:29:23 +0000 (UTC) Received: by blackfin.pond.sub.org (Postfix, from userid 1000) id 7BAF0113866C; Tue, 18 Jul 2017 22:29:20 +0200 (CEST) DMARC-Filter: OpenDMARC Filter v1.3.2 mx1.redhat.com C1CFA7CE0B 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 C1CFA7CE0B From: Markus Armbruster To: qemu-devel@nongnu.org Date: Tue, 18 Jul 2017 22:29:19 +0200 Message-Id: <1500409760-20730-10-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.11 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 09/10] migration: Unshare MigrationParameters struct for now 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" Commit de63ab6 "migrate: Share common MigrationParameters struct" reused MigrationParameters for the arguments of migrate-set-parameters, with the following rationale: It is rather verbose, and slightly error-prone, to repeat the same set of parameters for input (migrate-set-parameters) as for output (query-migrate-parameters), where the only difference is whether the members are optional. We can just document that the optional members will always be present on output, and then share a common struct between both commands. The next patch can then reduce the amount of code needed on input. I need to unshare them to correct a design flaw in a stupid, but minimally invasive way, in the next commit. We can restore the sharing when we redo that patch in a less stupid way. Add a suitable TODO comment. Note that I revert only the sharing part of commit de63ab6, not the part that made the members of query-migrate-parameters' result optional. The schema (and thus introspection) remains inaccurate for query-migrate-parameters. If we decide not to restore the sharing, we should revert that part, too. Signed-off-by: Markus Armbruster Reviewed-by: Daniel P. Berrange Reviewed-by: Eric Blake --- hmp.c | 4 +-- migration/migration.c | 12 +++++--- qapi-schema.json | 85 ++++++++++++++++++++++++++++++++++++++++++++++-= ---- 3 files changed, 87 insertions(+), 14 deletions(-) diff --git a/hmp.c b/hmp.c index 2b2db3c..0a5de75 100644 --- a/hmp.c +++ b/hmp.c @@ -1511,7 +1511,7 @@ void hmp_migrate_set_parameter(Monitor *mon, const QD= ict *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); + MigrateSetParameters *p =3D g_new0(MigrateSetParameters, 1); uint64_t valuebw =3D 0; Error *err =3D NULL; int i, ret; @@ -1589,7 +1589,7 @@ void hmp_migrate_set_parameter(Monitor *mon, const QD= ict *qdict) } =20 cleanup: - qapi_free_MigrationParameters(p); + qapi_free_MigrateSetParameters(p); visit_free(v); if (err) { error_report_err(err); diff --git a/migration/migration.c b/migration/migration.c index d0a1d13..f6a9443 100644 --- a/migration/migration.c +++ b/migration/migration.c @@ -644,7 +644,7 @@ void qmp_migrate_set_capabilities(MigrationCapabilitySt= atusList *params, } } =20 -void qmp_migrate_set_parameters(MigrationParameters *params, Error **errp) +void qmp_migrate_set_parameters(MigrateSetParameters *params, Error **errp) { MigrationState *s =3D migrate_get_current(); =20 @@ -704,7 +704,11 @@ void qmp_migrate_set_parameters(MigrationParameters *p= arams, Error **errp) "is invalid, it should be positive"); } =20 - /* TODO use QAPI_CLONE() instead of duplicating it inline */ + /* + * TODO if we fuse MigrateSetParameters back into + * MigrationParameters, use QAPI_CLONE() instead of duplicating it + * inline + */ if (params->has_compress_level) { s->parameters.compress_level =3D params->compress_level; } @@ -1165,7 +1169,7 @@ int64_t qmp_query_migrate_cache_size(Error **errp) =20 void qmp_migrate_set_speed(int64_t value, Error **errp) { - MigrationParameters p =3D { + MigrateSetParameters p =3D { .has_max_bandwidth =3D true, .max_bandwidth =3D value, }; @@ -1185,7 +1189,7 @@ void qmp_migrate_set_downtime(double value, Error **e= rrp) value *=3D 1000; /* Convert to milliseconds */ value =3D MAX(0, MIN(INT64_MAX, value)); =20 - MigrationParameters p =3D { + MigrateSetParameters p =3D { .has_downtime_limit =3D true, .downtime_limit =3D value, }; diff --git a/qapi-schema.json b/qapi-schema.json index 7b75cf1..b5ec942 100644 --- a/qapi-schema.json +++ b/qapi-schema.json @@ -1035,6 +1035,77 @@ 'downtime-limit', 'x-checkpoint-delay', 'block-incremental' ] } =20 ## +# @MigrateSetParameters: +# +# @compress-level: compression level +# +# @compress-threads: compression thread count +# +# @decompress-threads: decompression thread count +# +# @cpu-throttle-initial: Initial percentage of time guest cpus are +# throttled when migration auto-converge is activat= ed. +# The default value is 20. (Since 2.7) +# +# @cpu-throttle-increment: throttle percentage increase each time +# auto-converge detects that migration is not mak= ing +# progress. The default value is 10. (Since 2.7) +# +# @tls-creds: ID of the 'tls-creds' object that provides credentials +# for establishing a TLS connection over the migration data +# channel. On the outgoing side of the migration, the credenti= als +# must be for a 'client' endpoint, while for the incoming side= the +# credentials must be for a 'server' endpoint. Setting this +# to a non-empty string enables TLS for all migrations. +# An empty string means that QEMU will use plain text mode for +# migration, rather than TLS (Since 2.9) +# Previously (since 2.7), this was reported by omitting +# tls-creds instead. +# +# @tls-hostname: hostname of the target host for the migration. This +# is required when using x509 based TLS credentials and the +# migration URI does not already include a hostname. For +# example if using fd: or exec: based migration, the +# hostname must be provided so that the server's x509 +# certificate identity can be validated. (Since 2.7) +# An empty string means that QEMU will use the hostname +# associated with the migration URI, if any. (Since 2.9) +# Previously (since 2.7), this was reported by omitting +# tls-hostname instead. +# +# @max-bandwidth: to set maximum speed for migration. maximum speed in +# bytes per second. (Since 2.8) +# +# @downtime-limit: set maximum tolerated downtime for migration. maximum +# downtime in milliseconds (Since 2.8) +# +# @x-checkpoint-delay: the delay time between two COLO checkpoints. (Since= 2.8) +# +# @block-incremental: Affects how much storage is migrated when the +# block migration capability is enabled. When false, the entire +# storage backing chain is migrated into a flattened image at +# the destination; when true, only the active qcow2 layer is +# migrated and the destination must already have access to the +# same backing chain as was used on the source. (since 2.10) +# +# Since: 2.4 +## +# TODO either fuse back into MigrationParameters, or make +# MigrationParameters members mandatory +{ 'struct': 'MigrateSetParameters', + 'data': { '*compress-level': 'int', + '*compress-threads': 'int', + '*decompress-threads': 'int', + '*cpu-throttle-initial': 'int', + '*cpu-throttle-increment': 'int', + '*tls-creds': 'str', + '*tls-hostname': 'str', + '*max-bandwidth': 'int', + '*downtime-limit': 'int', + '*x-checkpoint-delay': 'int', + '*block-incremental': 'bool' } } + +## # @migrate-set-parameters: # # Set various migration parameters. @@ -1048,13 +1119,12 @@ # ## { 'command': 'migrate-set-parameters', 'boxed': true, - 'data': 'MigrationParameters' } + 'data': 'MigrateSetParameters' } =20 ## # @MigrationParameters: # -# Optional members can be omitted on input ('migrate-set-parameters') -# but members will always be present on output. +# The optional members aren't actually optional. # # @compress-level: compression level # @@ -1063,19 +1133,18 @@ # @decompress-threads: decompression thread count # # @cpu-throttle-initial: Initial percentage of time guest cpus are -# throttledwhen migration auto-converge is activate= d. -# The default value is 20. (Since 2.7) +# throttled when migration auto-converge is activat= ed. +# (Since 2.7) # # @cpu-throttle-increment: throttle percentage increase each time # auto-converge detects that migration is not mak= ing -# progress. The default value is 10. (Since 2.7) +# progress. (Since 2.7) # # @tls-creds: ID of the 'tls-creds' object that provides credentials # for establishing a TLS connection over the migration data # channel. On the outgoing side of the migration, the credenti= als # must be for a 'client' endpoint, while for the incoming side= the -# credentials must be for a 'server' endpoint. Setting this -# to a non-empty string enables TLS for all migrations. +# credentials must be for a 'server' endpoint. # An empty string means that QEMU will use plain text mode for # migration, rather than TLS (Since 2.7) # Note: 2.8 reports this by omitting tls-creds instead. --=20 2.7.5 From nobody Sun Apr 28 05:06:17 2024 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 1500410474197752.1031989903516; Tue, 18 Jul 2017 13:41:14 -0700 (PDT) Received: from localhost ([::1]:58529 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dXZIu-0007n2-Ms for importer@patchew.org; Tue, 18 Jul 2017 16:41:12 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:58159) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dXZ7W-000575-KN for qemu-devel@nongnu.org; Tue, 18 Jul 2017 16:29:28 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1dXZ7V-00018u-3H for qemu-devel@nongnu.org; Tue, 18 Jul 2017 16:29:26 -0400 Received: from mx1.redhat.com ([209.132.183.28]:38518) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1dXZ7U-00017y-Qa for qemu-devel@nongnu.org; Tue, 18 Jul 2017 16:29:25 -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 C6C95A04EC 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 684B471CAD for ; Tue, 18 Jul 2017 20:29:23 +0000 (UTC) Received: by blackfin.pond.sub.org (Postfix, from userid 1000) id 81FC5113866D; Tue, 18 Jul 2017 22:29:20 +0200 (CEST) DMARC-Filter: OpenDMARC Filter v1.3.2 mx1.redhat.com C6C95A04EC Authentication-Results: ext-mx02.extmail.prod.ext.phx2.redhat.com; dmarc=none (p=none dis=none) header.from=redhat.com Authentication-Results: ext-mx02.extmail.prod.ext.phx2.redhat.com; spf=pass smtp.mailfrom=armbru@redhat.com DKIM-Filter: OpenDKIM Filter v2.11.0 mx1.redhat.com C6C95A04EC From: Markus Armbruster To: qemu-devel@nongnu.org Date: Tue, 18 Jul 2017 22:29:20 +0200 Message-Id: <1500409760-20730-11-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.26]); 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 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: , 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 | 20 ++++++++++++++++++-- 3 files changed, 40 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..9bd3390 100644 --- a/qapi-schema.json +++ b/qapi-schema.json @@ -116,6 +116,22 @@ { 'command': 'qmp_capabilities' } =20 ## +# @StrOrNull: +# +# This is a string value or the explicit lack of a string (null +# pointer in C). Intended for cases when 'optional absent' already +# has a different meaning. +# +# @s: the string value +# @n: no string value +# +# Since: 2.10 +## +{ 'alternate': 'StrOrNull', + 'data': { 's': 'str', + 'n': 'null' } } + +## # @LostTickPolicy: # # Policy for handling lost ticks in timer devices. @@ -1098,8 +1114,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