From nobody Fri May 3 03:54:30 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of redhat.com designates 170.10.133.124 as permitted sender) client-ip=170.10.133.124; envelope-from=libvir-list-bounces@redhat.com; helo=us-smtp-delivery-124.mimecast.com; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 170.10.133.124 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=pass(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1635135921; cv=none; d=zohomail.com; s=zohoarc; b=C5tj4EDGB2omaYv16X6W+u0WUyDfw66lGk62f7Cejj3edd2XAyZF1ZVjGXON3OBCmuWgNlcxRpccSVYztBEnon6ks6CCsBL9IArQkiQpmPeGBX2/SNnOZfudj6xaZzXX4U7+bqbW410OTqen6NbvSl0wpLcIhOZPxjEk1Go6ZX0= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1635135921; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=/7bGzHcRMoSCx9w5hRqzo+lvUPzSfpqMf12UJ/k6xV4=; b=fE+Mtfp6+wUz0GwG7gVTOjZ3CpTlo3VkEF880g0dkaGQ+ZN/24bSZnikFt2cIyC9CNnOecfY+CZeX/4rlBg92LS6+RESxvLQnIDyq6+dZUmXQQRxbTOltukcDu7wplqXMxIAFZTdYCrbwJs6REuQdT0dpnLEsodATnPEeE4dAiU= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 170.10.133.124 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by mx.zohomail.com with SMTPS id 1635135921262197.80621808485012; Sun, 24 Oct 2021 21:25:21 -0700 (PDT) Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-172-JlUNHgFJN5uEAVGts4Dgww-1; Mon, 25 Oct 2021 00:25:17 -0400 Received: from smtp.corp.redhat.com (int-mx07.intmail.prod.int.phx2.redhat.com [10.5.11.22]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id A5708362FA; Mon, 25 Oct 2021 04:25:12 +0000 (UTC) Received: from colo-mx.corp.redhat.com (colo-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.20]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 897491037F37; Mon, 25 Oct 2021 04:25:12 +0000 (UTC) Received: from lists01.pubmisc.prod.ext.phx2.redhat.com (lists01.pubmisc.prod.ext.phx2.redhat.com [10.5.19.33]) by colo-mx.corp.redhat.com (Postfix) with ESMTP id 55FAA1818480; Mon, 25 Oct 2021 04:25:12 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.12]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id 19P4OP3h014840 for ; Mon, 25 Oct 2021 00:24:25 -0400 Received: by smtp.corp.redhat.com (Postfix) id E9A0060CCC; Mon, 25 Oct 2021 04:24:25 +0000 (UTC) Received: from blackfin.pond.sub.org (ovpn-112-7.ams2.redhat.com [10.36.112.7]) by smtp.corp.redhat.com (Postfix) with ESMTPS id CA6CD60CC3; Mon, 25 Oct 2021 04:24:07 +0000 (UTC) Received: by blackfin.pond.sub.org (Postfix, from userid 1000) id 00EF411380AA; Mon, 25 Oct 2021 06:24:05 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1635135920; h=from:from:sender:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:list-id:list-help: list-unsubscribe:list-subscribe:list-post; bh=/7bGzHcRMoSCx9w5hRqzo+lvUPzSfpqMf12UJ/k6xV4=; b=KX4JYAA77NLy3/qGnp7I+9sfZeBzOh9b5nQ65Mu4NHa462QEeb29vTZTU4MTBcemCQrrs2 stdcc0qUe9Qc1Ba++nCg55tYbAT4U+g/BSWMgOE6/n/ovluQvCAEOtxlVbyOS/KBpmpB/Y M3694Faqw/QRXM6q6ElC7G9vps8EKyw= X-MC-Unique: JlUNHgFJN5uEAVGts4Dgww-1 From: Markus Armbruster To: qemu-devel@nongnu.org Subject: [PATCH v4 1/5] qapi: Enable enum member introspection to show more than name Date: Mon, 25 Oct 2021 06:24:01 +0200 Message-Id: <20211025042405.3762351-2-armbru@redhat.com> In-Reply-To: <20211025042405.3762351-1-armbru@redhat.com> References: <20211025042405.3762351-1-armbru@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.12 X-loop: libvir-list@redhat.com Cc: kwolf@redhat.com, vsementsov@virtuozzo.com, libvir-list@redhat.com, eblake@redhat.com, pkrempa@redhat.com, marcandre.lureau@redhat.com, jsnow@redhat.com, libguestfs@redhat.com X-BeenThere: libvir-list@redhat.com X-Mailman-Version: 2.1.12 Precedence: junk List-Id: Development discussions about the libvirt library & tools List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: libvir-list-bounces@redhat.com Errors-To: libvir-list-bounces@redhat.com X-Scanned-By: MIMEDefang 2.84 on 10.5.11.22 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=libvir-list-bounces@redhat.com X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1635135923360100001 Content-Type: text/plain; charset="utf-8" The next commit will add feature flags to enum members. There's a problem, though: query-qmp-schema shows an enum type's members as an array of member names (SchemaInfoEnum member @values). If it showed an array of objects with a name member, we could simply add more members to these objects. Since it's just strings, we can't. I can see three ways to correct this design mistake: 1. Do it the way we should have done it, plus compatibility goo. We want a ['SchemaInfoEnumMember'] member in SchemaInfoEnum. Since changing @values would be a compatibility break, add a new member @members instead. @values is now redundant. In my testing, output of qemu-system-x86_64's query-qmp-schema grows by 11% (18.5KiB). We can deprecate @values now and drop it later. This will break outmoded clients. Well-behaved clients such as libvirt are expected to break cleanly. 2. Like 1, but omit "boring" elements of @member, and empty @member. @values does not become redundant. @members augments it. Somewhat cumbersome, but output of query-qmp-schema grows only as we make enum members non-boring. There is nothing to deprecate here. 3. Versioned query-qmp-schema. query-qmp-schema provides either @values or @members. The QMP client can select which version it wants. There is no redundant output. We can deprecate old versions and eventually drop them. This will break outmoded clients. Breaking cleanly is easier than for 1. While 1 and 2 operate within the common rules for compatible evolution apply (section "Compatibility considerations" in docs/devel/qapi-code-gen.rst), 3 bypasses them. Attractive when operating within the rules is just too awkward. Not the case here. This commit implements 1. Libvirt developers prefer it. Deprecate @values in favour of @members. Since query-qmp-schema compatibility is pretty fundamental for management applications, an extended grace period is advised. Signed-off-by: Markus Armbruster Reviewed-by: Eric Blake Tested-by: Peter Krempa Acked-by: Peter Krempa Reviewed-by: John Snow --- docs/about/deprecated.rst | 6 ++++++ docs/devel/qapi-code-gen.rst | 15 +++++++++++---- qapi/introspect.json | 25 +++++++++++++++++++++++-- scripts/qapi/introspect.py | 18 ++++++++++++++---- 4 files changed, 54 insertions(+), 10 deletions(-) diff --git a/docs/about/deprecated.rst b/docs/about/deprecated.rst index 0bed6ecb1d..be19317470 100644 --- a/docs/about/deprecated.rst +++ b/docs/about/deprecated.rst @@ -228,6 +228,12 @@ Use the more generic commands ``block-export-add`` and= ``block-export-del`` instead. As part of this deprecation, where ``nbd-server-add`` used a single ``bitmap``, the new ``block-export-add`` uses a list of ``bitmaps``. =20 +``query-qmp-schema`` return value member ``values`` (since 6.2) +''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''' + +Member ``values`` in return value elements with meta-type ``enum`` is +deprecated. Use ``members`` instead. + System accelerators ------------------- =20 diff --git a/docs/devel/qapi-code-gen.rst b/docs/devel/qapi-code-gen.rst index b2569de486..d267889d2c 100644 --- a/docs/devel/qapi-code-gen.rst +++ b/docs/devel/qapi-code-gen.rst @@ -1231,14 +1231,21 @@ Example: the SchemaInfo for ['str'] :: "element-type": "str" } =20 The SchemaInfo for an enumeration type has meta-type "enum" and -variant member "values". The values are listed in no particular -order; clients must search the entire enum when learning whether a -particular value is supported. +variant member "members". + +"members" is a JSON array describing the enumeration values. Each +element is a JSON object with member "name" (the member's name). The +"members" array is in no particular order; clients must search the +entire array when learning whether a particular value is supported. =20 Example: the SchemaInfo for MyEnum from section `Enumeration types`_ :: =20 { "name": "MyEnum", "meta-type": "enum", - "values": [ "value1", "value2", "value3" ] } + "members": [ + { "name": "value1" }, + { "name": "value2" }, + { "name": "value3" } + ] } =20 The SchemaInfo for a built-in type has the same name as the type in the QAPI schema (see section `Built-in Types`_), with one exception diff --git a/qapi/introspect.json b/qapi/introspect.json index 39bd303778..9683e884f8 100644 --- a/qapi/introspect.json +++ b/qapi/introspect.json @@ -142,14 +142,35 @@ # # Additional SchemaInfo members for meta-type 'enum'. # -# @values: the enumeration type's values, in no particular order. +# @members: the enum type's members, in no particular order +# (since 6.2). +# +# @values: the enumeration type's member names, in no particular order. +# Redundant with @members. Just for backward compatibility. +# +# Features: +# @deprecated: Member @values is deprecated. Use @members instead. # # Values of this type are JSON string on the wire. # # Since: 2.5 ## { 'struct': 'SchemaInfoEnum', - 'data': { 'values': ['str'] } } + 'data': { 'members': [ 'SchemaInfoEnumMember' ], + 'values': { 'type': [ 'str' ], + 'features': [ 'deprecated' ] } } } + +## +# @SchemaInfoEnumMember: +# +# An object member. +# +# @name: the member's name, as defined in the QAPI schema. +# +# Since: 6.2 +## +{ 'struct': 'SchemaInfoEnumMember', + 'data': { 'name': 'str' } } =20 ## # @SchemaInfoArray: diff --git a/scripts/qapi/introspect.py b/scripts/qapi/introspect.py index 4c079ee627..6334546363 100644 --- a/scripts/qapi/introspect.py +++ b/scripts/qapi/introspect.py @@ -68,6 +68,7 @@ # TypedDict constructs, so they are broadly typed here as simple # Python Dicts. SchemaInfo =3D Dict[str, object] +SchemaInfoEnumMember =3D Dict[str, object] SchemaInfoObject =3D Dict[str, object] SchemaInfoObjectVariant =3D Dict[str, object] SchemaInfoObjectMember =3D Dict[str, object] @@ -274,8 +275,16 @@ def _gen_tree(self, name: str, mtype: str, obj: Dict[s= tr, object], obj['features'] =3D self._gen_features(features) self._trees.append(Annotated(obj, ifcond, comment)) =20 - def _gen_member(self, member: QAPISchemaObjectTypeMember - ) -> Annotated[SchemaInfoObjectMember]: + @staticmethod + def _gen_enum_member(member: QAPISchemaEnumMember + ) -> Annotated[SchemaInfoEnumMember]: + obj: SchemaInfoEnumMember =3D { + 'name': member.name, + } + return Annotated(obj, member.ifcond) + + def _gen_object_member(self, member: QAPISchemaObjectTypeMember + ) -> Annotated[SchemaInfoObjectMember]: obj: SchemaInfoObjectMember =3D { 'name': member.name, 'type': self._use_type(member.type) @@ -305,7 +314,8 @@ def visit_enum_type(self, name: str, info: Optional[QAP= ISourceInfo], prefix: Optional[str]) -> None: self._gen_tree( name, 'enum', - {'values': [Annotated(m.name, m.ifcond) for m in members]}, + {'members': [self._gen_enum_member(m) for m in members], + 'values': [Annotated(m.name, m.ifcond) for m in members]}, ifcond, features ) =20 @@ -322,7 +332,7 @@ def visit_object_type_flat(self, name: str, info: Optio= nal[QAPISourceInfo], members: List[QAPISchemaObjectTypeMember], variants: Optional[QAPISchemaVariants]) -> = None: obj: SchemaInfoObject =3D { - 'members': [self._gen_member(m) for m in members] + 'members': [self._gen_object_member(m) for m in members] } if variants: obj['tag'] =3D variants.tag_member.name --=20 2.31.1 From nobody Fri May 3 03:54:30 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of redhat.com designates 170.10.129.124 as permitted sender) client-ip=170.10.129.124; envelope-from=libvir-list-bounces@redhat.com; helo=us-smtp-delivery-124.mimecast.com; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 170.10.129.124 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=pass(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1635135883; cv=none; d=zohomail.com; s=zohoarc; b=iESWbenImpiO51fjWs/cKnlZEVcfI/W/arLAuuG67W9swS1IOPazWmTyruR5/wCC0PLer2EF06g5KZ8vAHrLu0hL94GKKvYpLNKIZ2hesRiya+p1+aLxL5gIdYPRIPvy6X3R0S24qHwpx4zr+BSVGk8pmgBAw8a3d1+mn2+HOFY= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1635135883; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=ujcP5WRFtzs3sZBBhx5NaWSDE0NKlhl4MYokQBXhGLg=; b=PJs52AYE1dEAhttze7mTOfnCRL0FabWlXdCjm0tdvmXhCbUzR9xHk4G3fqeEz0g7Na98qkJG5vCCHz4DSPfT9SPZF4nY1Jp1frlP3hd4lt/GJeJTN5W6HxNprKG4OCQv7NcTEhECsimdNANpE4wI+9GvjVz2WKfXFHefB1lwrdw= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 170.10.129.124 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) by mx.zohomail.com with SMTPS id 1635135883112526.7942166148172; Sun, 24 Oct 2021 21:24:43 -0700 (PDT) Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-101-3NIvyM8FN1itLzkVgKjS5Q-1; Mon, 25 Oct 2021 00:24:31 -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 mimecast-mx01.redhat.com (Postfix) with ESMTPS id DA55E1006AA8; Mon, 25 Oct 2021 04:24:25 +0000 (UTC) Received: from colo-mx.corp.redhat.com (colo-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.20]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 271F05D6BA; Mon, 25 Oct 2021 04:24:24 +0000 (UTC) Received: from lists01.pubmisc.prod.ext.phx2.redhat.com (lists01.pubmisc.prod.ext.phx2.redhat.com [10.5.19.33]) by colo-mx.corp.redhat.com (Postfix) with ESMTP id B73901803B30; Mon, 25 Oct 2021 04:24:20 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.phx2.redhat.com [10.5.11.13]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id 19P4OIhR014770 for ; Mon, 25 Oct 2021 00:24:19 -0400 Received: by smtp.corp.redhat.com (Postfix) id EEA00694B5; Mon, 25 Oct 2021 04:24:18 +0000 (UTC) Received: from blackfin.pond.sub.org (ovpn-112-7.ams2.redhat.com [10.36.112.7]) by smtp.corp.redhat.com (Postfix) with ESMTPS id ABC0C5BAFF; Mon, 25 Oct 2021 04:24:07 +0000 (UTC) Received: by blackfin.pond.sub.org (Postfix, from userid 1000) id 042B611380B8; Mon, 25 Oct 2021 06:24:06 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1635135882; h=from:from:sender:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:list-id:list-help: list-unsubscribe:list-subscribe:list-post; bh=ujcP5WRFtzs3sZBBhx5NaWSDE0NKlhl4MYokQBXhGLg=; b=LgLiIyydZf6cVJ5d31YNgYHwpRy2N15BtcVX6powMD/zzHHc6MqIzZNdlj2lXD8nNYna8l IHcC05klVB//69Z4iH7hNl0WmxNffmqXf5SGpbAD2F2yVp9kFrunfvVBKjsg8So54TMrbh 1KXSwCTFQqAD3bhceA1mQVOoxQE1gaA= X-MC-Unique: 3NIvyM8FN1itLzkVgKjS5Q-1 From: Markus Armbruster To: qemu-devel@nongnu.org Subject: [PATCH v4 2/5] qapi: Add feature flags to enum members Date: Mon, 25 Oct 2021 06:24:02 +0200 Message-Id: <20211025042405.3762351-3-armbru@redhat.com> In-Reply-To: <20211025042405.3762351-1-armbru@redhat.com> References: <20211025042405.3762351-1-armbru@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.13 X-loop: libvir-list@redhat.com Cc: kwolf@redhat.com, vsementsov@virtuozzo.com, libvir-list@redhat.com, eblake@redhat.com, pkrempa@redhat.com, marcandre.lureau@redhat.com, jsnow@redhat.com, libguestfs@redhat.com X-BeenThere: libvir-list@redhat.com X-Mailman-Version: 2.1.12 Precedence: junk List-Id: Development discussions about the libvirt library & tools List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: libvir-list-bounces@redhat.com Errors-To: libvir-list-bounces@redhat.com X-Scanned-By: MIMEDefang 2.79 on 10.5.11.15 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=libvir-list-bounces@redhat.com X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1635135883846100001 Content-Type: text/plain; charset="utf-8" This is quite similar to commit 84ab008687 "qapi: Add feature flags to struct members", only for enums instead of structs. Special feature flag 'deprecated' is silently ignored there. This is okay only because it will be implemented shortly. Signed-off-by: Markus Armbruster Reviewed-by: Eric Blake Reviewed-by: John Snow --- docs/devel/qapi-code-gen.rst | 16 +++++++++----- qapi/compat.json | 2 ++ qapi/introspect.json | 5 ++++- scripts/qapi/expr.py | 3 ++- scripts/qapi/introspect.py | 5 +++-- scripts/qapi/schema.py | 22 +++++++++++++++++-- tests/qapi-schema/doc-good.json | 5 ++++- tests/qapi-schema/doc-good.out | 3 +++ tests/qapi-schema/doc-good.txt | 3 +++ .../qapi-schema/enum-dict-member-unknown.err | 2 +- tests/qapi-schema/qapi-schema-test.json | 3 ++- tests/qapi-schema/qapi-schema-test.out | 1 + tests/qapi-schema/test-qapi.py | 1 + 13 files changed, 57 insertions(+), 14 deletions(-) diff --git a/docs/devel/qapi-code-gen.rst b/docs/devel/qapi-code-gen.rst index d267889d2c..4071c9074a 100644 --- a/docs/devel/qapi-code-gen.rst +++ b/docs/devel/qapi-code-gen.rst @@ -200,7 +200,9 @@ Syntax:: '*if': COND, '*features': FEATURES } ENUM-VALUE =3D STRING - | { 'name': STRING, '*if': COND } + | { 'name': STRING, + '*if': COND, + '*features': FEATURES } =20 Member 'enum' names the enum type. =20 @@ -706,8 +708,10 @@ QEMU shows a certain behaviour. Special features ~~~~~~~~~~~~~~~~ =20 -Feature "deprecated" marks a command, event, or struct member as -deprecated. It is not supported elsewhere so far. +Feature "deprecated" marks a command, event, enum value, or struct +member as deprecated. It is not supported elsewhere so far. +Interfaces so marked may be withdrawn in future releases in accordance +with QEMU's deprecation policy. =20 =20 Naming rules and reserved names @@ -1157,7 +1161,8 @@ and "variants". =20 "members" is a JSON array describing the object's common members, if any. Each element is a JSON object with members "name" (the member's -name), "type" (the name of its type), and optionally "default". The +name), "type" (the name of its type), "features" (a JSON array of +feature strings), and "default". The latter two are optional. The member is optional if "default" is present. Currently, "default" can only have value null. Other values are reserved for future extensions. The "members" array is in no particular order; clients @@ -1234,7 +1239,8 @@ The SchemaInfo for an enumeration type has meta-type = "enum" and variant member "members". =20 "members" is a JSON array describing the enumeration values. Each -element is a JSON object with member "name" (the member's name). The +element is a JSON object with member "name" (the member's name), and +optionally "features" (a JSON array of feature strings). The "members" array is in no particular order; clients must search the entire array when learning whether a particular value is supported. =20 diff --git a/qapi/compat.json b/qapi/compat.json index ae3afc22df..1d2b76f00c 100644 --- a/qapi/compat.json +++ b/qapi/compat.json @@ -42,6 +42,8 @@ # with feature 'deprecated'. We may want to extend it to cover # semantic aspects, CLI, and experimental features. # +# Limitation: not implemented for deprecated enumeration values. +# # @deprecated-input: how to handle deprecated input (default 'accept') # @deprecated-output: how to handle deprecated output (default 'accept') # diff --git a/qapi/introspect.json b/qapi/introspect.json index 9683e884f8..183148b2e9 100644 --- a/qapi/introspect.json +++ b/qapi/introspect.json @@ -167,10 +167,13 @@ # # @name: the member's name, as defined in the QAPI schema. # +# @features: names of features associated with the member, in no +# particular order. +# # Since: 6.2 ## { 'struct': 'SchemaInfoEnumMember', - 'data': { 'name': 'str' } } + 'data': { 'name': 'str', '*features': [ 'str' ] } } =20 ## # @SchemaInfoArray: diff --git a/scripts/qapi/expr.py b/scripts/qapi/expr.py index 819ea6ad97..3cb389e875 100644 --- a/scripts/qapi/expr.py +++ b/scripts/qapi/expr.py @@ -472,7 +472,7 @@ def check_enum(expr: _JSONObject, info: QAPISourceInfo)= -> None: for m in members] for member in members: source =3D "'data' member" - check_keys(member, info, source, ['name'], ['if']) + check_keys(member, info, source, ['name'], ['if', 'features']) member_name =3D member['name'] check_name_is_str(member_name, info, source) source =3D "%s '%s'" % (source, member_name) @@ -483,6 +483,7 @@ def check_enum(expr: _JSONObject, info: QAPISourceInfo)= -> None: permit_upper=3Dpermissive, permit_underscore=3Dpermissive) check_if(member, info, source) + check_features(member.get('features'), info) =20 =20 def check_struct(expr: _JSONObject, info: QAPISourceInfo) -> None: diff --git a/scripts/qapi/introspect.py b/scripts/qapi/introspect.py index 6334546363..67c7d89aae 100644 --- a/scripts/qapi/introspect.py +++ b/scripts/qapi/introspect.py @@ -275,12 +275,13 @@ def _gen_tree(self, name: str, mtype: str, obj: Dict[= str, object], obj['features'] =3D self._gen_features(features) self._trees.append(Annotated(obj, ifcond, comment)) =20 - @staticmethod - def _gen_enum_member(member: QAPISchemaEnumMember + def _gen_enum_member(self, member: QAPISchemaEnumMember ) -> Annotated[SchemaInfoEnumMember]: obj: SchemaInfoEnumMember =3D { 'name': member.name, } + if member.features: + obj['features'] =3D self._gen_features(member.features) return Annotated(obj, member.ifcond) =20 def _gen_object_member(self, member: QAPISchemaObjectTypeMember diff --git a/scripts/qapi/schema.py b/scripts/qapi/schema.py index 004d7095ff..6d5f46509a 100644 --- a/scripts/qapi/schema.py +++ b/scripts/qapi/schema.py @@ -708,6 +708,19 @@ def describe(self, info): class QAPISchemaEnumMember(QAPISchemaMember): role =3D 'value' =20 + def __init__(self, name, info, ifcond=3DNone, features=3DNone): + super().__init__(name, info, ifcond) + for f in features or []: + assert isinstance(f, QAPISchemaFeature) + f.set_defined_in(name) + self.features =3D features or [] + + def connect_doc(self, doc): + super().connect_doc(doc) + if doc: + for f in self.features: + doc.connect_feature(f) + =20 class QAPISchemaFeature(QAPISchemaMember): role =3D 'feature' @@ -980,9 +993,14 @@ def _make_features(self, features, info): QAPISchemaIfCond(f.get('if'))) for f in features] =20 + def _make_enum_member(self, name, ifcond, features, info): + return QAPISchemaEnumMember(name, info, + QAPISchemaIfCond(ifcond), + self._make_features(features, info)) + def _make_enum_members(self, values, info): - return [QAPISchemaEnumMember(v['name'], info, - QAPISchemaIfCond(v.get('if'))) + return [self._make_enum_member(v['name'], v.get('if'), + v.get('features'), info) for v in values] =20 def _make_array_type(self, element_type, info): diff --git a/tests/qapi-schema/doc-good.json b/tests/qapi-schema/doc-good.j= son index 86dc25d2bd..74745fb405 100644 --- a/tests/qapi-schema/doc-good.json +++ b/tests/qapi-schema/doc-good.json @@ -58,11 +58,14 @@ # # Features: # @enum-feat: Also _one_ {and only} +# @enum-member-feat: a member feature # # @two is undocumented ## { 'enum': 'Enum', - 'data': [ { 'name': 'one', 'if': 'IFONE' }, 'two' ], + 'data': [ { 'name': 'one', 'if': 'IFONE', + 'features': [ 'enum-member-feat' ] }, + 'two' ], 'features': [ 'enum-feat' ], 'if': 'IFCOND' } =20 diff --git a/tests/qapi-schema/doc-good.out b/tests/qapi-schema/doc-good.out index 5a324e2627..9dd65b9d92 100644 --- a/tests/qapi-schema/doc-good.out +++ b/tests/qapi-schema/doc-good.out @@ -13,6 +13,7 @@ module doc-good.json enum Enum member one if IFONE + feature enum-member-feat member two if IFCOND feature enum-feat @@ -108,6 +109,8 @@ The _one_ {and only} =20 feature=3Denum-feat Also _one_ {and only} + feature=3Denum-member-feat +a member feature section=3DNone @two is undocumented doc symbol=3DBase diff --git a/tests/qapi-schema/doc-good.txt b/tests/qapi-schema/doc-good.txt index 701402ee5e..b3b76bd43f 100644 --- a/tests/qapi-schema/doc-good.txt +++ b/tests/qapi-schema/doc-good.txt @@ -56,6 +56,9 @@ Features "enum-feat" Also _one_ {and only} =20 +"enum-member-feat" + a member feature + "two" is undocumented =20 =20 diff --git a/tests/qapi-schema/enum-dict-member-unknown.err b/tests/qapi-sc= hema/enum-dict-member-unknown.err index f8617ea179..235cde0c49 100644 --- a/tests/qapi-schema/enum-dict-member-unknown.err +++ b/tests/qapi-schema/enum-dict-member-unknown.err @@ -1,3 +1,3 @@ enum-dict-member-unknown.json: In enum 'MyEnum': enum-dict-member-unknown.json:2: 'data' member has unknown key 'bad-key' -Valid keys are 'if', 'name'. +Valid keys are 'features', 'if', 'name'. diff --git a/tests/qapi-schema/qapi-schema-test.json b/tests/qapi-schema/qa= pi-schema-test.json index 2ec50109cb..b677ab861d 100644 --- a/tests/qapi-schema/qapi-schema-test.json +++ b/tests/qapi-schema/qapi-schema-test.json @@ -301,7 +301,8 @@ 'TEST_IF_COND_2'] } } ] } =20 { 'enum': 'FeatureEnum1', - 'data': [ 'eins', 'zwei', 'drei' ], + 'data': [ 'eins', 'zwei', + { 'name': 'drei', 'features': [ 'deprecated' ] } ], 'features': [ 'feature1' ] } =20 { 'union': 'FeatureUnion1', diff --git a/tests/qapi-schema/qapi-schema-test.out b/tests/qapi-schema/qap= i-schema-test.out index 9337adc9ea..16846dbeb8 100644 --- a/tests/qapi-schema/qapi-schema-test.out +++ b/tests/qapi-schema/qapi-schema-test.out @@ -341,6 +341,7 @@ enum FeatureEnum1 member eins member zwei member drei + feature deprecated feature feature1 object q_obj_FeatureUnion1-base member tag: FeatureEnum1 optional=3DFalse diff --git a/tests/qapi-schema/test-qapi.py b/tests/qapi-schema/test-qapi.py index c717a7a90b..2160cef082 100755 --- a/tests/qapi-schema/test-qapi.py +++ b/tests/qapi-schema/test-qapi.py @@ -37,6 +37,7 @@ def visit_enum_type(self, name, info, ifcond, features, m= embers, prefix): for m in members: print(' member %s' % m.name) self._print_if(m.ifcond, indent=3D8) + self._print_features(m.features, indent=3D8) self._print_if(ifcond) self._print_features(features) =20 --=20 2.31.1 From nobody Fri May 3 03:54:30 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of redhat.com designates 216.205.24.124 as permitted sender) client-ip=216.205.24.124; envelope-from=libvir-list-bounces@redhat.com; helo=us-smtp-delivery-124.mimecast.com; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 216.205.24.124 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=pass(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1635135898; cv=none; d=zohomail.com; s=zohoarc; b=Ai+s1tOlRbKJpIgLxl/7nuiAbQhm8oFa5i+bdV7kUz1oWuS3K1f7l0CfS+G9frexQBQjHs7WGPEEUbT9plStuuJJImMyJG6m/v8dMpmfFlRbhnoJZ2dGVfV8A8AFluYfqGpHS+eIyxIXbwFhNGxA292kJEEYFj38AsLH/MSG2qc= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1635135898; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=0jjQzczD4kEqGuY9oEEI2ywnjprqrl9/YheOgfujrm8=; b=jKdXfLhLEYUuGNTV8Luo2awFA7ghb28Fwq605TRhNlBpYtklJapdLdsNbPqaVwGcEk0KBOjuymfKjaZSqH9Qg5aNixcDHcc8+Jae5H0Pa1GOFnZHe8/leLQmanob1HWPHcPjPq2kUDnRoGqbN9+tlmUiNXFX7Ckj6eK2MkyE0Gw= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 216.205.24.124 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [216.205.24.124]) by mx.zohomail.com with SMTPS id 1635135898705815.4697161198757; Sun, 24 Oct 2021 21:24:58 -0700 (PDT) Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-289-cRDhBhTIOk-kNSeSDNTCMw-1; Mon, 25 Oct 2021 00:24:54 -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 mimecast-mx01.redhat.com (Postfix) with ESMTPS id 2AC2A1808312; Mon, 25 Oct 2021 04:24:49 +0000 (UTC) Received: from colo-mx.corp.redhat.com (colo-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.20]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 0CB2669217; Mon, 25 Oct 2021 04:24:49 +0000 (UTC) Received: from lists01.pubmisc.prod.ext.phx2.redhat.com (lists01.pubmisc.prod.ext.phx2.redhat.com [10.5.19.33]) by colo-mx.corp.redhat.com (Postfix) with ESMTP id CE6921818480; Mon, 25 Oct 2021 04:24:48 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx07.intmail.prod.int.phx2.redhat.com [10.5.11.22]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id 19P4ONpx014807 for ; Mon, 25 Oct 2021 00:24:23 -0400 Received: by smtp.corp.redhat.com (Postfix) id 3EDCC101F6D5; Mon, 25 Oct 2021 04:24:23 +0000 (UTC) Received: from blackfin.pond.sub.org (ovpn-112-7.ams2.redhat.com [10.36.112.7]) by smtp.corp.redhat.com (Postfix) with ESMTPS id CA75F1002D71; Mon, 25 Oct 2021 04:24:07 +0000 (UTC) Received: by blackfin.pond.sub.org (Postfix, from userid 1000) id 07C2411380BA; Mon, 25 Oct 2021 06:24:06 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1635135897; h=from:from:sender:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:list-id:list-help: list-unsubscribe:list-subscribe:list-post; bh=0jjQzczD4kEqGuY9oEEI2ywnjprqrl9/YheOgfujrm8=; b=jFzCx/eQOoN5iv6l78JEKBXBt2/I5VKigmLXMKPJx3rCS2S/U//q0sv8nKscGm1EBIVZtT M1ybvHWs3IV+SbgbRfLX9sfzFbHlYx8g3oj/CoO55xGInxgt4CngA7xbROLXu/vuzg3jFh iNsubsvMNvACNyVbytxLur+pnjuwyGQ= X-MC-Unique: cRDhBhTIOk-kNSeSDNTCMw-1 From: Markus Armbruster To: qemu-devel@nongnu.org Subject: [PATCH v4 3/5] qapi: Move compat policy from QObject to generic visitor Date: Mon, 25 Oct 2021 06:24:03 +0200 Message-Id: <20211025042405.3762351-4-armbru@redhat.com> In-Reply-To: <20211025042405.3762351-1-armbru@redhat.com> References: <20211025042405.3762351-1-armbru@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.84 on 10.5.11.22 X-loop: libvir-list@redhat.com Cc: kwolf@redhat.com, vsementsov@virtuozzo.com, libvir-list@redhat.com, eblake@redhat.com, pkrempa@redhat.com, marcandre.lureau@redhat.com, jsnow@redhat.com, libguestfs@redhat.com X-BeenThere: libvir-list@redhat.com X-Mailman-Version: 2.1.12 Precedence: junk List-Id: Development discussions about the libvirt library & tools List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: libvir-list-bounces@redhat.com Errors-To: libvir-list-bounces@redhat.com X-Scanned-By: MIMEDefang 2.79 on 10.5.11.11 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=libvir-list-bounces@redhat.com X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1635135900163100001 Content-Type: text/plain; charset="utf-8" The next commit needs to access compat policy from the generic visitor core. Move it there from qobject input and output visitor. Signed-off-by: Markus Armbruster Reviewed-by: Eric Blake --- include/qapi/qobject-input-visitor.h | 4 ---- include/qapi/qobject-output-visitor.h | 4 ---- include/qapi/visitor-impl.h | 3 +++ include/qapi/visitor.h | 9 +++++++++ qapi/qapi-visit-core.c | 9 +++++++++ qapi/qmp-dispatch.c | 4 ++-- qapi/qobject-input-visitor.c | 14 +------------- qapi/qobject-output-visitor.c | 14 +------------- 8 files changed, 25 insertions(+), 36 deletions(-) diff --git a/include/qapi/qobject-input-visitor.h b/include/qapi/qobject-in= put-visitor.h index 8d69388810..95985e25e5 100644 --- a/include/qapi/qobject-input-visitor.h +++ b/include/qapi/qobject-input-visitor.h @@ -15,7 +15,6 @@ #ifndef QOBJECT_INPUT_VISITOR_H #define QOBJECT_INPUT_VISITOR_H =20 -#include "qapi/qapi-types-compat.h" #include "qapi/visitor.h" =20 typedef struct QObjectInputVisitor QObjectInputVisitor; @@ -59,9 +58,6 @@ typedef struct QObjectInputVisitor QObjectInputVisitor; */ Visitor *qobject_input_visitor_new(QObject *obj); =20 -void qobject_input_visitor_set_policy(Visitor *v, - CompatPolicyInput deprecated); - /* * Create a QObject input visitor for @obj for use with keyval_parse() * diff --git a/include/qapi/qobject-output-visitor.h b/include/qapi/qobject-o= utput-visitor.h index f2a2f92a00..2b1726baf5 100644 --- a/include/qapi/qobject-output-visitor.h +++ b/include/qapi/qobject-output-visitor.h @@ -15,7 +15,6 @@ #define QOBJECT_OUTPUT_VISITOR_H =20 #include "qapi/visitor.h" -#include "qapi/qapi-types-compat.h" =20 typedef struct QObjectOutputVisitor QObjectOutputVisitor; =20 @@ -54,7 +53,4 @@ typedef struct QObjectOutputVisitor QObjectOutputVisitor; */ Visitor *qobject_output_visitor_new(QObject **result); =20 -void qobject_output_visitor_set_policy(Visitor *v, - CompatPolicyOutput deprecated); - #endif diff --git a/include/qapi/visitor-impl.h b/include/qapi/visitor-impl.h index 3b950f6e3d..72b6537bef 100644 --- a/include/qapi/visitor-impl.h +++ b/include/qapi/visitor-impl.h @@ -122,6 +122,9 @@ struct Visitor /* Must be set */ VisitorType type; =20 + /* Optional */ + struct CompatPolicy compat_policy; + /* Must be set for output visitors, optional otherwise. */ void (*complete)(Visitor *v, void *opaque); =20 diff --git a/include/qapi/visitor.h b/include/qapi/visitor.h index b3c9ef7a81..dcb96018a9 100644 --- a/include/qapi/visitor.h +++ b/include/qapi/visitor.h @@ -16,6 +16,7 @@ #define QAPI_VISITOR_H =20 #include "qapi/qapi-builtin-types.h" +#include "qapi/qapi-types-compat.h" =20 /* * The QAPI schema defines both a set of C data types, and a QMP wire @@ -477,6 +478,14 @@ bool visit_deprecated_accept(Visitor *v, const char *n= ame, Error **errp); */ bool visit_deprecated(Visitor *v, const char *name); =20 +/* + * Set policy for handling deprecated management interfaces. + * + * Intended use: call visit_set_policy(v, &compat_policy) when + * visiting management interface input or output. + */ +void visit_set_policy(Visitor *v, CompatPolicy *policy); + /* * Visit an enum value. * diff --git a/qapi/qapi-visit-core.c b/qapi/qapi-visit-core.c index a641adec51..066f77a26d 100644 --- a/qapi/qapi-visit-core.c +++ b/qapi/qapi-visit-core.c @@ -19,6 +19,10 @@ #include "qapi/visitor-impl.h" #include "trace.h" =20 +/* Zero-initialization must result in default policy */ +QEMU_BUILD_BUG_ON(COMPAT_POLICY_INPUT_ACCEPT || COMPAT_POLICY_OUTPUT_ACCEP= T); + + void visit_complete(Visitor *v, void *opaque) { assert(v->type !=3D VISITOR_OUTPUT || v->complete); @@ -153,6 +157,11 @@ bool visit_deprecated(Visitor *v, const char *name) return true; } =20 +void visit_set_policy(Visitor *v, CompatPolicy *policy) +{ + v->compat_policy =3D *policy; +} + bool visit_is_input(Visitor *v) { return v->type =3D=3D VISITOR_INPUT; diff --git a/qapi/qmp-dispatch.c b/qapi/qmp-dispatch.c index 59600210ce..7e943a0af5 100644 --- a/qapi/qmp-dispatch.c +++ b/qapi/qmp-dispatch.c @@ -32,7 +32,7 @@ Visitor *qobject_input_visitor_new_qmp(QObject *obj) { Visitor *v =3D qobject_input_visitor_new(obj); =20 - qobject_input_visitor_set_policy(v, compat_policy.deprecated_input); + visit_set_policy(v, &compat_policy); return v; } =20 @@ -40,7 +40,7 @@ Visitor *qobject_output_visitor_new_qmp(QObject **result) { Visitor *v =3D qobject_output_visitor_new(result); =20 - qobject_output_visitor_set_policy(v, compat_policy.deprecated_output); + visit_set_policy(v, &compat_policy); return v; } =20 diff --git a/qapi/qobject-input-visitor.c b/qapi/qobject-input-visitor.c index 04b790412e..71b24a4429 100644 --- a/qapi/qobject-input-visitor.c +++ b/qapi/qobject-input-visitor.c @@ -14,7 +14,6 @@ =20 #include "qemu/osdep.h" #include -#include "qapi/compat-policy.h" #include "qapi/error.h" #include "qapi/qobject-input-visitor.h" #include "qapi/visitor-impl.h" @@ -44,7 +43,6 @@ typedef struct StackObject { =20 struct QObjectInputVisitor { Visitor visitor; - CompatPolicyInput deprecated_policy; =20 /* Root of visit at visitor creation. */ QObject *root; @@ -667,9 +665,7 @@ static void qobject_input_optional(Visitor *v, const ch= ar *name, bool *present) static bool qobject_input_deprecated_accept(Visitor *v, const char *name, Error **errp) { - QObjectInputVisitor *qiv =3D to_qiv(v); - - switch (qiv->deprecated_policy) { + switch (v->compat_policy.deprecated_input) { case COMPAT_POLICY_INPUT_ACCEPT: return true; case COMPAT_POLICY_INPUT_REJECT: @@ -739,14 +735,6 @@ Visitor *qobject_input_visitor_new(QObject *obj) return &v->visitor; } =20 -void qobject_input_visitor_set_policy(Visitor *v, - CompatPolicyInput deprecated) -{ - QObjectInputVisitor *qiv =3D to_qiv(v); - - qiv->deprecated_policy =3D deprecated; -} - Visitor *qobject_input_visitor_new_keyval(QObject *obj) { QObjectInputVisitor *v =3D qobject_input_visitor_base_new(obj); diff --git a/qapi/qobject-output-visitor.c b/qapi/qobject-output-visitor.c index e4873308d4..9b7f510036 100644 --- a/qapi/qobject-output-visitor.c +++ b/qapi/qobject-output-visitor.c @@ -13,7 +13,6 @@ */ =20 #include "qemu/osdep.h" -#include "qapi/compat-policy.h" #include "qapi/qobject-output-visitor.h" #include "qapi/visitor-impl.h" #include "qemu/queue.h" @@ -32,7 +31,6 @@ typedef struct QStackEntry { =20 struct QObjectOutputVisitor { Visitor visitor; - CompatPolicyOutput deprecated_policy; =20 QSLIST_HEAD(, QStackEntry) stack; /* Stack of unfinished containers */ QObject *root; /* Root of the output visit */ @@ -212,9 +210,7 @@ static bool qobject_output_type_null(Visitor *v, const = char *name, =20 static bool qobject_output_deprecated(Visitor *v, const char *name) { - QObjectOutputVisitor *qov =3D to_qov(v); - - return qov->deprecated_policy !=3D COMPAT_POLICY_OUTPUT_HIDE; + return v->compat_policy.deprecated_output !=3D COMPAT_POLICY_OUTPUT_HI= DE; } =20 /* Finish building, and return the root object. @@ -275,11 +271,3 @@ Visitor *qobject_output_visitor_new(QObject **result) =20 return &v->visitor; } - -void qobject_output_visitor_set_policy(Visitor *v, - CompatPolicyOutput deprecated) -{ - QObjectOutputVisitor *qov =3D to_qov(v); - - qov->deprecated_policy =3D deprecated; -} --=20 2.31.1 From nobody Fri May 3 03:54:30 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of redhat.com designates 216.205.24.124 as permitted sender) client-ip=216.205.24.124; envelope-from=libvir-list-bounces@redhat.com; helo=us-smtp-delivery-124.mimecast.com; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 216.205.24.124 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=pass(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1635135925; cv=none; d=zohomail.com; s=zohoarc; b=klAwixFVtaWtQL8F4Go/1z1omf2S3nUPijrul/L0C7+z5EHPXJ0TqQKd4Odfcer4tXTE11hDSOf+rMsUmpfY59FJV8+aThmgWh2D6AANA57bkL4FAK+Nuti0HUldyUS6+Nxxtv/FouqxR6CP+D3sDB3+yYwbcvyUqjU5vCL+WjI= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1635135925; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=qlNzPqw6ia8B6tlqqTBvPygeeTCyKs53LLdUY+T5TdI=; b=FfEJl9mb4Vjb1nSiNtKJNfBPtgjjizD6f4d+9dbR+GGhslxtiErgIqTP2PZNQy19KLbTx8je3VBhxq/kbvGntkPGPQ5HPs7WDyChRCvO/OWrwFqnKIS3VxJEI6qnHLDnBU9nPALMDJkTVLNXKwQr9JcCvQUhbROl0bgkL34dHTc= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 216.205.24.124 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [216.205.24.124]) by mx.zohomail.com with SMTPS id 1635135925186927.2688748911299; Sun, 24 Oct 2021 21:25:25 -0700 (PDT) Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-497-dOkblD4wOVWxOPxrEgPBQA-1; Mon, 25 Oct 2021 00:25:20 -0400 Received: from smtp.corp.redhat.com (int-mx08.intmail.prod.int.phx2.redhat.com [10.5.11.23]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id A785B362F8; Mon, 25 Oct 2021 04:25:15 +0000 (UTC) Received: from colo-mx.corp.redhat.com (colo-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.20]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 821BA19D9D; Mon, 25 Oct 2021 04:25:15 +0000 (UTC) Received: from lists01.pubmisc.prod.ext.phx2.redhat.com (lists01.pubmisc.prod.ext.phx2.redhat.com [10.5.19.33]) by colo-mx.corp.redhat.com (Postfix) with ESMTP id 4FD241832DDE; Mon, 25 Oct 2021 04:25:15 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx04.intmail.prod.int.phx2.redhat.com [10.5.11.14]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id 19P4OSIr014867 for ; Mon, 25 Oct 2021 00:24:28 -0400 Received: by smtp.corp.redhat.com (Postfix) id 0E22A5DF36; Mon, 25 Oct 2021 04:24:28 +0000 (UTC) Received: from blackfin.pond.sub.org (ovpn-112-7.ams2.redhat.com [10.36.112.7]) by smtp.corp.redhat.com (Postfix) with ESMTPS id CA9591816A; Mon, 25 Oct 2021 04:24:07 +0000 (UTC) Received: by blackfin.pond.sub.org (Postfix, from userid 1000) id 0BF7A11380C3; Mon, 25 Oct 2021 06:24:06 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1635135924; h=from:from:sender:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:list-id:list-help: list-unsubscribe:list-subscribe:list-post; bh=qlNzPqw6ia8B6tlqqTBvPygeeTCyKs53LLdUY+T5TdI=; b=OF4rjloDE045AVaI41wTRkDKOtHR/ZUgorSZH6TS/pB7ihcjxqszIX3Yw9FbOtBqc7moND KHGzKpVxos9YIb5QQdPKE1aE0LfSwfxOtdn/cdTfw83Ix2yc15kzi5TCnmnQnxVOi58Oyc WqRrjUfTeSLj7slzWFKW/uhePkFfAgo= X-MC-Unique: dOkblD4wOVWxOPxrEgPBQA-1 From: Markus Armbruster To: qemu-devel@nongnu.org Subject: [PATCH v4 4/5] qapi: Implement deprecated-input={reject, crash} for enum values Date: Mon, 25 Oct 2021 06:24:04 +0200 Message-Id: <20211025042405.3762351-5-armbru@redhat.com> In-Reply-To: <20211025042405.3762351-1-armbru@redhat.com> References: <20211025042405.3762351-1-armbru@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.14 X-loop: libvir-list@redhat.com Cc: kwolf@redhat.com, vsementsov@virtuozzo.com, libvir-list@redhat.com, eblake@redhat.com, pkrempa@redhat.com, marcandre.lureau@redhat.com, jsnow@redhat.com, libguestfs@redhat.com X-BeenThere: libvir-list@redhat.com X-Mailman-Version: 2.1.12 Precedence: junk List-Id: Development discussions about the libvirt library & tools List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: libvir-list-bounces@redhat.com Errors-To: libvir-list-bounces@redhat.com X-Scanned-By: MIMEDefang 2.84 on 10.5.11.23 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=libvir-list-bounces@redhat.com X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1635135925651100001 Content-Type: text/plain; charset="utf-8" This copies the code implementing the policy from qapi/qmp-dispatch.c to qapi/qobject-input-visitor.c. Tolerable, but if we acquire more copies, we should look into factoring them out. Signed-off-by: Markus Armbruster Reviewed-by: Eric Blake Tested-by: Peter Krempa Acked-by: Peter Krempa --- qapi/compat.json | 3 ++- include/qapi/util.h | 6 +++++- qapi/qapi-visit-core.c | 18 +++++++++++++++--- scripts/qapi/types.py | 17 ++++++++++++++++- 4 files changed, 38 insertions(+), 6 deletions(-) diff --git a/qapi/compat.json b/qapi/compat.json index 1d2b76f00c..74a8493d3d 100644 --- a/qapi/compat.json +++ b/qapi/compat.json @@ -42,7 +42,8 @@ # with feature 'deprecated'. We may want to extend it to cover # semantic aspects, CLI, and experimental features. # -# Limitation: not implemented for deprecated enumeration values. +# Limitation: deprecated-output policy @hide is not implemented for +# enumeration values. They behave the same as with policy @accept. # # @deprecated-input: how to handle deprecated input (default 'accept') # @deprecated-output: how to handle deprecated output (default 'accept') diff --git a/include/qapi/util.h b/include/qapi/util.h index d7bfb30e25..257c600f99 100644 --- a/include/qapi/util.h +++ b/include/qapi/util.h @@ -11,9 +11,13 @@ #ifndef QAPI_UTIL_H #define QAPI_UTIL_H =20 +/* QEnumLookup flags */ +#define QAPI_ENUM_DEPRECATED 1 + typedef struct QEnumLookup { const char *const *array; - int size; + const unsigned char *const flags; + const int size; } QEnumLookup; =20 const char *qapi_enum_lookup(const QEnumLookup *lookup, int val); diff --git a/qapi/qapi-visit-core.c b/qapi/qapi-visit-core.c index 066f77a26d..49136ae88e 100644 --- a/qapi/qapi-visit-core.c +++ b/qapi/qapi-visit-core.c @@ -393,7 +393,7 @@ static bool input_type_enum(Visitor *v, const char *nam= e, int *obj, const QEnumLookup *lookup, Error **errp) { int64_t value; - char *enum_str; + g_autofree char *enum_str =3D NULL; =20 if (!visit_type_str(v, name, &enum_str, errp)) { return false; @@ -402,11 +402,23 @@ static bool input_type_enum(Visitor *v, const char *n= ame, int *obj, value =3D qapi_enum_parse(lookup, enum_str, -1, NULL); if (value < 0) { error_setg(errp, QERR_INVALID_PARAMETER, enum_str); - g_free(enum_str); return false; } =20 - g_free(enum_str); + if (lookup->flags && (lookup->flags[value] & QAPI_ENUM_DEPRECATED)) { + switch (v->compat_policy.deprecated_input) { + case COMPAT_POLICY_INPUT_ACCEPT: + break; + case COMPAT_POLICY_INPUT_REJECT: + error_setg(errp, "Deprecated value '%s' disabled by policy", + enum_str); + return false; + case COMPAT_POLICY_INPUT_CRASH: + default: + abort(); + } + } + *obj =3D value; return true; } diff --git a/scripts/qapi/types.py b/scripts/qapi/types.py index 831294fe42..ab2441adc9 100644 --- a/scripts/qapi/types.py +++ b/scripts/qapi/types.py @@ -38,6 +38,8 @@ def gen_enum_lookup(name: str, members: List[QAPISchemaEnumMember], prefix: Optional[str] =3D None) -> str: + max_index =3D c_enum_const(name, '_MAX', prefix) + flags =3D '' ret =3D mcgen(''' =20 const QEnumLookup %(c_name)s_lookup =3D { @@ -52,13 +54,26 @@ def gen_enum_lookup(name: str, ''', index=3Dindex, name=3Dmemb.name) ret +=3D memb.ifcond.gen_endif() + if 'deprecated' in (f.name for f in memb.features): + flags +=3D mcgen(''' + [%(index)s] =3D QAPI_ENUM_DEPRECATED, +''', + index=3Dindex) + + if flags: + ret +=3D mcgen(''' + }, + .flags =3D (const unsigned char[%(max_index)s]) { +''', + max_index=3Dmax_index) + ret +=3D flags =20 ret +=3D mcgen(''' }, .size =3D %(max_index)s }; ''', - max_index=3Dc_enum_const(name, '_MAX', prefix)) + max_index=3Dmax_index) return ret =20 =20 --=20 2.31.1 From nobody Fri May 3 03:54:30 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of redhat.com designates 216.205.24.124 as permitted sender) client-ip=216.205.24.124; envelope-from=libvir-list-bounces@redhat.com; helo=us-smtp-delivery-124.mimecast.com; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 216.205.24.124 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=pass(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1635135892; cv=none; d=zohomail.com; s=zohoarc; b=SD86B5fN5S0zcPQ7dgDDsZ411Q+/O5cUIGQBQ39X/9HacKlDE7c1/VGOqvSanrbxqjwvqlNPT9QaNkQV8xR3E6+YEQ6TG+4Vw8pMbJNSnEHK4S7zSwkZnLkQDELNoAI62PW9vwidx4m6f1IpCzNSxjYgEkj8jB0JWdLDU5W3N3U= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1635135892; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=TDuE6wB+NhgVZWT1yd+7ld8eNMlPXfVnsXRFVQ7a3Y8=; b=OQ9Amw3IcjVeaphvIAnrWVIBoc8/L3u0YZ2oh0TP1xoNtKUm2AgCutBuvlwo0yyDSbcspsJj+VUSInvCvKN7d2Yu9V8pSbj2C3573rvjLN8j3mKc5IeNhWt8UR4Zc46zIMhso3ebD/MVu2DHX+VQnyaq7YuUl440H63pL2VLDdY= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 216.205.24.124 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [216.205.24.124]) by mx.zohomail.com with SMTPS id 16351358923781015.7899693143096; Sun, 24 Oct 2021 21:24:52 -0700 (PDT) Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-195-FiTB8MBfNieBWODcN9jGTQ-1; Mon, 25 Oct 2021 00:24:49 -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 mimecast-mx01.redhat.com (Postfix) with ESMTPS id 55A84802B7A; Mon, 25 Oct 2021 04:24:44 +0000 (UTC) Received: from colo-mx.corp.redhat.com (colo-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.21]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 2883660BF4; Mon, 25 Oct 2021 04:24:44 +0000 (UTC) Received: from lists01.pubmisc.prod.ext.phx2.redhat.com (lists01.pubmisc.prod.ext.phx2.redhat.com [10.5.19.33]) by colo-mx.corp.redhat.com (Postfix) with ESMTP id A4CA34E590; Mon, 25 Oct 2021 04:24:43 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.phx2.redhat.com [10.5.11.13]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id 19P4OKP6014780 for ; Mon, 25 Oct 2021 00:24:20 -0400 Received: by smtp.corp.redhat.com (Postfix) id 84A935BB06; Mon, 25 Oct 2021 04:24:20 +0000 (UTC) Received: from blackfin.pond.sub.org (ovpn-112-7.ams2.redhat.com [10.36.112.7]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 534396060F; Mon, 25 Oct 2021 04:24:20 +0000 (UTC) Received: by blackfin.pond.sub.org (Postfix, from userid 1000) id 0F36B11380CA; Mon, 25 Oct 2021 06:24:06 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1635135891; h=from:from:sender:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:list-id:list-help: list-unsubscribe:list-subscribe:list-post; bh=TDuE6wB+NhgVZWT1yd+7ld8eNMlPXfVnsXRFVQ7a3Y8=; b=FzxNi/BUlEQ5J68cpkbt0NpRG++vyPpie6IGYXlNJQiZclnZQDjEAhjb+WJ0GH/GWhmsIa 49NALjFdmOqP7EfEcFSsD05c1VWpOtiQO3N23rs/ii+5BBi7k3/lZ4Np/TH69Q0t1/6t3L UGlbrXGKH/QuRHFkPTJACCZ/lSEvHoE= X-MC-Unique: FiTB8MBfNieBWODcN9jGTQ-1 From: Markus Armbruster To: qemu-devel@nongnu.org Subject: [PATCH v4 5/5] block: Deprecate transaction type drive-backup Date: Mon, 25 Oct 2021 06:24:05 +0200 Message-Id: <20211025042405.3762351-6-armbru@redhat.com> In-Reply-To: <20211025042405.3762351-1-armbru@redhat.com> References: <20211025042405.3762351-1-armbru@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.13 X-loop: libvir-list@redhat.com Cc: kwolf@redhat.com, vsementsov@virtuozzo.com, libvir-list@redhat.com, eblake@redhat.com, pkrempa@redhat.com, marcandre.lureau@redhat.com, jsnow@redhat.com, libguestfs@redhat.com X-BeenThere: libvir-list@redhat.com X-Mailman-Version: 2.1.12 Precedence: junk List-Id: Development discussions about the libvirt library & tools List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: libvir-list-bounces@redhat.com Errors-To: libvir-list-bounces@redhat.com X-Scanned-By: MIMEDefang 2.79 on 10.5.11.12 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=libvir-list-bounces@redhat.com X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1635135893947100001 Content-Type: text/plain; charset="utf-8" Several moons ago, Vladimir posted Subject: [PATCH v2 3/3] qapi: deprecate drive-backup Date: Wed, 5 May 2021 16:58:03 +0300 Message-Id: <20210505135803.67896-4-vsementsov@virtuozzo.com> https://lists.gnu.org/archive/html/qemu-devel/2021-05/msg01394.html with this TODO: We also need to deprecate drive-backup transaction action.. But union members in QAPI doesn't support 'deprecated' feature. I tried to dig a bit, but failed :/ Markus, could you please help with it? At least by advice? This is one way to resolve it. Sorry it took so long. John explored another way, namely adding feature flags to union branches. Could also be useful, say to add different features to branches in multiple unions sharing the same tag enum. Signed-off-by: Markus Armbruster Reviewed-by: Vladimir Sementsov-Ogievskiy --- qapi/transaction.json | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/qapi/transaction.json b/qapi/transaction.json index d175b5f863..381a2df782 100644 --- a/qapi/transaction.json +++ b/qapi/transaction.json @@ -54,6 +54,10 @@ # @blockdev-snapshot-sync: since 1.1 # @drive-backup: Since 1.6 # +# Features: +# @deprecated: Member @drive-backup is deprecated. Use member +# @blockdev-backup instead. +# # Since: 1.1 ## { 'enum': 'TransactionActionKind', @@ -62,7 +66,7 @@ 'block-dirty-bitmap-disable', 'block-dirty-bitmap-merge', 'blockdev-backup', 'blockdev-snapshot', 'blockdev-snapshot-internal-sync', 'blockdev-snapshot-sync', - 'drive-backup' ] } + { 'name': 'drive-backup', 'features': [ 'deprecated' ] } ] } =20 ## # @AbortWrapper: --=20 2.31.1