mirror of
https://github.com/kata-containers/kata-containers.git
synced 2025-09-19 07:49:17 +00:00
runtime-rs: Remove virtio config from Backend
Virtio-net and vhost-net share a common virtio config, and vhost-user-net uses another config, named `VhostUserConfig`. Thus, the virtio config could be added into `NetworkConfig` instead of `Backend`. Signed-off-by: Xuewei Niu <niuxuewei.nxw@antgroup.com>
This commit is contained in:
@@ -12,8 +12,8 @@ use tokio::sync::{Mutex, RwLock};
|
||||
|
||||
use crate::{
|
||||
vhost_user_blk::VhostUserBlkDevice, BlockConfig, BlockDevice, HybridVsockDevice, Hypervisor,
|
||||
NetworkBackend, NetworkDevice, VfioDevice, VhostUserConfig, KATA_BLK_DEV_TYPE,
|
||||
KATA_MMIO_BLK_DEV_TYPE, KATA_NVDIMM_DEV_TYPE, VIRTIO_BLOCK_MMIO, VIRTIO_BLOCK_PCI, VIRTIO_PMEM,
|
||||
NetworkDevice, VfioDevice, VhostUserConfig, KATA_BLK_DEV_TYPE, KATA_MMIO_BLK_DEV_TYPE,
|
||||
KATA_NVDIMM_DEV_TYPE, VIRTIO_BLOCK_MMIO, VIRTIO_BLOCK_PCI, VIRTIO_PMEM,
|
||||
};
|
||||
|
||||
use super::{
|
||||
@@ -221,18 +221,11 @@ impl DeviceManager {
|
||||
return Some(device_id.to_string());
|
||||
}
|
||||
}
|
||||
DeviceType::Network(device) => match device.config.backend {
|
||||
NetworkBackend::Virtio(config) => {
|
||||
if config.host_dev_name == host_path {
|
||||
DeviceType::Network(device) => {
|
||||
if device.config.host_dev_name == host_path {
|
||||
return Some(device_id.to_string());
|
||||
}
|
||||
}
|
||||
NetworkBackend::Vhost(config) => {
|
||||
if config.host_dev_name == host_path {
|
||||
return Some(device_id.to_string());
|
||||
}
|
||||
}
|
||||
},
|
||||
_ => {
|
||||
// TODO: support find other device type
|
||||
continue;
|
||||
@@ -314,10 +307,7 @@ impl DeviceManager {
|
||||
}
|
||||
DeviceConfig::NetworkCfg(config) => {
|
||||
// try to find the device, found and just return id.
|
||||
let host_path = match &config.backend {
|
||||
NetworkBackend::Virtio(config) => &config.host_dev_name,
|
||||
NetworkBackend::Vhost(config) => &config.host_dev_name,
|
||||
};
|
||||
let host_path = config.host_dev_name.as_str();
|
||||
if let Some(dev_id_matched) = self.find_device(host_path.to_owned()).await {
|
||||
info!(
|
||||
sl!(),
|
||||
|
@@ -23,8 +23,7 @@ pub use virtio_fs::{
|
||||
ShareFsDevice, ShareFsDeviceConfig, ShareFsMountConfig, ShareFsMountDevice, ShareFsMountType,
|
||||
ShareFsOperation,
|
||||
};
|
||||
pub use virtio_net::{Address, NetworkBackend, NetworkConfig, NetworkDevice, VirtioConfig};
|
||||
pub use virtio_net::{Address, NetworkConfig, NetworkDevice};
|
||||
pub use virtio_net::{Address, Backend, NetworkConfig, NetworkDevice};
|
||||
pub use virtio_vsock::{
|
||||
HybridVsockConfig, HybridVsockDevice, VsockConfig, VsockDevice, DEFAULT_GUEST_VSOCK_CID,
|
||||
};
|
||||
|
@@ -26,27 +26,11 @@ impl fmt::Debug for Address {
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Clone, Debug)]
|
||||
pub enum NetworkBackend {
|
||||
Virtio(VirtioConfig),
|
||||
Vhost(VirtioConfig),
|
||||
}
|
||||
|
||||
impl Default for NetworkBackend {
|
||||
fn default() -> Self {
|
||||
Self::Virtio(VirtioConfig::default())
|
||||
}
|
||||
}
|
||||
|
||||
/// Virtio network backend config
|
||||
#[derive(Clone, Debug, Default)]
|
||||
pub struct VirtioConfig {
|
||||
/// Host level path for the guest network interface.
|
||||
pub host_dev_name: String,
|
||||
/// Guest iface name for the guest network interface.
|
||||
pub virt_iface_name: String,
|
||||
/// Allow duplicate mac
|
||||
pub allow_duplicate_mac: bool,
|
||||
pub enum Backend {
|
||||
#[default]
|
||||
Virtio,
|
||||
Vhost,
|
||||
}
|
||||
|
||||
#[derive(Clone, Debug, Default)]
|
||||
@@ -55,7 +39,11 @@ pub struct NetworkConfig {
|
||||
pub index: u64,
|
||||
|
||||
/// Network device backend
|
||||
pub backend: NetworkBackend,
|
||||
pub backend: Backend,
|
||||
/// Host level path for the guest network interface.
|
||||
pub host_dev_name: String,
|
||||
/// Guest iface name for the guest network interface.
|
||||
pub virt_iface_name: String,
|
||||
/// Guest MAC address.
|
||||
pub guest_mac: Option<Address>,
|
||||
/// Virtio queue size
|
||||
@@ -66,6 +54,8 @@ pub struct NetworkConfig {
|
||||
pub use_shared_irq: Option<bool>,
|
||||
/// Use generic irq
|
||||
pub use_generic_irq: Option<bool>,
|
||||
/// Allow duplicate mac
|
||||
pub allow_duplicate_mac: bool,
|
||||
}
|
||||
|
||||
#[derive(Clone, Debug, Default)]
|
||||
|
@@ -18,7 +18,7 @@ use anyhow::{Context, Result};
|
||||
use async_trait::async_trait;
|
||||
use dbs_utils::net::MacAddr as DragonballMacAddr;
|
||||
use dragonball::api::v1::{
|
||||
Backend as DragonballNetworkBackend, NetworkInterfaceConfig as DragonballNetworkConfig,
|
||||
Backend as DragonballBackend, NetworkInterfaceConfig as DragonballNetworkConfig,
|
||||
VirtioConfig as DragonballVirtioConfig,
|
||||
};
|
||||
use kata_types::capabilities::Capabilities;
|
||||
@@ -26,7 +26,7 @@ use kata_types::config::hypervisor::Hypervisor as HypervisorConfig;
|
||||
use tokio::sync::RwLock;
|
||||
use tracing::instrument;
|
||||
|
||||
use crate::{DeviceType, Hypervisor, NetworkBackend, NetworkConfig, VcpuThreadIds};
|
||||
use crate::{Backend, DeviceType, Hypervisor, NetworkConfig, VcpuThreadIds};
|
||||
|
||||
pub struct Dragonball {
|
||||
inner: Arc<RwLock<DragonballInner>>,
|
||||
@@ -196,27 +196,6 @@ impl Persist for Dragonball {
|
||||
}
|
||||
}
|
||||
|
||||
impl From<NetworkBackend> for DragonballNetworkBackend {
|
||||
fn from(value: NetworkBackend) -> Self {
|
||||
match value {
|
||||
NetworkBackend::Virtio(config) => Self::Virtio(DragonballVirtioConfig {
|
||||
iface_id: config.virt_iface_name.clone(),
|
||||
host_dev_name: config.host_dev_name.clone(),
|
||||
rx_rate_limiter: None,
|
||||
tx_rate_limiter: None,
|
||||
allow_duplicate_mac: config.allow_duplicate_mac,
|
||||
}),
|
||||
NetworkBackend::Vhost(config) => Self::Vhost(DragonballVirtioConfig {
|
||||
iface_id: config.virt_iface_name.clone(),
|
||||
host_dev_name: config.host_dev_name.clone(),
|
||||
rx_rate_limiter: None,
|
||||
tx_rate_limiter: None,
|
||||
allow_duplicate_mac: config.allow_duplicate_mac,
|
||||
}),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl From<NetworkConfig> for DragonballNetworkConfig {
|
||||
fn from(value: NetworkConfig) -> Self {
|
||||
let r = &value;
|
||||
@@ -226,10 +205,24 @@ impl From<NetworkConfig> for DragonballNetworkConfig {
|
||||
|
||||
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.
|
||||
rx_rate_limiter: None,
|
||||
// TODO(justxuewei): tx_rate_limiter is not supported.
|
||||
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: value.backend.clone().into(),
|
||||
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()
|
||||
|
@@ -4,28 +4,19 @@
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
//
|
||||
|
||||
use std::{
|
||||
io::{self, Error},
|
||||
sync::Arc,
|
||||
};
|
||||
use std::io::{self, Error};
|
||||
use std::sync::Arc;
|
||||
|
||||
use anyhow::{Context, Result};
|
||||
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 tokio::sync::RwLock;
|
||||
|
||||
use hypervisor::{
|
||||
device::{
|
||||
device_manager::{do_handle_device, DeviceManager},
|
||||
driver::NetworkConfig,
|
||||
DeviceConfig, DeviceType,
|
||||
},
|
||||
Hypervisor, NetworkBackend, NetworkDevice, VirtioConfig,
|
||||
};
|
||||
|
||||
use super::{
|
||||
endpoint_persist::{EndpointState, IpVlanEndpointState},
|
||||
Endpoint,
|
||||
};
|
||||
use super::endpoint_persist::{EndpointState, IpVlanEndpointState};
|
||||
use super::Endpoint;
|
||||
use crate::network::{network_model::TC_FILTER_NET_MODEL_STR, utils, NetworkPair};
|
||||
|
||||
// IPVlanEndpoint is the endpoint bridged to VM
|
||||
@@ -64,11 +55,9 @@ impl IPVlanEndpoint {
|
||||
})?;
|
||||
|
||||
Ok(NetworkConfig {
|
||||
backend: NetworkBackend::Virtio(VirtioConfig {
|
||||
host_dev_name: iface.name.clone(),
|
||||
virt_iface_name: self.net_pair.virt_iface.name.clone(),
|
||||
..Default::default()
|
||||
}),
|
||||
backend: Backend::Virtio,
|
||||
guest_mac: Some(guest_mac),
|
||||
..Default::default()
|
||||
})
|
||||
|
@@ -4,28 +4,19 @@
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
//
|
||||
|
||||
use std::{
|
||||
io::{self, Error},
|
||||
sync::Arc,
|
||||
};
|
||||
use std::io::{self, Error};
|
||||
use std::sync::Arc;
|
||||
|
||||
use anyhow::{Context, Result};
|
||||
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 tokio::sync::RwLock;
|
||||
|
||||
use hypervisor::{
|
||||
device::{
|
||||
device_manager::{do_handle_device, DeviceManager},
|
||||
driver::NetworkConfig,
|
||||
DeviceConfig, DeviceType,
|
||||
},
|
||||
Hypervisor, NetworkBackend, NetworkDevice, VirtioConfig,
|
||||
};
|
||||
|
||||
use super::{
|
||||
endpoint_persist::{EndpointState, MacvlanEndpointState},
|
||||
Endpoint,
|
||||
};
|
||||
use super::endpoint_persist::{EndpointState, MacvlanEndpointState};
|
||||
use super::Endpoint;
|
||||
use crate::network::{utils, NetworkPair};
|
||||
|
||||
#[derive(Debug)]
|
||||
@@ -63,11 +54,9 @@ impl MacVlanEndpoint {
|
||||
})?;
|
||||
|
||||
Ok(NetworkConfig {
|
||||
backend: NetworkBackend::Virtio(VirtioConfig {
|
||||
host_dev_name: iface.name.clone(),
|
||||
virt_iface_name: self.net_pair.virt_iface.name.clone(),
|
||||
..Default::default()
|
||||
}),
|
||||
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::{Hypervisor, NetworkBackend, NetworkConfig, NetworkDevice, VirtioConfig};
|
||||
use hypervisor::{Backend, Hypervisor, NetworkConfig, NetworkDevice};
|
||||
use tokio::sync::RwLock;
|
||||
|
||||
use super::endpoint_persist::TapEndpointState;
|
||||
@@ -74,11 +74,9 @@ impl TapEndpoint {
|
||||
fn get_network_config(&self) -> Result<NetworkConfig> {
|
||||
let guest_mac = utils::parse_mac(&self.guest_mac).context("Parse mac address")?;
|
||||
Ok(NetworkConfig {
|
||||
backend: NetworkBackend::Virtio(VirtioConfig {
|
||||
host_dev_name: self.tap_iface.name.clone(),
|
||||
virt_iface_name: self.name.clone(),
|
||||
..Default::default()
|
||||
}),
|
||||
backend: Backend::Virtio,
|
||||
guest_mac: Some(guest_mac),
|
||||
queue_num: self.queue_num,
|
||||
queue_size: self.queue_size,
|
||||
|
@@ -4,28 +4,19 @@
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
//
|
||||
|
||||
use std::{
|
||||
io::{self, Error},
|
||||
sync::Arc,
|
||||
};
|
||||
use std::io::{self, Error};
|
||||
use std::sync::Arc;
|
||||
|
||||
use anyhow::{Context, Result};
|
||||
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 tokio::sync::RwLock;
|
||||
|
||||
use hypervisor::{
|
||||
device::{
|
||||
device_manager::{do_handle_device, DeviceManager},
|
||||
driver::NetworkConfig,
|
||||
DeviceConfig, DeviceType,
|
||||
},
|
||||
Hypervisor, NetworkBackend, NetworkDevice, VirtioConfig,
|
||||
};
|
||||
|
||||
use super::{
|
||||
endpoint_persist::{EndpointState, VethEndpointState},
|
||||
Endpoint,
|
||||
};
|
||||
use super::endpoint_persist::{EndpointState, VethEndpointState};
|
||||
use super::Endpoint;
|
||||
use crate::network::{utils, NetworkPair};
|
||||
|
||||
#[derive(Debug)]
|
||||
@@ -63,11 +54,9 @@ impl VethEndpoint {
|
||||
})?;
|
||||
|
||||
Ok(NetworkConfig {
|
||||
backend: NetworkBackend::Virtio(VirtioConfig {
|
||||
host_dev_name: iface.name.clone(),
|
||||
virt_iface_name: self.net_pair.virt_iface.name.clone(),
|
||||
..Default::default()
|
||||
}),
|
||||
backend: Backend::Virtio,
|
||||
guest_mac: Some(guest_mac),
|
||||
..Default::default()
|
||||
})
|
||||
|
@@ -4,29 +4,21 @@
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
//
|
||||
|
||||
use std::{
|
||||
io::{self, Error},
|
||||
sync::Arc,
|
||||
};
|
||||
use std::io::{self, Error};
|
||||
use std::sync::Arc;
|
||||
|
||||
use anyhow::{Context, Result};
|
||||
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 tokio::sync::RwLock;
|
||||
|
||||
use hypervisor::{
|
||||
device::{
|
||||
device_manager::{do_handle_device, DeviceManager},
|
||||
driver::NetworkConfig,
|
||||
DeviceConfig, DeviceType,
|
||||
},
|
||||
Hypervisor, NetworkBackend, NetworkDevice, VirtioConfig,
|
||||
};
|
||||
|
||||
use super::{
|
||||
endpoint_persist::{EndpointState, VlanEndpointState},
|
||||
Endpoint,
|
||||
};
|
||||
use crate::network::{network_model::TC_FILTER_NET_MODEL_STR, utils, NetworkPair};
|
||||
use super::endpoint_persist::{EndpointState, VlanEndpointState};
|
||||
use super::Endpoint;
|
||||
use crate::network::network_model::TC_FILTER_NET_MODEL_STR;
|
||||
use crate::network::{utils, NetworkPair};
|
||||
|
||||
#[derive(Debug)]
|
||||
pub struct VlanEndpoint {
|
||||
@@ -62,11 +54,9 @@ impl VlanEndpoint {
|
||||
})?;
|
||||
|
||||
Ok(NetworkConfig {
|
||||
backend: NetworkBackend::Virtio(VirtioConfig {
|
||||
host_dev_name: iface.name.clone(),
|
||||
virt_iface_name: self.net_pair.virt_iface.name.clone(),
|
||||
..Default::default()
|
||||
}),
|
||||
backend: Backend::Virtio,
|
||||
guest_mac: Some(guest_mac),
|
||||
..Default::default()
|
||||
})
|
||||
|
Reference in New Issue
Block a user