From nobody Thu Dec 18 23:00:21 2025 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.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 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=redhat.com Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1549483131342290.3571740851562; Wed, 6 Feb 2019 11:58:51 -0800 (PST) Received: from localhost ([127.0.0.1]:57803 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1grTLI-0001ut-7G for importer@patchew.org; Wed, 06 Feb 2019 14:58:44 -0500 Received: from eggs.gnu.org ([209.51.188.92]:38208) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1grTIg-0008SR-Cj for qemu-devel@nongnu.org; Wed, 06 Feb 2019 14:56:03 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1grTIe-0007tj-Pd for qemu-devel@nongnu.org; Wed, 06 Feb 2019 14:56:02 -0500 Received: from mx1.redhat.com ([209.132.183.28]:41550) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1grTIa-0007rY-Vv; Wed, 06 Feb 2019 14:55:57 -0500 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 2BFD1C07224A; Wed, 6 Feb 2019 19:55:56 +0000 (UTC) Received: from localhost (unknown [10.40.205.248]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 7FBDD5D9D6; Wed, 6 Feb 2019 19:55:55 +0000 (UTC) From: Max Reitz To: qemu-block@nongnu.org Date: Wed, 6 Feb 2019 20:55:44 +0100 Message-Id: <20190206195551.28893-2-mreitz@redhat.com> In-Reply-To: <20190206195551.28893-1-mreitz@redhat.com> References: <20190206195551.28893-1-mreitz@redhat.com> MIME-Version: 1.0 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.32]); Wed, 06 Feb 2019 19:55:56 +0000 (UTC) Content-Transfer-Encoding: quoted-printable X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 209.132.183.28 Subject: [Qemu-devel] [PATCH v3 1/8] qapi: Add default-variant for flat unions X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Kevin Wolf , qemu-devel@nongnu.org, Michael Roth , Markus Armbruster , Max Reitz Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" Content-Type: text/plain; charset="utf-8" This patch allows specifying a discriminator that is an optional member of the base struct. In such a case, a default value must be provided that is used when no value is given. Signed-off-by: Max Reitz Reviewed-by: Eric Blake --- qapi/introspect.json | 8 +++++ scripts/qapi/common.py | 58 ++++++++++++++++++++++++++++------ scripts/qapi/doc.py | 10 ++++-- scripts/qapi/introspect.py | 10 ++++-- scripts/qapi/visit.py | 13 ++++++++ tests/qapi-schema/test-qapi.py | 2 ++ 6 files changed, 86 insertions(+), 15 deletions(-) diff --git a/qapi/introspect.json b/qapi/introspect.json index 3d22166b2b..e4740aa7a0 100644 --- a/qapi/introspect.json +++ b/qapi/introspect.json @@ -168,6 +168,13 @@ # @tag: the name of the member serving as type tag. # An element of @members with this name must exist. # +# @default-variant: if the @tag element of @members is optional, this +# is the default value for choosing a variant. Its +# value will be a valid value for @tag. +# Present exactly when @tag is present and the +# associated element of @members is optional. +# (Since: 4.0) +# # @variants: variant members, i.e. additional members that # depend on the type tag's value. Present exactly when # @tag is present. The variants are in no particular order, @@ -181,6 +188,7 @@ { 'struct': 'SchemaInfoObject', 'data': { 'members': [ 'SchemaInfoObjectMember' ], '*tag': 'str', + '*default-variant': 'str', '*variants': [ 'SchemaInfoObjectVariant' ] } } =20 ## diff --git a/scripts/qapi/common.py b/scripts/qapi/common.py index c89edc0cb0..13fd55d9c9 100644 --- a/scripts/qapi/common.py +++ b/scripts/qapi/common.py @@ -750,6 +750,7 @@ def check_union(expr, info): name =3D expr['union'] base =3D expr.get('base') discriminator =3D expr.get('discriminator') + default_variant =3D expr.get('default-variant') members =3D expr['data'] =20 # Two types of unions, determined by discriminator. @@ -774,16 +775,37 @@ def check_union(expr, info): base_members =3D find_base_members(base) assert base_members is not None =20 - # The value of member 'discriminator' must name a non-optional - # member of the base struct. + # The value of member 'discriminator' must name a member of + # the base struct. check_name(info, "Discriminator of flat union '%s'" % name, discriminator) - discriminator_value =3D base_members.get(discriminator) - if not discriminator_value: - raise QAPISemError(info, - "Discriminator '%s' is not a member of base= " - "struct '%s'" - % (discriminator, base)) + if default_variant is None: + discriminator_value =3D base_members.get(discriminator) + if not discriminator_value: + if base_members.get('*' + discriminator) is None: + raise QAPISemError(info, + "Discriminator '%s' is not a member= of " + "base struct '%s'" + % (discriminator, base)) + else: + raise QAPISemError(info, + "Default variant must be specified = for " + "optional discriminator '%s'" + % discriminator) + else: + discriminator_value =3D base_members.get('*' + discriminator) + if not discriminator_value: + if base_members.get(discriminator) is None: + raise QAPISemError(info, + "Discriminator '%s' is not a member= of " + "base struct '%s'" + % (discriminator, base)) + else: + raise QAPISemError(info, + "Must not specify a default variant= for " + "non-optional discriminator '%s'" + % discriminator) + if discriminator_value.get('if'): raise QAPISemError(info, 'The discriminator %s.%s for union %s= ' 'must not be conditional' % @@ -796,6 +818,16 @@ def check_union(expr, info): "Discriminator '%s' must be of enumeration " "type" % discriminator) =20 + if default_variant is not None: + # Must be a value of the enumeration + if not any(value for value in enum_define['data'] + if value['name'] =3D=3D default_variant): + raise QAPISemError(info, + "Default variant '%s' of flat union '%s= ' is " + "not part of '%s'" + % (default_variant, name, + discriminator_value['type'])) + # Check every branch; don't allow an empty union if len(members) =3D=3D 0: raise QAPISemError(info, "Union '%s' cannot have empty 'data'" % n= ame) @@ -976,7 +1008,7 @@ def check_exprs(exprs): elif 'union' in expr: meta =3D 'union' check_keys(expr_elem, 'union', ['data'], - ['base', 'discriminator', 'if']) + ['base', 'discriminator', 'if', 'default-variant']) normalize_members(expr.get('base')) normalize_members(expr['data']) union_types[expr[meta]] =3D expr @@ -1431,12 +1463,14 @@ class QAPISchemaObjectTypeMember(QAPISchemaMember): =20 =20 class QAPISchemaObjectTypeVariants(object): - def __init__(self, tag_name, tag_member, variants): + def __init__(self, tag_name, tag_member, default_tag_value, variants): # Flat unions pass tag_name but not tag_member. # Simple unions and alternates pass tag_member but not tag_name. # After check(), tag_member is always set, and tag_name remains # a reliable witness of being used by a flat union. assert bool(tag_member) !=3D bool(tag_name) + # default_tag_value is only passed for flat unions. + assert bool(tag_name) or not bool(default_tag_value) assert (isinstance(tag_name, str) or isinstance(tag_member, QAPISchemaObjectTypeMember)) assert len(variants) > 0 @@ -1444,6 +1478,7 @@ class QAPISchemaObjectTypeVariants(object): assert isinstance(v, QAPISchemaObjectTypeVariant) self._tag_name =3D tag_name self.tag_member =3D tag_member + self.default_tag_value =3D default_tag_value self.variants =3D variants =20 def set_owner(self, name): @@ -1773,6 +1808,7 @@ class QAPISchema(object): base =3D expr.get('base') ifcond =3D expr.get('if') tag_name =3D expr.get('discriminator') + default_tag_value =3D expr.get('default-variant') tag_member =3D None if isinstance(base, dict): base =3D self._make_implicit_object_type( @@ -1794,6 +1830,7 @@ class QAPISchema(object): QAPISchemaObjectType(name, info, doc, ifcond, base, members, QAPISchemaObjectTypeVariants(tag_name, tag_member, + default_tag_= value, variants))) =20 def _def_alternate_type(self, expr, info, doc): @@ -1807,6 +1844,7 @@ class QAPISchema(object): QAPISchemaAlternateType(name, info, doc, ifcond, QAPISchemaObjectTypeVariants(None, tag_membe= r, + None, variants)= )) =20 def _def_command(self, expr, info, doc): diff --git a/scripts/qapi/doc.py b/scripts/qapi/doc.py index c03b690161..c7ad23985b 100755 --- a/scripts/qapi/doc.py +++ b/scripts/qapi/doc.py @@ -168,8 +168,14 @@ def texi_members(doc, what, base, variants, member_fun= c): items +=3D '@item The members of @code{%s}\n' % base.doc_type() if variants: for v in variants.variants: - when =3D ' when @code{%s} is @t{"%s"}%s' % ( - variants.tag_member.name, v.name, texi_if(v.ifcond, " (", = ")")) + if v.name =3D=3D variants.default_tag_value: + when =3D ' when @code{%s} is @t{"%s"} or not given%s' % ( + variants.tag_member.name, v.name, + texi_if(v.ifcond, " (", ")")) + else: + when =3D ' when @code{%s} is @t{"%s"}%s' % ( + variants.tag_member.name, v.name, + texi_if(v.ifcond, " (", ")")) if v.type.is_implicit(): assert not v.type.base and not v.type.variants for m in v.type.local_members: diff --git a/scripts/qapi/introspect.py b/scripts/qapi/introspect.py index f7f2ca07e4..db8af348d2 100644 --- a/scripts/qapi/introspect.py +++ b/scripts/qapi/introspect.py @@ -166,9 +166,12 @@ const QLitObject %(c_name)s =3D %(c_string)s; ret =3D (ret, {'if': member.ifcond}) return ret =20 - def _gen_variants(self, tag_name, variants): - return {'tag': tag_name, - 'variants': [self._gen_variant(v) for v in variants]} + def _gen_variants(self, tag_name, default_variant, variants): + ret =3D {'tag': tag_name, + 'variants': [self._gen_variant(v) for v in variants]} + if default_variant: + ret['default-variant'] =3D default_variant + return ret =20 def _gen_variant(self, variant): return ({'case': variant.name, 'type': self._use_type(variant.type= )}, @@ -192,6 +195,7 @@ const QLitObject %(c_name)s =3D %(c_string)s; obj =3D {'members': [self._gen_member(m) for m in members]} if variants: obj.update(self._gen_variants(variants.tag_member.name, + variants.default_tag_value, variants.variants)) self._gen_qlit(name, 'object', obj, ifcond) =20 diff --git a/scripts/qapi/visit.py b/scripts/qapi/visit.py index 82eab72b21..57eccdfdc2 100644 --- a/scripts/qapi/visit.py +++ b/scripts/qapi/visit.py @@ -77,6 +77,19 @@ void visit_type_%(c_name)s_members(Visitor *v, %(c_name)= s *obj, Error **errp) ret +=3D gen_endif(memb.ifcond) =20 if variants: + if variants.default_tag_value is not None: + ret +=3D mcgen(''' + if (!obj->has_%(c_name)s) { + obj->has_%(c_name)s =3D true; + obj->%(c_name)s =3D %(enum_const)s; + } +''', + c_name=3Dc_name(variants.tag_member.name), + enum_const=3Dc_enum_const( + variants.tag_member.type.name, + variants.default_tag_value, + variants.tag_member.type.prefix)) + ret +=3D mcgen(''' switch (obj->%(c_name)s) { ''', diff --git a/tests/qapi-schema/test-qapi.py b/tests/qapi-schema/test-qapi.py index d592854601..be223e2cc4 100644 --- a/tests/qapi-schema/test-qapi.py +++ b/tests/qapi-schema/test-qapi.py @@ -66,6 +66,8 @@ class QAPISchemaTestVisitor(QAPISchemaVisitor): def _print_variants(variants): if variants: print(' tag %s' % variants.tag_member.name) + if variants.default_tag_value: + print(' default variant: %s' % variants.default_tag_val= ue) for v in variants.variants: print(' case %s: %s' % (v.name, v.type.name)) QAPISchemaTestVisitor._print_if(v.ifcond, indent=3D8) --=20 2.20.1 From nobody Thu Dec 18 23:00:21 2025 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.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 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=redhat.com Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1549483079425774.2476794383356; Wed, 6 Feb 2019 11:57:59 -0800 (PST) Received: from localhost ([127.0.0.1]:57797 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1grTKU-0001Cd-Gp for importer@patchew.org; Wed, 06 Feb 2019 14:57:54 -0500 Received: from eggs.gnu.org ([209.51.188.92]:38210) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1grTIg-0008SX-Fb for qemu-devel@nongnu.org; Wed, 06 Feb 2019 14:56:03 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1grTIf-0007up-Im for qemu-devel@nongnu.org; Wed, 06 Feb 2019 14:56:02 -0500 Received: from mx1.redhat.com ([209.132.183.28]:44040) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1grTId-0007sX-AR; Wed, 06 Feb 2019 14:55:59 -0500 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 8200558577; Wed, 6 Feb 2019 19:55:58 +0000 (UTC) Received: from localhost (unknown [10.40.205.248]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 11D7D87DB; Wed, 6 Feb 2019 19:55:57 +0000 (UTC) From: Max Reitz To: qemu-block@nongnu.org Date: Wed, 6 Feb 2019 20:55:45 +0100 Message-Id: <20190206195551.28893-3-mreitz@redhat.com> In-Reply-To: <20190206195551.28893-1-mreitz@redhat.com> References: <20190206195551.28893-1-mreitz@redhat.com> MIME-Version: 1.0 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.39]); Wed, 06 Feb 2019 19:55:58 +0000 (UTC) Content-Transfer-Encoding: quoted-printable X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 209.132.183.28 Subject: [Qemu-devel] [PATCH v3 2/8] docs/qapi: Document optional discriminators X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Kevin Wolf , qemu-devel@nongnu.org, Michael Roth , Markus Armbruster , Max Reitz Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" Content-Type: text/plain; charset="utf-8" Reviewed-by: Eric Blake Signed-off-by: Max Reitz --- docs/devel/qapi-code-gen.txt | 21 +++++++++++++++++++-- 1 file changed, 19 insertions(+), 2 deletions(-) diff --git a/docs/devel/qapi-code-gen.txt b/docs/devel/qapi-code-gen.txt index 87183d3a09..32c576f30b 100644 --- a/docs/devel/qapi-code-gen.txt +++ b/docs/devel/qapi-code-gen.txt @@ -472,8 +472,8 @@ All branches of the union must be complex types, and th= e top-level members of the union dictionary on the wire will be combination of members from both the base type and the appropriate branch type (when merging two dictionaries, there must be no keys in common). The -'discriminator' member must be the name of a non-optional enum-typed -member of the base struct. +'discriminator' member must be the name of an enum-typed member of the +base struct. =20 The following example enhances the above simple union example by adding an optional common member 'read-only', renaming the @@ -504,6 +504,23 @@ In the resulting generated C data types, a flat union = is represented as a struct with the base members included directly, and then a union of structures for each branch of the struct. =20 +If the discriminator points to an optional member of the base struct, +its default value must be specified as a 'default-variant'. In the +following example, the above BlockDriver struct is changed so it +defaults to the 'file' driver if that field is omitted on the wire: + + { 'union': 'BlockdevOptions', + 'base': { '*driver': 'BlockdevDriver', '*read-only': 'bool' }, + 'discriminator': 'driver', + 'default-variant': 'file', + 'data': { 'file': 'BlockdevOptionsFile', + 'qcow2': 'BlockdevOptionsQcow2' } } + +Now the 'file' JSON object can be abbreviated to: + + { "read-only": "true", + "filename": "/some/place/my-image" } + A simple union can always be re-written as a flat union where the base class has a single member named 'type', and where each branch of the union has a struct with a single member named 'data'. That is, --=20 2.20.1 From nobody Thu Dec 18 23:00:21 2025 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.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 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=redhat.com Return-Path: Received: from lists.gnu.org (209.51.188.17 [209.51.188.17]) by mx.zohomail.com with SMTPS id 1549483285493771.684533361927; Wed, 6 Feb 2019 12:01:25 -0800 (PST) Received: from localhost ([127.0.0.1]:57868 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1grTNn-00049X-54 for importer@patchew.org; Wed, 06 Feb 2019 15:01:19 -0500 Received: from eggs.gnu.org ([209.51.188.92]:38274) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1grTIl-000065-TK for qemu-devel@nongnu.org; Wed, 06 Feb 2019 14:56:09 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1grTIk-0007xp-6P for qemu-devel@nongnu.org; Wed, 06 Feb 2019 14:56:07 -0500 Received: from mx1.redhat.com ([209.132.183.28]:51604) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1grTIf-0007tx-Uh; Wed, 06 Feb 2019 14:56:02 -0500 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 2F38189AFB; Wed, 6 Feb 2019 19:56:01 +0000 (UTC) Received: from localhost (unknown [10.40.205.248]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 78D31608C2; Wed, 6 Feb 2019 19:56:00 +0000 (UTC) From: Max Reitz To: qemu-block@nongnu.org Date: Wed, 6 Feb 2019 20:55:46 +0100 Message-Id: <20190206195551.28893-4-mreitz@redhat.com> In-Reply-To: <20190206195551.28893-1-mreitz@redhat.com> References: <20190206195551.28893-1-mreitz@redhat.com> MIME-Version: 1.0 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.26]); Wed, 06 Feb 2019 19:56:01 +0000 (UTC) Content-Transfer-Encoding: quoted-printable X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 209.132.183.28 Subject: [Qemu-devel] [PATCH v3 3/8] tests: Add QAPI optional discriminator tests X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Kevin Wolf , qemu-devel@nongnu.org, Michael Roth , Markus Armbruster , Max Reitz Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" Content-Type: text/plain; charset="utf-8" There already is an optional discriminator test, although it also noted the discriminator name itself as optional. This already gives us one error test case, to which this patch adds various others. Furthermore, a passing test case is added to qapi-schema-test. Signed-off-by: Max Reitz Reviewed-by: Eric Blake --- tests/Makefile.include | 5 ++++- ...union-optional-discriminator-invalid-default.json | 12 ++++++++++++ ...optional-discriminator-invalid-specification.json | 12 ++++++++++++ ...lat-union-optional-discriminator-no-default.json} | 5 +++-- .../flat-union-superfluous-default-variant.json | 11 +++++++++++ tests/qapi-schema/qapi-schema-test.json | 11 +++++++++++ ...-union-optional-discriminator-invalid-default.err | 1 + ...nion-optional-discriminator-invalid-default.exit} | 0 ...union-optional-discriminator-invalid-default.out} | 0 ...-optional-discriminator-invalid-specification.err | 1 + ...optional-discriminator-invalid-specification.exit | 1 + ...-optional-discriminator-invalid-specification.out | 0 .../flat-union-optional-discriminator-no-default.err | 1 + ...flat-union-optional-discriminator-no-default.exit | 1 + .../flat-union-optional-discriminator-no-default.out | 0 .../flat-union-optional-discriminator.err | 1 - .../flat-union-superfluous-default-variant.err | 1 + .../flat-union-superfluous-default-variant.exit | 1 + .../flat-union-superfluous-default-variant.out | 0 tests/qapi-schema/qapi-schema-test.out | 10 ++++++++++ 20 files changed, 70 insertions(+), 4 deletions(-) create mode 100644 tests/qapi-schema/flat-union-optional-discriminator-inv= alid-default.json create mode 100644 tests/qapi-schema/flat-union-optional-discriminator-inv= alid-specification.json rename tests/qapi-schema/{flat-union-optional-discriminator.json =3D> flat= -union-optional-discriminator-no-default.json} (70%) create mode 100644 tests/qapi-schema/flat-union-superfluous-default-varian= t.json create mode 100644 tests/qapi-schema/flat-union-optional-discriminator-inv= alid-default.err rename tests/qapi-schema/{flat-union-optional-discriminator.exit =3D> flat= -union-optional-discriminator-invalid-default.exit} (100%) rename tests/qapi-schema/{flat-union-optional-discriminator.out =3D> flat-= union-optional-discriminator-invalid-default.out} (100%) create mode 100644 tests/qapi-schema/flat-union-optional-discriminator-inv= alid-specification.err create mode 100644 tests/qapi-schema/flat-union-optional-discriminator-inv= alid-specification.exit create mode 100644 tests/qapi-schema/flat-union-optional-discriminator-inv= alid-specification.out create mode 100644 tests/qapi-schema/flat-union-optional-discriminator-no-= default.err create mode 100644 tests/qapi-schema/flat-union-optional-discriminator-no-= default.exit create mode 100644 tests/qapi-schema/flat-union-optional-discriminator-no-= default.out delete mode 100644 tests/qapi-schema/flat-union-optional-discriminator.err create mode 100644 tests/qapi-schema/flat-union-superfluous-default-varian= t.err create mode 100644 tests/qapi-schema/flat-union-superfluous-default-varian= t.exit create mode 100644 tests/qapi-schema/flat-union-superfluous-default-varian= t.out diff --git a/tests/Makefile.include b/tests/Makefile.include index 75ad9c0dd3..8fd05da00a 100644 --- a/tests/Makefile.include +++ b/tests/Makefile.include @@ -422,8 +422,11 @@ qapi-schema +=3D flat-union-invalid-branch-key.json qapi-schema +=3D flat-union-invalid-discriminator.json qapi-schema +=3D flat-union-invalid-if-discriminator.json qapi-schema +=3D flat-union-no-base.json -qapi-schema +=3D flat-union-optional-discriminator.json +qapi-schema +=3D flat-union-optional-discriminator-invalid-specification.j= son +qapi-schema +=3D flat-union-optional-discriminator-no-default.json +qapi-schema +=3D flat-union-optional-discriminator-invalid-default.json qapi-schema +=3D flat-union-string-discriminator.json +qapi-schema +=3D flat-union-superfluous-default-variant.json qapi-schema +=3D funny-char.json qapi-schema +=3D ident-with-escape.json qapi-schema +=3D include-before-err.json diff --git a/tests/qapi-schema/flat-union-optional-discriminator-invalid-de= fault.json b/tests/qapi-schema/flat-union-optional-discriminator-invalid-de= fault.json new file mode 100644 index 0000000000..015a47ba52 --- /dev/null +++ b/tests/qapi-schema/flat-union-optional-discriminator-invalid-default.j= son @@ -0,0 +1,12 @@ +# default-variant must refer to an actual value of the discriminator's +# enum +{ 'enum': 'Enum', 'data': [ 'one', 'two' ] } +{ 'struct': 'Base', + 'data': { '*switch': 'Enum' } } +{ 'struct': 'Branch', 'data': { 'name': 'str' } } +{ 'union': 'MyUnion', + 'base': 'Base', + 'discriminator': 'switch', + 'default-variant': 'three', + 'data': { 'one': 'Branch', + 'two': 'Branch' } } diff --git a/tests/qapi-schema/flat-union-optional-discriminator-invalid-sp= ecification.json b/tests/qapi-schema/flat-union-optional-discriminator-inva= lid-specification.json new file mode 100644 index 0000000000..fd896942a2 --- /dev/null +++ b/tests/qapi-schema/flat-union-optional-discriminator-invalid-specifica= tion.json @@ -0,0 +1,12 @@ +# For using optional discriminators, only the field in the base struct +# must be marked optional, not the discriminator name itself +{ 'enum': 'Enum', 'data': [ 'one', 'two' ] } +{ 'struct': 'Base', + 'data': { '*switch': 'Enum' } } +{ 'struct': 'Branch', 'data': { 'name': 'str' } } +{ 'union': 'MyUnion', + 'base': 'Base', + 'discriminator': '*switch', + 'default-variant': 'one', + 'data': { 'one': 'Branch', + 'two': 'Branch' } } diff --git a/tests/qapi-schema/flat-union-optional-discriminator.json b/tes= ts/qapi-schema/flat-union-optional-discriminator-no-default.json similarity index 70% rename from tests/qapi-schema/flat-union-optional-discriminator.json rename to tests/qapi-schema/flat-union-optional-discriminator-no-default.js= on index 08a8f7ef8b..0d612f5a62 100644 --- a/tests/qapi-schema/flat-union-optional-discriminator.json +++ b/tests/qapi-schema/flat-union-optional-discriminator-no-default.json @@ -1,10 +1,11 @@ -# we require the discriminator to be non-optional +# Using an optional discriminator requires specifying a default +# variant { 'enum': 'Enum', 'data': [ 'one', 'two' ] } { 'struct': 'Base', 'data': { '*switch': 'Enum' } } { 'struct': 'Branch', 'data': { 'name': 'str' } } { 'union': 'MyUnion', 'base': 'Base', - 'discriminator': '*switch', + 'discriminator': 'switch', 'data': { 'one': 'Branch', 'two': 'Branch' } } diff --git a/tests/qapi-schema/flat-union-superfluous-default-variant.json = b/tests/qapi-schema/flat-union-superfluous-default-variant.json new file mode 100644 index 0000000000..8558165868 --- /dev/null +++ b/tests/qapi-schema/flat-union-superfluous-default-variant.json @@ -0,0 +1,11 @@ +# default-variant only makes sense with an optional discriminator +{ 'enum': 'Enum', 'data': [ 'one', 'two' ] } +{ 'struct': 'Base', + 'data': { 'switch': 'Enum' } } +{ 'struct': 'Branch', 'data': { 'name': 'str' } } +{ 'union': 'MyUnion', + 'base': 'Base', + 'discriminator': 'switch', + 'default-variant': 'one', + 'data': { 'one': 'Branch', + 'two': 'Branch' } } diff --git a/tests/qapi-schema/qapi-schema-test.json b/tests/qapi-schema/qa= pi-schema-test.json index cb0857df52..6c7462928e 100644 --- a/tests/qapi-schema/qapi-schema-test.json +++ b/tests/qapi-schema/qapi-schema-test.json @@ -104,6 +104,17 @@ { 'struct': 'UserDefC', 'data': { 'string1': 'str', 'string2': 'str' } } =20 +# for testing unions with an optional discriminator +{ 'union': 'UserDefFlatUnion3', + 'base': { '*enum1': 'EnumOne' }, + 'discriminator': 'enum1', + 'default-variant': 'value1', + 'data': { 'value1' : 'UserDefA', + 'value2' : 'UserDefB', + 'value3' : 'UserDefB' + # 'value4' defaults to empty + } } + # for testing use of 'number' within alternates { 'alternate': 'AltEnumBool', 'data': { 'e': 'EnumOne', 'b': 'bool' } } { 'alternate': 'AltEnumNum', 'data': { 'e': 'EnumOne', 'n': 'number' } } diff --git a/tests/qapi-schema/flat-union-optional-discriminator-invalid-de= fault.err b/tests/qapi-schema/flat-union-optional-discriminator-invalid-def= ault.err new file mode 100644 index 0000000000..b6bd3423d6 --- /dev/null +++ b/tests/qapi-schema/flat-union-optional-discriminator-invalid-default.e= rr @@ -0,0 +1 @@ +tests/qapi-schema/flat-union-optional-discriminator-invalid-default.json:7= : Default variant 'three' of flat union 'MyUnion' is not part of 'Enum' diff --git a/tests/qapi-schema/flat-union-optional-discriminator.exit b/tes= ts/qapi-schema/flat-union-optional-discriminator-invalid-default.exit similarity index 100% rename from tests/qapi-schema/flat-union-optional-discriminator.exit rename to tests/qapi-schema/flat-union-optional-discriminator-invalid-defau= lt.exit diff --git a/tests/qapi-schema/flat-union-optional-discriminator.out b/test= s/qapi-schema/flat-union-optional-discriminator-invalid-default.out similarity index 100% rename from tests/qapi-schema/flat-union-optional-discriminator.out rename to tests/qapi-schema/flat-union-optional-discriminator-invalid-defau= lt.out diff --git a/tests/qapi-schema/flat-union-optional-discriminator-invalid-sp= ecification.err b/tests/qapi-schema/flat-union-optional-discriminator-inval= id-specification.err new file mode 100644 index 0000000000..cbf154e726 --- /dev/null +++ b/tests/qapi-schema/flat-union-optional-discriminator-invalid-specifica= tion.err @@ -0,0 +1 @@ +tests/qapi-schema/flat-union-optional-discriminator-invalid-specification.= json:7: Discriminator of flat union 'MyUnion' does not allow optional name = '*switch' diff --git a/tests/qapi-schema/flat-union-optional-discriminator-invalid-sp= ecification.exit b/tests/qapi-schema/flat-union-optional-discriminator-inva= lid-specification.exit new file mode 100644 index 0000000000..d00491fd7e --- /dev/null +++ b/tests/qapi-schema/flat-union-optional-discriminator-invalid-specifica= tion.exit @@ -0,0 +1 @@ +1 diff --git a/tests/qapi-schema/flat-union-optional-discriminator-invalid-sp= ecification.out b/tests/qapi-schema/flat-union-optional-discriminator-inval= id-specification.out new file mode 100644 index 0000000000..e69de29bb2 diff --git a/tests/qapi-schema/flat-union-optional-discriminator-no-default= .err b/tests/qapi-schema/flat-union-optional-discriminator-no-default.err new file mode 100644 index 0000000000..1342efd9e8 --- /dev/null +++ b/tests/qapi-schema/flat-union-optional-discriminator-no-default.err @@ -0,0 +1 @@ +tests/qapi-schema/flat-union-optional-discriminator-no-default.json:7: Def= ault variant must be specified for optional discriminator 'switch' diff --git a/tests/qapi-schema/flat-union-optional-discriminator-no-default= .exit b/tests/qapi-schema/flat-union-optional-discriminator-no-default.exit new file mode 100644 index 0000000000..d00491fd7e --- /dev/null +++ b/tests/qapi-schema/flat-union-optional-discriminator-no-default.exit @@ -0,0 +1 @@ +1 diff --git a/tests/qapi-schema/flat-union-optional-discriminator-no-default= .out b/tests/qapi-schema/flat-union-optional-discriminator-no-default.out new file mode 100644 index 0000000000..e69de29bb2 diff --git a/tests/qapi-schema/flat-union-optional-discriminator.err b/test= s/qapi-schema/flat-union-optional-discriminator.err deleted file mode 100644 index aaabedb3bd..0000000000 --- a/tests/qapi-schema/flat-union-optional-discriminator.err +++ /dev/null @@ -1 +0,0 @@ -tests/qapi-schema/flat-union-optional-discriminator.json:6: Discriminator = of flat union 'MyUnion' does not allow optional name '*switch' diff --git a/tests/qapi-schema/flat-union-superfluous-default-variant.err b= /tests/qapi-schema/flat-union-superfluous-default-variant.err new file mode 100644 index 0000000000..5230bbf645 --- /dev/null +++ b/tests/qapi-schema/flat-union-superfluous-default-variant.err @@ -0,0 +1 @@ +tests/qapi-schema/flat-union-superfluous-default-variant.json:6: Must not = specify a default variant for non-optional discriminator 'switch' diff --git a/tests/qapi-schema/flat-union-superfluous-default-variant.exit = b/tests/qapi-schema/flat-union-superfluous-default-variant.exit new file mode 100644 index 0000000000..d00491fd7e --- /dev/null +++ b/tests/qapi-schema/flat-union-superfluous-default-variant.exit @@ -0,0 +1 @@ +1 diff --git a/tests/qapi-schema/flat-union-superfluous-default-variant.out b= /tests/qapi-schema/flat-union-superfluous-default-variant.out new file mode 100644 index 0000000000..e69de29bb2 diff --git a/tests/qapi-schema/qapi-schema-test.out b/tests/qapi-schema/qap= i-schema-test.out index 9464101d26..0044fb4554 100644 --- a/tests/qapi-schema/qapi-schema-test.out +++ b/tests/qapi-schema/qapi-schema-test.out @@ -92,6 +92,16 @@ alternate UserDefAlternate object UserDefC member string1: str optional=3DFalse member string2: str optional=3DFalse +object q_obj_UserDefFlatUnion3-base + member enum1: EnumOne optional=3DTrue +object UserDefFlatUnion3 + base q_obj_UserDefFlatUnion3-base + tag enum1 + default variant: value1 + case value1: UserDefA + case value2: UserDefB + case value3: UserDefB + case value4: q_empty alternate AltEnumBool tag type case e: EnumOne --=20 2.20.1 From nobody Thu Dec 18 23:00:21 2025 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.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 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=redhat.com Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1549483219840262.9760275502272; Wed, 6 Feb 2019 12:00:19 -0800 (PST) Received: from localhost ([127.0.0.1]:57825 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1grTMo-0003PQ-MS for importer@patchew.org; Wed, 06 Feb 2019 15:00:18 -0500 Received: from eggs.gnu.org ([209.51.188.92]:38261) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1grTIl-00005q-D7 for qemu-devel@nongnu.org; Wed, 06 Feb 2019 14:56:08 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1grTIk-0007xx-GK for qemu-devel@nongnu.org; Wed, 06 Feb 2019 14:56:07 -0500 Received: from mx1.redhat.com ([209.132.183.28]:51240) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1grTIi-0007wj-B5; Wed, 06 Feb 2019 14:56:04 -0500 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 8D2F037EE7; Wed, 6 Feb 2019 19:56:03 +0000 (UTC) Received: from localhost (unknown [10.40.205.248]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 1D38F5D9D6; Wed, 6 Feb 2019 19:56:02 +0000 (UTC) From: Max Reitz To: qemu-block@nongnu.org Date: Wed, 6 Feb 2019 20:55:47 +0100 Message-Id: <20190206195551.28893-5-mreitz@redhat.com> In-Reply-To: <20190206195551.28893-1-mreitz@redhat.com> References: <20190206195551.28893-1-mreitz@redhat.com> MIME-Version: 1.0 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.29]); Wed, 06 Feb 2019 19:56:03 +0000 (UTC) Content-Transfer-Encoding: quoted-printable X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 209.132.183.28 Subject: [Qemu-devel] [PATCH v3 4/8] qapi: Formalize qcow2 encryption probing X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Kevin Wolf , qemu-devel@nongnu.org, Michael Roth , Markus Armbruster , Max Reitz Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" Content-Type: text/plain; charset="utf-8" Currently, you can give no encryption format for a qcow2 file while still passing a key-secret. That does not conform to the schema, so this patch changes the schema to allow it. Signed-off-by: Max Reitz Reviewed-by: Eric Blake --- qapi/block-core.json | 31 ++++++++++++++++++++++++++++--- block/qcow2.c | 3 +++ 2 files changed, 31 insertions(+), 3 deletions(-) diff --git a/qapi/block-core.json b/qapi/block-core.json index 5f17d67d71..abf9af0c4d 100644 --- a/qapi/block-core.json +++ b/qapi/block-core.json @@ -47,6 +47,9 @@ ## # @ImageInfoSpecificQCow2Encryption: # +# @format will never be "auto", as this pseudo-format just tells the +# qcow2 driver to read the actual format from the image header. +# # Since: 2.10 ## { 'union': 'ImageInfoSpecificQCow2Encryption', @@ -2961,10 +2964,30 @@ # @BlockdevQcow2EncryptionFormat: # @aes: AES-CBC with plain64 initialization venctors # +# @auto: Determine the encryption format from the image +# header. This only allows the use of the +# key-secret option. (Since: 4.0) +# # Since: 2.10 ## { 'enum': 'BlockdevQcow2EncryptionFormat', - 'data': [ 'aes', 'luks' ] } + 'data': [ 'aes', 'luks', 'auto' ] } + +## +# @BlockdevQcow2EncryptionSecret: +# +# Allows specifying a key-secret without specifying the exact +# encryption format, which is determined automatically from the image +# header. +# +# @key-secret: The ID of a QCryptoSecret object providing the +# decryption key. Mandatory except when probing +# image for metadata only. +# +# Since: 4.0 +## +{ 'struct': 'BlockdevQcow2EncryptionSecret', + 'data': { '*key-secret': 'str' } } =20 ## # @BlockdevQcow2Encryption: @@ -2972,10 +2995,12 @@ # Since: 2.10 ## { 'union': 'BlockdevQcow2Encryption', - 'base': { 'format': 'BlockdevQcow2EncryptionFormat' }, + 'base': { '*format': 'BlockdevQcow2EncryptionFormat' }, 'discriminator': 'format', + 'default-variant': 'auto', 'data': { 'aes': 'QCryptoBlockOptionsQCow', - 'luks': 'QCryptoBlockOptionsLUKS'} } + 'luks': 'QCryptoBlockOptionsLUKS', + 'auto': 'BlockdevQcow2EncryptionSecret' } } =20 ## # @BlockdevOptionsQcow2: diff --git a/block/qcow2.c b/block/qcow2.c index c21452bc2f..5885f5175e 100644 --- a/block/qcow2.c +++ b/block/qcow2.c @@ -883,6 +883,9 @@ static int qcow2_update_options_prepare(BlockDriverStat= e *bs, =20 qdict_extract_subqdict(options, &encryptopts, "encrypt."); encryptfmt =3D qdict_get_try_str(encryptopts, "format"); + if (!g_strcmp0(encryptfmt, "auto")) { + encryptfmt =3D NULL; + } =20 opts =3D qemu_opts_create(&qcow2_runtime_opts, NULL, 0, &error_abort); qemu_opts_absorb_qdict(opts, options, &local_err); --=20 2.20.1 From nobody Thu Dec 18 23:00:21 2025 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.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 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=redhat.com Return-Path: Received: from lists.gnu.org (209.51.188.17 [209.51.188.17]) by mx.zohomail.com with SMTPS id 1549483399908769.5996011975471; Wed, 6 Feb 2019 12:03:19 -0800 (PST) Received: from localhost ([127.0.0.1]:57886 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1grTPd-0005QT-Sp for importer@patchew.org; Wed, 06 Feb 2019 15:03:13 -0500 Received: from eggs.gnu.org ([209.51.188.92]:38298) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1grTIn-00008U-RR for qemu-devel@nongnu.org; Wed, 06 Feb 2019 14:56:10 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1grTIn-0007zA-1y for qemu-devel@nongnu.org; Wed, 06 Feb 2019 14:56:09 -0500 Received: from mx1.redhat.com ([209.132.183.28]:51654) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1grTIl-0007y3-A4; Wed, 06 Feb 2019 14:56:07 -0500 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 62F7489AFE; Wed, 6 Feb 2019 19:56:06 +0000 (UTC) Received: from localhost (unknown [10.40.205.248]) by smtp.corp.redhat.com (Postfix) with ESMTPS id BC99662486; Wed, 6 Feb 2019 19:56:05 +0000 (UTC) From: Max Reitz To: qemu-block@nongnu.org Date: Wed, 6 Feb 2019 20:55:48 +0100 Message-Id: <20190206195551.28893-6-mreitz@redhat.com> In-Reply-To: <20190206195551.28893-1-mreitz@redhat.com> References: <20190206195551.28893-1-mreitz@redhat.com> MIME-Version: 1.0 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.26]); Wed, 06 Feb 2019 19:56:06 +0000 (UTC) Content-Transfer-Encoding: quoted-printable X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 209.132.183.28 Subject: [Qemu-devel] [PATCH v3 5/8] qapi: Formalize qcow encryption probing X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Kevin Wolf , qemu-devel@nongnu.org, Michael Roth , Markus Armbruster , Max Reitz Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" Content-Type: text/plain; charset="utf-8" qcow only supports a single encryption (and there is no reason why that would change in the future), so we can make it the default. Signed-off-by: Max Reitz Reviewed-by: Eric Blake Reviewed-by: Daniel P. Berrang=C3=A9 --- qapi/block-core.json | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/qapi/block-core.json b/qapi/block-core.json index abf9af0c4d..8e193fe71f 100644 --- a/qapi/block-core.json +++ b/qapi/block-core.json @@ -2939,8 +2939,9 @@ # Since: 2.10 ## { 'union': 'BlockdevQcowEncryption', - 'base': { 'format': 'BlockdevQcowEncryptionFormat' }, + 'base': { '*format': 'BlockdevQcowEncryptionFormat' }, 'discriminator': 'format', + 'default-variant': 'aes', 'data': { 'aes': 'QCryptoBlockOptionsQCow' } } =20 ## --=20 2.20.1 From nobody Thu Dec 18 23:00:21 2025 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.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 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=redhat.com Return-Path: Received: from lists.gnu.org (209.51.188.17 [209.51.188.17]) by mx.zohomail.com with SMTPS id 1549483444774303.0377697879961; Wed, 6 Feb 2019 12:04:04 -0800 (PST) Received: from localhost ([127.0.0.1]:57892 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1grTQO-00060a-Kk for importer@patchew.org; Wed, 06 Feb 2019 15:04:00 -0500 Received: from eggs.gnu.org ([209.51.188.92]:38340) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1grTIv-0000Gs-JM for qemu-devel@nongnu.org; Wed, 06 Feb 2019 14:56:19 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1grTIs-00081l-V2 for qemu-devel@nongnu.org; Wed, 06 Feb 2019 14:56:16 -0500 Received: from mx1.redhat.com ([209.132.183.28]:48506) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1grTIn-0007zJ-Q1; Wed, 06 Feb 2019 14:56:09 -0500 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 0C62B3F1E7; Wed, 6 Feb 2019 19:56:09 +0000 (UTC) Received: from localhost (unknown [10.40.205.248]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 58DD662480; Wed, 6 Feb 2019 19:56:08 +0000 (UTC) From: Max Reitz To: qemu-block@nongnu.org Date: Wed, 6 Feb 2019 20:55:49 +0100 Message-Id: <20190206195551.28893-7-mreitz@redhat.com> In-Reply-To: <20190206195551.28893-1-mreitz@redhat.com> References: <20190206195551.28893-1-mreitz@redhat.com> MIME-Version: 1.0 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]); Wed, 06 Feb 2019 19:56:09 +0000 (UTC) Content-Transfer-Encoding: quoted-printable X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 209.132.183.28 Subject: [Qemu-devel] [PATCH v3 6/8] block: Try to create well typed json:{} filenames X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Kevin Wolf , qemu-devel@nongnu.org, Michael Roth , Markus Armbruster , Max Reitz Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" Content-Type: text/plain; charset="utf-8" By applying a health mix of qdict_flatten(), qdict_crumple(), qdict_stringify_for_keyval(), the keyval input visitor, and the QObject output visitor (not necessarily in that order), we can at least try to bring bs->full_open_options into accordance with the QAPI schema. This may not always work (there are some options left that have not been QAPI-fied yet), but in practice it usually will. In any case, sometimes emitting wrongly typed json:{} filenames is better than doing it effectively half the time. This affects some iotests because json:{} filenames are now usually crumpled. In 198, "format": "auto" now appears in the qcow2 encryption options because going through a visitor makes optional discriminators' default values explicit. Buglink: https://bugzilla.redhat.com/show_bug.cgi?id=3D1534396 Signed-off-by: Max Reitz Reviewed-by: Eric Blake --- block.c | 68 +++++++++++++++++++++++++++++++++++++- tests/qemu-iotests/059.out | 2 +- tests/qemu-iotests/099.out | 4 +-- tests/qemu-iotests/110.out | 2 +- tests/qemu-iotests/198.out | 4 +-- tests/qemu-iotests/207.out | 10 +++--- 6 files changed, 78 insertions(+), 12 deletions(-) diff --git a/block.c b/block.c index d496debda4..c22f3fe5f1 100644 --- a/block.c +++ b/block.c @@ -36,6 +36,7 @@ #include "qapi/qmp/qjson.h" #include "qapi/qmp/qnull.h" #include "qapi/qmp/qstring.h" +#include "qapi/qobject-input-visitor.h" #include "qapi/qobject-output-visitor.h" #include "qapi/qapi-visit-block-core.h" #include "sysemu/block-backend.h" @@ -5581,6 +5582,56 @@ static bool bdrv_backing_overridden(BlockDriverState= *bs) } } =20 +/** + * Take a blockdev @options QDict and convert its values to the + * correct type. + * + * Fail if @options does not match the QAPI schema of BlockdevOptions. + * + * In case of failure, return NULL and set @errp. + * + * In case of success, return a correctly typed new QDict. + */ +static QDict *bdrv_type_blockdev_opts(const QDict *options, Error **errp) +{ + Visitor *v; + BlockdevOptions *blockdev_options; + QObject *typed_opts; + QDict *string_options; + Error *local_err =3D NULL; + + string_options =3D qdict_clone_shallow(options); + + qdict_flatten(string_options); + v =3D qobject_input_visitor_new_flat_confused(string_options, errp); + if (!v) { + error_prepend(errp, "Failed to prepare options: "); + return NULL; + } + + visit_type_BlockdevOptions(v, NULL, &blockdev_options, &local_err); + visit_free(v); + if (local_err) { + error_propagate(errp, local_err); + error_prepend(errp, "Not a valid BlockdevOptions object: "); + return NULL; + } + + v =3D qobject_output_visitor_new(&typed_opts); + visit_type_BlockdevOptions(v, NULL, &blockdev_options, &local_err); + if (!local_err) { + visit_complete(v, &typed_opts); + } + visit_free(v); + qapi_free_BlockdevOptions(blockdev_options); + if (local_err) { + error_propagate(errp, local_err); + return NULL; + } + + return qobject_to(QDict, typed_opts); +} + /* Updates the following BDS fields: * - exact_filename: A filename which may be used for opening a block dev= ice * which (mostly) equals the given BDS (even without any @@ -5698,10 +5749,25 @@ void bdrv_refresh_filename(BlockDriverState *bs) if (bs->exact_filename[0]) { pstrcpy(bs->filename, sizeof(bs->filename), bs->exact_filename); } else { - QString *json =3D qobject_to_json(QOBJECT(bs->full_open_options)); + QString *json; + QDict *typed_opts, *json_opts; + + typed_opts =3D bdrv_type_blockdev_opts(bs->full_open_options, NULL= ); + + /* + * We cannot be certain that bs->full_open_options matches + * BlockdevOptions, so bdrv_type_blockdev_opts() may fail. + * That is not fatal, we can just emit bs->full_open_options + * directly -- qemu will accept that, even if it does not + * match the schema. + */ + json_opts =3D typed_opts ?: bs->full_open_options; + + json =3D qobject_to_json(QOBJECT(json_opts)); snprintf(bs->filename, sizeof(bs->filename), "json:%s", qstring_get_str(json)); qobject_unref(json); + qobject_unref(typed_opts); } } =20 diff --git a/tests/qemu-iotests/059.out b/tests/qemu-iotests/059.out index f6dce7947c..0238b9e9a8 100644 --- a/tests/qemu-iotests/059.out +++ b/tests/qemu-iotests/059.out @@ -2050,7 +2050,7 @@ wrote 512/512 bytes at offset 10240 =20 =3D=3D=3D Testing monolithicFlat with internally generated JSON file name = =3D=3D=3D Formatting 'TEST_DIR/t.IMGFMT', fmt=3DIMGFMT size=3D67108864 subformat=3Dm= onolithicFlat -can't open: Cannot use relative extent paths with VMDK descriptor file 'js= on:{"image": {"driver": "file", "filename": "TEST_DIR/t.IMGFMT"}, "driver":= "blkdebug", "inject-error.0.event": "read_aio"}' +can't open: Cannot use relative extent paths with VMDK descriptor file 'js= on:{"inject-error": [{"event": "read_aio"}], "image": {"driver": "file", "f= ilename": "TEST_DIR/t.IMGFMT"}, "driver": "blkdebug"}' =20 =3D=3D=3D Testing version 3 =3D=3D=3D image: TEST_DIR/iotest-version3.IMGFMT diff --git a/tests/qemu-iotests/099.out b/tests/qemu-iotests/099.out index 8cce627529..0a9c434148 100644 --- a/tests/qemu-iotests/099.out +++ b/tests/qemu-iotests/099.out @@ -12,11 +12,11 @@ blkverify:TEST_DIR/t.IMGFMT.compare:TEST_DIR/t.IMGFMT =20 =3D=3D=3D Testing JSON filename for blkdebug =3D=3D=3D =20 -json:{"driver": "IMGFMT", "file": {"image": {"driver": "file", "filename":= "TEST_DIR/t.IMGFMT"}, "driver": "blkdebug", "inject-error.0.event": "l1_up= date"}} +json:{"driver": "IMGFMT", "file": {"inject-error": [{"event": "l1_update"}= ], "image": {"driver": "file", "filename": "TEST_DIR/t.IMGFMT"}, "driver": = "blkdebug"}} =20 =3D=3D=3D Testing indirectly enforced JSON filename =3D=3D=3D =20 -json:{"driver": "raw", "file": {"test": {"driver": "IMGFMT", "file": {"ima= ge": {"driver": "file", "filename": "TEST_DIR/t.IMGFMT"}, "driver": "blkdeb= ug", "inject-error.0.event": "l1_update"}}, "driver": "blkverify", "raw": {= "driver": "file", "filename": "TEST_DIR/t.IMGFMT.compare"}}} +json:{"driver": "raw", "file": {"test": {"driver": "IMGFMT", "file": {"inj= ect-error": [{"event": "l1_update"}], "image": {"driver": "file", "filename= ": "TEST_DIR/t.IMGFMT"}, "driver": "blkdebug"}}, "driver": "blkverify", "ra= w": {"driver": "file", "filename": "TEST_DIR/t.IMGFMT.compare"}}} =20 =3D=3D=3D Testing plain filename for blkdebug =3D=3D=3D =20 diff --git a/tests/qemu-iotests/110.out b/tests/qemu-iotests/110.out index 46e6a60510..cb055ed39c 100644 --- a/tests/qemu-iotests/110.out +++ b/tests/qemu-iotests/110.out @@ -11,7 +11,7 @@ backing file: t.IMGFMT.base (actual path: TEST_DIR/t.IMGF= MT.base) =20 =3D=3D=3D Non-reconstructable filename =3D=3D=3D =20 -image: json:{"driver": "IMGFMT", "file": {"set-state.0.event": "read_aio",= "image": {"driver": "file", "filename": "TEST_DIR/t.IMGFMT"}, "driver": "b= lkdebug", "set-state.0.new_state": 42}} +image: json:{"driver": "IMGFMT", "file": {"set-state": [{"new_state": 42, = "event": "read_aio"}], "image": {"driver": "file", "filename": "TEST_DIR/t.= IMGFMT"}, "driver": "blkdebug"}} file format: IMGFMT virtual size: 64M (67108864 bytes) backing file: t.IMGFMT.base (actual path: TEST_DIR/t.IMGFMT.base) diff --git a/tests/qemu-iotests/198.out b/tests/qemu-iotests/198.out index adb805cce9..a3cb530a0c 100644 --- a/tests/qemu-iotests/198.out +++ b/tests/qemu-iotests/198.out @@ -32,7 +32,7 @@ read 16777216/16777216 bytes at offset 0 16 MiB, X ops; XX:XX:XX.X (XXX YYY/sec and XXX ops/sec) =20 =3D=3D checking image base =3D=3D -image: json:{"encrypt.key-secret": "sec0", "driver": "IMGFMT", "file": {"d= river": "file", "filename": "TEST_DIR/t.IMGFMT.base"}} +image: json:{"driver": "IMGFMT", "encrypt": {"format": "auto", "key-secret= ": "sec0"}, "file": {"driver": "file", "filename": "TEST_DIR/t.IMGFMT.base"= }} file format: IMGFMT virtual size: 16M (16777216 bytes) Format specific information: @@ -74,7 +74,7 @@ Format specific information: master key iters: 1024 =20 =3D=3D checking image layer =3D=3D -image: json:{"encrypt.key-secret": "sec1", "driver": "IMGFMT", "file": {"d= river": "file", "filename": "TEST_DIR/t.IMGFMT"}} +image: json:{"driver": "IMGFMT", "encrypt": {"format": "auto", "key-secret= ": "sec1"}, "file": {"driver": "file", "filename": "TEST_DIR/t.IMGFMT"}} file format: IMGFMT virtual size: 16M (16777216 bytes) backing file: TEST_DIR/t.IMGFMT.base diff --git a/tests/qemu-iotests/207.out b/tests/qemu-iotests/207.out index 45ac7c2a8f..b7d285a1e5 100644 --- a/tests/qemu-iotests/207.out +++ b/tests/qemu-iotests/207.out @@ -5,7 +5,7 @@ {"execute": "job-dismiss", "arguments": {"id": "job0"}} {"return": {}} =20 -image: json:{"driver": "IMGFMT", "file": {"server.host": "127.0.0.1", "ser= ver.port": "22", "driver": "ssh", "path": "TEST_IMG"}} +image: json:{"driver": "IMGFMT", "file": {"driver": "ssh", "path": "TEST_I= MG", "server": {"port": "22", "host": "127.0.0.1"}}} file format: IMGFMT virtual size: 4.0M (4194304 bytes) =20 @@ -21,7 +21,7 @@ virtual size: 4.0M (4194304 bytes) {"execute": "job-dismiss", "arguments": {"id": "job0"}} {"return": {}} =20 -image: json:{"driver": "IMGFMT", "file": {"server.host": "127.0.0.1", "ser= ver.port": "22", "driver": "ssh", "path": "TEST_IMG"}} +image: json:{"driver": "IMGFMT", "file": {"driver": "ssh", "path": "TEST_I= MG", "server": {"port": "22", "host": "127.0.0.1"}}} file format: IMGFMT virtual size: 8.0M (8388608 bytes) =20 @@ -30,7 +30,7 @@ virtual size: 8.0M (8388608 bytes) {"execute": "job-dismiss", "arguments": {"id": "job0"}} {"return": {}} =20 -image: json:{"driver": "IMGFMT", "file": {"server.host": "127.0.0.1", "ser= ver.port": "22", "driver": "ssh", "path": "TEST_IMG"}} +image: json:{"driver": "IMGFMT", "file": {"driver": "ssh", "path": "TEST_I= MG", "server": {"port": "22", "host": "127.0.0.1"}}} file format: IMGFMT virtual size: 4.0M (4194304 bytes) =20 @@ -45,7 +45,7 @@ Job failed: remote host key does not match host_key_check= 'wrong' {"execute": "job-dismiss", "arguments": {"id": "job0"}} {"return": {}} =20 -image: json:{"driver": "IMGFMT", "file": {"server.host": "127.0.0.1", "ser= ver.port": "22", "driver": "ssh", "path": "TEST_IMG"}} +image: json:{"driver": "IMGFMT", "file": {"driver": "ssh", "path": "TEST_I= MG", "server": {"port": "22", "host": "127.0.0.1"}}} file format: IMGFMT virtual size: 8.0M (8388608 bytes) =20 @@ -60,7 +60,7 @@ Job failed: remote host key does not match host_key_check= 'wrong' {"execute": "job-dismiss", "arguments": {"id": "job0"}} {"return": {}} =20 -image: json:{"driver": "IMGFMT", "file": {"server.host": "127.0.0.1", "ser= ver.port": "22", "driver": "ssh", "path": "TEST_IMG"}} +image: json:{"driver": "IMGFMT", "file": {"driver": "ssh", "path": "TEST_I= MG", "server": {"port": "22", "host": "127.0.0.1"}}} file format: IMGFMT virtual size: 4.0M (4194304 bytes) =20 --=20 2.20.1 From nobody Thu Dec 18 23:00:21 2025 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.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 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=redhat.com Return-Path: Received: from lists.gnu.org (209.51.188.17 [209.51.188.17]) by mx.zohomail.com with SMTPS id 1549483194823392.0920894723097; Wed, 6 Feb 2019 11:59:54 -0800 (PST) Received: from localhost ([127.0.0.1]:57817 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1grTMK-000311-QX for importer@patchew.org; Wed, 06 Feb 2019 14:59:48 -0500 Received: from eggs.gnu.org ([209.51.188.92]:38359) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1grTIw-0000I3-SM for qemu-devel@nongnu.org; Wed, 06 Feb 2019 14:56:19 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1grTIv-00085F-Ha for qemu-devel@nongnu.org; Wed, 06 Feb 2019 14:56:18 -0500 Received: from mx1.redhat.com ([209.132.183.28]:41708) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1grTIq-00080S-9c; Wed, 06 Feb 2019 14:56:12 -0500 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 mx1.redhat.com (Postfix) with ESMTPS id 7D3D0C058CA8; Wed, 6 Feb 2019 19:56:11 +0000 (UTC) Received: from localhost (unknown [10.40.205.248]) by smtp.corp.redhat.com (Postfix) with ESMTPS id ED28B1851A; Wed, 6 Feb 2019 19:56:10 +0000 (UTC) From: Max Reitz To: qemu-block@nongnu.org Date: Wed, 6 Feb 2019 20:55:50 +0100 Message-Id: <20190206195551.28893-8-mreitz@redhat.com> In-Reply-To: <20190206195551.28893-1-mreitz@redhat.com> References: <20190206195551.28893-1-mreitz@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.84 on 10.5.11.23 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.32]); Wed, 06 Feb 2019 19:56:11 +0000 (UTC) Content-Transfer-Encoding: quoted-printable X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 209.132.183.28 Subject: [Qemu-devel] [PATCH v3 7/8] iotests: Test internal option typing X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Kevin Wolf , qemu-devel@nongnu.org, Michael Roth , Markus Armbruster , Max Reitz Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" Content-Type: text/plain; charset="utf-8" It would be nice if qemu used the correct types for blockdev options internally, even if the user specified string values (either through -drive or by being not so nice and using json:{} with string values). This patch adds a test verifying that fact. Signed-off-by: Max Reitz Reviewed-by: Eric Blake --- tests/qemu-iotests/089 | 25 +++++++++++++++++++++++++ tests/qemu-iotests/089.out | 9 +++++++++ 2 files changed, 34 insertions(+) diff --git a/tests/qemu-iotests/089 b/tests/qemu-iotests/089 index 3165d79e2a..0ac1e1fbf5 100755 --- a/tests/qemu-iotests/089 +++ b/tests/qemu-iotests/089 @@ -35,6 +35,7 @@ trap "_cleanup; exit \$status" 0 1 2 3 15 # get standard environment, filters and checks . ./common.rc . ./common.filter +. ./common.qemu =20 _supported_fmt qcow2 _supported_proto file @@ -144,6 +145,30 @@ $QEMU_IO -c "open -o driver=3Dqcow2 json:{\"file.filen= ame\":\"$TEST_IMG\"}" \ $QEMU_IO -c "open -o driver=3Dqcow2 json:{\"driver\":\"raw\",\"file.filena= me\":\"$TEST_IMG\"}" \ -c "info" 2>&1 | _filter_img_info =20 +echo +echo "=3D=3D=3D Testing option typing =3D=3D=3D" +echo + +# json:{} accepts both strings and correctly typed values (even mixed, +# although we probably do not want to support that...), but when +# creating a json:{} filename, it should be correctly typed. +# Therefore, both of these should make the "size" value an integer. + +TEST_IMG=3D"json:{'driver': 'null-co', 'size': 42 }" _img_info | grep '^i= mage' +TEST_IMG=3D"json:{'driver': 'null-co', 'size': '42'}" _img_info | grep '^i= mage' + +echo + +# This should even work when some driver abuses bs->options to store +# non-QAPI options (and the given -drive options are not complete) +# (Watch for whether file.align appears as an int or a string) +qemu_comm_method=3Dmonitor _launch_qemu \ + -drive if=3Dnone,id=3Ddrv0,node-name=3Dnode0,format=3Draw,file=3Dblkde= bug::null-co://,file.align=3D512 + +_send_qemu_cmd $QEMU_HANDLE 'info block' 'json:' + +_cleanup_qemu + =20 # success, all done echo "*** done" diff --git a/tests/qemu-iotests/089.out b/tests/qemu-iotests/089.out index 89e3e4340a..35ffbabe77 100644 --- a/tests/qemu-iotests/089.out +++ b/tests/qemu-iotests/089.out @@ -49,4 +49,13 @@ vm state offset: 512 MiB format name: IMGFMT cluster size: 64 KiB vm state offset: 512 MiB + +=3D=3D=3D Testing option typing =3D=3D=3D + +image: json:{"driver": "null-co", "size": 42} +image: json:{"driver": "null-co", "size": 42} + +QEMU X.Y.Z monitor - type 'help' for more information +(qemu) info block +drv0 (node0): json:{"driver": "raw", "file": {"image": {"driver": "null-co= "}, "driver": "blkdebug", "align": 512}} (raw) *** done --=20 2.20.1 From nobody Thu Dec 18 23:00:21 2025 Delivered-To: importer@patchew.org Received-SPF: temperror (zoho.com: Error in retrieving data from DNS) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; spf=temperror (zoho.com: Error in retrieving data from DNS) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=redhat.com Return-Path: Received: from lists.gnu.org (209.51.188.17 [209.51.188.17]) by mx.zohomail.com with SMTPS id 1549483554877338.8218276557782; Wed, 6 Feb 2019 12:05:54 -0800 (PST) Received: from localhost ([127.0.0.1]:57940 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1grTS3-00072F-PS for importer@patchew.org; Wed, 06 Feb 2019 15:05:43 -0500 Received: from eggs.gnu.org ([209.51.188.92]:38381) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1grTIz-0000Kn-6c for qemu-devel@nongnu.org; Wed, 06 Feb 2019 14:56:22 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1grTIy-00086s-31 for qemu-devel@nongnu.org; Wed, 06 Feb 2019 14:56:21 -0500 Received: from mx1.redhat.com ([209.132.183.28]:51760) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1grTIt-00081Q-Q8; Wed, 06 Feb 2019 14:56:16 -0500 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 8389F89AD4; Wed, 6 Feb 2019 19:56:14 +0000 (UTC) Received: from localhost (unknown [10.40.205.248]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 010D187DB; Wed, 6 Feb 2019 19:56:13 +0000 (UTC) From: Max Reitz To: qemu-block@nongnu.org Date: Wed, 6 Feb 2019 20:55:51 +0100 Message-Id: <20190206195551.28893-9-mreitz@redhat.com> In-Reply-To: <20190206195551.28893-1-mreitz@redhat.com> References: <20190206195551.28893-1-mreitz@redhat.com> MIME-Version: 1.0 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.26]); Wed, 06 Feb 2019 19:56:14 +0000 (UTC) Content-Transfer-Encoding: quoted-printable X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 209.132.183.28 Subject: [Qemu-devel] [PATCH v3 8/8] iotests: qcow2's encrypt.format is now optional X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Kevin Wolf , qemu-devel@nongnu.org, Michael Roth , Markus Armbruster , Max Reitz Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" Content-Type: text/plain; charset="utf-8" Remove the encrypt.format option from the two blockdev-add test cases for encrypted qcow2 images in 087 to explicitly test that this parameter is now optional. Additionally, show that explicitly specifying encrypt.format=3Dauto works just as well, the same for specifying the correct format (encrypt.format=3Dluks here), and that specifying the wrong format (encrypt.format=3Daes) results in an error. While touching this test case, reduce the LUKS iteration time to 10 so the test stays reasonably fast. Signed-off-by: Max Reitz Reviewed-by: Daniel P. Berrang=C3=A9 Reviewed-by: Eric Blake --- tests/qemu-iotests/087 | 65 +++++++++++++++++++++++--------------- tests/qemu-iotests/087.out | 26 ++++++++++++++- 2 files changed, 64 insertions(+), 27 deletions(-) diff --git a/tests/qemu-iotests/087 b/tests/qemu-iotests/087 index f625887082..78c953ec50 100755 --- a/tests/qemu-iotests/087 +++ b/tests/qemu-iotests/087 @@ -149,7 +149,6 @@ run_qemu <