mirror of
https://github.com/kata-containers/kata-containers.git
synced 2025-09-03 01:44:29 +00:00
runtime-rs: Prepare pcie port devices before start sandbox
Prepare pcie port devices before starting VM with the help of device manager and PCIe Topology. Fixes #10361 Signed-off-by: alex.lyn <alex.lyn@antgroup.com>
This commit is contained in:
@@ -4,6 +4,7 @@
|
|||||||
// SPDX-License-Identifier: Apache-2.0
|
// SPDX-License-Identifier: Apache-2.0
|
||||||
//
|
//
|
||||||
|
|
||||||
|
use crate::health_check::HealthCheck;
|
||||||
use agent::kata::KataAgent;
|
use agent::kata::KataAgent;
|
||||||
use agent::types::KernelModule;
|
use agent::types::KernelModule;
|
||||||
use agent::{
|
use agent::{
|
||||||
@@ -20,6 +21,7 @@ use common::{
|
|||||||
};
|
};
|
||||||
|
|
||||||
use containerd_shim_protos::events::task::{TaskExit, TaskOOM};
|
use containerd_shim_protos::events::task::{TaskExit, TaskOOM};
|
||||||
|
use hypervisor::PortDeviceConfig;
|
||||||
use hypervisor::VsockConfig;
|
use hypervisor::VsockConfig;
|
||||||
use hypervisor::HYPERVISOR_FIRECRACKER;
|
use hypervisor::HYPERVISOR_FIRECRACKER;
|
||||||
use hypervisor::HYPERVISOR_REMOTE;
|
use hypervisor::HYPERVISOR_REMOTE;
|
||||||
@@ -47,8 +49,6 @@ use strum::Display;
|
|||||||
use tokio::sync::{mpsc::Sender, Mutex, RwLock};
|
use tokio::sync::{mpsc::Sender, Mutex, RwLock};
|
||||||
use tracing::instrument;
|
use tracing::instrument;
|
||||||
|
|
||||||
use crate::health_check::HealthCheck;
|
|
||||||
|
|
||||||
pub(crate) const VIRTCONTAINER: &str = "virt_container";
|
pub(crate) const VIRTCONTAINER: &str = "virt_container";
|
||||||
|
|
||||||
pub struct SandboxRestoreArgs {
|
pub struct SandboxRestoreArgs {
|
||||||
@@ -166,9 +166,42 @@ impl VirtSandbox {
|
|||||||
resource_configs.push(ResourceConfig::Protection(protection_dev_config));
|
resource_configs.push(ResourceConfig::Protection(protection_dev_config));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// prepare pcie port device config
|
||||||
|
if let Some(port_dev_config) = self.prepare_pcie_port_devices().await {
|
||||||
|
resource_configs.push(ResourceConfig::PortDevice(port_dev_config));
|
||||||
|
}
|
||||||
|
|
||||||
Ok(resource_configs)
|
Ok(resource_configs)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
async fn prepare_pcie_port_devices(&self) -> Option<PortDeviceConfig> {
|
||||||
|
// Fetch the device manager and read the PCIe topology
|
||||||
|
let device_manager = self.resource_manager.get_device_manager().await;
|
||||||
|
let dm = device_manager.read().await;
|
||||||
|
|
||||||
|
// Get the PCIe topology and port information
|
||||||
|
match dm.get_pcie_topology().and_then(|t| t.get_pcie_port()) {
|
||||||
|
Some((port_type, total_ports)) if total_ports > 0 => {
|
||||||
|
info!(
|
||||||
|
sl!(),
|
||||||
|
"Preparing PCIe {:?} with {} devices for VM.", port_type, total_ports
|
||||||
|
);
|
||||||
|
Some(PortDeviceConfig::new(port_type, total_ports))
|
||||||
|
}
|
||||||
|
Some((_, 0)) => {
|
||||||
|
info!(sl!(), "No PCIe ports available for VM.");
|
||||||
|
None
|
||||||
|
}
|
||||||
|
_ => {
|
||||||
|
info!(
|
||||||
|
sl!(),
|
||||||
|
"Invalid PCIe configuration or no topology available."
|
||||||
|
);
|
||||||
|
None
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
async fn prepare_network_resource(
|
async fn prepare_network_resource(
|
||||||
&self,
|
&self,
|
||||||
network_env: &SandboxNetworkEnv,
|
network_env: &SandboxNetworkEnv,
|
||||||
|
Reference in New Issue
Block a user