[PATCH 7/7] rust: migration: implement ToMigrationState as part of impl_vmstate_bitsized

Paolo Bonzini posted 7 patches 4 months, 3 weeks ago
Maintainers: Manos Pitsidianakis <manos.pitsidianakis@linaro.org>
There is a newer version of this series
[PATCH 7/7] rust: migration: implement ToMigrationState as part of impl_vmstate_bitsized
Posted by Paolo Bonzini 4 months, 3 weeks ago
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.

Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
---
 rust/migration/src/vmstate.rs | 19 +++++++++++++++++++
 1 file changed, 19 insertions(+)

diff --git a/rust/migration/src/vmstate.rs b/rust/migration/src/vmstate.rs
index 421a236194d..882dab746fc 100644
--- a/rust/migration/src/vmstate.rs
+++ b/rust/migration/src/vmstate.rs
@@ -295,6 +295,25 @@ unsafe impl $crate::vmstate::VMState for $type {
                                           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(())
+            }
+        }
     };
 }
 
-- 
2.51.0
Re: [PATCH 7/7] rust: migration: implement ToMigrationState as part of impl_vmstate_bitsized
Posted by Zhao Liu 4 months, 1 week ago
On Sat, Sep 20, 2025 at 04:29:58PM +0200, Paolo Bonzini wrote:
> Date: Sat, 20 Sep 2025 16:29:58 +0200
> From: Paolo Bonzini <pbonzini@redhat.com>
> Subject: [PATCH 7/7] rust: migration: implement ToMigrationState as part of
>  impl_vmstate_bitsized
> X-Mailer: git-send-email 2.51.0
> 
> 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.
> 
> Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
> ---
>  rust/migration/src/vmstate.rs | 19 +++++++++++++++++++
>  1 file changed, 19 insertions(+)

Reviewed-by: Zhao Liu <zhao1.liu@intel.com>