Skip to content
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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions .buildkite/custom-tests.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,15 +8,15 @@
]
},
{
"test_name": "build-vhost-user-master",
"command": "cargo build --features=vhost-user-master",
"test_name": "build-vhost-user-frontend",
"command": "cargo build --features=vhost-user-frontend",
"platform": [
"x86_64"
]
},
{
"test_name": "build-vhost-user-slave",
"command": "cargo build --features=vhost-user-slave",
"test_name": "build-vhost-user-backend",
"command": "cargo build --features=vhost-user-backend",
"platform": [
"x86_64"
]
Expand Down
2 changes: 1 addition & 1 deletion coverage_config_aarch64.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"coverage_score": 39.8,
"exclude_path": "",
"crate_features": "vhost/vhost-vsock,vhost/vhost-kern,vhost/vhost-user-master,vhost/vhost-user-slave"
"crate_features": "vhost/vhost-vsock,vhost/vhost-kern,vhost/vhost-user-frontend,vhost/vhost-user-backend"
}
2 changes: 1 addition & 1 deletion coverage_config_x86_64.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"coverage_score": 84.0,
"exclude_path": "vhost/src/vhost_kern/",
"crate_features": "vhost/vhost-user-master,vhost/vhost-user-slave"
"crate_features": "vhost/vhost-user-frontend,vhost/vhost-user-backend"
}
1 change: 1 addition & 0 deletions crates/vhost-user-backend/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
### Added

### Changed
- Change uses of master/slave for frontend/backend in the codebase.

### Fixed

Expand Down
4 changes: 2 additions & 2 deletions crates/vhost-user-backend/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -14,14 +14,14 @@ xen = ["vm-memory/xen", "vhost/xen"]
[dependencies]
libc = "0.2.39"
log = "0.4.17"
vhost = { path = "../vhost", version = "0.8", features = ["vhost-user-slave"] }
vhost = { path = "../vhost", version = "0.8", features = ["vhost-user-backend"] }
virtio-bindings = "0.2.1"
virtio-queue = "0.9.0"
vm-memory = { version = "0.12.0", features = ["backend-mmap", "backend-atomic"] }
vmm-sys-util = "0.11.0"

[dev-dependencies]
nix = "0.26"
vhost = { path = "../vhost", version = "0.8", features = ["test-utils", "vhost-user-master", "vhost-user-slave"] }
vhost = { path = "../vhost", version = "0.8", features = ["test-utils", "vhost-user-frontend", "vhost-user-backend"] }
vm-memory = { version = "0.12.0", features = ["backend-mmap", "backend-atomic", "backend-bitmap"] }
tempfile = "3.2.0"
6 changes: 3 additions & 3 deletions crates/vhost-user-backend/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -29,14 +29,14 @@ where
### Create a `VhostUserDaemon` Instance
The `VhostUserDaemon::new()` creates an instance of `VhostUserDaemon` object. The client needs to
pass in an `VhostUserBackend` object, which will be used to configure the `VhostUserDaemon`
instance, handle control messages from the vhost-user master and handle virtio requests from
instance, handle control messages from the vhost-user frontend and handle virtio requests from
virtio queues. A group of working threads will be created to handle virtio requests from configured
virtio queues.

### Start the `VhostUserDaemon`
The `VhostUserDaemon::start()` method waits for an incoming connection from the vhost-user masters
The `VhostUserDaemon::start()` method waits for an incoming connection from the vhost-user frontends
on the `listener`. Once a connection is ready, a main thread will be created to handle vhost-user
messages from the vhost-user master.
messages from the vhost-user frontend.

### Stop the `VhostUserDaemon`
The `VhostUserDaemon::stop()` method waits for the main thread to exit. An exit event must be sent
Expand Down
24 changes: 12 additions & 12 deletions crates/vhost-user-backend/src/backend.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ use std::ops::Deref;
use std::sync::{Arc, Mutex, RwLock};

use vhost::vhost_user::message::VhostUserProtocolFeatures;
use vhost::vhost_user::Slave;
use vhost::vhost_user::Backend;
use vm_memory::bitmap::Bitmap;
use vmm_sys_util::epoll::EventSet;
use vmm_sys_util::eventfd::EventFd;
Expand Down Expand Up @@ -76,11 +76,11 @@ where
/// Update guest memory regions.
fn update_memory(&self, mem: GM<B>) -> Result<()>;

/// Set handler for communicating with the master by the slave communication channel.
/// Set handler for communicating with the frontend by the backend communication channel.
///
/// A default implementation is provided as we cannot expect all backends to implement this
/// function.
fn set_slave_req_fd(&self, _slave: Slave) {}
fn set_backend_req_fd(&self, _backend: Backend) {}

/// Get the map to map queue index to worker thread index.
///
Expand Down Expand Up @@ -157,11 +157,11 @@ where
/// Update guest memory regions.
fn update_memory(&mut self, mem: GM<B>) -> Result<()>;

/// Set handler for communicating with the master by the slave communication channel.
/// Set handler for communicating with the frontend by the backend communication channel.
///
/// A default implementation is provided as we cannot expect all backends to implement this
/// function.
fn set_slave_req_fd(&mut self, _slave: Slave) {}
fn set_backend_req_fd(&mut self, _backend: Backend) {}

/// Get the map to map queue index to worker thread index.
///
Expand Down Expand Up @@ -236,8 +236,8 @@ where
self.deref().update_memory(mem)
}

fn set_slave_req_fd(&self, slave: Slave) {
self.deref().set_slave_req_fd(slave)
fn set_backend_req_fd(&self, backend: Backend) {
self.deref().set_backend_req_fd(backend)
}

fn queues_per_thread(&self) -> Vec<u64> {
Expand Down Expand Up @@ -301,8 +301,8 @@ where
self.lock().unwrap().update_memory(mem)
}

fn set_slave_req_fd(&self, slave: Slave) {
self.lock().unwrap().set_slave_req_fd(slave)
fn set_backend_req_fd(&self, backend: Backend) {
self.lock().unwrap().set_backend_req_fd(backend)
}

fn queues_per_thread(&self) -> Vec<u64> {
Expand Down Expand Up @@ -367,8 +367,8 @@ where
self.write().unwrap().update_memory(mem)
}

fn set_slave_req_fd(&self, slave: Slave) {
self.write().unwrap().set_slave_req_fd(slave)
fn set_backend_req_fd(&self, backend: Backend) {
self.write().unwrap().set_backend_req_fd(backend)
}

fn queues_per_thread(&self) -> Vec<u64> {
Expand Down Expand Up @@ -459,7 +459,7 @@ pub mod tests {
Ok(())
}

fn set_slave_req_fd(&mut self, _slave: Slave) {}
fn set_backend_req_fd(&mut self, _backend: Backend) {}

fn queues_per_thread(&self) -> Vec<u64> {
vec![1, 1]
Expand Down
16 changes: 8 additions & 8 deletions crates/vhost-user-backend/src/handler.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ use vhost::vhost_user::message::{
VhostUserVringState,
};
use vhost::vhost_user::{
Error as VhostUserError, Result as VhostUserResult, Slave, VhostUserSlaveReqHandlerMut,
Backend, Error as VhostUserError, Result as VhostUserResult, VhostUserBackendReqHandlerMut,
};
use virtio_bindings::bindings::virtio_ring::VIRTIO_RING_F_EVENT_IDX;
use virtio_queue::{Error as VirtQueError, QueueT};
Expand Down Expand Up @@ -218,7 +218,7 @@ where
}
}

impl<S, V, B> VhostUserSlaveReqHandlerMut for VhostUserHandler<S, V, B>
impl<S, V, B> VhostUserBackendReqHandlerMut for VhostUserHandler<S, V, B>
where
S: VhostUserBackend<V, B>,
V: VringT<GM<B>>,
Expand Down Expand Up @@ -362,7 +362,7 @@ where
// be to receive the 'used' index in SET_VRING_BASE, as is done when using packed VQs.
let idx = self.vrings[index as usize]
.queue_used_idx()
.map_err(|_| VhostUserError::SlaveInternalError)?;
.map_err(|_| VhostUserError::BackendInternalError)?;
self.vrings[index as usize].set_queue_next_used(idx);

Ok(())
Expand Down Expand Up @@ -461,7 +461,7 @@ where
}

fn set_protocol_features(&mut self, features: u64) -> VhostUserResult<()> {
// Note: slave that reported VHOST_USER_F_PROTOCOL_FEATURES must
// Note: backend that reported VHOST_USER_F_PROTOCOL_FEATURES must
// support this message even before VHOST_USER_SET_FEATURES was
// called.
self.acked_protocol_features = features;
Expand All @@ -481,7 +481,7 @@ where
return Err(VhostUserError::InvalidParam);
}

// Slave must not pass data to/from the backend until ring is
// Backend must not pass data to/from the backend until ring is
// enabled by VHOST_USER_SET_VRING_ENABLE with parameter 1,
// or after it has been disabled by VHOST_USER_SET_VRING_ENABLE
// with parameter 0.
Expand Down Expand Up @@ -510,12 +510,12 @@ where
.map_err(VhostUserError::ReqHandlerError)
}

fn set_slave_req_fd(&mut self, slave: Slave) {
fn set_backend_req_fd(&mut self, backend: Backend) {
if self.acked_protocol_features & VhostUserProtocolFeatures::REPLY_ACK.bits() != 0 {
slave.set_reply_ack_flag(true);
backend.set_reply_ack_flag(true);
}

self.backend.set_slave_req_fd(slave);
self.backend.set_backend_req_fd(backend);
}

fn get_inflight_fd(
Expand Down
40 changes: 21 additions & 19 deletions crates/vhost-user-backend/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ use std::fmt::{Display, Formatter};
use std::sync::{Arc, Mutex};
use std::thread;

use vhost::vhost_user::{Error as VhostUserError, Listener, SlaveListener, SlaveReqHandler};
use vhost::vhost_user::{BackendListener, BackendReqHandler, Error as VhostUserError, Listener};
use vm_memory::bitmap::Bitmap;
use vm_memory::mmap::NewBitmap;
use vm_memory::{GuestMemoryAtomic, GuestMemoryMmap};
Expand Down Expand Up @@ -41,10 +41,10 @@ type GM<B> = GuestMemoryAtomic<GuestMemoryMmap<B>>;
pub enum Error {
/// Failed to create a new vhost-user handler.
NewVhostUserHandler(VhostUserHandlerError),
/// Failed creating vhost-user slave listener.
CreateSlaveListener(VhostUserError),
/// Failed creating vhost-user slave handler.
CreateSlaveReqHandler(VhostUserError),
/// Failed creating vhost-user backend listener.
CreateBackendListener(VhostUserError),
/// Failed creating vhost-user backend handler.
CreateBackendReqHandler(VhostUserError),
/// Failed starting daemon thread.
StartDaemon(std::io::Error),
/// Failed waiting for daemon thread.
Expand All @@ -57,8 +57,10 @@ impl Display for Error {
fn fmt(&self, f: &mut Formatter) -> std::fmt::Result {
match self {
Error::NewVhostUserHandler(e) => write!(f, "cannot create vhost user handler: {}", e),
Error::CreateSlaveListener(e) => write!(f, "cannot create slave listener: {}", e),
Error::CreateSlaveReqHandler(e) => write!(f, "cannot create slave req handler: {}", e),
Error::CreateBackendListener(e) => write!(f, "cannot create backend listener: {}", e),
Error::CreateBackendReqHandler(e) => {
write!(f, "cannot create backend req handler: {}", e)
}
Error::StartDaemon(e) => write!(f, "failed to start daemon: {}", e),
Error::WaitDaemon(_e) => write!(f, "failed to wait for daemon exit"),
Error::HandleRequest(e) => write!(f, "failed to handle request: {}", e),
Expand Down Expand Up @@ -114,7 +116,7 @@ where
/// it acts as a client or a server.
fn start_daemon(
&mut self,
mut handler: SlaveReqHandler<Mutex<VhostUserHandler<S, V, B>>>,
mut handler: BackendReqHandler<Mutex<VhostUserHandler<S, V, B>>>,
) -> Result<()> {
let handle = thread::Builder::new()
.name(self.name.clone())
Expand All @@ -133,9 +135,9 @@ where
/// that should be terminating once the other end of the socket (the VMM)
/// hangs up.
pub fn start_client(&mut self, socket_path: &str) -> Result<()> {
let slave_handler = SlaveReqHandler::connect(socket_path, self.handler.clone())
.map_err(Error::CreateSlaveReqHandler)?;
self.start_daemon(slave_handler)
let backend_handler = BackendReqHandler::connect(socket_path, self.handler.clone())
.map_err(Error::CreateBackendReqHandler)?;
self.start_daemon(backend_handler)
}

/// Listen to the vhost-user socket and run a dedicated thread handling all requests coming
Expand All @@ -146,19 +148,19 @@ where
// TODO: the current implementation has limitations that only one incoming connection will be
// handled from the listener. Should it be enhanced to support reconnection?
pub fn start(&mut self, listener: Listener) -> Result<()> {
let mut slave_listener = SlaveListener::new(listener, self.handler.clone())
.map_err(Error::CreateSlaveListener)?;
let slave_handler = self.accept(&mut slave_listener)?;
self.start_daemon(slave_handler)
let mut backend_listener = BackendListener::new(listener, self.handler.clone())
.map_err(Error::CreateBackendListener)?;
let backend_handler = self.accept(&mut backend_listener)?;
self.start_daemon(backend_handler)
}

fn accept(
&self,
slave_listener: &mut SlaveListener<Mutex<VhostUserHandler<S, V, B>>>,
) -> Result<SlaveReqHandler<Mutex<VhostUserHandler<S, V, B>>>> {
backend_listener: &mut BackendListener<Mutex<VhostUserHandler<S, V, B>>>,
) -> Result<BackendReqHandler<Mutex<VhostUserHandler<S, V, B>>>> {
loop {
match slave_listener.accept() {
Err(e) => return Err(Error::CreateSlaveListener(e)),
match backend_listener.accept() {
Err(e) => return Err(Error::CreateBackendListener(e)),
Ok(Some(v)) => return Ok(v),
Ok(None) => continue,
}
Expand Down
4 changes: 2 additions & 2 deletions crates/vhost-user-backend/src/vring.rs
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ pub trait VringT<M: GuestAddressSpace>:
/// Add an used descriptor into the used queue.
fn add_used(&self, desc_index: u16, len: u32) -> Result<(), VirtQueError>;

/// Notify the vhost-user master that used descriptors have been put into the used queue.
/// Notify the vhost-user frontend that used descriptors have been put into the used queue.
fn signal_used_queue(&self) -> io::Result<()>;

/// Enable event notification for queue.
Expand Down Expand Up @@ -145,7 +145,7 @@ impl<M: GuestAddressSpace> VringState<M> {
.add_used(self.mem.memory().deref(), desc_index, len)
}

/// Notify the vhost-user master that used descriptors have been put into the used queue.
/// Notify the vhost-user frontend that used descriptors have been put into the used queue.
pub fn signal_used_queue(&self) -> io::Result<()> {
if let Some(call) = self.call.as_ref() {
call.write(1)
Expand Down
Loading