All of lore.kernel.org
 help / color / mirror / Atom feed
From: Markus Armbruster <armbru@redhat.com>
To: Paolo Bonzini <pbonzini@redhat.com>
Cc: Vladimir Sementsov-Ogievskiy <vsementsov@yandex-team.ru>,
	 Peter Xu <peterx@redhat.com>,  Fabiano Rosas <farosas@suse.de>,
	 qemu-devel <qemu-devel@nongnu.org>
Subject: Re: [PATCH v3 12/18] migration: VMStateInfo: introduce new handlers with errp
Date: Tue, 28 Apr 2026 13:39:17 +0200	[thread overview]
Message-ID: <878qa72u1m.fsf@pond.sub.org> (raw)
In-Reply-To: <de48c866-6018-4a5f-9129-2c1d184f4495@redhat.com> (Paolo Bonzini's message of "Tue, 28 Apr 2026 10:39:43 +0200")

Paolo Bonzini <pbonzini@redhat.com> writes:

> On 4/28/26 10:17, Vladimir Sementsov-Ogievskiy wrote:
>> [add Markus]
>> On 27.04.26 22:11, Paolo Bonzini wrote:
>>>
>>>
>>> Il lun 27 apr 2026, 15:19 Vladimir Sementsov-Ogievskiy <vsementsov@yandex-team.ru <mailto:vsementsov@yandex-team.ru>> ha scritto:
>>>>
>>>> On 26.04.26 11:33, Paolo Bonzini wrote:
>>>>> On 3/4/26 21:22, Vladimir Sementsov-Ogievskiy wrote:
>>>>>> +    bool coroutine_mixed_fn (*load)(QEMUFile *f, void *pv, size_t size,
>>>>>> +                                    const VMStateField *field,
>>>>>> +                                    Error **errp);
>>>>>> +    bool coroutine_mixed_fn (*save)(QEMUFile *f, void *pv, size_t size,
>>>>>> +                                    const VMStateField *field,
>>>>>> +                                    JSONWriter *vmdesc,
>>>>>> +                                    Error **errp);
>>>>> Use void functions for callbacks, with a wrapper adding the bool type. While bool/errp is preferred in general, for callbacks it provides N opportunities to get it wrong instead of just one.
>>>>>
>>>>
>>>> Hmm, for now, the series is already merged.
>>>>
>>>> Next, I'm unsure, how callbacks are different from other functions around errors?
>>>
>>> As I wrote above, confusing the *error == NULL and bool return value is avoided without much extra effort for callbacks (or other kinds of virtual functions) l, because there is a single caller. So the balance between "avoiding the possibility of getting the return value wrong" and "convenience of having a return value" tilts more towards the former.

Bug patterns:

1. Set an error, immediately return success.  I can't remember seeing
this.

2. Set an error, forget to return, somehow survive all the way to the
normal success return.  I've seen and fixed this.  Returning void does
not help at all here.

3. Set an error, goto error exit without flipping the return value
variable from success to failure.  I've seen and fixed this, too.  Best
to initialize the return value variable to failure, and flip it to
success only when success is ensured.  Of course, that flip can be
forgotten as well if it's needed in multiple places.  That's rare.
Anyway, returning eliminates this bug pattern.

The last one does some tilting.

Tilting the other way: keeping the rules simple and consistent with
GError's.

>> Understand. Hm.
>>
>> An alternative for this single-caller case, is just add an assertion into this caller:
>>
>> bool wrapper(..., errp) {
>>     ERRP_GUARD();
>>     bool ok = x->foo(..., errp);
>>     assert(ok == !(*errp));
>>     return ok;
>> }
>
> I don't think this makes sense, the assertion moves a compile-time guarantee to a run-time guarantee which is strictly worse.
>
> There are many more examples of void+errp callbacks than bool+errp, the most important one being .realize for devices.  A quick grep, which is certainly not fully accurate, shows 63 vs. 27:
>
> $ git grep -w 'void.*(\*.*errp' | wc -l
> 63
> $ git grep -w 'bool.*(\*.*errp' | wc -l
> 27

Yes.  At some point, I briefly considered updating them to return bool
for rules conformance, but decided it wasn't worth it.

> In many cases there are just two or three implementation so I wouldn't go to great lengths to change it even if I disagree.  But for vmstate (e.g. pre_load_errp and friends) this is not going to be the case in the long run, and it's more similar to the device case.

We should always be willing to accept reasoned exceptions to rules.
However...

>>>> I'm not sure that making wrappers, which will have to use ERRP_GUARD and check
>>>> *errp for the error is a good practice. If it is, it would be good to start by
>>>> modifying the documentation in include/qapi/error.h to mention the exclusion
>>>> for callbacks.

... explaining them in documentation is desirable.

  reply	other threads:[~2026-04-28 11:40 UTC|newest]

Thread overview: 41+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-03-04 21:22 [PATCH v3 00/18] migration: more bool+errp APIs Vladimir Sementsov-Ogievskiy
2026-03-04 21:22 ` [PATCH v3 01/18] migration: vmstate_save_state_v: fix double error_setg Vladimir Sementsov-Ogievskiy
2026-04-26  8:05   ` Michael Tokarev
2026-03-04 21:22 ` [PATCH v3 02/18] migration: make vmstate_save_state_v() static Vladimir Sementsov-Ogievskiy
2026-03-04 21:22 ` [PATCH v3 03/18] migration: make .post_save() a void function Vladimir Sementsov-Ogievskiy
2026-03-06 23:20   ` Fabiano Rosas
2026-03-06 23:34     ` noreply77-demartz@thinocorp.com
2026-03-09 14:41     ` Zhao Liu
2026-03-04 21:22 ` [PATCH v3 04/18] migration: vmstate_load_state(): add some newlines Vladimir Sementsov-Ogievskiy
2026-03-04 21:22 ` [PATCH v3 05/18] migration: vmstate_save/load_state(): refactor tracing errors Vladimir Sementsov-Ogievskiy
2026-03-05 16:59   ` Peter Xu
2026-03-04 21:22 ` [PATCH v3 06/18] migration: factor out vmstate_pre_save() from vmstate_save_state() Vladimir Sementsov-Ogievskiy
2026-03-04 21:22 ` [PATCH v3 07/18] migration: factor out vmstate_save_field() " Vladimir Sementsov-Ogievskiy
2026-03-04 21:22 ` [PATCH v3 08/18] migration: factor out vmstate_pre_load() from vmstate_load_state() Vladimir Sementsov-Ogievskiy
2026-03-04 21:22 ` [PATCH v3 09/18] migration: factor out vmstate_load_field() " Vladimir Sementsov-Ogievskiy
2026-03-04 21:22 ` [PATCH v3 10/18] migration: factor out vmstate_post_load() " Vladimir Sementsov-Ogievskiy
2026-03-04 21:22 ` [PATCH v3 11/18] migration: convert vmstate_subsection_save/load functions to bool Vladimir Sementsov-Ogievskiy
2026-03-04 21:22 ` [PATCH v3 12/18] migration: VMStateInfo: introduce new handlers with errp Vladimir Sementsov-Ogievskiy
2026-04-26  8:33   ` Paolo Bonzini
2026-04-27 13:19     ` Vladimir Sementsov-Ogievskiy
2026-04-27 19:11       ` Paolo Bonzini
2026-04-28  8:17         ` Vladimir Sementsov-Ogievskiy
2026-04-28  8:39           ` Paolo Bonzini
2026-04-28 11:39             ` Markus Armbruster [this message]
2026-04-28 14:34               ` Paolo Bonzini
2026-03-04 21:22 ` [PATCH v3 13/18] migration: introduce vmstate_load_vmsd() and vmstate_save_vmsd() Vladimir Sementsov-Ogievskiy
2026-03-05 17:01   ` Peter Xu
2026-03-04 21:22 ` [PATCH v3 14/18] migration/cpr: move to new migration APIs Vladimir Sementsov-Ogievskiy
2026-03-04 21:22 ` [PATCH v3 15/18] migration/savevm: " Vladimir Sementsov-Ogievskiy
2026-03-04 21:23 ` [PATCH v3 16/18] hw/s390x/css: drop use of .err_hint for vmstate Vladimir Sementsov-Ogievskiy
2026-03-05  2:29   ` Eric Farman
2026-03-05 17:14   ` Peter Xu
2026-03-04 21:23 ` [PATCH v3 17/18] migration: drop VMStateField.err_hint Vladimir Sementsov-Ogievskiy
2026-03-05  2:39   ` Eric Farman
2026-03-05  5:18   ` Akihiko Odaki
2026-03-05 17:14   ` Peter Xu
2026-03-04 21:23 ` [PATCH v3 18/18] migration/vmstate-types: move to new migration APIs Vladimir Sementsov-Ogievskiy
2026-03-05 17:15   ` Peter Xu
2026-03-06 20:53 ` [PATCH v3 00/18] migration: more bool+errp APIs Fabiano Rosas
2026-03-24  7:22   ` Vladimir Sementsov-Ogievskiy
2026-03-24 12:42     ` Fabiano Rosas

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=878qa72u1m.fsf@pond.sub.org \
    --to=armbru@redhat.com \
    --cc=farosas@suse.de \
    --cc=pbonzini@redhat.com \
    --cc=peterx@redhat.com \
    --cc=qemu-devel@nongnu.org \
    --cc=vsementsov@yandex-team.ru \
    /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.