Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

dragonball: add vhost-user connection management logic #8450

Merged
merged 2 commits into from
Nov 21, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
1 change: 1 addition & 0 deletions src/dragonball/src/dbs_virtio_devices/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -53,3 +53,4 @@ virtio-mem = ["virtio-mmio"]
virtio-balloon = ["virtio-mmio"]
vhost = ["virtio-mmio", "vhost-rs/vhost-user-master", "vhost-rs/vhost-kern"]
vhost-net = ["vhost", "vhost-rs/vhost-net"]
vhost-user = ["vhost"]
40 changes: 39 additions & 1 deletion src/dragonball/src/dbs_virtio_devices/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,32 @@ pub enum ActivateError {
InvalidQueueConfig,
#[error("IO: {0}.")]
IOError(#[from] IOError),
#[error("Virtio error")]
VirtioError(Error),
#[error("Epoll manager error")]
EpollMgr(dbs_utils::epoll_manager::Error),
#[cfg(feature = "vhost")]
#[error("Vhost activate error")]
VhostActivate(vhost_rs::Error),
}

impl std::convert::From<Error> for ActivateError {
fn from(error: Error) -> ActivateError {
ActivateError::VirtioError(error)
}
}

impl std::convert::From<dbs_utils::epoll_manager::Error> for ActivateError {
fn from(error: dbs_utils::epoll_manager::Error) -> ActivateError {
ActivateError::EpollMgr(error)
}
}

#[cfg(feature = "vhost")]
impl std::convert::From<vhost_rs::Error> for ActivateError {
fn from(error: vhost_rs::Error) -> ActivateError {
ActivateError::VhostActivate(error)
}
}

/// Error code for VirtioDevice::read_config()/write_config().
Expand Down Expand Up @@ -155,6 +181,9 @@ pub enum Error {
/// Guest gave us a descriptor that was too big to use.
#[error("descriptor length too big.")]
DescriptorLengthTooBig,
/// Error from the epoll event manager
#[error("dbs_utils error: {0:?}.")]
EpollMgr(dbs_utils::epoll_manager::Error),
/// Guest gave us a write only descriptor that protocol says to read from.
#[error("unexpected write only descriptor.")]
UnexpectedWriteOnlyDescriptor,
Expand All @@ -181,7 +210,7 @@ pub enum Error {
VirtioQueueError(#[from] VqError),
/// Error from Device activate.
#[error("Device activate error: {0}")]
ActivateError(#[from] ActivateError),
ActivateError(#[from] Box<ActivateError>),
/// Error from Interrupt.
#[error("Interrupt error: {0}")]
InterruptError(IOError),
Expand Down Expand Up @@ -229,6 +258,15 @@ 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:?}")]
VhostError(vhost_rs::Error),
#[cfg(feature = "vhost")]
/// Error from the vhost user subsystem
#[error("Vhost-user error: {0:?}")]
VhostUserError(vhost_rs::vhost_user::Error),
}

// Error for tap devices
Expand Down
6 changes: 4 additions & 2 deletions src/dragonball/src/dbs_virtio_devices/src/mmio/mmio_state.rs
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,9 @@ where
// If the driver incorrectly sets up the queues, the following check will fail and take
// the device into an unusable state.
if !self.check_queues_valid() {
return Err(Error::ActivateError(ActivateError::InvalidQueueConfig));
return Err(Error::ActivateError(Box::new(
ActivateError::InvalidQueueConfig,
)));
}

self.register_ioevent()?;
Expand All @@ -138,7 +140,7 @@ where
.map(|_| self.device_activated = true)
.map_err(|e| {
error!("device activate error: {:?}", e);
Error::ActivateError(e)
Error::ActivateError(Box::new(e))
})
}

Expand Down
18 changes: 18 additions & 0 deletions src/dragonball/src/dbs_virtio_devices/src/vhost/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,3 +6,21 @@

#[cfg(feature = "vhost-net")]
pub mod vhost_kern;

pub use vhost_rs::vhost_user::Error as VhostUserError;
pub use vhost_rs::Error as VhostError;

#[cfg(feature = "vhost-user")]
pub mod vhost_user;

impl std::convert::From<VhostError> for super::Error {
fn from(e: VhostError) -> Self {
super::Error::VhostError(e)
}
}

impl std::convert::From<VhostUserError> for super::Error {
fn from(e: VhostUserError) -> Self {
super::Error::VhostUserError(e)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -290,7 +290,7 @@ where
"{}: Invalid virtio queue pairs, expected a value greater than 0, but got {}",
NET_DRIVER_NAME, self.vq_pairs
);
return Err(VirtioError::ActivateError(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 +299,7 @@ where
self.handles.len(),
self.taps.len(),
self.vq_pairs);
return Err(VirtioError::ActivateError(ActivateError::InternalError));
return Err(VirtioError::ActivateError(Box::new(ActivateError::InternalError)));
}

for idx in 0..self.vq_pairs {
Expand Down