From 1a5a89508b9a03a5546f2fa78d55204e7734b528 Mon Sep 17 00:00:00 2001 From: Rob Bradford Date: Tue, 26 Oct 2021 11:19:01 +0100 Subject: [PATCH] vmm: Remove segment_id from DeviceNode With the segment id now encoded in the bdf it is not necessary to have the separate field for it. Signed-off-by: Rob Bradford --- vmm/src/device_manager.rs | 16 +++------------- vmm/src/device_tree.rs | 14 +++----------- 2 files changed, 6 insertions(+), 24 deletions(-) diff --git a/vmm/src/device_manager.rs b/vmm/src/device_manager.rs index 29117757a..66c4cb32a 100644 --- a/vmm/src/device_manager.rs +++ b/vmm/src/device_manager.rs @@ -400,9 +400,6 @@ pub enum DeviceManagerError { /// Missing PCI b/d/f from the DeviceNode. MissingDeviceNodePciBdf, - /// Missing PCI segment id from the DeviceNode. - MissingDeviceNodePciSegmentId, - /// No support for device passthrough NoDevicePassthroughSupport, @@ -3019,7 +3016,6 @@ impl DeviceManager { } node.pci_bdf = Some(pci_device_bdf.into()); - node.pci_segment_id = Some(pci_segment_id); node.pci_device_handle = Some(PciDeviceHandle::Vfio(vfio_pci_device)); self.device_tree @@ -3178,7 +3174,6 @@ impl DeviceManager { let mut node = device_node!(vfio_user_name); node.pci_bdf = Some(pci_device_bdf.into()); - node.pci_segment_id = Some(pci_segment_id); node.pci_device_handle = Some(PciDeviceHandle::VfioUser(vfio_user_pci_device)); self.device_tree @@ -3227,9 +3222,7 @@ impl DeviceManager { .pci_bdf .ok_or(DeviceManagerError::MissingDeviceNodePciBdf)? .into(); - let pci_segment_id = node - .pci_segment_id - .ok_or(DeviceManagerError::MissingDeviceNodePciSegmentId)?; + let pci_segment_id = pci_device_bdf.segment(); self.pci_segments[pci_segment_id as usize] .pci_bus @@ -3337,7 +3330,6 @@ impl DeviceManager { } node.migratable = Some(Arc::clone(&virtio_pci_device) as Arc>); node.pci_bdf = Some(pci_device_bdf.into()); - node.pci_segment_id = Some(pci_segment_id); node.pci_device_handle = Some(PciDeviceHandle::Virtio(virtio_pci_device)); self.device_tree.lock().unwrap().insert(id, node); @@ -3516,9 +3508,7 @@ impl DeviceManager { .pci_bdf .ok_or(DeviceManagerError::MissingDeviceNodePciBdf)? .into(); - let pci_segment_id = pci_device_node - .pci_segment_id - .ok_or(DeviceManagerError::MissingDeviceNodePciSegmentId)?; + let pci_segment_id = pci_device_bdf.segment(); let pci_device_handle = pci_device_node .pci_device_handle @@ -3571,7 +3561,7 @@ impl DeviceManager { // Remove the device from the device tree along with its children. let mut device_tree = self.device_tree.lock().unwrap(); let pci_device_node = device_tree - .remove_node_by_pci_bdf(pci_segment_id, pci_device_bdf.into()) + .remove_node_by_pci_bdf(pci_device_bdf.into()) .ok_or(DeviceManagerError::MissingPciDevice)?; for child in pci_device_node.children.iter() { device_tree.remove(child); diff --git a/vmm/src/device_tree.rs b/vmm/src/device_tree.rs index 45ec319b5..77ce12a45 100644 --- a/vmm/src/device_tree.rs +++ b/vmm/src/device_tree.rs @@ -16,7 +16,6 @@ pub struct DeviceNode { pub children: Vec, #[serde(skip)] pub migratable: Option>>, - pub pci_segment_id: Option, pub pci_bdf: Option, #[serde(skip)] pub pci_device_handle: Option, @@ -32,7 +31,6 @@ impl DeviceNode { migratable, pci_bdf: None, pci_device_handle: None, - pci_segment_id: None, } } } @@ -81,20 +79,14 @@ impl DeviceTree { pub fn pci_devices(&self) -> Vec<&DeviceNode> { self.0 .values() - .filter(|v| { - v.pci_bdf.is_some() && v.pci_segment_id.is_some() && v.pci_device_handle.is_some() - }) + .filter(|v| v.pci_bdf.is_some() && v.pci_device_handle.is_some()) .collect() } - pub fn remove_node_by_pci_bdf( - &mut self, - pci_segment_id: u16, - pci_bdf: u32, - ) -> Option { + pub fn remove_node_by_pci_bdf(&mut self, pci_bdf: u32) -> Option { let mut id = None; for (k, v) in self.0.iter() { - if v.pci_segment_id == Some(pci_segment_id) && v.pci_bdf == Some(pci_bdf) { + if v.pci_bdf == Some(pci_bdf) { id = Some(k.clone()); break; }