Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions src/vmm/src/builder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ use crate::cpu_config::templates::{GetCpuTemplate, GetCpuTemplateError, GuestCon
use crate::device_manager;
use crate::device_manager::pci_mngr::PciManagerError;
use crate::device_manager::{
AttachDeviceError, DeviceManager, DeviceManagerCreateError, DevicePersistError,
AttachDeviceError, DeviceManager, DeviceManagerCreateError, DeviceManagerPersistError,
DeviceRestoreArgs,
};
use crate::devices::acpi::vmgenid::VmGenIdError;
Expand Down Expand Up @@ -423,7 +423,7 @@ pub enum BuildMicrovmFromSnapshotError {
/// Failed to apply VMM secccomp filter: {0}
SeccompFiltersInternal(#[from] crate::seccomp::InstallationError),
/// Failed to restore devices: {0}
RestoreDevices(#[from] DevicePersistError),
RestoreDevices(#[from] DeviceManagerPersistError),
}

/// Builds and starts a microVM based on the provided MicrovmState.
Expand Down
57 changes: 52 additions & 5 deletions src/vmm/src/device_manager/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -31,11 +31,20 @@ use crate::devices::legacy::RTCDevice;
use crate::devices::legacy::serial::SerialOut;
use crate::devices::legacy::{IER_RDA_BIT, IER_RDA_OFFSET, SerialDevice};
use crate::devices::pseudo::BootTimer;
use crate::devices::virtio::ActivateError;
use crate::devices::virtio::balloon::BalloonError;
use crate::devices::virtio::block::BlockError;
use crate::devices::virtio::device::VirtioDevice;
use crate::devices::virtio::mem::persist::VirtioMemPersistError;
use crate::devices::virtio::net::persist::NetPersistError;
use crate::devices::virtio::pmem::persist::PmemPersistError;
use crate::devices::virtio::rng::persist::EntropyPersistError;
use crate::devices::virtio::transport::mmio::{IrqTrigger, MmioTransport};
use crate::devices::virtio::vsock::{VsockError, VsockUnixBackendError};
use crate::resources::VmResources;
use crate::snapshot::Persist;
use crate::utils::open_file_write_nonblock;
use crate::vmm_config::mmds::MmdsConfigError;
use crate::vstate::bus::BusError;
use crate::vstate::memory::GuestMemoryMmap;
use crate::{EmulateSerialInitError, EventManager, Vm};
Expand Down Expand Up @@ -389,14 +398,50 @@ pub struct DevicesState {
pub pci_state: pci_mngr::PciDevicesState,
}

/// Errors for (de)serialization of the devices.
#[derive(Debug, thiserror::Error, displaydoc::Display)]
pub enum DevicePersistError {
/// Balloon: {0}
Balloon(#[from] BalloonError),
/// Block: {0}
Block(#[from] BlockError),
/// MMIO Device manager: {0}
MmioDeviceManager(#[from] mmio::MmioError),
/// Mmio transport
MmioTransport,
/// PCI Device manager: {0}
PciDeviceManager(#[from] PciManagerError),
/// Bus error: {0}
Bus(#[from] BusError),
#[cfg(target_arch = "aarch64")]
/// Legacy: {0}
Legacy(#[from] std::io::Error),
/// Net: {0}
Net(#[from] NetPersistError),
/// Vsock: {0}
Vsock(#[from] VsockError),
/// VsockUnixBackend: {0}
VsockUnixBackend(#[from] VsockUnixBackendError),
/// MmdsConfig: {0}
MmdsConfig(#[from] MmdsConfigError),
/// Entropy: {0}
Entropy(#[from] EntropyPersistError),
/// Pmem: {0}
Pmem(#[from] PmemPersistError),
/// virtio-mem: {0}
VirtioMem(#[from] VirtioMemPersistError),
/// Could not activate device: {0}
DeviceActivation(#[from] ActivateError),
}

#[derive(Debug, thiserror::Error, displaydoc::Display)]
pub enum DeviceManagerPersistError {
/// Error restoring MMIO devices: {0}
MmioRestore(#[from] persist::DevicePersistError),
MmioRestore(DevicePersistError),
/// Error restoring ACPI devices: {0}
AcpiRestore(#[from] persist::ACPIDeviceManagerRestoreError),
/// Error restoring PCI devices: {0}
PciRestore(#[from] PciManagerError),
PciRestore(DevicePersistError),
/// Error notifying VMGenID device: {0}
VmGenidUpdate(#[from] std::io::Error),
/// Error resetting serial console: {0}
Expand Down Expand Up @@ -430,7 +475,7 @@ impl std::fmt::Debug for DeviceRestoreArgs<'_> {
impl<'a> Persist<'a> for DeviceManager {
type State = DevicesState;
type ConstructorArgs = DeviceRestoreArgs<'a>;
type Error = DevicePersistError;
type Error = DeviceManagerPersistError;

fn save(&self) -> Self::State {
DevicesState {
Expand Down Expand Up @@ -461,7 +506,8 @@ impl<'a> Persist<'a> for DeviceManager {
vm_resources: constructor_args.vm_resources,
instance_id: constructor_args.instance_id,
};
let mmio_devices = MMIODeviceManager::restore(mmio_ctor_args, &state.mmio_state)?;
let mmio_devices = MMIODeviceManager::restore(mmio_ctor_args, &state.mmio_state)
.map_err(DeviceManagerPersistError::MmioRestore)?;

// Restore ACPI devices
let acpi_ctor_args = ACPIDeviceManagerConstructorArgs {
Expand All @@ -479,7 +525,8 @@ impl<'a> Persist<'a> for DeviceManager {
instance_id: constructor_args.instance_id,
event_manager: constructor_args.event_manager,
};
let pci_devices = PciDevices::restore(pci_ctor_args, &state.pci_state)?;
let pci_devices = PciDevices::restore(pci_ctor_args, &state.pci_state)
.map_err(DeviceManagerPersistError::PciRestore)?;

let device_manager = DeviceManager {
mmio_devices,
Expand Down
Loading