mirror of
https://github.com/kata-containers/kata-containers.git
synced 2025-08-10 20:32:54 +00:00
runtime-rs: reimplement add_network_device() using Netdev & DeviceVirtioNet
This commit replaces the existing NetDevice-based implementation with one using Netdev and DeviceVirtioNet. Signed-off-by: Pavel Mores <pmores@redhat.com>
This commit is contained in:
parent
0a57e2bb32
commit
12e40ede97
@ -1262,23 +1262,40 @@ impl<'a> QemuCmdLine<'a> {
|
|||||||
pub fn add_network_device(
|
pub fn add_network_device(
|
||||||
&mut self,
|
&mut self,
|
||||||
config: &NetworkConfig,
|
config: &NetworkConfig,
|
||||||
network_info: &NetworkInfo,
|
_network_info: &NetworkInfo,
|
||||||
) -> Result<Vec<File>> {
|
) -> Result<Vec<File>> {
|
||||||
let disable_vhost_net = network_info.disable_vhost_net;
|
let mut netdev = Netdev::new(
|
||||||
let queues = network_info.network_queues;
|
&format!("network-{}", &config.index),
|
||||||
let if_name = config.host_dev_name.as_str();
|
&config.host_dev_name,
|
||||||
|
self.config.network_info.network_queues,
|
||||||
|
)?;
|
||||||
|
if self.config.network_info.disable_vhost_net {
|
||||||
|
netdev.set_disable_vhost_net(true);
|
||||||
|
}
|
||||||
|
|
||||||
let (tun_files, vhost_files) = generate_netdev_fds(if_name, queues)?;
|
let mut virtio_net_device =
|
||||||
let tun_fds: Vec<i32> = tun_files.iter().map(|dev| dev.as_raw_fd()).collect();
|
DeviceVirtioNet::new(&netdev.id, config.guest_mac.clone().unwrap());
|
||||||
let vhost_fds: Vec<i32> = vhost_files.iter().map(|dev| dev.as_raw_fd()).collect();
|
|
||||||
|
|
||||||
let net_device = NetDevice::new(config, disable_vhost_net, tun_fds, vhost_fds);
|
let nested = match is_running_in_vm() {
|
||||||
self.devices.push(Box::new(net_device));
|
Ok(retval) => retval,
|
||||||
|
Err(err) => {
|
||||||
|
info!(
|
||||||
|
sl!(),
|
||||||
|
"unable to check if running in VM, assuming not: {}", err
|
||||||
|
);
|
||||||
|
false
|
||||||
|
}
|
||||||
|
};
|
||||||
|
if nested {
|
||||||
|
virtio_net_device.set_disable_modern(true);
|
||||||
|
}
|
||||||
|
if self.config.network_info.network_queues > 1 {
|
||||||
|
virtio_net_device.set_num_queues(self.config.network_info.network_queues);
|
||||||
|
}
|
||||||
|
|
||||||
let dev_files = vec![tun_files, vhost_files];
|
self.devices.push(Box::new(netdev));
|
||||||
let fds: Vec<File> = dev_files.into_iter().flatten().collect();
|
self.devices.push(Box::new(virtio_net_device));
|
||||||
|
Ok(vec![])
|
||||||
Ok(fds)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn add_console(&mut self, console_socket_path: &str) {
|
pub fn add_console(&mut self, console_socket_path: &str) {
|
||||||
|
Loading…
Reference in New Issue
Block a user