mirror of
https://github.com/kata-containers/kata-containers.git
synced 2025-07-20 10:20:39 +00:00
runtime-rs: initialize pcie topology in Device Manager
Add a pcie_topology field to DeviceManager and initialize pcie_topology when ResourceManager calls DeviceManager's new() with TopologyConfigInfo. Fixes: #7218 Signed-off-by: alex.lyn <alex.lyn@antgroup.com>
This commit is contained in:
parent
b42548b8e1
commit
ea69c17008
@ -8,6 +8,7 @@ use std::{collections::HashMap, sync::Arc};
|
|||||||
|
|
||||||
use anyhow::{anyhow, Context, Result};
|
use anyhow::{anyhow, Context, Result};
|
||||||
use kata_sys_util::rand::RandomBytes;
|
use kata_sys_util::rand::RandomBytes;
|
||||||
|
use kata_types::config::hypervisor::TopologyConfigInfo;
|
||||||
use tokio::sync::{Mutex, RwLock};
|
use tokio::sync::{Mutex, RwLock};
|
||||||
|
|
||||||
use crate::{
|
use crate::{
|
||||||
@ -94,15 +95,20 @@ pub struct DeviceManager {
|
|||||||
devices: HashMap<String, ArcMutexDevice>,
|
devices: HashMap<String, ArcMutexDevice>,
|
||||||
hypervisor: Arc<dyn Hypervisor>,
|
hypervisor: Arc<dyn Hypervisor>,
|
||||||
shared_info: SharedInfo,
|
shared_info: SharedInfo,
|
||||||
|
pcie_topology: Option<PCIeTopology>,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl DeviceManager {
|
impl DeviceManager {
|
||||||
pub async fn new(hypervisor: Arc<dyn Hypervisor>) -> Result<Self> {
|
pub async fn new(
|
||||||
|
hypervisor: Arc<dyn Hypervisor>,
|
||||||
|
topo_config: Option<&TopologyConfigInfo>,
|
||||||
|
) -> Result<Self> {
|
||||||
let devices = HashMap::<String, ArcMutexDevice>::new();
|
let devices = HashMap::<String, ArcMutexDevice>::new();
|
||||||
Ok(DeviceManager {
|
Ok(DeviceManager {
|
||||||
devices,
|
devices,
|
||||||
hypervisor,
|
hypervisor,
|
||||||
shared_info: SharedInfo::new().await,
|
shared_info: SharedInfo::new().await,
|
||||||
|
pcie_topology: PCIeTopology::new(topo_config),
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -120,10 +126,11 @@ impl DeviceManager {
|
|||||||
.devices
|
.devices
|
||||||
.get(device_id)
|
.get(device_id)
|
||||||
.context("failed to find device")?;
|
.context("failed to find device")?;
|
||||||
|
|
||||||
let mut device_guard = device.lock().await;
|
let mut device_guard = device.lock().await;
|
||||||
// attach device
|
// attach device
|
||||||
let result = device_guard
|
let result = device_guard
|
||||||
.attach(&mut None::<&mut PCIeTopology>, self.hypervisor.as_ref())
|
.attach(&mut self.pcie_topology.as_mut(), self.hypervisor.as_ref())
|
||||||
.await;
|
.await;
|
||||||
// handle attach error
|
// handle attach error
|
||||||
if let Err(e) = result {
|
if let Err(e) = result {
|
||||||
@ -165,7 +172,7 @@ impl DeviceManager {
|
|||||||
if let Some(dev) = self.devices.get(device_id) {
|
if let Some(dev) = self.devices.get(device_id) {
|
||||||
let mut device_guard = dev.lock().await;
|
let mut device_guard = dev.lock().await;
|
||||||
let result = match device_guard
|
let result = match device_guard
|
||||||
.detach(&mut None::<&mut PCIeTopology>, self.hypervisor.as_ref())
|
.detach(&mut self.pcie_topology.as_mut(), self.hypervisor.as_ref())
|
||||||
.await
|
.await
|
||||||
{
|
{
|
||||||
Ok(index) => {
|
Ok(index) => {
|
||||||
@ -605,6 +612,7 @@ mod tests {
|
|||||||
BlockConfig, KATA_BLK_DEV_TYPE,
|
BlockConfig, KATA_BLK_DEV_TYPE,
|
||||||
};
|
};
|
||||||
use anyhow::{anyhow, Context, Result};
|
use anyhow::{anyhow, Context, Result};
|
||||||
|
use kata_types::config::hypervisor::TopologyConfigInfo;
|
||||||
use std::sync::Arc;
|
use std::sync::Arc;
|
||||||
use tests_utils::load_test_config;
|
use tests_utils::load_test_config;
|
||||||
use tokio::sync::RwLock;
|
use tokio::sync::RwLock;
|
||||||
@ -612,6 +620,7 @@ mod tests {
|
|||||||
async fn new_device_manager() -> Result<Arc<RwLock<DeviceManager>>> {
|
async fn new_device_manager() -> Result<Arc<RwLock<DeviceManager>>> {
|
||||||
let hypervisor_name: &str = "qemu";
|
let hypervisor_name: &str = "qemu";
|
||||||
let toml_config = load_test_config(hypervisor_name.to_owned())?;
|
let toml_config = load_test_config(hypervisor_name.to_owned())?;
|
||||||
|
let topo_config = TopologyConfigInfo::new(&toml_config);
|
||||||
let hypervisor_config = toml_config
|
let hypervisor_config = toml_config
|
||||||
.hypervisor
|
.hypervisor
|
||||||
.get(hypervisor_name)
|
.get(hypervisor_name)
|
||||||
@ -623,7 +632,7 @@ mod tests {
|
|||||||
.await;
|
.await;
|
||||||
|
|
||||||
let dm = Arc::new(RwLock::new(
|
let dm = Arc::new(RwLock::new(
|
||||||
DeviceManager::new(Arc::new(hypervisor))
|
DeviceManager::new(Arc::new(hypervisor), topo_config.as_ref())
|
||||||
.await
|
.await
|
||||||
.context("device manager")?,
|
.context("device manager")?,
|
||||||
));
|
));
|
||||||
|
@ -17,7 +17,7 @@ use hypervisor::{
|
|||||||
},
|
},
|
||||||
BlockConfig, Hypervisor, VfioConfig,
|
BlockConfig, Hypervisor, VfioConfig,
|
||||||
};
|
};
|
||||||
use kata_types::config::TomlConfig;
|
use kata_types::config::{hypervisor::TopologyConfigInfo, TomlConfig};
|
||||||
use kata_types::mount::Mount;
|
use kata_types::mount::Mount;
|
||||||
use oci::{Linux, LinuxCpu, LinuxResources};
|
use oci::{Linux, LinuxCpu, LinuxResources};
|
||||||
use persist::sandbox_persist::Persist;
|
use persist::sandbox_persist::Persist;
|
||||||
@ -59,8 +59,9 @@ impl ResourceManagerInner {
|
|||||||
toml_config: Arc<TomlConfig>,
|
toml_config: Arc<TomlConfig>,
|
||||||
init_size_manager: InitialSizeManager,
|
init_size_manager: InitialSizeManager,
|
||||||
) -> Result<Self> {
|
) -> Result<Self> {
|
||||||
|
let topo_config = TopologyConfigInfo::new(&toml_config);
|
||||||
// create device manager
|
// create device manager
|
||||||
let dev_manager = DeviceManager::new(hypervisor.clone())
|
let dev_manager = DeviceManager::new(hypervisor.clone(), topo_config.as_ref())
|
||||||
.await
|
.await
|
||||||
.context("failed to create device manager")?;
|
.context("failed to create device manager")?;
|
||||||
|
|
||||||
@ -510,12 +511,14 @@ impl Persist for ResourceManagerInner {
|
|||||||
sid: resource_args.sid.clone(),
|
sid: resource_args.sid.clone(),
|
||||||
config: resource_args.config,
|
config: resource_args.config,
|
||||||
};
|
};
|
||||||
|
let topo_config = TopologyConfigInfo::new(&args.config);
|
||||||
|
|
||||||
Ok(Self {
|
Ok(Self {
|
||||||
sid: resource_args.sid,
|
sid: resource_args.sid,
|
||||||
agent: resource_args.agent,
|
agent: resource_args.agent,
|
||||||
hypervisor: resource_args.hypervisor.clone(),
|
hypervisor: resource_args.hypervisor.clone(),
|
||||||
device_manager: Arc::new(RwLock::new(
|
device_manager: Arc::new(RwLock::new(
|
||||||
DeviceManager::new(resource_args.hypervisor).await?,
|
DeviceManager::new(resource_args.hypervisor, topo_config.as_ref()).await?,
|
||||||
)),
|
)),
|
||||||
network: None,
|
network: None,
|
||||||
share_fs: None,
|
share_fs: None,
|
||||||
|
@ -9,6 +9,7 @@ mod tests {
|
|||||||
use std::sync::Arc;
|
use std::sync::Arc;
|
||||||
|
|
||||||
use anyhow::{anyhow, Context, Result};
|
use anyhow::{anyhow, Context, Result};
|
||||||
|
use kata_types::config::hypervisor::TopologyConfigInfo;
|
||||||
use netlink_packet_route::MACVLAN_MODE_PRIVATE;
|
use netlink_packet_route::MACVLAN_MODE_PRIVATE;
|
||||||
use scopeguard::defer;
|
use scopeguard::defer;
|
||||||
use tests_utils::load_test_config;
|
use tests_utils::load_test_config;
|
||||||
@ -29,6 +30,7 @@ mod tests {
|
|||||||
async fn get_device_manager() -> Result<Arc<RwLock<DeviceManager>>> {
|
async fn get_device_manager() -> Result<Arc<RwLock<DeviceManager>>> {
|
||||||
let hypervisor_name: &str = "qemu";
|
let hypervisor_name: &str = "qemu";
|
||||||
let toml_config = load_test_config(hypervisor_name.to_owned())?;
|
let toml_config = load_test_config(hypervisor_name.to_owned())?;
|
||||||
|
let topo_config = TopologyConfigInfo::new(&toml_config);
|
||||||
let hypervisor_config = toml_config
|
let hypervisor_config = toml_config
|
||||||
.hypervisor
|
.hypervisor
|
||||||
.get(hypervisor_name)
|
.get(hypervisor_name)
|
||||||
@ -40,7 +42,7 @@ mod tests {
|
|||||||
.await;
|
.await;
|
||||||
|
|
||||||
let dm = Arc::new(RwLock::new(
|
let dm = Arc::new(RwLock::new(
|
||||||
DeviceManager::new(Arc::new(hypervisor))
|
DeviceManager::new(Arc::new(hypervisor), topo_config.as_ref())
|
||||||
.await
|
.await
|
||||||
.context("device manager")?,
|
.context("device manager")?,
|
||||||
));
|
));
|
||||||
|
Loading…
Reference in New Issue
Block a user