diff --git a/Cargo.lock b/Cargo.lock index 20dafc2a8..8dfca0cee 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -115,8 +115,6 @@ dependencies = [ "serde", "thiserror", "uuid", - "versionize", - "versionize_derive", "vm-fdt", "vm-memory", "vm-migration", @@ -320,15 +318,6 @@ dependencies = [ "rustc-demangle", ] -[[package]] -name = "bincode" -version = "1.3.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b1f45e9417d87227c7a56d22e471c6206462cba514c7590c09aff4cf6d1ddcad" -dependencies = [ - "serde", -] - [[package]] name = "bitfield-struct" version = "0.5.6" @@ -362,11 +351,10 @@ dependencies = [ "libc", "log", "remain", + "serde", "smallvec", "thiserror", "uuid", - "versionize", - "versionize_derive", "virtio-bindings", "virtio-queue", "vm-memory", @@ -524,12 +512,6 @@ dependencies = [ "cfg-if", ] -[[package]] -name = "crc64" -version = "2.0.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2707e3afba5e19b75d582d88bc79237418f2a2a2d673d01cf9b03633b46e98f3" - [[package]] name = "crossbeam-utils" version = "0.8.19" @@ -612,10 +594,9 @@ dependencies = [ "libc", "log", "pci", + "serde", "thiserror", "tpm", - "versionize", - "versionize_derive", "vm-allocator", "vm-device", "vm-memory", @@ -1396,8 +1377,6 @@ dependencies = [ "serde", "serde_json", "thiserror", - "versionize", - "versionize_derive", "virtio-bindings", "virtio-queue", "vm-memory", @@ -1600,8 +1579,6 @@ dependencies = [ "log", "serde", "thiserror", - "versionize", - "versionize_derive", "vfio-bindings", "vfio-ioctls", "vfio_user", @@ -2356,33 +2333,6 @@ version = "0.9.4" source = "registry+https://github.com/rust-lang/crates.io-index" 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]] name = "vfio-bindings" version = "0.4.0" @@ -2515,10 +2465,9 @@ dependencies = [ "seccompiler", "serde", "serde_json", + "serde_with", "serial_buffer", "thiserror", - "versionize", - "versionize_derive", "vhost", "virtio-bindings", "virtio-queue", @@ -2589,8 +2538,6 @@ dependencies = [ "serde", "serde_json", "thiserror", - "versionize", - "versionize_derive", "vm-memory", ] @@ -2646,8 +2593,6 @@ dependencies = [ "thiserror", "tracer", "uuid", - "versionize", - "versionize_derive", "vfio-ioctls", "vfio_user", "virtio-devices", diff --git a/Cargo.toml b/Cargo.toml index 5d636c8a1..dca32b136 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -53,7 +53,6 @@ zbus = { version = "3.15.2", optional = true } # List of patched crates [patch.crates-io] 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] dirs = "5.0.1" diff --git a/arch/Cargo.toml b/arch/Cargo.toml index a12fb36c4..550f7d032 100644 --- a/arch/Cargo.toml +++ b/arch/Cargo.toml @@ -19,8 +19,6 @@ log = "0.4.21" serde = { version = "1.0.197", features = ["rc", "derive"] } thiserror = "1.0.58" 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-migration = { path = "../vm-migration" } vmm-sys-util = { version = "0.12.1", features = ["with-serde"] } diff --git a/arch/src/lib.rs b/arch/src/lib.rs index d08b7aa67..04d7c0106 100644 --- a/arch/src/lib.rs +++ b/arch/src/lib.rs @@ -18,9 +18,6 @@ use std::fmt; use std::result; use std::sync::Arc; use thiserror::Error; -use versionize::{VersionMap, Versionize, VersionizeError, VersionizeResult}; -use versionize_derive::Versionize; -use vm_migration::VersionMapped; type GuestMemoryMmap = vm_memory::GuestMemoryMmap; type GuestRegionMmap = vm_memory::GuestRegionMmap; @@ -58,7 +55,7 @@ pub enum Error { pub type Result = result::Result; /// 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 { /// RAM type Ram, @@ -76,8 +73,6 @@ pub enum RegionType { Reserved, } -impl VersionMapped for RegionType {} - /// Module for aarch64 related functionality. #[cfg(target_arch = "aarch64")] pub mod aarch64; diff --git a/block/Cargo.toml b/block/Cargo.toml index 5b53b1689..728dd6b36 100644 --- a/block/Cargo.toml +++ b/block/Cargo.toml @@ -15,11 +15,10 @@ io-uring = { version = "0.6.3", optional = true } libc = "0.2.153" log = "0.4.21" remain = "0.2.13" +serde = { version = "1.0.197", features = ["derive"] } smallvec = "1.13.2" thiserror = "1.0.58" 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-queue = "0.11.0" vm-memory = { version = "0.14.1", features = ["backend-mmap", "backend-atomic", "backend-bitmap"] } diff --git a/block/src/lib.rs b/block/src/lib.rs index a5d22dcce..fcb4d0f77 100644 --- a/block/src/lib.rs +++ b/block/src/lib.rs @@ -37,6 +37,7 @@ use crate::vhdx::{Vhdx, VhdxError}; #[cfg(feature = "io_uring")] use io_uring::{opcode, IoUring, Probe}; use libc::{ioctl, S_IFBLK, S_IFMT}; +use serde::{Deserialize, Serialize}; use smallvec::SmallVec; use std::alloc::{alloc_zeroed, dealloc, Layout}; use std::cmp; @@ -52,8 +53,6 @@ use std::sync::Arc; use std::sync::MutexGuard; use std::time::Instant; use thiserror::Error; -use versionize::{VersionMap, Versionize, VersionizeResult}; -use versionize_derive::Versionize; use virtio_bindings::virtio_blk::*; use virtio_queue::DescriptorChain; 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)] pub struct VirtioBlockConfig { pub capacity: u64, @@ -567,7 +566,7 @@ pub struct VirtioBlockConfig { pub write_zeroes_may_unmap: u8, pub unused1: [u8; 3], } -#[derive(Copy, Clone, Debug, Default, Versionize)] +#[derive(Copy, Clone, Debug, Default, Serialize, Deserialize)] #[repr(C, packed)] pub struct VirtioBlockGeometry { pub cylinders: u16, diff --git a/devices/Cargo.toml b/devices/Cargo.toml index 570af38c1..958a64fed 100644 --- a/devices/Cargo.toml +++ b/devices/Cargo.toml @@ -15,10 +15,9 @@ hypervisor = { path = "../hypervisor" } libc = "0.2.153" log = "0.4.21" pci = { path = "../pci" } +serde = { version = "1.0.197", features = ["derive"] } thiserror = "1.0.58" tpm = { path = "../tpm" } -versionize = "0.2.0" -versionize_derive = "0.1.6" vm-allocator = { path = "../vm-allocator" } vm-device = { path = "../vm-device" } vm-memory = "0.14.1" diff --git a/devices/src/ioapic.rs b/devices/src/ioapic.rs index 687979268..3f9be8c89 100644 --- a/devices/src/ioapic.rs +++ b/devices/src/ioapic.rs @@ -11,19 +11,16 @@ use super::interrupt_controller::{Error, InterruptController}; use byteorder::{ByteOrder, LittleEndian}; +use serde::{Deserialize, Serialize}; use std::result; use std::sync::{Arc, Barrier}; -use versionize::{VersionMap, Versionize, VersionizeResult}; -use versionize_derive::Versionize; use vm_device::interrupt::{ InterruptIndex, InterruptManager, InterruptSourceConfig, InterruptSourceGroup, MsiIrqGroupConfig, MsiIrqSourceConfig, }; use vm_device::BusDevice; use vm_memory::GuestAddress; -use vm_migration::{ - Migratable, MigratableError, Pausable, Snapshot, Snapshottable, Transportable, VersionMapped, -}; +use vm_migration::{Migratable, MigratableError, Pausable, Snapshot, Snapshottable, Transportable}; use vmm_sys_util::eventfd::EventFd; type Result = result::Result; @@ -136,7 +133,7 @@ pub struct Ioapic { interrupt_source_group: Arc, } -#[derive(Versionize)] +#[derive(Serialize, Deserialize)] pub struct IoapicState { id_reg: u32, reg_sel: u32, @@ -144,7 +141,6 @@ pub struct IoapicState { used_entries: [bool; NUM_IOAPIC_PINS], apic_address: u64, } -impl VersionMapped for IoapicState {} impl BusDevice for Ioapic { 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::new_from_versioned_state(&self.state()) + Snapshot::new_from_state(&self.state()) } } diff --git a/devices/src/legacy/gpio_pl061.rs b/devices/src/legacy/gpio_pl061.rs index 02eeebd19..9aa34db1e 100644 --- a/devices/src/legacy/gpio_pl061.rs +++ b/devices/src/legacy/gpio_pl061.rs @@ -8,16 +8,13 @@ //! use crate::{read_le_u32, write_le_u32}; +use serde::{Deserialize, Serialize}; use std::result; use std::sync::{Arc, Barrier}; use std::{fmt, io}; -use versionize::{VersionMap, Versionize, VersionizeResult}; -use versionize_derive::Versionize; use vm_device::interrupt::InterruptSourceGroup; use vm_device::BusDevice; -use vm_migration::{ - Migratable, MigratableError, Pausable, Snapshot, Snapshottable, Transportable, VersionMapped, -}; +use vm_migration::{Migratable, MigratableError, Pausable, Snapshot, Snapshottable, Transportable}; const OFS_DATA: u64 = 0x400; // Data Register const GPIODIR: u64 = 0x400; // Direction Register @@ -89,7 +86,7 @@ pub struct Gpio { interrupt: Arc, } -#[derive(Versionize)] +#[derive(Serialize, Deserialize)] pub struct GpioState { data: u32, old_in_data: u32, @@ -102,8 +99,6 @@ pub struct GpioState { afsel: u32, } -impl VersionMapped for GpioState {} - impl Gpio { /// Constructs an PL061 GPIO device. pub fn new( @@ -328,7 +323,7 @@ impl Snapshottable for Gpio { } fn snapshot(&mut self) -> std::result::Result { - Snapshot::new_from_versioned_state(&self.state()) + Snapshot::new_from_state(&self.state()) } } diff --git a/devices/src/legacy/serial.rs b/devices/src/legacy/serial.rs index d3cc12e19..a46a89578 100644 --- a/devices/src/legacy/serial.rs +++ b/devices/src/legacy/serial.rs @@ -5,16 +5,13 @@ // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE-BSD-3-Clause file. +use serde::{Deserialize, Serialize}; use std::collections::VecDeque; use std::sync::{Arc, Barrier}; use std::{io, result}; -use versionize::{VersionMap, Versionize, VersionizeResult}; -use versionize_derive::Versionize; use vm_device::interrupt::InterruptSourceGroup; use vm_device::BusDevice; -use vm_migration::{ - Migratable, MigratableError, Pausable, Snapshot, Snapshottable, Transportable, VersionMapped, -}; +use vm_migration::{Migratable, MigratableError, Pausable, Snapshot, Snapshottable, Transportable}; use vmm_sys_util::errno::Result; const LOOP_SIZE: usize = 0x40; @@ -74,7 +71,7 @@ pub struct Serial { out: Option>, } -#[derive(Versionize)] +#[derive(Serialize, Deserialize)] pub struct SerialState { interrupt_enable: u8, interrupt_identification: u8, @@ -86,7 +83,6 @@ pub struct SerialState { baud_divisor: u16, in_buffer: Vec, } -impl VersionMapped for SerialState {} impl Serial { pub fn new( @@ -334,7 +330,7 @@ impl Snapshottable for Serial { } fn snapshot(&mut self) -> std::result::Result { - Snapshot::new_from_versioned_state(&self.state()) + Snapshot::new_from_state(&self.state()) } } diff --git a/devices/src/legacy/uart_pl011.rs b/devices/src/legacy/uart_pl011.rs index d355ffd69..889071bc5 100644 --- a/devices/src/legacy/uart_pl011.rs +++ b/devices/src/legacy/uart_pl011.rs @@ -7,18 +7,15 @@ //! use crate::{read_le_u32, write_le_u32}; +use serde::{Deserialize, Serialize}; use std::collections::VecDeque; use std::fmt; use std::sync::{Arc, Barrier}; use std::time::Instant; use std::{io, result}; -use versionize::{VersionMap, Versionize, VersionizeResult}; -use versionize_derive::Versionize; use vm_device::interrupt::InterruptSourceGroup; use vm_device::BusDevice; -use vm_migration::{ - Migratable, MigratableError, Pausable, Snapshot, Snapshottable, Transportable, VersionMapped, -}; +use vm_migration::{Migratable, MigratableError, Pausable, Snapshot, Snapshottable, Transportable}; /* Registers */ const UARTDR: u64 = 0; @@ -94,7 +91,7 @@ pub struct Pl011 { timestamp: std::time::Instant, } -#[derive(Versionize)] +#[derive(Serialize, Deserialize)] pub struct Pl011State { flags: u32, lcr: u32, @@ -113,8 +110,6 @@ pub struct Pl011State { read_trigger: u32, } -impl VersionMapped for Pl011State {} - impl Pl011 { /// Constructs an AMBA PL011 UART device. pub fn new( @@ -454,7 +449,7 @@ impl Snapshottable for Pl011 { } fn snapshot(&mut self) -> std::result::Result { - Snapshot::new_from_versioned_state(&self.state()) + Snapshot::new_from_state(&self.state()) } } diff --git a/devices/src/pvpanic.rs b/devices/src/pvpanic.rs index a3e82f8fb..f57e3c963 100644 --- a/devices/src/pvpanic.rs +++ b/devices/src/pvpanic.rs @@ -9,18 +9,15 @@ use pci::{ PciClassCode, PciConfiguration, PciDevice, PciDeviceError, PciHeaderType, PciSubclass, PCI_CONFIGURATION_ID, }; +use serde::{Deserialize, Serialize}; use std::any::Any; use std::result; use std::sync::{Arc, Barrier, Mutex}; use thiserror::Error; -use versionize::{VersionMap, Versionize, VersionizeResult}; -use versionize_derive::Versionize; use vm_allocator::{AddressAllocator, SystemAllocator}; use vm_device::{BusDevice, Resource}; use vm_memory::{Address, GuestAddress}; -use vm_migration::{ - Migratable, MigratableError, Pausable, Snapshot, Snapshottable, Transportable, VersionMapped, -}; +use vm_migration::{Migratable, MigratableError, Pausable, Snapshot, Snapshottable, Transportable}; const PVPANIC_VENDOR_ID: u16 = 0x1b36; const PVPANIC_DEVICE_ID: u16 = 0x0011; @@ -60,23 +57,20 @@ pub struct PvPanicDevice { bar_regions: Vec, } -#[derive(Versionize)] +#[derive(Serialize, Deserialize)] pub struct PvPanicDeviceState { events: u8, } -impl VersionMapped for PvPanicDeviceState {} - impl PvPanicDevice { pub fn new(id: String, snapshot: Option) -> Result { let pci_configuration_state = - vm_migration::versioned_state_from_id(snapshot.as_ref(), PCI_CONFIGURATION_ID) - .map_err(|e| { - PvPanicError::RetrievePciConfigurationState(anyhow!( - "Failed to get PciConfigurationState from Snapshot: {}", - e - )) - })?; + vm_migration::state_from_id(snapshot.as_ref(), PCI_CONFIGURATION_ID).map_err(|e| { + PvPanicError::RetrievePciConfigurationState(anyhow!( + "Failed to get PciConfigurationState from Snapshot: {}", + e + )) + })?; let mut configuration = PciConfiguration::new( PVPANIC_VENDOR_ID, @@ -97,7 +91,7 @@ impl PvPanicDevice { let state: Option = snapshot .as_ref() - .map(|s| s.to_versioned_state()) + .map(|s| s.to_state()) .transpose() .map_err(|e| { PvPanicError::CreatePvPanicDevice(anyhow!( @@ -259,7 +253,7 @@ impl Snapshottable for PvPanicDevice { } fn snapshot(&mut self) -> std::result::Result { - let mut snapshot = Snapshot::new_from_versioned_state(&self.state())?; + let mut snapshot = Snapshot::new_from_state(&self.state())?; // Snapshot PciConfiguration snapshot.add_snapshot(self.configuration.id(), self.configuration.snapshot()?); diff --git a/fuzz/Cargo.toml b/fuzz/Cargo.toml index d70b6288e..22073ee5a 100644 --- a/fuzz/Cargo.toml +++ b/fuzz/Cargo.toml @@ -36,7 +36,6 @@ path = ".." [patch.crates-io] 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 [workspace] diff --git a/net_util/Cargo.toml b/net_util/Cargo.toml index 21b0098dd..e663f4cde 100644 --- a/net_util/Cargo.toml +++ b/net_util/Cargo.toml @@ -13,8 +13,6 @@ net_gen = { path = "../net_gen" } rate_limiter = { path = "../rate_limiter" } serde = "1.0.197" thiserror = "1.0.58" -versionize = "0.2.0" -versionize_derive = "0.1.6" virtio-bindings = "0.2.2" virtio-queue = "0.11.0" vm-memory = { version = "0.14.1", features = ["backend-mmap", "backend-atomic", "backend-bitmap"] } diff --git a/net_util/src/lib.rs b/net_util/src/lib.rs index 69e34658c..117f2b1a6 100644 --- a/net_util/src/lib.rs +++ b/net_util/src/lib.rs @@ -14,13 +14,13 @@ mod open_tap; mod queue_pair; mod tap; +use serde::{Deserialize, Serialize}; use std::io::Error as IoError; use std::os::raw::c_uint; use std::os::unix::io::{FromRawFd, RawFd}; use std::{io, mem, net}; use thiserror::Error; -use versionize::{VersionMap, Versionize, VersionizeResult}; -use versionize_derive::Versionize; + 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_F_GUEST_CSUM, VIRTIO_NET_F_GUEST_ECN, VIRTIO_NET_F_GUEST_TSO4, @@ -45,7 +45,7 @@ pub enum Error { pub type Result = std::result::Result; #[repr(C, packed)] -#[derive(Copy, Clone, Debug, Default, Versionize)] +#[derive(Copy, Clone, Debug, Default, Serialize, Deserialize)] pub struct VirtioNetConfig { pub mac: [u8; 6], pub status: u16, diff --git a/pci/Cargo.toml b/pci/Cargo.toml index c395356fb..ea2b6ead1 100644 --- a/pci/Cargo.toml +++ b/pci/Cargo.toml @@ -22,8 +22,6 @@ libc = "0.2.153" log = "0.4.21" serde = { version = "1.0.197", features = ["derive"] } thiserror = "1.0.58" -versionize = "0.2.0" -versionize_derive = "0.1.6" vm-allocator = { path = "../vm-allocator" } vm-device = { path = "../vm-device" } vm-memory = { version = "0.14.1", features = ["backend-mmap", "backend-atomic", "backend-bitmap"] } diff --git a/pci/src/configuration.rs b/pci/src/configuration.rs index 93c552bdd..89d831bbb 100644 --- a/pci/src/configuration.rs +++ b/pci/src/configuration.rs @@ -7,12 +7,11 @@ use crate::device::BarReprogrammingParams; use crate::{MsixConfig, PciInterruptPin}; use byteorder::{ByteOrder, LittleEndian}; +use serde::{Deserialize, Serialize}; use std::fmt::{self, Display}; use std::sync::{Arc, Mutex}; -use versionize::{VersionMap, Versionize, VersionizeError, VersionizeResult}; -use versionize_derive::Versionize; 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. 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 { None } -#[derive(Debug, Default, Clone, Copy, Versionize)] +#[derive(Debug, Default, Clone, Copy, Serialize, Deserialize)] struct PciBar { addr: u32, size: u32, @@ -406,7 +405,7 @@ struct PciBar { r#type: Option, } -#[derive(Versionize)] +#[derive(Serialize, Deserialize)] pub struct PciConfigurationState { registers: Vec, writable_bits: Vec, @@ -418,8 +417,6 @@ pub struct PciConfigurationState { msix_cap_reg_idx: Option, } -impl VersionMapped for PciConfigurationState {} - /// Contains the configuration space of a PCI node. /// See the [specification](https://en.wikipedia.org/wiki/PCI_configuration_space). /// 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 -#[derive(Copy, Clone, PartialEq, Eq, Versionize, Debug)] +#[derive(Copy, Clone, PartialEq, Eq, Serialize, Deserialize, Debug)] pub enum PciBarRegionType { Memory32BitRegion = 0, IoRegion = 0x01, @@ -1072,7 +1069,7 @@ impl Snapshottable for PciConfiguration { } fn snapshot(&mut self) -> std::result::Result { - Snapshot::new_from_versioned_state(&self.state()) + Snapshot::new_from_state(&self.state()) } } diff --git a/pci/src/msi.rs b/pci/src/msi.rs index 58f3d9acd..c93391d16 100644 --- a/pci/src/msi.rs +++ b/pci/src/msi.rs @@ -4,15 +4,14 @@ // use byteorder::{ByteOrder, LittleEndian}; +use serde::{Deserialize, Serialize}; use std::io; use std::sync::Arc; use thiserror::Error; -use versionize::{VersionMap, Versionize, VersionizeResult}; -use versionize_derive::Versionize; use vm_device::interrupt::{ InterruptIndex, InterruptSourceConfig, InterruptSourceGroup, MsiIrqSourceConfig, }; -use vm_migration::{MigratableError, Pausable, Snapshot, Snapshottable, VersionMapped}; +use vm_migration::{MigratableError, Pausable, Snapshot, Snapshottable}; // MSI control masks const MSI_CTL_ENABLE: u16 = 0x1; @@ -47,7 +46,7 @@ pub enum Error { pub const MSI_CONFIG_ID: &str = "msi_config"; -#[derive(Clone, Copy, Default, Versionize)] +#[derive(Clone, Copy, Default, Serialize, Deserialize)] pub struct MsiCap { // Message Control Register // 0: MSI enable. @@ -172,13 +171,11 @@ impl MsiCap { } } -#[derive(Versionize)] +#[derive(Serialize, Deserialize)] pub struct MsiConfigState { cap: MsiCap, } -impl VersionMapped for MsiConfigState {} - pub struct MsiConfig { pub cap: MsiCap, interrupt_source_group: Arc, @@ -294,6 +291,6 @@ impl Snapshottable for MsiConfig { } fn snapshot(&mut self) -> std::result::Result { - Snapshot::new_from_versioned_state(&self.state()) + Snapshot::new_from_state(&self.state()) } } diff --git a/pci/src/msix.rs b/pci/src/msix.rs index 22c282cf5..4c25b4249 100644 --- a/pci/src/msix.rs +++ b/pci/src/msix.rs @@ -5,16 +5,16 @@ use crate::{PciCapability, PciCapabilityId}; use byteorder::{ByteOrder, LittleEndian}; +use serde::Deserialize; +use serde::Serialize; use std::io; use std::result; use std::sync::Arc; -use versionize::{VersionMap, Versionize, VersionizeResult}; -use versionize_derive::Versionize; use vm_device::interrupt::{ InterruptIndex, InterruptSourceConfig, InterruptSourceGroup, MsiIrqSourceConfig, }; 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 MSIX_TABLE_ENTRIES_MODULO: u64 = 16; @@ -35,7 +35,7 @@ pub enum Error { UpdateInterruptRoute(io::Error), } -#[derive(Debug, Clone, Versionize, Eq, PartialEq)] +#[derive(Debug, Clone, Serialize, Deserialize, Eq, PartialEq)] pub struct MsixTableEntry { pub msg_addr_lo: u32, pub msg_addr_hi: u32, @@ -60,7 +60,7 @@ impl Default for MsixTableEntry { } } -#[derive(Versionize)] +#[derive(Serialize, Deserialize)] pub struct MsixConfigState { table_entries: Vec, pba_entries: Vec, @@ -68,8 +68,6 @@ pub struct MsixConfigState { enabled: bool, } -impl VersionMapped for MsixConfigState {} - pub struct MsixConfig { pub table_entries: Vec, pub pba_entries: Vec, @@ -436,13 +434,13 @@ impl Snapshottable for MsixConfig { } fn snapshot(&mut self) -> std::result::Result { - Snapshot::new_from_versioned_state(&self.state()) + Snapshot::new_from_state(&self.state()) } } #[allow(dead_code)] #[repr(packed)] -#[derive(Clone, Copy, Default, Versionize)] +#[derive(Clone, Copy, Default, Serialize, Deserialize)] pub struct MsixCap { // Message Control Register // 10-0: MSI-X Table size diff --git a/pci/src/vfio.rs b/pci/src/vfio.rs index ba3350c0a..c688e7da3 100644 --- a/pci/src/vfio.rs +++ b/pci/src/vfio.rs @@ -15,6 +15,7 @@ use anyhow::anyhow; use byteorder::{ByteOrder, LittleEndian}; use hypervisor::HypervisorVmError; use libc::{sysconf, _SC_PAGESIZE}; +use serde::{Deserialize, Serialize}; use std::any::Any; use std::collections::{BTreeMap, HashMap}; use std::io; @@ -22,8 +23,6 @@ use std::os::unix::io::AsRawFd; use std::ptr::null_mut; use std::sync::{Arc, Barrier, Mutex}; use thiserror::Error; -use versionize::{VersionMap, Versionize, VersionizeResult}; -use versionize_derive::Versionize; use vfio_bindings::bindings::vfio::*; use vfio_ioctls::{ VfioContainer, VfioDevice, VfioIrq, VfioRegionInfoCap, VfioRegionSparseMmapArea, @@ -38,9 +37,7 @@ use vm_device::interrupt::{ }; use vm_device::{BusDevice, Resource}; use vm_memory::{Address, GuestAddress, GuestAddressSpace, GuestMemory, GuestUsize}; -use vm_migration::{ - Migratable, MigratableError, Pausable, Snapshot, Snapshottable, Transportable, VersionMapped, -}; +use vm_migration::{Migratable, MigratableError, Pausable, Snapshot, Snapshottable, Transportable}; use vmm_sys_util::eventfd::EventFd; pub(crate) const VFIO_COMMON_ID: &str = "vfio_common"; @@ -95,7 +92,7 @@ enum InterruptUpdateAction { DisableMsix, } -#[derive(Versionize)] +#[derive(Serialize, Deserialize)] struct IntxState { enabled: bool, } @@ -105,7 +102,7 @@ pub(crate) struct VfioIntx { enabled: bool, } -#[derive(Versionize)] +#[derive(Serialize, Deserialize)] struct MsiState { cap: MsiCap, cap_offset: u32, @@ -137,7 +134,7 @@ impl VfioMsi { } } -#[derive(Versionize)] +#[derive(Serialize, Deserialize)] struct MsixState { cap: MsixCap, cap_offset: u32, @@ -440,15 +437,13 @@ impl Vfio for VfioDeviceWrapper { } } -#[derive(Versionize)] +#[derive(Serialize, Deserialize)] struct VfioCommonState { intx_state: Option, msi_state: Option, msix_state: Option, } -impl VersionMapped for VfioCommonState {} - pub(crate) struct ConfigPatch { mask: u32, patch: u32, @@ -476,13 +471,12 @@ impl VfioCommon { x_nv_gpudirect_clique: Option, ) -> Result { let pci_configuration_state = - vm_migration::versioned_state_from_id(snapshot.as_ref(), PCI_CONFIGURATION_ID) - .map_err(|e| { - VfioPciError::RetrievePciConfigurationState(anyhow!( - "Failed to get PciConfigurationState from Snapshot: {}", - e - )) - })?; + vm_migration::state_from_id(snapshot.as_ref(), PCI_CONFIGURATION_ID).map_err(|e| { + VfioPciError::RetrievePciConfigurationState(anyhow!( + "Failed to get PciConfigurationState from Snapshot: {}", + e + )) + })?; let configuration = PciConfiguration::new( 0, @@ -515,7 +509,7 @@ impl VfioCommon { let state: Option = snapshot .as_ref() - .map(|s| s.to_versioned_state()) + .map(|s| s.to_state()) .transpose() .map_err(|e| { VfioPciError::RetrieveVfioCommonState(anyhow!( @@ -523,20 +517,20 @@ impl VfioCommon { e )) })?; - let msi_state = vm_migration::versioned_state_from_id(snapshot.as_ref(), MSI_CONFIG_ID) - .map_err(|e| { + let msi_state = + vm_migration::state_from_id(snapshot.as_ref(), MSI_CONFIG_ID).map_err(|e| { VfioPciError::RetrieveMsiConfigState(anyhow!( "Failed to get MsiConfigState from Snapshot: {}", e )) })?; - let msix_state = vm_migration::versioned_state_from_id(snapshot.as_ref(), MSIX_CONFIG_ID) - .map_err(|e| { - VfioPciError::RetrieveMsixConfigState(anyhow!( - "Failed to get MsixConfigState from Snapshot: {}", - e - )) - })?; + let msix_state = + vm_migration::state_from_id(snapshot.as_ref(), MSIX_CONFIG_ID).map_err(|e| { + VfioPciError::RetrieveMsixConfigState(anyhow!( + "Failed to get MsixConfigState from Snapshot: {}", + e + )) + })?; if let Some(state) = state.as_ref() { vfio_common.set_state(state, msi_state, msix_state)?; @@ -1388,7 +1382,7 @@ impl Snapshottable for VfioCommon { } fn snapshot(&mut self) -> std::result::Result { - 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 vfio_common_snapshot.add_snapshot(self.configuration.id(), self.configuration.snapshot()?); diff --git a/virtio-devices/Cargo.toml b/virtio-devices/Cargo.toml index 2c137fb2b..48e758282 100644 --- a/virtio-devices/Cargo.toml +++ b/virtio-devices/Cargo.toml @@ -23,10 +23,9 @@ rate_limiter = { path = "../rate_limiter" } seccompiler = "0.4.0" serde = { version = "1.0.197", features = ["derive"] } serde_json = "1.0.115" +serde_with = { version = "3.7.0", default-features = false, features = ["macros"] } serial_buffer = { path = "../serial_buffer" } 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"] } virtio-bindings = { version = "0.2.2", features = ["virtio-v5_0_0"] } virtio-queue = "0.11.0" diff --git a/virtio-devices/src/balloon.rs b/virtio-devices/src/balloon.rs index c25e0067f..7f6653906 100644 --- a/virtio-devices/src/balloon.rs +++ b/virtio-devices/src/balloon.rs @@ -22,23 +22,20 @@ use crate::{ }; use anyhow::anyhow; use seccompiler::SeccompAction; +use serde::{Deserialize, Serialize}; use std::io::{self, Write}; use std::mem::size_of; use std::os::unix::io::AsRawFd; use std::result; use std::sync::{atomic::AtomicBool, Arc, Barrier}; use thiserror::Error; -use versionize::{VersionMap, Versionize, VersionizeResult}; -use versionize_derive::Versionize; use virtio_queue::{Queue, QueueT}; use vm_allocator::page_size::{align_page_size_down, get_page_size}; use vm_memory::{ Address, ByteValued, Bytes, GuestAddress, GuestAddressSpace, GuestMemory, GuestMemoryAtomic, GuestMemoryError, GuestMemoryRegion, }; -use vm_migration::{ - Migratable, MigratableError, Pausable, Snapshot, Snapshottable, Transportable, VersionMapped, -}; +use vm_migration::{Migratable, MigratableError, Pausable, Snapshot, Snapshottable, Transportable}; use vmm_sys_util::eventfd::EventFd; const QUEUE_SIZE: u16 = 128; @@ -89,7 +86,7 @@ pub enum Error { // Got from include/uapi/linux/virtio_balloon.h #[repr(C)] -#[derive(Copy, Clone, Debug, Default, Versionize)] +#[derive(Copy, Clone, Debug, Default, Serialize, Deserialize)] pub struct VirtioBalloonConfig { // Number of pages host wants Guest to give up. num_pages: u32, @@ -418,15 +415,13 @@ impl EpollHelperHandler for BalloonEpollHandler { } } -#[derive(Versionize)] +#[derive(Serialize, Deserialize)] pub struct BalloonState { pub avail_features: u64, pub acked_features: u64, pub config: VirtioBalloonConfig, } -impl VersionMapped for BalloonState {} - // Virtio device for exposing entropy to the guest OS through virtio. pub struct Balloon { common: VirtioCommon, @@ -672,7 +667,7 @@ impl Snapshottable for Balloon { } fn snapshot(&mut self) -> std::result::Result { - Snapshot::new_from_versioned_state(&self.state()) + Snapshot::new_from_state(&self.state()) } } impl Transportable for Balloon {} diff --git a/virtio-devices/src/block.rs b/virtio-devices/src/block.rs index b7c77e31b..d7616bf8f 100644 --- a/virtio-devices/src/block.rs +++ b/virtio-devices/src/block.rs @@ -25,6 +25,7 @@ use block::{ use rate_limiter::group::{RateLimiterGroup, RateLimiterGroupHandle}; use rate_limiter::TokenType; use seccompiler::SeccompAction; +use serde::{Deserialize, Serialize}; use std::collections::BTreeMap; use std::collections::HashMap; use std::collections::VecDeque; @@ -37,13 +38,10 @@ use std::result; use std::sync::atomic::{AtomicBool, AtomicU64, Ordering}; use std::sync::{Arc, Barrier}; use thiserror::Error; -use versionize::{VersionMap, Versionize, VersionizeResult}; -use versionize_derive::Versionize; use virtio_bindings::virtio_blk::*; use virtio_bindings::virtio_config::*; use virtio_queue::{Queue, QueueOwnedT, QueueT}; use vm_memory::{ByteValued, Bytes, GuestAddressSpace, GuestMemoryAtomic, GuestMemoryError}; -use vm_migration::VersionMapped; use vm_migration::{Migratable, MigratableError, Pausable, Snapshot, Snapshottable, Transportable}; use vm_virtio::AccessPlatform; use vmm_sys_util::eventfd::EventFd; @@ -552,7 +550,7 @@ pub struct Block { queue_affinity: BTreeMap>, } -#[derive(Versionize)] +#[derive(Serialize, Deserialize)] pub struct BlockState { pub disk_path: String, pub disk_nsectors: u64, @@ -561,8 +559,6 @@ pub struct BlockState { pub config: VirtioBlockConfig, } -impl VersionMapped for BlockState {} - impl Block { /// Create a new virtio block device that operates on the given file. #[allow(clippy::too_many_arguments)] @@ -916,7 +912,7 @@ impl Snapshottable for Block { } fn snapshot(&mut self) -> std::result::Result { - Snapshot::new_from_versioned_state(&self.state()) + Snapshot::new_from_state(&self.state()) } } impl Transportable for Block {} diff --git a/virtio-devices/src/console.rs b/virtio-devices/src/console.rs index 7a097b564..fcca7b6c0 100644 --- a/virtio-devices/src/console.rs +++ b/virtio-devices/src/console.rs @@ -14,6 +14,7 @@ use crate::VirtioInterrupt; use anyhow::anyhow; use libc::{EFD_NONBLOCK, TIOCGWINSZ}; use seccompiler::SeccompAction; +use serde::{Deserialize, Serialize}; use serial_buffer::SerialBuffer; use std::cmp; use std::collections::VecDeque; @@ -25,11 +26,8 @@ use std::result; use std::sync::atomic::{AtomicBool, AtomicU64, Ordering}; use std::sync::{Arc, Barrier, Mutex}; use thiserror::Error; -use versionize::{VersionMap, Versionize, VersionizeResult}; -use versionize_derive::Versionize; use virtio_queue::{Queue, QueueT}; use vm_memory::{ByteValued, Bytes, GuestAddressSpace, GuestMemory, GuestMemoryAtomic}; -use vm_migration::VersionMapped; use vm_migration::{Migratable, MigratableError, Pausable, Snapshot, Snapshottable, Transportable}; use vm_virtio::{AccessPlatform, Translatable}; use vmm_sys_util::eventfd::EventFd; @@ -67,7 +65,7 @@ enum Error { QueueAddUsed(virtio_queue::Error), } -#[derive(Copy, Clone, Debug, Versionize)] +#[derive(Copy, Clone, Debug, Serialize, Deserialize)] #[repr(C, packed)] pub struct VirtioConsoleConfig { cols: u16, @@ -593,7 +591,7 @@ pub struct Console { exit_evt: EventFd, } -#[derive(Versionize)] +#[derive(Serialize, Deserialize)] pub struct ConsoleState { avail_features: u64, acked_features: u64, @@ -620,8 +618,6 @@ fn get_win_size(tty: &dyn AsRawFd) -> (u16, u16) { (ws.cols, ws.rows) } -impl VersionMapped for ConsoleState {} - impl Console { /// Create a new virtio console device pub fn new( @@ -825,7 +821,7 @@ impl Snapshottable for Console { } fn snapshot(&mut self) -> std::result::Result { - Snapshot::new_from_versioned_state(&self.state()) + Snapshot::new_from_state(&self.state()) } } impl Transportable for Console {} diff --git a/virtio-devices/src/iommu.rs b/virtio-devices/src/iommu.rs index e52ff5423..fce796d4b 100644 --- a/virtio-devices/src/iommu.rs +++ b/virtio-devices/src/iommu.rs @@ -13,6 +13,7 @@ use crate::GuestMemoryMmap; use crate::{DmaRemapping, VirtioInterrupt, VirtioInterruptType}; use anyhow::anyhow; use seccompiler::SeccompAction; +use serde::{Deserialize, Serialize}; use std::collections::BTreeMap; use std::io; use std::mem::size_of; @@ -22,15 +23,12 @@ use std::result; use std::sync::atomic::{AtomicBool, Ordering}; use std::sync::{Arc, Barrier, Mutex, RwLock}; use thiserror::Error; -use versionize::{VersionMap, Versionize, VersionizeResult}; -use versionize_derive::Versionize; use virtio_queue::{DescriptorChain, Queue, QueueT}; use vm_device::dma_mapping::ExternalDmaMapping; use vm_memory::{ Address, ByteValued, Bytes, GuestAddress, GuestAddressSpace, GuestMemoryAtomic, GuestMemoryError, GuestMemoryLoadGuard, }; -use vm_migration::VersionMapped; use vm_migration::{Migratable, MigratableError, Pausable, Snapshot, Snapshottable, Transportable}; use vm_virtio::AccessPlatform; 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 { gpa: u64, size: u64, @@ -905,7 +903,7 @@ pub struct Iommu { type EndpointsState = Vec<(u32, u32)>; type DomainsState = Vec<(u32, (Vec<(u64, Mapping)>, bool))>; -#[derive(Versionize)] +#[derive(Serialize, Deserialize)] pub struct IommuState { avail_features: u64, acked_features: u64, @@ -913,8 +911,6 @@ pub struct IommuState { domains: DomainsState, } -impl VersionMapped for IommuState {} - impl Iommu { pub fn new( id: String, @@ -1154,7 +1150,7 @@ impl Snapshottable for Iommu { } fn snapshot(&mut self) -> std::result::Result { - Snapshot::new_from_versioned_state(&self.state()) + Snapshot::new_from_state(&self.state()) } } impl Transportable for Iommu {} diff --git a/virtio-devices/src/mem.rs b/virtio-devices/src/mem.rs index 5058ce732..434401377 100644 --- a/virtio-devices/src/mem.rs +++ b/virtio-devices/src/mem.rs @@ -25,6 +25,7 @@ use crate::{GuestMemoryMmap, GuestRegionMmap}; use crate::{VirtioInterrupt, VirtioInterruptType}; use anyhow::anyhow; use seccompiler::SeccompAction; +use serde::{Deserialize, Serialize}; use std::collections::BTreeMap; use std::io; use std::mem::size_of; @@ -34,8 +35,6 @@ use std::sync::atomic::AtomicBool; use std::sync::mpsc; use std::sync::{Arc, Barrier, Mutex}; use thiserror::Error; -use versionize::{VersionMap, Versionize, VersionizeResult}; -use versionize_derive::Versionize; use virtio_queue::{DescriptorChain, Queue, QueueT}; use vm_device::dma_mapping::ExternalDmaMapping; use vm_memory::{ @@ -43,9 +42,7 @@ use vm_memory::{ GuestMemoryError, GuestMemoryLoadGuard, GuestMemoryRegion, }; use vm_migration::protocol::MemoryRangeTable; -use vm_migration::{ - Migratable, MigratableError, Pausable, Snapshot, Snapshottable, Transportable, VersionMapped, -}; +use vm_migration::{Migratable, MigratableError, Pausable, Snapshot, Snapshottable, Transportable}; use vmm_sys_util::eventfd::EventFd; const QUEUE_SIZE: u16 = 128; @@ -170,7 +167,7 @@ struct VirtioMemResp { unsafe impl ByteValued for VirtioMemResp {} #[repr(C)] -#[derive(Copy, Clone, Debug, Default, Versionize)] +#[derive(Copy, Clone, Debug, Default, Serialize, Deserialize)] pub struct VirtioMemConfig { // Block size and alignment. Cannot change. block_size: u64, @@ -338,7 +335,7 @@ impl Request { } } -#[derive(Clone, Versionize)] +#[derive(Clone, Serialize, Deserialize)] pub struct BlocksState { bitmap: Vec, } @@ -688,7 +685,7 @@ pub enum VirtioMemMappingSource { Device(u32), } -#[derive(Versionize)] +#[derive(Serialize, Deserialize)] pub struct MemState { pub avail_features: u64, pub acked_features: u64, @@ -696,8 +693,6 @@ pub struct MemState { pub blocks_state: BlocksState, } -impl VersionMapped for MemState {} - pub struct Mem { common: VirtioCommon, id: String, @@ -1013,7 +1008,7 @@ impl Snapshottable for Mem { } fn snapshot(&mut self) -> std::result::Result { - Snapshot::new_from_versioned_state(&self.state()) + Snapshot::new_from_state(&self.state()) } } impl Transportable for Mem {} diff --git a/virtio-devices/src/net.rs b/virtio-devices/src/net.rs index 12805bcd1..ce46b9388 100644 --- a/virtio-devices/src/net.rs +++ b/virtio-devices/src/net.rs @@ -24,6 +24,7 @@ use net_util::{ NetQueuePair, OpenTapError, RxVirtio, Tap, TapError, TxVirtio, VirtioNetConfig, }; use seccompiler::SeccompAction; +use serde::{Deserialize, Serialize}; use std::collections::HashMap; use std::net::Ipv4Addr; use std::num::Wrapping; @@ -34,14 +35,11 @@ use std::sync::atomic::{AtomicBool, Ordering}; use std::sync::{Arc, Barrier}; use std::thread; use thiserror::Error; -use versionize::{VersionMap, Versionize, VersionizeResult}; -use versionize_derive::Versionize; use virtio_bindings::virtio_config::*; use virtio_bindings::virtio_net::*; use virtio_bindings::virtio_ring::VIRTIO_RING_F_EVENT_IDX; use virtio_queue::{Queue, QueueT}; use vm_memory::{ByteValued, GuestAddressSpace, GuestMemoryAtomic}; -use vm_migration::VersionMapped; use vm_migration::{Migratable, MigratableError, Pausable, Snapshot, Snapshottable, Transportable}; use vm_virtio::AccessPlatform; use vmm_sys_util::eventfd::EventFd; @@ -423,7 +421,7 @@ pub struct Net { exit_evt: EventFd, } -#[derive(Versionize)] +#[derive(Serialize, Deserialize)] pub struct NetState { pub avail_features: u64, pub acked_features: u64, @@ -431,8 +429,6 @@ pub struct NetState { pub queue_size: Vec, } -impl VersionMapped for NetState {} - impl Net { /// Create a new virtio network device with the given TAP interface. #[allow(clippy::too_many_arguments)] @@ -886,7 +882,7 @@ impl Snapshottable for Net { } fn snapshot(&mut self) -> std::result::Result { - Snapshot::new_from_versioned_state(&self.state()) + Snapshot::new_from_state(&self.state()) } } impl Transportable for Net {} diff --git a/virtio-devices/src/pmem.rs b/virtio-devices/src/pmem.rs index c5f550a87..57ef9c63d 100644 --- a/virtio-devices/src/pmem.rs +++ b/virtio-devices/src/pmem.rs @@ -18,6 +18,7 @@ use crate::{GuestMemoryMmap, MmapRegion}; use crate::{VirtioInterrupt, VirtioInterruptType}; use anyhow::anyhow; use seccompiler::SeccompAction; +use serde::{Deserialize, Serialize}; use std::fs::File; use std::io; use std::mem::size_of; @@ -26,14 +27,11 @@ use std::result; use std::sync::atomic::AtomicBool; use std::sync::{Arc, Barrier}; use thiserror::Error; -use versionize::{VersionMap, Versionize, VersionizeResult}; -use versionize_derive::Versionize; use virtio_queue::{DescriptorChain, Queue, QueueT}; use vm_memory::{ Address, ByteValued, Bytes, GuestAddress, GuestAddressSpace, GuestMemoryAtomic, GuestMemoryError, GuestMemoryLoadGuard, }; -use vm_migration::VersionMapped; use vm_migration::{Migratable, MigratableError, Pausable, Snapshot, Snapshottable, Transportable}; use vm_virtio::{AccessPlatform, Translatable}; 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. 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)] struct VirtioPmemConfig { start: u64, @@ -279,15 +277,13 @@ pub struct Pmem { _region: MmapRegion, } -#[derive(Versionize)] +#[derive(Serialize, Deserialize)] pub struct PmemState { avail_features: u64, acked_features: u64, config: VirtioPmemConfig, } -impl VersionMapped for PmemState {} - impl Pmem { #[allow(clippy::too_many_arguments)] pub fn new( @@ -468,7 +464,7 @@ impl Snapshottable for Pmem { } fn snapshot(&mut self) -> std::result::Result { - Snapshot::new_from_versioned_state(&self.state()) + Snapshot::new_from_state(&self.state()) } } diff --git a/virtio-devices/src/rng.rs b/virtio-devices/src/rng.rs index af1098270..7c70d1f10 100644 --- a/virtio-devices/src/rng.rs +++ b/virtio-devices/src/rng.rs @@ -16,6 +16,7 @@ use crate::GuestMemoryMmap; use crate::{VirtioInterrupt, VirtioInterruptType}; use anyhow::anyhow; use seccompiler::SeccompAction; +use serde::{Deserialize, Serialize}; use std::fs::File; use std::io; use std::os::unix::io::AsRawFd; @@ -23,11 +24,8 @@ use std::result; use std::sync::atomic::AtomicBool; use std::sync::{Arc, Barrier}; use thiserror::Error; -use versionize::{VersionMap, Versionize, VersionizeResult}; -use versionize_derive::Versionize; use virtio_queue::{Queue, QueueT}; use vm_memory::{GuestAddressSpace, GuestMemory, GuestMemoryAtomic}; -use vm_migration::VersionMapped; use vm_migration::{Migratable, MigratableError, Pausable, Snapshot, Snapshottable, Transportable}; use vm_virtio::{AccessPlatform, Translatable}; use vmm_sys_util::eventfd::EventFd; @@ -160,14 +158,12 @@ pub struct Rng { exit_evt: EventFd, } -#[derive(Versionize)] +#[derive(Deserialize, Serialize)] pub struct RngState { pub avail_features: u64, pub acked_features: u64, } -impl VersionMapped for RngState {} - impl Rng { /// Create a new virtio rng device that gets random data from /dev/urandom. pub fn new( @@ -326,7 +322,7 @@ impl Snapshottable for Rng { } fn snapshot(&mut self) -> std::result::Result { - Snapshot::new_from_versioned_state(&self.state()) + Snapshot::new_from_state(&self.state()) } } diff --git a/virtio-devices/src/transport/pci_common_config.rs b/virtio-devices/src/transport/pci_common_config.rs index 7c82dda2f..e732ebd17 100644 --- a/virtio-devices/src/transport/pci_common_config.rs +++ b/virtio-devices/src/transport/pci_common_config.rs @@ -8,17 +8,16 @@ use crate::VirtioDevice; use byteorder::{ByteOrder, LittleEndian}; +use serde::{Deserialize, Serialize}; use std::sync::atomic::{AtomicU16, Ordering}; use std::sync::{Arc, Mutex}; -use versionize::{VersionMap, Versionize, VersionizeResult}; -use versionize_derive::Versionize; use virtio_queue::{Queue, QueueT}; -use vm_migration::{MigratableError, Pausable, Snapshot, Snapshottable, VersionMapped}; +use vm_migration::{MigratableError, Pausable, Snapshot, Snapshottable}; use vm_virtio::AccessPlatform; pub const VIRTIO_PCI_COMMON_CONFIG_ID: &str = "virtio_pci_common_config"; -#[derive(Clone, Versionize)] +#[derive(Clone, Serialize, Deserialize)] pub struct VirtioPciCommonConfigState { pub driver_status: u8, pub config_generation: u8, @@ -29,8 +28,6 @@ pub struct VirtioPciCommonConfigState { pub msix_queues: Vec, } -impl VersionMapped for VirtioPciCommonConfigState {} - /// Contains the data for reading and writing the common configuration structure of a virtio PCI /// device. /// @@ -321,7 +318,7 @@ impl Snapshottable for VirtioPciCommonConfig { } fn snapshot(&mut self) -> std::result::Result { - Snapshot::new_from_versioned_state(&self.state()) + Snapshot::new_from_state(&self.state()) } } diff --git a/virtio-devices/src/transport/pci_device.rs b/virtio-devices/src/transport/pci_device.rs index 58e79ae33..5e5ce3a2d 100644 --- a/virtio-devices/src/transport/pci_device.rs +++ b/virtio-devices/src/transport/pci_device.rs @@ -20,6 +20,7 @@ use pci::{ PciCapability, PciCapabilityId, PciClassCode, PciConfiguration, PciDevice, PciDeviceError, PciHeaderType, PciMassStorageSubclass, PciNetworkControllerSubclass, PciSubclass, }; +use serde::{Deserialize, Serialize}; use std::any::Any; use std::cmp; use std::io::Write; @@ -27,8 +28,6 @@ use std::ops::Deref; use std::sync::atomic::{AtomicBool, AtomicU16, AtomicUsize, Ordering}; use std::sync::{Arc, Barrier, Mutex}; use thiserror::Error; -use versionize::{VersionMap, Versionize, VersionizeResult}; -use versionize_derive::Versionize; use virtio_queue::{Queue, QueueT}; use vm_allocator::{AddressAllocator, SystemAllocator}; use vm_device::dma_mapping::ExternalDmaMapping; @@ -37,9 +36,7 @@ use vm_device::interrupt::{ }; use vm_device::{BusDevice, PciBarType, Resource}; use vm_memory::{Address, ByteValued, GuestAddress, GuestAddressSpace, GuestMemoryAtomic, Le32}; -use vm_migration::{ - Migratable, MigratableError, Pausable, Snapshot, Snapshottable, Transportable, VersionMapped, -}; +use vm_migration::{Migratable, MigratableError, Pausable, Snapshot, Snapshottable, Transportable}; use vm_virtio::AccessPlatform; 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_DEVICE_ID_BASE: u16 = 0x1040; // Add to device type to get device ID. -#[derive(Versionize)] +#[derive(Serialize, Deserialize)] struct QueueState { max_size: u16, size: u16, @@ -273,7 +270,7 @@ struct QueueState { used_ring: u64, } -#[derive(Versionize)] +#[derive(Serialize, Deserialize)] pub struct VirtioPciDeviceState { device_activated: bool, queues: Vec, @@ -282,8 +279,6 @@ pub struct VirtioPciDeviceState { cap_pci_cfg: Vec, } -impl VersionMapped for VirtioPciDeviceState {} - pub struct VirtioPciDeviceActivator { interrupt: Option>, memory: Option>, @@ -431,15 +426,13 @@ impl VirtioPciDevice { )) })?; - let msix_state = - vm_migration::versioned_state_from_id(snapshot.as_ref(), pci::MSIX_CONFIG_ID).map_err( - |e| { - VirtioPciDeviceError::CreateVirtioPciDevice(anyhow!( - "Failed to get MsixConfigState from Snapshot: {}", - e - )) - }, - )?; + let msix_state = vm_migration::state_from_id(snapshot.as_ref(), pci::MSIX_CONFIG_ID) + .map_err(|e| { + VirtioPciDeviceError::CreateVirtioPciDevice(anyhow!( + "Failed to get MsixConfigState from Snapshot: {}", + e + )) + })?; let (msix_config, msix_config_clone) = if msix_num > 0 { let msix_config = Arc::new(Mutex::new( @@ -473,13 +466,14 @@ impl VirtioPciDevice { }; let pci_configuration_state = - vm_migration::versioned_state_from_id(snapshot.as_ref(), pci::PCI_CONFIGURATION_ID) - .map_err(|e| { + vm_migration::state_from_id(snapshot.as_ref(), pci::PCI_CONFIGURATION_ID).map_err( + |e| { VirtioPciDeviceError::CreateVirtioPciDevice(anyhow!( "Failed to get PciConfigurationState from Snapshot: {}", e )) - })?; + }, + )?; let configuration = PciConfiguration::new( VIRTIO_PCI_VENDOR_ID, @@ -496,13 +490,14 @@ impl VirtioPciDevice { ); let common_config_state = - vm_migration::versioned_state_from_id(snapshot.as_ref(), VIRTIO_PCI_COMMON_CONFIG_ID) - .map_err(|e| { - VirtioPciDeviceError::CreateVirtioPciDevice(anyhow!( - "Failed to get VirtioPciCommonConfigState from Snapshot: {}", - e - )) - })?; + vm_migration::state_from_id(snapshot.as_ref(), VIRTIO_PCI_COMMON_CONFIG_ID).map_err( + |e| { + VirtioPciDeviceError::CreateVirtioPciDevice(anyhow!( + "Failed to get VirtioPciCommonConfigState from Snapshot: {}", + e + )) + }, + )?; let common_config = if let Some(common_config_state) = common_config_state { VirtioPciCommonConfig::new(common_config_state, access_platform) @@ -523,7 +518,7 @@ impl VirtioPciDevice { let state: Option = snapshot .as_ref() - .map(|s| s.to_versioned_state()) + .map(|s| s.to_state()) .transpose() .map_err(|e| { VirtioPciDeviceError::CreateVirtioPciDevice(anyhow!( @@ -1289,7 +1284,7 @@ impl Snapshottable for VirtioPciDevice { } fn snapshot(&mut self) -> std::result::Result { - 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 virtio_pci_dev_snapshot diff --git a/virtio-devices/src/vdpa.rs b/virtio-devices/src/vdpa.rs index 74ebf1899..003e0d73b 100644 --- a/virtio-devices/src/vdpa.rs +++ b/virtio-devices/src/vdpa.rs @@ -9,6 +9,7 @@ use crate::{ VIRTIO_F_IOMMU_PLATFORM, }; use anyhow::anyhow; +use serde::{Deserialize, Serialize}; use std::{ collections::BTreeMap, io, result, @@ -18,8 +19,6 @@ use std::{ }, }; use thiserror::Error; -use versionize::{VersionMap, Versionize, VersionizeResult}; -use versionize_derive::Versionize; use vhost::{ vdpa::{VhostVdpa, VhostVdpaIovaRange}, vhost_kern::VhostKernFeatures, @@ -29,9 +28,7 @@ use vhost::{ use virtio_queue::{Descriptor, Queue, QueueT}; use vm_device::dma_mapping::ExternalDmaMapping; use vm_memory::{GuestAddress, GuestAddressSpace, GuestMemory, GuestMemoryAtomic}; -use vm_migration::{ - Migratable, MigratableError, Pausable, Snapshot, Snapshottable, Transportable, VersionMapped, -}; +use vm_migration::{Migratable, MigratableError, Pausable, Snapshot, Snapshottable, Transportable}; use vm_virtio::{AccessPlatform, Translatable}; use vmm_sys_util::eventfd::EventFd; @@ -95,7 +92,7 @@ pub enum Error { pub type Result = std::result::Result; -#[derive(Versionize)] +#[derive(Serialize, Deserialize)] pub struct VdpaState { pub avail_features: u64, pub acked_features: u64, @@ -107,8 +104,6 @@ pub struct VdpaState { pub backend_features: u64, } -impl VersionMapped for VdpaState {} - pub struct Vdpa { common: VirtioCommon, 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)) })?)?; diff --git a/virtio-devices/src/vhost_user/blk.rs b/virtio-devices/src/vhost_user/blk.rs index 2729fe29f..9ed0edc0e 100644 --- a/virtio-devices/src/vhost_user/blk.rs +++ b/virtio-devices/src/vhost_user/blk.rs @@ -11,13 +11,13 @@ use crate::{GuestMemoryMmap, GuestRegionMmap}; use crate::{VirtioInterrupt, VIRTIO_F_IOMMU_PLATFORM}; use block::VirtioBlockConfig; use seccompiler::SeccompAction; +use serde::{Deserialize, Serialize}; use std::mem; use std::result; use std::sync::atomic::AtomicBool; use std::sync::{Arc, Barrier, Mutex}; use std::thread; -use versionize::{VersionMap, Versionize, VersionizeResult}; -use versionize_derive::Versionize; + use vhost::vhost_user::message::{ VhostUserConfigFlags, VhostUserProtocolFeatures, VhostUserVirtioFeatures, VHOST_USER_CONFIG_OFFSET, @@ -32,13 +32,13 @@ use virtio_queue::Queue; use vm_memory::{ByteValued, GuestMemoryAtomic}; use vm_migration::{ protocol::MemoryRangeTable, Migratable, MigratableError, Pausable, Snapshot, Snapshottable, - Transportable, VersionMapped, + Transportable, }; use vmm_sys_util::eventfd::EventFd; const DEFAULT_QUEUE_NUMBER: usize = 1; -#[derive(Versionize)] +#[derive(Serialize, Deserialize)] pub struct State { pub avail_features: u64, pub acked_features: u64, @@ -47,8 +47,6 @@ pub struct State { pub vu_num_queues: usize, } -impl VersionMapped for State {} - struct BackendReqHandler {} impl VhostUserFrontendReqHandler for BackendReqHandler {} diff --git a/virtio-devices/src/vhost_user/fs.rs b/virtio-devices/src/vhost_user/fs.rs index 10c39cb69..ae0362a06 100644 --- a/virtio-devices/src/vhost_user/fs.rs +++ b/virtio-devices/src/vhost_user/fs.rs @@ -13,14 +13,14 @@ use crate::{ use crate::{GuestMemoryMmap, GuestRegionMmap, MmapRegion}; use libc::{c_void, off64_t, pread64, pwrite64}; use seccompiler::SeccompAction; +use serde::{Deserialize, Serialize}; +use serde_with::{serde_as, Bytes}; use std::io; use std::os::unix::io::AsRawFd; use std::result; use std::sync::atomic::AtomicBool; use std::sync::{Arc, Barrier, Mutex}; use std::thread; -use versionize::{VersionMap, Versionize, VersionizeResult}; -use versionize_derive::Versionize; use vhost::vhost_user::message::{ VhostUserFSBackendMsg, VhostUserFSBackendMsgFlags, VhostUserProtocolFeatures, VhostUserVirtioFeatures, VHOST_USER_FS_BACKEND_ENTRIES, @@ -34,14 +34,14 @@ use vm_memory::{ }; use vm_migration::{ protocol::MemoryRangeTable, Migratable, MigratableError, Pausable, Snapshot, Snapshottable, - Transportable, VersionMapped, + Transportable, }; use vmm_sys_util::eventfd::EventFd; const NUM_QUEUE_OFFSET: usize = 1; const DEFAULT_QUEUE_NUMBER: usize = 2; -#[derive(Versionize)] +#[derive(Serialize, Deserialize)] pub struct State { pub avail_features: u64, pub acked_features: u64, @@ -51,8 +51,6 @@ pub struct State { pub backend_req_support: bool, } -impl VersionMapped for State {} - struct BackendReqHandler { cache_offset: GuestAddress, cache_size: u64, @@ -272,9 +270,11 @@ impl VhostUserFrontendReqHandler for BackendReqHandler { } pub const VIRTIO_FS_TAG_LEN: usize = 36; -#[derive(Copy, Clone, Versionize)] +#[serde_as] +#[derive(Copy, Clone, Serialize, Deserialize)] #[repr(C, packed)] pub struct VirtioFsConfig { + #[serde_as(as = "Bytes")] pub tag: [u8; VIRTIO_FS_TAG_LEN], pub num_request_queues: u32, } diff --git a/virtio-devices/src/vhost_user/mod.rs b/virtio-devices/src/vhost_user/mod.rs index a4f56c31f..85d30fee3 100644 --- a/virtio-devices/src/vhost_user/mod.rs +++ b/virtio-devices/src/vhost_user/mod.rs @@ -8,12 +8,12 @@ use crate::{ VIRTIO_F_RING_INDIRECT_DESC, VIRTIO_F_VERSION_1, }; use anyhow::anyhow; +use serde::{Deserialize, Serialize}; use std::io; use std::ops::Deref; use std::os::unix::io::AsRawFd; use std::sync::{atomic::AtomicBool, Arc, Barrier, Mutex}; use thiserror::Error; -use versionize::Versionize; use vhost::vhost_user::message::{ VhostUserInflight, VhostUserProtocolFeatures, VhostUserVirtioFeatures, }; @@ -25,7 +25,7 @@ use vm_memory::{ mmap::MmapRegionError, Address, Error as MmapError, GuestAddressSpace, GuestMemory, GuestMemoryAtomic, }; -use vm_migration::{protocol::MemoryRangeTable, MigratableError, Snapshot, VersionMapped}; +use vm_migration::{protocol::MemoryRangeTable, MigratableError, Snapshot}; use vmm_sys_util::eventfd::EventFd; use vu_common_ctrl::VhostUserHandle; @@ -430,11 +430,11 @@ impl VhostUserCommon { } } - pub fn snapshot(&mut self, state: &T) -> std::result::Result + pub fn snapshot<'a, T>(&mut self, state: &T) -> std::result::Result 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 { self.shutdown(); diff --git a/virtio-devices/src/vhost_user/net.rs b/virtio-devices/src/vhost_user/net.rs index abe427c06..16cccb6a6 100644 --- a/virtio-devices/src/vhost_user/net.rs +++ b/virtio-devices/src/vhost_user/net.rs @@ -12,12 +12,11 @@ use crate::{ use crate::{GuestMemoryMmap, GuestRegionMmap}; use net_util::{build_net_config_space, CtrlQueue, MacAddr, VirtioNetConfig}; use seccompiler::SeccompAction; +use serde::{Deserialize, Serialize}; use std::result; use std::sync::atomic::AtomicBool; use std::sync::{Arc, Barrier, Mutex}; use std::thread; -use versionize::{VersionMap, Versionize, VersionizeResult}; -use versionize_derive::Versionize; use vhost::vhost_user::message::{VhostUserProtocolFeatures, VhostUserVirtioFeatures}; use vhost::vhost_user::{FrontendReqHandler, VhostUserFrontend, VhostUserFrontendReqHandler}; use virtio_bindings::virtio_net::{ @@ -31,13 +30,13 @@ use virtio_queue::{Queue, QueueT}; use vm_memory::{ByteValued, GuestMemoryAtomic}; use vm_migration::{ protocol::MemoryRangeTable, Migratable, MigratableError, Pausable, Snapshot, Snapshottable, - Transportable, VersionMapped, + Transportable, }; use vmm_sys_util::eventfd::EventFd; const DEFAULT_QUEUE_NUMBER: usize = 2; -#[derive(Versionize)] +#[derive(Serialize, Deserialize)] pub struct State { pub avail_features: u64, pub acked_features: u64, @@ -46,8 +45,6 @@ pub struct State { pub vu_num_queues: usize, } -impl VersionMapped for State {} - struct BackendReqHandler {} impl VhostUserFrontendReqHandler for BackendReqHandler {} diff --git a/virtio-devices/src/vsock/device.rs b/virtio-devices/src/vsock/device.rs index 35be15582..9350e6b03 100644 --- a/virtio-devices/src/vsock/device.rs +++ b/virtio-devices/src/vsock/device.rs @@ -40,22 +40,19 @@ use crate::{ use anyhow::anyhow; use byteorder::{ByteOrder, LittleEndian}; use seccompiler::SeccompAction; +use serde::{Deserialize, Serialize}; use std::io; use std::os::unix::io::AsRawFd; use std::path::PathBuf; use std::result; use std::sync::atomic::AtomicBool; use std::sync::{Arc, Barrier, RwLock}; -use versionize::{VersionMap, Versionize, VersionizeResult}; -use versionize_derive::Versionize; use virtio_queue::Queue; use virtio_queue::QueueOwnedT; use virtio_queue::QueueT; use vm_memory::GuestAddressSpace; use vm_memory::GuestMemoryAtomic; -use vm_migration::{ - Migratable, MigratableError, Pausable, Snapshot, Snapshottable, Transportable, VersionMapped, -}; +use vm_migration::{Migratable, MigratableError, Pausable, Snapshot, Snapshottable, Transportable}; use vm_virtio::AccessPlatform; use vmm_sys_util::eventfd::EventFd; @@ -323,14 +320,12 @@ pub struct Vsock { exit_evt: EventFd, } -#[derive(Versionize)] +#[derive(Serialize, Deserialize)] pub struct VsockState { pub avail_features: u64, pub acked_features: u64, } -impl VersionMapped for VsockState {} - impl Vsock where B: VsockBackend + Sync, @@ -519,7 +514,7 @@ where } fn snapshot(&mut self) -> std::result::Result { - Snapshot::new_from_versioned_state(&self.state()) + Snapshot::new_from_state(&self.state()) } } impl Transportable for Vsock where B: VsockBackend + Sync + 'static {} diff --git a/virtio-devices/src/watchdog.rs b/virtio-devices/src/watchdog.rs index 546a6f302..13a8fe279 100644 --- a/virtio-devices/src/watchdog.rs +++ b/virtio-devices/src/watchdog.rs @@ -16,6 +16,7 @@ use crate::GuestMemoryMmap; use crate::{VirtioInterrupt, VirtioInterruptType}; use anyhow::anyhow; use seccompiler::SeccompAction; +use serde::{Deserialize, Serialize}; use std::fs::File; use std::io::{self, Read}; 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::time::Instant; use thiserror::Error; -use versionize::{VersionMap, Versionize, VersionizeResult}; -use versionize_derive::Versionize; use virtio_queue::{Queue, QueueT}; use vm_memory::{Bytes, GuestAddressSpace, GuestMemoryAtomic}; -use vm_migration::VersionMapped; use vm_migration::{Migratable, MigratableError, Pausable, Snapshot, Snapshottable, Transportable}; use vmm_sys_util::eventfd::EventFd; @@ -197,15 +195,13 @@ pub struct Watchdog { exit_evt: EventFd, } -#[derive(Versionize)] +#[derive(Serialize, Deserialize)] pub struct WatchdogState { pub avail_features: u64, pub acked_features: u64, pub enabled: bool, } -impl VersionMapped for WatchdogState {} - impl Watchdog { /// Create a new virtio watchdog device that will reboot VM if the guest hangs pub fn new( @@ -420,7 +416,7 @@ impl Snapshottable for Watchdog { } fn snapshot(&mut self) -> std::result::Result { - Snapshot::new_from_versioned_state(&self.state()) + Snapshot::new_from_state(&self.state()) } } diff --git a/vm-migration/Cargo.toml b/vm-migration/Cargo.toml index ce4b68b29..6dd5bebe9 100644 --- a/vm-migration/Cargo.toml +++ b/vm-migration/Cargo.toml @@ -9,6 +9,4 @@ anyhow = "1.0.81" thiserror = "1.0.58" serde = { version = "1.0.197", features = ["rc", "derive"] } 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"] } diff --git a/vm-migration/src/lib.rs b/vm-migration/src/lib.rs index 77b3771dc..5454bdb7c 100644 --- a/vm-migration/src/lib.rs +++ b/vm-migration/src/lib.rs @@ -7,21 +7,9 @@ use crate::protocol::MemoryRangeTable; use anyhow::anyhow; use serde::{Deserialize, Serialize}; use thiserror::Error; -use versionize::{VersionMap, Versionize}; 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)] pub enum MigratableError { #[error("Failed to pause migratable component: {0}")] @@ -80,7 +68,9 @@ pub trait Pausable { /// Splitting a component migration data into different sections /// allows for easier and forward compatible extensions. #[derive(Clone, Default, Deserialize, Serialize)] -pub struct SnapshotData(pub Vec); +pub struct SnapshotData { + state: String, +} impl SnapshotData { /// Generate the state data from the snapshot data @@ -88,16 +78,7 @@ impl SnapshotData { where T: Deserialize<'a>, { - serde_json::from_slice(&self.0) - .map_err(|e| MigratableError::Restore(anyhow!("Error deserialising: {}", e))) - } - - /// Generate versioned state - pub fn to_versioned_state(&self) -> Result - where - T: Versionize + VersionMapped, - { - T::deserialize(&mut self.0.as_slice(), &T::version_map(), VMM_VERSION) + serde_json::from_str(&self.state) .map_err(|e| MigratableError::Restore(anyhow!("Error deserialising: {}", e))) } @@ -106,23 +87,10 @@ impl SnapshotData { where 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)))?; - Ok(SnapshotData(data)) - } - - /// Create from versioned state - pub fn new_from_versioned_state(state: &T) -> Result - 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)) + Ok(SnapshotData { state }) } } @@ -163,16 +131,6 @@ impl Snapshot { Ok(Snapshot::from_data(SnapshotData::new_from_state(state)?)) } - /// Create from versioned state - pub fn new_from_versioned_state(state: &T) -> Result - where - T: Versionize + VersionMapped, - { - Ok(Snapshot::from_data(SnapshotData::new_from_versioned_state( - state, - )?)) - } - /// Add a sub-component's Snapshot to the Snapshot. pub fn add_snapshot(&mut self, id: String, snapshot: Snapshot) { self.snapshots.insert(id, snapshot); @@ -188,34 +146,21 @@ impl Snapshot { .ok_or_else(|| MigratableError::Restore(anyhow!("Missing snapshot data")))? .to_state() } - - /// Generate versioned state - pub fn to_versioned_state(&self) -> Result - 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.and_then(|s| s.snapshots.get(id).cloned()) } -pub fn versioned_state_from_id( - snapshot: Option<&Snapshot>, - id: &str, -) -> Result, MigratableError> +pub fn state_from_id<'a, T>(s: Option<&'a Snapshot>, id: &str) -> Result, MigratableError> where - T: Versionize + VersionMapped, + T: Deserialize<'a>, { - snapshot - .and_then(|s| s.snapshots.get(id).cloned()) - .map(|s| s.to_versioned_state()) - .transpose() + if let Some(s) = s.as_ref() { + s.snapshots.get(id).map(|s| s.to_state()).transpose() + } else { + Ok(None) + } } /// A snapshottable component can be snapshotted. diff --git a/vm-migration/src/protocol.rs b/vm-migration/src/protocol.rs index ddbb6117d..ad453b178 100644 --- a/vm-migration/src/protocol.rs +++ b/vm-migration/src/protocol.rs @@ -3,11 +3,9 @@ // SPDX-License-Identifier: Apache-2.0 // -use crate::{MigratableError, VersionMapped}; +use crate::MigratableError; use serde::{Deserialize, Serialize}; use std::io::{Read, Write}; -use versionize::{VersionMap, Versionize, VersionizeResult}; -use versionize_derive::Versionize; use vm_memory::ByteValued; // Migration protocol @@ -199,19 +197,17 @@ impl Response { } #[repr(C)] -#[derive(Clone, Default, Serialize, Deserialize, Versionize)] +#[derive(Clone, Default, Serialize, Deserialize)] pub struct MemoryRange { pub gpa: u64, pub length: u64, } -#[derive(Clone, Default, Serialize, Deserialize, Versionize)] +#[derive(Clone, Default, Serialize, Deserialize)] pub struct MemoryRangeTable { data: Vec, } -impl VersionMapped for MemoryRangeTable {} - impl MemoryRangeTable { pub fn from_bitmap(bitmap: Vec, start_addr: u64, page_size: u64) -> Self { let mut table = MemoryRangeTable::default(); diff --git a/vmm/Cargo.toml b/vmm/Cargo.toml index 270d627d3..bac30fbba 100644 --- a/vmm/Cargo.toml +++ b/vmm/Cargo.toml @@ -56,8 +56,6 @@ signal-hook = "0.3.17" thiserror = "1.0.58" tracer = { path = "../tracer" } 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_user = { git = "https://github.com/rust-vmm/vfio-user", branch = "main" } virtio-devices = { path = "../virtio-devices" } diff --git a/vmm/src/device_manager.rs b/vmm/src/device_manager.rs index 61ff76115..60198f727 100644 --- a/vmm/src/device_manager.rs +++ b/vmm/src/device_manager.rs @@ -96,8 +96,8 @@ use vm_memory::{Address, GuestAddress, GuestUsize, MmapRegion}; #[cfg(target_arch = "x86_64")] use vm_memory::{GuestAddressSpace, GuestMemory}; use vm_migration::{ - protocol::MemoryRangeTable, snapshot_from_id, versioned_state_from_id, Migratable, - MigratableError, Pausable, Snapshot, SnapshotData, Snapshottable, Transportable, + protocol::MemoryRangeTable, snapshot_from_id, state_from_id, Migratable, MigratableError, + Pausable, Snapshot, SnapshotData, Snapshottable, Transportable, }; use vm_virtio::AccessPlatform; use vm_virtio::VirtioDeviceType; @@ -1371,7 +1371,7 @@ impl DeviceManager { .try_clone() .map_err(DeviceManagerError::EventFd)?, 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::CreateVirtioIommu)?; @@ -1519,7 +1519,7 @@ impl DeviceManager { id.clone(), APIC_START, 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::CreateInterruptController)?, @@ -1791,7 +1791,7 @@ impl DeviceManager { let gpio_device = Arc::new(Mutex::new(devices::legacy::Gpio::new( id.clone(), 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)?, ))); @@ -1892,7 +1892,7 @@ impl DeviceManager { id.clone(), interrupt_group, 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)?, ))); @@ -1949,7 +1949,7 @@ impl DeviceManager { interrupt_group, serial_writer, 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)?, ))); @@ -2128,7 +2128,7 @@ impl DeviceManager { self.exit_evt .try_clone() .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::CreateVirtioConsole)?; @@ -2362,8 +2362,6 @@ impl DeviceManager { 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 socket = disk_cfg.vhost_socket.as_ref().unwrap().clone(); let vu_cfg = VhostUserConfig { @@ -2380,9 +2378,7 @@ impl DeviceManager { .try_clone() .map_err(DeviceManagerError::EventFd)?, self.force_iommu, - snapshot - .map(|s| s.to_versioned_state()) - .transpose() + state_from_id(self.snapshot.as_ref(), id.as_str()) .map_err(DeviceManagerError::RestoreGetState)?, ) { Ok(vub_device) => vub_device, @@ -2542,9 +2538,7 @@ impl DeviceManager { self.exit_evt .try_clone() .map_err(DeviceManagerError::EventFd)?, - snapshot - .map(|s| s.to_versioned_state()) - .transpose() + state_from_id(self.snapshot.as_ref(), id.as_str()) .map_err(DeviceManagerError::RestoreGetState)?, queue_affinity, ) @@ -2601,8 +2595,6 @@ impl DeviceManager { }; 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 socket = net_cfg.vhost_socket.as_ref().unwrap().clone(); let vu_cfg = VhostUserConfig { @@ -2626,9 +2618,7 @@ impl DeviceManager { .try_clone() .map_err(DeviceManagerError::EventFd)?, self.force_iommu, - snapshot - .map(|s| s.to_versioned_state()) - .transpose() + state_from_id(self.snapshot.as_ref(), id.as_str()) .map_err(DeviceManagerError::RestoreGetState)?, net_cfg.offload_tso, net_cfg.offload_ufo, @@ -2646,11 +2636,8 @@ impl DeviceManager { vhost_user_net as Arc>, ) } else { - let state = snapshot - .map(|s| s.to_versioned_state()) - .transpose() + let state = state_from_id(self.snapshot.as_ref(), id.as_str()) .map_err(DeviceManagerError::RestoreGetState)?; - let virtio_net = if let Some(ref tap_if_name) = net_cfg.tap { Arc::new(Mutex::new( virtio_devices::Net::new( @@ -2784,7 +2771,7 @@ impl DeviceManager { self.exit_evt .try_clone() .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::CreateVirtioRng)?, @@ -2840,7 +2827,7 @@ impl DeviceManager { .try_clone() .map_err(DeviceManagerError::EventFd)?, 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::CreateVirtioFs)?, @@ -3024,7 +3011,7 @@ impl DeviceManager { self.exit_evt .try_clone() .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::CreateVirtioPmem)?, @@ -3096,7 +3083,7 @@ impl DeviceManager { self.exit_evt .try_clone() .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::CreateVirtioVsock)?, @@ -3156,7 +3143,7 @@ impl DeviceManager { .try_clone() .map_err(DeviceManagerError::EventFd)?, 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::CreateVirtioMem)?, @@ -3208,7 +3195,7 @@ impl DeviceManager { self.exit_evt .try_clone() .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::CreateVirtioBalloon)?, @@ -3252,7 +3239,7 @@ impl DeviceManager { self.exit_evt .try_clone() .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::CreateVirtioWatchdog)?, @@ -3299,7 +3286,7 @@ impl DeviceManager { device_path, self.memory_manager.lock().unwrap().guest_memory(), 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::CreateVdpa)?, diff --git a/vmm/src/memory_manager.rs b/vmm/src/memory_manager.rs index 2a7ecd2d5..5729677b1 100644 --- a/vmm/src/memory_manager.rs +++ b/vmm/src/memory_manager.rs @@ -39,8 +39,6 @@ use std::result; use std::sync::{Arc, Barrier, Mutex}; use std::{ffi, thread}; use tracer::trace_scoped; -use versionize::{VersionMap, Versionize, VersionizeResult}; -use versionize_derive::Versionize; use virtio_devices::BlocksState; #[cfg(target_arch = "x86_64")] use vm_allocator::GsiApic; @@ -55,7 +53,7 @@ use vm_memory::{ }; use vm_migration::{ protocol::MemoryRange, protocol::MemoryRangeTable, Migratable, MigratableError, Pausable, - Snapshot, SnapshotData, Snapshottable, Transportable, VersionMapped, + Snapshot, SnapshotData, Snapshottable, Transportable, }; 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; -#[derive(Clone, Default, Serialize, Deserialize, Versionize)] +#[derive(Clone, Default, Serialize, Deserialize)] struct HotPlugState { base: u64, length: u64, @@ -143,7 +141,7 @@ impl MemoryZone { pub type MemoryZones = HashMap; -#[derive(Clone, Serialize, Deserialize, Versionize)] +#[derive(Clone, Serialize, Deserialize)] struct GuestRamMapping { slot: u32, gpa: u64, @@ -153,7 +151,7 @@ struct GuestRamMapping { file_offset: u64, } -#[derive(Clone, Serialize, Deserialize, Versionize)] +#[derive(Clone, Serialize, Deserialize)] struct ArchMemRegion { base: u64, size: usize, @@ -1269,7 +1267,7 @@ impl MemoryManager { memory_file_path.push(String::from(SNAPSHOT_FILENAME)); let mem_snapshot: MemoryManagerSnapshotData = - snapshot.to_versioned_state().map_err(Error::Restore)?; + snapshot.to_state().map_err(Error::Restore)?; let mm = MemoryManager::new( vm, @@ -2628,7 +2626,7 @@ impl Aml for MemoryManager { impl Pausable for MemoryManager {} -#[derive(Clone, Serialize, Deserialize, Versionize)] +#[derive(Clone, Serialize, Deserialize)] pub struct MemoryManagerSnapshotData { memory_ranges: MemoryRangeTable, guest_ram_mappings: Vec, @@ -2642,8 +2640,6 @@ pub struct MemoryManagerSnapshotData { next_hotplug_slot: usize, } -impl VersionMapped for MemoryManagerSnapshotData {} - impl Snapshottable for MemoryManager { fn id(&self) -> String { MEMORY_MANAGER_SNAPSHOT_ID.to_string() @@ -2662,7 +2658,7 @@ impl Snapshottable for MemoryManager { // memory range content for the ranges requiring it. 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(), )?)) } diff --git a/vmm/src/vm.rs b/vmm/src/vm.rs index 80a96ea68..690967f5b 100644 --- a/vmm/src/vm.rs +++ b/vmm/src/vm.rs @@ -94,7 +94,7 @@ use vm_memory::{ use vm_migration::protocol::{Request, Response, Status}; use vm_migration::{ protocol::MemoryRangeTable, snapshot_from_id, Migratable, MigratableError, Pausable, Snapshot, - SnapshotData, Snapshottable, Transportable, + Snapshottable, Transportable, }; use vmm_sys_util::eventfd::EventFd; 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"))] clock: self.saved_clock, #[cfg(all(feature = "kvm", target_arch = "x86_64"))] 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 mut cpu_manager = self.cpu_manager.lock().unwrap();