From: Amos Kong <akong@redhat.com>
To: Markus Armbruster <armbru@redhat.com>
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
Subject: Re: [Qemu-devel] [PATCH 3/5] query-command-line-options: query all the options in qemu-options.hx
Date: Mon, 17 Feb 2014 16:26:44 +0800 [thread overview]
Message-ID: <20140217082644.GB21308@amosk.info> (raw)
In-Reply-To: <877g91svpi.fsf@blackfin.pond.sub.org>
On Tue, Feb 11, 2014 at 01:03:05PM +0100, Markus Armbruster wrote:
> Amos Kong <akong@redhat.com> writes:
>
> > 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_groups[].
> > The options have no arguments will also be returned (eg: -enable-fips)
> >
> > Signed-off-by: Amos Kong <akong@redhat.com>
> > ---
> > 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_infolist(const QemuOptDesc *desc)
> > return param_list;
> > }
> >
> > +static int get_group_index(const char *name)
> > +{
> > + int i;
> > +
> > + for (i = 0; vm_config_groups[i] != 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_line_options(bool has_option,
> > CommandLineOptionInfo *info;
> > int i;
> >
> > - for (i = 0; vm_config_groups[i] != NULL; i++) {
> > - if (!has_option || !strcmp(option, vm_config_groups[i]->name)) {
> > + char const *option_names[] = {
> > +#define QEMU_OPTIONS_GENERATE_NAME
> > +#include "qemu-options-wrapper.h"
> > + };
> > +
> > + char const *option_hasargs[] = {
> > +#define QEMU_OPTIONS_GENERATE_HASARG
> > +#include "qemu-options-wrapper.h"
> > + };
>
> 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.
>
> Duplicating tables can be okay, but I suspect using the existing one
> would be simpler. Have you tried?
Right, it's redundant work.
> > +
> > + for (i = 0; i < sizeof(option_names) / sizeof(char *); i++) {
> > + if (!has_option || !strcmp(option, option_names[i])) {
> > info = g_malloc0(sizeof(*info));
> > - info->option = g_strdup(vm_config_groups[i]->name);
> > - if (!strcmp("drive", vm_config_groups[i]->name)) {
> > + info->option = g_strdup(option_names[i]);
> > +
> > + int idx = get_group_index(option_names[i]);
>
> 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.
Ok
> > +
> > + if (!strcmp("HAS_ARG", option_hasargs[i])) {
> > + info->has_parameters = true;
> > + }
>
> qemu/util/qemu-config.c:171:21: error: ‘CommandLineOptionInfo’ has no member named ‘has_parameters’
>
> Did you forget to include a schema change?
Schema change was wrongly included to patch 5/5.
> Awfully roundabout way to test whether the option takes an argument.
> Here's the other part, from PATCH 2/5:
>
> +#define DEF(option, opt_arg, opt_enum, opt_help, arch_mask) \
> + stringify(opt_arg),
>
> Please do it more like vl.c:
>
> #define HAS_ARG true
> bool option_has_arg[] = {
> #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 ‘qmp_query_command_line_options’:
| ./qemu-options.def:10:16: error: ‘HAS_ARG’ undeclared (first use in this function)
| DEF("machine", HAS_ARG, QEMU_OPTION_machine, \
| ^
| ./qemu-options-wrapper.h:32:5: note: in definition of macro ‘DEF’
| 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 ‘DEF’
| opt_arg,
| ^
This problem can be solved by defining HAS_ARG in qemu-config.c as in vl.c
+ #define HAS_ARG 0x0001
> Then you can simply test option_has_arg[i].
>
> Or reuse vl.c's table.
OK.
> > +
> > + if (!strcmp("drive", option_names[i])) {
> > info->parameters = get_drive_infolist();
> > - } else {
> > + } else if (idx >= 0) {
> > info->parameters =
> > - get_param_infolist(vm_config_groups[i]->desc);
> > + get_param_infolist(vm_config_groups[idx]->desc);
> > }
> > +
> > entry = g_malloc0(sizeof(*entry));
> > entry->value = info;
> > entry->next = conf_list;
--
Amos.
next prev parent reply other threads:[~2014-02-17 8:27 UTC|newest]
Thread overview: 20+ messages / expand[flat|nested] mbox.gz Atom feed top
2014-01-28 3:53 [Qemu-devel] [PATCH 0/5] fix query-command-line-options Amos Kong
2014-01-28 3:53 ` [Qemu-devel] [PATCH 1/5] qmp: rename query_option_descs() to get_param_infolist() Amos Kong
2014-02-12 20:33 ` Eric Blake
2014-01-28 3:53 ` [Qemu-devel] [PATCH 2/5] introduce two marcos to dump the options info Amos Kong
2014-02-11 10:55 ` Markus Armbruster
2014-02-12 20:37 ` Eric Blake
2014-01-28 3:53 ` [Qemu-devel] [PATCH 3/5] query-command-line-options: query all the options in qemu-options.hx Amos Kong
2014-02-11 12:03 ` Markus Armbruster
2014-02-17 8:26 ` Amos Kong [this message]
2014-02-12 20:39 ` Eric Blake
2014-01-28 3:53 ` [Qemu-devel] [PATCH 4/5] introduce QEMU_OPTIONS_GENERATE_HELPMSG Amos Kong
2014-02-11 12:03 ` Markus Armbruster
2014-02-12 20:41 ` Eric Blake
2014-01-28 3:53 ` [Qemu-devel] [PATCH 5/5] query-command-line-options: return help message for legacy options Amos Kong
2014-02-11 12:19 ` Markus Armbruster
2014-02-12 20:48 ` Eric Blake
2014-02-17 8:49 ` Amos Kong
2014-02-12 21:00 ` Eric Blake
2014-02-17 8:56 ` Amos Kong
2014-02-10 20:26 ` [Qemu-devel] [PATCH 0/5] fix query-command-line-options Luiz Capitulino
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20140217082644.GB21308@amosk.info \
--to=akong@redhat.com \
--cc=anthony@codemonkey.ws \
--cc=armbru@redhat.com \
--cc=jyang@redhat.com \
--cc=laine@redhat.com \
--cc=lcapitulino@redhat.com \
--cc=libvir-list@redhat.com \
--cc=pbonzini@redhat.com \
--cc=qemu-devel@nongnu.org \
--cc=rjones@redhat.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).