Received: from eggs.gnu.org ([2001:4830:134:3::10]:59457) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1aQzZa-0004JF-50 for qemu-devel@nongnu.org; Wed, 03 Feb 2016 10:42:26 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1aQzZW-0000zD-TF for qemu-devel@nongnu.org; Wed, 03 Feb 2016 10:42:26 -0500 Received: from mx1.redhat.com ([209.132.183.28]:39559) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1aQzZW-0000ym-MF for qemu-devel@nongnu.org; Wed, 03 Feb 2016 10:42:22 -0500 From: Markus Armbruster References: <1453963872-13549-1-git-send-email-vsementsov@virtuozzo.com> <1453963872-13549-3-git-send-email-vsementsov@virtuozzo.com> <56B129CC.4010005@redhat.com> <56B1EBCA.30201@virtuozzo.com> <56B2195A.4040503@redhat.com> Date: Wed, 03 Feb 2016 16:42:19 +0100 In-Reply-To: <56B2195A.4040503@redhat.com> (Eric Blake's message of "Wed, 3 Feb 2016 08:14:34 -0700") Message-ID: <87wpqln6lg.fsf@blackfin.pond.sub.org> MIME-Version: 1.0 Content-Type: text/plain Subject: Re: [Qemu-devel] [PATCH 2/3] pcdimm: add 'type' field to PCDIMMDeviceInfo List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: Eric Blake Cc: Vladimir Sementsov-Ogievskiy , Xiao Guangrong , "Michael S. Tsirkin" , qemu-devel@nongnu.org, Stefan Hajnoczi , "Denis V. Lunev" , Igor Mammedov Eric Blake writes: > On 02/03/2016 05:00 AM, Vladimir Sementsov-Ogievskiy wrote: > >>>> +# @type: device type: 'pc-dimm' or 'nvdimm' (since 2.6) >>>> +# >>>> # Since: 2.1 >>>> ## >>>> { 'struct': 'PCDIMMDeviceInfo', >>>> @@ -3934,7 +3936,8 @@ >>>> 'node': 'int', >>>> 'memdev': 'str', >>>> 'hotplugged': 'bool', >>>> - 'hotpluggable': 'bool' >>>> + 'hotpluggable': 'bool', >>>> + 'type': 'str' >>> No. Since it is a finite set of values (just two possible), you should >>> be using an enum here rather than open-coded 'str'. Something like: >>> >>> { 'enum': 'DIMMType', 'data': [ 'pc-dimm', 'nvdimm' ] } >>> >> >> Are you sure? This is only output Info, so user will never "set" this >> field. Also, qemu type system (as I understand) is based on string >> names. object_dynamic_cast and other functions uses "const char >> *typename". This enum will be out of qemu type system and we will have >> to sync it.. Is there already some practice of translating string >> typenames to enum values? > > Yes, exposing a finite set of strings as an enum is ideal for the user > interface, even if we carry string values instead of enum values in > other places in the code. QAPI already includes convenience methods for > translating between strings and enum values (EnumName_lookup[] to go > from int to string, and qapi_enum_parse() to reverse from string back to > enum). Well, it's not an arbitrary set of strings, it the set of names of concrete subtypes of "pc-dimm". See also my reply to this patch (Message-ID: <8737tbjfp9.fsf@blackfin.pond.sub.org>), which also shows how to introspect this set. Doesn't mean we must not create an enum for this set. If we do, we get to map from type name to enum value in qmp_pc_dimm_device_list(). Begs the question what to do when we run into a type name we don't know to map. The deeper question is whether we want to duplicate sets of QOM type names as QAPI enums in general. I'm leaning towards "we don't", but I'm happy to hear arguments for doing it.