qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
From: Eric Blake <eblake@redhat.com>
To: Markus Armbruster <armbru@redhat.com>
Cc: pbonzini@redhat.com, qemu-devel@nongnu.org
Subject: Re: [Qemu-devel] [PATCH 5/9] QemuOpts: Convert qemu_opts_foreach() to Error
Date: Tue, 02 Jun 2015 06:34:39 -0600	[thread overview]
Message-ID: <556DA2DF.3010809@redhat.com> (raw)
In-Reply-To: <878uc2cpk9.fsf@blackfin.pond.sub.org>

[-- Attachment #1: Type: text/plain, Size: 2971 bytes --]

On 06/02/2015 05:33 AM, Markus Armbruster wrote:
> Eric Blake <eblake@redhat.com> writes:
> 
>> On 05/28/2015 06:21 AM, Markus Armbruster wrote:
>>> Retain the function value for now, to permit selective conversion of
>>> its callers.
>>>
>>> Signed-off-by: Markus Armbruster <armbru@redhat.com>
>>> ---

>>> -typedef int (*qemu_opts_loopfunc)(QemuOpts *opts, void *opaque);
>>> +typedef int (*qemu_opts_loopfunc)(void *opaque, QemuOpts *opts, Error **errp);
>>
>> Might be nice to justify in the commit message why swapping the
>> arguments of the callback made sense.  But doesn't affect code
>> correctness, so:
>>
>> Reviewed-by: Eric Blake <eblake@redhat.com>
> 
> Not sure what to write.  Not even quite sure why I like it better this
> way, only that I do.  Could be because it puts the object we're
> modifying (when we modify any of the argument objects) on the left.

That's indeed weak, but it's more justification than nothing, so I'll
buy it.

>>>  int qemu_opts_foreach(QemuOptsList *list, qemu_opts_loopfunc func,
>>> -                      void *opaque)
>>> +                      void *opaque, Error **errp)
>>>  {
>>>      Location loc;
>>>      QemuOpts *opts;
>>> @@ -1062,7 +1063,7 @@ int qemu_opts_foreach(QemuOptsList *list, qemu_opts_loopfunc func,
>>>      loc_push_none(&loc);
>>>      QTAILQ_FOREACH(opts, &list->head, next) {
>>>          loc_restore(&opts->loc);
>>> -        rc = func(opts, opaque);
>>> +        rc = func(opaque, opts, errp);
>>>          if (rc) {
>>>              return rc;
>>>          }
>>
>> Do you want to enforce that if errp is set, that rc is non-zero, to
>> match your contract?  Perhaps by assert(!*errp) at this point?  But if
>> the return value goes away later in the series in favor of only using
>> errp, it may be a moot question.
> 
> assert(!*errp) is incorrect, because callers may pass a null errp to
> ignore errors.  Could do
> 
>         if (rc) {
>             return rc;
>         }
>         assert(!errp || !*errp);
> 
> Catches misbehaving func() only when caller passes non-null errp.  To
> catcht it always, we'd need to use Error *err here, and
> error_propagate(errp, err).  I doubt it's worth the trouble.

Or, you could do:

if (!errp) {
    errp = &error_abort;
}
...
if (rc) {
    return rc;
}
assert(!*errp);

and not have to use error_propagate() - either the caller is tracking
errors, or the caller passed NULL because they are tracking return value
and we can assume that their callback will not raise errors (even on
negative returns).  But that's a slightly different contract.

You're right that the possibility of NULL makes it not as trivial as I
first thought, so I'm starting to waffle on whether enforcing the
contract is worth the extra lines of code.  Anyone else with an opinion?

-- 
Eric Blake   eblake redhat com    +1-919-301-3266
Libvirt virtualization library http://libvirt.org


[-- Attachment #2: OpenPGP digital signature --]
[-- Type: application/pgp-signature, Size: 604 bytes --]

  reply	other threads:[~2015-06-02 12:34 UTC|newest]

Thread overview: 31+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2015-05-28 12:21 [Qemu-devel] [PATCH 0/9] Miscellaneous error reporting improvements Markus Armbruster
2015-05-28 12:21 ` [Qemu-devel] [PATCH 1/9] vl: Report failure to sandbox at most once Markus Armbruster
2015-05-28 14:24   ` Eric Blake
2015-05-28 12:21 ` [Qemu-devel] [PATCH 2/9] vl: Print -device help " Markus Armbruster
2015-05-28 14:47   ` Eric Blake
2015-05-28 12:21 ` [Qemu-devel] [PATCH 3/9] vl: Fail right after first bad -object Markus Armbruster
2015-05-28 14:52   ` Eric Blake
2015-06-02  8:41     ` Markus Armbruster
2015-05-28 12:21 ` [Qemu-devel] [PATCH 4/9] QemuOpts: Drop qemu_opts_foreach() parameter abort_on_failure Markus Armbruster
2015-05-28 15:10   ` Eric Blake
2015-06-02  8:42     ` Markus Armbruster
2015-05-28 12:21 ` [Qemu-devel] [PATCH 5/9] QemuOpts: Convert qemu_opts_foreach() to Error Markus Armbruster
2015-05-28 16:18   ` Eric Blake
2015-06-02 11:33     ` Markus Armbruster
2015-06-02 12:34       ` Eric Blake [this message]
2015-06-02 14:13         ` Paolo Bonzini
2015-05-28 12:21 ` [Qemu-devel] [PATCH 6/9] blkdebug: Simplify passing of Error through qemu_opts_foreach() Markus Armbruster
2015-05-28 17:15   ` Eric Blake
2015-05-28 12:21 ` [Qemu-devel] [PATCH 7/9] QemuOpts: Drop qemu_opt_foreach() parameter abort_on_failure Markus Armbruster
2015-05-28 18:57   ` Eric Blake
2015-05-28 12:21 ` [Qemu-devel] [PATCH 8/9] QemuOpts: Convert qemu_opt_foreach() to Error Markus Armbruster
2015-05-28 19:07   ` Eric Blake
2015-05-28 12:21 ` [Qemu-devel] [PATCH 9/9] vhost-user: Improve -netdev/netdev_add/-net/... error reporting Markus Armbruster
2015-05-28 19:20   ` Eric Blake
2015-06-02 16:32   ` Stefan Hajnoczi
2015-05-29  8:51 ` [Qemu-devel] [PATCH 0/9] Miscellaneous error reporting improvements Kevin Wolf
2015-05-29 11:22   ` Markus Armbruster
2015-05-29 12:42     ` Kevin Wolf
2015-05-29 14:00     ` Eric Blake
2015-06-02 11:51       ` Markus Armbruster
2015-06-02 12:51         ` Eric Blake

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=556DA2DF.3010809@redhat.com \
    --to=eblake@redhat.com \
    --cc=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 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).