vmm: Version MemoryManager state

Signed-off-by: Rob Bradford <robert.bradford@intel.com>
This commit is contained in:
Rob Bradford 2021-05-21 12:50:41 +00:00 committed by Sebastien Boeuf
parent 719e36049b
commit f840327ffb
3 changed files with 13 additions and 9 deletions

2
Cargo.lock generated
View File

@ -1293,6 +1293,8 @@ dependencies = [
"serde_json",
"signal-hook",
"thiserror",
"versionize",
"versionize_derive",
"vfio-ioctls",
"virtio-devices",
"vm-allocator",

View File

@ -41,6 +41,8 @@ serde_derive = ">=1.0.27"
serde_json = ">=1.0.9"
signal-hook = "0.3.8"
thiserror = "1.0"
versionize = "0.1.6"
versionize_derive = "0.1.4"
vfio-ioctls = { git = "https://github.com/rust-vmm/vfio-ioctls", branch = "master" }
virtio-devices = { path = "../virtio-devices" }
vm-allocator = { path = "../vm-allocator" }

View File

@ -27,6 +27,8 @@ use std::os::unix::io::{AsRawFd, FromRawFd, RawFd};
use std::path::PathBuf;
use std::result;
use std::sync::{Arc, Barrier, Mutex};
use versionize::{VersionMap, Versionize, VersionizeResult};
use versionize_derive::Versionize;
#[cfg(target_arch = "x86_64")]
use vm_allocator::GsiApic;
use vm_allocator::SystemAllocator;
@ -40,7 +42,7 @@ use vm_memory::{
use vm_migration::{
protocol::{MemoryRange, MemoryRangeTable},
Migratable, MigratableError, Pausable, Snapshot, SnapshotDataSection, Snapshottable,
Transportable,
Transportable, VersionMapped,
};
#[cfg(feature = "acpi")]
@ -846,7 +848,7 @@ impl MemoryManager {
let vm_snapshot_path = url_to_path(source_url).map_err(Error::Restore)?;
let mem_snapshot: MemoryManagerSnapshotData = snapshot
.to_state(MEMORY_MANAGER_SNAPSHOT_ID)
.to_versioned_state(MEMORY_MANAGER_SNAPSHOT_ID)
.map_err(Error::Restore)?;
// Here we turn the content file name into a content file path as
@ -1914,22 +1916,20 @@ impl Aml for MemoryManager {
impl Pausable for MemoryManager {}
#[derive(Serialize, Deserialize)]
#[serde(remote = "GuestAddress")]
pub struct GuestAddressDef(pub u64);
#[derive(Clone, Serialize, Deserialize)]
#[derive(Clone, Versionize)]
pub struct MemoryRegion {
content: Option<String>,
start_addr: u64,
size: u64,
}
#[derive(Serialize, Deserialize)]
#[derive(Versionize)]
pub struct MemoryManagerSnapshotData {
memory_regions: Vec<MemoryRegion>,
}
impl VersionMapped for MemoryManagerSnapshotData {}
impl Snapshottable for MemoryManager {
fn id(&self) -> String {
MEMORY_MANAGER_SNAPSHOT_ID.to_string()
@ -1983,7 +1983,7 @@ impl Snapshottable for MemoryManager {
// memory region content for the regions requiring it.
self.snapshot_memory_regions = memory_regions.clone();
memory_manager_snapshot.add_data_section(SnapshotDataSection::new_from_state(
memory_manager_snapshot.add_data_section(SnapshotDataSection::new_from_versioned_state(
MEMORY_MANAGER_SNAPSHOT_ID,
&MemoryManagerSnapshotData { memory_regions },
)?);