Skip to content

Commit d4ad1f2

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 7a45e88 commit d4ad1f2

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::virtio::balloon::Balloon;
@@ -422,7 +422,7 @@ pub enum BuildMicrovmFromSnapshotError {
422422
/// Failed to apply VMM secccomp filter: {0}
423423
SeccompFiltersInternal(#[from] crate::seccomp::InstallationError),
424424
/// Failed to restore devices: {0}
425-
RestoreDevices(#[from] DevicePersistError),
425+
RestoreDevices(#[from] DeviceManagerPersistError),
426426
}
427427

428428
/// 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};
@@ -388,14 +397,50 @@ pub struct DevicesState {
388397
pub pci_state: pci_mngr::PciDevicesState,
389398
}
390399

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

434479
fn save(&self) -> Self::State {
435480
DevicesState {
@@ -460,7 +505,8 @@ impl<'a> Persist<'a> for DeviceManager {
460505
vm_resources: constructor_args.vm_resources,
461506
instance_id: constructor_args.instance_id,
462507
};
463-
let mmio_devices = MMIODeviceManager::restore(mmio_ctor_args, &state.mmio_state)?;
508+
let mmio_devices = MMIODeviceManager::restore(mmio_ctor_args, &state.mmio_state)
509+
.map_err(DeviceManagerPersistError::MmioRestore)?;
464510

465511
// Restore ACPI devices
466512
let mut acpi_devices = ACPIDeviceManager::restore(constructor_args.vm, &state.acpi_state)?;
@@ -474,7 +520,8 @@ impl<'a> Persist<'a> for DeviceManager {
474520
instance_id: constructor_args.instance_id,
475521
event_manager: constructor_args.event_manager,
476522
};
477-
let pci_devices = PciDevices::restore(pci_ctor_args, &state.pci_state)?;
523+
let pci_devices = PciDevices::restore(pci_ctor_args, &state.pci_state)
524+
.map_err(DeviceManagerPersistError::PciRestore)?;
478525

479526
let device_manager = DeviceManager {
480527
mmio_devices,

0 commit comments

Comments
 (0)