devices: Move to versioned snapshots

Signed-off-by: Rob Bradford <robert.bradford@intel.com>
This commit is contained in:
Rob Bradford 2021-05-11 14:26:09 +00:00 committed by Sebastien Boeuf
parent c03fe508c1
commit 1205bce0ef
7 changed files with 52 additions and 29 deletions

7
Cargo.lock generated
View File

@ -1,5 +1,7 @@
# This file is automatically @generated by Cargo. # This file is automatically @generated by Cargo.
# It is not intended for manual editing. # It is not intended for manual editing.
version = 3
[[package]] [[package]]
name = "acpi_tables" name = "acpi_tables"
version = "0.1.0" version = "0.1.0"
@ -253,9 +255,8 @@ dependencies = [
"epoll", "epoll",
"libc", "libc",
"log 0.4.14", "log 0.4.14",
"serde", "versionize",
"serde_derive", "versionize_derive",
"serde_json",
"vm-device", "vm-device",
"vm-memory", "vm-memory",
"vm-migration", "vm-migration",

View File

@ -5,17 +5,16 @@ authors = ["The Chromium OS Authors"]
edition = "2018" edition = "2018"
[dependencies] [dependencies]
acpi_tables = { path = "../acpi_tables", optional = true }
anyhow = "1.0" anyhow = "1.0"
bitflags = ">=1.2.1" bitflags = ">=1.2.1"
byteorder = "1.4.3" byteorder = "1.4.3"
epoll = ">=4.0.1" epoll = ">=4.0.1"
libc = "0.2.94" libc = "0.2.94"
log = "0.4.14" log = "0.4.14"
serde = {version = ">=1.0.27", features = ["rc"] } versionize = "0.1.6"
serde_derive = ">=1.0.27" versionize_derive = "0.1.4"
serde_json = ">=1.0.9"
vm-device = { path = "../vm-device" } vm-device = { path = "../vm-device" }
acpi_tables = { path = "../acpi_tables", optional = true }
vm-memory = "0.5.0" vm-memory = "0.5.0"
vm-migration = { path = "../vm-migration" } vm-migration = { path = "../vm-migration" }
vmm-sys-util = ">=0.3.1" vmm-sys-util = ">=0.3.1"

View File

@ -14,13 +14,17 @@ use anyhow::anyhow;
use byteorder::{ByteOrder, LittleEndian}; use byteorder::{ByteOrder, LittleEndian};
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::{Migratable, MigratableError, Pausable, Snapshot, Snapshottable, Transportable}; use vm_migration::{
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>;
@ -133,7 +137,7 @@ pub struct Ioapic {
interrupt_source_group: Arc<Box<dyn InterruptSourceGroup>>, interrupt_source_group: Arc<Box<dyn InterruptSourceGroup>>,
} }
#[derive(Serialize, Deserialize)] #[derive(Versionize)]
pub struct IoapicState { pub struct IoapicState {
id_reg: u32, id_reg: u32,
reg_sel: u32, reg_sel: u32,
@ -141,6 +145,7 @@ 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]) {
@ -410,13 +415,18 @@ 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_state(&self.id, &self.state()) Snapshot::new_from_versioned_state(&self.id, &self.state())
} }
fn restore(&mut self, snapshot: Snapshot) -> std::result::Result<(), MigratableError> { fn restore(&mut self, snapshot: Snapshot) -> std::result::Result<(), MigratableError> {
self.set_state(&snapshot.to_state(&self.id)?).map_err(|e| { self.set_state(&snapshot.to_versioned_state(&self.id)?)
MigratableError::Restore(anyhow!("Could not restore state for {}: {:?}", self.id, e)) .map_err(|e| {
}) MigratableError::Restore(anyhow!(
"Could not restore state for {}: {:?}",
self.id,
e
))
})
} }
} }

View File

@ -11,9 +11,13 @@ use crate::{read_le_u32, write_le_u32};
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::{Migratable, MigratableError, Pausable, Snapshot, Snapshottable, Transportable}; use vm_migration::{
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
@ -85,7 +89,7 @@ pub struct Gpio {
interrupt: Arc<Box<dyn InterruptSourceGroup>>, interrupt: Arc<Box<dyn InterruptSourceGroup>>,
} }
#[derive(Serialize, Deserialize)] #[derive(Versionize)]
pub struct GpioState { pub struct GpioState {
data: u32, data: u32,
old_in_data: u32, old_in_data: u32,
@ -98,6 +102,8 @@ 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(id: String, interrupt: Arc<Box<dyn InterruptSourceGroup>>) -> Self { pub fn new(id: String, interrupt: Arc<Box<dyn InterruptSourceGroup>>) -> Self {
@ -313,11 +319,11 @@ 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_state(&self.id, &self.state()) Snapshot::new_from_versioned_state(&self.id, &self.state())
} }
fn restore(&mut self, snapshot: Snapshot) -> std::result::Result<(), MigratableError> { 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(()) Ok(())
} }
} }

View File

@ -8,9 +8,13 @@
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::{Migratable, MigratableError, Pausable, Snapshot, Snapshottable, Transportable}; use vm_migration::{
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;
@ -70,7 +74,7 @@ pub struct Serial {
out: Option<Box<dyn io::Write + Send>>, out: Option<Box<dyn io::Write + Send>>,
} }
#[derive(Serialize, Deserialize)] #[derive(Versionize)]
pub struct SerialState { pub struct SerialState {
interrupt_enable: u8, interrupt_enable: u8,
interrupt_identification: u8, interrupt_identification: u8,
@ -82,6 +86,7 @@ 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(
@ -288,11 +293,11 @@ 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_state(&self.id, &self.state()) Snapshot::new_from_versioned_state(&self.id, &self.state())
} }
fn restore(&mut self, snapshot: Snapshot) -> std::result::Result<(), MigratableError> { 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(()) Ok(())
} }
} }

View File

@ -11,9 +11,13 @@ use std::collections::VecDeque;
use std::fmt; use std::fmt;
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::{Migratable, MigratableError, Pausable, Snapshot, Snapshottable, Transportable}; use vm_migration::{
Migratable, MigratableError, Pausable, Snapshot, Snapshottable, Transportable, VersionMapped,
};
/* Registers */ /* Registers */
const UARTDR: u64 = 0; const UARTDR: u64 = 0;
@ -86,7 +90,7 @@ pub struct Pl011 {
out: Option<Box<dyn io::Write + Send>>, out: Option<Box<dyn io::Write + Send>>,
} }
#[derive(Serialize, Deserialize)] #[derive(Versionize)]
pub struct Pl011State { pub struct Pl011State {
flags: u32, flags: u32,
lcr: u32, lcr: u32,
@ -104,6 +108,8 @@ 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(
@ -357,11 +363,11 @@ 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_state(&self.id, &self.state()) Snapshot::new_from_versioned_state(&self.id, &self.state())
} }
fn restore(&mut self, snapshot: Snapshot) -> std::result::Result<(), MigratableError> { 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(()) Ok(())
} }
} }

View File

@ -16,14 +16,10 @@ extern crate libc;
extern crate log; extern crate log;
#[cfg(feature = "acpi")] #[cfg(feature = "acpi")]
extern crate acpi_tables; extern crate acpi_tables;
extern crate serde;
extern crate vm_device; extern crate vm_device;
extern crate vm_memory; extern crate vm_memory;
extern crate vm_migration; extern crate vm_migration;
extern crate vmm_sys_util; extern crate vmm_sys_util;
#[macro_use]
extern crate serde_derive;
extern crate serde_json;
#[cfg(feature = "acpi")] #[cfg(feature = "acpi")]
pub mod acpi; pub mod acpi;