mirror of
https://github.com/cloud-hypervisor/cloud-hypervisor.git
synced 2026-08-05 02:19:16 +00:00
misc: Migrate away from versionize
Replace with serde instead. Fixes: #6370 Signed-off-by: Rob Bradford <rbradford@rivosinc.com>
This commit is contained in:
@@ -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, MigratableError> {
|
||||
Snapshot::new_from_versioned_state(&self.state())
|
||||
Snapshot::new_from_state(&self.state())
|
||||
}
|
||||
}
|
||||
impl Transportable for Balloon {}
|
||||
|
||||
@@ -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<u16, Vec<usize>>,
|
||||
}
|
||||
|
||||
#[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, MigratableError> {
|
||||
Snapshot::new_from_versioned_state(&self.state())
|
||||
Snapshot::new_from_state(&self.state())
|
||||
}
|
||||
}
|
||||
impl Transportable for Block {}
|
||||
|
||||
@@ -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, MigratableError> {
|
||||
Snapshot::new_from_versioned_state(&self.state())
|
||||
Snapshot::new_from_state(&self.state())
|
||||
}
|
||||
}
|
||||
impl Transportable for Console {}
|
||||
|
||||
@@ -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, MigratableError> {
|
||||
Snapshot::new_from_versioned_state(&self.state())
|
||||
Snapshot::new_from_state(&self.state())
|
||||
}
|
||||
}
|
||||
impl Transportable for Iommu {}
|
||||
|
||||
@@ -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<bool>,
|
||||
}
|
||||
@@ -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, MigratableError> {
|
||||
Snapshot::new_from_versioned_state(&self.state())
|
||||
Snapshot::new_from_state(&self.state())
|
||||
}
|
||||
}
|
||||
impl Transportable for Mem {}
|
||||
|
||||
@@ -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<u16>,
|
||||
}
|
||||
|
||||
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, MigratableError> {
|
||||
Snapshot::new_from_versioned_state(&self.state())
|
||||
Snapshot::new_from_state(&self.state())
|
||||
}
|
||||
}
|
||||
impl Transportable for Net {}
|
||||
|
||||
@@ -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, MigratableError> {
|
||||
Snapshot::new_from_versioned_state(&self.state())
|
||||
Snapshot::new_from_state(&self.state())
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -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, MigratableError> {
|
||||
Snapshot::new_from_versioned_state(&self.state())
|
||||
Snapshot::new_from_state(&self.state())
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -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<u16>,
|
||||
}
|
||||
|
||||
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, MigratableError> {
|
||||
Snapshot::new_from_versioned_state(&self.state())
|
||||
Snapshot::new_from_state(&self.state())
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -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<QueueState>,
|
||||
@@ -282,8 +279,6 @@ pub struct VirtioPciDeviceState {
|
||||
cap_pci_cfg: Vec<u8>,
|
||||
}
|
||||
|
||||
impl VersionMapped for VirtioPciDeviceState {}
|
||||
|
||||
pub struct VirtioPciDeviceActivator {
|
||||
interrupt: Option<Arc<dyn VirtioInterrupt>>,
|
||||
memory: Option<GuestMemoryAtomic<GuestMemoryMmap>>,
|
||||
@@ -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<VirtioPciDeviceState> = 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<Snapshot, MigratableError> {
|
||||
let mut virtio_pci_dev_snapshot = Snapshot::new_from_versioned_state(&self.state())?;
|
||||
let mut virtio_pci_dev_snapshot = Snapshot::new_from_state(&self.state())?;
|
||||
|
||||
// Snapshot PciConfiguration
|
||||
virtio_pci_dev_snapshot
|
||||
|
||||
@@ -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<T> = std::result::Result<T, Error>;
|
||||
|
||||
#[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))
|
||||
})?)?;
|
||||
|
||||
|
||||
@@ -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 {}
|
||||
|
||||
|
||||
@@ -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,
|
||||
}
|
||||
|
||||
@@ -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<T>(&mut self, state: &T) -> std::result::Result<Snapshot, MigratableError>
|
||||
pub fn snapshot<'a, T>(&mut self, state: &T) -> std::result::Result<Snapshot, MigratableError>
|
||||
where
|
||||
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();
|
||||
|
||||
@@ -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 {}
|
||||
|
||||
|
||||
@@ -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<B: VsockBackend> {
|
||||
exit_evt: EventFd,
|
||||
}
|
||||
|
||||
#[derive(Versionize)]
|
||||
#[derive(Serialize, Deserialize)]
|
||||
pub struct VsockState {
|
||||
pub avail_features: u64,
|
||||
pub acked_features: u64,
|
||||
}
|
||||
|
||||
impl VersionMapped for VsockState {}
|
||||
|
||||
impl<B> Vsock<B>
|
||||
where
|
||||
B: VsockBackend + Sync,
|
||||
@@ -519,7 +514,7 @@ where
|
||||
}
|
||||
|
||||
fn snapshot(&mut self) -> std::result::Result<Snapshot, MigratableError> {
|
||||
Snapshot::new_from_versioned_state(&self.state())
|
||||
Snapshot::new_from_state(&self.state())
|
||||
}
|
||||
}
|
||||
impl<B> Transportable for Vsock<B> where B: VsockBackend + Sync + 'static {}
|
||||
|
||||
@@ -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, MigratableError> {
|
||||
Snapshot::new_from_versioned_state(&self.state())
|
||||
Snapshot::new_from_state(&self.state())
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user