From: Markus Armbruster <armbru@redhat.com>
To: Vladimir Sementsov-Ogievskiy <vsementsov@yandex-team.ru>
Cc: peterx@redhat.com, stefanb@linux.vnet.ibm.com, farosas@suse.de,
qemu-devel@nongnu.org, armbru@redhat.com, berrange@redhat.com
Subject: Re: [PATCH v3 4/4] migration: vmsd errp handlers: return bool
Date: Mon, 27 Oct 2025 11:38:36 +0100 [thread overview]
Message-ID: <87o6psocib.fsf@pond.sub.org> (raw)
In-Reply-To: <20251025202649.1122420-5-vsementsov@yandex-team.ru> (Vladimir Sementsov-Ogievskiy's message of "Sat, 25 Oct 2025 23:26:49 +0300")
Vladimir Sementsov-Ogievskiy <vsementsov@yandex-team.ru> writes:
> Switch the new API to simple bool-returning interface, as return value
> is not used otherwise than check is function failed or not. No logic
> depend on concrete errno values.
>
> Signed-off-by: Vladimir Sementsov-Ogievskiy <vsementsov@yandex-team.ru>
> ---
> backends/tpm/tpm_emulator.c | 10 ++++------
> docs/devel/migration/main.rst | 6 +++---
> include/migration/vmstate.h | 6 +++---
> migration/vmstate.c | 14 ++++++--------
> 4 files changed, 16 insertions(+), 20 deletions(-)
>
> diff --git a/backends/tpm/tpm_emulator.c b/backends/tpm/tpm_emulator.c
> index aa69eb606f..6cc9aa199c 100644
> --- a/backends/tpm/tpm_emulator.c
> +++ b/backends/tpm/tpm_emulator.c
> @@ -947,25 +947,23 @@ static void tpm_emulator_vm_state_change(void *opaque, bool running,
>
> /*
> * Load the TPM state blobs into the TPM.
> - *
> - * Returns negative errno codes in case of error.
> */
> -static int tpm_emulator_post_load(void *opaque, int version_id, Error **errp)
> +static bool tpm_emulator_post_load(void *opaque, int version_id, Error **errp)
> {
> TPMBackend *tb = opaque;
> int ret;
>
> ret = tpm_emulator_set_state_blobs(tb, errp);
Note for later: this returns 0 or -EIO.
> if (ret < 0) {
> - return ret;
> + return false;
> }
>
> if (tpm_emulator_startup_tpm_resume(tb, 0, true) < 0) {
> error_setg(errp, "Failed to resume tpm");
> - return -EIO;
> + return false;
> }
>
> - return 0;
> + return true;
> }
>
> static const VMStateDescription vmstate_tpm_emulator = {
> diff --git a/docs/devel/migration/main.rst b/docs/devel/migration/main.rst
> index 1afe7b9689..234d280249 100644
> --- a/docs/devel/migration/main.rst
> +++ b/docs/devel/migration/main.rst
> @@ -446,15 +446,15 @@ The functions to do that are inside a vmstate definition, and are called:
>
> Following are the errp variants of these functions.
>
> -- ``int (*pre_load_errp)(void *opaque, Error **errp);``
> +- ``bool (*pre_load_errp)(void *opaque, Error **errp);``
>
> This function is called before we load the state of one device.
>
> -- ``int (*post_load_errp)(void *opaque, int version_id, Error **errp);``
> +- ``bool (*post_load_errp)(void *opaque, int version_id, Error **errp);``
>
> This function is called after we load the state of one device.
>
> -- ``int (*pre_save_errp)(void *opaque, Error **errp);``
> +- ``bool (*pre_save_errp)(void *opaque, Error **errp);``
>
> This function is called before we save the state of one device.
>
> diff --git a/include/migration/vmstate.h b/include/migration/vmstate.h
> index 63ccaee07a..dbe330dd5f 100644
> --- a/include/migration/vmstate.h
> +++ b/include/migration/vmstate.h
> @@ -218,11 +218,11 @@ struct VMStateDescription {
> int minimum_version_id;
> MigrationPriority priority;
> int (*pre_load)(void *opaque);
> - int (*pre_load_errp)(void *opaque, Error **errp);
> + bool (*pre_load_errp)(void *opaque, Error **errp);
> int (*post_load)(void *opaque, int version_id);
> - int (*post_load_errp)(void *opaque, int version_id, Error **errp);
> + bool (*post_load_errp)(void *opaque, int version_id, Error **errp);
> int (*pre_save)(void *opaque);
> - int (*pre_save_errp)(void *opaque, Error **errp);
> + bool (*pre_save_errp)(void *opaque, Error **errp);
> int (*post_save)(void *opaque);
> bool (*needed)(void *opaque);
> bool (*dev_unplug_pending)(void *opaque);
> diff --git a/migration/vmstate.c b/migration/vmstate.c
> index 677e56c84a..adaaf91b3f 100644
> --- a/migration/vmstate.c
> +++ b/migration/vmstate.c
> @@ -154,13 +154,12 @@ int vmstate_load_state(QEMUFile *f, const VMStateDescription *vmsd,
> return -EINVAL;
> }
> if (vmsd->pre_load_errp) {
> - ret = vmsd->pre_load_errp(opaque, errp);
> - if (ret < 0) {
> + if (!vmsd->pre_load_errp(opaque, errp)) {
> error_prepend(errp, "pre load hook failed for: '%s', "
> "version_id: %d, minimum version_id: %d: ",
> vmsd->name, vmsd->version_id,
> vmsd->minimum_version_id);
> - return ret;
> + return -EINVAL;
> }
> } else if (vmsd->pre_load) {
> ret = vmsd->pre_load(opaque);
> @@ -256,11 +255,11 @@ int vmstate_load_state(QEMUFile *f, const VMStateDescription *vmsd,
> return ret;
> }
> if (vmsd->post_load_errp) {
> - ret = vmsd->post_load_errp(opaque, version_id, errp);
> - if (ret < 0) {
> + if (!vmsd->post_load_errp(opaque, version_id, errp)) {
> error_prepend(errp, "post load hook failed for: %s, version_id: "
> "%d, minimum_version: %d: ", vmsd->name,
> vmsd->version_id, vmsd->minimum_version_id);
> + ret = -EINVAL;
With ->post_load_errp is tpm_emulator_post_load(), the value returned on
error changes from -EIO to -EINVAL.
Do callers of vmstate_load_state() care?
> }
> } else if (vmsd->post_load) {
> ret = vmsd->post_load(opaque, version_id);
> @@ -438,11 +437,10 @@ int vmstate_save_state_v(QEMUFile *f, const VMStateDescription *vmsd,
> trace_vmstate_save_state_top(vmsd->name);
>
> if (vmsd->pre_save_errp) {
> - ret = vmsd->pre_save_errp(opaque, errp);
> trace_vmstate_save_state_pre_save_res(vmsd->name, ret);
> - if (ret < 0) {
> + if (!vmsd->pre_save_errp(opaque, errp)) {
> error_prepend(errp, "pre-save for %s failed: ", vmsd->name);
> - return ret;
> + return -EINVAL;
> }
> } else if (vmsd->pre_save) {
> ret = vmsd->pre_save(opaque);
> --
> 2.48.1
next prev parent reply other threads:[~2025-10-27 10:39 UTC|newest]
Thread overview: 22+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-10-25 20:26 [PATCH v3 0/4] migration: vmsd errp handlers: return bool Vladimir Sementsov-Ogievskiy
2025-10-25 20:26 ` [PATCH v3 1/4] migration: vmstate_save_state_v(): fix error path Vladimir Sementsov-Ogievskiy
2025-10-27 14:24 ` Stefan Berger
2025-10-25 20:26 ` [PATCH v3 2/4] tmp_emulator: fix unset errp on " Vladimir Sementsov-Ogievskiy
2025-10-27 10:16 ` Markus Armbruster
2025-10-27 14:33 ` Vladimir Sementsov-Ogievskiy
2025-10-27 15:06 ` Markus Armbruster
2025-10-25 20:26 ` [PATCH v3 3/4] migration/vmstate: stop reporting error number for new _errp APIs Vladimir Sementsov-Ogievskiy
2025-10-27 10:23 ` Markus Armbruster
2025-10-27 20:28 ` Vladimir Sementsov-Ogievskiy
2025-10-27 14:38 ` Stefan Berger
2025-10-27 14:55 ` Vladimir Sementsov-Ogievskiy
2025-10-25 20:26 ` [PATCH v3 4/4] migration: vmsd errp handlers: return bool Vladimir Sementsov-Ogievskiy
2025-10-27 10:38 ` Markus Armbruster [this message]
2025-10-27 14:58 ` Vladimir Sementsov-Ogievskiy
2025-10-27 16:30 ` Arun Menon
2025-10-27 17:06 ` Vladimir Sementsov-Ogievskiy
2025-10-28 15:12 ` Peter Xu
2025-10-28 16:26 ` Vladimir Sementsov-Ogievskiy
2025-10-28 16:42 ` Peter Xu
2025-10-27 20:33 ` Vladimir Sementsov-Ogievskiy
2025-10-28 5:08 ` Arun Menon
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=87o6psocib.fsf@pond.sub.org \
--to=armbru@redhat.com \
--cc=berrange@redhat.com \
--cc=farosas@suse.de \
--cc=peterx@redhat.com \
--cc=qemu-devel@nongnu.org \
--cc=stefanb@linux.vnet.ibm.com \
--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 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).