qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
From: Eric Blake <eblake@redhat.com>
To: Vladimir Sementsov-Ogievskiy <vsementsov@virtuozzo.com>,
	Markus Armbruster <armbru@redhat.com>
Cc: "marcandre.lureau@redhat.com" <marcandre.lureau@redhat.com>,
	"berrange@redhat.com" <berrange@redhat.com>,
	"qemu-devel@nongnu.org" <qemu-devel@nongnu.org>,
	"ehabkost@redhat.com" <ehabkost@redhat.com>,
	"pbonzini@redhat.com" <pbonzini@redhat.com>
Subject: Re: [PATCH v6] hw/core/qdev: cleanup Error ** variables
Date: Thu, 5 Dec 2019 10:45:26 -0600	[thread overview]
Message-ID: <61df02c1-2be4-a2fc-e320-c88666b673fc@redhat.com> (raw)
In-Reply-To: <6d311ad1-528c-5787-64d0-779d6dcbadef@virtuozzo.com>

On 12/5/19 8:48 AM, Vladimir Sementsov-Ogievskiy wrote:

>>> @@ -918,27 +917,26 @@ static void device_set_realized(Object *obj, bool value, Error **errp)
>>>           }
>>>    
>>>        } else if (!value && dev->realized) {
>>> -        Error **local_errp = NULL;
>>> +        /* We want local_err to track only the first error */
>>>            QLIST_FOREACH(bus, &dev->child_bus, sibling) {
>>> -            local_errp = local_err ? NULL : &local_err;
>>>                object_property_set_bool(OBJECT(bus), false, "realized",
>>> -                                     local_errp);
>>> +                                     local_err ? NULL : &local_err);
>>>            }
>>
>> This is a rather unusual way to keep the first error of several.

It may be unusual, but has the benefit of avoiding error_propagate...

>> qapi/error.h advises:
>>
>>    * Receive and accumulate multiple errors (first one wins):
>>    *     Error *err = NULL, *local_err = NULL;
>>    *     foo(arg, &err);
>>    *     bar(arg, &local_err);
>>    *     error_propagate(&err, local_err);
>>    *     if (err) {
>>    *         handle the error...
>>    *     }
> 
> Hmm, honestly, I like more what I've written:
> 
> 1. less code
> 2. logic is more clean: we store first error to local_err, and after first error
>      pass NULL as a parameter. No propagation or extra error variables.
> 3. more efficient (no propagation, no extra allocation for errors which we'll drop
>      anyway) (I understand that efficiency of error path is not thing to care about,
>      so it's at third place)
> 
> Also, propagation which you propose is also unusual thing (it proposed in comment,
> but who reads it :). I've never seen it before, and I've to go and check that
> error_propagate works correctly when first argument is already set.
> 
> So, I'd prefer to keep now this patch as is, and to convert later if we really need it.
> 
>>
>> If replacing this by the usual way is too troublesome now, we can do it
>> after the ERRP_AUTO_PROPAGATE() conversion.  Your choice.

...and after conversion to use ERRP_AUTO_PROPATATE(), the use of 
error_propagate() should NOT occur in any code _except_ for the macro 
definition (any other use of the function points out a place where we 
failed to use the macro to get rid of boilerplate).

-- 
Eric Blake, Principal Software Engineer
Red Hat, Inc.           +1-919-301-3226
Virtualization:  qemu.org | libvirt.org



  reply	other threads:[~2019-12-05 16:47 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-11-27 19:20 [PATCH v6] hw/core/qdev: cleanup Error ** variables Vladimir Sementsov-Ogievskiy
2019-11-29  6:07 ` Markus Armbruster
2019-12-05 14:48   ` Vladimir Sementsov-Ogievskiy
2019-12-05 16:45     ` Eric Blake [this message]
2019-12-06  8:26       ` Markus Armbruster
2019-12-06 10:46         ` Vladimir Sementsov-Ogievskiy

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=61df02c1-2be4-a2fc-e320-c88666b673fc@redhat.com \
    --to=eblake@redhat.com \
    --cc=armbru@redhat.com \
    --cc=berrange@redhat.com \
    --cc=ehabkost@redhat.com \
    --cc=marcandre.lureau@redhat.com \
    --cc=pbonzini@redhat.com \
    --cc=qemu-devel@nongnu.org \
    --cc=vsementsov@virtuozzo.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).