misc: Migrate away from versionize

Replace with serde instead.

Fixes: #6370

Signed-off-by: Rob Bradford <rbradford@rivosinc.com>
This commit is contained in:
Rob Bradford 2024-04-07 14:28:07 +01:00 committed by Bo Chen
parent dad55fcef2
commit 10ab87d6a3
45 changed files with 219 additions and 471 deletions

61
Cargo.lock generated
View File

@ -115,8 +115,6 @@ dependencies = [
"serde", "serde",
"thiserror", "thiserror",
"uuid", "uuid",
"versionize",
"versionize_derive",
"vm-fdt", "vm-fdt",
"vm-memory", "vm-memory",
"vm-migration", "vm-migration",
@ -320,15 +318,6 @@ dependencies = [
"rustc-demangle", "rustc-demangle",
] ]
[[package]]
name = "bincode"
version = "1.3.3"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "b1f45e9417d87227c7a56d22e471c6206462cba514c7590c09aff4cf6d1ddcad"
dependencies = [
"serde",
]
[[package]] [[package]]
name = "bitfield-struct" name = "bitfield-struct"
version = "0.5.6" version = "0.5.6"
@ -362,11 +351,10 @@ dependencies = [
"libc", "libc",
"log", "log",
"remain", "remain",
"serde",
"smallvec", "smallvec",
"thiserror", "thiserror",
"uuid", "uuid",
"versionize",
"versionize_derive",
"virtio-bindings", "virtio-bindings",
"virtio-queue", "virtio-queue",
"vm-memory", "vm-memory",
@ -524,12 +512,6 @@ dependencies = [
"cfg-if", "cfg-if",
] ]
[[package]]
name = "crc64"
version = "2.0.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "2707e3afba5e19b75d582d88bc79237418f2a2a2d673d01cf9b03633b46e98f3"
[[package]] [[package]]
name = "crossbeam-utils" name = "crossbeam-utils"
version = "0.8.19" version = "0.8.19"
@ -612,10 +594,9 @@ dependencies = [
"libc", "libc",
"log", "log",
"pci", "pci",
"serde",
"thiserror", "thiserror",
"tpm", "tpm",
"versionize",
"versionize_derive",
"vm-allocator", "vm-allocator",
"vm-device", "vm-device",
"vm-memory", "vm-memory",
@ -1396,8 +1377,6 @@ dependencies = [
"serde", "serde",
"serde_json", "serde_json",
"thiserror", "thiserror",
"versionize",
"versionize_derive",
"virtio-bindings", "virtio-bindings",
"virtio-queue", "virtio-queue",
"vm-memory", "vm-memory",
@ -1600,8 +1579,6 @@ dependencies = [
"log", "log",
"serde", "serde",
"thiserror", "thiserror",
"versionize",
"versionize_derive",
"vfio-bindings", "vfio-bindings",
"vfio-ioctls", "vfio-ioctls",
"vfio_user", "vfio_user",
@ -2356,33 +2333,6 @@ version = "0.9.4"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "49874b5167b65d7193b8aba1567f5c7d93d001cafc34600cee003eda787e483f" checksum = "49874b5167b65d7193b8aba1567f5c7d93d001cafc34600cee003eda787e483f"
[[package]]
name = "versionize"
version = "0.2.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "62929d59c7f6730b7298fcb363760550f4db6e353fbac4076d447d0e82799d6d"
dependencies = [
"bincode",
"crc64",
"proc-macro2",
"quote",
"serde",
"serde_derive",
"syn 1.0.109",
"versionize_derive",
"vmm-sys-util",
]
[[package]]
name = "versionize_derive"
version = "0.1.6"
source = "git+https://github.com/cloud-hypervisor/versionize_derive?branch=ch-0.1.6#7906da996152e2d0ab08f5526440683bf3ca7834"
dependencies = [
"proc-macro2",
"quote",
"syn 1.0.109",
]
[[package]] [[package]]
name = "vfio-bindings" name = "vfio-bindings"
version = "0.4.0" version = "0.4.0"
@ -2515,10 +2465,9 @@ dependencies = [
"seccompiler", "seccompiler",
"serde", "serde",
"serde_json", "serde_json",
"serde_with",
"serial_buffer", "serial_buffer",
"thiserror", "thiserror",
"versionize",
"versionize_derive",
"vhost", "vhost",
"virtio-bindings", "virtio-bindings",
"virtio-queue", "virtio-queue",
@ -2589,8 +2538,6 @@ dependencies = [
"serde", "serde",
"serde_json", "serde_json",
"thiserror", "thiserror",
"versionize",
"versionize_derive",
"vm-memory", "vm-memory",
] ]
@ -2646,8 +2593,6 @@ dependencies = [
"thiserror", "thiserror",
"tracer", "tracer",
"uuid", "uuid",
"versionize",
"versionize_derive",
"vfio-ioctls", "vfio-ioctls",
"vfio_user", "vfio_user",
"virtio-devices", "virtio-devices",

View File

@ -53,7 +53,6 @@ zbus = { version = "3.15.2", optional = true }
# List of patched crates # List of patched crates
[patch.crates-io] [patch.crates-io]
kvm-bindings = { git = "https://github.com/cloud-hypervisor/kvm-bindings", branch = "ch-v0.7.0" } kvm-bindings = { git = "https://github.com/cloud-hypervisor/kvm-bindings", branch = "ch-v0.7.0" }
versionize_derive = { git = "https://github.com/cloud-hypervisor/versionize_derive", branch = "ch-0.1.6" }
[dev-dependencies] [dev-dependencies]
dirs = "5.0.1" dirs = "5.0.1"

View File

@ -19,8 +19,6 @@ log = "0.4.21"
serde = { version = "1.0.197", features = ["rc", "derive"] } serde = { version = "1.0.197", features = ["rc", "derive"] }
thiserror = "1.0.58" thiserror = "1.0.58"
uuid = "1.8.0" uuid = "1.8.0"
versionize = "0.2.0"
versionize_derive = "0.1.6"
vm-memory = { version = "0.14.1", features = ["backend-mmap", "backend-bitmap"] } vm-memory = { version = "0.14.1", features = ["backend-mmap", "backend-bitmap"] }
vm-migration = { path = "../vm-migration" } vm-migration = { path = "../vm-migration" }
vmm-sys-util = { version = "0.12.1", features = ["with-serde"] } vmm-sys-util = { version = "0.12.1", features = ["with-serde"] }

View File

@ -18,9 +18,6 @@ use std::fmt;
use std::result; use std::result;
use std::sync::Arc; use std::sync::Arc;
use thiserror::Error; use thiserror::Error;
use versionize::{VersionMap, Versionize, VersionizeError, VersionizeResult};
use versionize_derive::Versionize;
use vm_migration::VersionMapped;
type GuestMemoryMmap = vm_memory::GuestMemoryMmap<vm_memory::bitmap::AtomicBitmap>; type GuestMemoryMmap = vm_memory::GuestMemoryMmap<vm_memory::bitmap::AtomicBitmap>;
type GuestRegionMmap = vm_memory::GuestRegionMmap<vm_memory::bitmap::AtomicBitmap>; type GuestRegionMmap = vm_memory::GuestRegionMmap<vm_memory::bitmap::AtomicBitmap>;
@ -58,7 +55,7 @@ pub enum Error {
pub type Result<T> = result::Result<T, Error>; pub type Result<T> = result::Result<T, Error>;
/// Type for memory region types. /// Type for memory region types.
#[derive(Clone, Copy, PartialEq, Eq, Debug, Serialize, Deserialize, Versionize)] #[derive(Clone, Copy, PartialEq, Eq, Debug, Serialize, Deserialize)]
pub enum RegionType { pub enum RegionType {
/// RAM type /// RAM type
Ram, Ram,
@ -76,8 +73,6 @@ pub enum RegionType {
Reserved, Reserved,
} }
impl VersionMapped for RegionType {}
/// Module for aarch64 related functionality. /// Module for aarch64 related functionality.
#[cfg(target_arch = "aarch64")] #[cfg(target_arch = "aarch64")]
pub mod aarch64; pub mod aarch64;

View File

@ -15,11 +15,10 @@ io-uring = { version = "0.6.3", optional = true }
libc = "0.2.153" libc = "0.2.153"
log = "0.4.21" log = "0.4.21"
remain = "0.2.13" remain = "0.2.13"
serde = { version = "1.0.197", features = ["derive"] }
smallvec = "1.13.2" smallvec = "1.13.2"
thiserror = "1.0.58" thiserror = "1.0.58"
uuid = { version = "1.8.0", features = ["v4"] } uuid = { version = "1.8.0", features = ["v4"] }
versionize = "0.2.0"
versionize_derive = "0.1.6"
virtio-bindings = { version = "0.2.2", features = ["virtio-v5_0_0"] } virtio-bindings = { version = "0.2.2", features = ["virtio-v5_0_0"] }
virtio-queue = "0.11.0" virtio-queue = "0.11.0"
vm-memory = { version = "0.14.1", features = ["backend-mmap", "backend-atomic", "backend-bitmap"] } vm-memory = { version = "0.14.1", features = ["backend-mmap", "backend-atomic", "backend-bitmap"] }

View File

@ -37,6 +37,7 @@ use crate::vhdx::{Vhdx, VhdxError};
#[cfg(feature = "io_uring")] #[cfg(feature = "io_uring")]
use io_uring::{opcode, IoUring, Probe}; use io_uring::{opcode, IoUring, Probe};
use libc::{ioctl, S_IFBLK, S_IFMT}; use libc::{ioctl, S_IFBLK, S_IFMT};
use serde::{Deserialize, Serialize};
use smallvec::SmallVec; use smallvec::SmallVec;
use std::alloc::{alloc_zeroed, dealloc, Layout}; use std::alloc::{alloc_zeroed, dealloc, Layout};
use std::cmp; use std::cmp;
@ -52,8 +53,6 @@ use std::sync::Arc;
use std::sync::MutexGuard; use std::sync::MutexGuard;
use std::time::Instant; use std::time::Instant;
use thiserror::Error; use thiserror::Error;
use versionize::{VersionMap, Versionize, VersionizeResult};
use versionize_derive::Versionize;
use virtio_bindings::virtio_blk::*; use virtio_bindings::virtio_blk::*;
use virtio_queue::DescriptorChain; use virtio_queue::DescriptorChain;
use vm_memory::{ use vm_memory::{
@ -544,7 +543,7 @@ impl Request {
} }
} }
#[derive(Copy, Clone, Debug, Default, Versionize)] #[derive(Copy, Clone, Debug, Default, Serialize, Deserialize)]
#[repr(C, packed)] #[repr(C, packed)]
pub struct VirtioBlockConfig { pub struct VirtioBlockConfig {
pub capacity: u64, pub capacity: u64,
@ -567,7 +566,7 @@ pub struct VirtioBlockConfig {
pub write_zeroes_may_unmap: u8, pub write_zeroes_may_unmap: u8,
pub unused1: [u8; 3], pub unused1: [u8; 3],
} }
#[derive(Copy, Clone, Debug, Default, Versionize)] #[derive(Copy, Clone, Debug, Default, Serialize, Deserialize)]
#[repr(C, packed)] #[repr(C, packed)]
pub struct VirtioBlockGeometry { pub struct VirtioBlockGeometry {
pub cylinders: u16, pub cylinders: u16,

View File

@ -15,10 +15,9 @@ hypervisor = { path = "../hypervisor" }
libc = "0.2.153" libc = "0.2.153"
log = "0.4.21" log = "0.4.21"
pci = { path = "../pci" } pci = { path = "../pci" }
serde = { version = "1.0.197", features = ["derive"] }
thiserror = "1.0.58" thiserror = "1.0.58"
tpm = { path = "../tpm" } tpm = { path = "../tpm" }
versionize = "0.2.0"
versionize_derive = "0.1.6"
vm-allocator = { path = "../vm-allocator" } vm-allocator = { path = "../vm-allocator" }
vm-device = { path = "../vm-device" } vm-device = { path = "../vm-device" }
vm-memory = "0.14.1" vm-memory = "0.14.1"

View File

@ -11,19 +11,16 @@
use super::interrupt_controller::{Error, InterruptController}; use super::interrupt_controller::{Error, InterruptController};
use byteorder::{ByteOrder, LittleEndian}; use byteorder::{ByteOrder, LittleEndian};
use serde::{Deserialize, Serialize};
use std::result; use std::result;
use std::sync::{Arc, Barrier}; use std::sync::{Arc, Barrier};
use versionize::{VersionMap, Versionize, VersionizeResult};
use versionize_derive::Versionize;
use vm_device::interrupt::{ use vm_device::interrupt::{
InterruptIndex, InterruptManager, InterruptSourceConfig, InterruptSourceGroup, InterruptIndex, InterruptManager, InterruptSourceConfig, InterruptSourceGroup,
MsiIrqGroupConfig, MsiIrqSourceConfig, MsiIrqGroupConfig, MsiIrqSourceConfig,
}; };
use vm_device::BusDevice; use vm_device::BusDevice;
use vm_memory::GuestAddress; use vm_memory::GuestAddress;
use vm_migration::{ use vm_migration::{Migratable, MigratableError, Pausable, Snapshot, Snapshottable, Transportable};
Migratable, MigratableError, Pausable, Snapshot, Snapshottable, Transportable, VersionMapped,
};
use vmm_sys_util::eventfd::EventFd; use vmm_sys_util::eventfd::EventFd;
type Result<T> = result::Result<T, Error>; type Result<T> = result::Result<T, Error>;
@ -136,7 +133,7 @@ pub struct Ioapic {
interrupt_source_group: Arc<dyn InterruptSourceGroup>, interrupt_source_group: Arc<dyn InterruptSourceGroup>,
} }
#[derive(Versionize)] #[derive(Serialize, Deserialize)]
pub struct IoapicState { pub struct IoapicState {
id_reg: u32, id_reg: u32,
reg_sel: u32, reg_sel: u32,
@ -144,7 +141,6 @@ pub struct IoapicState {
used_entries: [bool; NUM_IOAPIC_PINS], used_entries: [bool; NUM_IOAPIC_PINS],
apic_address: u64, apic_address: u64,
} }
impl VersionMapped for IoapicState {}
impl BusDevice for Ioapic { impl BusDevice for Ioapic {
fn read(&mut self, _base: u64, offset: u64, data: &mut [u8]) { fn read(&mut self, _base: u64, offset: u64, data: &mut [u8]) {
@ -444,7 +440,7 @@ impl Snapshottable for Ioapic {
} }
fn snapshot(&mut self) -> std::result::Result<Snapshot, MigratableError> { fn snapshot(&mut self) -> std::result::Result<Snapshot, MigratableError> {
Snapshot::new_from_versioned_state(&self.state()) Snapshot::new_from_state(&self.state())
} }
} }

View File

@ -8,16 +8,13 @@
//! //!
use crate::{read_le_u32, write_le_u32}; use crate::{read_le_u32, write_le_u32};
use serde::{Deserialize, Serialize};
use std::result; use std::result;
use std::sync::{Arc, Barrier}; use std::sync::{Arc, Barrier};
use std::{fmt, io}; use std::{fmt, io};
use versionize::{VersionMap, Versionize, VersionizeResult};
use versionize_derive::Versionize;
use vm_device::interrupt::InterruptSourceGroup; use vm_device::interrupt::InterruptSourceGroup;
use vm_device::BusDevice; use vm_device::BusDevice;
use vm_migration::{ use vm_migration::{Migratable, MigratableError, Pausable, Snapshot, Snapshottable, Transportable};
Migratable, MigratableError, Pausable, Snapshot, Snapshottable, Transportable, VersionMapped,
};
const OFS_DATA: u64 = 0x400; // Data Register const OFS_DATA: u64 = 0x400; // Data Register
const GPIODIR: u64 = 0x400; // Direction Register const GPIODIR: u64 = 0x400; // Direction Register
@ -89,7 +86,7 @@ pub struct Gpio {
interrupt: Arc<dyn InterruptSourceGroup>, interrupt: Arc<dyn InterruptSourceGroup>,
} }
#[derive(Versionize)] #[derive(Serialize, Deserialize)]
pub struct GpioState { pub struct GpioState {
data: u32, data: u32,
old_in_data: u32, old_in_data: u32,
@ -102,8 +99,6 @@ pub struct GpioState {
afsel: u32, afsel: u32,
} }
impl VersionMapped for GpioState {}
impl Gpio { impl Gpio {
/// Constructs an PL061 GPIO device. /// Constructs an PL061 GPIO device.
pub fn new( pub fn new(
@ -328,7 +323,7 @@ impl Snapshottable for Gpio {
} }
fn snapshot(&mut self) -> std::result::Result<Snapshot, MigratableError> { fn snapshot(&mut self) -> std::result::Result<Snapshot, MigratableError> {
Snapshot::new_from_versioned_state(&self.state()) Snapshot::new_from_state(&self.state())
} }
} }

View File

@ -5,16 +5,13 @@
// Use of this source code is governed by a BSD-style license that can be // Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE-BSD-3-Clause file. // found in the LICENSE-BSD-3-Clause file.
use serde::{Deserialize, Serialize};
use std::collections::VecDeque; use std::collections::VecDeque;
use std::sync::{Arc, Barrier}; use std::sync::{Arc, Barrier};
use std::{io, result}; use std::{io, result};
use versionize::{VersionMap, Versionize, VersionizeResult};
use versionize_derive::Versionize;
use vm_device::interrupt::InterruptSourceGroup; use vm_device::interrupt::InterruptSourceGroup;
use vm_device::BusDevice; use vm_device::BusDevice;
use vm_migration::{ use vm_migration::{Migratable, MigratableError, Pausable, Snapshot, Snapshottable, Transportable};
Migratable, MigratableError, Pausable, Snapshot, Snapshottable, Transportable, VersionMapped,
};
use vmm_sys_util::errno::Result; use vmm_sys_util::errno::Result;
const LOOP_SIZE: usize = 0x40; const LOOP_SIZE: usize = 0x40;
@ -74,7 +71,7 @@ pub struct Serial {
out: Option<Box<dyn io::Write + Send>>, out: Option<Box<dyn io::Write + Send>>,
} }
#[derive(Versionize)] #[derive(Serialize, Deserialize)]
pub struct SerialState { pub struct SerialState {
interrupt_enable: u8, interrupt_enable: u8,
interrupt_identification: u8, interrupt_identification: u8,
@ -86,7 +83,6 @@ pub struct SerialState {
baud_divisor: u16, baud_divisor: u16,
in_buffer: Vec<u8>, in_buffer: Vec<u8>,
} }
impl VersionMapped for SerialState {}
impl Serial { impl Serial {
pub fn new( pub fn new(
@ -334,7 +330,7 @@ impl Snapshottable for Serial {
} }
fn snapshot(&mut self) -> std::result::Result<Snapshot, MigratableError> { fn snapshot(&mut self) -> std::result::Result<Snapshot, MigratableError> {
Snapshot::new_from_versioned_state(&self.state()) Snapshot::new_from_state(&self.state())
} }
} }

View File

@ -7,18 +7,15 @@
//! //!
use crate::{read_le_u32, write_le_u32}; use crate::{read_le_u32, write_le_u32};
use serde::{Deserialize, Serialize};
use std::collections::VecDeque; use std::collections::VecDeque;
use std::fmt; use std::fmt;
use std::sync::{Arc, Barrier}; use std::sync::{Arc, Barrier};
use std::time::Instant; use std::time::Instant;
use std::{io, result}; use std::{io, result};
use versionize::{VersionMap, Versionize, VersionizeResult};
use versionize_derive::Versionize;
use vm_device::interrupt::InterruptSourceGroup; use vm_device::interrupt::InterruptSourceGroup;
use vm_device::BusDevice; use vm_device::BusDevice;
use vm_migration::{ use vm_migration::{Migratable, MigratableError, Pausable, Snapshot, Snapshottable, Transportable};
Migratable, MigratableError, Pausable, Snapshot, Snapshottable, Transportable, VersionMapped,
};
/* Registers */ /* Registers */
const UARTDR: u64 = 0; const UARTDR: u64 = 0;
@ -94,7 +91,7 @@ pub struct Pl011 {
timestamp: std::time::Instant, timestamp: std::time::Instant,
} }
#[derive(Versionize)] #[derive(Serialize, Deserialize)]
pub struct Pl011State { pub struct Pl011State {
flags: u32, flags: u32,
lcr: u32, lcr: u32,
@ -113,8 +110,6 @@ pub struct Pl011State {
read_trigger: u32, read_trigger: u32,
} }
impl VersionMapped for Pl011State {}
impl Pl011 { impl Pl011 {
/// Constructs an AMBA PL011 UART device. /// Constructs an AMBA PL011 UART device.
pub fn new( pub fn new(
@ -454,7 +449,7 @@ impl Snapshottable for Pl011 {
} }
fn snapshot(&mut self) -> std::result::Result<Snapshot, MigratableError> { fn snapshot(&mut self) -> std::result::Result<Snapshot, MigratableError> {
Snapshot::new_from_versioned_state(&self.state()) Snapshot::new_from_state(&self.state())
} }
} }

View File

@ -9,18 +9,15 @@ use pci::{
PciClassCode, PciConfiguration, PciDevice, PciDeviceError, PciHeaderType, PciSubclass, PciClassCode, PciConfiguration, PciDevice, PciDeviceError, PciHeaderType, PciSubclass,
PCI_CONFIGURATION_ID, PCI_CONFIGURATION_ID,
}; };
use serde::{Deserialize, Serialize};
use std::any::Any; use std::any::Any;
use std::result; use std::result;
use std::sync::{Arc, Barrier, Mutex}; use std::sync::{Arc, Barrier, Mutex};
use thiserror::Error; use thiserror::Error;
use versionize::{VersionMap, Versionize, VersionizeResult};
use versionize_derive::Versionize;
use vm_allocator::{AddressAllocator, SystemAllocator}; use vm_allocator::{AddressAllocator, SystemAllocator};
use vm_device::{BusDevice, Resource}; use vm_device::{BusDevice, Resource};
use vm_memory::{Address, GuestAddress}; use vm_memory::{Address, GuestAddress};
use vm_migration::{ use vm_migration::{Migratable, MigratableError, Pausable, Snapshot, Snapshottable, Transportable};
Migratable, MigratableError, Pausable, Snapshot, Snapshottable, Transportable, VersionMapped,
};
const PVPANIC_VENDOR_ID: u16 = 0x1b36; const PVPANIC_VENDOR_ID: u16 = 0x1b36;
const PVPANIC_DEVICE_ID: u16 = 0x0011; const PVPANIC_DEVICE_ID: u16 = 0x0011;
@ -60,23 +57,20 @@ pub struct PvPanicDevice {
bar_regions: Vec<PciBarConfiguration>, bar_regions: Vec<PciBarConfiguration>,
} }
#[derive(Versionize)] #[derive(Serialize, Deserialize)]
pub struct PvPanicDeviceState { pub struct PvPanicDeviceState {
events: u8, events: u8,
} }
impl VersionMapped for PvPanicDeviceState {}
impl PvPanicDevice { impl PvPanicDevice {
pub fn new(id: String, snapshot: Option<Snapshot>) -> Result<Self, PvPanicError> { pub fn new(id: String, snapshot: Option<Snapshot>) -> Result<Self, PvPanicError> {
let pci_configuration_state = let pci_configuration_state =
vm_migration::versioned_state_from_id(snapshot.as_ref(), PCI_CONFIGURATION_ID) vm_migration::state_from_id(snapshot.as_ref(), PCI_CONFIGURATION_ID).map_err(|e| {
.map_err(|e| { PvPanicError::RetrievePciConfigurationState(anyhow!(
PvPanicError::RetrievePciConfigurationState(anyhow!( "Failed to get PciConfigurationState from Snapshot: {}",
"Failed to get PciConfigurationState from Snapshot: {}", e
e ))
)) })?;
})?;
let mut configuration = PciConfiguration::new( let mut configuration = PciConfiguration::new(
PVPANIC_VENDOR_ID, PVPANIC_VENDOR_ID,
@ -97,7 +91,7 @@ impl PvPanicDevice {
let state: Option<PvPanicDeviceState> = snapshot let state: Option<PvPanicDeviceState> = snapshot
.as_ref() .as_ref()
.map(|s| s.to_versioned_state()) .map(|s| s.to_state())
.transpose() .transpose()
.map_err(|e| { .map_err(|e| {
PvPanicError::CreatePvPanicDevice(anyhow!( PvPanicError::CreatePvPanicDevice(anyhow!(
@ -259,7 +253,7 @@ impl Snapshottable for PvPanicDevice {
} }
fn snapshot(&mut self) -> std::result::Result<Snapshot, MigratableError> { fn snapshot(&mut self) -> std::result::Result<Snapshot, MigratableError> {
let mut snapshot = Snapshot::new_from_versioned_state(&self.state())?; let mut snapshot = Snapshot::new_from_state(&self.state())?;
// Snapshot PciConfiguration // Snapshot PciConfiguration
snapshot.add_snapshot(self.configuration.id(), self.configuration.snapshot()?); snapshot.add_snapshot(self.configuration.id(), self.configuration.snapshot()?);

View File

@ -36,7 +36,6 @@ path = ".."
[patch.crates-io] [patch.crates-io]
kvm-bindings = { git = "https://github.com/cloud-hypervisor/kvm-bindings", branch = "ch-v0.7.0" } kvm-bindings = { git = "https://github.com/cloud-hypervisor/kvm-bindings", branch = "ch-v0.7.0" }
versionize_derive = { git = "https://github.com/cloud-hypervisor/versionize_derive", branch = "ch-0.1.6" }
# Prevent this from interfering with workspaces # Prevent this from interfering with workspaces
[workspace] [workspace]

View File

@ -13,8 +13,6 @@ net_gen = { path = "../net_gen" }
rate_limiter = { path = "../rate_limiter" } rate_limiter = { path = "../rate_limiter" }
serde = "1.0.197" serde = "1.0.197"
thiserror = "1.0.58" thiserror = "1.0.58"
versionize = "0.2.0"
versionize_derive = "0.1.6"
virtio-bindings = "0.2.2" virtio-bindings = "0.2.2"
virtio-queue = "0.11.0" virtio-queue = "0.11.0"
vm-memory = { version = "0.14.1", features = ["backend-mmap", "backend-atomic", "backend-bitmap"] } vm-memory = { version = "0.14.1", features = ["backend-mmap", "backend-atomic", "backend-bitmap"] }

View File

@ -14,13 +14,13 @@ mod open_tap;
mod queue_pair; mod queue_pair;
mod tap; mod tap;
use serde::{Deserialize, Serialize};
use std::io::Error as IoError; use std::io::Error as IoError;
use std::os::raw::c_uint; use std::os::raw::c_uint;
use std::os::unix::io::{FromRawFd, RawFd}; use std::os::unix::io::{FromRawFd, RawFd};
use std::{io, mem, net}; use std::{io, mem, net};
use thiserror::Error; use thiserror::Error;
use versionize::{VersionMap, Versionize, VersionizeResult};
use versionize_derive::Versionize;
use virtio_bindings::virtio_net::{ use virtio_bindings::virtio_net::{
virtio_net_hdr_v1, VIRTIO_NET_CTRL_MQ_VQ_PAIRS_MAX, VIRTIO_NET_CTRL_MQ_VQ_PAIRS_MIN, virtio_net_hdr_v1, VIRTIO_NET_CTRL_MQ_VQ_PAIRS_MAX, VIRTIO_NET_CTRL_MQ_VQ_PAIRS_MIN,
VIRTIO_NET_F_GUEST_CSUM, VIRTIO_NET_F_GUEST_ECN, VIRTIO_NET_F_GUEST_TSO4, VIRTIO_NET_F_GUEST_CSUM, VIRTIO_NET_F_GUEST_ECN, VIRTIO_NET_F_GUEST_TSO4,
@ -45,7 +45,7 @@ pub enum Error {
pub type Result<T> = std::result::Result<T, Error>; pub type Result<T> = std::result::Result<T, Error>;
#[repr(C, packed)] #[repr(C, packed)]
#[derive(Copy, Clone, Debug, Default, Versionize)] #[derive(Copy, Clone, Debug, Default, Serialize, Deserialize)]
pub struct VirtioNetConfig { pub struct VirtioNetConfig {
pub mac: [u8; 6], pub mac: [u8; 6],
pub status: u16, pub status: u16,

View File

@ -22,8 +22,6 @@ libc = "0.2.153"
log = "0.4.21" log = "0.4.21"
serde = { version = "1.0.197", features = ["derive"] } serde = { version = "1.0.197", features = ["derive"] }
thiserror = "1.0.58" thiserror = "1.0.58"
versionize = "0.2.0"
versionize_derive = "0.1.6"
vm-allocator = { path = "../vm-allocator" } vm-allocator = { path = "../vm-allocator" }
vm-device = { path = "../vm-device" } vm-device = { path = "../vm-device" }
vm-memory = { version = "0.14.1", features = ["backend-mmap", "backend-atomic", "backend-bitmap"] } vm-memory = { version = "0.14.1", features = ["backend-mmap", "backend-atomic", "backend-bitmap"] }

View File

@ -7,12 +7,11 @@
use crate::device::BarReprogrammingParams; use crate::device::BarReprogrammingParams;
use crate::{MsixConfig, PciInterruptPin}; use crate::{MsixConfig, PciInterruptPin};
use byteorder::{ByteOrder, LittleEndian}; use byteorder::{ByteOrder, LittleEndian};
use serde::{Deserialize, Serialize};
use std::fmt::{self, Display}; use std::fmt::{self, Display};
use std::sync::{Arc, Mutex}; use std::sync::{Arc, Mutex};
use versionize::{VersionMap, Versionize, VersionizeError, VersionizeResult};
use versionize_derive::Versionize;
use vm_device::PciBarType; use vm_device::PciBarType;
use vm_migration::{MigratableError, Pausable, Snapshot, Snapshottable, VersionMapped}; use vm_migration::{MigratableError, Pausable, Snapshot, Snapshottable};
// The number of 32bit registers in the config space, 4096 bytes. // The number of 32bit registers in the config space, 4096 bytes.
const NUM_CONFIGURATION_REGISTERS: usize = 1024; const NUM_CONFIGURATION_REGISTERS: usize = 1024;
@ -398,7 +397,7 @@ fn decode_64_bits_bar_size(bar_size_hi: u32, bar_size_lo: u32) -> Option<u64> {
None None
} }
#[derive(Debug, Default, Clone, Copy, Versionize)] #[derive(Debug, Default, Clone, Copy, Serialize, Deserialize)]
struct PciBar { struct PciBar {
addr: u32, addr: u32,
size: u32, size: u32,
@ -406,7 +405,7 @@ struct PciBar {
r#type: Option<PciBarRegionType>, r#type: Option<PciBarRegionType>,
} }
#[derive(Versionize)] #[derive(Serialize, Deserialize)]
pub struct PciConfigurationState { pub struct PciConfigurationState {
registers: Vec<u32>, registers: Vec<u32>,
writable_bits: Vec<u32>, writable_bits: Vec<u32>,
@ -418,8 +417,6 @@ pub struct PciConfigurationState {
msix_cap_reg_idx: Option<usize>, msix_cap_reg_idx: Option<usize>,
} }
impl VersionMapped for PciConfigurationState {}
/// Contains the configuration space of a PCI node. /// Contains the configuration space of a PCI node.
/// See the [specification](https://en.wikipedia.org/wiki/PCI_configuration_space). /// See the [specification](https://en.wikipedia.org/wiki/PCI_configuration_space).
/// The configuration space is accessed with DWORD reads and writes from the guest. /// The configuration space is accessed with DWORD reads and writes from the guest.
@ -437,7 +434,7 @@ pub struct PciConfiguration {
} }
/// See pci_regs.h in kernel /// See pci_regs.h in kernel
#[derive(Copy, Clone, PartialEq, Eq, Versionize, Debug)] #[derive(Copy, Clone, PartialEq, Eq, Serialize, Deserialize, Debug)]
pub enum PciBarRegionType { pub enum PciBarRegionType {
Memory32BitRegion = 0, Memory32BitRegion = 0,
IoRegion = 0x01, IoRegion = 0x01,
@ -1072,7 +1069,7 @@ impl Snapshottable for PciConfiguration {
} }
fn snapshot(&mut self) -> std::result::Result<Snapshot, MigratableError> { fn snapshot(&mut self) -> std::result::Result<Snapshot, MigratableError> {
Snapshot::new_from_versioned_state(&self.state()) Snapshot::new_from_state(&self.state())
} }
} }

View File

@ -4,15 +4,14 @@
// //
use byteorder::{ByteOrder, LittleEndian}; use byteorder::{ByteOrder, LittleEndian};
use serde::{Deserialize, Serialize};
use std::io; use std::io;
use std::sync::Arc; use std::sync::Arc;
use thiserror::Error; use thiserror::Error;
use versionize::{VersionMap, Versionize, VersionizeResult};
use versionize_derive::Versionize;
use vm_device::interrupt::{ use vm_device::interrupt::{
InterruptIndex, InterruptSourceConfig, InterruptSourceGroup, MsiIrqSourceConfig, InterruptIndex, InterruptSourceConfig, InterruptSourceGroup, MsiIrqSourceConfig,
}; };
use vm_migration::{MigratableError, Pausable, Snapshot, Snapshottable, VersionMapped}; use vm_migration::{MigratableError, Pausable, Snapshot, Snapshottable};
// MSI control masks // MSI control masks
const MSI_CTL_ENABLE: u16 = 0x1; const MSI_CTL_ENABLE: u16 = 0x1;
@ -47,7 +46,7 @@ pub enum Error {
pub const MSI_CONFIG_ID: &str = "msi_config"; pub const MSI_CONFIG_ID: &str = "msi_config";
#[derive(Clone, Copy, Default, Versionize)] #[derive(Clone, Copy, Default, Serialize, Deserialize)]
pub struct MsiCap { pub struct MsiCap {
// Message Control Register // Message Control Register
// 0: MSI enable. // 0: MSI enable.
@ -172,13 +171,11 @@ impl MsiCap {
} }
} }
#[derive(Versionize)] #[derive(Serialize, Deserialize)]
pub struct MsiConfigState { pub struct MsiConfigState {
cap: MsiCap, cap: MsiCap,
} }
impl VersionMapped for MsiConfigState {}
pub struct MsiConfig { pub struct MsiConfig {
pub cap: MsiCap, pub cap: MsiCap,
interrupt_source_group: Arc<dyn InterruptSourceGroup>, interrupt_source_group: Arc<dyn InterruptSourceGroup>,
@ -294,6 +291,6 @@ impl Snapshottable for MsiConfig {
} }
fn snapshot(&mut self) -> std::result::Result<Snapshot, MigratableError> { fn snapshot(&mut self) -> std::result::Result<Snapshot, MigratableError> {
Snapshot::new_from_versioned_state(&self.state()) Snapshot::new_from_state(&self.state())
} }
} }

View File

@ -5,16 +5,16 @@
use crate::{PciCapability, PciCapabilityId}; use crate::{PciCapability, PciCapabilityId};
use byteorder::{ByteOrder, LittleEndian}; use byteorder::{ByteOrder, LittleEndian};
use serde::Deserialize;
use serde::Serialize;
use std::io; use std::io;
use std::result; use std::result;
use std::sync::Arc; use std::sync::Arc;
use versionize::{VersionMap, Versionize, VersionizeResult};
use versionize_derive::Versionize;
use vm_device::interrupt::{ use vm_device::interrupt::{
InterruptIndex, InterruptSourceConfig, InterruptSourceGroup, MsiIrqSourceConfig, InterruptIndex, InterruptSourceConfig, InterruptSourceGroup, MsiIrqSourceConfig,
}; };
use vm_memory::ByteValued; use vm_memory::ByteValued;
use vm_migration::{MigratableError, Pausable, Snapshot, Snapshottable, VersionMapped}; use vm_migration::{MigratableError, Pausable, Snapshot, Snapshottable};
const MAX_MSIX_VECTORS_PER_DEVICE: u16 = 2048; const MAX_MSIX_VECTORS_PER_DEVICE: u16 = 2048;
const MSIX_TABLE_ENTRIES_MODULO: u64 = 16; const MSIX_TABLE_ENTRIES_MODULO: u64 = 16;
@ -35,7 +35,7 @@ pub enum Error {
UpdateInterruptRoute(io::Error), UpdateInterruptRoute(io::Error),
} }
#[derive(Debug, Clone, Versionize, Eq, PartialEq)] #[derive(Debug, Clone, Serialize, Deserialize, Eq, PartialEq)]
pub struct MsixTableEntry { pub struct MsixTableEntry {
pub msg_addr_lo: u32, pub msg_addr_lo: u32,
pub msg_addr_hi: u32, pub msg_addr_hi: u32,
@ -60,7 +60,7 @@ impl Default for MsixTableEntry {
} }
} }
#[derive(Versionize)] #[derive(Serialize, Deserialize)]
pub struct MsixConfigState { pub struct MsixConfigState {
table_entries: Vec<MsixTableEntry>, table_entries: Vec<MsixTableEntry>,
pba_entries: Vec<u64>, pba_entries: Vec<u64>,
@ -68,8 +68,6 @@ pub struct MsixConfigState {
enabled: bool, enabled: bool,
} }
impl VersionMapped for MsixConfigState {}
pub struct MsixConfig { pub struct MsixConfig {
pub table_entries: Vec<MsixTableEntry>, pub table_entries: Vec<MsixTableEntry>,
pub pba_entries: Vec<u64>, pub pba_entries: Vec<u64>,
@ -436,13 +434,13 @@ impl Snapshottable for MsixConfig {
} }
fn snapshot(&mut self) -> std::result::Result<Snapshot, MigratableError> { fn snapshot(&mut self) -> std::result::Result<Snapshot, MigratableError> {
Snapshot::new_from_versioned_state(&self.state()) Snapshot::new_from_state(&self.state())
} }
} }
#[allow(dead_code)] #[allow(dead_code)]
#[repr(packed)] #[repr(packed)]
#[derive(Clone, Copy, Default, Versionize)] #[derive(Clone, Copy, Default, Serialize, Deserialize)]
pub struct MsixCap { pub struct MsixCap {
// Message Control Register // Message Control Register
// 10-0: MSI-X Table size // 10-0: MSI-X Table size

View File

@ -15,6 +15,7 @@ use anyhow::anyhow;
use byteorder::{ByteOrder, LittleEndian}; use byteorder::{ByteOrder, LittleEndian};
use hypervisor::HypervisorVmError; use hypervisor::HypervisorVmError;
use libc::{sysconf, _SC_PAGESIZE}; use libc::{sysconf, _SC_PAGESIZE};
use serde::{Deserialize, Serialize};
use std::any::Any; use std::any::Any;
use std::collections::{BTreeMap, HashMap}; use std::collections::{BTreeMap, HashMap};
use std::io; use std::io;
@ -22,8 +23,6 @@ use std::os::unix::io::AsRawFd;
use std::ptr::null_mut; use std::ptr::null_mut;
use std::sync::{Arc, Barrier, Mutex}; use std::sync::{Arc, Barrier, Mutex};
use thiserror::Error; use thiserror::Error;
use versionize::{VersionMap, Versionize, VersionizeResult};
use versionize_derive::Versionize;
use vfio_bindings::bindings::vfio::*; use vfio_bindings::bindings::vfio::*;
use vfio_ioctls::{ use vfio_ioctls::{
VfioContainer, VfioDevice, VfioIrq, VfioRegionInfoCap, VfioRegionSparseMmapArea, VfioContainer, VfioDevice, VfioIrq, VfioRegionInfoCap, VfioRegionSparseMmapArea,
@ -38,9 +37,7 @@ use vm_device::interrupt::{
}; };
use vm_device::{BusDevice, Resource}; use vm_device::{BusDevice, Resource};
use vm_memory::{Address, GuestAddress, GuestAddressSpace, GuestMemory, GuestUsize}; use vm_memory::{Address, GuestAddress, GuestAddressSpace, GuestMemory, GuestUsize};
use vm_migration::{ use vm_migration::{Migratable, MigratableError, Pausable, Snapshot, Snapshottable, Transportable};
Migratable, MigratableError, Pausable, Snapshot, Snapshottable, Transportable, VersionMapped,
};
use vmm_sys_util::eventfd::EventFd; use vmm_sys_util::eventfd::EventFd;
pub(crate) const VFIO_COMMON_ID: &str = "vfio_common"; pub(crate) const VFIO_COMMON_ID: &str = "vfio_common";
@ -95,7 +92,7 @@ enum InterruptUpdateAction {
DisableMsix, DisableMsix,
} }
#[derive(Versionize)] #[derive(Serialize, Deserialize)]
struct IntxState { struct IntxState {
enabled: bool, enabled: bool,
} }
@ -105,7 +102,7 @@ pub(crate) struct VfioIntx {
enabled: bool, enabled: bool,
} }
#[derive(Versionize)] #[derive(Serialize, Deserialize)]
struct MsiState { struct MsiState {
cap: MsiCap, cap: MsiCap,
cap_offset: u32, cap_offset: u32,
@ -137,7 +134,7 @@ impl VfioMsi {
} }
} }
#[derive(Versionize)] #[derive(Serialize, Deserialize)]
struct MsixState { struct MsixState {
cap: MsixCap, cap: MsixCap,
cap_offset: u32, cap_offset: u32,
@ -440,15 +437,13 @@ impl Vfio for VfioDeviceWrapper {
} }
} }
#[derive(Versionize)] #[derive(Serialize, Deserialize)]
struct VfioCommonState { struct VfioCommonState {
intx_state: Option<IntxState>, intx_state: Option<IntxState>,
msi_state: Option<MsiState>, msi_state: Option<MsiState>,
msix_state: Option<MsixState>, msix_state: Option<MsixState>,
} }
impl VersionMapped for VfioCommonState {}
pub(crate) struct ConfigPatch { pub(crate) struct ConfigPatch {
mask: u32, mask: u32,
patch: u32, patch: u32,
@ -476,13 +471,12 @@ impl VfioCommon {
x_nv_gpudirect_clique: Option<u8>, x_nv_gpudirect_clique: Option<u8>,
) -> Result<Self, VfioPciError> { ) -> Result<Self, VfioPciError> {
let pci_configuration_state = let pci_configuration_state =
vm_migration::versioned_state_from_id(snapshot.as_ref(), PCI_CONFIGURATION_ID) vm_migration::state_from_id(snapshot.as_ref(), PCI_CONFIGURATION_ID).map_err(|e| {
.map_err(|e| { VfioPciError::RetrievePciConfigurationState(anyhow!(
VfioPciError::RetrievePciConfigurationState(anyhow!( "Failed to get PciConfigurationState from Snapshot: {}",
"Failed to get PciConfigurationState from Snapshot: {}", e
e ))
)) })?;
})?;
let configuration = PciConfiguration::new( let configuration = PciConfiguration::new(
0, 0,
@ -515,7 +509,7 @@ impl VfioCommon {
let state: Option<VfioCommonState> = snapshot let state: Option<VfioCommonState> = snapshot
.as_ref() .as_ref()
.map(|s| s.to_versioned_state()) .map(|s| s.to_state())
.transpose() .transpose()
.map_err(|e| { .map_err(|e| {
VfioPciError::RetrieveVfioCommonState(anyhow!( VfioPciError::RetrieveVfioCommonState(anyhow!(
@ -523,20 +517,20 @@ impl VfioCommon {
e e
)) ))
})?; })?;
let msi_state = vm_migration::versioned_state_from_id(snapshot.as_ref(), MSI_CONFIG_ID) let msi_state =
.map_err(|e| { vm_migration::state_from_id(snapshot.as_ref(), MSI_CONFIG_ID).map_err(|e| {
VfioPciError::RetrieveMsiConfigState(anyhow!( VfioPciError::RetrieveMsiConfigState(anyhow!(
"Failed to get MsiConfigState from Snapshot: {}", "Failed to get MsiConfigState from Snapshot: {}",
e e
)) ))
})?; })?;
let msix_state = vm_migration::versioned_state_from_id(snapshot.as_ref(), MSIX_CONFIG_ID) let msix_state =
.map_err(|e| { vm_migration::state_from_id(snapshot.as_ref(), MSIX_CONFIG_ID).map_err(|e| {
VfioPciError::RetrieveMsixConfigState(anyhow!( VfioPciError::RetrieveMsixConfigState(anyhow!(
"Failed to get MsixConfigState from Snapshot: {}", "Failed to get MsixConfigState from Snapshot: {}",
e e
)) ))
})?; })?;
if let Some(state) = state.as_ref() { if let Some(state) = state.as_ref() {
vfio_common.set_state(state, msi_state, msix_state)?; vfio_common.set_state(state, msi_state, msix_state)?;
@ -1388,7 +1382,7 @@ impl Snapshottable for VfioCommon {
} }
fn snapshot(&mut self) -> std::result::Result<Snapshot, MigratableError> { fn snapshot(&mut self) -> std::result::Result<Snapshot, MigratableError> {
let mut vfio_common_snapshot = Snapshot::new_from_versioned_state(&self.state())?; let mut vfio_common_snapshot = Snapshot::new_from_state(&self.state())?;
// Snapshot PciConfiguration // Snapshot PciConfiguration
vfio_common_snapshot.add_snapshot(self.configuration.id(), self.configuration.snapshot()?); vfio_common_snapshot.add_snapshot(self.configuration.id(), self.configuration.snapshot()?);

View File

@ -23,10 +23,9 @@ rate_limiter = { path = "../rate_limiter" }
seccompiler = "0.4.0" seccompiler = "0.4.0"
serde = { version = "1.0.197", features = ["derive"] } serde = { version = "1.0.197", features = ["derive"] }
serde_json = "1.0.115" serde_json = "1.0.115"
serde_with = { version = "3.7.0", default-features = false, features = ["macros"] }
serial_buffer = { path = "../serial_buffer" } serial_buffer = { path = "../serial_buffer" }
thiserror = "1.0.58" thiserror = "1.0.58"
versionize = "0.2.0"
versionize_derive = "0.1.6"
vhost = { version = "0.10.0", features = ["vhost-user-frontend", "vhost-user-backend", "vhost-kern", "vhost-vdpa"] } vhost = { version = "0.10.0", features = ["vhost-user-frontend", "vhost-user-backend", "vhost-kern", "vhost-vdpa"] }
virtio-bindings = { version = "0.2.2", features = ["virtio-v5_0_0"] } virtio-bindings = { version = "0.2.2", features = ["virtio-v5_0_0"] }
virtio-queue = "0.11.0" virtio-queue = "0.11.0"

View File

@ -22,23 +22,20 @@ use crate::{
}; };
use anyhow::anyhow; use anyhow::anyhow;
use seccompiler::SeccompAction; use seccompiler::SeccompAction;
use serde::{Deserialize, Serialize};
use std::io::{self, Write}; use std::io::{self, Write};
use std::mem::size_of; use std::mem::size_of;
use std::os::unix::io::AsRawFd; use std::os::unix::io::AsRawFd;
use std::result; use std::result;
use std::sync::{atomic::AtomicBool, Arc, Barrier}; use std::sync::{atomic::AtomicBool, Arc, Barrier};
use thiserror::Error; use thiserror::Error;
use versionize::{VersionMap, Versionize, VersionizeResult};
use versionize_derive::Versionize;
use virtio_queue::{Queue, QueueT}; use virtio_queue::{Queue, QueueT};
use vm_allocator::page_size::{align_page_size_down, get_page_size}; use vm_allocator::page_size::{align_page_size_down, get_page_size};
use vm_memory::{ use vm_memory::{
Address, ByteValued, Bytes, GuestAddress, GuestAddressSpace, GuestMemory, GuestMemoryAtomic, Address, ByteValued, Bytes, GuestAddress, GuestAddressSpace, GuestMemory, GuestMemoryAtomic,
GuestMemoryError, GuestMemoryRegion, GuestMemoryError, GuestMemoryRegion,
}; };
use vm_migration::{ use vm_migration::{Migratable, MigratableError, Pausable, Snapshot, Snapshottable, Transportable};
Migratable, MigratableError, Pausable, Snapshot, Snapshottable, Transportable, VersionMapped,
};
use vmm_sys_util::eventfd::EventFd; use vmm_sys_util::eventfd::EventFd;
const QUEUE_SIZE: u16 = 128; const QUEUE_SIZE: u16 = 128;
@ -89,7 +86,7 @@ pub enum Error {
// Got from include/uapi/linux/virtio_balloon.h // Got from include/uapi/linux/virtio_balloon.h
#[repr(C)] #[repr(C)]
#[derive(Copy, Clone, Debug, Default, Versionize)] #[derive(Copy, Clone, Debug, Default, Serialize, Deserialize)]
pub struct VirtioBalloonConfig { pub struct VirtioBalloonConfig {
// Number of pages host wants Guest to give up. // Number of pages host wants Guest to give up.
num_pages: u32, num_pages: u32,
@ -418,15 +415,13 @@ impl EpollHelperHandler for BalloonEpollHandler {
} }
} }
#[derive(Versionize)] #[derive(Serialize, Deserialize)]
pub struct BalloonState { pub struct BalloonState {
pub avail_features: u64, pub avail_features: u64,
pub acked_features: u64, pub acked_features: u64,
pub config: VirtioBalloonConfig, pub config: VirtioBalloonConfig,
} }
impl VersionMapped for BalloonState {}
// Virtio device for exposing entropy to the guest OS through virtio. // Virtio device for exposing entropy to the guest OS through virtio.
pub struct Balloon { pub struct Balloon {
common: VirtioCommon, common: VirtioCommon,
@ -672,7 +667,7 @@ impl Snapshottable for Balloon {
} }
fn snapshot(&mut self) -> std::result::Result<Snapshot, MigratableError> { fn snapshot(&mut self) -> std::result::Result<Snapshot, MigratableError> {
Snapshot::new_from_versioned_state(&self.state()) Snapshot::new_from_state(&self.state())
} }
} }
impl Transportable for Balloon {} impl Transportable for Balloon {}

View File

@ -25,6 +25,7 @@ use block::{
use rate_limiter::group::{RateLimiterGroup, RateLimiterGroupHandle}; use rate_limiter::group::{RateLimiterGroup, RateLimiterGroupHandle};
use rate_limiter::TokenType; use rate_limiter::TokenType;
use seccompiler::SeccompAction; use seccompiler::SeccompAction;
use serde::{Deserialize, Serialize};
use std::collections::BTreeMap; use std::collections::BTreeMap;
use std::collections::HashMap; use std::collections::HashMap;
use std::collections::VecDeque; use std::collections::VecDeque;
@ -37,13 +38,10 @@ use std::result;
use std::sync::atomic::{AtomicBool, AtomicU64, Ordering}; use std::sync::atomic::{AtomicBool, AtomicU64, Ordering};
use std::sync::{Arc, Barrier}; use std::sync::{Arc, Barrier};
use thiserror::Error; use thiserror::Error;
use versionize::{VersionMap, Versionize, VersionizeResult};
use versionize_derive::Versionize;
use virtio_bindings::virtio_blk::*; use virtio_bindings::virtio_blk::*;
use virtio_bindings::virtio_config::*; use virtio_bindings::virtio_config::*;
use virtio_queue::{Queue, QueueOwnedT, QueueT}; use virtio_queue::{Queue, QueueOwnedT, QueueT};
use vm_memory::{ByteValued, Bytes, GuestAddressSpace, GuestMemoryAtomic, GuestMemoryError}; use vm_memory::{ByteValued, Bytes, GuestAddressSpace, GuestMemoryAtomic, GuestMemoryError};
use vm_migration::VersionMapped;
use vm_migration::{Migratable, MigratableError, Pausable, Snapshot, Snapshottable, Transportable}; use vm_migration::{Migratable, MigratableError, Pausable, Snapshot, Snapshottable, Transportable};
use vm_virtio::AccessPlatform; use vm_virtio::AccessPlatform;
use vmm_sys_util::eventfd::EventFd; use vmm_sys_util::eventfd::EventFd;
@ -552,7 +550,7 @@ pub struct Block {
queue_affinity: BTreeMap<u16, Vec<usize>>, queue_affinity: BTreeMap<u16, Vec<usize>>,
} }
#[derive(Versionize)] #[derive(Serialize, Deserialize)]
pub struct BlockState { pub struct BlockState {
pub disk_path: String, pub disk_path: String,
pub disk_nsectors: u64, pub disk_nsectors: u64,
@ -561,8 +559,6 @@ pub struct BlockState {
pub config: VirtioBlockConfig, pub config: VirtioBlockConfig,
} }
impl VersionMapped for BlockState {}
impl Block { impl Block {
/// Create a new virtio block device that operates on the given file. /// Create a new virtio block device that operates on the given file.
#[allow(clippy::too_many_arguments)] #[allow(clippy::too_many_arguments)]
@ -916,7 +912,7 @@ impl Snapshottable for Block {
} }
fn snapshot(&mut self) -> std::result::Result<Snapshot, MigratableError> { fn snapshot(&mut self) -> std::result::Result<Snapshot, MigratableError> {
Snapshot::new_from_versioned_state(&self.state()) Snapshot::new_from_state(&self.state())
} }
} }
impl Transportable for Block {} impl Transportable for Block {}

View File

@ -14,6 +14,7 @@ use crate::VirtioInterrupt;
use anyhow::anyhow; use anyhow::anyhow;
use libc::{EFD_NONBLOCK, TIOCGWINSZ}; use libc::{EFD_NONBLOCK, TIOCGWINSZ};
use seccompiler::SeccompAction; use seccompiler::SeccompAction;
use serde::{Deserialize, Serialize};
use serial_buffer::SerialBuffer; use serial_buffer::SerialBuffer;
use std::cmp; use std::cmp;
use std::collections::VecDeque; use std::collections::VecDeque;
@ -25,11 +26,8 @@ use std::result;
use std::sync::atomic::{AtomicBool, AtomicU64, Ordering}; use std::sync::atomic::{AtomicBool, AtomicU64, Ordering};
use std::sync::{Arc, Barrier, Mutex}; use std::sync::{Arc, Barrier, Mutex};
use thiserror::Error; use thiserror::Error;
use versionize::{VersionMap, Versionize, VersionizeResult};
use versionize_derive::Versionize;
use virtio_queue::{Queue, QueueT}; use virtio_queue::{Queue, QueueT};
use vm_memory::{ByteValued, Bytes, GuestAddressSpace, GuestMemory, GuestMemoryAtomic}; use vm_memory::{ByteValued, Bytes, GuestAddressSpace, GuestMemory, GuestMemoryAtomic};
use vm_migration::VersionMapped;
use vm_migration::{Migratable, MigratableError, Pausable, Snapshot, Snapshottable, Transportable}; use vm_migration::{Migratable, MigratableError, Pausable, Snapshot, Snapshottable, Transportable};
use vm_virtio::{AccessPlatform, Translatable}; use vm_virtio::{AccessPlatform, Translatable};
use vmm_sys_util::eventfd::EventFd; use vmm_sys_util::eventfd::EventFd;
@ -67,7 +65,7 @@ enum Error {
QueueAddUsed(virtio_queue::Error), QueueAddUsed(virtio_queue::Error),
} }
#[derive(Copy, Clone, Debug, Versionize)] #[derive(Copy, Clone, Debug, Serialize, Deserialize)]
#[repr(C, packed)] #[repr(C, packed)]
pub struct VirtioConsoleConfig { pub struct VirtioConsoleConfig {
cols: u16, cols: u16,
@ -593,7 +591,7 @@ pub struct Console {
exit_evt: EventFd, exit_evt: EventFd,
} }
#[derive(Versionize)] #[derive(Serialize, Deserialize)]
pub struct ConsoleState { pub struct ConsoleState {
avail_features: u64, avail_features: u64,
acked_features: u64, acked_features: u64,
@ -620,8 +618,6 @@ fn get_win_size(tty: &dyn AsRawFd) -> (u16, u16) {
(ws.cols, ws.rows) (ws.cols, ws.rows)
} }
impl VersionMapped for ConsoleState {}
impl Console { impl Console {
/// Create a new virtio console device /// Create a new virtio console device
pub fn new( pub fn new(
@ -825,7 +821,7 @@ impl Snapshottable for Console {
} }
fn snapshot(&mut self) -> std::result::Result<Snapshot, MigratableError> { fn snapshot(&mut self) -> std::result::Result<Snapshot, MigratableError> {
Snapshot::new_from_versioned_state(&self.state()) Snapshot::new_from_state(&self.state())
} }
} }
impl Transportable for Console {} impl Transportable for Console {}

View File

@ -13,6 +13,7 @@ use crate::GuestMemoryMmap;
use crate::{DmaRemapping, VirtioInterrupt, VirtioInterruptType}; use crate::{DmaRemapping, VirtioInterrupt, VirtioInterruptType};
use anyhow::anyhow; use anyhow::anyhow;
use seccompiler::SeccompAction; use seccompiler::SeccompAction;
use serde::{Deserialize, Serialize};
use std::collections::BTreeMap; use std::collections::BTreeMap;
use std::io; use std::io;
use std::mem::size_of; use std::mem::size_of;
@ -22,15 +23,12 @@ use std::result;
use std::sync::atomic::{AtomicBool, Ordering}; use std::sync::atomic::{AtomicBool, Ordering};
use std::sync::{Arc, Barrier, Mutex, RwLock}; use std::sync::{Arc, Barrier, Mutex, RwLock};
use thiserror::Error; use thiserror::Error;
use versionize::{VersionMap, Versionize, VersionizeResult};
use versionize_derive::Versionize;
use virtio_queue::{DescriptorChain, Queue, QueueT}; use virtio_queue::{DescriptorChain, Queue, QueueT};
use vm_device::dma_mapping::ExternalDmaMapping; use vm_device::dma_mapping::ExternalDmaMapping;
use vm_memory::{ use vm_memory::{
Address, ByteValued, Bytes, GuestAddress, GuestAddressSpace, GuestMemoryAtomic, Address, ByteValued, Bytes, GuestAddress, GuestAddressSpace, GuestMemoryAtomic,
GuestMemoryError, GuestMemoryLoadGuard, GuestMemoryError, GuestMemoryLoadGuard,
}; };
use vm_migration::VersionMapped;
use vm_migration::{Migratable, MigratableError, Pausable, Snapshot, Snapshottable, Transportable}; use vm_migration::{Migratable, MigratableError, Pausable, Snapshot, Snapshottable, Transportable};
use vm_virtio::AccessPlatform; use vm_virtio::AccessPlatform;
use vmm_sys_util::eventfd::EventFd; use vmm_sys_util::eventfd::EventFd;
@ -781,7 +779,7 @@ impl EpollHelperHandler for IommuEpollHandler {
} }
} }
#[derive(Clone, Copy, Debug, Versionize)] #[derive(Clone, Copy, Debug, Serialize, Deserialize)]
struct Mapping { struct Mapping {
gpa: u64, gpa: u64,
size: u64, size: u64,
@ -905,7 +903,7 @@ pub struct Iommu {
type EndpointsState = Vec<(u32, u32)>; type EndpointsState = Vec<(u32, u32)>;
type DomainsState = Vec<(u32, (Vec<(u64, Mapping)>, bool))>; type DomainsState = Vec<(u32, (Vec<(u64, Mapping)>, bool))>;
#[derive(Versionize)] #[derive(Serialize, Deserialize)]
pub struct IommuState { pub struct IommuState {
avail_features: u64, avail_features: u64,
acked_features: u64, acked_features: u64,
@ -913,8 +911,6 @@ pub struct IommuState {
domains: DomainsState, domains: DomainsState,
} }
impl VersionMapped for IommuState {}
impl Iommu { impl Iommu {
pub fn new( pub fn new(
id: String, id: String,
@ -1154,7 +1150,7 @@ impl Snapshottable for Iommu {
} }
fn snapshot(&mut self) -> std::result::Result<Snapshot, MigratableError> { fn snapshot(&mut self) -> std::result::Result<Snapshot, MigratableError> {
Snapshot::new_from_versioned_state(&self.state()) Snapshot::new_from_state(&self.state())
} }
} }
impl Transportable for Iommu {} impl Transportable for Iommu {}

View File

@ -25,6 +25,7 @@ use crate::{GuestMemoryMmap, GuestRegionMmap};
use crate::{VirtioInterrupt, VirtioInterruptType}; use crate::{VirtioInterrupt, VirtioInterruptType};
use anyhow::anyhow; use anyhow::anyhow;
use seccompiler::SeccompAction; use seccompiler::SeccompAction;
use serde::{Deserialize, Serialize};
use std::collections::BTreeMap; use std::collections::BTreeMap;
use std::io; use std::io;
use std::mem::size_of; use std::mem::size_of;
@ -34,8 +35,6 @@ use std::sync::atomic::AtomicBool;
use std::sync::mpsc; use std::sync::mpsc;
use std::sync::{Arc, Barrier, Mutex}; use std::sync::{Arc, Barrier, Mutex};
use thiserror::Error; use thiserror::Error;
use versionize::{VersionMap, Versionize, VersionizeResult};
use versionize_derive::Versionize;
use virtio_queue::{DescriptorChain, Queue, QueueT}; use virtio_queue::{DescriptorChain, Queue, QueueT};
use vm_device::dma_mapping::ExternalDmaMapping; use vm_device::dma_mapping::ExternalDmaMapping;
use vm_memory::{ use vm_memory::{
@ -43,9 +42,7 @@ use vm_memory::{
GuestMemoryError, GuestMemoryLoadGuard, GuestMemoryRegion, GuestMemoryError, GuestMemoryLoadGuard, GuestMemoryRegion,
}; };
use vm_migration::protocol::MemoryRangeTable; use vm_migration::protocol::MemoryRangeTable;
use vm_migration::{ use vm_migration::{Migratable, MigratableError, Pausable, Snapshot, Snapshottable, Transportable};
Migratable, MigratableError, Pausable, Snapshot, Snapshottable, Transportable, VersionMapped,
};
use vmm_sys_util::eventfd::EventFd; use vmm_sys_util::eventfd::EventFd;
const QUEUE_SIZE: u16 = 128; const QUEUE_SIZE: u16 = 128;
@ -170,7 +167,7 @@ struct VirtioMemResp {
unsafe impl ByteValued for VirtioMemResp {} unsafe impl ByteValued for VirtioMemResp {}
#[repr(C)] #[repr(C)]
#[derive(Copy, Clone, Debug, Default, Versionize)] #[derive(Copy, Clone, Debug, Default, Serialize, Deserialize)]
pub struct VirtioMemConfig { pub struct VirtioMemConfig {
// Block size and alignment. Cannot change. // Block size and alignment. Cannot change.
block_size: u64, block_size: u64,
@ -338,7 +335,7 @@ impl Request {
} }
} }
#[derive(Clone, Versionize)] #[derive(Clone, Serialize, Deserialize)]
pub struct BlocksState { pub struct BlocksState {
bitmap: Vec<bool>, bitmap: Vec<bool>,
} }
@ -688,7 +685,7 @@ pub enum VirtioMemMappingSource {
Device(u32), Device(u32),
} }
#[derive(Versionize)] #[derive(Serialize, Deserialize)]
pub struct MemState { pub struct MemState {
pub avail_features: u64, pub avail_features: u64,
pub acked_features: u64, pub acked_features: u64,
@ -696,8 +693,6 @@ pub struct MemState {
pub blocks_state: BlocksState, pub blocks_state: BlocksState,
} }
impl VersionMapped for MemState {}
pub struct Mem { pub struct Mem {
common: VirtioCommon, common: VirtioCommon,
id: String, id: String,
@ -1013,7 +1008,7 @@ impl Snapshottable for Mem {
} }
fn snapshot(&mut self) -> std::result::Result<Snapshot, MigratableError> { fn snapshot(&mut self) -> std::result::Result<Snapshot, MigratableError> {
Snapshot::new_from_versioned_state(&self.state()) Snapshot::new_from_state(&self.state())
} }
} }
impl Transportable for Mem {} impl Transportable for Mem {}

View File

@ -24,6 +24,7 @@ use net_util::{
NetQueuePair, OpenTapError, RxVirtio, Tap, TapError, TxVirtio, VirtioNetConfig, NetQueuePair, OpenTapError, RxVirtio, Tap, TapError, TxVirtio, VirtioNetConfig,
}; };
use seccompiler::SeccompAction; use seccompiler::SeccompAction;
use serde::{Deserialize, Serialize};
use std::collections::HashMap; use std::collections::HashMap;
use std::net::Ipv4Addr; use std::net::Ipv4Addr;
use std::num::Wrapping; use std::num::Wrapping;
@ -34,14 +35,11 @@ use std::sync::atomic::{AtomicBool, Ordering};
use std::sync::{Arc, Barrier}; use std::sync::{Arc, Barrier};
use std::thread; use std::thread;
use thiserror::Error; use thiserror::Error;
use versionize::{VersionMap, Versionize, VersionizeResult};
use versionize_derive::Versionize;
use virtio_bindings::virtio_config::*; use virtio_bindings::virtio_config::*;
use virtio_bindings::virtio_net::*; use virtio_bindings::virtio_net::*;
use virtio_bindings::virtio_ring::VIRTIO_RING_F_EVENT_IDX; use virtio_bindings::virtio_ring::VIRTIO_RING_F_EVENT_IDX;
use virtio_queue::{Queue, QueueT}; use virtio_queue::{Queue, QueueT};
use vm_memory::{ByteValued, GuestAddressSpace, GuestMemoryAtomic}; use vm_memory::{ByteValued, GuestAddressSpace, GuestMemoryAtomic};
use vm_migration::VersionMapped;
use vm_migration::{Migratable, MigratableError, Pausable, Snapshot, Snapshottable, Transportable}; use vm_migration::{Migratable, MigratableError, Pausable, Snapshot, Snapshottable, Transportable};
use vm_virtio::AccessPlatform; use vm_virtio::AccessPlatform;
use vmm_sys_util::eventfd::EventFd; use vmm_sys_util::eventfd::EventFd;
@ -423,7 +421,7 @@ pub struct Net {
exit_evt: EventFd, exit_evt: EventFd,
} }
#[derive(Versionize)] #[derive(Serialize, Deserialize)]
pub struct NetState { pub struct NetState {
pub avail_features: u64, pub avail_features: u64,
pub acked_features: u64, pub acked_features: u64,
@ -431,8 +429,6 @@ pub struct NetState {
pub queue_size: Vec<u16>, pub queue_size: Vec<u16>,
} }
impl VersionMapped for NetState {}
impl Net { impl Net {
/// Create a new virtio network device with the given TAP interface. /// Create a new virtio network device with the given TAP interface.
#[allow(clippy::too_many_arguments)] #[allow(clippy::too_many_arguments)]
@ -886,7 +882,7 @@ impl Snapshottable for Net {
} }
fn snapshot(&mut self) -> std::result::Result<Snapshot, MigratableError> { fn snapshot(&mut self) -> std::result::Result<Snapshot, MigratableError> {
Snapshot::new_from_versioned_state(&self.state()) Snapshot::new_from_state(&self.state())
} }
} }
impl Transportable for Net {} impl Transportable for Net {}

View File

@ -18,6 +18,7 @@ use crate::{GuestMemoryMmap, MmapRegion};
use crate::{VirtioInterrupt, VirtioInterruptType}; use crate::{VirtioInterrupt, VirtioInterruptType};
use anyhow::anyhow; use anyhow::anyhow;
use seccompiler::SeccompAction; use seccompiler::SeccompAction;
use serde::{Deserialize, Serialize};
use std::fs::File; use std::fs::File;
use std::io; use std::io;
use std::mem::size_of; use std::mem::size_of;
@ -26,14 +27,11 @@ use std::result;
use std::sync::atomic::AtomicBool; use std::sync::atomic::AtomicBool;
use std::sync::{Arc, Barrier}; use std::sync::{Arc, Barrier};
use thiserror::Error; use thiserror::Error;
use versionize::{VersionMap, Versionize, VersionizeResult};
use versionize_derive::Versionize;
use virtio_queue::{DescriptorChain, Queue, QueueT}; use virtio_queue::{DescriptorChain, Queue, QueueT};
use vm_memory::{ use vm_memory::{
Address, ByteValued, Bytes, GuestAddress, GuestAddressSpace, GuestMemoryAtomic, Address, ByteValued, Bytes, GuestAddress, GuestAddressSpace, GuestMemoryAtomic,
GuestMemoryError, GuestMemoryLoadGuard, GuestMemoryError, GuestMemoryLoadGuard,
}; };
use vm_migration::VersionMapped;
use vm_migration::{Migratable, MigratableError, Pausable, Snapshot, Snapshottable, Transportable}; use vm_migration::{Migratable, MigratableError, Pausable, Snapshot, Snapshottable, Transportable};
use vm_virtio::{AccessPlatform, Translatable}; use vm_virtio::{AccessPlatform, Translatable};
use vmm_sys_util::eventfd::EventFd; use vmm_sys_util::eventfd::EventFd;
@ -48,7 +46,7 @@ const VIRTIO_PMEM_RESP_TYPE_EIO: u32 = 1;
// New descriptors are pending on the virtio queue. // New descriptors are pending on the virtio queue.
const QUEUE_AVAIL_EVENT: u16 = EPOLL_HELPER_EVENT_LAST + 1; const QUEUE_AVAIL_EVENT: u16 = EPOLL_HELPER_EVENT_LAST + 1;
#[derive(Copy, Clone, Debug, Default, Versionize)] #[derive(Copy, Clone, Debug, Default, Serialize, Deserialize)]
#[repr(C)] #[repr(C)]
struct VirtioPmemConfig { struct VirtioPmemConfig {
start: u64, start: u64,
@ -279,15 +277,13 @@ pub struct Pmem {
_region: MmapRegion, _region: MmapRegion,
} }
#[derive(Versionize)] #[derive(Serialize, Deserialize)]
pub struct PmemState { pub struct PmemState {
avail_features: u64, avail_features: u64,
acked_features: u64, acked_features: u64,
config: VirtioPmemConfig, config: VirtioPmemConfig,
} }
impl VersionMapped for PmemState {}
impl Pmem { impl Pmem {
#[allow(clippy::too_many_arguments)] #[allow(clippy::too_many_arguments)]
pub fn new( pub fn new(
@ -468,7 +464,7 @@ impl Snapshottable for Pmem {
} }
fn snapshot(&mut self) -> std::result::Result<Snapshot, MigratableError> { fn snapshot(&mut self) -> std::result::Result<Snapshot, MigratableError> {
Snapshot::new_from_versioned_state(&self.state()) Snapshot::new_from_state(&self.state())
} }
} }

View File

@ -16,6 +16,7 @@ use crate::GuestMemoryMmap;
use crate::{VirtioInterrupt, VirtioInterruptType}; use crate::{VirtioInterrupt, VirtioInterruptType};
use anyhow::anyhow; use anyhow::anyhow;
use seccompiler::SeccompAction; use seccompiler::SeccompAction;
use serde::{Deserialize, Serialize};
use std::fs::File; use std::fs::File;
use std::io; use std::io;
use std::os::unix::io::AsRawFd; use std::os::unix::io::AsRawFd;
@ -23,11 +24,8 @@ use std::result;
use std::sync::atomic::AtomicBool; use std::sync::atomic::AtomicBool;
use std::sync::{Arc, Barrier}; use std::sync::{Arc, Barrier};
use thiserror::Error; use thiserror::Error;
use versionize::{VersionMap, Versionize, VersionizeResult};
use versionize_derive::Versionize;
use virtio_queue::{Queue, QueueT}; use virtio_queue::{Queue, QueueT};
use vm_memory::{GuestAddressSpace, GuestMemory, GuestMemoryAtomic}; use vm_memory::{GuestAddressSpace, GuestMemory, GuestMemoryAtomic};
use vm_migration::VersionMapped;
use vm_migration::{Migratable, MigratableError, Pausable, Snapshot, Snapshottable, Transportable}; use vm_migration::{Migratable, MigratableError, Pausable, Snapshot, Snapshottable, Transportable};
use vm_virtio::{AccessPlatform, Translatable}; use vm_virtio::{AccessPlatform, Translatable};
use vmm_sys_util::eventfd::EventFd; use vmm_sys_util::eventfd::EventFd;
@ -160,14 +158,12 @@ pub struct Rng {
exit_evt: EventFd, exit_evt: EventFd,
} }
#[derive(Versionize)] #[derive(Deserialize, Serialize)]
pub struct RngState { pub struct RngState {
pub avail_features: u64, pub avail_features: u64,
pub acked_features: u64, pub acked_features: u64,
} }
impl VersionMapped for RngState {}
impl Rng { impl Rng {
/// Create a new virtio rng device that gets random data from /dev/urandom. /// Create a new virtio rng device that gets random data from /dev/urandom.
pub fn new( pub fn new(
@ -326,7 +322,7 @@ impl Snapshottable for Rng {
} }
fn snapshot(&mut self) -> std::result::Result<Snapshot, MigratableError> { fn snapshot(&mut self) -> std::result::Result<Snapshot, MigratableError> {
Snapshot::new_from_versioned_state(&self.state()) Snapshot::new_from_state(&self.state())
} }
} }

View File

@ -8,17 +8,16 @@
use crate::VirtioDevice; use crate::VirtioDevice;
use byteorder::{ByteOrder, LittleEndian}; use byteorder::{ByteOrder, LittleEndian};
use serde::{Deserialize, Serialize};
use std::sync::atomic::{AtomicU16, Ordering}; use std::sync::atomic::{AtomicU16, Ordering};
use std::sync::{Arc, Mutex}; use std::sync::{Arc, Mutex};
use versionize::{VersionMap, Versionize, VersionizeResult};
use versionize_derive::Versionize;
use virtio_queue::{Queue, QueueT}; use virtio_queue::{Queue, QueueT};
use vm_migration::{MigratableError, Pausable, Snapshot, Snapshottable, VersionMapped}; use vm_migration::{MigratableError, Pausable, Snapshot, Snapshottable};
use vm_virtio::AccessPlatform; use vm_virtio::AccessPlatform;
pub const VIRTIO_PCI_COMMON_CONFIG_ID: &str = "virtio_pci_common_config"; pub const VIRTIO_PCI_COMMON_CONFIG_ID: &str = "virtio_pci_common_config";
#[derive(Clone, Versionize)] #[derive(Clone, Serialize, Deserialize)]
pub struct VirtioPciCommonConfigState { pub struct VirtioPciCommonConfigState {
pub driver_status: u8, pub driver_status: u8,
pub config_generation: u8, pub config_generation: u8,
@ -29,8 +28,6 @@ pub struct VirtioPciCommonConfigState {
pub msix_queues: Vec<u16>, pub msix_queues: Vec<u16>,
} }
impl VersionMapped for VirtioPciCommonConfigState {}
/// Contains the data for reading and writing the common configuration structure of a virtio PCI /// Contains the data for reading and writing the common configuration structure of a virtio PCI
/// device. /// device.
/// ///
@ -321,7 +318,7 @@ impl Snapshottable for VirtioPciCommonConfig {
} }
fn snapshot(&mut self) -> std::result::Result<Snapshot, MigratableError> { fn snapshot(&mut self) -> std::result::Result<Snapshot, MigratableError> {
Snapshot::new_from_versioned_state(&self.state()) Snapshot::new_from_state(&self.state())
} }
} }

View File

@ -20,6 +20,7 @@ use pci::{
PciCapability, PciCapabilityId, PciClassCode, PciConfiguration, PciDevice, PciDeviceError, PciCapability, PciCapabilityId, PciClassCode, PciConfiguration, PciDevice, PciDeviceError,
PciHeaderType, PciMassStorageSubclass, PciNetworkControllerSubclass, PciSubclass, PciHeaderType, PciMassStorageSubclass, PciNetworkControllerSubclass, PciSubclass,
}; };
use serde::{Deserialize, Serialize};
use std::any::Any; use std::any::Any;
use std::cmp; use std::cmp;
use std::io::Write; use std::io::Write;
@ -27,8 +28,6 @@ use std::ops::Deref;
use std::sync::atomic::{AtomicBool, AtomicU16, AtomicUsize, Ordering}; use std::sync::atomic::{AtomicBool, AtomicU16, AtomicUsize, Ordering};
use std::sync::{Arc, Barrier, Mutex}; use std::sync::{Arc, Barrier, Mutex};
use thiserror::Error; use thiserror::Error;
use versionize::{VersionMap, Versionize, VersionizeResult};
use versionize_derive::Versionize;
use virtio_queue::{Queue, QueueT}; use virtio_queue::{Queue, QueueT};
use vm_allocator::{AddressAllocator, SystemAllocator}; use vm_allocator::{AddressAllocator, SystemAllocator};
use vm_device::dma_mapping::ExternalDmaMapping; use vm_device::dma_mapping::ExternalDmaMapping;
@ -37,9 +36,7 @@ use vm_device::interrupt::{
}; };
use vm_device::{BusDevice, PciBarType, Resource}; use vm_device::{BusDevice, PciBarType, Resource};
use vm_memory::{Address, ByteValued, GuestAddress, GuestAddressSpace, GuestMemoryAtomic, Le32}; use vm_memory::{Address, ByteValued, GuestAddress, GuestAddressSpace, GuestMemoryAtomic, Le32};
use vm_migration::{ use vm_migration::{Migratable, MigratableError, Pausable, Snapshot, Snapshottable, Transportable};
Migratable, MigratableError, Pausable, Snapshot, Snapshottable, Transportable, VersionMapped,
};
use vm_virtio::AccessPlatform; use vm_virtio::AccessPlatform;
use vmm_sys_util::eventfd::EventFd; use vmm_sys_util::eventfd::EventFd;
@ -263,7 +260,7 @@ const NOTIFY_OFF_MULTIPLIER: u32 = 4; // A dword per notification address.
const VIRTIO_PCI_VENDOR_ID: u16 = 0x1af4; const VIRTIO_PCI_VENDOR_ID: u16 = 0x1af4;
const VIRTIO_PCI_DEVICE_ID_BASE: u16 = 0x1040; // Add to device type to get device ID. const VIRTIO_PCI_DEVICE_ID_BASE: u16 = 0x1040; // Add to device type to get device ID.
#[derive(Versionize)] #[derive(Serialize, Deserialize)]
struct QueueState { struct QueueState {
max_size: u16, max_size: u16,
size: u16, size: u16,
@ -273,7 +270,7 @@ struct QueueState {
used_ring: u64, used_ring: u64,
} }
#[derive(Versionize)] #[derive(Serialize, Deserialize)]
pub struct VirtioPciDeviceState { pub struct VirtioPciDeviceState {
device_activated: bool, device_activated: bool,
queues: Vec<QueueState>, queues: Vec<QueueState>,
@ -282,8 +279,6 @@ pub struct VirtioPciDeviceState {
cap_pci_cfg: Vec<u8>, cap_pci_cfg: Vec<u8>,
} }
impl VersionMapped for VirtioPciDeviceState {}
pub struct VirtioPciDeviceActivator { pub struct VirtioPciDeviceActivator {
interrupt: Option<Arc<dyn VirtioInterrupt>>, interrupt: Option<Arc<dyn VirtioInterrupt>>,
memory: Option<GuestMemoryAtomic<GuestMemoryMmap>>, memory: Option<GuestMemoryAtomic<GuestMemoryMmap>>,
@ -431,15 +426,13 @@ impl VirtioPciDevice {
)) ))
})?; })?;
let msix_state = let msix_state = vm_migration::state_from_id(snapshot.as_ref(), pci::MSIX_CONFIG_ID)
vm_migration::versioned_state_from_id(snapshot.as_ref(), pci::MSIX_CONFIG_ID).map_err( .map_err(|e| {
|e| { VirtioPciDeviceError::CreateVirtioPciDevice(anyhow!(
VirtioPciDeviceError::CreateVirtioPciDevice(anyhow!( "Failed to get MsixConfigState from Snapshot: {}",
"Failed to get MsixConfigState from Snapshot: {}", e
e ))
)) })?;
},
)?;
let (msix_config, msix_config_clone) = if msix_num > 0 { let (msix_config, msix_config_clone) = if msix_num > 0 {
let msix_config = Arc::new(Mutex::new( let msix_config = Arc::new(Mutex::new(
@ -473,13 +466,14 @@ impl VirtioPciDevice {
}; };
let pci_configuration_state = let pci_configuration_state =
vm_migration::versioned_state_from_id(snapshot.as_ref(), pci::PCI_CONFIGURATION_ID) vm_migration::state_from_id(snapshot.as_ref(), pci::PCI_CONFIGURATION_ID).map_err(
.map_err(|e| { |e| {
VirtioPciDeviceError::CreateVirtioPciDevice(anyhow!( VirtioPciDeviceError::CreateVirtioPciDevice(anyhow!(
"Failed to get PciConfigurationState from Snapshot: {}", "Failed to get PciConfigurationState from Snapshot: {}",
e e
)) ))
})?; },
)?;
let configuration = PciConfiguration::new( let configuration = PciConfiguration::new(
VIRTIO_PCI_VENDOR_ID, VIRTIO_PCI_VENDOR_ID,
@ -496,13 +490,14 @@ impl VirtioPciDevice {
); );
let common_config_state = let common_config_state =
vm_migration::versioned_state_from_id(snapshot.as_ref(), VIRTIO_PCI_COMMON_CONFIG_ID) vm_migration::state_from_id(snapshot.as_ref(), VIRTIO_PCI_COMMON_CONFIG_ID).map_err(
.map_err(|e| { |e| {
VirtioPciDeviceError::CreateVirtioPciDevice(anyhow!( VirtioPciDeviceError::CreateVirtioPciDevice(anyhow!(
"Failed to get VirtioPciCommonConfigState from Snapshot: {}", "Failed to get VirtioPciCommonConfigState from Snapshot: {}",
e e
)) ))
})?; },
)?;
let common_config = if let Some(common_config_state) = common_config_state { let common_config = if let Some(common_config_state) = common_config_state {
VirtioPciCommonConfig::new(common_config_state, access_platform) VirtioPciCommonConfig::new(common_config_state, access_platform)
@ -523,7 +518,7 @@ impl VirtioPciDevice {
let state: Option<VirtioPciDeviceState> = snapshot let state: Option<VirtioPciDeviceState> = snapshot
.as_ref() .as_ref()
.map(|s| s.to_versioned_state()) .map(|s| s.to_state())
.transpose() .transpose()
.map_err(|e| { .map_err(|e| {
VirtioPciDeviceError::CreateVirtioPciDevice(anyhow!( VirtioPciDeviceError::CreateVirtioPciDevice(anyhow!(
@ -1289,7 +1284,7 @@ impl Snapshottable for VirtioPciDevice {
} }
fn snapshot(&mut self) -> std::result::Result<Snapshot, MigratableError> { fn snapshot(&mut self) -> std::result::Result<Snapshot, MigratableError> {
let mut virtio_pci_dev_snapshot = Snapshot::new_from_versioned_state(&self.state())?; let mut virtio_pci_dev_snapshot = Snapshot::new_from_state(&self.state())?;
// Snapshot PciConfiguration // Snapshot PciConfiguration
virtio_pci_dev_snapshot virtio_pci_dev_snapshot

View File

@ -9,6 +9,7 @@ use crate::{
VIRTIO_F_IOMMU_PLATFORM, VIRTIO_F_IOMMU_PLATFORM,
}; };
use anyhow::anyhow; use anyhow::anyhow;
use serde::{Deserialize, Serialize};
use std::{ use std::{
collections::BTreeMap, collections::BTreeMap,
io, result, io, result,
@ -18,8 +19,6 @@ use std::{
}, },
}; };
use thiserror::Error; use thiserror::Error;
use versionize::{VersionMap, Versionize, VersionizeResult};
use versionize_derive::Versionize;
use vhost::{ use vhost::{
vdpa::{VhostVdpa, VhostVdpaIovaRange}, vdpa::{VhostVdpa, VhostVdpaIovaRange},
vhost_kern::VhostKernFeatures, vhost_kern::VhostKernFeatures,
@ -29,9 +28,7 @@ use vhost::{
use virtio_queue::{Descriptor, Queue, QueueT}; use virtio_queue::{Descriptor, Queue, QueueT};
use vm_device::dma_mapping::ExternalDmaMapping; use vm_device::dma_mapping::ExternalDmaMapping;
use vm_memory::{GuestAddress, GuestAddressSpace, GuestMemory, GuestMemoryAtomic}; use vm_memory::{GuestAddress, GuestAddressSpace, GuestMemory, GuestMemoryAtomic};
use vm_migration::{ use vm_migration::{Migratable, MigratableError, Pausable, Snapshot, Snapshottable, Transportable};
Migratable, MigratableError, Pausable, Snapshot, Snapshottable, Transportable, VersionMapped,
};
use vm_virtio::{AccessPlatform, Translatable}; use vm_virtio::{AccessPlatform, Translatable};
use vmm_sys_util::eventfd::EventFd; use vmm_sys_util::eventfd::EventFd;
@ -95,7 +92,7 @@ pub enum Error {
pub type Result<T> = std::result::Result<T, Error>; pub type Result<T> = std::result::Result<T, Error>;
#[derive(Versionize)] #[derive(Serialize, Deserialize)]
pub struct VdpaState { pub struct VdpaState {
pub avail_features: u64, pub avail_features: u64,
pub acked_features: u64, pub acked_features: u64,
@ -107,8 +104,6 @@ pub struct VdpaState {
pub backend_features: u64, pub backend_features: u64,
} }
impl VersionMapped for VdpaState {}
pub struct Vdpa { pub struct Vdpa {
common: VirtioCommon, common: VirtioCommon,
id: String, id: String,
@ -489,7 +484,7 @@ impl Snapshottable for Vdpa {
))); )));
} }
let snapshot = Snapshot::new_from_versioned_state(&self.state().map_err(|e| { let snapshot = Snapshot::new_from_state(&self.state().map_err(|e| {
MigratableError::Snapshot(anyhow!("Error snapshotting vDPA device: {:?}", e)) MigratableError::Snapshot(anyhow!("Error snapshotting vDPA device: {:?}", e))
})?)?; })?)?;

View File

@ -11,13 +11,13 @@ use crate::{GuestMemoryMmap, GuestRegionMmap};
use crate::{VirtioInterrupt, VIRTIO_F_IOMMU_PLATFORM}; use crate::{VirtioInterrupt, VIRTIO_F_IOMMU_PLATFORM};
use block::VirtioBlockConfig; use block::VirtioBlockConfig;
use seccompiler::SeccompAction; use seccompiler::SeccompAction;
use serde::{Deserialize, Serialize};
use std::mem; use std::mem;
use std::result; use std::result;
use std::sync::atomic::AtomicBool; use std::sync::atomic::AtomicBool;
use std::sync::{Arc, Barrier, Mutex}; use std::sync::{Arc, Barrier, Mutex};
use std::thread; use std::thread;
use versionize::{VersionMap, Versionize, VersionizeResult};
use versionize_derive::Versionize;
use vhost::vhost_user::message::{ use vhost::vhost_user::message::{
VhostUserConfigFlags, VhostUserProtocolFeatures, VhostUserVirtioFeatures, VhostUserConfigFlags, VhostUserProtocolFeatures, VhostUserVirtioFeatures,
VHOST_USER_CONFIG_OFFSET, VHOST_USER_CONFIG_OFFSET,
@ -32,13 +32,13 @@ use virtio_queue::Queue;
use vm_memory::{ByteValued, GuestMemoryAtomic}; use vm_memory::{ByteValued, GuestMemoryAtomic};
use vm_migration::{ use vm_migration::{
protocol::MemoryRangeTable, Migratable, MigratableError, Pausable, Snapshot, Snapshottable, protocol::MemoryRangeTable, Migratable, MigratableError, Pausable, Snapshot, Snapshottable,
Transportable, VersionMapped, Transportable,
}; };
use vmm_sys_util::eventfd::EventFd; use vmm_sys_util::eventfd::EventFd;
const DEFAULT_QUEUE_NUMBER: usize = 1; const DEFAULT_QUEUE_NUMBER: usize = 1;
#[derive(Versionize)] #[derive(Serialize, Deserialize)]
pub struct State { pub struct State {
pub avail_features: u64, pub avail_features: u64,
pub acked_features: u64, pub acked_features: u64,
@ -47,8 +47,6 @@ pub struct State {
pub vu_num_queues: usize, pub vu_num_queues: usize,
} }
impl VersionMapped for State {}
struct BackendReqHandler {} struct BackendReqHandler {}
impl VhostUserFrontendReqHandler for BackendReqHandler {} impl VhostUserFrontendReqHandler for BackendReqHandler {}

View File

@ -13,14 +13,14 @@ use crate::{
use crate::{GuestMemoryMmap, GuestRegionMmap, MmapRegion}; use crate::{GuestMemoryMmap, GuestRegionMmap, MmapRegion};
use libc::{c_void, off64_t, pread64, pwrite64}; use libc::{c_void, off64_t, pread64, pwrite64};
use seccompiler::SeccompAction; use seccompiler::SeccompAction;
use serde::{Deserialize, Serialize};
use serde_with::{serde_as, Bytes};
use std::io; use std::io;
use std::os::unix::io::AsRawFd; use std::os::unix::io::AsRawFd;
use std::result; use std::result;
use std::sync::atomic::AtomicBool; use std::sync::atomic::AtomicBool;
use std::sync::{Arc, Barrier, Mutex}; use std::sync::{Arc, Barrier, Mutex};
use std::thread; use std::thread;
use versionize::{VersionMap, Versionize, VersionizeResult};
use versionize_derive::Versionize;
use vhost::vhost_user::message::{ use vhost::vhost_user::message::{
VhostUserFSBackendMsg, VhostUserFSBackendMsgFlags, VhostUserProtocolFeatures, VhostUserFSBackendMsg, VhostUserFSBackendMsgFlags, VhostUserProtocolFeatures,
VhostUserVirtioFeatures, VHOST_USER_FS_BACKEND_ENTRIES, VhostUserVirtioFeatures, VHOST_USER_FS_BACKEND_ENTRIES,
@ -34,14 +34,14 @@ use vm_memory::{
}; };
use vm_migration::{ use vm_migration::{
protocol::MemoryRangeTable, Migratable, MigratableError, Pausable, Snapshot, Snapshottable, protocol::MemoryRangeTable, Migratable, MigratableError, Pausable, Snapshot, Snapshottable,
Transportable, VersionMapped, Transportable,
}; };
use vmm_sys_util::eventfd::EventFd; use vmm_sys_util::eventfd::EventFd;
const NUM_QUEUE_OFFSET: usize = 1; const NUM_QUEUE_OFFSET: usize = 1;
const DEFAULT_QUEUE_NUMBER: usize = 2; const DEFAULT_QUEUE_NUMBER: usize = 2;
#[derive(Versionize)] #[derive(Serialize, Deserialize)]
pub struct State { pub struct State {
pub avail_features: u64, pub avail_features: u64,
pub acked_features: u64, pub acked_features: u64,
@ -51,8 +51,6 @@ pub struct State {
pub backend_req_support: bool, pub backend_req_support: bool,
} }
impl VersionMapped for State {}
struct BackendReqHandler { struct BackendReqHandler {
cache_offset: GuestAddress, cache_offset: GuestAddress,
cache_size: u64, cache_size: u64,
@ -272,9 +270,11 @@ impl VhostUserFrontendReqHandler for BackendReqHandler {
} }
pub const VIRTIO_FS_TAG_LEN: usize = 36; pub const VIRTIO_FS_TAG_LEN: usize = 36;
#[derive(Copy, Clone, Versionize)] #[serde_as]
#[derive(Copy, Clone, Serialize, Deserialize)]
#[repr(C, packed)] #[repr(C, packed)]
pub struct VirtioFsConfig { pub struct VirtioFsConfig {
#[serde_as(as = "Bytes")]
pub tag: [u8; VIRTIO_FS_TAG_LEN], pub tag: [u8; VIRTIO_FS_TAG_LEN],
pub num_request_queues: u32, pub num_request_queues: u32,
} }

View File

@ -8,12 +8,12 @@ use crate::{
VIRTIO_F_RING_INDIRECT_DESC, VIRTIO_F_VERSION_1, VIRTIO_F_RING_INDIRECT_DESC, VIRTIO_F_VERSION_1,
}; };
use anyhow::anyhow; use anyhow::anyhow;
use serde::{Deserialize, Serialize};
use std::io; use std::io;
use std::ops::Deref; use std::ops::Deref;
use std::os::unix::io::AsRawFd; use std::os::unix::io::AsRawFd;
use std::sync::{atomic::AtomicBool, Arc, Barrier, Mutex}; use std::sync::{atomic::AtomicBool, Arc, Barrier, Mutex};
use thiserror::Error; use thiserror::Error;
use versionize::Versionize;
use vhost::vhost_user::message::{ use vhost::vhost_user::message::{
VhostUserInflight, VhostUserProtocolFeatures, VhostUserVirtioFeatures, VhostUserInflight, VhostUserProtocolFeatures, VhostUserVirtioFeatures,
}; };
@ -25,7 +25,7 @@ use vm_memory::{
mmap::MmapRegionError, Address, Error as MmapError, GuestAddressSpace, GuestMemory, mmap::MmapRegionError, Address, Error as MmapError, GuestAddressSpace, GuestMemory,
GuestMemoryAtomic, GuestMemoryAtomic,
}; };
use vm_migration::{protocol::MemoryRangeTable, MigratableError, Snapshot, VersionMapped}; use vm_migration::{protocol::MemoryRangeTable, MigratableError, Snapshot};
use vmm_sys_util::eventfd::EventFd; use vmm_sys_util::eventfd::EventFd;
use vu_common_ctrl::VhostUserHandle; use vu_common_ctrl::VhostUserHandle;
@ -430,11 +430,11 @@ impl VhostUserCommon {
} }
} }
pub fn snapshot<T>(&mut self, state: &T) -> std::result::Result<Snapshot, MigratableError> pub fn snapshot<'a, T>(&mut self, state: &T) -> std::result::Result<Snapshot, MigratableError>
where where
T: Versionize + VersionMapped, T: Serialize + Deserialize<'a>,
{ {
let snapshot = Snapshot::new_from_versioned_state(state)?; let snapshot = Snapshot::new_from_state(state)?;
if self.migration_started { if self.migration_started {
self.shutdown(); self.shutdown();

View File

@ -12,12 +12,11 @@ use crate::{
use crate::{GuestMemoryMmap, GuestRegionMmap}; use crate::{GuestMemoryMmap, GuestRegionMmap};
use net_util::{build_net_config_space, CtrlQueue, MacAddr, VirtioNetConfig}; use net_util::{build_net_config_space, CtrlQueue, MacAddr, VirtioNetConfig};
use seccompiler::SeccompAction; use seccompiler::SeccompAction;
use serde::{Deserialize, Serialize};
use std::result; use std::result;
use std::sync::atomic::AtomicBool; use std::sync::atomic::AtomicBool;
use std::sync::{Arc, Barrier, Mutex}; use std::sync::{Arc, Barrier, Mutex};
use std::thread; use std::thread;
use versionize::{VersionMap, Versionize, VersionizeResult};
use versionize_derive::Versionize;
use vhost::vhost_user::message::{VhostUserProtocolFeatures, VhostUserVirtioFeatures}; use vhost::vhost_user::message::{VhostUserProtocolFeatures, VhostUserVirtioFeatures};
use vhost::vhost_user::{FrontendReqHandler, VhostUserFrontend, VhostUserFrontendReqHandler}; use vhost::vhost_user::{FrontendReqHandler, VhostUserFrontend, VhostUserFrontendReqHandler};
use virtio_bindings::virtio_net::{ use virtio_bindings::virtio_net::{
@ -31,13 +30,13 @@ use virtio_queue::{Queue, QueueT};
use vm_memory::{ByteValued, GuestMemoryAtomic}; use vm_memory::{ByteValued, GuestMemoryAtomic};
use vm_migration::{ use vm_migration::{
protocol::MemoryRangeTable, Migratable, MigratableError, Pausable, Snapshot, Snapshottable, protocol::MemoryRangeTable, Migratable, MigratableError, Pausable, Snapshot, Snapshottable,
Transportable, VersionMapped, Transportable,
}; };
use vmm_sys_util::eventfd::EventFd; use vmm_sys_util::eventfd::EventFd;
const DEFAULT_QUEUE_NUMBER: usize = 2; const DEFAULT_QUEUE_NUMBER: usize = 2;
#[derive(Versionize)] #[derive(Serialize, Deserialize)]
pub struct State { pub struct State {
pub avail_features: u64, pub avail_features: u64,
pub acked_features: u64, pub acked_features: u64,
@ -46,8 +45,6 @@ pub struct State {
pub vu_num_queues: usize, pub vu_num_queues: usize,
} }
impl VersionMapped for State {}
struct BackendReqHandler {} struct BackendReqHandler {}
impl VhostUserFrontendReqHandler for BackendReqHandler {} impl VhostUserFrontendReqHandler for BackendReqHandler {}

View File

@ -40,22 +40,19 @@ use crate::{
use anyhow::anyhow; use anyhow::anyhow;
use byteorder::{ByteOrder, LittleEndian}; use byteorder::{ByteOrder, LittleEndian};
use seccompiler::SeccompAction; use seccompiler::SeccompAction;
use serde::{Deserialize, Serialize};
use std::io; use std::io;
use std::os::unix::io::AsRawFd; use std::os::unix::io::AsRawFd;
use std::path::PathBuf; use std::path::PathBuf;
use std::result; use std::result;
use std::sync::atomic::AtomicBool; use std::sync::atomic::AtomicBool;
use std::sync::{Arc, Barrier, RwLock}; use std::sync::{Arc, Barrier, RwLock};
use versionize::{VersionMap, Versionize, VersionizeResult};
use versionize_derive::Versionize;
use virtio_queue::Queue; use virtio_queue::Queue;
use virtio_queue::QueueOwnedT; use virtio_queue::QueueOwnedT;
use virtio_queue::QueueT; use virtio_queue::QueueT;
use vm_memory::GuestAddressSpace; use vm_memory::GuestAddressSpace;
use vm_memory::GuestMemoryAtomic; use vm_memory::GuestMemoryAtomic;
use vm_migration::{ use vm_migration::{Migratable, MigratableError, Pausable, Snapshot, Snapshottable, Transportable};
Migratable, MigratableError, Pausable, Snapshot, Snapshottable, Transportable, VersionMapped,
};
use vm_virtio::AccessPlatform; use vm_virtio::AccessPlatform;
use vmm_sys_util::eventfd::EventFd; use vmm_sys_util::eventfd::EventFd;
@ -323,14 +320,12 @@ pub struct Vsock<B: VsockBackend> {
exit_evt: EventFd, exit_evt: EventFd,
} }
#[derive(Versionize)] #[derive(Serialize, Deserialize)]
pub struct VsockState { pub struct VsockState {
pub avail_features: u64, pub avail_features: u64,
pub acked_features: u64, pub acked_features: u64,
} }
impl VersionMapped for VsockState {}
impl<B> Vsock<B> impl<B> Vsock<B>
where where
B: VsockBackend + Sync, B: VsockBackend + Sync,
@ -519,7 +514,7 @@ where
} }
fn snapshot(&mut self) -> std::result::Result<Snapshot, MigratableError> { fn snapshot(&mut self) -> std::result::Result<Snapshot, MigratableError> {
Snapshot::new_from_versioned_state(&self.state()) Snapshot::new_from_state(&self.state())
} }
} }
impl<B> Transportable for Vsock<B> where B: VsockBackend + Sync + 'static {} impl<B> Transportable for Vsock<B> where B: VsockBackend + Sync + 'static {}

View File

@ -16,6 +16,7 @@ use crate::GuestMemoryMmap;
use crate::{VirtioInterrupt, VirtioInterruptType}; use crate::{VirtioInterrupt, VirtioInterruptType};
use anyhow::anyhow; use anyhow::anyhow;
use seccompiler::SeccompAction; use seccompiler::SeccompAction;
use serde::{Deserialize, Serialize};
use std::fs::File; use std::fs::File;
use std::io::{self, Read}; use std::io::{self, Read};
use std::os::unix::io::{AsRawFd, FromRawFd, RawFd}; use std::os::unix::io::{AsRawFd, FromRawFd, RawFd};
@ -24,11 +25,8 @@ use std::sync::atomic::AtomicBool;
use std::sync::{Arc, Barrier, Mutex}; use std::sync::{Arc, Barrier, Mutex};
use std::time::Instant; use std::time::Instant;
use thiserror::Error; use thiserror::Error;
use versionize::{VersionMap, Versionize, VersionizeResult};
use versionize_derive::Versionize;
use virtio_queue::{Queue, QueueT}; use virtio_queue::{Queue, QueueT};
use vm_memory::{Bytes, GuestAddressSpace, GuestMemoryAtomic}; use vm_memory::{Bytes, GuestAddressSpace, GuestMemoryAtomic};
use vm_migration::VersionMapped;
use vm_migration::{Migratable, MigratableError, Pausable, Snapshot, Snapshottable, Transportable}; use vm_migration::{Migratable, MigratableError, Pausable, Snapshot, Snapshottable, Transportable};
use vmm_sys_util::eventfd::EventFd; use vmm_sys_util::eventfd::EventFd;
@ -197,15 +195,13 @@ pub struct Watchdog {
exit_evt: EventFd, exit_evt: EventFd,
} }
#[derive(Versionize)] #[derive(Serialize, Deserialize)]
pub struct WatchdogState { pub struct WatchdogState {
pub avail_features: u64, pub avail_features: u64,
pub acked_features: u64, pub acked_features: u64,
pub enabled: bool, pub enabled: bool,
} }
impl VersionMapped for WatchdogState {}
impl Watchdog { impl Watchdog {
/// Create a new virtio watchdog device that will reboot VM if the guest hangs /// Create a new virtio watchdog device that will reboot VM if the guest hangs
pub fn new( pub fn new(
@ -420,7 +416,7 @@ impl Snapshottable for Watchdog {
} }
fn snapshot(&mut self) -> std::result::Result<Snapshot, MigratableError> { fn snapshot(&mut self) -> std::result::Result<Snapshot, MigratableError> {
Snapshot::new_from_versioned_state(&self.state()) Snapshot::new_from_state(&self.state())
} }
} }

View File

@ -9,6 +9,4 @@ anyhow = "1.0.81"
thiserror = "1.0.58" thiserror = "1.0.58"
serde = { version = "1.0.197", features = ["rc", "derive"] } serde = { version = "1.0.197", features = ["rc", "derive"] }
serde_json = "1.0.115" serde_json = "1.0.115"
versionize = "0.2.0"
versionize_derive = "0.1.6"
vm-memory = { version = "0.14.1", features = ["backend-mmap", "backend-atomic"] } vm-memory = { version = "0.14.1", features = ["backend-mmap", "backend-atomic"] }

View File

@ -7,21 +7,9 @@ use crate::protocol::MemoryRangeTable;
use anyhow::anyhow; use anyhow::anyhow;
use serde::{Deserialize, Serialize}; use serde::{Deserialize, Serialize};
use thiserror::Error; use thiserror::Error;
use versionize::{VersionMap, Versionize};
pub mod protocol; pub mod protocol;
/// Global VMM version for versioning
const MAJOR_VERSION: u16 = 38;
const MINOR_VERSION: u16 = 0;
const VMM_VERSION: u16 = MAJOR_VERSION << 12 | MINOR_VERSION & 0b1111;
pub trait VersionMapped {
fn version_map() -> VersionMap {
VersionMap::new()
}
}
#[derive(Error, Debug)] #[derive(Error, Debug)]
pub enum MigratableError { pub enum MigratableError {
#[error("Failed to pause migratable component: {0}")] #[error("Failed to pause migratable component: {0}")]
@ -80,7 +68,9 @@ pub trait Pausable {
/// Splitting a component migration data into different sections /// Splitting a component migration data into different sections
/// allows for easier and forward compatible extensions. /// allows for easier and forward compatible extensions.
#[derive(Clone, Default, Deserialize, Serialize)] #[derive(Clone, Default, Deserialize, Serialize)]
pub struct SnapshotData(pub Vec<u8>); pub struct SnapshotData {
state: String,
}
impl SnapshotData { impl SnapshotData {
/// Generate the state data from the snapshot data /// Generate the state data from the snapshot data
@ -88,16 +78,7 @@ impl SnapshotData {
where where
T: Deserialize<'a>, T: Deserialize<'a>,
{ {
serde_json::from_slice(&self.0) serde_json::from_str(&self.state)
.map_err(|e| MigratableError::Restore(anyhow!("Error deserialising: {}", e)))
}
/// Generate versioned state
pub fn to_versioned_state<T>(&self) -> Result<T, MigratableError>
where
T: Versionize + VersionMapped,
{
T::deserialize(&mut self.0.as_slice(), &T::version_map(), VMM_VERSION)
.map_err(|e| MigratableError::Restore(anyhow!("Error deserialising: {}", e))) .map_err(|e| MigratableError::Restore(anyhow!("Error deserialising: {}", e)))
} }
@ -106,23 +87,10 @@ impl SnapshotData {
where where
T: Serialize, T: Serialize,
{ {
let data = serde_json::to_vec(state) let state = serde_json::to_string(state)
.map_err(|e| MigratableError::Snapshot(anyhow!("Error serialising: {}", e)))?; .map_err(|e| MigratableError::Snapshot(anyhow!("Error serialising: {}", e)))?;
Ok(SnapshotData(data)) Ok(SnapshotData { state })
}
/// Create from versioned state
pub fn new_from_versioned_state<T>(state: &T) -> Result<Self, MigratableError>
where
T: Versionize + VersionMapped,
{
let mut data = Vec::new();
state
.serialize(&mut data, &T::version_map(), VMM_VERSION)
.map_err(|e| MigratableError::Snapshot(anyhow!("Error serialising: {}", e)))?;
Ok(SnapshotData(data))
} }
} }
@ -163,16 +131,6 @@ impl Snapshot {
Ok(Snapshot::from_data(SnapshotData::new_from_state(state)?)) Ok(Snapshot::from_data(SnapshotData::new_from_state(state)?))
} }
/// Create from versioned state
pub fn new_from_versioned_state<T>(state: &T) -> Result<Self, MigratableError>
where
T: Versionize + VersionMapped,
{
Ok(Snapshot::from_data(SnapshotData::new_from_versioned_state(
state,
)?))
}
/// Add a sub-component's Snapshot to the Snapshot. /// Add a sub-component's Snapshot to the Snapshot.
pub fn add_snapshot(&mut self, id: String, snapshot: Snapshot) { pub fn add_snapshot(&mut self, id: String, snapshot: Snapshot) {
self.snapshots.insert(id, snapshot); self.snapshots.insert(id, snapshot);
@ -188,34 +146,21 @@ impl Snapshot {
.ok_or_else(|| MigratableError::Restore(anyhow!("Missing snapshot data")))? .ok_or_else(|| MigratableError::Restore(anyhow!("Missing snapshot data")))?
.to_state() .to_state()
} }
/// Generate versioned state
pub fn to_versioned_state<T>(&self) -> Result<T, MigratableError>
where
T: Versionize + VersionMapped,
{
self.snapshot_data
.as_ref()
.ok_or_else(|| MigratableError::Restore(anyhow!("Missing snapshot data")))?
.to_versioned_state()
}
} }
pub fn snapshot_from_id(snapshot: Option<&Snapshot>, id: &str) -> Option<Snapshot> { pub fn snapshot_from_id(snapshot: Option<&Snapshot>, id: &str) -> Option<Snapshot> {
snapshot.and_then(|s| s.snapshots.get(id).cloned()) snapshot.and_then(|s| s.snapshots.get(id).cloned())
} }
pub fn versioned_state_from_id<T>( pub fn state_from_id<'a, T>(s: Option<&'a Snapshot>, id: &str) -> Result<Option<T>, MigratableError>
snapshot: Option<&Snapshot>,
id: &str,
) -> Result<Option<T>, MigratableError>
where where
T: Versionize + VersionMapped, T: Deserialize<'a>,
{ {
snapshot if let Some(s) = s.as_ref() {
.and_then(|s| s.snapshots.get(id).cloned()) s.snapshots.get(id).map(|s| s.to_state()).transpose()
.map(|s| s.to_versioned_state()) } else {
.transpose() Ok(None)
}
} }
/// A snapshottable component can be snapshotted. /// A snapshottable component can be snapshotted.

View File

@ -3,11 +3,9 @@
// SPDX-License-Identifier: Apache-2.0 // SPDX-License-Identifier: Apache-2.0
// //
use crate::{MigratableError, VersionMapped}; use crate::MigratableError;
use serde::{Deserialize, Serialize}; use serde::{Deserialize, Serialize};
use std::io::{Read, Write}; use std::io::{Read, Write};
use versionize::{VersionMap, Versionize, VersionizeResult};
use versionize_derive::Versionize;
use vm_memory::ByteValued; use vm_memory::ByteValued;
// Migration protocol // Migration protocol
@ -199,19 +197,17 @@ impl Response {
} }
#[repr(C)] #[repr(C)]
#[derive(Clone, Default, Serialize, Deserialize, Versionize)] #[derive(Clone, Default, Serialize, Deserialize)]
pub struct MemoryRange { pub struct MemoryRange {
pub gpa: u64, pub gpa: u64,
pub length: u64, pub length: u64,
} }
#[derive(Clone, Default, Serialize, Deserialize, Versionize)] #[derive(Clone, Default, Serialize, Deserialize)]
pub struct MemoryRangeTable { pub struct MemoryRangeTable {
data: Vec<MemoryRange>, data: Vec<MemoryRange>,
} }
impl VersionMapped for MemoryRangeTable {}
impl MemoryRangeTable { impl MemoryRangeTable {
pub fn from_bitmap(bitmap: Vec<u64>, start_addr: u64, page_size: u64) -> Self { pub fn from_bitmap(bitmap: Vec<u64>, start_addr: u64, page_size: u64) -> Self {
let mut table = MemoryRangeTable::default(); let mut table = MemoryRangeTable::default();

View File

@ -56,8 +56,6 @@ signal-hook = "0.3.17"
thiserror = "1.0.58" thiserror = "1.0.58"
tracer = { path = "../tracer" } tracer = { path = "../tracer" }
uuid = "1.8.0" uuid = "1.8.0"
versionize = "0.2.0"
versionize_derive = "0.1.6"
vfio-ioctls = { git = "https://github.com/rust-vmm/vfio", branch = "main", default-features = false } vfio-ioctls = { git = "https://github.com/rust-vmm/vfio", branch = "main", default-features = false }
vfio_user = { git = "https://github.com/rust-vmm/vfio-user", branch = "main" } vfio_user = { git = "https://github.com/rust-vmm/vfio-user", branch = "main" }
virtio-devices = { path = "../virtio-devices" } virtio-devices = { path = "../virtio-devices" }

View File

@ -96,8 +96,8 @@ use vm_memory::{Address, GuestAddress, GuestUsize, MmapRegion};
#[cfg(target_arch = "x86_64")] #[cfg(target_arch = "x86_64")]
use vm_memory::{GuestAddressSpace, GuestMemory}; use vm_memory::{GuestAddressSpace, GuestMemory};
use vm_migration::{ use vm_migration::{
protocol::MemoryRangeTable, snapshot_from_id, versioned_state_from_id, Migratable, protocol::MemoryRangeTable, snapshot_from_id, state_from_id, Migratable, MigratableError,
MigratableError, Pausable, Snapshot, SnapshotData, Snapshottable, Transportable, Pausable, Snapshot, SnapshotData, Snapshottable, Transportable,
}; };
use vm_virtio::AccessPlatform; use vm_virtio::AccessPlatform;
use vm_virtio::VirtioDeviceType; use vm_virtio::VirtioDeviceType;
@ -1371,7 +1371,7 @@ impl DeviceManager {
.try_clone() .try_clone()
.map_err(DeviceManagerError::EventFd)?, .map_err(DeviceManagerError::EventFd)?,
self.get_msi_iova_space(), self.get_msi_iova_space(),
versioned_state_from_id(self.snapshot.as_ref(), iommu_id.as_str()) state_from_id(self.snapshot.as_ref(), iommu_id.as_str())
.map_err(DeviceManagerError::RestoreGetState)?, .map_err(DeviceManagerError::RestoreGetState)?,
) )
.map_err(DeviceManagerError::CreateVirtioIommu)?; .map_err(DeviceManagerError::CreateVirtioIommu)?;
@ -1519,7 +1519,7 @@ impl DeviceManager {
id.clone(), id.clone(),
APIC_START, APIC_START,
Arc::clone(&self.msi_interrupt_manager), Arc::clone(&self.msi_interrupt_manager),
versioned_state_from_id(self.snapshot.as_ref(), id.as_str()) state_from_id(self.snapshot.as_ref(), id.as_str())
.map_err(DeviceManagerError::RestoreGetState)?, .map_err(DeviceManagerError::RestoreGetState)?,
) )
.map_err(DeviceManagerError::CreateInterruptController)?, .map_err(DeviceManagerError::CreateInterruptController)?,
@ -1791,7 +1791,7 @@ impl DeviceManager {
let gpio_device = Arc::new(Mutex::new(devices::legacy::Gpio::new( let gpio_device = Arc::new(Mutex::new(devices::legacy::Gpio::new(
id.clone(), id.clone(),
interrupt_group, interrupt_group,
versioned_state_from_id(self.snapshot.as_ref(), id.as_str()) state_from_id(self.snapshot.as_ref(), id.as_str())
.map_err(DeviceManagerError::RestoreGetState)?, .map_err(DeviceManagerError::RestoreGetState)?,
))); )));
@ -1892,7 +1892,7 @@ impl DeviceManager {
id.clone(), id.clone(),
interrupt_group, interrupt_group,
serial_writer, serial_writer,
versioned_state_from_id(self.snapshot.as_ref(), id.as_str()) state_from_id(self.snapshot.as_ref(), id.as_str())
.map_err(DeviceManagerError::RestoreGetState)?, .map_err(DeviceManagerError::RestoreGetState)?,
))); )));
@ -1949,7 +1949,7 @@ impl DeviceManager {
interrupt_group, interrupt_group,
serial_writer, serial_writer,
self.timestamp, self.timestamp,
versioned_state_from_id(self.snapshot.as_ref(), id.as_str()) state_from_id(self.snapshot.as_ref(), id.as_str())
.map_err(DeviceManagerError::RestoreGetState)?, .map_err(DeviceManagerError::RestoreGetState)?,
))); )));
@ -2128,7 +2128,7 @@ impl DeviceManager {
self.exit_evt self.exit_evt
.try_clone() .try_clone()
.map_err(DeviceManagerError::EventFd)?, .map_err(DeviceManagerError::EventFd)?,
versioned_state_from_id(self.snapshot.as_ref(), id.as_str()) state_from_id(self.snapshot.as_ref(), id.as_str())
.map_err(DeviceManagerError::RestoreGetState)?, .map_err(DeviceManagerError::RestoreGetState)?,
) )
.map_err(DeviceManagerError::CreateVirtioConsole)?; .map_err(DeviceManagerError::CreateVirtioConsole)?;
@ -2362,8 +2362,6 @@ impl DeviceManager {
info!("Creating virtio-block device: {:?}", disk_cfg); info!("Creating virtio-block device: {:?}", disk_cfg);
let snapshot = snapshot_from_id(self.snapshot.as_ref(), id.as_str());
let (virtio_device, migratable_device) = if disk_cfg.vhost_user { let (virtio_device, migratable_device) = if disk_cfg.vhost_user {
let socket = disk_cfg.vhost_socket.as_ref().unwrap().clone(); let socket = disk_cfg.vhost_socket.as_ref().unwrap().clone();
let vu_cfg = VhostUserConfig { let vu_cfg = VhostUserConfig {
@ -2380,9 +2378,7 @@ impl DeviceManager {
.try_clone() .try_clone()
.map_err(DeviceManagerError::EventFd)?, .map_err(DeviceManagerError::EventFd)?,
self.force_iommu, self.force_iommu,
snapshot state_from_id(self.snapshot.as_ref(), id.as_str())
.map(|s| s.to_versioned_state())
.transpose()
.map_err(DeviceManagerError::RestoreGetState)?, .map_err(DeviceManagerError::RestoreGetState)?,
) { ) {
Ok(vub_device) => vub_device, Ok(vub_device) => vub_device,
@ -2542,9 +2538,7 @@ impl DeviceManager {
self.exit_evt self.exit_evt
.try_clone() .try_clone()
.map_err(DeviceManagerError::EventFd)?, .map_err(DeviceManagerError::EventFd)?,
snapshot state_from_id(self.snapshot.as_ref(), id.as_str())
.map(|s| s.to_versioned_state())
.transpose()
.map_err(DeviceManagerError::RestoreGetState)?, .map_err(DeviceManagerError::RestoreGetState)?,
queue_affinity, queue_affinity,
) )
@ -2601,8 +2595,6 @@ impl DeviceManager {
}; };
info!("Creating virtio-net device: {:?}", net_cfg); info!("Creating virtio-net device: {:?}", net_cfg);
let snapshot = snapshot_from_id(self.snapshot.as_ref(), id.as_str());
let (virtio_device, migratable_device) = if net_cfg.vhost_user { let (virtio_device, migratable_device) = if net_cfg.vhost_user {
let socket = net_cfg.vhost_socket.as_ref().unwrap().clone(); let socket = net_cfg.vhost_socket.as_ref().unwrap().clone();
let vu_cfg = VhostUserConfig { let vu_cfg = VhostUserConfig {
@ -2626,9 +2618,7 @@ impl DeviceManager {
.try_clone() .try_clone()
.map_err(DeviceManagerError::EventFd)?, .map_err(DeviceManagerError::EventFd)?,
self.force_iommu, self.force_iommu,
snapshot state_from_id(self.snapshot.as_ref(), id.as_str())
.map(|s| s.to_versioned_state())
.transpose()
.map_err(DeviceManagerError::RestoreGetState)?, .map_err(DeviceManagerError::RestoreGetState)?,
net_cfg.offload_tso, net_cfg.offload_tso,
net_cfg.offload_ufo, net_cfg.offload_ufo,
@ -2646,11 +2636,8 @@ impl DeviceManager {
vhost_user_net as Arc<Mutex<dyn Migratable>>, vhost_user_net as Arc<Mutex<dyn Migratable>>,
) )
} else { } else {
let state = snapshot let state = state_from_id(self.snapshot.as_ref(), id.as_str())
.map(|s| s.to_versioned_state())
.transpose()
.map_err(DeviceManagerError::RestoreGetState)?; .map_err(DeviceManagerError::RestoreGetState)?;
let virtio_net = if let Some(ref tap_if_name) = net_cfg.tap { let virtio_net = if let Some(ref tap_if_name) = net_cfg.tap {
Arc::new(Mutex::new( Arc::new(Mutex::new(
virtio_devices::Net::new( virtio_devices::Net::new(
@ -2784,7 +2771,7 @@ impl DeviceManager {
self.exit_evt self.exit_evt
.try_clone() .try_clone()
.map_err(DeviceManagerError::EventFd)?, .map_err(DeviceManagerError::EventFd)?,
versioned_state_from_id(self.snapshot.as_ref(), id.as_str()) state_from_id(self.snapshot.as_ref(), id.as_str())
.map_err(DeviceManagerError::RestoreGetState)?, .map_err(DeviceManagerError::RestoreGetState)?,
) )
.map_err(DeviceManagerError::CreateVirtioRng)?, .map_err(DeviceManagerError::CreateVirtioRng)?,
@ -2840,7 +2827,7 @@ impl DeviceManager {
.try_clone() .try_clone()
.map_err(DeviceManagerError::EventFd)?, .map_err(DeviceManagerError::EventFd)?,
self.force_iommu, self.force_iommu,
versioned_state_from_id(self.snapshot.as_ref(), id.as_str()) state_from_id(self.snapshot.as_ref(), id.as_str())
.map_err(DeviceManagerError::RestoreGetState)?, .map_err(DeviceManagerError::RestoreGetState)?,
) )
.map_err(DeviceManagerError::CreateVirtioFs)?, .map_err(DeviceManagerError::CreateVirtioFs)?,
@ -3024,7 +3011,7 @@ impl DeviceManager {
self.exit_evt self.exit_evt
.try_clone() .try_clone()
.map_err(DeviceManagerError::EventFd)?, .map_err(DeviceManagerError::EventFd)?,
versioned_state_from_id(self.snapshot.as_ref(), id.as_str()) state_from_id(self.snapshot.as_ref(), id.as_str())
.map_err(DeviceManagerError::RestoreGetState)?, .map_err(DeviceManagerError::RestoreGetState)?,
) )
.map_err(DeviceManagerError::CreateVirtioPmem)?, .map_err(DeviceManagerError::CreateVirtioPmem)?,
@ -3096,7 +3083,7 @@ impl DeviceManager {
self.exit_evt self.exit_evt
.try_clone() .try_clone()
.map_err(DeviceManagerError::EventFd)?, .map_err(DeviceManagerError::EventFd)?,
versioned_state_from_id(self.snapshot.as_ref(), id.as_str()) state_from_id(self.snapshot.as_ref(), id.as_str())
.map_err(DeviceManagerError::RestoreGetState)?, .map_err(DeviceManagerError::RestoreGetState)?,
) )
.map_err(DeviceManagerError::CreateVirtioVsock)?, .map_err(DeviceManagerError::CreateVirtioVsock)?,
@ -3156,7 +3143,7 @@ impl DeviceManager {
.try_clone() .try_clone()
.map_err(DeviceManagerError::EventFd)?, .map_err(DeviceManagerError::EventFd)?,
virtio_mem_zone.blocks_state().clone(), virtio_mem_zone.blocks_state().clone(),
versioned_state_from_id(self.snapshot.as_ref(), memory_zone_id.as_str()) state_from_id(self.snapshot.as_ref(), memory_zone_id.as_str())
.map_err(DeviceManagerError::RestoreGetState)?, .map_err(DeviceManagerError::RestoreGetState)?,
) )
.map_err(DeviceManagerError::CreateVirtioMem)?, .map_err(DeviceManagerError::CreateVirtioMem)?,
@ -3208,7 +3195,7 @@ impl DeviceManager {
self.exit_evt self.exit_evt
.try_clone() .try_clone()
.map_err(DeviceManagerError::EventFd)?, .map_err(DeviceManagerError::EventFd)?,
versioned_state_from_id(self.snapshot.as_ref(), id.as_str()) state_from_id(self.snapshot.as_ref(), id.as_str())
.map_err(DeviceManagerError::RestoreGetState)?, .map_err(DeviceManagerError::RestoreGetState)?,
) )
.map_err(DeviceManagerError::CreateVirtioBalloon)?, .map_err(DeviceManagerError::CreateVirtioBalloon)?,
@ -3252,7 +3239,7 @@ impl DeviceManager {
self.exit_evt self.exit_evt
.try_clone() .try_clone()
.map_err(DeviceManagerError::EventFd)?, .map_err(DeviceManagerError::EventFd)?,
versioned_state_from_id(self.snapshot.as_ref(), id.as_str()) state_from_id(self.snapshot.as_ref(), id.as_str())
.map_err(DeviceManagerError::RestoreGetState)?, .map_err(DeviceManagerError::RestoreGetState)?,
) )
.map_err(DeviceManagerError::CreateVirtioWatchdog)?, .map_err(DeviceManagerError::CreateVirtioWatchdog)?,
@ -3299,7 +3286,7 @@ impl DeviceManager {
device_path, device_path,
self.memory_manager.lock().unwrap().guest_memory(), self.memory_manager.lock().unwrap().guest_memory(),
vdpa_cfg.num_queues as u16, vdpa_cfg.num_queues as u16,
versioned_state_from_id(self.snapshot.as_ref(), id.as_str()) state_from_id(self.snapshot.as_ref(), id.as_str())
.map_err(DeviceManagerError::RestoreGetState)?, .map_err(DeviceManagerError::RestoreGetState)?,
) )
.map_err(DeviceManagerError::CreateVdpa)?, .map_err(DeviceManagerError::CreateVdpa)?,

View File

@ -39,8 +39,6 @@ use std::result;
use std::sync::{Arc, Barrier, Mutex}; use std::sync::{Arc, Barrier, Mutex};
use std::{ffi, thread}; use std::{ffi, thread};
use tracer::trace_scoped; use tracer::trace_scoped;
use versionize::{VersionMap, Versionize, VersionizeResult};
use versionize_derive::Versionize;
use virtio_devices::BlocksState; use virtio_devices::BlocksState;
#[cfg(target_arch = "x86_64")] #[cfg(target_arch = "x86_64")]
use vm_allocator::GsiApic; use vm_allocator::GsiApic;
@ -55,7 +53,7 @@ use vm_memory::{
}; };
use vm_migration::{ use vm_migration::{
protocol::MemoryRange, protocol::MemoryRangeTable, Migratable, MigratableError, Pausable, protocol::MemoryRange, protocol::MemoryRangeTable, Migratable, MigratableError, Pausable,
Snapshot, SnapshotData, Snapshottable, Transportable, VersionMapped, Snapshot, SnapshotData, Snapshottable, Transportable,
}; };
pub const MEMORY_MANAGER_ACPI_SIZE: usize = 0x18; pub const MEMORY_MANAGER_ACPI_SIZE: usize = 0x18;
@ -82,7 +80,7 @@ const PLATFORM_DEVICE_AREA_SIZE: u64 = 1 << 20;
const MAX_PREFAULT_THREAD_COUNT: usize = 16; const MAX_PREFAULT_THREAD_COUNT: usize = 16;
#[derive(Clone, Default, Serialize, Deserialize, Versionize)] #[derive(Clone, Default, Serialize, Deserialize)]
struct HotPlugState { struct HotPlugState {
base: u64, base: u64,
length: u64, length: u64,
@ -143,7 +141,7 @@ impl MemoryZone {
pub type MemoryZones = HashMap<String, MemoryZone>; pub type MemoryZones = HashMap<String, MemoryZone>;
#[derive(Clone, Serialize, Deserialize, Versionize)] #[derive(Clone, Serialize, Deserialize)]
struct GuestRamMapping { struct GuestRamMapping {
slot: u32, slot: u32,
gpa: u64, gpa: u64,
@ -153,7 +151,7 @@ struct GuestRamMapping {
file_offset: u64, file_offset: u64,
} }
#[derive(Clone, Serialize, Deserialize, Versionize)] #[derive(Clone, Serialize, Deserialize)]
struct ArchMemRegion { struct ArchMemRegion {
base: u64, base: u64,
size: usize, size: usize,
@ -1269,7 +1267,7 @@ impl MemoryManager {
memory_file_path.push(String::from(SNAPSHOT_FILENAME)); memory_file_path.push(String::from(SNAPSHOT_FILENAME));
let mem_snapshot: MemoryManagerSnapshotData = let mem_snapshot: MemoryManagerSnapshotData =
snapshot.to_versioned_state().map_err(Error::Restore)?; snapshot.to_state().map_err(Error::Restore)?;
let mm = MemoryManager::new( let mm = MemoryManager::new(
vm, vm,
@ -2628,7 +2626,7 @@ impl Aml for MemoryManager {
impl Pausable for MemoryManager {} impl Pausable for MemoryManager {}
#[derive(Clone, Serialize, Deserialize, Versionize)] #[derive(Clone, Serialize, Deserialize)]
pub struct MemoryManagerSnapshotData { pub struct MemoryManagerSnapshotData {
memory_ranges: MemoryRangeTable, memory_ranges: MemoryRangeTable,
guest_ram_mappings: Vec<GuestRamMapping>, guest_ram_mappings: Vec<GuestRamMapping>,
@ -2642,8 +2640,6 @@ pub struct MemoryManagerSnapshotData {
next_hotplug_slot: usize, next_hotplug_slot: usize,
} }
impl VersionMapped for MemoryManagerSnapshotData {}
impl Snapshottable for MemoryManager { impl Snapshottable for MemoryManager {
fn id(&self) -> String { fn id(&self) -> String {
MEMORY_MANAGER_SNAPSHOT_ID.to_string() MEMORY_MANAGER_SNAPSHOT_ID.to_string()
@ -2662,7 +2658,7 @@ impl Snapshottable for MemoryManager {
// memory range content for the ranges requiring it. // memory range content for the ranges requiring it.
self.snapshot_memory_ranges = memory_ranges; self.snapshot_memory_ranges = memory_ranges;
Ok(Snapshot::from_data(SnapshotData::new_from_versioned_state( Ok(Snapshot::from_data(SnapshotData::new_from_state(
&self.snapshot_data(), &self.snapshot_data(),
)?)) )?))
} }

View File

@ -94,7 +94,7 @@ use vm_memory::{
use vm_migration::protocol::{Request, Response, Status}; use vm_migration::protocol::{Request, Response, Status};
use vm_migration::{ use vm_migration::{
protocol::MemoryRangeTable, snapshot_from_id, Migratable, MigratableError, Pausable, Snapshot, protocol::MemoryRangeTable, snapshot_from_id, Migratable, MigratableError, Pausable, Snapshot,
SnapshotData, Snapshottable, Transportable, Snapshottable, Transportable,
}; };
use vmm_sys_util::eventfd::EventFd; use vmm_sys_util::eventfd::EventFd;
use vmm_sys_util::sock_ctrl_msg::ScmSocket; use vmm_sys_util::sock_ctrl_msg::ScmSocket;
@ -2579,15 +2579,14 @@ impl Snapshottable for Vm {
})? })?
}; };
let vm_snapshot_data = serde_json::to_vec(&VmSnapshot { let vm_snapshot_state = VmSnapshot {
#[cfg(all(feature = "kvm", target_arch = "x86_64"))] #[cfg(all(feature = "kvm", target_arch = "x86_64"))]
clock: self.saved_clock, clock: self.saved_clock,
#[cfg(all(feature = "kvm", target_arch = "x86_64"))] #[cfg(all(feature = "kvm", target_arch = "x86_64"))]
common_cpuid, common_cpuid,
}) };
.map_err(|e| MigratableError::Snapshot(e.into()))?;
let mut vm_snapshot = Snapshot::from_data(SnapshotData(vm_snapshot_data)); let mut vm_snapshot = Snapshot::new_from_state(&vm_snapshot_state)?;
let (id, snapshot) = { let (id, snapshot) = {
let mut cpu_manager = self.cpu_manager.lock().unwrap(); let mut cpu_manager = self.cpu_manager.lock().unwrap();