All of lore.kernel.org
 help / color / mirror / Atom feed
From: Markus Armbruster <armbru@redhat.com>
To: Eric Blake <eblake@redhat.com>
Cc: Kevin Wolf <kwolf@redhat.com>,
	qemu-devel@nongnu.org, stefanha@redhat.com
Subject: Re: [Qemu-devel] [PATCH] block: Catch simultaneous usage of options and their aliases
Date: Thu, 18 Sep 2014 16:06:27 +0200	[thread overview]
Message-ID: <87y4thm3a4.fsf@blackfin.pond.sub.org> (raw)
In-Reply-To: <541AD06B.1070804@redhat.com> (Eric Blake's message of "Thu, 18 Sep 2014 06:30:35 -0600")

Eric Blake <eblake@redhat.com> writes:

> On 09/18/2014 03:57 AM, Kevin Wolf wrote:
>> While thinking about precedence of conflicting block device options from
>> different sources, I noticed that you can specify both an option and its
>> legacy alias at the same time (e.g. readonly=on,read-only=off). Rather
>> than specifying the order of precedence, we should simply forbid such
>> combinations.
>> 
>> Signed-off-by: Kevin Wolf <kwolf@redhat.com>
>> ---
>>  blockdev.c | 46 +++++++++++++++++++++++++++++++---------------
>>  tests/qemu-iotests/051     | 23 +++++++++++++++++++++++
>>  tests/qemu-iotests/051.out | 45 +++++++++++++++++++++++++++++++++++++++++++++
>>  3 files changed, 99 insertions(+), 15 deletions(-)
>
> Reviewed-by: Eric Blake <eblake@redhat.com>
>
>>  
>> -static void qemu_opt_rename(QemuOpts *opts, const char *from, const char *to)
>> +static void qemu_opt_rename(QemuOpts *opts, const char *from, const char *to,
>> +                            Error **errp)
>>  {
>>      const char *value;
>>  
>> +    if (*errp) {
>> +        return;
>> +    }
>
> Not the most typical usage, so it might be worth a comment that this
> function can be called with errp already set.  But since it's static,
> it's not too hard to figure out as-is.

The problem with this usage is it doesn't combine well with the common
usage.  That's why I purged it from the code back in May:

commit 297a3646c2947ee64a6d42ca264039732c6218e0
Author: Markus Armbruster <armbru@redhat.com>
Date:   Wed May 7 09:53:54 2014 +0200

    qapi: Replace uncommon use of the error API by the common one
    
    We commonly use the error API like this:
    
        err = NULL;
        foo(..., &err);
        if (err) {
            goto out;
        }
        bar(..., &err);
    
    Every error source is checked separately.  The second function is only
    called when the first one succeeds.  Both functions are free to pass
    their argument to error_set().  Because error_set() asserts no error
    has been set, this effectively means they must not be called with an
    error set.
    
    The qapi-generated code uses the error API differently:
    
        // *errp was initialized to NULL somewhere up the call chain
        frob(..., errp);
        gnat(..., errp);
    
    Errors accumulate in *errp: first error wins, subsequent errors get
    dropped.  To make this work, the second function does nothing when
    called with an error set.  Requires non-null errp, or else the second
    function can't see the first one fail.
    
    This usage has also bled into visitor tests, and two device model
    object property getters rtc_get_date() and balloon_stats_get_all().
    
    With the "accumulate" technique, you need fewer error checks in
    callers, and buy that with an error check in every callee.  Can be
    nice.
    
    However, mixing the two techniques is confusing.  You can't use the
    "accumulate" technique with functions designed for the "check
    separately" technique.  You can use the "check separately" technique
    with functions designed for the "accumulate" technique, but then
    error_set() can't catch you setting an error more than once.
    
    Standardize on the "check separately" technique for now, because it's
    overwhelmingly prevalent.
    
    Signed-off-by: Markus Armbruster <armbru@redhat.com>
    Reviewed-by: Eric Blake <eblake@redhat.com>
    Signed-off-by: Luiz Capitulino <lcapitulino@redhat.com>

See also the thread leading up to this commit:
https://lists.nongnu.org/archive/html/qemu-devel/2014-04/msg01424.html
in particular the part starting at
https://lists.nongnu.org/archive/html/qemu-devel/2014-04/msg01830.html

I guess you're about as thrilled by what the common usage does to your
code as I am:

    qemu_opt_rename(all_opts, "iops", "throttling.iops-total", &local_err);
    if (local_err) {
        goto fail_opt_rename;
    }
    qemu_opt_rename(all_opts, "iops_rd", "throttling.iops-read", &local_err);
    if (local_err) {
        goto fail_opt_rename;
    }
    qemu_opt_rename(all_opts, "iops_wr", "throttling.iops-write", &local_err);
    if (local_err) {
        goto fail_opt_rename;
    }
[11 instances of the same pattern mercifully omitted...]

fail_opt_rename:
    error_report("%s", error_get_pretty(local_err));
    error_free(local_err);
    return NULL;

But this code is annoyingly repetitive even before the patch!  Here's
what I'd do:

    static struct {
        const char *from, *to;
    } rename[] = {
        { "iops", "throttling.iops-total" },
        { "iops_rd", "throttling.iops-read" },
        { "iops_wr", "throttling.iops-write" },
        { "bps", "throttling.bps-total" },
        { "bps_rd", "throttling.bps-read" },
        { "bps_wr", "throttling.bps-write" },
        { "iops_max", "throttling.iops-total-max" },
        { "iops_rd_max", "throttling.iops-read-max" },
        { "iops_wr_max", "throttling.iops-write-max" },
        { "bps_max", "throttling.bps-total-max" },
        { "bps_rd_max", "throttling.bps-read-max" },
        { "bps_wr_max", "throttling.bps-write-max" },
        { "iops_size", "throttling.iops-size" },
        { "readonly", "read-only" },
    };
    Error *local_err = NULL;
    int i;

    for (i = 0; i < ARRAY_SIZE(rename); i++) {
        qemu_opt_rename(all_opts, rename[i].from, rename[i].to,
                        &local_err);
        if (local_err) {
            error_report("%s", error_get_pretty(local_err));
            error_free(local_err);
            return NULL;
        }
    }

  reply	other threads:[~2014-09-18 14:06 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2014-09-18  9:57 [Qemu-devel] [PATCH] block: Catch simultaneous usage of options and their aliases Kevin Wolf
2014-09-18 12:30 ` Eric Blake
2014-09-18 14:06   ` Markus Armbruster [this message]
2014-09-18 14:34     ` Kevin Wolf

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=87y4thm3a4.fsf@blackfin.pond.sub.org \
    --to=armbru@redhat.com \
    --cc=eblake@redhat.com \
    --cc=kwolf@redhat.com \
    --cc=qemu-devel@nongnu.org \
    --cc=stefanha@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 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.