vmm: Device name verification based on DeviceTree

Instead of relying on a PCI specific device list, we use the DeviceTree
as a reference to determine if a device name is already in use or not.

Signed-off-by: Sebastien Boeuf <sebastien.boeuf@intel.com>
This commit is contained in:
Sebastien Boeuf 2021-03-17 13:19:24 +01:00
parent 13724dbd22
commit 62aaccee28
2 changed files with 5 additions and 5 deletions

View File

@ -2741,7 +2741,7 @@ impl DeviceManager {
// Increment the counter. // Increment the counter.
self.device_id_cnt += Wrapping(1); self.device_id_cnt += Wrapping(1);
// Check if the name is already in use. // Check if the name is already in use.
if !self.pci_id_list.contains_key(&name) { if !self.device_tree.lock().unwrap().contains_key(&name) {
return Ok(name); return Ok(name);
} }
@ -2864,7 +2864,7 @@ impl DeviceManager {
.map_err(DeviceManagerError::VfioPciCreate)?; .map_err(DeviceManagerError::VfioPciCreate)?;
let vfio_name = if let Some(id) = &device_cfg.id { let vfio_name = if let Some(id) = &device_cfg.id {
if self.pci_id_list.contains_key(id) { if self.device_tree.lock().unwrap().contains_key(id) {
return Err(DeviceManagerError::DeviceIdAlreadyInUse); return Err(DeviceManagerError::DeviceIdAlreadyInUse);
} }
@ -2955,9 +2955,6 @@ impl DeviceManager {
) )
.map_err(DeviceManagerError::AddPciDevice)?; .map_err(DeviceManagerError::AddPciDevice)?;
if self.pci_id_list.contains_key(&device_id) {
return Err(DeviceManagerError::DeviceIdAlreadyInUse);
}
self.pci_id_list.insert(device_id, bdf); self.pci_id_list.insert(device_id, bdf);
Ok(bars) Ok(bars)
} }

View File

@ -51,6 +51,9 @@ impl DeviceTree {
pub fn new() -> Self { pub fn new() -> Self {
DeviceTree(HashMap::new()) DeviceTree(HashMap::new())
} }
pub fn contains_key(&self, k: &str) -> bool {
self.0.contains_key(k)
}
pub fn get(&self, k: &str) -> Option<&DeviceNode> { pub fn get(&self, k: &str) -> Option<&DeviceNode> {
self.0.get(k) self.0.get(k)
} }