[PATCH] migration: check is_active for old-style vmstate

Yanfei Xu posted 1 patch 3 weeks, 6 days ago
Patches applied successfully (tree, apply log)
git fetch https://github.com/patchew-project/qemu tags/patchew/20260311051658.1074299-1-yanfei.xu@bytedance.com
Maintainers: Peter Xu <peterx@redhat.com>, Fabiano Rosas <farosas@suse.de>
migration/savevm.c | 14 +++++++++++++-
1 file changed, 13 insertions(+), 1 deletion(-)
[PATCH] migration: check is_active for old-style vmstate
Posted by Yanfei Xu 3 weeks, 6 days ago
old-style vmstate doesn't use vmsd and instead rely on SaveStateEntry
ops. Check is_active for old-style vmstate to determine whether they
should be skipped during migration.

Signed-off-by: Yanfei Xu <yanfei.xu@bytedance.com>
---
 migration/savevm.c | 14 +++++++++++++-
 1 file changed, 13 insertions(+), 1 deletion(-)

diff --git a/migration/savevm.c b/migration/savevm.c
index 197c89e0e6..7eee83ffca 100644
--- a/migration/savevm.c
+++ b/migration/savevm.c
@@ -1030,15 +1030,27 @@ static int vmstate_save(QEMUFile *f, SaveStateEntry *se, JSONWriter *vmdesc,
                         Error **errp)
 {
     int ret;
+    const bool has_old_style = se->ops && se->ops->save_state;
 
-    if ((!se->ops || !se->ops->save_state) && !se->vmsd) {
+    if (!has_old_style && !se->vmsd) {
         return 0;
+    } else if (has_old_style && se->vmsd) {
+        error_report("%s: '%s' (section_id=%u): unexpected: both vmsd (%s) and"
+                     " old-style save_state are set", __func__, se->idstr,
+                     se->section_id, se->vmsd->name);
+        return -EINVAL;
     }
+
     if (se->vmsd && !vmstate_section_needed(se->vmsd, se->opaque)) {
         trace_savevm_section_skip(se->idstr, se->section_id);
         return 0;
     }
 
+    if (has_old_style && se->ops->is_active && !se->ops->is_active(se->opaque)) {
+        trace_savevm_section_skip(se->idstr, se->section_id);
+        return 0;
+    }
+
     trace_savevm_section_start(se->idstr, se->section_id);
     save_section_header(f, se, QEMU_VM_SECTION_FULL);
     if (vmdesc) {
-- 
2.20.1
Re: [PATCH] migration: check is_active for old-style vmstate
Posted by Peter Xu 3 weeks, 6 days ago
On Wed, Mar 11, 2026 at 01:16:58PM +0800, Yanfei Xu wrote:
> old-style vmstate doesn't use vmsd and instead rely on SaveStateEntry
> ops. Check is_active for old-style vmstate to determine whether they
> should be skipped during migration.

Would you please dscribe the use case?

We only have two users in upstream tree that provided is_active(), and
neither of them provided save_state().  IOW, so far it works kind of mutual
exclusively v.s. save_state(), afaict.

> 
> Signed-off-by: Yanfei Xu <yanfei.xu@bytedance.com>
> ---
>  migration/savevm.c | 14 +++++++++++++-
>  1 file changed, 13 insertions(+), 1 deletion(-)
> 
> diff --git a/migration/savevm.c b/migration/savevm.c
> index 197c89e0e6..7eee83ffca 100644
> --- a/migration/savevm.c
> +++ b/migration/savevm.c
> @@ -1030,15 +1030,27 @@ static int vmstate_save(QEMUFile *f, SaveStateEntry *se, JSONWriter *vmdesc,
>                          Error **errp)
>  {
>      int ret;
> +    const bool has_old_style = se->ops && se->ops->save_state;
>  
> -    if ((!se->ops || !se->ops->save_state) && !se->vmsd) {
> +    if (!has_old_style && !se->vmsd) {
>          return 0;
> +    } else if (has_old_style && se->vmsd) {
> +        error_report("%s: '%s' (section_id=%u): unexpected: both vmsd (%s) and"
> +                     " old-style save_state are set", __func__, se->idstr,
> +                     se->section_id, se->vmsd->name);
> +        return -EINVAL;
>      }
> +
>      if (se->vmsd && !vmstate_section_needed(se->vmsd, se->opaque)) {
>          trace_savevm_section_skip(se->idstr, se->section_id);
>          return 0;
>      }
>  
> +    if (has_old_style && se->ops->is_active && !se->ops->is_active(se->opaque)) {
> +        trace_savevm_section_skip(se->idstr, se->section_id);
> +        return 0;
> +    }
> +
>      trace_savevm_section_start(se->idstr, se->section_id);
>      save_section_header(f, se, QEMU_VM_SECTION_FULL);
>      if (vmdesc) {
> -- 
> 2.20.1
> 

-- 
Peter Xu