rust: move VMState from bql to migration

The high-level wrapper Migratable<T> will contain a BqlCell,
which would introduce a circular dependency betwen the bql and
migration crates.  Move the implementation of VMState for cells
to "migration", together with the implementation for std types.

Reviewed-by: Zhao Liu <zhao1.liu@intel.com>
Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
This commit is contained in:
Paolo Bonzini 2025-10-09 10:24:54 +02:00
parent 8999ca00a4
commit 4526418aff
8 changed files with 7 additions and 12 deletions

2
rust/Cargo.lock generated
View file

@ -59,7 +59,6 @@ name = "bql"
version = "0.1.0" version = "0.1.0"
dependencies = [ dependencies = [
"glib-sys", "glib-sys",
"migration",
] ]
[[package]] [[package]]
@ -198,6 +197,7 @@ checksum = "f52b00d39961fc5b2736ea853c9cc86238e165017a493d1d5c8eac6bdc4cc273"
name = "migration" name = "migration"
version = "0.1.0" version = "0.1.0"
dependencies = [ dependencies = [
"bql",
"common", "common",
"glib-sys", "glib-sys",
"util", "util",

View file

@ -13,7 +13,6 @@ repository.workspace = true
rust-version.workspace = true rust-version.workspace = true
[dependencies] [dependencies]
migration = { path = "../migration" }
glib-sys.workspace = true glib-sys.workspace = true
[features] [features]

View file

@ -37,7 +37,6 @@ _bql_rs = static_library(
override_options: ['rust_std=2021', 'build.rust_std=2021'], override_options: ['rust_std=2021', 'build.rust_std=2021'],
rust_abi: 'rust', rust_abi: 'rust',
rust_args: _bql_cfg, rust_args: _bql_cfg,
link_with: [_migration_rs],
dependencies: [glib_sys_rs], dependencies: [glib_sys_rs],
) )

View file

@ -151,8 +151,6 @@ use std::{
ptr::NonNull, ptr::NonNull,
}; };
use migration::impl_vmstate_transparent;
/// A mutable memory location that is protected by the Big QEMU Lock. /// A mutable memory location that is protected by the Big QEMU Lock.
/// ///
/// # Memory layout /// # Memory layout
@ -364,8 +362,6 @@ impl<T: Default> BqlCell<T> {
} }
} }
impl_vmstate_transparent!(crate::cell::BqlCell<T> where T: VMState);
/// A mutable memory location with dynamically checked borrow rules, /// A mutable memory location with dynamically checked borrow rules,
/// protected by the Big QEMU Lock. /// protected by the Big QEMU Lock.
/// ///
@ -691,8 +687,6 @@ impl<T> From<T> for BqlRefCell<T> {
} }
} }
impl_vmstate_transparent!(crate::cell::BqlRefCell<T> where T: VMState);
struct BorrowRef<'b> { struct BorrowRef<'b> {
borrow: &'b Cell<BorrowFlag>, borrow: &'b Cell<BorrowFlag>,
} }

View file

@ -29,8 +29,8 @@ subdir('qemu-macros')
subdir('common') subdir('common')
subdir('bits') subdir('bits')
subdir('util') subdir('util')
subdir('migration')
subdir('bql') subdir('bql')
subdir('migration')
subdir('qom') subdir('qom')
subdir('system') subdir('system')
subdir('chardev') subdir('chardev')

View file

@ -13,6 +13,7 @@ repository.workspace = true
rust-version.workspace = true rust-version.workspace = true
[dependencies] [dependencies]
bql = { path = "../bql" }
common = { path = "../common" } common = { path = "../common" }
util = { path = "../util" } util = { path = "../util" }
glib-sys.workspace = true glib-sys.workspace = true

View file

@ -37,12 +37,12 @@ _migration_rs = static_library(
), ),
override_options: ['rust_std=2021', 'build.rust_std=2021'], override_options: ['rust_std=2021', 'build.rust_std=2021'],
rust_abi: 'rust', rust_abi: 'rust',
link_with: [_util_rs], link_with: [_util_rs, _bql_rs],
dependencies: [common_rs, glib_sys_rs], dependencies: [common_rs, glib_sys_rs],
) )
migration_rs = declare_dependency(link_with: [_migration_rs], migration_rs = declare_dependency(link_with: [_migration_rs],
dependencies: [migration, qemuutil]) dependencies: [bql_rs, migration, qemuutil])
# Doctests are essentially integration tests, so they need the same dependencies. # Doctests are essentially integration tests, so they need the same dependencies.
# Note that running them requires the object files for C code, so place them # Note that running them requires the object files for C code, so place them

View file

@ -276,6 +276,8 @@ macro_rules! impl_vmstate_transparent {
}; };
} }
impl_vmstate_transparent!(bql::BqlCell<T> where T: VMState);
impl_vmstate_transparent!(bql::BqlRefCell<T> where T: VMState);
impl_vmstate_transparent!(std::cell::Cell<T> where T: VMState); impl_vmstate_transparent!(std::cell::Cell<T> where T: VMState);
impl_vmstate_transparent!(std::cell::UnsafeCell<T> where T: VMState); impl_vmstate_transparent!(std::cell::UnsafeCell<T> where T: VMState);
impl_vmstate_transparent!(std::pin::Pin<T> where T: VMState); impl_vmstate_transparent!(std::pin::Pin<T> where T: VMState);