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:
Xuewei Niu
2023-09-06 10:48:25 +08:00
parent ad66378bf5
commit 8ea87405ed
9 changed files with 86 additions and 159 deletions

View File

@@ -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()
}),
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()
})

View File

@@ -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()
}),
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()
})

View File

@@ -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()
}),
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,

View File

@@ -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()
}),
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()
})

View File

@@ -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()
}),
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()
})