mirror of
https://github.com/cloud-hypervisor/cloud-hypervisor.git
synced 2026-08-05 02:19:16 +00:00
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 <sebastien.boeuf@intel.com>
This commit is contained in:
@@ -578,9 +578,34 @@ impl DeviceNode {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[derive(Clone, Serialize, Deserialize)]
|
||||||
|
struct DeviceTree(HashMap<String, DeviceNode>);
|
||||||
|
|
||||||
|
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<DeviceNode> {
|
||||||
|
self.0.insert(k, v)
|
||||||
|
}
|
||||||
|
#[cfg(feature = "pci_support")]
|
||||||
|
fn remove(&mut self, k: &str) -> Option<DeviceNode> {
|
||||||
|
self.0.remove(k)
|
||||||
|
}
|
||||||
|
fn iter(&self) -> std::collections::hash_map::Iter<String, DeviceNode> {
|
||||||
|
self.0.iter()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
#[derive(Serialize, Deserialize)]
|
#[derive(Serialize, Deserialize)]
|
||||||
struct DeviceManagerState {
|
struct DeviceManagerState {
|
||||||
device_tree: HashMap<String, DeviceNode>,
|
device_tree: DeviceTree,
|
||||||
device_id_cnt: Wrapping<usize>,
|
device_id_cnt: Wrapping<usize>,
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -661,7 +686,7 @@ pub struct DeviceManager {
|
|||||||
|
|
||||||
// Tree of devices, representing the dependencies between devices.
|
// Tree of devices, representing the dependencies between devices.
|
||||||
// Useful for introspection, snapshot and restore.
|
// Useful for introspection, snapshot and restore.
|
||||||
device_tree: HashMap<String, DeviceNode>,
|
device_tree: DeviceTree,
|
||||||
|
|
||||||
// Exit event
|
// Exit event
|
||||||
#[cfg(feature = "acpi")]
|
#[cfg(feature = "acpi")]
|
||||||
@@ -736,7 +761,7 @@ impl DeviceManager {
|
|||||||
pci_id_list: HashMap::new(),
|
pci_id_list: HashMap::new(),
|
||||||
#[cfg(feature = "pci_support")]
|
#[cfg(feature = "pci_support")]
|
||||||
pci_devices: HashMap::new(),
|
pci_devices: HashMap::new(),
|
||||||
device_tree: HashMap::new(),
|
device_tree: DeviceTree::new(),
|
||||||
#[cfg(feature = "acpi")]
|
#[cfg(feature = "acpi")]
|
||||||
exit_evt: _exit_evt.try_clone().map_err(DeviceManagerError::EventFd)?,
|
exit_evt: _exit_evt.try_clone().map_err(DeviceManagerError::EventFd)?,
|
||||||
reset_evt: reset_evt.try_clone().map_err(DeviceManagerError::EventFd)?,
|
reset_evt: reset_evt.try_clone().map_err(DeviceManagerError::EventFd)?,
|
||||||
|
|||||||
Reference in New Issue
Block a user