@@ -31,11 +31,20 @@ use crate::devices::legacy::RTCDevice;
3131use crate :: devices:: legacy:: serial:: SerialOut ;
3232use crate :: devices:: legacy:: { IER_RDA_BIT , IER_RDA_OFFSET , SerialDevice } ;
3333use crate :: devices:: pseudo:: BootTimer ;
34+ use crate :: devices:: virtio:: ActivateError ;
35+ use crate :: devices:: virtio:: balloon:: BalloonError ;
36+ use crate :: devices:: virtio:: block:: BlockError ;
3437use 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 ;
3542use crate :: devices:: virtio:: transport:: mmio:: { IrqTrigger , MmioTransport } ;
43+ use crate :: devices:: virtio:: vsock:: { VsockError , VsockUnixBackendError } ;
3644use crate :: resources:: VmResources ;
3745use crate :: snapshot:: Persist ;
3846use crate :: utils:: open_file_write_nonblock;
47+ use crate :: vmm_config:: mmds:: MmdsConfigError ;
3948use crate :: vstate:: bus:: BusError ;
4049use crate :: vstate:: memory:: GuestMemoryMmap ;
4150use 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 ) ]
393403pub 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<'_> {
430475impl < ' 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