Skip to content

Commit ccdb655

Browse files
committed
chore(pci): gracefully handle errors in the PCI restore code
All errors were previously unwrapped, differently from MMIO where they were handled. Refactor the code to handle the errors in the same way as MMIO. Signed-off-by: Riccardo Mancini <[email protected]>
1 parent c37849c commit ccdb655

File tree

4 files changed

+157
-185
lines changed

4 files changed

+157
-185
lines changed

src/vmm/src/builder.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ use crate::cpu_config::templates::{GetCpuTemplate, GetCpuTemplateError, GuestCon
2626
use crate::device_manager;
2727
use crate::device_manager::pci_mngr::PciManagerError;
2828
use crate::device_manager::{
29-
AttachDeviceError, DeviceManager, DeviceManagerCreateError, DevicePersistError,
29+
AttachDeviceError, DeviceManager, DeviceManagerCreateError, DeviceManagerPersistError,
3030
DeviceRestoreArgs,
3131
};
3232
use crate::devices::acpi::vmgenid::VmGenIdError;
@@ -423,7 +423,7 @@ pub enum BuildMicrovmFromSnapshotError {
423423
/// Failed to apply VMM secccomp filter: {0}
424424
SeccompFiltersInternal(#[from] crate::seccomp::InstallationError),
425425
/// Failed to restore devices: {0}
426-
RestoreDevices(#[from] DevicePersistError),
426+
RestoreDevices(#[from] DeviceManagerPersistError),
427427
}
428428

429429
/// Builds and starts a microVM based on the provided MicrovmState.

src/vmm/src/device_manager/mod.rs

Lines changed: 52 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -31,11 +31,20 @@ use crate::devices::legacy::RTCDevice;
3131
use crate::devices::legacy::serial::SerialOut;
3232
use crate::devices::legacy::{IER_RDA_BIT, IER_RDA_OFFSET, SerialDevice};
3333
use crate::devices::pseudo::BootTimer;
34+
use crate::devices::virtio::ActivateError;
35+
use crate::devices::virtio::balloon::BalloonError;
36+
use crate::devices::virtio::block::BlockError;
3437
use crate::devices::virtio::device::VirtioDevice;
38+
use crate::devices::virtio::mem::persist::VirtioMemPersistError;
39+
use crate::devices::virtio::net::persist::NetPersistError;
40+
use crate::devices::virtio::pmem::persist::PmemPersistError;
41+
use crate::devices::virtio::rng::persist::EntropyPersistError;
3542
use crate::devices::virtio::transport::mmio::{IrqTrigger, MmioTransport};
43+
use crate::devices::virtio::vsock::{VsockError, VsockUnixBackendError};
3644
use crate::resources::VmResources;
3745
use crate::snapshot::Persist;
3846
use crate::utils::open_file_write_nonblock;
47+
use crate::vmm_config::mmds::MmdsConfigError;
3948
use crate::vstate::bus::BusError;
4049
use crate::vstate::memory::GuestMemoryMmap;
4150
use crate::{EmulateSerialInitError, EventManager, Vm};
@@ -389,14 +398,50 @@ pub struct DevicesState {
389398
pub pci_state: pci_mngr::PciDevicesState,
390399
}
391400

401+
/// Errors for (de)serialization of the devices.
392402
#[derive(Debug, thiserror::Error, displaydoc::Display)]
393403
pub enum DevicePersistError {
404+
/// Balloon: {0}
405+
Balloon(#[from] BalloonError),
406+
/// Block: {0}
407+
Block(#[from] BlockError),
408+
/// MMIO Device manager: {0}
409+
MmioDeviceManager(#[from] mmio::MmioError),
410+
/// Mmio transport
411+
MmioTransport,
412+
/// PCI Device manager: {0}
413+
PciDeviceManager(#[from] PciManagerError),
414+
/// Bus error: {0}
415+
Bus(#[from] BusError),
416+
#[cfg(target_arch = "aarch64")]
417+
/// Legacy: {0}
418+
Legacy(#[from] std::io::Error),
419+
/// Net: {0}
420+
Net(#[from] NetPersistError),
421+
/// Vsock: {0}
422+
Vsock(#[from] VsockError),
423+
/// VsockUnixBackend: {0}
424+
VsockUnixBackend(#[from] VsockUnixBackendError),
425+
/// MmdsConfig: {0}
426+
MmdsConfig(#[from] MmdsConfigError),
427+
/// Entropy: {0}
428+
Entropy(#[from] EntropyPersistError),
429+
/// Pmem: {0}
430+
Pmem(#[from] PmemPersistError),
431+
/// virtio-mem: {0}
432+
VirtioMem(#[from] VirtioMemPersistError),
433+
/// Could not activate device: {0}
434+
DeviceActivation(#[from] ActivateError),
435+
}
436+
437+
#[derive(Debug, thiserror::Error, displaydoc::Display)]
438+
pub enum DeviceManagerPersistError {
394439
/// Error restoring MMIO devices: {0}
395-
MmioRestore(#[from] persist::DevicePersistError),
440+
MmioRestore(DevicePersistError),
396441
/// Error restoring ACPI devices: {0}
397442
AcpiRestore(#[from] persist::ACPIDeviceManagerRestoreError),
398443
/// Error restoring PCI devices: {0}
399-
PciRestore(#[from] PciManagerError),
444+
PciRestore(DevicePersistError),
400445
/// Error notifying VMGenID device: {0}
401446
VmGenidUpdate(#[from] std::io::Error),
402447
/// Error resetting serial console: {0}
@@ -430,7 +475,7 @@ impl std::fmt::Debug for DeviceRestoreArgs<'_> {
430475
impl<'a> Persist<'a> for DeviceManager {
431476
type State = DevicesState;
432477
type ConstructorArgs = DeviceRestoreArgs<'a>;
433-
type Error = DevicePersistError;
478+
type Error = DeviceManagerPersistError;
434479

435480
fn save(&self) -> Self::State {
436481
DevicesState {
@@ -461,7 +506,8 @@ impl<'a> Persist<'a> for DeviceManager {
461506
vm_resources: constructor_args.vm_resources,
462507
instance_id: constructor_args.instance_id,
463508
};
464-
let mmio_devices = MMIODeviceManager::restore(mmio_ctor_args, &state.mmio_state)?;
509+
let mmio_devices = MMIODeviceManager::restore(mmio_ctor_args, &state.mmio_state)
510+
.map_err(DeviceManagerPersistError::MmioRestore)?;
465511

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

484531
let device_manager = DeviceManager {
485532
mmio_devices,

0 commit comments

Comments
 (0)