mirror of
https://github.com/kata-containers/kata-containers.git
synced 2025-07-31 23:36:12 +00:00
runtime-rs: Use vhost-net device by default
This patch set vhost-net as default backend of networking. It allows users to set `disable_vhost_net` to `true` to reenable virtio-net backend. Plus, which backend to use is a matter of hypervisor, runtime-rs will no longer need to know that. Fixes: #8608 Signed-off-by: Xuewei Niu <niuxuewei.nxw@antgroup.com>
This commit is contained in:
parent
ee74fca92c
commit
c11b066728
@ -475,7 +475,7 @@ impl TryFrom<ShareFsSettings> for FsConfig {
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use super::*;
|
||||
use crate::{Address, Backend};
|
||||
use crate::Address;
|
||||
|
||||
#[test]
|
||||
fn test_networkconfig_to_netconfig() {
|
||||
@ -489,7 +489,6 @@ mod tests {
|
||||
allow_duplicate_mac: false,
|
||||
use_generic_irq: None,
|
||||
use_shared_irq: None,
|
||||
backend: Backend::default(),
|
||||
};
|
||||
|
||||
let net = NetConfig::try_from(cfg.clone());
|
||||
|
@ -22,7 +22,7 @@ pub use virtio_blk::{
|
||||
pub use virtio_fs::{
|
||||
ShareFsConfig, ShareFsDevice, ShareFsMountConfig, ShareFsMountOperation, ShareFsMountType,
|
||||
};
|
||||
pub use virtio_net::{Address, Backend, NetworkConfig, NetworkDevice};
|
||||
pub use virtio_net::{Address, NetworkConfig, NetworkDevice};
|
||||
pub use virtio_vsock::{
|
||||
HybridVsockConfig, HybridVsockDevice, VsockConfig, VsockDevice, DEFAULT_GUEST_VSOCK_CID,
|
||||
};
|
||||
|
@ -26,20 +26,11 @@ impl fmt::Debug for Address {
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Clone, Debug, Default)]
|
||||
pub enum Backend {
|
||||
#[default]
|
||||
Virtio,
|
||||
Vhost,
|
||||
}
|
||||
|
||||
#[derive(Clone, Debug, Default)]
|
||||
pub struct NetworkConfig {
|
||||
/// for detach, now it's default value 0.
|
||||
pub index: u64,
|
||||
|
||||
/// Network device backend
|
||||
pub backend: Backend,
|
||||
/// Host level path for the guest network interface.
|
||||
pub host_dev_name: String,
|
||||
/// Guest iface name for the guest network interface.
|
||||
|
@ -12,7 +12,7 @@ use dragonball::api::v1::{
|
||||
};
|
||||
use dragonball::device_manager::blk_dev_mgr::BlockDeviceType;
|
||||
|
||||
use super::DragonballInner;
|
||||
use super::{build_dragonball_network_config, DragonballInner};
|
||||
use crate::{
|
||||
device::DeviceType, HybridVsockConfig, NetworkConfig, ShareFsConfig, ShareFsMountConfig,
|
||||
ShareFsMountOperation, ShareFsMountType, VfioBusMode, VfioDevice, VmmState, JAILER_ROOT,
|
||||
@ -210,8 +210,9 @@ impl DragonballInner {
|
||||
}
|
||||
|
||||
fn add_net_device(&mut self, config: &NetworkConfig) -> Result<()> {
|
||||
let net_cfg = build_dragonball_network_config(&self.config, config);
|
||||
self.vmm_instance
|
||||
.insert_network_device(config.into())
|
||||
.insert_network_device(net_cfg)
|
||||
.context("insert network device")
|
||||
}
|
||||
|
||||
|
@ -26,7 +26,7 @@ use kata_types::config::hypervisor::Hypervisor as HypervisorConfig;
|
||||
use tokio::sync::RwLock;
|
||||
use tracing::instrument;
|
||||
|
||||
use crate::{Backend, DeviceType, Hypervisor, NetworkConfig, VcpuThreadIds};
|
||||
use crate::{DeviceType, Hypervisor, NetworkConfig, VcpuThreadIds};
|
||||
|
||||
pub struct Dragonball {
|
||||
inner: Arc<RwLock<DragonballInner>>,
|
||||
@ -201,41 +201,39 @@ impl Persist for Dragonball {
|
||||
}
|
||||
}
|
||||
|
||||
impl From<NetworkConfig> for DragonballNetworkConfig {
|
||||
fn from(value: NetworkConfig) -> Self {
|
||||
let r = &value;
|
||||
r.into()
|
||||
}
|
||||
}
|
||||
|
||||
impl From<&NetworkConfig> for DragonballNetworkConfig {
|
||||
fn from(value: &NetworkConfig) -> Self {
|
||||
let virtio_config = DragonballVirtioConfig {
|
||||
iface_id: value.virt_iface_name.clone(),
|
||||
host_dev_name: value.host_dev_name.clone(),
|
||||
// TODO(justxuewei): rx_rate_limiter is not supported, see:
|
||||
// https://github.com/kata-containers/kata-containers/issues/8327.
|
||||
rx_rate_limiter: None,
|
||||
// TODO(justxuewei): tx_rate_limiter is not supported, see:
|
||||
// https://github.com/kata-containers/kata-containers/issues/8327.
|
||||
tx_rate_limiter: None,
|
||||
allow_duplicate_mac: value.allow_duplicate_mac,
|
||||
};
|
||||
let backend = match value.backend {
|
||||
Backend::Virtio => DragonballBackend::Virtio(virtio_config),
|
||||
Backend::Vhost => DragonballBackend::Vhost(virtio_config),
|
||||
};
|
||||
|
||||
Self {
|
||||
num_queues: Some(value.queue_num),
|
||||
queue_size: Some(value.queue_size as u16),
|
||||
backend,
|
||||
guest_mac: value.guest_mac.clone().map(|mac| {
|
||||
// We are safety since mac address is checked by endpoints.
|
||||
DragonballMacAddr::from_bytes(&mac.0).unwrap()
|
||||
}),
|
||||
use_shared_irq: value.use_shared_irq,
|
||||
use_generic_irq: value.use_generic_irq,
|
||||
}
|
||||
/// Generate Dragonball network config according to hypervisor config and
|
||||
/// runtime network config.
|
||||
pub(crate) fn build_dragonball_network_config(
|
||||
hconfig: &HypervisorConfig,
|
||||
nconfig: &NetworkConfig,
|
||||
) -> DragonballNetworkConfig {
|
||||
let virtio_config = DragonballVirtioConfig {
|
||||
iface_id: nconfig.virt_iface_name.clone(),
|
||||
host_dev_name: nconfig.host_dev_name.clone(),
|
||||
// TODO(justxuewei): rx_rate_limiter is not supported, see:
|
||||
// https://github.com/kata-containers/kata-containers/issues/8327.
|
||||
rx_rate_limiter: None,
|
||||
// TODO(justxuewei): tx_rate_limiter is not supported, see:
|
||||
// https://github.com/kata-containers/kata-containers/issues/8327.
|
||||
tx_rate_limiter: None,
|
||||
allow_duplicate_mac: nconfig.allow_duplicate_mac,
|
||||
};
|
||||
|
||||
let backend = if hconfig.network_info.disable_vhost_net {
|
||||
DragonballBackend::Virtio(virtio_config)
|
||||
} else {
|
||||
DragonballBackend::Vhost(virtio_config)
|
||||
};
|
||||
|
||||
DragonballNetworkConfig {
|
||||
num_queues: Some(nconfig.queue_num),
|
||||
queue_size: Some(nconfig.queue_size as u16),
|
||||
backend,
|
||||
guest_mac: nconfig.guest_mac.clone().map(|mac| {
|
||||
// We are safety since mac address is checked by endpoints.
|
||||
DragonballMacAddr::from_bytes(&mac.0).unwrap()
|
||||
}),
|
||||
use_shared_irq: nconfig.use_shared_irq,
|
||||
use_generic_irq: nconfig.use_generic_irq,
|
||||
}
|
||||
}
|
||||
|
@ -12,7 +12,7 @@ use async_trait::async_trait;
|
||||
use hypervisor::device::device_manager::{do_handle_device, DeviceManager};
|
||||
use hypervisor::device::driver::NetworkConfig;
|
||||
use hypervisor::device::{DeviceConfig, DeviceType};
|
||||
use hypervisor::{Backend, Hypervisor, NetworkDevice};
|
||||
use hypervisor::{Hypervisor, NetworkDevice};
|
||||
use tokio::sync::RwLock;
|
||||
|
||||
use super::endpoint_persist::{EndpointState, IpVlanEndpointState};
|
||||
@ -57,7 +57,6 @@ impl IPVlanEndpoint {
|
||||
Ok(NetworkConfig {
|
||||
host_dev_name: iface.name.clone(),
|
||||
virt_iface_name: self.net_pair.virt_iface.name.clone(),
|
||||
backend: Backend::Virtio,
|
||||
guest_mac: Some(guest_mac),
|
||||
..Default::default()
|
||||
})
|
||||
|
@ -12,7 +12,7 @@ use async_trait::async_trait;
|
||||
use hypervisor::device::device_manager::{do_handle_device, DeviceManager};
|
||||
use hypervisor::device::driver::NetworkConfig;
|
||||
use hypervisor::device::{DeviceConfig, DeviceType};
|
||||
use hypervisor::{Backend, Hypervisor, NetworkDevice};
|
||||
use hypervisor::{Hypervisor, NetworkDevice};
|
||||
use tokio::sync::RwLock;
|
||||
|
||||
use super::endpoint_persist::{EndpointState, MacvlanEndpointState};
|
||||
@ -56,7 +56,6 @@ impl MacVlanEndpoint {
|
||||
Ok(NetworkConfig {
|
||||
host_dev_name: iface.name.clone(),
|
||||
virt_iface_name: self.net_pair.virt_iface.name.clone(),
|
||||
backend: Backend::Virtio,
|
||||
guest_mac: Some(guest_mac),
|
||||
..Default::default()
|
||||
})
|
||||
|
@ -10,7 +10,7 @@ use anyhow::{Context, Result};
|
||||
use async_trait::async_trait;
|
||||
use hypervisor::device::device_manager::{do_handle_device, DeviceManager};
|
||||
use hypervisor::device::{DeviceConfig, DeviceType};
|
||||
use hypervisor::{Backend, Hypervisor, NetworkConfig, NetworkDevice};
|
||||
use hypervisor::{Hypervisor, NetworkConfig, NetworkDevice};
|
||||
use tokio::sync::RwLock;
|
||||
|
||||
use super::endpoint_persist::TapEndpointState;
|
||||
@ -76,7 +76,6 @@ impl TapEndpoint {
|
||||
Ok(NetworkConfig {
|
||||
host_dev_name: self.tap_iface.name.clone(),
|
||||
virt_iface_name: self.name.clone(),
|
||||
backend: Backend::Virtio,
|
||||
guest_mac: Some(guest_mac),
|
||||
queue_num: self.queue_num,
|
||||
queue_size: self.queue_size,
|
||||
|
@ -12,7 +12,7 @@ use async_trait::async_trait;
|
||||
use hypervisor::device::device_manager::{do_handle_device, DeviceManager};
|
||||
use hypervisor::device::driver::NetworkConfig;
|
||||
use hypervisor::device::{DeviceConfig, DeviceType};
|
||||
use hypervisor::{Backend, Hypervisor, NetworkDevice};
|
||||
use hypervisor::{Hypervisor, NetworkDevice};
|
||||
use tokio::sync::RwLock;
|
||||
|
||||
use super::endpoint_persist::{EndpointState, VethEndpointState};
|
||||
@ -56,7 +56,6 @@ impl VethEndpoint {
|
||||
Ok(NetworkConfig {
|
||||
host_dev_name: iface.name.clone(),
|
||||
virt_iface_name: self.net_pair.virt_iface.name.clone(),
|
||||
backend: Backend::Virtio,
|
||||
guest_mac: Some(guest_mac),
|
||||
..Default::default()
|
||||
})
|
||||
|
@ -12,7 +12,7 @@ use async_trait::async_trait;
|
||||
use hypervisor::device::device_manager::{do_handle_device, DeviceManager};
|
||||
use hypervisor::device::driver::NetworkConfig;
|
||||
use hypervisor::device::{DeviceConfig, DeviceType};
|
||||
use hypervisor::{Backend, Hypervisor, NetworkDevice};
|
||||
use hypervisor::{Hypervisor, NetworkDevice};
|
||||
use tokio::sync::RwLock;
|
||||
|
||||
use super::endpoint_persist::{EndpointState, VlanEndpointState};
|
||||
@ -56,7 +56,6 @@ impl VlanEndpoint {
|
||||
Ok(NetworkConfig {
|
||||
host_dev_name: iface.name.clone(),
|
||||
virt_iface_name: self.net_pair.virt_iface.name.clone(),
|
||||
backend: Backend::Virtio,
|
||||
guest_mac: Some(guest_mac),
|
||||
..Default::default()
|
||||
})
|
||||
|
Loading…
Reference in New Issue
Block a user