From: Eduardo Habkost <ehabkost@redhat.com>
To: Eric Blake <eblake@redhat.com>
Cc: "Philippe Mathieu-Daudé" <f4bug@amsat.org>,
"Paolo Bonzini" <pbonzini@redhat.com>,
"Fam Zheng" <famz@redhat.com>,
"qemu-devel@nongnu.org Developers" <qemu-devel@nongnu.org>,
"Stefan Hajnoczi" <stefanha@redhat.com>,
"Markus Armbruster" <armbru@redhat.com>
Subject: Re: [Qemu-devel] [PATCH] scsi-generic: Simplify error handling code
Date: Thu, 18 Jan 2018 19:38:05 -0200 [thread overview]
Message-ID: <20180118213805.GI5292@localhost.localdomain> (raw)
In-Reply-To: <59cde1ab-cf5f-b40a-4377-b33091b593a2@redhat.com>
On Thu, Jan 18, 2018 at 02:34:39PM -0600, Eric Blake wrote:
> On 01/18/2018 09:55 AM, Philippe Mathieu-Daudé wrote:
> > On Thu, Jan 18, 2018 at 9:03 AM, Paolo Bonzini <pbonzini@redhat.com> wrote:
> >> On 18/01/2018 12:21, Philippe Mathieu-Daudé wrote:
> >>>> I'm not a fan of bool return types, in general (because "!" is often
> >>>> success while "< 0" is failure) and especially when there is an Error**;
> >>>> I disagree with commit 9d3b155186. But the function is not in an area I
> >>>> maintain so I'm queuing this, thanks.
> >>> Do you prefer "if (local_err)" and "if (errp && *errp)" ?
> >>
> >> The latter is wrong. I do prefer
> >
> > Ok so my 253674981e24 missed that train too.
Oops. I thought we had Coccinelle scripts to detect that
pattern.
>
> Markus has expressed as desire, as the error maintainer, to make errp
> functions return a useful value for less boilerplate, and at one point
> was even debating about Coccinelle scripts to make the conversion
> easier. Perhaps int with -1 is more reliable than bool for that useful
> value, but this is definitely a topic of past discussion.
>
> By the way, if (local_err) is definitely preferable; 'if (errp &&
> *errp)' means that your behavior is different depending on whether the
> caller wanted to ignore the error, and not whether you wanted to handle
> the error.
>
> >
> >>
> >> if (local_err) {
> >> error_propagate(errp, local_err);
> >> return;
> >> }
>
> Yes, that's the right boilerplate if you don't have a return value witness.
>
> >>
> >> or maybe (but only if there is a meaning to a zero vs. positive return
> >> value, or if errno is an important part of the returned Error *)
> >>
> >> ret = f(..., errp);
> >> if (ret < 0) {
> >> return;
> >> }
> >>
> >>> I wondered once if a macro might improve this pattern but thought the
> >>> code would get more obscure.
> >>
> >> Eduardo had a series to avoid error_propagate, where NULL was replaced
> >> by a (non-NULL) IGNORED_ERRORS macro. Then you could do:
> >>
> >> f(..., errp);
> >> if (error_is_set(errp)) {
> >> return;
> >> }
> >>
> >> See here:
> >> https://lists.gnu.org/archive/html/qemu-devel/2017-06/msg03139.html
> >
> > This series never hit /master!
> >
> > Reading the thread I'm not sure what was the expected outcome.
>
> And since Markus may not answer this thread for a while, I'm still not
> sure if there is any expected outcome.
Quoting Markus on that discussion:
"If we switch to returning success/failure (which also gets rid of the
boilerplate), then the macros may still let us get rid of boilerplate
more quickly, for some additional churn. Worthwhile? Depends on how
long the return value change takes us."
I guess the lack of activity switching the code to returning
success/failure is enough evidence that the switch will take us
forever?
We can do some effort to document the preferred convention to
return success/failure, but I don't think we will be able to
convert the existing void/ret/bool functions to a single style
(whatever it is) in a reasonable time.
That said, IMO returning 0/-1 or true/false is always preferred
to returning void, so there's no need to add more local_err
boilerplate code.
--
Eduardo
next prev parent reply other threads:[~2018-01-18 21:38 UTC|newest]
Thread overview: 11+ messages / expand[flat|nested] mbox.gz Atom feed top
2018-01-18 2:52 [Qemu-devel] [PATCH] scsi-generic: Simplify error handling code Fam Zheng
2018-01-18 4:34 ` Philippe Mathieu-Daudé
2018-01-18 8:20 ` Paolo Bonzini
2018-01-18 11:21 ` Philippe Mathieu-Daudé
2018-01-18 12:03 ` Paolo Bonzini
2018-01-18 15:55 ` Philippe Mathieu-Daudé
2018-01-18 15:59 ` Paolo Bonzini
2018-01-18 20:34 ` Eric Blake
2018-01-18 21:38 ` Eduardo Habkost [this message]
2018-01-18 22:19 ` Paolo Bonzini
2018-01-18 22:39 ` Eduardo Habkost
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=20180118213805.GI5292@localhost.localdomain \
--to=ehabkost@redhat.com \
--cc=armbru@redhat.com \
--cc=eblake@redhat.com \
--cc=f4bug@amsat.org \
--cc=famz@redhat.com \
--cc=pbonzini@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 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).