dragonball: Make vhost-user-net ready for VhostUserEndpoint

The changes involve:

- Expose VhostUserConfig struct to runtime-rs.
- Set a default value while num_queues or queue_size are 0.

Signed-off-by: Xuewei Niu <niuxuewei.nxw@antgroup.com>
This commit is contained in:
Xuewei Niu
2023-12-25 14:28:10 +08:00
parent 54df832407
commit 693a0cfbfd
2 changed files with 18 additions and 1 deletions

View File

@@ -32,4 +32,6 @@ pub use virtio_net::VirtioConfig;
feature = "vhost-net",
feature = "vhost-user-net"
))]
pub use virtio_net::{Backend, NetworkInterfaceConfig, NetworkInterfaceUpdateConfig};
pub use virtio_net::{
Backend, NetworkInterfaceConfig, NetworkInterfaceUpdateConfig, VhostUserConfig,
};

View File

@@ -68,6 +68,7 @@ pub struct VirtioConfig {
pub allow_duplicate_mac: bool,
}
/// Config for vhost-user-net device
#[cfg(feature = "vhost-user-net")]
#[derive(Clone, Debug, Default, Deserialize, PartialEq, Eq, Serialize)]
pub struct VhostUserConfig {
@@ -197,9 +198,23 @@ impl From<&NetworkInterfaceConfig> for VhostUserNetDeviceConfigInfo {
fn from(value: &NetworkInterfaceConfig) -> Self {
let num_queues = value
.num_queues
.map(|nq| {
if nq == 0 {
vhost_user_net_dev_mgr::DEFAULT_NUM_QUEUES
} else {
nq
}
})
.unwrap_or(vhost_user_net_dev_mgr::DEFAULT_NUM_QUEUES);
let queue_size = value
.queue_size
.map(|qs| {
if qs == 0 {
vhost_user_net_dev_mgr::DEFAULT_QUEUE_SIZE
} else {
qs
}
})
.unwrap_or(vhost_user_net_dev_mgr::DEFAULT_QUEUE_SIZE);
// It is safe because we tested the type of config before.
#[allow(unreachable_patterns)]