Skip to content

Commit

Permalink
dragonball: Set default queue config for vhost-net device
Browse files Browse the repository at this point in the history
Dragonball sets a default queue config in the case of `None`. The
queue_size and num_queues of vhost-net are set to `Some(0)` by default.
Therefore, we might get an invalid queue config. This patch fixes this
issue.

Signed-off-by: Xuewei Niu <niuxuewei.nxw@antgroup.com>
  • Loading branch information
justxuewei committed Dec 11, 2023
1 parent 525400a commit afdcc72
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 4 deletions.
14 changes: 14 additions & 0 deletions src/dragonball/src/api/v1/virtio_net.rs
Original file line number Diff line number Diff line change
Expand Up @@ -128,9 +128,23 @@ impl From<&NetworkInterfaceConfig> for VhostNetDeviceConfigInfo {
fn from(value: &NetworkInterfaceConfig) -> Self {
let num_queues = value
.num_queues
.map(|nq| {
if nq == 0 {
vhost_net_dev_mgr::DEFAULT_NUM_QUEUES
} else {
nq
}
})
.unwrap_or(vhost_net_dev_mgr::DEFAULT_NUM_QUEUES);
let queue_size = value
.queue_size
.map(|qs| {
if qs == 0 {
vhost_net_dev_mgr::DEFAULT_QUEUE_SIZE
} else {
qs
}
})
.unwrap_or(vhost_net_dev_mgr::DEFAULT_QUEUE_SIZE);

// It is safe because we tested the type of config before.
Expand Down
2 changes: 1 addition & 1 deletion src/dragonball/src/dbs_virtio_devices/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -258,7 +258,7 @@ pub enum Error {
#[cfg(feature = "virtio-balloon")]
#[error("Virtio-balloon error: {0}")]
VirtioBalloonError(#[from] balloon::BalloonError),

#[cfg(feature = "vhost")]
/// Error from the vhost subsystem
#[error("Vhost error: {0:?}")]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -290,7 +290,9 @@ where
"{}: Invalid virtio queue pairs, expected a value greater than 0, but got {}",
NET_DRIVER_NAME, self.vq_pairs
);
return Err(VirtioError::ActivateError(Box::new(ActivateError::InvalidParam)));
return Err(VirtioError::ActivateError(Box::new(
ActivateError::InvalidParam,
)));
}

if self.handles.len() != self.vq_pairs || self.taps.len() != self.vq_pairs {
Expand All @@ -299,7 +301,9 @@ where
self.handles.len(),
self.taps.len(),
self.vq_pairs);
return Err(VirtioError::ActivateError(Box::new(ActivateError::InternalError)));
return Err(VirtioError::ActivateError(Box::new(
ActivateError::InternalError,
)));
}

for idx in 0..self.vq_pairs {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ use std::os::unix::io::{AsRawFd, RawFd};
use std::os::unix::net::UnixStream;
use std::{mem, slice};

use vmm_sys_util::tempfile::TempFile;
use libc::{c_void, iovec};
use vhost_rs::vhost_user::message::{
VhostUserHeaderFlag, VhostUserInflight, VhostUserMemory, VhostUserMemoryRegion,
Expand All @@ -16,6 +15,7 @@ use vhost_rs::vhost_user::message::{
};
use vhost_rs::vhost_user::Error;
use vmm_sys_util::sock_ctrl_msg::ScmSocket;
use vmm_sys_util::tempfile::TempFile;

pub const MAX_ATTACHED_FD_ENTRIES: usize = 32;

Expand Down

0 comments on commit afdcc72

Please sign in to comment.