All of lore.kernel.org
 help / color / mirror / Atom feed
From: Markus Armbruster <armbru@redhat.com>
To: Paolo Bonzini <pbonzini@redhat.com>
Cc: qemu-devel@nongnu.org
Subject: Re: [PATCH v2 2/6] qemu-option: pass QemuOptsList to opts_accepts_any
Date: Mon, 09 Nov 2020 16:27:55 +0100	[thread overview]
Message-ID: <871rh27dok.fsf@dusky.pond.sub.org> (raw)
In-Reply-To: <20201109133931.979563-3-pbonzini@redhat.com> (Paolo Bonzini's message of "Mon, 9 Nov 2020 08:39:27 -0500")

Paolo Bonzini <pbonzini@redhat.com> writes:

> A QemuOptsList can be of one of two kinds: either it is pre-validated, or
> it accepts any key and validation happens somewhere else (typically in
> a Visitor or against a list of QOM properties).

For a value of "typically" :)

>                                                  opts_accepts_any
> returns true if a QemuOpts instance was created from a QemuOptsList of
> the latter kind, but there is no function to do the check on a QemuOptsList.
>
> We will need it in the next patch; since almost all callers of
> opts_accepts_any use opts->list anyway,

I'm not sure I get the "since" part.  Peeking ahead...  you're lifting
the first -> into the callers, which is obviously safe.  I *guess*
you're trying to say it's also not ugly: most callers already contain
the ->, which you reuse, so there's hardly any code duplication.

>                                         simply repurpose it instead
> of adding a new function.
>
> Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
> ---
>  util/qemu-option.c | 23 +++++++++++++----------
>  1 file changed, 13 insertions(+), 10 deletions(-)
>
> diff --git a/util/qemu-option.c b/util/qemu-option.c
> index ab3b58599e..59be4f9d21 100644
> --- a/util/qemu-option.c
> +++ b/util/qemu-option.c
> @@ -460,16 +460,16 @@ static bool qemu_opt_parse(QemuOpt *opt, Error **errp)
>      }
>  }
>  
> -static bool opts_accepts_any(const QemuOpts *opts)
> +static bool opts_accepts_any(const QemuOptsList *list)
>  {
> -    return opts->list->desc[0].name == NULL;
> +    return list->desc[0].name == NULL;
>  }
>  
>  int qemu_opt_unset(QemuOpts *opts, const char *name)
>  {
>      QemuOpt *opt = qemu_opt_find(opts, name);
>  
> -    assert(opts_accepts_any(opts));
> +    assert(opts_accepts_any(opts->list));
>  
>      if (opt == NULL) {
>          return -1;

Here, it's a straighforward lift of opts->.

> @@ -500,9 +500,10 @@ static bool opt_validate(QemuOpt *opt, bool *help_wanted,
>                           Error **errp)
>  {
>      const QemuOptDesc *desc;
> +    const QemuOptsList *list = opt->opts->list;
>  
> -    desc = find_desc_by_name(opt->opts->list->desc, opt->name);
> -    if (!desc && !opts_accepts_any(opt->opts)) {
> +    desc = find_desc_by_name(list->desc, opt->name);
> +    if (!desc && !opts_accepts_any(list)) {
>          error_setg(errp, QERR_INVALID_PARAMETER, opt->name);
>          if (help_wanted && is_help_option(opt->name)) {
>              *help_wanted = true;

Here, you reuse the existing opts-> by splicing in a variable.

This isn't as obvious as the straighforward lift, and I guess this is
what made you mention "since" in the commit message.

> @@ -535,9 +536,10 @@ bool qemu_opt_set_bool(QemuOpts *opts, const char *name, bool val,
>  {
>      QemuOpt *opt;
>      const QemuOptDesc *desc;
> +    const QemuOptsList *list = opts->list;
>  
> -    desc = find_desc_by_name(opts->list->desc, name);
> -    if (!desc && !opts_accepts_any(opts)) {
> +    desc = find_desc_by_name(list->desc, name);
> +    if (!desc && !opts_accepts_any(list)) {
>          error_setg(errp, QERR_INVALID_PARAMETER, name);
>          return false;
>      }
> @@ -557,9 +559,10 @@ bool qemu_opt_set_number(QemuOpts *opts, const char *name, int64_t val,
>  {
>      QemuOpt *opt;
>      const QemuOptDesc *desc;
> +    const QemuOptsList *list = opts->list;
>  
> -    desc = find_desc_by_name(opts->list->desc, name);
> -    if (!desc && !opts_accepts_any(opts)) {
> +    desc = find_desc_by_name(list->desc, name);
> +    if (!desc && !opts_accepts_any(list)) {
>          error_setg(errp, QERR_INVALID_PARAMETER, name);
>          return false;
>      }
> @@ -1110,7 +1113,7 @@ bool qemu_opts_validate(QemuOpts *opts, const QemuOptDesc *desc, Error **errp)
>  {
>      QemuOpt *opt;
>  
> -    assert(opts_accepts_any(opts));
> +    assert(opts_accepts_any(opts->list));
>  
>      QTAILQ_FOREACH(opt, &opts->head, next) {
>          opt->desc = find_desc_by_name(desc, opt->name);

The commit message confused me a bit.  Regardless:

Reviewed-by: Markus Armbruster <armbru@redhat.com>



  reply	other threads:[~2020-11-09 15:28 UTC|newest]

Thread overview: 26+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-11-09 13:39 [PATCH v2 for-5.2 0/6] Deprecate or forbid crazy QemuOpts cases Paolo Bonzini
2020-11-09 13:39 ` [PATCH v2 1/6] qemu-option: simplify search for end of key Paolo Bonzini
2020-11-09 14:48   ` Markus Armbruster
2020-11-09 13:39 ` [PATCH v2 2/6] qemu-option: pass QemuOptsList to opts_accepts_any Paolo Bonzini
2020-11-09 15:27   ` Markus Armbruster [this message]
2020-11-09 13:39 ` [PATCH v2 3/6] qemu-option: restrict qemu_opts_set to merge-lists QemuOpts Paolo Bonzini
2020-11-09 15:55   ` Markus Armbruster
2020-11-09 16:21     ` Paolo Bonzini
2020-11-09 18:52       ` Markus Armbruster
2020-11-09 18:58         ` Paolo Bonzini
2020-11-09 13:39 ` [PATCH v2 4/6] qemu-option: clean up id vs. list->merge_lists Paolo Bonzini
2020-11-09 16:56   ` Markus Armbruster
2020-11-09 17:17     ` Paolo Bonzini
2020-11-09 18:38       ` Markus Armbruster
2020-11-09 18:59         ` Paolo Bonzini
2020-11-10  8:29           ` Markus Armbruster
2020-11-10  8:39             ` Paolo Bonzini
2020-11-10  9:54               ` Markus Armbruster
2020-11-09 13:39 ` [PATCH v2 5/6] qemu-option: move help handling to get_opt_name_value Paolo Bonzini
2020-11-09 19:40   ` Markus Armbruster
2020-11-09 19:47     ` Paolo Bonzini
2020-11-09 13:39 ` [PATCH v2 6/6] qemu-option: warn for short-form boolean options Paolo Bonzini
2020-11-09 21:19   ` Markus Armbruster
2020-11-09 21:42     ` Paolo Bonzini
2020-11-10  8:32       ` Markus Armbruster
2020-11-09 13:54 ` [PATCH v2 for-5.2 0/6] Deprecate or forbid crazy QemuOpts cases no-reply

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=871rh27dok.fsf@dusky.pond.sub.org \
    --to=armbru@redhat.com \
    --cc=pbonzini@redhat.com \
    --cc=qemu-devel@nongnu.org \
    /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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.