On Wed, Oct 01, 2025 at 09:52:06AM +0200, Paolo Bonzini wrote: > Date: Wed, 1 Oct 2025 09:52:06 +0200 > From: Paolo Bonzini <[email protected]> > Subject: [PATCH 07/11] rust: migration: add high-level migration wrappers > X-Mailer: git-send-email 2.51.0 > > Instead of dealing with pre/post callbacks, allow devices to > implement a snapshot/restore mechanism; this has two main > advantages: > > - it can be easily implemented via procedural macros > > - there can be generic implementations to deal with various > kinds of interior-mutable containers, from BqlRefCell to Mutex, > so that C code does not see Rust concepts such as Mutex<>. > > Using it is easy; you can implement the snapshot/restore trait > ToMigrationState and declare your state like: > > regs: Migratable<Mutex<MyDeviceRegisters>> > > Migratable<> allows dereferencing to the underlying object with > no run-time cost. > > Note that Migratable<> actually does not accept ToMigrationState, > only the similar ToMigrationStateShared trait that the user will mostly > not care about. This is required by the fact that pre/post callbacks > take a &self, and ensures that the argument is a Mutex or BqlRefCell > (including an array or Arc<> thereof). > > Signed-off-by: Paolo Bonzini <[email protected]> > --- > docs/devel/rust.rst | 1 + > rust/migration/meson.build | 1 + > rust/migration/src/lib.rs | 3 + > rust/migration/src/migratable.rs | 434 +++++++++++++++++++++++++++++++ > 4 files changed, 439 insertions(+) > create mode 100644 rust/migration/src/migratable.rs
Reviewed-by: Zhao Liu <[email protected]>
