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 <robert.bradford@intel.com>
This commit is contained in:
Rob Bradford 2021-10-26 11:19:01 +01:00
parent bad26133cb
commit 1a5a89508b
2 changed files with 6 additions and 24 deletions

View File

@ -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<Mutex<dyn Migratable>>);
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);

View File

@ -16,7 +16,6 @@ pub struct DeviceNode {
pub children: Vec<String>,
#[serde(skip)]
pub migratable: Option<Arc<Mutex<dyn Migratable>>>,
pub pci_segment_id: Option<u16>,
pub pci_bdf: Option<u32>,
#[serde(skip)]
pub pci_device_handle: Option<PciDeviceHandle>,
@ -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<DeviceNode> {
pub fn remove_node_by_pci_bdf(&mut self, pci_bdf: u32) -> Option<DeviceNode> {
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;
}