From: Vladimir Sementsov-Ogievskiy <vsementsov@yandex-team.ru>
To: peterx@redhat.com
Cc: farosas@suse.de, vsementsov@yandex-team.ru, qemu-devel@nongnu.org
Subject: [PATCH v3 06/18] migration: factor out vmstate_pre_save() from vmstate_save_state()
Date: Thu, 5 Mar 2026 00:22:50 +0300 [thread overview]
Message-ID: <20260304212303.667141-7-vsementsov@yandex-team.ru> (raw)
In-Reply-To: <20260304212303.667141-1-vsementsov@yandex-team.ru>
Simplify vmstate_save_state() which is rather big, and simplify further
refactoring.
Signed-off-by: Vladimir Sementsov-Ogievskiy <vsementsov@yandex-team.ru>
Reviewed-by: Peter Xu <peterx@redhat.com>
---
migration/vmstate.c | 37 +++++++++++++++++++++++--------------
1 file changed, 23 insertions(+), 14 deletions(-)
diff --git a/migration/vmstate.c b/migration/vmstate.c
index 87e1f049592..605b5c59c76 100644
--- a/migration/vmstate.c
+++ b/migration/vmstate.c
@@ -435,6 +435,26 @@ bool vmstate_section_needed(const VMStateDescription *vmsd, void *opaque)
return true;
}
+static bool vmstate_pre_save(const VMStateDescription *vmsd, void *opaque,
+ Error **errp)
+{
+ ERRP_GUARD();
+
+ if (vmsd->pre_save_errp) {
+ if (!vmsd->pre_save_errp(opaque, errp)) {
+ error_prepend(errp, "pre-save for %s failed: ", vmsd->name);
+ return false;
+ }
+ } else if (vmsd->pre_save) {
+ if (vmsd->pre_save(opaque) < 0) {
+ error_setg(errp, "pre-save failed: %s", vmsd->name);
+ return false;
+ }
+ }
+
+ return true;
+}
+
static int vmstate_save_state_v(QEMUFile *f, const VMStateDescription *vmsd,
void *opaque, JSONWriter *vmdesc,
int version_id, Error **errp)
@@ -445,20 +465,9 @@ static 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) ? 0 : -EINVAL;
- if (ret < 0) {
- error_prepend(errp, "pre-save for %s failed: ", vmsd->name);
- trace_vmstate_save_state_pre_save_fail(vmsd->name);
- return ret;
- }
- } else if (vmsd->pre_save) {
- ret = vmsd->pre_save(opaque);
- if (ret) {
- error_setg(errp, "pre-save failed: %s", vmsd->name);
- trace_vmstate_save_state_pre_save_fail(vmsd->name);
- return ret;
- }
+ if (!vmstate_pre_save(vmsd, opaque, errp)) {
+ trace_vmstate_save_state_pre_save_fail(vmsd->name);
+ return -EINVAL;
}
trace_vmstate_save_state_pre_save_success(vmsd->name);
--
2.52.0
next prev parent reply other threads:[~2026-03-04 21:24 UTC|newest]
Thread overview: 33+ 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-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 ` Vladimir Sementsov-Ogievskiy [this message]
2026-03-04 21:22 ` [PATCH v3 07/18] migration: factor out vmstate_save_field() from vmstate_save_state() 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-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=20260304212303.667141-7-vsementsov@yandex-team.ru \
--to=vsementsov@yandex-team.ru \
--cc=farosas@suse.de \
--cc=peterx@redhat.com \
--cc=qemu-devel@nongnu.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