From 88839026b9dae14b6465aa3b481e85634cca0000 Mon Sep 17 00:00:00 2001 From: "alex.lyn" Date: Wed, 27 Dec 2023 15:21:53 +0800 Subject: [PATCH] runtime-rs: introduce TopologyConfigInfo to initialize pcie topology A TopologyConfigInfo added to store device config info for PCIe/PCI devices in the VM from Hypervisor DeviceInfo. And TopologyConfigInfo::new will be the entry to initialize PCIe Topology for each VM. Fixes: #7218 Signed-off-by: alex.lyn --- .../kata-types/src/config/hypervisor/mod.rs | 32 +++++++++++++++++++ 1 file changed, 32 insertions(+) diff --git a/src/libs/kata-types/src/config/hypervisor/mod.rs b/src/libs/kata-types/src/config/hypervisor/mod.rs index d00d2533db..b571e26c6f 100644 --- a/src/libs/kata-types/src/config/hypervisor/mod.rs +++ b/src/libs/kata-types/src/config/hypervisor/mod.rs @@ -492,6 +492,38 @@ impl DeviceInfo { } } +/// Virtual machine PCIe Topology configuration. +#[derive(Clone, Debug, Default)] +pub struct TopologyConfigInfo { + /// Hypervisor name + pub hypervisor_name: String, + /// Device Info + pub device_info: DeviceInfo, +} + +impl TopologyConfigInfo { + /// Initialize the topology config info from toml config + pub fn new(toml_config: &TomlConfig) -> Option { + // Firecracker does not support PCIe Devices, so we should not initialize such a PCIe topology for it. + // If the case of fc hit, just return None. + let hypervisor_names = [ + HYPERVISOR_NAME_QEMU, + HYPERVISOR_NAME_CH, + HYPERVISOR_NAME_DRAGONBALL, + ]; + let hypervisor_name = toml_config.runtime.hypervisor_name.as_str(); + if !hypervisor_names.contains(&hypervisor_name) { + return None; + } + + let hv = toml_config.hypervisor.get(hypervisor_name)?; + Some(Self { + hypervisor_name: hypervisor_name.to_string(), + device_info: hv.device_info.clone(), + }) + } +} + /// Configuration information for virtual machine. #[derive(Clone, Debug, Default, Deserialize, Serialize)] pub struct MachineInfo {