* [PATCH v2 03/16] migration: make .post_save() a void function
[not found] <20260220210214.800050-1-vsementsov@yandex-team.ru>
@ 2026-02-20 21:02 ` Vladimir Sementsov-Ogievskiy
2026-02-27 22:41 ` Fabiano Rosas
0 siblings, 1 reply; 4+ messages in thread
From: Vladimir Sementsov-Ogievskiy @ 2026-02-20 21:02 UTC (permalink / raw)
To: peterx
Cc: farosas, vsementsov, Pierrick Bouvier, Nicholas Piggin,
Harsh Prateek Bora, Peter Maydell, open list:All patches CC here,
open list:sPAPR (pseries), open list:ARM TCG CPUs
All other handlers now have _errp() variants. Should we go this way
for .post_save()? Actually it's rather strange, when the vmstate do
successful preparations in .pre_save(), then successfully save all
sections and subsections, end then fail when all the state is
successfully transferred to the target.
Happily, we have only three .post_save() realizations, all always
successful. Let's make this a rule.
Also note, that we call .post_save() in two places, and handle
its (theoretical) failure inconsistently. Fix that too.
Signed-off-by: Vladimir Sementsov-Ogievskiy <vsementsov@yandex-team.ru>
---
docs/devel/migration/main.rst | 2 +-
hw/ppc/spapr_pci.c | 3 +--
include/migration/vmstate.h | 10 +++++++++-
migration/savevm.c | 3 +--
migration/vmstate.c | 12 +++---------
target/arm/machine.c | 4 +---
6 files changed, 16 insertions(+), 18 deletions(-)
diff --git a/docs/devel/migration/main.rst b/docs/devel/migration/main.rst
index 234d280249..2de7050764 100644
--- a/docs/devel/migration/main.rst
+++ b/docs/devel/migration/main.rst
@@ -439,7 +439,7 @@ The functions to do that are inside a vmstate definition, and are called:
This function is called before we save the state of one device.
-- ``int (*post_save)(void *opaque);``
+- ``void (*post_save)(void *opaque);``
This function is called after we save the state of one device
(even upon failure, unless the call to pre_save returned an error).
diff --git a/hw/ppc/spapr_pci.c b/hw/ppc/spapr_pci.c
index ea998bdff1..1dc3b02659 100644
--- a/hw/ppc/spapr_pci.c
+++ b/hw/ppc/spapr_pci.c
@@ -2093,14 +2093,13 @@ static int spapr_pci_pre_save(void *opaque)
return 0;
}
-static int spapr_pci_post_save(void *opaque)
+static void spapr_pci_post_save(void *opaque)
{
SpaprPhbState *sphb = opaque;
g_free(sphb->msi_devs);
sphb->msi_devs = NULL;
sphb->msi_devs_num = 0;
- return 0;
}
static int spapr_pci_post_load(void *opaque, int version_id)
diff --git a/include/migration/vmstate.h b/include/migration/vmstate.h
index 3695afd483..15578b3e28 100644
--- a/include/migration/vmstate.h
+++ b/include/migration/vmstate.h
@@ -223,7 +223,15 @@ struct VMStateDescription {
bool (*post_load_errp)(void *opaque, int version_id, Error **errp);
int (*pre_save)(void *opaque);
bool (*pre_save_errp)(void *opaque, Error **errp);
- int (*post_save)(void *opaque);
+
+ /*
+ * post_save() rarely used to free some temporary resources.
+ * It's is called if .pre_save[_errp]() call was successful
+ * (or .pre_save[_errp] handler absent), regardless success
+ * or failure during fields and subsections save. If
+ * .pre_save[_errp]() fails, .post_save() is not called.
+ */
+ void (*post_save)(void *opaque);
bool (*needed)(void *opaque);
bool (*dev_unplug_pending)(void *opaque);
diff --git a/migration/savevm.c b/migration/savevm.c
index 3a16c467b2..c5236e71ba 100644
--- a/migration/savevm.c
+++ b/migration/savevm.c
@@ -321,14 +321,13 @@ static int configuration_pre_save(void *opaque)
return 0;
}
-static int configuration_post_save(void *opaque)
+static void configuration_post_save(void *opaque)
{
SaveState *state = opaque;
g_free(state->capabilities);
state->capabilities = NULL;
state->caps_count = 0;
- return 0;
}
static int configuration_pre_load(void *opaque)
diff --git a/migration/vmstate.c b/migration/vmstate.c
index 651c3fe011..5111e7a141 100644
--- a/migration/vmstate.c
+++ b/migration/vmstate.c
@@ -550,10 +550,7 @@ static int vmstate_save_state_v(QEMUFile *f, const VMStateDescription *vmsd,
if (ret) {
error_prepend(errp, "Save of field %s/%s failed: ",
vmsd->name, field->name);
- if (vmsd->post_save) {
- vmsd->post_save(opaque);
- }
- return ret;
+ goto out;
}
/* Compressed arrays only care about the first element */
@@ -578,12 +575,9 @@ static int vmstate_save_state_v(QEMUFile *f, const VMStateDescription *vmsd,
ret = vmstate_subsection_save(f, vmsd, opaque, vmdesc, errp);
+out:
if (vmsd->post_save) {
- int ps_ret = vmsd->post_save(opaque);
- if (!ret && ps_ret) {
- ret = ps_ret;
- error_setg(errp, "post-save failed: %s", vmsd->name);
- }
+ vmsd->post_save(opaque);
}
return ret;
}
diff --git a/target/arm/machine.c b/target/arm/machine.c
index bbaae34449..de810220e2 100644
--- a/target/arm/machine.c
+++ b/target/arm/machine.c
@@ -993,15 +993,13 @@ static int cpu_pre_save(void *opaque)
return 0;
}
-static int cpu_post_save(void *opaque)
+static void cpu_post_save(void *opaque)
{
ARMCPU *cpu = opaque;
if (!kvm_enabled()) {
pmu_op_finish(&cpu->env);
}
-
- return 0;
}
static int cpu_pre_load(void *opaque)
--
2.52.0
^ permalink raw reply related [flat|nested] 4+ messages in thread
* Re: [PATCH v2 03/16] migration: make .post_save() a void function
2026-02-20 21:02 ` [PATCH v2 03/16] migration: make .post_save() a void function Vladimir Sementsov-Ogievskiy
@ 2026-02-27 22:41 ` Fabiano Rosas
2026-02-27 23:56 ` Vladimir Sementsov-Ogievskiy
0 siblings, 1 reply; 4+ messages in thread
From: Fabiano Rosas @ 2026-02-27 22:41 UTC (permalink / raw)
To: Vladimir Sementsov-Ogievskiy, peterx
Cc: vsementsov, Pierrick Bouvier, Nicholas Piggin, Harsh Prateek Bora,
Peter Maydell, open list:All patches CC here,
open list:sPAPR (pseries), open list:ARM TCG CPUs
Vladimir Sementsov-Ogievskiy <vsementsov@yandex-team.ru> writes:
> All other handlers now have _errp() variants. Should we go this way
> for .post_save()? Actually it's rather strange, when the vmstate do
> successful preparations in .pre_save(), then successfully save all
> sections and subsections, end then fail when all the state is
> successfully transferred to the target.
>
> Happily, we have only three .post_save() realizations, all always
> successful. Let's make this a rule.
>
> Also note, that we call .post_save() in two places, and handle
> its (theoretical) failure inconsistently. Fix that too.
>
> Signed-off-by: Vladimir Sementsov-Ogievskiy <vsementsov@yandex-team.ru>
> ---
> docs/devel/migration/main.rst | 2 +-
> hw/ppc/spapr_pci.c | 3 +--
> include/migration/vmstate.h | 10 +++++++++-
> migration/savevm.c | 3 +--
> migration/vmstate.c | 12 +++---------
> target/arm/machine.c | 4 +---
> 6 files changed, 16 insertions(+), 18 deletions(-)
>
> diff --git a/docs/devel/migration/main.rst b/docs/devel/migration/main.rst
> index 234d280249..2de7050764 100644
> --- a/docs/devel/migration/main.rst
> +++ b/docs/devel/migration/main.rst
> @@ -439,7 +439,7 @@ The functions to do that are inside a vmstate definition, and are called:
>
> This function is called before we save the state of one device.
>
> -- ``int (*post_save)(void *opaque);``
> +- ``void (*post_save)(void *opaque);``
>
> This function is called after we save the state of one device
> (even upon failure, unless the call to pre_save returned an error).
> diff --git a/hw/ppc/spapr_pci.c b/hw/ppc/spapr_pci.c
> index ea998bdff1..1dc3b02659 100644
> --- a/hw/ppc/spapr_pci.c
> +++ b/hw/ppc/spapr_pci.c
> @@ -2093,14 +2093,13 @@ static int spapr_pci_pre_save(void *opaque)
> return 0;
> }
>
> -static int spapr_pci_post_save(void *opaque)
> +static void spapr_pci_post_save(void *opaque)
> {
> SpaprPhbState *sphb = opaque;
>
> g_free(sphb->msi_devs);
> sphb->msi_devs = NULL;
> sphb->msi_devs_num = 0;
> - return 0;
> }
>
> static int spapr_pci_post_load(void *opaque, int version_id)
> diff --git a/include/migration/vmstate.h b/include/migration/vmstate.h
> index 3695afd483..15578b3e28 100644
> --- a/include/migration/vmstate.h
> +++ b/include/migration/vmstate.h
> @@ -223,7 +223,15 @@ struct VMStateDescription {
> bool (*post_load_errp)(void *opaque, int version_id, Error **errp);
> int (*pre_save)(void *opaque);
> bool (*pre_save_errp)(void *opaque, Error **errp);
> - int (*post_save)(void *opaque);
> +
> + /*
> + * post_save() rarely used to free some temporary resources.
> + * It's is called if .pre_save[_errp]() call was successful
> + * (or .pre_save[_errp] handler absent), regardless success
> + * or failure during fields and subsections save. If
> + * .pre_save[_errp]() fails, .post_save() is not called.
> + */
I would not mention usage directly and maybe also simplify the language
a bit. If there's doubt on the exact flow, people can read the code:
/*
* Unless .pre_save() fails, post_save() is called after saving
* fields and subsections. It should not fail because at this point
* the state has potentially already been transferred.
*/
> + void (*post_save)(void *opaque);
> bool (*needed)(void *opaque);
> bool (*dev_unplug_pending)(void *opaque);
>
> diff --git a/migration/savevm.c b/migration/savevm.c
> index 3a16c467b2..c5236e71ba 100644
> --- a/migration/savevm.c
> +++ b/migration/savevm.c
> @@ -321,14 +321,13 @@ static int configuration_pre_save(void *opaque)
> return 0;
> }
>
> -static int configuration_post_save(void *opaque)
> +static void configuration_post_save(void *opaque)
> {
> SaveState *state = opaque;
>
> g_free(state->capabilities);
> state->capabilities = NULL;
> state->caps_count = 0;
> - return 0;
> }
>
> static int configuration_pre_load(void *opaque)
> diff --git a/migration/vmstate.c b/migration/vmstate.c
> index 651c3fe011..5111e7a141 100644
> --- a/migration/vmstate.c
> +++ b/migration/vmstate.c
> @@ -550,10 +550,7 @@ static int vmstate_save_state_v(QEMUFile *f, const VMStateDescription *vmsd,
> if (ret) {
> error_prepend(errp, "Save of field %s/%s failed: ",
> vmsd->name, field->name);
> - if (vmsd->post_save) {
> - vmsd->post_save(opaque);
> - }
> - return ret;
> + goto out;
> }
>
> /* Compressed arrays only care about the first element */
> @@ -578,12 +575,9 @@ static int vmstate_save_state_v(QEMUFile *f, const VMStateDescription *vmsd,
>
> ret = vmstate_subsection_save(f, vmsd, opaque, vmdesc, errp);
>
> +out:
> if (vmsd->post_save) {
> - int ps_ret = vmsd->post_save(opaque);
> - if (!ret && ps_ret) {
> - ret = ps_ret;
> - error_setg(errp, "post-save failed: %s", vmsd->name);
> - }
> + vmsd->post_save(opaque);
Nice cleanup.
> }
> return ret;
> }
> diff --git a/target/arm/machine.c b/target/arm/machine.c
> index bbaae34449..de810220e2 100644
> --- a/target/arm/machine.c
> +++ b/target/arm/machine.c
> @@ -993,15 +993,13 @@ static int cpu_pre_save(void *opaque)
> return 0;
> }
>
> -static int cpu_post_save(void *opaque)
> +static void cpu_post_save(void *opaque)
> {
> ARMCPU *cpu = opaque;
>
> if (!kvm_enabled()) {
> pmu_op_finish(&cpu->env);
> }
> -
> - return 0;
> }
>
> static int cpu_pre_load(void *opaque)
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [PATCH v2 03/16] migration: make .post_save() a void function
2026-02-27 22:41 ` Fabiano Rosas
@ 2026-02-27 23:56 ` Vladimir Sementsov-Ogievskiy
2026-03-03 15:05 ` Peter Xu
0 siblings, 1 reply; 4+ messages in thread
From: Vladimir Sementsov-Ogievskiy @ 2026-02-27 23:56 UTC (permalink / raw)
To: Fabiano Rosas, peterx
Cc: Pierrick Bouvier, Nicholas Piggin, Harsh Prateek Bora,
Peter Maydell, open list:All patches CC here,
open list:sPAPR (pseries), open list:ARM TCG CPUs
On 28.02.26 01:41, Fabiano Rosas wrote:
>> diff --git a/include/migration/vmstate.h b/include/migration/vmstate.h
>> index 3695afd483..15578b3e28 100644
>> --- a/include/migration/vmstate.h
>> +++ b/include/migration/vmstate.h
>> @@ -223,7 +223,15 @@ struct VMStateDescription {
>> bool (*post_load_errp)(void *opaque, int version_id, Error **errp);
>> int (*pre_save)(void *opaque);
>> bool (*pre_save_errp)(void *opaque, Error **errp);
>> - int (*post_save)(void *opaque);
>> +
>> + /*
>> + * post_save() rarely used to free some temporary resources.
>> + * It's is called if .pre_save[_errp]() call was successful
>> + * (or .pre_save[_errp] handler absent), regardless success
>> + * or failure during fields and subsections save. If
>> + * .pre_save[_errp]() fails, .post_save() is not called.
>> + */
> I would not mention usage directly and maybe also simplify the language
> a bit. If there's doubt on the exact flow, people can read the code:
>
> /*
> * Unless .pre_save() fails, post_save() is called after saving
> * fields and subsections. It should not fail because at this point
> * the state has potentially already been transferred.
> */
Agree, sounds good.
--
Best regards,
Vladimir
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [PATCH v2 03/16] migration: make .post_save() a void function
2026-02-27 23:56 ` Vladimir Sementsov-Ogievskiy
@ 2026-03-03 15:05 ` Peter Xu
0 siblings, 0 replies; 4+ messages in thread
From: Peter Xu @ 2026-03-03 15:05 UTC (permalink / raw)
To: Vladimir Sementsov-Ogievskiy
Cc: Fabiano Rosas, Pierrick Bouvier, Nicholas Piggin,
Harsh Prateek Bora, Peter Maydell, open list:All patches CC here,
open list:sPAPR (pseries), open list:ARM TCG CPUs
On Sat, Feb 28, 2026 at 02:56:30AM +0300, Vladimir Sementsov-Ogievskiy wrote:
> On 28.02.26 01:41, Fabiano Rosas wrote:
> > > diff --git a/include/migration/vmstate.h b/include/migration/vmstate.h
> > > index 3695afd483..15578b3e28 100644
> > > --- a/include/migration/vmstate.h
> > > +++ b/include/migration/vmstate.h
> > > @@ -223,7 +223,15 @@ struct VMStateDescription {
> > > bool (*post_load_errp)(void *opaque, int version_id, Error **errp);
> > > int (*pre_save)(void *opaque);
> > > bool (*pre_save_errp)(void *opaque, Error **errp);
> > > - int (*post_save)(void *opaque);
> > > +
> > > + /*
> > > + * post_save() rarely used to free some temporary resources.
> > > + * It's is called if .pre_save[_errp]() call was successful
> > > + * (or .pre_save[_errp] handler absent), regardless success
> > > + * or failure during fields and subsections save. If
> > > + * .pre_save[_errp]() fails, .post_save() is not called.
> > > + */
> > I would not mention usage directly and maybe also simplify the language
> > a bit. If there's doubt on the exact flow, people can read the code:
> >
> > /*
> > * Unless .pre_save() fails, post_save() is called after saving
> > * fields and subsections. It should not fail because at this point
> > * the state has potentially already been transferred.
> > */
>
>
> Agree, sounds good.
With the update, feel free to take:
Reviewed-by: Peter Xu <peterx@redhat.com>
--
Peter Xu
^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~2026-03-03 15:07 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
[not found] <20260220210214.800050-1-vsementsov@yandex-team.ru>
2026-02-20 21:02 ` [PATCH v2 03/16] migration: make .post_save() a void function Vladimir Sementsov-Ogievskiy
2026-02-27 22:41 ` Fabiano Rosas
2026-02-27 23:56 ` Vladimir Sementsov-Ogievskiy
2026-03-03 15:05 ` Peter Xu
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox