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:
@@ -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<Mutex<dyn Migratable>>,
|
||||
)
|
||||
} 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)?,
|
||||
|
||||
@@ -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<String, MemoryZone>;
|
||||
|
||||
#[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<GuestRamMapping>,
|
||||
@@ -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(),
|
||||
)?))
|
||||
}
|
||||
|
||||
@@ -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();
|
||||
|
||||
Reference in New Issue
Block a user