mirror of
https://github.com/cloud-hypervisor/cloud-hypervisor.git
synced 2025-01-22 20:45:21 +00:00
vmm: Remove the list of migratable devices
Now that the device tree fully replaced the need for a dedicated list of migratable devices, this commit cleans up the codebase by removing it from the DeviceManager. Signed-off-by: Sebastien Boeuf <sebastien.boeuf@intel.com>
This commit is contained in:
parent
1be7037229
commit
b91ab1e3a5
@ -632,9 +632,6 @@ pub struct DeviceManager {
|
||||
// VM configuration
|
||||
config: Arc<Mutex<VmConfig>>,
|
||||
|
||||
// Migratable devices
|
||||
migratable_devices: HashMap<String, Arc<Mutex<dyn Migratable>>>,
|
||||
|
||||
// Memory Manager
|
||||
memory_manager: Arc<Mutex<MemoryManager>>,
|
||||
|
||||
@ -742,7 +739,6 @@ impl DeviceManager {
|
||||
#[cfg(feature = "acpi")]
|
||||
ged_notification_device: None,
|
||||
config,
|
||||
migratable_devices: HashMap::new(),
|
||||
memory_manager,
|
||||
virtio_devices: Vec::new(),
|
||||
bus_devices: Vec::new(),
|
||||
@ -871,11 +867,6 @@ impl DeviceManager {
|
||||
Ok(())
|
||||
}
|
||||
|
||||
fn add_migratable_device(&mut self, migratable_device: Arc<Mutex<dyn Migratable>>) {
|
||||
let id = migratable_device.lock().unwrap().id();
|
||||
self.migratable_devices.insert(id, migratable_device);
|
||||
}
|
||||
|
||||
#[allow(unused_variables)]
|
||||
fn add_pci_devices(
|
||||
&mut self,
|
||||
@ -1033,8 +1024,6 @@ impl DeviceManager {
|
||||
DeviceNode::new(id, Some(Arc::clone(&ioapic) as Arc<Mutex<dyn Migratable>>)),
|
||||
);
|
||||
|
||||
self.add_migratable_device(Arc::clone(&ioapic) as Arc<Mutex<dyn Migratable>>);
|
||||
|
||||
Ok(ioapic)
|
||||
}
|
||||
|
||||
@ -1211,8 +1200,6 @@ impl DeviceManager {
|
||||
DeviceNode::new(id, Some(Arc::clone(&serial) as Arc<Mutex<dyn Migratable>>)),
|
||||
);
|
||||
|
||||
self.add_migratable_device(Arc::clone(&serial) as Arc<Mutex<dyn Migratable>>);
|
||||
|
||||
Some(serial)
|
||||
} else {
|
||||
None
|
||||
@ -1254,8 +1241,6 @@ impl DeviceManager {
|
||||
),
|
||||
);
|
||||
|
||||
self.add_migratable_device(virtio_console_device as Arc<Mutex<dyn Migratable>>);
|
||||
|
||||
Some(console_input)
|
||||
} else {
|
||||
None
|
||||
@ -1363,10 +1348,6 @@ impl DeviceManager {
|
||||
),
|
||||
);
|
||||
|
||||
self.add_migratable_device(
|
||||
Arc::clone(&vhost_user_block_device) as Arc<Mutex<dyn Migratable>>
|
||||
);
|
||||
|
||||
Ok((
|
||||
Arc::clone(&vhost_user_block_device) as VirtioDeviceArc,
|
||||
false,
|
||||
@ -1424,8 +1405,6 @@ impl DeviceManager {
|
||||
),
|
||||
);
|
||||
|
||||
self.add_migratable_device(Arc::clone(&block) as Arc<Mutex<dyn Migratable>>);
|
||||
|
||||
Ok((Arc::clone(&block) as VirtioDeviceArc, disk_cfg.iommu, id))
|
||||
}
|
||||
ImageType::Qcow2 => {
|
||||
@ -1459,8 +1438,6 @@ impl DeviceManager {
|
||||
),
|
||||
);
|
||||
|
||||
self.add_migratable_device(Arc::clone(&block) as Arc<Mutex<dyn Migratable>>);
|
||||
|
||||
Ok((Arc::clone(&block) as VirtioDeviceArc, disk_cfg.iommu, id))
|
||||
}
|
||||
}
|
||||
@ -1547,9 +1524,6 @@ impl DeviceManager {
|
||||
),
|
||||
);
|
||||
|
||||
self.add_migratable_device(
|
||||
Arc::clone(&vhost_user_net_device) as Arc<Mutex<dyn Migratable>>
|
||||
);
|
||||
Ok((
|
||||
Arc::clone(&vhost_user_net_device) as VirtioDeviceArc,
|
||||
net_cfg.iommu,
|
||||
@ -1597,7 +1571,6 @@ impl DeviceManager {
|
||||
),
|
||||
);
|
||||
|
||||
self.add_migratable_device(Arc::clone(&virtio_net_device) as Arc<Mutex<dyn Migratable>>);
|
||||
Ok((
|
||||
Arc::clone(&virtio_net_device) as VirtioDeviceArc,
|
||||
net_cfg.iommu,
|
||||
@ -1652,10 +1625,6 @@ impl DeviceManager {
|
||||
Some(Arc::clone(&virtio_rng_device) as Arc<Mutex<dyn Migratable>>),
|
||||
),
|
||||
);
|
||||
|
||||
self.add_migratable_device(
|
||||
Arc::clone(&virtio_rng_device) as Arc<Mutex<dyn Migratable>>
|
||||
);
|
||||
}
|
||||
|
||||
Ok(devices)
|
||||
@ -1795,8 +1764,6 @@ impl DeviceManager {
|
||||
node.migratable = Some(Arc::clone(&virtio_fs_device) as Arc<Mutex<dyn Migratable>>);
|
||||
self.device_tree.insert(id.clone(), node);
|
||||
|
||||
self.add_migratable_device(Arc::clone(&virtio_fs_device) as Arc<Mutex<dyn Migratable>>);
|
||||
|
||||
Ok((Arc::clone(&virtio_fs_device) as VirtioDeviceArc, false, id))
|
||||
} else {
|
||||
Err(DeviceManagerError::NoVirtioFsSock)
|
||||
@ -1984,8 +1951,6 @@ impl DeviceManager {
|
||||
node.migratable = Some(Arc::clone(&virtio_pmem_device) as Arc<Mutex<dyn Migratable>>);
|
||||
self.device_tree.insert(id.clone(), node);
|
||||
|
||||
self.add_migratable_device(Arc::clone(&virtio_pmem_device) as Arc<Mutex<dyn Migratable>>);
|
||||
|
||||
Ok((
|
||||
Arc::clone(&virtio_pmem_device) as VirtioDeviceArc,
|
||||
pmem_cfg.iommu,
|
||||
@ -2051,8 +2016,6 @@ impl DeviceManager {
|
||||
),
|
||||
);
|
||||
|
||||
self.add_migratable_device(Arc::clone(&vsock_device) as Arc<Mutex<dyn Migratable>>);
|
||||
|
||||
Ok((
|
||||
Arc::clone(&vsock_device) as VirtioDeviceArc,
|
||||
vsock_cfg.iommu,
|
||||
@ -2111,8 +2074,6 @@ impl DeviceManager {
|
||||
Some(Arc::clone(&virtio_mem_device) as Arc<Mutex<dyn Migratable>>),
|
||||
),
|
||||
);
|
||||
|
||||
self.add_migratable_device(Arc::clone(&virtio_mem_device) as Arc<Mutex<dyn Migratable>>);
|
||||
}
|
||||
|
||||
Ok(devices)
|
||||
@ -2394,8 +2355,6 @@ impl DeviceManager {
|
||||
node.migratable = Some(Arc::clone(&virtio_pci_device) as Arc<Mutex<dyn Migratable>>);
|
||||
self.device_tree.insert(id, node);
|
||||
|
||||
self.add_migratable_device(Arc::clone(&virtio_pci_device) as Arc<Mutex<dyn Migratable>>);
|
||||
|
||||
Ok(pci_device_bdf)
|
||||
}
|
||||
|
||||
@ -2536,8 +2495,6 @@ impl DeviceManager {
|
||||
node.migratable = Some(Arc::clone(&mmio_device_arc) as Arc<Mutex<dyn Migratable>>);
|
||||
self.device_tree.insert(id, node);
|
||||
|
||||
self.add_migratable_device(Arc::clone(&mmio_device_arc) as Arc<Mutex<dyn Migratable>>);
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
||||
@ -2714,15 +2671,12 @@ impl DeviceManager {
|
||||
.map_err(DeviceManagerError::PutPciDeviceId)?;
|
||||
|
||||
if let Some(any_device) = self.pci_devices.remove(&pci_device_bdf) {
|
||||
let (pci_device, bus_device, migratable_device, virtio_device) = if let Ok(
|
||||
vfio_pci_device,
|
||||
) =
|
||||
let (pci_device, bus_device, virtio_device) = if let Ok(vfio_pci_device) =
|
||||
any_device.clone().downcast::<Mutex<VfioPciDevice>>()
|
||||
{
|
||||
(
|
||||
Arc::clone(&vfio_pci_device) as Arc<Mutex<dyn PciDevice>>,
|
||||
Arc::clone(&vfio_pci_device) as Arc<Mutex<dyn BusDevice>>,
|
||||
None as Option<Arc<Mutex<dyn Migratable>>>,
|
||||
None as Option<VirtioDeviceArc>,
|
||||
)
|
||||
} else if let Ok(virtio_pci_device) = any_device.downcast::<Mutex<VirtioPciDevice>>() {
|
||||
@ -2738,7 +2692,6 @@ impl DeviceManager {
|
||||
(
|
||||
Arc::clone(&virtio_pci_device) as Arc<Mutex<dyn PciDevice>>,
|
||||
Arc::clone(&virtio_pci_device) as Arc<Mutex<dyn BusDevice>>,
|
||||
Some(Arc::clone(&virtio_pci_device) as Arc<Mutex<dyn Migratable>>),
|
||||
Some(virtio_pci_device.lock().unwrap().virtio_device()),
|
||||
)
|
||||
} else {
|
||||
@ -2773,12 +2726,6 @@ impl DeviceManager {
|
||||
self.bus_devices
|
||||
.retain(|dev| !Arc::ptr_eq(dev, &bus_device));
|
||||
|
||||
// Remove the device from the list of Migratable devices.
|
||||
if let Some(migratable_device) = &migratable_device {
|
||||
let id = migratable_device.lock().unwrap().id();
|
||||
self.migratable_devices.retain(|i, _| *i != id);
|
||||
}
|
||||
|
||||
// Shutdown and remove the underlying virtio-device if present
|
||||
if let Some(virtio_device) = virtio_device {
|
||||
for mapping in virtio_device.lock().unwrap().userspace_mappings() {
|
||||
@ -3137,16 +3084,20 @@ impl Aml for DeviceManager {
|
||||
|
||||
impl Pausable for DeviceManager {
|
||||
fn pause(&mut self) -> result::Result<(), MigratableError> {
|
||||
for (_, dev) in self.migratable_devices.iter() {
|
||||
dev.lock().unwrap().pause()?;
|
||||
for (_, device_node) in self.device_tree.iter() {
|
||||
if let Some(migratable) = &device_node.migratable {
|
||||
migratable.lock().unwrap().pause()?;
|
||||
}
|
||||
}
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
||||
fn resume(&mut self) -> result::Result<(), MigratableError> {
|
||||
for (_, dev) in self.migratable_devices.iter() {
|
||||
dev.lock().unwrap().resume()?;
|
||||
for (_, device_node) in self.device_tree.iter() {
|
||||
if let Some(migratable) = &device_node.migratable {
|
||||
migratable.lock().unwrap().resume()?;
|
||||
}
|
||||
}
|
||||
|
||||
Ok(())
|
||||
|
Loading…
x
Reference in New Issue
Block a user