Received: from eggs.gnu.org ([2001:4830:134:3::10]:52444) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1WFJXT-0008Er-Sk for qemu-devel@nongnu.org; Mon, 17 Feb 2014 03:27:01 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1WFJXN-0007sw-T7 for qemu-devel@nongnu.org; Mon, 17 Feb 2014 03:26:55 -0500 Received: from mx1.redhat.com ([209.132.183.28]:50191) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1WFJXN-0007sV-Ke for qemu-devel@nongnu.org; Mon, 17 Feb 2014 03:26:49 -0500 Date: Mon, 17 Feb 2014 16:26:44 +0800 From: Amos Kong Message-ID: <20140217082644.GB21308@amosk.info> References: <1390881230-14033-1-git-send-email-akong@redhat.com> <1390881230-14033-4-git-send-email-akong@redhat.com> <877g91svpi.fsf@blackfin.pond.sub.org> MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Disposition: inline In-Reply-To: <877g91svpi.fsf@blackfin.pond.sub.org> Content-Transfer-Encoding: quoted-printable Subject: Re: [Qemu-devel] [PATCH 3/5] query-command-line-options: query all the options in qemu-options.hx List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: Markus Armbruster Cc: jyang@redhat.com, laine@redhat.com, libvir-list@redhat.com, qemu-devel@nongnu.org, rjones@redhat.com, anthony@codemonkey.ws, pbonzini@redhat.com, lcapitulino@redhat.com On Tue, Feb 11, 2014 at 01:03:05PM +0100, Markus Armbruster wrote: > Amos Kong writes: >=20 > > vm_config_groups[] contain the options which have parameter, but some > > legcy options haven't been added to vm_config_groups[]. > > > > All the options can be found in qemu-options.hx, this patch used two > > new marcos to generate two tables, we can check if the option name is > > valid and if the option has arguments. > > > > This patch also try to visit all the options in option_names[], then > > we won't lost the legacy options that weren't added to vm_config_grou= ps[]. > > The options have no arguments will also be returned (eg: -enable-fips= ) > > > > Signed-off-by: Amos Kong > > --- > > util/qemu-config.c | 41 +++++++++++++++++++++++++++++++++++------ > > 1 file changed, 35 insertions(+), 6 deletions(-) > > > > diff --git a/util/qemu-config.c b/util/qemu-config.c > > index d624d92..de233d8 100644 > > --- a/util/qemu-config.c > > +++ b/util/qemu-config.c > > @@ -78,6 +78,17 @@ static CommandLineParameterInfoList *get_param_inf= olist(const QemuOptDesc *desc) > > return param_list; > > } > > =20 > > +static int get_group_index(const char *name) > > +{ > > + int i; > > + > > + for (i =3D 0; vm_config_groups[i] !=3D NULL; i++) { > > + if (!strcmp(vm_config_groups[i]->name, name)) { > > + return i; > > + } > > + } > > + return -1; > > +} > > /* remove repeated entry from the info list */ > > static void cleanup_infolist(CommandLineParameterInfoList *head) > > { > > @@ -139,16 +150,34 @@ CommandLineOptionInfoList *qmp_query_command_li= ne_options(bool has_option, > > CommandLineOptionInfo *info; > > int i; > > =20 > > - for (i =3D 0; vm_config_groups[i] !=3D NULL; i++) { > > - if (!has_option || !strcmp(option, vm_config_groups[i]->name= )) { > > + char const *option_names[] =3D { > > +#define QEMU_OPTIONS_GENERATE_NAME > > +#include "qemu-options-wrapper.h" > > + }; > > + > > + char const *option_hasargs[] =3D { > > +#define QEMU_OPTIONS_GENERATE_HASARG > > +#include "qemu-options-wrapper.h" > > + }; >=20 > Both tables are technically redundant. The same information is already > in vl.c's qemu_options[]. That one also includes -h, which the tables > here miss. >=20 > Duplicating tables can be okay, but I suspect using the existing one > would be simpler. Have you tried? Right, it's redundant work. =20 > > + > > + for (i =3D 0; i < sizeof(option_names) / sizeof(char *); i++) { > > + if (!has_option || !strcmp(option, option_names[i])) { > > info =3D g_malloc0(sizeof(*info)); > > - info->option =3D g_strdup(vm_config_groups[i]->name); > > - if (!strcmp("drive", vm_config_groups[i]->name)) { > > + info->option =3D g_strdup(option_names[i]); > > + > > + int idx =3D get_group_index(option_names[i]); >=20 > Variable declaration follows statement. Please declare int idx at the > beginning of a block. I'd declare it right at the beginning, together > with int i. =20 Ok > > + > > + if (!strcmp("HAS_ARG", option_hasargs[i])) { > > + info->has_parameters =3D true; > > + } >=20 > qemu/util/qemu-config.c:171:21: error: =E2=80=98CommandLineOptionInfo=E2= =80=99 has no member named =E2=80=98has_parameters=E2=80=99 >=20 > Did you forget to include a schema change? Schema change was wrongly included to patch 5/5. =20 > Awfully roundabout way to test whether the option takes an argument. > Here's the other part, from PATCH 2/5: >=20 > +#define DEF(option, opt_arg, opt_enum, opt_help, arch_mask) \ > + stringify(opt_arg), >=20 > Please do it more like vl.c: >=20 > #define HAS_ARG true > bool option_has_arg[] =3D { > #define QEMU_OPTIONS_GENERATE_HASARG > #include "qemu-options-wrapper.h" > } I touched an error in the past, so convert the has_arg to string. | In file included from util/qemu-config.c:160:0: | ./qemu-options.def: In function =E2=80=98qmp_query_command_line_options= =E2=80=99: | ./qemu-options.def:10:16: error: =E2=80=98HAS_ARG=E2=80=99 undeclared (= first use in this function) | DEF("machine", HAS_ARG, QEMU_OPTION_machine, \ | ^ | ./qemu-options-wrapper.h:32:5: note: in definition of macro =E2=80=98DE= F=E2=80=99 | opt_arg, | ^ | ./qemu-options.def:10:16: note: each undeclared identifier is reported = only once for each function it appears in | DEF("machine", HAS_ARG, QEMU_OPTION_machine, \ | ^ | ./qemu-options-wrapper.h:32:5: note: in definition of macro =E2=80=98DE= F=E2=80=99 | opt_arg, | ^ This problem can be solved by defining HAS_ARG in qemu-config.c as in vl.= c + #define HAS_ARG 0x0001 =20 > Then you can simply test option_has_arg[i]. >=20 > Or reuse vl.c's table. OK. =20 > > + > > + if (!strcmp("drive", option_names[i])) { > > info->parameters =3D get_drive_infolist(); > > - } else { > > + } else if (idx >=3D 0) { > > info->parameters =3D > > - get_param_infolist(vm_config_groups[i]->desc); > > + get_param_infolist(vm_config_groups[idx]->desc); > > } > > + > > entry =3D g_malloc0(sizeof(*entry)); > > entry->value =3D info; > > entry->next =3D conf_list; --=20 Amos.