mirror of
https://github.com/kata-containers/kata-containers.git
synced 2025-08-12 13:22:28 +00:00
runtime-rs: add network device handler in start_vm.
Add network device handler in start_vm, which is sepcially for Qemu VM running with added net params to command line. Fixes: #8865 Signed-off-by: Alex Lyn <alex.lyn@antgroup.com>
This commit is contained in:
parent
9f6003adde
commit
69a5e5b955
@ -4,11 +4,12 @@
|
||||
//
|
||||
|
||||
use crate::utils::clear_fd_flags;
|
||||
use crate::{kernel_param::KernelParams, HypervisorConfig};
|
||||
use crate::{kernel_param::KernelParams, HypervisorConfig, NetworkConfig};
|
||||
|
||||
use anyhow::{anyhow, Context, Result};
|
||||
use async_trait::async_trait;
|
||||
use std::fs::read_to_string;
|
||||
use kata_types::config::hypervisor::NetworkInfo;
|
||||
use std::fs::{read_to_string, File};
|
||||
use std::os::unix::io::RawFd;
|
||||
|
||||
// These should have been called MiB and GiB for better readability but the
|
||||
@ -846,6 +847,18 @@ impl<'a> QemuCmdLine<'a> {
|
||||
));
|
||||
}
|
||||
|
||||
pub fn add_network_device(
|
||||
&mut self,
|
||||
_config: &NetworkConfig,
|
||||
network_info: &NetworkInfo,
|
||||
) -> Result<Vec<File>> {
|
||||
let _disable_vhost_net = network_info.disable_vhost_net;
|
||||
let _queues = network_info.network_queues;
|
||||
let fds: Vec<std::fs::File> = Vec::new();
|
||||
|
||||
Ok(fds)
|
||||
}
|
||||
|
||||
pub async fn build(&self) -> Result<Vec<String>> {
|
||||
let mut result = Vec::new();
|
||||
|
||||
|
@ -5,11 +5,12 @@
|
||||
|
||||
use super::cmdline_generator::QemuCmdLine;
|
||||
use crate::{
|
||||
hypervisor_persist::HypervisorState, HypervisorConfig, MemoryConfig, VcpuThreadIds,
|
||||
VsockDevice, HYPERVISOR_QEMU,
|
||||
hypervisor_persist::HypervisorState, utils::enter_netns, HypervisorConfig, MemoryConfig,
|
||||
VcpuThreadIds, VsockDevice, HYPERVISOR_QEMU,
|
||||
};
|
||||
use anyhow::{anyhow, Context, Result};
|
||||
use async_trait::async_trait;
|
||||
use kata_sys_util::netns::NetnsGuard;
|
||||
use kata_types::{
|
||||
capabilities::{Capabilities, CapabilityBits},
|
||||
config::KATA_PATH,
|
||||
@ -68,6 +69,10 @@ impl QemuInner {
|
||||
// descriptor needs to stay open until the qemu process launches.
|
||||
// This is why we need to store it in a variable at this scope.
|
||||
let mut _vhost_fd = None;
|
||||
// We need to keep the vhost-net/tuntap file descriptor open until the QEMU process launches.
|
||||
// However, we're likely not interested in the specific type of file descriptor itself. We just
|
||||
// want to ensure any fds associated with network devices remain open within the current scope.
|
||||
let mut _fds_for_qemu: Vec<std::fs::File> = Vec::new();
|
||||
|
||||
for device in &mut self.devices {
|
||||
match device {
|
||||
@ -102,6 +107,11 @@ impl QemuInner {
|
||||
}
|
||||
}
|
||||
}
|
||||
DeviceType::Network(network) => {
|
||||
let network_info = &self.config.network_info;
|
||||
|
||||
_fds_for_qemu = cmdline.add_network_device(&network.config, network_info)?;
|
||||
}
|
||||
_ => info!(sl!(), "qemu cmdline: unsupported device: {:?}", device),
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user