Skip to content

Commit 2dedce1

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 b86b9f4 commit 2dedce1

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
@@ -265,6 +265,8 @@ pub struct DevicesState {
265265
pub mmio_state: persist::DeviceStates,
266266
/// ACPI devices state
267267
pub acpi_state: persist::ACPIDeviceManagerState,
268+
/// PCI devices state
269+
pub pci_state: pci_mngr::PciDevicesState,
268270
}
269271

270272
#[derive(Debug, thiserror::Error, displaydoc::Display)]
@@ -273,6 +275,8 @@ pub enum DevicePersistError {
273275
MmioRestore(#[from] persist::DevicePersistError),
274276
/// Error restoring ACPI devices: {0}
275277
AcpiRestore(#[from] persist::ACPIDeviceManagerRestoreError),
278+
/// Error restoring PCI devices: {0}
279+
PciRestore(#[from] PciManagerError),
276280
/// Error notifying VMGenID device: {0}
277281
VmGenidUpdate(#[from] std::io::Error),
278282
/// Error resetting serial console: {0}
@@ -295,6 +299,7 @@ impl DeviceManager {
295299
DevicesState {
296300
mmio_state: self.mmio_devices.save(),
297301
acpi_state: self.acpi_devices.save(),
302+
pci_state: self.pci_devices.save(),
298303
}
299304
}
300305

@@ -366,6 +371,10 @@ impl DeviceManager {
366371
self.acpi_devices = ACPIDeviceManager::restore(acpi_ctor_args, &state.acpi_state)?;
367372
self.acpi_devices.notify_vmgenid()?;
368373

374+
// Restore PCI devices
375+
self.pci_devices
376+
.restore(&state.pci_state, &self.resource_allocator)?;
377+
369378
Ok(())
370379
}
371380
}

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;
@@ -42,4 +43,27 @@ impl PciDevices {
4243

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

0 commit comments

Comments
 (0)