From: "Daniel P. Berrangé" <berrange@redhat.com>
To: "Philippe Mathieu-Daudé" <f4bug@amsat.org>
Cc: "Markus Armbruster" <armbru@redhat.com>,
"Claudio Fontana" <cfontana@suse.de>,
"Paolo Bonzini" <pbonzini@redhat.com>,
"Richard Henderson" <richard.henderson@linaro.org>,
"Kevin Wolf" <kwolf@redhat.com>,
"qemu-devel@nongnu.org Developers" <qemu-devel@nongnu.org>,
dinechin@redhat.com, "Gerd Hoffmann" <kraxel@redhat.com>,
"Marc-André Lureau" <marcandre.lureau@redhat.com>
Subject: Re: [PATCH v4 2/3] module: add Error arguments to module_load_one and module_load_qom_one
Date: Thu, 22 Sep 2022 14:44:13 +0100 [thread overview]
Message-ID: <YyxmrTnpziXGxRMm@redhat.com> (raw)
In-Reply-To: <CAAdtpL7=6YN+jh30xB_PB5aAxaWoFf4-3nLsWiAMGK6ZvWnLww@mail.gmail.com>
On Thu, Sep 22, 2022 at 03:34:42PM +0200, Philippe Mathieu-Daudé wrote:
> On Thu, Sep 22, 2022 at 3:20 PM Markus Armbruster <armbru@redhat.com> wrote:
> >
> > Claudio Fontana <cfontana@suse.de> writes:
> >
> > [...]
> >
> > > I think it would be better to completely make the return value separate from the Error,
> > > and really treat Error as an exception and not mix it up with the regular execution,
> > >
> > > but if it is the general consensus that I am the only one seeing this conflation problem we can model it this way too.
> >
> > It's a matter of language pragmatics. In Java, you throw an exception
> > on error. In C, you return an error value.
> >
> > Trying to emulate exceptions in C might be even more unadvisable than
> > trying to avoid them in Java. Best to work with the language, not
> > against it.
> >
> > Trouble is the error values we can conveniently return in C can't convey
> > enough information. So we use Error for that. Just like GLib uses
> > GError.
> >
> > More modern languages do "return error value" much better than C can. C
> > is what it is.
> >
> > We could certainly argue how to do better than we do now in QEMU's C
> > code. However, the Error API is used all over the place, which makes
> > changing it expensive. "Rethinking the whole Error API" (your words)
> > would have to generate benefits worth this expense. Which seems
> > unlikely.
>
> QEMU Error* and GLib GError are designed to report recoverable runtime *errors*.
>
> There is or is no error. A boolean return value seems appropriate.
>
> We are bikeshedding about the API because we are abusing it in a non-error case.
>
> If we want to try to load an optional module, the Error* argument is
> not the proper way to return the information regarding why we couldn't
> load.
>
> In both cases we want to know if the module was loaded. If this is an
> optional module, we don't care why it couldn't be loaded.
No, that's wrong. If the module exists on disk but is incompatible
with the current QEMU, then we need to be reporting that as an
error to the caller, so they can propagate this problem back up
the stack to the QMP command or CLI arg that started the code path.
We don't need to be using the return status to tell the caller if
the module was loaded or not. We only should be telling thue caller
is there was a reportable error or not.
Consider, there is a call to load block drivers. We don't need
to know whether each block driver was loaded or not. eg if the
'curl' code is a module and we fail to load it, then when code
tries to create a curl based block device the missing curl
support will be reported at that time. The callers that load
modules should only need to express whether their load attempt
is mandatory or optional, in terms of the module existing on
disk. If the modules exists on disk, any further errors
encountered when loading it should be propagated.
> So trying to make everybody happy:
>
> // Return true if the module could be loaded, otherwise return false
> and errp contains the error.
> bool module_load_one(const char *prefix, const char *name, Error *errp);
>
> // Return true if the module could be loaded, false otherwise.
> bool module_try_load_one(const char *prefix, const char *name);
Nope, this latter doesn't work as it throws away important errors
when loading an incompatible/broken module.
With regards,
Daniel
--
|: https://berrange.com -o- https://www.flickr.com/photos/dberrange :|
|: https://libvirt.org -o- https://fstop138.berrange.com :|
|: https://entangle-photo.org -o- https://www.instagram.com/dberrange :|
next prev parent reply other threads:[~2022-09-22 15:11 UTC|newest]
Thread overview: 50+ messages / expand[flat|nested] mbox.gz Atom feed top
2022-09-08 18:30 [PATCH v4 0/3] improve error handling for module load Claudio Fontana
2022-09-08 18:30 ` [PATCH v4 1/3] module: removed unused function argument "mayfail" Claudio Fontana
2022-09-08 18:30 ` [PATCH v4 2/3] module: add Error arguments to module_load_one and module_load_qom_one Claudio Fontana
2022-09-15 8:43 ` Claudio Fontana
2022-09-16 8:13 ` Richard Henderson
2022-09-16 8:16 ` Claudio Fontana
2022-09-16 9:27 ` Markus Armbruster
2022-09-16 10:48 ` Claudio Fontana
2022-09-16 14:26 ` Markus Armbruster
2022-09-16 15:06 ` Claudio Fontana
2022-09-19 8:17 ` Markus Armbruster
2022-09-19 8:45 ` Claudio Fontana
2022-09-21 12:47 ` Markus Armbruster
2022-09-19 10:18 ` Philippe Mathieu-Daudé via
2022-09-21 12:16 ` Markus Armbruster
2022-09-21 16:03 ` Claudio Fontana
2022-09-22 6:07 ` Markus Armbruster
2022-09-22 8:28 ` Daniel P. Berrangé
2022-09-22 9:20 ` Claudio Fontana
2022-09-22 9:21 ` Claudio Fontana
2022-09-22 9:27 ` Claudio Fontana
2022-09-22 9:31 ` Daniel P. Berrangé
2022-09-22 9:34 ` Claudio Fontana
2022-09-22 10:37 ` Daniel P. Berrangé
2022-09-22 12:30 ` Claudio Fontana
2022-09-22 12:33 ` Daniel P. Berrangé
2022-09-22 12:35 ` Claudio Fontana
2022-09-22 9:38 ` Markus Armbruster
2022-09-22 9:43 ` Claudio Fontana
2022-09-22 12:42 ` Markus Armbruster
2022-09-22 12:45 ` Claudio Fontana
2022-09-22 13:20 ` Markus Armbruster
2022-09-22 13:33 ` Claudio Fontana
2022-09-22 14:36 ` Markus Armbruster
2022-09-22 15:22 ` Claudio Fontana
2022-09-23 5:31 ` Markus Armbruster
2022-09-23 9:40 ` Claudio Fontana
2022-09-22 13:34 ` Philippe Mathieu-Daudé via
2022-09-22 13:42 ` Claudio Fontana
2022-09-22 13:44 ` Daniel P. Berrangé [this message]
2022-09-22 14:01 ` Claudio Fontana
2022-09-22 14:54 ` Kevin Wolf
2022-09-22 15:08 ` Claudio Fontana
2022-09-22 15:27 ` Markus Armbruster
2022-09-22 15:51 ` Claudio Fontana
2022-09-22 17:05 ` Kevin Wolf
2022-09-23 9:42 ` Claudio Fontana
2022-09-23 9:44 ` Claudio Fontana
2022-09-25 10:35 ` Richard Henderson
2022-09-08 18:30 ` [PATCH v4 3/3] accel: abort if we fail to load the accelerator plugin Claudio Fontana
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=YyxmrTnpziXGxRMm@redhat.com \
--to=berrange@redhat.com \
--cc=armbru@redhat.com \
--cc=cfontana@suse.de \
--cc=dinechin@redhat.com \
--cc=f4bug@amsat.org \
--cc=kraxel@redhat.com \
--cc=kwolf@redhat.com \
--cc=marcandre.lureau@redhat.com \
--cc=pbonzini@redhat.com \
--cc=qemu-devel@nongnu.org \
--cc=richard.henderson@linaro.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).