Skip to content

Commit 2930519

Browse files
committed
pci: add support for snapshotting PCI devices
At the moment, the logic just restores the device manager and add the PCIe root complex if PCI is enabled. Signed-off-by: Babis Chalios <[email protected]>
1 parent ce3ea28 commit 2930519

File tree

2 files changed

+33
-0
lines changed

2 files changed

+33
-0
lines changed

src/vmm/src/device_manager/mod.rs

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -279,6 +279,8 @@ pub struct DevicesState {
279279
pub mmio_state: persist::DeviceStates,
280280
/// ACPI devices state
281281
pub acpi_state: persist::ACPIDeviceManagerState,
282+
/// PCI devices state
283+
pub pci_state: pci_mngr::PciDevicesState,
282284
}
283285

284286
#[derive(Debug, thiserror::Error, displaydoc::Display)]
@@ -287,6 +289,8 @@ pub enum DevicePersistError {
287289
MmioRestore(#[from] persist::DevicePersistError),
288290
/// Error restoring ACPI devices: {0}
289291
AcpiRestore(#[from] persist::ACPIDeviceManagerRestoreError),
292+
/// Error restoring PCI devices: {0}
293+
PciRestore(#[from] PciManagerError),
290294
/// Error notifying VMGenID device: {0}
291295
VmGenidUpdate(#[from] std::io::Error),
292296
/// Error resetting serial console: {0}
@@ -309,6 +313,7 @@ impl DeviceManager {
309313
DevicesState {
310314
mmio_state: self.mmio_devices.save(),
311315
acpi_state: self.acpi_devices.save(),
316+
pci_state: self.pci_devices.save(),
312317
}
313318
}
314319

@@ -380,6 +385,10 @@ impl DeviceManager {
380385
self.acpi_devices = ACPIDeviceManager::restore(acpi_ctor_args, &state.acpi_state)?;
381386
self.acpi_devices.notify_vmgenid()?;
382387

388+
// Restore PCI devices
389+
self.pci_devices
390+
.restore(&state.pci_state, &self.resource_allocator)?;
391+
383392
Ok(())
384393
}
385394
}

src/vmm/src/device_manager/pci_mngr.rs

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33

44
use std::sync::Arc;
55

6+
use serde::{Deserialize, Serialize};
67
use vm_device::BusError;
78

89
use super::resources::ResourceAllocator;
@@ -46,4 +47,27 @@ impl PciDevices {
4647

4748
Ok(())
4849
}
50+
51+
pub fn save(&self) -> PciDevicesState {
52+
PciDevicesState {
53+
pci_enabled: self.pci_segment.is_some(),
54+
}
55+
}
56+
57+
pub fn restore(
58+
&mut self,
59+
state: &PciDevicesState,
60+
resource_allocator: &Arc<ResourceAllocator>,
61+
) -> Result<(), PciManagerError> {
62+
if state.pci_enabled {
63+
self.attach_pci_segment(resource_allocator)?;
64+
}
65+
66+
Ok(())
67+
}
68+
}
69+
70+
#[derive(Default, Debug, Clone, Serialize, Deserialize)]
71+
pub struct PciDevicesState {
72+
pci_enabled: bool,
4973
}

0 commit comments

Comments
 (0)