mirror of
https://github.com/kata-containers/kata-containers.git
synced 2025-06-28 16:27:50 +00:00
runtime-rs: Move Dragonball stuff out of device drivers
Moving Dragonball structs convertions out of device drivers to keep driver neutral. The convertions include `NetworkBackend` to `DragonballNetworkBackend` and `NetworkConfig` to `DragonballNetworkConfig`. Signed-off-by: Xuewei Niu <niuxuewei.nxw@antgroup.com>
This commit is contained in:
parent
3e0614cdf0
commit
ad66378bf5
@ -8,16 +8,9 @@ use std::fmt;
|
|||||||
|
|
||||||
use anyhow::{Context, Result};
|
use anyhow::{Context, Result};
|
||||||
use async_trait::async_trait;
|
use async_trait::async_trait;
|
||||||
use dbs_utils::net::MacAddr as DragonballMacAddr;
|
|
||||||
use dragonball::api::v1::{
|
|
||||||
Backend as DragonballNetworkBackend, NetworkInterfaceConfig as DragonballNetworkConfig,
|
|
||||||
VirtioConfig as DragonballVirtioConfig,
|
|
||||||
};
|
|
||||||
|
|
||||||
use crate::{
|
use crate::device::{Device, DeviceType};
|
||||||
device::{Device, DeviceType},
|
use crate::Hypervisor as hypervisor;
|
||||||
Hypervisor as hypervisor,
|
|
||||||
};
|
|
||||||
|
|
||||||
#[derive(Clone)]
|
#[derive(Clone)]
|
||||||
pub struct Address(pub [u8; 6]);
|
pub struct Address(pub [u8; 6]);
|
||||||
@ -45,27 +38,6 @@ impl Default for NetworkBackend {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
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,
|
|
||||||
}),
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Virtio network backend config
|
/// Virtio network backend config
|
||||||
#[derive(Clone, Debug, Default)]
|
#[derive(Clone, Debug, Default)]
|
||||||
pub struct VirtioConfig {
|
pub struct VirtioConfig {
|
||||||
@ -96,29 +68,6 @@ pub struct NetworkConfig {
|
|||||||
pub use_generic_irq: Option<bool>,
|
pub use_generic_irq: Option<bool>,
|
||||||
}
|
}
|
||||||
|
|
||||||
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 {
|
|
||||||
Self {
|
|
||||||
num_queues: Some(value.queue_num),
|
|
||||||
queue_size: Some(value.queue_size as u16),
|
|
||||||
backend: value.backend.clone().into(),
|
|
||||||
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,
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
#[derive(Clone, Debug, Default)]
|
#[derive(Clone, Debug, Default)]
|
||||||
pub struct NetworkDevice {
|
pub struct NetworkDevice {
|
||||||
/// Unique identifier of the device
|
/// Unique identifier of the device
|
||||||
|
@ -16,12 +16,17 @@ use std::sync::Arc;
|
|||||||
|
|
||||||
use anyhow::{Context, Result};
|
use anyhow::{Context, Result};
|
||||||
use async_trait::async_trait;
|
use async_trait::async_trait;
|
||||||
|
use dbs_utils::net::MacAddr as DragonballMacAddr;
|
||||||
|
use dragonball::api::v1::{
|
||||||
|
Backend as DragonballNetworkBackend, NetworkInterfaceConfig as DragonballNetworkConfig,
|
||||||
|
VirtioConfig as DragonballVirtioConfig,
|
||||||
|
};
|
||||||
use kata_types::capabilities::Capabilities;
|
use kata_types::capabilities::Capabilities;
|
||||||
use kata_types::config::hypervisor::Hypervisor as HypervisorConfig;
|
use kata_types::config::hypervisor::Hypervisor as HypervisorConfig;
|
||||||
use tokio::sync::RwLock;
|
use tokio::sync::RwLock;
|
||||||
use tracing::instrument;
|
use tracing::instrument;
|
||||||
|
|
||||||
use crate::{DeviceType, Hypervisor, VcpuThreadIds};
|
use crate::{DeviceType, Hypervisor, NetworkBackend, NetworkConfig, VcpuThreadIds};
|
||||||
|
|
||||||
pub struct Dragonball {
|
pub struct Dragonball {
|
||||||
inner: Arc<RwLock<DragonballInner>>,
|
inner: Arc<RwLock<DragonballInner>>,
|
||||||
@ -190,3 +195,47 @@ 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;
|
||||||
|
r.into()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl From<&NetworkConfig> for DragonballNetworkConfig {
|
||||||
|
fn from(value: &NetworkConfig) -> Self {
|
||||||
|
Self {
|
||||||
|
num_queues: Some(value.queue_num),
|
||||||
|
queue_size: Some(value.queue_size as u16),
|
||||||
|
backend: value.backend.clone().into(),
|
||||||
|
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,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user