From f840327ffbdcd5daf893ec8e836c94ffb5c6b912 Mon Sep 17 00:00:00 2001 From: Rob Bradford Date: Fri, 21 May 2021 12:50:41 +0000 Subject: [PATCH] vmm: Version MemoryManager state Signed-off-by: Rob Bradford --- Cargo.lock | 2 ++ vmm/Cargo.toml | 2 ++ vmm/src/memory_manager.rs | 18 +++++++++--------- 3 files changed, 13 insertions(+), 9 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 975ef5190..c97e5d742 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1293,6 +1293,8 @@ dependencies = [ "serde_json", "signal-hook", "thiserror", + "versionize", + "versionize_derive", "vfio-ioctls", "virtio-devices", "vm-allocator", diff --git a/vmm/Cargo.toml b/vmm/Cargo.toml index ef3961ef6..c75a753d3 100644 --- a/vmm/Cargo.toml +++ b/vmm/Cargo.toml @@ -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" } diff --git a/vmm/src/memory_manager.rs b/vmm/src/memory_manager.rs index a60b3d171..2113dfe6a 100644 --- a/vmm/src/memory_manager.rs +++ b/vmm/src/memory_manager.rs @@ -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, start_addr: u64, size: u64, } -#[derive(Serialize, Deserialize)] +#[derive(Versionize)] pub struct MemoryManagerSnapshotData { memory_regions: Vec, } +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 }, )?);