Received: from eggs.gnu.org ([2001:4830:134:3::10]:49979) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1YVgVg-0000RM-Ax for qemu-devel@nongnu.org; Wed, 11 Mar 2015 09:17:17 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1YVgVZ-0005Bk-UT for qemu-devel@nongnu.org; Wed, 11 Mar 2015 09:17:16 -0400 Received: from mx1.redhat.com ([209.132.183.28]:39938) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1YVgVZ-0005BR-No for qemu-devel@nongnu.org; Wed, 11 Mar 2015 09:17:09 -0400 Date: Wed, 11 Mar 2015 14:17:04 +0100 From: Kevin Wolf Message-ID: <20150311131704.GJ6628@noname.str.redhat.com> References: <20150309175036.GK1832@HEDWIG.INI.CMU.EDU> <877fup1c0m.fsf@blackfin.pond.sub.org> <20150310173504.GM1832@HEDWIG.INI.CMU.EDU> <87oao0rmxp.fsf@blackfin.pond.sub.org> <20150311115940.GF6628@noname.str.redhat.com> <20150311124045.GP1832@HEDWIG.INI.CMU.EDU> <20150311125300.GQ1832@HEDWIG.INI.CMU.EDU> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20150311125300.GQ1832@HEDWIG.INI.CMU.EDU> Subject: Re: [Qemu-devel] help parsing qemu options List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: "Gabriel L. Somlo" Cc: Markus Armbruster , qemu-devel@nongnu.org Am 11.03.2015 um 13:53 hat Gabriel L. Somlo geschrieben: > On Wed, Mar 11, 2015 at 08:40:46AM -0400, Gabriel L. Somlo wrote: > > On Wed, Mar 11, 2015 at 12:59:40PM +0100, Kevin Wolf wrote: > > > > > > def_value_str exists in the current codebase, and it seems to take > > > precedence when a different default is specified by the caller. > > > > So I've now added .def_value_str fields: > > > > static QemuOptsList qemu_foo_opts = { > > .name = "foo", > > .head = QTAILQ_HEAD_INITIALIZER(qemu_foo_opts.head), > > .desc = { > > { > > .name = "name", > > .type = QEMU_OPT_STRING, > > .def_value_str = "abc", > > }, { > > .name = "file", > > .type = QEMU_OPT_STRING, > > .def_value_str = "xyz", > > }, > > { /* end of list */ } > > }, > > }; > > > > but "-foo name,file" still results in qemu_opt_get(opts, "name") > > returning "on", rather than "abc". Is that a bug, or am I missing > > something, or doing something wrong ? > > Specifically, in qemu_opt_get() (in util/qemu-option.c:311) > desc->def_value_str is only used if qemu_opt_find() returns NULL, > which in my case does NOT happen ("on" is returned instead). > > That, in turn, probably happens because opts_do_parse() > (in util/qemu-options.c:776) assumes that "option without value" > is "probably a flag" :) > > Not sure we'd want to mess with that assumption, but that most likely > means I don't get to use .def_value_str the way I thought I could :) Indeed, setting a default value alone won't solve your problem. It might help you with implementing the solution, though, which would involve something like changing the meaning of valueless options to taking the default and using "on" as the default for boolean values. I haven't thought thoroughly about QemuOptsLists yet which accept any option. They may still be a reason for the approach outlined above to fail. Kevin