mirror of
https://github.com/cloud-hypervisor/cloud-hypervisor.git
synced 2024-08-20 15:01:16 +00:00
virtio-devices: transport: Versionize VirtioPciDevice state
Signed-off-by: Rob Bradford <robert.bradford@intel.com>
This commit is contained in:
parent
57f532a760
commit
905135fe8c
@ -27,6 +27,8 @@ use std::num::Wrapping;
|
|||||||
use std::result;
|
use std::result;
|
||||||
use std::sync::atomic::{AtomicBool, AtomicU16, AtomicUsize, Ordering};
|
use std::sync::atomic::{AtomicBool, AtomicU16, AtomicUsize, Ordering};
|
||||||
use std::sync::{Arc, Barrier, Mutex};
|
use std::sync::{Arc, Barrier, Mutex};
|
||||||
|
use versionize::{VersionMap, Versionize, VersionizeResult};
|
||||||
|
use versionize_derive::Versionize;
|
||||||
use vm_allocator::SystemAllocator;
|
use vm_allocator::SystemAllocator;
|
||||||
use vm_device::interrupt::{
|
use vm_device::interrupt::{
|
||||||
InterruptIndex, InterruptManager, InterruptSourceGroup, MsiIrqGroupConfig,
|
InterruptIndex, InterruptManager, InterruptSourceGroup, MsiIrqGroupConfig,
|
||||||
@ -36,7 +38,9 @@ use vm_memory::{
|
|||||||
Address, ByteValued, GuestAddress, GuestAddressSpace, GuestMemoryAtomic, GuestMemoryMmap,
|
Address, ByteValued, GuestAddress, GuestAddressSpace, GuestMemoryAtomic, GuestMemoryMmap,
|
||||||
GuestUsize, Le32,
|
GuestUsize, Le32,
|
||||||
};
|
};
|
||||||
use vm_migration::{Migratable, MigratableError, Pausable, Snapshot, Snapshottable, Transportable};
|
use vm_migration::{
|
||||||
|
Migratable, MigratableError, Pausable, Snapshot, Snapshottable, Transportable, VersionMapped,
|
||||||
|
};
|
||||||
use vm_virtio::{queue, VirtioIommuRemapping, VIRTIO_MSI_NO_VECTOR};
|
use vm_virtio::{queue, VirtioIommuRemapping, VIRTIO_MSI_NO_VECTOR};
|
||||||
use vmm_sys_util::{errno::Result, eventfd::EventFd};
|
use vmm_sys_util::{errno::Result, eventfd::EventFd};
|
||||||
|
|
||||||
@ -260,7 +264,7 @@ const NOTIFY_OFF_MULTIPLIER: u32 = 4; // A dword per notification address.
|
|||||||
const VIRTIO_PCI_VENDOR_ID: u16 = 0x1af4;
|
const VIRTIO_PCI_VENDOR_ID: u16 = 0x1af4;
|
||||||
const VIRTIO_PCI_DEVICE_ID_BASE: u16 = 0x1040; // Add to device type to get device ID.
|
const VIRTIO_PCI_DEVICE_ID_BASE: u16 = 0x1040; // Add to device type to get device ID.
|
||||||
|
|
||||||
#[derive(Serialize, Deserialize)]
|
#[derive(Versionize)]
|
||||||
struct QueueState {
|
struct QueueState {
|
||||||
max_size: u16,
|
max_size: u16,
|
||||||
size: u16,
|
size: u16,
|
||||||
@ -271,13 +275,15 @@ struct QueueState {
|
|||||||
used_ring: u64,
|
used_ring: u64,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Serialize, Deserialize)]
|
#[derive(Versionize)]
|
||||||
struct VirtioPciDeviceState {
|
struct VirtioPciDeviceState {
|
||||||
device_activated: bool,
|
device_activated: bool,
|
||||||
queues: Vec<QueueState>,
|
queues: Vec<QueueState>,
|
||||||
interrupt_status: usize,
|
interrupt_status: usize,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
impl VersionMapped for VirtioPciDeviceState {}
|
||||||
|
|
||||||
pub struct VirtioPciDevice {
|
pub struct VirtioPciDevice {
|
||||||
id: String,
|
id: String,
|
||||||
|
|
||||||
@ -1101,7 +1107,8 @@ impl Snapshottable for VirtioPciDevice {
|
|||||||
}
|
}
|
||||||
|
|
||||||
fn snapshot(&mut self) -> std::result::Result<Snapshot, MigratableError> {
|
fn snapshot(&mut self) -> std::result::Result<Snapshot, MigratableError> {
|
||||||
let mut virtio_pci_dev_snapshot = Snapshot::new_from_state(&self.id, &self.state())?;
|
let mut virtio_pci_dev_snapshot =
|
||||||
|
Snapshot::new_from_versioned_state(&self.id, &self.state())?;
|
||||||
|
|
||||||
// Snapshot PciConfiguration
|
// Snapshot PciConfiguration
|
||||||
virtio_pci_dev_snapshot.add_snapshot(self.configuration.snapshot()?);
|
virtio_pci_dev_snapshot.add_snapshot(self.configuration.snapshot()?);
|
||||||
@ -1144,7 +1151,7 @@ impl Snapshottable for VirtioPciDevice {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// First restore the status of the virtqueues.
|
// First restore the status of the virtqueues.
|
||||||
self.set_state(&virtio_pci_dev_section.to_state()?)
|
self.set_state(&virtio_pci_dev_section.to_versioned_state()?)
|
||||||
.map_err(|e| {
|
.map_err(|e| {
|
||||||
MigratableError::Restore(anyhow!(
|
MigratableError::Restore(anyhow!(
|
||||||
"Could not restore VIRTIO_PCI_DEVICE state {:?}",
|
"Could not restore VIRTIO_PCI_DEVICE state {:?}",
|
||||||
|
Loading…
Reference in New Issue
Block a user