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