Received: from eggs.gnu.org ([2001:4830:134:3::10]:47705) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1YcAM4-0005ao-P1 for qemu-devel@nongnu.org; Sun, 29 Mar 2015 06:22:10 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1YcAM0-0004eO-OK for qemu-devel@nongnu.org; Sun, 29 Mar 2015 06:22:08 -0400 Received: from mx1.redhat.com ([209.132.183.28]:55539) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1YcAM0-0004eI-HF for qemu-devel@nongnu.org; Sun, 29 Mar 2015 06:22:04 -0400 From: Markus Armbruster References: <1427227433-5030-1-git-send-email-eblake@redhat.com> <1427227433-5030-23-git-send-email-eblake@redhat.com> <87mw2ybefw.fsf@blackfin.pond.sub.org> <5515BD96.8010202@redhat.com> Date: Sun, 29 Mar 2015 12:22:01 +0200 In-Reply-To: <5515BD96.8010202@redhat.com> (Eric Blake's message of "Fri, 27 Mar 2015 14:29:10 -0600") Message-ID: <87oanc3xyu.fsf@blackfin.pond.sub.org> MIME-Version: 1.0 Content-Type: text/plain Subject: Re: [Qemu-devel] [PATCH v5 22/28] qapi: Whitelist commands that don't return dictionary List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: Eric Blake Cc: kwolf@redhat.com, famz@redhat.com, qemu-devel@nongnu.org, wenchaoqemu@gmail.com, lcapitulino@redhat.com Eric Blake writes: > On 03/27/2015 10:19 AM, Markus Armbruster wrote: >> Eric Blake writes: >> >>> ...or an array of dictionaries. Although we have to cater to >>> existing commands, returning a non-dictionary means the command >>> is not extensible (no new name/value pairs can be added if more >>> information must be returned in parallel). By making the >>> whitelist explicit, any new command that falls foul of this >>> practice will have to be self-documenting, which will encourage >>> developers to either justify the action or rework the design to >>> use a dictionary after all. >>> >>> Signed-off-by: Eric Blake >>> --- > > >> >> Thinking on introspection, I started to wonder whether there's actually >> a command returning a union, yet. So I applied the appended stupid >> patch on top, and found the following commands returning (list of) >> non-struct type: >> >> * qapi-schema.json: >> >> 'ringbuf-read' built-in type 'str' >> 'human-monitor-command' built-in type 'str' >> 'query-migrate-cache-size' built-in type 'int' >> 'query-tpm-models' enum type 'TpmModel' > > More precisely, "array of enum type 'TpmModel'" (or "list", depending on > whether we go with JSON array/object terminology, or QObject dict/list). > I wonder if it is worth trying to tweak the error message to more > precisely track when I strip away the [] earlier in check_type to still > report sane messages about 'array of ...' if a later check fails. I figure the error message is understandable enough as is. But if it improving it would be easy, then why not. Could be done on top. >> 'query-tpm-types' enum type 'TpmType' >> 'query-memory-devices' union type 'MemoryDeviceInfo' >> >> * qga/qapi-schema.json: >> >> 'guest-sync-delimited' built-in type 'int' >> 'guest-sync' built-in type 'int' >> 'guest-get-time' built-in type 'int' >> 'guest-file-open' built-in type 'int' >> 'guest-fsfreeze-status' enum type 'GuestFsfreezeStatus' >> 'guest-fsfreeze-freeze' built-in type 'int' >> 'guest-fsfreeze-freeze-list' built-in type 'int' >> 'guest-fsfreeze-thaw' built-in type 'int' >> 'guest-set-vcpus' built-in type 'int' > > Good - your patch found all of my whitelists, plus... > >> >> The sole example for union is 'MemoryDeviceInfo'. It has one case %-} > > Yeah, MemoryDeviceInfo as a union currently has only one type, but it > was done that way in case we add other memory devices. So it was > actually quite forward-thinking. > > ...one additional thing. But returning (an array of) a union should be > okay (it is a dictionary, and therefore extensible); this patch was only > about flagging non-dictionaries. > > [side note: again, my idea of renaming 'type' into 'struct' in the .json > files would make it easier to talk about "complex types" as the set of > "struct" and "union" types, rather than the current confusion of > deciding if "type" means all meta-types or just struct meta-types.] Yes.