diff --git a/Cargo.lock b/Cargo.lock index 68430e31c..24bf24907 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1,5 +1,7 @@ # This file is automatically @generated by Cargo. # It is not intended for manual editing. +version = 3 + [[package]] name = "acpi_tables" version = "0.1.0" @@ -253,9 +255,8 @@ dependencies = [ "epoll", "libc", "log 0.4.14", - "serde", - "serde_derive", - "serde_json", + "versionize", + "versionize_derive", "vm-device", "vm-memory", "vm-migration", diff --git a/devices/Cargo.toml b/devices/Cargo.toml index 83fcc3852..d55b07942 100644 --- a/devices/Cargo.toml +++ b/devices/Cargo.toml @@ -5,17 +5,16 @@ authors = ["The Chromium OS Authors"] edition = "2018" [dependencies] +acpi_tables = { path = "../acpi_tables", optional = true } anyhow = "1.0" bitflags = ">=1.2.1" byteorder = "1.4.3" epoll = ">=4.0.1" libc = "0.2.94" log = "0.4.14" -serde = {version = ">=1.0.27", features = ["rc"] } -serde_derive = ">=1.0.27" -serde_json = ">=1.0.9" +versionize = "0.1.6" +versionize_derive = "0.1.4" vm-device = { path = "../vm-device" } -acpi_tables = { path = "../acpi_tables", optional = true } vm-memory = "0.5.0" vm-migration = { path = "../vm-migration" } vmm-sys-util = ">=0.3.1" diff --git a/devices/src/ioapic.rs b/devices/src/ioapic.rs index 3387981e8..52a942b3a 100644 --- a/devices/src/ioapic.rs +++ b/devices/src/ioapic.rs @@ -14,13 +14,17 @@ use anyhow::anyhow; use byteorder::{ByteOrder, LittleEndian}; 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}; +use vm_migration::{ + Migratable, MigratableError, Pausable, Snapshot, Snapshottable, Transportable, VersionMapped, +}; use vmm_sys_util::eventfd::EventFd; type Result = result::Result; @@ -133,7 +137,7 @@ pub struct Ioapic { interrupt_source_group: Arc>, } -#[derive(Serialize, Deserialize)] +#[derive(Versionize)] pub struct IoapicState { id_reg: u32, reg_sel: u32, @@ -141,6 +145,7 @@ 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]) { @@ -410,13 +415,18 @@ impl Snapshottable for Ioapic { } fn snapshot(&mut self) -> std::result::Result { - Snapshot::new_from_state(&self.id, &self.state()) + Snapshot::new_from_versioned_state(&self.id, &self.state()) } fn restore(&mut self, snapshot: Snapshot) -> std::result::Result<(), MigratableError> { - self.set_state(&snapshot.to_state(&self.id)?).map_err(|e| { - MigratableError::Restore(anyhow!("Could not restore state for {}: {:?}", self.id, e)) - }) + self.set_state(&snapshot.to_versioned_state(&self.id)?) + .map_err(|e| { + MigratableError::Restore(anyhow!( + "Could not restore state for {}: {:?}", + self.id, + e + )) + }) } } diff --git a/devices/src/legacy/gpio_pl061.rs b/devices/src/legacy/gpio_pl061.rs index 3cd6b2442..8121c9948 100644 --- a/devices/src/legacy/gpio_pl061.rs +++ b/devices/src/legacy/gpio_pl061.rs @@ -11,9 +11,13 @@ use crate::{read_le_u32, write_le_u32}; 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}; +use vm_migration::{ + Migratable, MigratableError, Pausable, Snapshot, Snapshottable, Transportable, VersionMapped, +}; const OFS_DATA: u64 = 0x400; // Data Register const GPIODIR: u64 = 0x400; // Direction Register @@ -85,7 +89,7 @@ pub struct Gpio { interrupt: Arc>, } -#[derive(Serialize, Deserialize)] +#[derive(Versionize)] pub struct GpioState { data: u32, old_in_data: u32, @@ -98,6 +102,8 @@ pub struct GpioState { afsel: u32, } +impl VersionMapped for GpioState {} + impl Gpio { /// Constructs an PL061 GPIO device. pub fn new(id: String, interrupt: Arc>) -> Self { @@ -313,11 +319,11 @@ impl Snapshottable for Gpio { } fn snapshot(&mut self) -> std::result::Result { - Snapshot::new_from_state(&self.id, &self.state()) + Snapshot::new_from_versioned_state(&self.id, &self.state()) } fn restore(&mut self, snapshot: Snapshot) -> std::result::Result<(), MigratableError> { - self.set_state(&snapshot.to_state(&self.id)?); + self.set_state(&snapshot.to_versioned_state(&self.id)?); Ok(()) } } diff --git a/devices/src/legacy/serial.rs b/devices/src/legacy/serial.rs index 2b10edb98..27b73766d 100644 --- a/devices/src/legacy/serial.rs +++ b/devices/src/legacy/serial.rs @@ -8,9 +8,13 @@ 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}; +use vm_migration::{ + Migratable, MigratableError, Pausable, Snapshot, Snapshottable, Transportable, VersionMapped, +}; use vmm_sys_util::errno::Result; const LOOP_SIZE: usize = 0x40; @@ -70,7 +74,7 @@ pub struct Serial { out: Option>, } -#[derive(Serialize, Deserialize)] +#[derive(Versionize)] pub struct SerialState { interrupt_enable: u8, interrupt_identification: u8, @@ -82,6 +86,7 @@ pub struct SerialState { baud_divisor: u16, in_buffer: Vec, } +impl VersionMapped for SerialState {} impl Serial { pub fn new( @@ -288,11 +293,11 @@ impl Snapshottable for Serial { } fn snapshot(&mut self) -> std::result::Result { - Snapshot::new_from_state(&self.id, &self.state()) + Snapshot::new_from_versioned_state(&self.id, &self.state()) } fn restore(&mut self, snapshot: Snapshot) -> std::result::Result<(), MigratableError> { - self.set_state(&snapshot.to_state(&self.id)?); + self.set_state(&snapshot.to_versioned_state(&self.id)?); Ok(()) } } diff --git a/devices/src/legacy/uart_pl011.rs b/devices/src/legacy/uart_pl011.rs index c43cfe11a..061f5cff8 100644 --- a/devices/src/legacy/uart_pl011.rs +++ b/devices/src/legacy/uart_pl011.rs @@ -11,9 +11,13 @@ use std::collections::VecDeque; use std::fmt; 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}; +use vm_migration::{ + Migratable, MigratableError, Pausable, Snapshot, Snapshottable, Transportable, VersionMapped, +}; /* Registers */ const UARTDR: u64 = 0; @@ -86,7 +90,7 @@ pub struct Pl011 { out: Option>, } -#[derive(Serialize, Deserialize)] +#[derive(Versionize)] pub struct Pl011State { flags: u32, lcr: u32, @@ -104,6 +108,8 @@ pub struct Pl011State { read_trigger: u32, } +impl VersionMapped for Pl011State {} + impl Pl011 { /// Constructs an AMBA PL011 UART device. pub fn new( @@ -357,11 +363,11 @@ impl Snapshottable for Pl011 { } fn snapshot(&mut self) -> std::result::Result { - Snapshot::new_from_state(&self.id, &self.state()) + Snapshot::new_from_versioned_state(&self.id, &self.state()) } fn restore(&mut self, snapshot: Snapshot) -> std::result::Result<(), MigratableError> { - self.set_state(&snapshot.to_state(&self.id)?); + self.set_state(&snapshot.to_versioned_state(&self.id)?); Ok(()) } } diff --git a/devices/src/lib.rs b/devices/src/lib.rs index 0c26397a7..7f78718d3 100644 --- a/devices/src/lib.rs +++ b/devices/src/lib.rs @@ -16,14 +16,10 @@ extern crate libc; extern crate log; #[cfg(feature = "acpi")] extern crate acpi_tables; -extern crate serde; extern crate vm_device; extern crate vm_memory; extern crate vm_migration; extern crate vmm_sys_util; -#[macro_use] -extern crate serde_derive; -extern crate serde_json; #[cfg(feature = "acpi")] pub mod acpi;