misc: Migrate away from versionize

Replace with serde instead.

Fixes: #6370

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

View File

@@ -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 {}

View File

@@ -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,
}

View File

@@ -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();

View File

@@ -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 {}