From 7fec020f53943b8b8c3df8fc6bc6739aff0df0f9 Mon Sep 17 00:00:00 2001 From: Sebastien Boeuf Date: Thu, 30 Apr 2020 19:10:31 +0200 Subject: [PATCH] vmm: Create a dedicated DeviceTree structure In order to hide the complexity chosen for the device tree stored in the DeviceManager, we introduce a new DeviceTree structure. For now, this structure is a simple passthrough of a HashMap, but it can be extended to handle some DeviceTree specific operations. Signed-off-by: Sebastien Boeuf --- vmm/src/device_manager.rs | 31 ++++++++++++++++++++++++++++--- 1 file changed, 28 insertions(+), 3 deletions(-) diff --git a/vmm/src/device_manager.rs b/vmm/src/device_manager.rs index 59a2e3a6e..90c651513 100644 --- a/vmm/src/device_manager.rs +++ b/vmm/src/device_manager.rs @@ -578,9 +578,34 @@ impl DeviceNode { } } +#[derive(Clone, Serialize, Deserialize)] +struct DeviceTree(HashMap); + +impl DeviceTree { + fn new() -> Self { + DeviceTree(HashMap::new()) + } + fn get(&self, k: &str) -> Option<&DeviceNode> { + self.0.get(k) + } + fn get_mut(&mut self, k: &str) -> Option<&mut DeviceNode> { + self.0.get_mut(k) + } + fn insert(&mut self, k: String, v: DeviceNode) -> Option { + self.0.insert(k, v) + } + #[cfg(feature = "pci_support")] + fn remove(&mut self, k: &str) -> Option { + self.0.remove(k) + } + fn iter(&self) -> std::collections::hash_map::Iter { + self.0.iter() + } +} + #[derive(Serialize, Deserialize)] struct DeviceManagerState { - device_tree: HashMap, + device_tree: DeviceTree, device_id_cnt: Wrapping, } @@ -661,7 +686,7 @@ pub struct DeviceManager { // Tree of devices, representing the dependencies between devices. // Useful for introspection, snapshot and restore. - device_tree: HashMap, + device_tree: DeviceTree, // Exit event #[cfg(feature = "acpi")] @@ -736,7 +761,7 @@ impl DeviceManager { pci_id_list: HashMap::new(), #[cfg(feature = "pci_support")] pci_devices: HashMap::new(), - device_tree: HashMap::new(), + device_tree: DeviceTree::new(), #[cfg(feature = "acpi")] exit_evt: _exit_evt.try_clone().map_err(DeviceManagerError::EventFd)?, reset_evt: reset_evt.try_clone().map_err(DeviceManagerError::EventFd)?,