]> git.ipfire.org Git - thirdparty/qemu.git/commitdiff
rust: migration: implement ToMigrationState as part of impl_vmstate_bitsized
authorPaolo Bonzini <pbonzini@redhat.com>
Fri, 19 Sep 2025 09:18:44 +0000 (11:18 +0200)
committerPaolo Bonzini <pbonzini@redhat.com>
Tue, 14 Oct 2025 12:43:54 +0000 (14:43 +0200)
This is most likely desirable, and is the easiest way to migrate
a bit-sized value without peeking at the innards of the bilge crate.

Reviewed-by: Zhao Liu <zhao1.liu@intel.com>
Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
rust/migration/src/vmstate.rs

index 445fe7fbc08a42aefa03bc8a6783254e4211ba4c..42e5df8d818ffd500c92073d32a1438b4bf6325a 100644 (file)
@@ -296,6 +296,25 @@ macro_rules! impl_vmstate_bitsized {
                                           as ::bilge::prelude::Number>::UnderlyingType
                                          as $crate::vmstate::VMState>::VARRAY_FLAG;
         }
+
+        impl $crate::migratable::ToMigrationState for $type {
+            type Migrated = <<$type as ::bilge::prelude::Bitsized>::ArbitraryInt
+                                          as ::bilge::prelude::Number>::UnderlyingType;
+
+            fn snapshot_migration_state(&self, target: &mut Self::Migrated) -> Result<(), $crate::InvalidError> {
+                *target = Self::Migrated::from(*self);
+                Ok(())
+            }
+
+            fn restore_migrated_state_mut(
+                &mut self,
+                source: Self::Migrated,
+                version_id: u8,
+            ) -> Result<(), $crate::InvalidError> {
+                *self = Self::from(source);
+                Ok(())
+            }
+        }
     };
 }