diff --git a/.buildkite/custom-tests.json b/.buildkite/custom-tests.json
index b0da5ad..892cbb5 100644
--- a/.buildkite/custom-tests.json
+++ b/.buildkite/custom-tests.json
@@ -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"
]
diff --git a/coverage_config_aarch64.json b/coverage_config_aarch64.json
index 089bc19..12a512d 100644
--- a/coverage_config_aarch64.json
+++ b/coverage_config_aarch64.json
@@ -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"
}
diff --git a/coverage_config_x86_64.json b/coverage_config_x86_64.json
index f270b64..944803a 100644
--- a/coverage_config_x86_64.json
+++ b/coverage_config_x86_64.json
@@ -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"
}
diff --git a/crates/vhost-user-backend/Cargo.toml b/crates/vhost-user-backend/Cargo.toml
index a42ea78..8080850 100644
--- a/crates/vhost-user-backend/Cargo.toml
+++ b/crates/vhost-user-backend/Cargo.toml
@@ -14,7 +14,7 @@ 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"] }
@@ -22,6 +22,6 @@ 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"
diff --git a/crates/vhost/CHANGELOG.md b/crates/vhost/CHANGELOG.md
index af8c430..6175b40 100644
--- a/crates/vhost/CHANGELOG.md
+++ b/crates/vhost/CHANGELOG.md
@@ -4,6 +4,7 @@
### Added
### Changed
+- Change uses of master/slave for frontend/backend in the codebase.
### Fixed
diff --git a/crates/vhost/Cargo.toml b/crates/vhost/Cargo.toml
index 3ed9d09..d57dc8a 100644
--- a/crates/vhost/Cargo.toml
+++ b/crates/vhost/Cargo.toml
@@ -21,8 +21,8 @@ vhost-kern = []
vhost-vdpa = ["vhost-kern"]
vhost-net = ["vhost-kern"]
vhost-user = []
-vhost-user-master = ["vhost-user"]
-vhost-user-slave = ["vhost-user"]
+vhost-user-frontend = ["vhost-user"]
+vhost-user-backend = ["vhost-user"]
xen = ["vm-memory/xen"]
[dependencies]
diff --git a/crates/vhost/README.md b/crates/vhost/README.md
index 6f5f0e5..731ad0a 100644
--- a/crates/vhost/README.md
+++ b/crates/vhost/README.md
@@ -26,9 +26,9 @@ to establish virtqueue sharing with a user space process on the same host.
It uses communication over a Unix domain socket to share file descriptors in
the ancillary data of the message.
-The protocol defines two sides of the communication, master and slave.
-Master is the application that shares its virtqueues, slave is the consumer
-of the virtqueues. Master and slave can be either a client (i.e. connecting)
+The protocol defines two sides of the communication, frontend and backend.
+Frontend is the application that shares its virtqueues, backend is the consumer
+of the virtqueues. Frontend and backend can be either a client (i.e. connecting)
or server (listening) in the socket communication.
## Xen support
diff --git a/crates/vhost/docs/vhost_architecture.drawio b/crates/vhost/docs/vhost_architecture.drawio
index 8c669d8..610aff4 100644
--- a/crates/vhost/docs/vhost_architecture.drawio
+++ b/crates/vhost/docs/vhost_architecture.drawio
@@ -13,10 +13,10 @@
-
+
-
+
@@ -27,10 +27,10 @@
-
+
-
+
@@ -39,13 +39,13 @@
-
+
-
+
-
+
@@ -63,7 +63,7 @@
-
+
@@ -126,7 +126,7 @@
-
+
diff --git a/crates/vhost/src/lib.rs b/crates/vhost/src/lib.rs
index f8be913..1c82861 100644
--- a/crates/vhost/src/lib.rs
+++ b/crates/vhost/src/lib.rs
@@ -26,8 +26,8 @@
//! vhost implementation in the Linux kernel. It implements the control plane needed to establish
//! virtqueues sharing with a user space process on the same host. It uses communication over a
//! Unix domain socket to share file descriptors in the ancillary data of the message.
-//! The protocol defines 2 sides of the communication, master and slave. Master is the application
-//! that shares its virtqueues. Slave is the consumer of the virtqueues. Master and slave can be
+//! The protocol defines 2 sides of the communication, frontend and backend. Frontend is the application
+//! that shares its virtqueues. Backend is the consumer of the virtqueues. Frontend and backend can be
//! either a client (i.e. connecting) or server (listening) in the socket communication.
#![deny(missing_docs)]
diff --git a/crates/vhost/src/vhost_user/backend.rs b/crates/vhost/src/vhost_user/backend.rs
new file mode 100644
index 0000000..48e4457
--- /dev/null
+++ b/crates/vhost/src/vhost_user/backend.rs
@@ -0,0 +1,86 @@
+// Copyright (C) 2019 Alibaba Cloud Computing. All rights reserved.
+// SPDX-License-Identifier: Apache-2.0
+
+//! Traits and Structs for vhost-user backend.
+
+use std::sync::Arc;
+
+use super::connection::{Endpoint, Listener};
+use super::message::*;
+use super::{BackendReqHandler, Result, VhostUserBackendReqHandler};
+
+/// Vhost-user backend side connection listener.
+pub struct BackendListener {
+ listener: Listener,
+ backend: Option>,
+}
+
+/// Sets up a listener for incoming frontend connections, and handles construction
+/// of a Backend on success.
+impl BackendListener {
+ /// Create a unix domain socket for incoming frontend connections.
+ pub fn new(listener: Listener, backend: Arc) -> Result {
+ Ok(BackendListener {
+ listener,
+ backend: Some(backend),
+ })
+ }
+
+ /// Accept an incoming connection from the frontend, returning Some(Backend) on
+ /// success, or None if the socket is nonblocking and no incoming connection
+ /// was detected
+ pub fn accept(&mut self) -> Result>> {
+ if let Some(fd) = self.listener.accept()? {
+ return Ok(Some(BackendReqHandler::new(
+ Endpoint::::from_stream(fd),
+ self.backend.take().unwrap(),
+ )));
+ }
+ Ok(None)
+ }
+
+ /// Change blocking status on the listener.
+ pub fn set_nonblocking(&self, block: bool) -> Result<()> {
+ self.listener.set_nonblocking(block)
+ }
+}
+
+#[cfg(test)]
+mod tests {
+ use std::sync::Mutex;
+
+ use super::*;
+ use crate::vhost_user::dummy_backend::DummyBackendReqHandler;
+
+ #[test]
+ fn test_backend_listener_set_nonblocking() {
+ let backend = Arc::new(Mutex::new(DummyBackendReqHandler::new()));
+ let listener =
+ Listener::new("/tmp/vhost_user_lib_unit_test_backend_nonblocking", true).unwrap();
+ let backend_listener = BackendListener::new(listener, backend).unwrap();
+
+ backend_listener.set_nonblocking(true).unwrap();
+ backend_listener.set_nonblocking(false).unwrap();
+ backend_listener.set_nonblocking(false).unwrap();
+ backend_listener.set_nonblocking(true).unwrap();
+ backend_listener.set_nonblocking(true).unwrap();
+ }
+
+ #[cfg(feature = "vhost-user-frontend")]
+ #[test]
+ fn test_backend_listener_accept() {
+ use super::super::Frontend;
+
+ let path = "/tmp/vhost_user_lib_unit_test_backend_accept";
+ let backend = Arc::new(Mutex::new(DummyBackendReqHandler::new()));
+ let listener = Listener::new(path, true).unwrap();
+ let mut backend_listener = BackendListener::new(listener, backend).unwrap();
+
+ backend_listener.set_nonblocking(true).unwrap();
+ assert!(backend_listener.accept().unwrap().is_none());
+ assert!(backend_listener.accept().unwrap().is_none());
+
+ let _frontend = Frontend::connect(path, 1).unwrap();
+ let _backend = backend_listener.accept().unwrap().unwrap();
+ }
+}
diff --git a/crates/vhost/src/vhost_user/slave_req.rs b/crates/vhost/src/vhost_user/backend_req.rs
similarity index 52%
rename from crates/vhost/src/vhost_user/slave_req.rs
rename to crates/vhost/src/vhost_user/backend_req.rs
index ade1e91..b43982f 100644
--- a/crates/vhost/src/vhost_user/slave_req.rs
+++ b/crates/vhost/src/vhost_user/backend_req.rs
@@ -9,12 +9,12 @@ use std::sync::{Arc, Mutex, MutexGuard};
use super::connection::Endpoint;
use super::message::*;
-use super::{Error, HandlerResult, Result, VhostUserMasterReqHandler};
+use super::{Error, HandlerResult, Result, VhostUserFrontendReqHandler};
use vm_memory::ByteValued;
-struct SlaveInternal {
- sock: Endpoint,
+struct BackendInternal {
+ sock: Endpoint,
// Protocol feature VHOST_USER_PROTOCOL_F_REPLY_ACK has been negotiated.
reply_ack_negotiated: bool,
@@ -23,7 +23,7 @@ struct SlaveInternal {
error: Option,
}
-impl SlaveInternal {
+impl BackendInternal {
fn check_state(&self) -> Result {
match self.error {
Some(e) => Err(Error::SocketBroken(std::io::Error::from_raw_os_error(e))),
@@ -33,7 +33,7 @@ impl SlaveInternal {
fn send_message(
&mut self,
- request: SlaveReq,
+ request: BackendReq,
body: &T,
fds: Option<&[RawFd]>,
) -> Result {
@@ -49,7 +49,7 @@ impl SlaveInternal {
self.wait_for_ack(&hdr)
}
- fn wait_for_ack(&mut self, hdr: &VhostUserMsgHeader) -> Result {
+ fn wait_for_ack(&mut self, hdr: &VhostUserMsgHeader) -> Result {
self.check_state()?;
if !self.reply_ack_negotiated {
return Ok(0);
@@ -60,32 +60,32 @@ impl SlaveInternal {
return Err(Error::InvalidMessage);
}
if body.value != 0 {
- return Err(Error::MasterInternalError);
+ return Err(Error::FrontendInternalError);
}
Ok(body.value)
}
}
-/// Request proxy to send vhost-user slave requests to the master through the slave
+/// Request proxy to send vhost-user backend requests to the frontend through the backend
/// communication channel.
///
-/// The [Slave] acts as a message proxy to forward vhost-user slave requests to the
-/// master through the vhost-user slave communication channel. The forwarded messages will be
-/// handled by the [MasterReqHandler] server.
+/// The [Backend] acts as a message proxy to forward vhost-user backend requests to the
+/// frontend through the vhost-user backend communication channel. The forwarded messages will be
+/// handled by the [FrontendReqHandler] server.
///
-/// [Slave]: struct.Slave.html
-/// [MasterReqHandler]: struct.MasterReqHandler.html
+/// [Backend]: struct.Backend.html
+/// [FrontendReqHandler]: struct.FrontendReqHandler.html
#[derive(Clone)]
-pub struct Slave {
+pub struct Backend {
// underlying Unix domain socket for communication
- node: Arc>,
+ node: Arc>,
}
-impl Slave {
- fn new(ep: Endpoint) -> Self {
- Slave {
- node: Arc::new(Mutex::new(SlaveInternal {
+impl Backend {
+ fn new(ep: Endpoint) -> Self {
+ Backend {
+ node: Arc::new(Mutex::new(BackendInternal {
sock: ep,
reply_ack_negotiated: false,
error: None,
@@ -93,13 +93,13 @@ impl Slave {
}
}
- fn node(&self) -> MutexGuard {
+ fn node(&self) -> MutexGuard {
self.node.lock().unwrap()
}
fn send_message(
&self,
- request: SlaveReq,
+ request: BackendReq,
body: &T,
fds: Option<&[RawFd]>,
) -> io::Result {
@@ -110,13 +110,13 @@ impl Slave {
/// Create a new instance from a `UnixStream` object.
pub fn from_stream(sock: UnixStream) -> Self {
- Self::new(Endpoint::::from_stream(sock))
+ Self::new(Endpoint::::from_stream(sock))
}
/// Set the negotiation state of the `VHOST_USER_PROTOCOL_F_REPLY_ACK` protocol feature.
///
/// When the `VHOST_USER_PROTOCOL_F_REPLY_ACK` protocol feature has been negotiated,
- /// the "REPLY_ACK" flag will be set in the message header for every slave to master request
+ /// the "REPLY_ACK" flag will be set in the message header for every backend to frontend request
/// message.
pub fn set_reply_ack_flag(&self, enable: bool) {
self.node().reply_ack_negotiated = enable;
@@ -128,15 +128,15 @@ impl Slave {
}
}
-impl VhostUserMasterReqHandler for Slave {
- /// Forward vhost-user-fs map file requests to the slave.
- fn fs_slave_map(&self, fs: &VhostUserFSSlaveMsg, fd: &dyn AsRawFd) -> HandlerResult {
- self.send_message(SlaveReq::FS_MAP, fs, Some(&[fd.as_raw_fd()]))
+impl VhostUserFrontendReqHandler for Backend {
+ /// Forward vhost-user-fs map file requests to the backend.
+ fn fs_backend_map(&self, fs: &VhostUserFSBackendMsg, fd: &dyn AsRawFd) -> HandlerResult {
+ self.send_message(BackendReq::FS_MAP, fs, Some(&[fd.as_raw_fd()]))
}
- /// Forward vhost-user-fs unmap file requests to the master.
- fn fs_slave_unmap(&self, fs: &VhostUserFSSlaveMsg) -> HandlerResult {
- self.send_message(SlaveReq::FS_UNMAP, fs, None)
+ /// Forward vhost-user-fs unmap file requests to the frontend.
+ fn fs_backend_unmap(&self, fs: &VhostUserFSBackendMsg) -> HandlerResult {
+ self.send_message(BackendReq::FS_UNMAP, fs, None)
}
}
@@ -147,73 +147,73 @@ mod tests {
use super::*;
#[test]
- fn test_slave_req_set_failed() {
+ fn test_backend_req_set_failed() {
let (p1, _p2) = UnixStream::pair().unwrap();
- let slave = Slave::from_stream(p1);
+ let backend = Backend::from_stream(p1);
- assert!(slave.node().error.is_none());
- slave.set_failed(libc::EAGAIN);
- assert_eq!(slave.node().error, Some(libc::EAGAIN));
+ assert!(backend.node().error.is_none());
+ backend.set_failed(libc::EAGAIN);
+ assert_eq!(backend.node().error, Some(libc::EAGAIN));
}
#[test]
- fn test_slave_req_send_failure() {
+ fn test_backend_req_send_failure() {
let (p1, p2) = UnixStream::pair().unwrap();
- let slave = Slave::from_stream(p1);
+ let backend = Backend::from_stream(p1);
- slave.set_failed(libc::ECONNRESET);
- slave
- .fs_slave_map(&VhostUserFSSlaveMsg::default(), &p2)
+ backend.set_failed(libc::ECONNRESET);
+ backend
+ .fs_backend_map(&VhostUserFSBackendMsg::default(), &p2)
.unwrap_err();
- slave
- .fs_slave_unmap(&VhostUserFSSlaveMsg::default())
+ backend
+ .fs_backend_unmap(&VhostUserFSBackendMsg::default())
.unwrap_err();
- slave.node().error = None;
+ backend.node().error = None;
}
#[test]
- fn test_slave_req_recv_negative() {
+ fn test_backend_req_recv_negative() {
let (p1, p2) = UnixStream::pair().unwrap();
- let slave = Slave::from_stream(p1);
- let mut master = Endpoint::::from_stream(p2);
+ let backend = Backend::from_stream(p1);
+ let mut frontend = Endpoint::::from_stream(p2);
- let len = mem::size_of::();
+ let len = mem::size_of::();
let mut hdr = VhostUserMsgHeader::new(
- SlaveReq::FS_MAP,
+ BackendReq::FS_MAP,
VhostUserHeaderFlag::REPLY.bits(),
len as u32,
);
let body = VhostUserU64::new(0);
- master
- .send_message(&hdr, &body, Some(&[master.as_raw_fd()]))
+ frontend
+ .send_message(&hdr, &body, Some(&[frontend.as_raw_fd()]))
.unwrap();
- slave
- .fs_slave_map(&VhostUserFSSlaveMsg::default(), &master)
+ backend
+ .fs_backend_map(&VhostUserFSBackendMsg::default(), &frontend)
.unwrap();
- slave.set_reply_ack_flag(true);
- slave
- .fs_slave_map(&VhostUserFSSlaveMsg::default(), &master)
+ backend.set_reply_ack_flag(true);
+ backend
+ .fs_backend_map(&VhostUserFSBackendMsg::default(), &frontend)
.unwrap_err();
- hdr.set_code(SlaveReq::FS_UNMAP);
- master.send_message(&hdr, &body, None).unwrap();
- slave
- .fs_slave_map(&VhostUserFSSlaveMsg::default(), &master)
+ hdr.set_code(BackendReq::FS_UNMAP);
+ frontend.send_message(&hdr, &body, None).unwrap();
+ backend
+ .fs_backend_map(&VhostUserFSBackendMsg::default(), &frontend)
.unwrap_err();
- hdr.set_code(SlaveReq::FS_MAP);
+ hdr.set_code(BackendReq::FS_MAP);
let body = VhostUserU64::new(1);
- master.send_message(&hdr, &body, None).unwrap();
- slave
- .fs_slave_map(&VhostUserFSSlaveMsg::default(), &master)
+ frontend.send_message(&hdr, &body, None).unwrap();
+ backend
+ .fs_backend_map(&VhostUserFSBackendMsg::default(), &frontend)
.unwrap_err();
let body = VhostUserU64::new(0);
- master.send_message(&hdr, &body, None).unwrap();
- slave
- .fs_slave_map(&VhostUserFSSlaveMsg::default(), &master)
+ frontend.send_message(&hdr, &body, None).unwrap();
+ backend
+ .fs_backend_map(&VhostUserFSBackendMsg::default(), &frontend)
.unwrap();
}
}
diff --git a/crates/vhost/src/vhost_user/slave_req_handler.rs b/crates/vhost/src/vhost_user/backend_req_handler.rs
similarity index 82%
rename from crates/vhost/src/vhost_user/slave_req_handler.rs
rename to crates/vhost/src/vhost_user/backend_req_handler.rs
index e998339..feb763d 100644
--- a/crates/vhost/src/vhost_user/slave_req_handler.rs
+++ b/crates/vhost/src/vhost_user/backend_req_handler.rs
@@ -10,33 +10,33 @@ use std::sync::{Arc, Mutex};
use vm_memory::ByteValued;
+use super::backend_req::Backend;
use super::connection::Endpoint;
use super::message::*;
-use super::slave_req::Slave;
use super::{take_single_file, Error, Result};
-/// Services provided to the master by the slave with interior mutability.
+/// Services provided to the frontend by the backend with interior mutability.
///
-/// The [VhostUserSlaveReqHandler] trait defines the services provided to the master by the slave.
-/// And the [VhostUserSlaveReqHandlerMut] trait is a helper mirroring [VhostUserSlaveReqHandler],
+/// The [VhostUserBackendReqHandler] trait defines the services provided to the frontend by the backend.
+/// And the [VhostUserBackendReqHandlerMut] trait is a helper mirroring [VhostUserBackendReqHandler],
/// but without interior mutability.
-/// The vhost-user specification defines a master communication channel, by which masters could
-/// request services from slaves. The [VhostUserSlaveReqHandler] trait defines services provided by
-/// slaves, and it's used both on the master side and slave side.
+/// The vhost-user specification defines a frontend communication channel, by which frontends could
+/// request services from backends. The [VhostUserBackendReqHandler] trait defines services provided by
+/// backends, and it's used both on the frontend side and backend side.
///
-/// - on the master side, a stub forwarder implementing [VhostUserSlaveReqHandler] will proxy
-/// service requests to slaves.
-/// - on the slave side, the [SlaveReqHandler] will forward service requests to a handler
-/// implementing [VhostUserSlaveReqHandler].
+/// - on the frontend side, a stub forwarder implementing [VhostUserBackendReqHandler] will proxy
+/// service requests to backends.
+/// - on the backend side, the [BackendReqHandler] will forward service requests to a handler
+/// implementing [VhostUserBackendReqHandler].
///
-/// The [VhostUserSlaveReqHandler] trait is design with interior mutability to improve performance
+/// The [VhostUserBackendReqHandler] trait is design with interior mutability to improve performance
/// for multi-threading.
///
-/// [VhostUserSlaveReqHandler]: trait.VhostUserSlaveReqHandler.html
-/// [VhostUserSlaveReqHandlerMut]: trait.VhostUserSlaveReqHandlerMut.html
-/// [SlaveReqHandler]: struct.SlaveReqHandler.html
+/// [VhostUserBackendReqHandler]: trait.VhostUserBackendReqHandler.html
+/// [VhostUserBackendReqHandlerMut]: trait.VhostUserBackendReqHandlerMut.html
+/// [BackendReqHandler]: struct.BackendReqHandler.html
#[allow(missing_docs)]
-pub trait VhostUserSlaveReqHandler {
+pub trait VhostUserBackendReqHandler {
fn set_owner(&self) -> Result<()>;
fn reset_owner(&self) -> Result<()>;
fn get_features(&self) -> Result;
@@ -64,7 +64,7 @@ pub trait VhostUserSlaveReqHandler {
fn set_vring_enable(&self, index: u32, enable: bool) -> Result<()>;
fn get_config(&self, offset: u32, size: u32, flags: VhostUserConfigFlags) -> Result>;
fn set_config(&self, offset: u32, buf: &[u8], flags: VhostUserConfigFlags) -> Result<()>;
- fn set_slave_req_fd(&self, _slave: Slave) {}
+ fn set_backend_req_fd(&self, _backend: Backend) {}
fn get_inflight_fd(&self, inflight: &VhostUserInflight) -> Result<(VhostUserInflight, File)>;
fn set_inflight_fd(&self, inflight: &VhostUserInflight, file: File) -> Result<()>;
fn get_max_mem_slots(&self) -> Result;
@@ -72,11 +72,11 @@ pub trait VhostUserSlaveReqHandler {
fn remove_mem_region(&self, region: &VhostUserSingleMemoryRegion) -> Result<()>;
}
-/// Services provided to the master by the slave without interior mutability.
+/// Services provided to the frontend by the backend without interior mutability.
///
-/// This is a helper trait mirroring the [VhostUserSlaveReqHandler] trait.
+/// This is a helper trait mirroring the [VhostUserBackendReqHandler] trait.
#[allow(missing_docs)]
-pub trait VhostUserSlaveReqHandlerMut {
+pub trait VhostUserBackendReqHandlerMut {
fn set_owner(&mut self) -> Result<()>;
fn reset_owner(&mut self) -> Result<()>;
fn get_features(&mut self) -> Result;
@@ -109,7 +109,7 @@ pub trait VhostUserSlaveReqHandlerMut {
flags: VhostUserConfigFlags,
) -> Result>;
fn set_config(&mut self, offset: u32, buf: &[u8], flags: VhostUserConfigFlags) -> Result<()>;
- fn set_slave_req_fd(&mut self, _slave: Slave) {}
+ fn set_backend_req_fd(&mut self, _backend: Backend) {}
fn get_inflight_fd(
&mut self,
inflight: &VhostUserInflight,
@@ -120,7 +120,7 @@ pub trait VhostUserSlaveReqHandlerMut {
fn remove_mem_region(&mut self, region: &VhostUserSingleMemoryRegion) -> Result<()>;
}
-impl VhostUserSlaveReqHandler for Mutex {
+impl VhostUserBackendReqHandler for Mutex {
fn set_owner(&self) -> Result<()> {
self.lock().unwrap().set_owner()
}
@@ -203,8 +203,8 @@ impl VhostUserSlaveReqHandler for Mutex {
self.lock().unwrap().set_config(offset, buf, flags)
}
- 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 get_inflight_fd(&self, inflight: &VhostUserInflight) -> Result<(VhostUserInflight, File)> {
@@ -228,20 +228,20 @@ impl VhostUserSlaveReqHandler for Mutex {
}
}
-/// Server to handle service requests from masters from the master communication channel.
+/// Server to handle service requests from frontends from the frontend communication channel.
///
-/// The [SlaveReqHandler] acts as a server on the slave side, to handle service requests from
-/// masters on the master communication channel. It's actually a proxy invoking the registered
-/// handler implementing [VhostUserSlaveReqHandler] to do the real work.
+/// The [BackendReqHandler] acts as a server on the backend side, to handle service requests from
+/// frontends on the frontend communication channel. It's actually a proxy invoking the registered
+/// handler implementing [VhostUserBackendReqHandler] to do the real work.
///
-/// The lifetime of the SlaveReqHandler object should be the same as the underline Unix Domain
+/// The lifetime of the BackendReqHandler object should be the same as the underline Unix Domain
/// Socket, so it gets simpler to recover from disconnect.
///
-/// [VhostUserSlaveReqHandler]: trait.VhostUserSlaveReqHandler.html
-/// [SlaveReqHandler]: struct.SlaveReqHandler.html
-pub struct SlaveReqHandler {
+/// [VhostUserBackendReqHandler]: trait.VhostUserBackendReqHandler.html
+/// [BackendReqHandler]: struct.BackendReqHandler.html
+pub struct BackendReqHandler {
// underlying Unix domain socket for communication
- main_sock: Endpoint,
+ main_sock: Endpoint,
// the vhost-user backend device object
backend: Arc,
@@ -256,10 +256,10 @@ pub struct SlaveReqHandler {
error: Option,
}
-impl SlaveReqHandler {
- /// Create a vhost-user slave endpoint.
- pub(super) fn new(main_sock: Endpoint, backend: Arc) -> Self {
- SlaveReqHandler {
+impl BackendReqHandler {
+ /// Create a vhost-user backend endpoint.
+ pub(super) fn new(main_sock: Endpoint, backend: Arc) -> Self {
+ BackendReqHandler {
main_sock,
backend,
virtio_features: 0,
@@ -287,18 +287,18 @@ impl SlaveReqHandler {
}
}
- /// Create a vhost-user slave endpoint from a connected socket.
+ /// Create a vhost-user backend endpoint from a connected socket.
pub fn from_stream(socket: UnixStream, backend: Arc) -> Self {
Self::new(Endpoint::from_stream(socket), backend)
}
- /// Create a new vhost-user slave endpoint.
+ /// Create a new vhost-user backend endpoint.
///
/// # Arguments
/// * - `path` - path of Unix domain socket listener to connect to
- /// * - `backend` - handler for requests from the master to the slave
+ /// * - `backend` - handler for requests from the frontend to the backend
pub fn connect(path: &str, backend: Arc) -> Result {
- Ok(Self::new(Endpoint::::connect(path)?, backend))
+ Ok(Self::new(Endpoint::::connect(path)?, backend))
}
/// Mark endpoint as failed with specified error code.
@@ -306,9 +306,9 @@ impl SlaveReqHandler {
self.error = Some(error);
}
- /// Main entrance to server slave request from the slave communication channel.
+ /// Main entrance to server backend request from the backend communication channel.
///
- /// Receive and handle one incoming request message from the master. The caller needs to:
+ /// Receive and handle one incoming request message from the frontend. The caller needs to:
/// - serialize calls to this function
/// - decide what to do when error happens
/// - optional recover from failure
@@ -340,17 +340,17 @@ impl SlaveReqHandler {
};
match hdr.get_code() {
- Ok(MasterReq::SET_OWNER) => {
+ Ok(FrontendReq::SET_OWNER) => {
self.check_request_size(&hdr, size, 0)?;
let res = self.backend.set_owner();
self.send_ack_message(&hdr, res)?;
}
- Ok(MasterReq::RESET_OWNER) => {
+ Ok(FrontendReq::RESET_OWNER) => {
self.check_request_size(&hdr, size, 0)?;
let res = self.backend.reset_owner();
self.send_ack_message(&hdr, res)?;
}
- Ok(MasterReq::GET_FEATURES) => {
+ Ok(FrontendReq::GET_FEATURES) => {
self.check_request_size(&hdr, size, 0)?;
let features = self.backend.get_features()?;
let msg = VhostUserU64::new(features);
@@ -358,23 +358,23 @@ impl SlaveReqHandler {
self.virtio_features = features;
self.update_reply_ack_flag();
}
- Ok(MasterReq::SET_FEATURES) => {
+ Ok(FrontendReq::SET_FEATURES) => {
let msg = self.extract_request_body::(&hdr, size, &buf)?;
let res = self.backend.set_features(msg.value);
self.acked_virtio_features = msg.value;
self.update_reply_ack_flag();
self.send_ack_message(&hdr, res)?;
}
- Ok(MasterReq::SET_MEM_TABLE) => {
+ Ok(FrontendReq::SET_MEM_TABLE) => {
let res = self.set_mem_table(&hdr, size, &buf, files);
self.send_ack_message(&hdr, res)?;
}
- Ok(MasterReq::SET_VRING_NUM) => {
+ Ok(FrontendReq::SET_VRING_NUM) => {
let msg = self.extract_request_body::(&hdr, size, &buf)?;
let res = self.backend.set_vring_num(msg.index, msg.num);
self.send_ack_message(&hdr, res)?;
}
- Ok(MasterReq::SET_VRING_ADDR) => {
+ Ok(FrontendReq::SET_VRING_ADDR) => {
let msg = self.extract_request_body::(&hdr, size, &buf)?;
let flags = match VhostUserVringAddrFlags::from_bits(msg.flags) {
Some(val) => val,
@@ -390,35 +390,35 @@ impl SlaveReqHandler {
);
self.send_ack_message(&hdr, res)?;
}
- Ok(MasterReq::SET_VRING_BASE) => {
+ Ok(FrontendReq::SET_VRING_BASE) => {
let msg = self.extract_request_body::(&hdr, size, &buf)?;
let res = self.backend.set_vring_base(msg.index, msg.num);
self.send_ack_message(&hdr, res)?;
}
- Ok(MasterReq::GET_VRING_BASE) => {
+ Ok(FrontendReq::GET_VRING_BASE) => {
let msg = self.extract_request_body::(&hdr, size, &buf)?;
let reply = self.backend.get_vring_base(msg.index)?;
self.send_reply_message(&hdr, &reply)?;
}
- Ok(MasterReq::SET_VRING_CALL) => {
+ Ok(FrontendReq::SET_VRING_CALL) => {
self.check_request_size(&hdr, size, mem::size_of::())?;
let (index, file) = self.handle_vring_fd_request(&buf, files)?;
let res = self.backend.set_vring_call(index, file);
self.send_ack_message(&hdr, res)?;
}
- Ok(MasterReq::SET_VRING_KICK) => {
+ Ok(FrontendReq::SET_VRING_KICK) => {
self.check_request_size(&hdr, size, mem::size_of::())?;
let (index, file) = self.handle_vring_fd_request(&buf, files)?;
let res = self.backend.set_vring_kick(index, file);
self.send_ack_message(&hdr, res)?;
}
- Ok(MasterReq::SET_VRING_ERR) => {
+ Ok(FrontendReq::SET_VRING_ERR) => {
self.check_request_size(&hdr, size, mem::size_of::())?;
let (index, file) = self.handle_vring_fd_request(&buf, files)?;
let res = self.backend.set_vring_err(index, file);
self.send_ack_message(&hdr, res)?;
}
- Ok(MasterReq::GET_PROTOCOL_FEATURES) => {
+ Ok(FrontendReq::GET_PROTOCOL_FEATURES) => {
self.check_request_size(&hdr, size, 0)?;
let features = self.backend.get_protocol_features()?;
@@ -431,7 +431,7 @@ impl SlaveReqHandler {
self.protocol_features = features;
self.update_reply_ack_flag();
}
- Ok(MasterReq::SET_PROTOCOL_FEATURES) => {
+ Ok(FrontendReq::SET_PROTOCOL_FEATURES) => {
let msg = self.extract_request_body::(&hdr, size, &buf)?;
let res = self.backend.set_protocol_features(msg.value);
self.acked_protocol_features = msg.value;
@@ -441,14 +441,14 @@ impl SlaveReqHandler {
#[cfg(feature = "xen")]
self.check_proto_feature(VhostUserProtocolFeatures::XEN_MMAP)?;
}
- Ok(MasterReq::GET_QUEUE_NUM) => {
+ Ok(FrontendReq::GET_QUEUE_NUM) => {
self.check_proto_feature(VhostUserProtocolFeatures::MQ)?;
self.check_request_size(&hdr, size, 0)?;
let num = self.backend.get_queue_num()?;
let msg = VhostUserU64::new(num);
self.send_reply_message(&hdr, &msg)?;
}
- Ok(MasterReq::SET_VRING_ENABLE) => {
+ Ok(FrontendReq::SET_VRING_ENABLE) => {
let msg = self.extract_request_body::(&hdr, size, &buf)?;
self.check_feature(VhostUserVirtioFeatures::PROTOCOL_FEATURES)?;
let enable = match msg.num {
@@ -460,24 +460,24 @@ impl SlaveReqHandler {
let res = self.backend.set_vring_enable(msg.index, enable);
self.send_ack_message(&hdr, res)?;
}
- Ok(MasterReq::GET_CONFIG) => {
+ Ok(FrontendReq::GET_CONFIG) => {
self.check_proto_feature(VhostUserProtocolFeatures::CONFIG)?;
self.check_request_size(&hdr, size, hdr.get_size() as usize)?;
self.get_config(&hdr, &buf)?;
}
- Ok(MasterReq::SET_CONFIG) => {
+ Ok(FrontendReq::SET_CONFIG) => {
self.check_proto_feature(VhostUserProtocolFeatures::CONFIG)?;
self.check_request_size(&hdr, size, hdr.get_size() as usize)?;
let res = self.set_config(size, &buf);
self.send_ack_message(&hdr, res)?;
}
- Ok(MasterReq::SET_SLAVE_REQ_FD) => {
- self.check_proto_feature(VhostUserProtocolFeatures::SLAVE_REQ)?;
+ Ok(FrontendReq::SET_BACKEND_REQ_FD) => {
+ self.check_proto_feature(VhostUserProtocolFeatures::BACKEND_REQ)?;
self.check_request_size(&hdr, size, hdr.get_size() as usize)?;
- let res = self.set_slave_req_fd(files);
+ let res = self.set_backend_req_fd(files);
self.send_ack_message(&hdr, res)?;
}
- Ok(MasterReq::GET_INFLIGHT_FD) => {
+ Ok(FrontendReq::GET_INFLIGHT_FD) => {
self.check_proto_feature(VhostUserProtocolFeatures::INFLIGHT_SHMFD)?;
let msg = self.extract_request_body::(&hdr, size, &buf)?;
@@ -486,21 +486,21 @@ impl SlaveReqHandler {
self.main_sock
.send_message(&reply_hdr, &inflight, Some(&[file.as_raw_fd()]))?;
}
- Ok(MasterReq::SET_INFLIGHT_FD) => {
+ Ok(FrontendReq::SET_INFLIGHT_FD) => {
self.check_proto_feature(VhostUserProtocolFeatures::INFLIGHT_SHMFD)?;
let file = take_single_file(files).ok_or(Error::IncorrectFds)?;
let msg = self.extract_request_body::(&hdr, size, &buf)?;
let res = self.backend.set_inflight_fd(&msg, file);
self.send_ack_message(&hdr, res)?;
}
- Ok(MasterReq::GET_MAX_MEM_SLOTS) => {
+ Ok(FrontendReq::GET_MAX_MEM_SLOTS) => {
self.check_proto_feature(VhostUserProtocolFeatures::CONFIGURE_MEM_SLOTS)?;
self.check_request_size(&hdr, size, 0)?;
let num = self.backend.get_max_mem_slots()?;
let msg = VhostUserU64::new(num);
self.send_reply_message(&hdr, &msg)?;
}
- Ok(MasterReq::ADD_MEM_REG) => {
+ Ok(FrontendReq::ADD_MEM_REG) => {
self.check_proto_feature(VhostUserProtocolFeatures::CONFIGURE_MEM_SLOTS)?;
let mut files = files.ok_or(Error::InvalidParam)?;
if files.len() != 1 {
@@ -511,7 +511,7 @@ impl SlaveReqHandler {
let res = self.backend.add_mem_region(&msg, files.swap_remove(0));
self.send_ack_message(&hdr, res)?;
}
- Ok(MasterReq::REM_MEM_REG) => {
+ Ok(FrontendReq::REM_MEM_REG) => {
self.check_proto_feature(VhostUserProtocolFeatures::CONFIGURE_MEM_SLOTS)?;
let msg =
@@ -528,7 +528,7 @@ impl SlaveReqHandler {
fn set_mem_table(
&mut self,
- hdr: &VhostUserMsgHeader,
+ hdr: &VhostUserMsgHeader,
size: usize,
buf: &[u8],
files: Option>,
@@ -575,7 +575,7 @@ impl SlaveReqHandler {
self.backend.set_mem_table(regions, files)
}
- fn get_config(&mut self, hdr: &VhostUserMsgHeader, buf: &[u8]) -> Result<()> {
+ fn get_config(&mut self, hdr: &VhostUserMsgHeader, buf: &[u8]) -> Result<()> {
let payload_offset = mem::size_of::();
if buf.len() > MAX_MSG_SIZE || buf.len() < payload_offset {
return Err(Error::InvalidMessage);
@@ -594,9 +594,9 @@ impl SlaveReqHandler {
};
let res = self.backend.get_config(msg.offset, msg.size, flags);
- // vhost-user slave's payload size MUST match master's request
+ // vhost-user backend's payload size MUST match frontend's request
// on success, uses zero length of payload to indicate an error
- // to vhost-user master.
+ // to vhost-user frontend.
match res {
Ok(ref buf) if buf.len() == msg.size as usize => {
let reply = VhostUserConfig::new(msg.offset, buf.len() as u32, flags);
@@ -632,14 +632,14 @@ impl SlaveReqHandler {
.set_config(msg.offset, &buf[mem::size_of::()..], flags)
}
- fn set_slave_req_fd(&mut self, files: Option>) -> Result<()> {
+ fn set_backend_req_fd(&mut self, files: Option>) -> Result<()> {
let file = take_single_file(files).ok_or(Error::InvalidMessage)?;
// SAFETY: Safe because we have ownership of the files that were
// checked when received. We have to trust that they are Unix sockets
// since we have no way to check this. If not, it will fail later.
let sock = unsafe { UnixStream::from_raw_fd(file.into_raw_fd()) };
- let slave = Slave::from_stream(sock);
- self.backend.set_slave_req_fd(slave);
+ let backend = Backend::from_stream(sock);
+ self.backend.set_backend_req_fd(backend);
Ok(())
}
@@ -682,7 +682,7 @@ impl SlaveReqHandler {
fn check_request_size(
&self,
- hdr: &VhostUserMsgHeader,
+ hdr: &VhostUserMsgHeader,
size: usize,
expected: usize,
) -> Result<()> {
@@ -698,20 +698,20 @@ impl SlaveReqHandler {
fn check_attached_files(
&self,
- hdr: &VhostUserMsgHeader,
+ hdr: &VhostUserMsgHeader,
files: &Option>,
) -> Result<()> {
match hdr.get_code() {
Ok(
- MasterReq::SET_MEM_TABLE
- | MasterReq::SET_VRING_CALL
- | MasterReq::SET_VRING_KICK
- | MasterReq::SET_VRING_ERR
- | MasterReq::SET_LOG_BASE
- | MasterReq::SET_LOG_FD
- | MasterReq::SET_SLAVE_REQ_FD
- | MasterReq::SET_INFLIGHT_FD
- | MasterReq::ADD_MEM_REG,
+ FrontendReq::SET_MEM_TABLE
+ | FrontendReq::SET_VRING_CALL
+ | FrontendReq::SET_VRING_KICK
+ | FrontendReq::SET_VRING_ERR
+ | FrontendReq::SET_LOG_BASE
+ | FrontendReq::SET_LOG_FD
+ | FrontendReq::SET_BACKEND_REQ_FD
+ | FrontendReq::SET_INFLIGHT_FD
+ | FrontendReq::ADD_MEM_REG,
) => Ok(()),
_ if files.is_some() => Err(Error::InvalidMessage),
_ => Ok(()),
@@ -720,7 +720,7 @@ impl SlaveReqHandler {
fn extract_request_body(
&self,
- hdr: &VhostUserMsgHeader,
+ hdr: &VhostUserMsgHeader,
size: usize,
buf: &[u8],
) -> Result {
@@ -748,9 +748,9 @@ impl SlaveReqHandler {
fn new_reply_header(
&self,
- req: &VhostUserMsgHeader,
+ req: &VhostUserMsgHeader,
payload_size: usize,
- ) -> Result> {
+ ) -> Result> {
if mem::size_of::() > MAX_MSG_SIZE
|| payload_size > MAX_MSG_SIZE
|| mem::size_of::() + payload_size > MAX_MSG_SIZE
@@ -767,7 +767,7 @@ impl SlaveReqHandler {
fn send_ack_message(
&mut self,
- req: &VhostUserMsgHeader,
+ req: &VhostUserMsgHeader,
res: Result<()>,
) -> Result<()> {
if self.reply_ack_enabled && req.is_need_reply() {
@@ -784,7 +784,7 @@ impl SlaveReqHandler {
fn send_reply_message(
&mut self,
- req: &VhostUserMsgHeader,
+ req: &VhostUserMsgHeader,
msg: &T,
) -> Result<()> {
let hdr = self.new_reply_header::(req, 0)?;
@@ -794,7 +794,7 @@ impl SlaveReqHandler {
fn send_reply_with_payload(
&mut self,
- req: &VhostUserMsgHeader,
+ req: &VhostUserMsgHeader,
msg: &T,
payload: &[u8],
) -> Result<()> {
@@ -805,7 +805,7 @@ impl SlaveReqHandler {
}
}
-impl AsRawFd for SlaveReqHandler {
+impl AsRawFd for BackendReqHandler {
fn as_raw_fd(&self) -> RawFd {
self.main_sock.as_raw_fd()
}
@@ -816,14 +816,14 @@ mod tests {
use std::os::unix::io::AsRawFd;
use super::*;
- use crate::vhost_user::dummy_slave::DummySlaveReqHandler;
+ use crate::vhost_user::dummy_backend::DummyBackendReqHandler;
#[test]
- fn test_slave_req_handler_new() {
+ fn test_backend_req_handler_new() {
let (p1, _p2) = UnixStream::pair().unwrap();
- let endpoint = Endpoint::::from_stream(p1);
- let backend = Arc::new(Mutex::new(DummySlaveReqHandler::new()));
- let mut handler = SlaveReqHandler::new(endpoint, backend);
+ let endpoint = Endpoint::::from_stream(p1);
+ let backend = Arc::new(Mutex::new(DummyBackendReqHandler::new()));
+ let mut handler = BackendReqHandler::new(endpoint, backend);
handler.check_state().unwrap();
handler.set_failed(libc::EAGAIN);
diff --git a/crates/vhost/src/vhost_user/connection.rs b/crates/vhost/src/vhost_user/connection.rs
index 4a62e12..3edda33 100644
--- a/crates/vhost/src/vhost_user/connection.rs
+++ b/crates/vhost/src/vhost_user/connection.rs
@@ -669,23 +669,23 @@ mod tests {
let path = temp_path();
let listener = Listener::new(&path, true).unwrap();
listener.set_nonblocking(true).unwrap();
- let mut master = Endpoint::::connect(&path).unwrap();
+ let mut frontend = Endpoint::::connect(&path).unwrap();
let sock = listener.accept().unwrap().unwrap();
- let mut slave = Endpoint::::from_stream(sock);
+ let mut backend = Endpoint::::from_stream(sock);
let buf1 = vec![0x1, 0x2, 0x3, 0x4];
- let mut len = master.send_slice(&buf1[..], None).unwrap();
+ let mut len = frontend.send_slice(&buf1[..], None).unwrap();
assert_eq!(len, 4);
- let (bytes, buf2, _) = slave.recv_into_buf(0x1000).unwrap();
+ let (bytes, buf2, _) = backend.recv_into_buf(0x1000).unwrap();
assert_eq!(bytes, 4);
assert_eq!(&buf1[..], &buf2[..bytes]);
- len = master.send_slice(&buf1[..], None).unwrap();
+ len = frontend.send_slice(&buf1[..], None).unwrap();
assert_eq!(len, 4);
- let (bytes, buf2, _) = slave.recv_into_buf(0x2).unwrap();
+ let (bytes, buf2, _) = backend.recv_into_buf(0x2).unwrap();
assert_eq!(bytes, 2);
assert_eq!(&buf1[..2], &buf2[..]);
- let (bytes, buf2, _) = slave.recv_into_buf(0x2).unwrap();
+ let (bytes, buf2, _) = backend.recv_into_buf(0x2).unwrap();
assert_eq!(bytes, 2);
assert_eq!(&buf1[2..], &buf2[..]);
}
@@ -695,21 +695,21 @@ mod tests {
let path = temp_path();
let listener = Listener::new(&path, true).unwrap();
listener.set_nonblocking(true).unwrap();
- let mut master = Endpoint::::connect(&path).unwrap();
+ let mut frontend = Endpoint::::connect(&path).unwrap();
let sock = listener.accept().unwrap().unwrap();
- let mut slave = Endpoint::::from_stream(sock);
+ let mut backend = Endpoint::::from_stream(sock);
let mut fd = TempFile::new().unwrap().into_file();
write!(fd, "test").unwrap();
// Normal case for sending/receiving file descriptors
let buf1 = vec![0x1, 0x2, 0x3, 0x4];
- let len = master
+ let len = frontend
.send_slice(&buf1[..], Some(&[fd.as_raw_fd()]))
.unwrap();
assert_eq!(len, 4);
- let (bytes, buf2, files) = slave.recv_into_buf(4).unwrap();
+ let (bytes, buf2, files) = backend.recv_into_buf(4).unwrap();
assert_eq!(bytes, 4);
assert_eq!(&buf1[..], &buf2[..]);
assert!(files.is_some());
@@ -726,7 +726,7 @@ mod tests {
// Following communication pattern should work:
// Sending side: data(header, body) with fds
// Receiving side: data(header) with fds, data(body)
- let len = master
+ let len = frontend
.send_slice(
&buf1[..],
Some(&[fd.as_raw_fd(), fd.as_raw_fd(), fd.as_raw_fd()]),
@@ -734,7 +734,7 @@ mod tests {
.unwrap();
assert_eq!(len, 4);
- let (bytes, buf2, files) = slave.recv_into_buf(0x2).unwrap();
+ let (bytes, buf2, files) = backend.recv_into_buf(0x2).unwrap();
assert_eq!(bytes, 2);
assert_eq!(&buf1[..2], &buf2[..]);
assert!(files.is_some());
@@ -747,7 +747,7 @@ mod tests {
file.read_to_string(&mut content).unwrap();
assert_eq!(content, "test");
}
- let (bytes, buf2, files) = slave.recv_into_buf(0x2).unwrap();
+ let (bytes, buf2, files) = backend.recv_into_buf(0x2).unwrap();
assert_eq!(bytes, 2);
assert_eq!(&buf1[2..], &buf2[..]);
assert!(files.is_none());
@@ -755,7 +755,7 @@ mod tests {
// Following communication pattern should not work:
// Sending side: data(header, body) with fds
// Receiving side: data(header), data(body) with fds
- let len = master
+ let len = frontend
.send_slice(
&buf1[..],
Some(&[fd.as_raw_fd(), fd.as_raw_fd(), fd.as_raw_fd()]),
@@ -763,10 +763,10 @@ mod tests {
.unwrap();
assert_eq!(len, 4);
- let (bytes, buf4) = slave.recv_data(2).unwrap();
+ let (bytes, buf4) = backend.recv_data(2).unwrap();
assert_eq!(bytes, 2);
assert_eq!(&buf1[..2], &buf4[..]);
- let (bytes, buf2, files) = slave.recv_into_buf(0x2).unwrap();
+ let (bytes, buf2, files) = backend.recv_into_buf(0x2).unwrap();
assert_eq!(bytes, 2);
assert_eq!(&buf1[2..], &buf2[..]);
assert!(files.is_none());
@@ -774,9 +774,9 @@ mod tests {
// Following communication pattern should work:
// Sending side: data, data with fds
// Receiving side: data, data with fds
- let len = master.send_slice(&buf1[..], None).unwrap();
+ let len = frontend.send_slice(&buf1[..], None).unwrap();
assert_eq!(len, 4);
- let len = master
+ let len = frontend
.send_slice(
&buf1[..],
Some(&[fd.as_raw_fd(), fd.as_raw_fd(), fd.as_raw_fd()]),
@@ -784,12 +784,12 @@ mod tests {
.unwrap();
assert_eq!(len, 4);
- let (bytes, buf2, files) = slave.recv_into_buf(0x4).unwrap();
+ let (bytes, buf2, files) = backend.recv_into_buf(0x4).unwrap();
assert_eq!(bytes, 4);
assert_eq!(&buf1[..], &buf2[..]);
assert!(files.is_none());
- let (bytes, buf2, files) = slave.recv_into_buf(0x2).unwrap();
+ let (bytes, buf2, files) = backend.recv_into_buf(0x2).unwrap();
assert_eq!(bytes, 2);
assert_eq!(&buf1[..2], &buf2[..]);
assert!(files.is_some());
@@ -802,7 +802,7 @@ mod tests {
file.read_to_string(&mut content).unwrap();
assert_eq!(content, "test");
}
- let (bytes, buf2, files) = slave.recv_into_buf(0x2).unwrap();
+ let (bytes, buf2, files) = backend.recv_into_buf(0x2).unwrap();
assert_eq!(bytes, 2);
assert_eq!(&buf1[2..], &buf2[..]);
assert!(files.is_none());
@@ -810,9 +810,9 @@ mod tests {
// Following communication pattern should not work:
// Sending side: data1, data2 with fds
// Receiving side: data + partial of data2, left of data2 with fds
- let len = master.send_slice(&buf1[..], None).unwrap();
+ let len = frontend.send_slice(&buf1[..], None).unwrap();
assert_eq!(len, 4);
- let len = master
+ let len = frontend
.send_slice(
&buf1[..],
Some(&[fd.as_raw_fd(), fd.as_raw_fd(), fd.as_raw_fd()]),
@@ -820,15 +820,15 @@ mod tests {
.unwrap();
assert_eq!(len, 4);
- let (bytes, _) = slave.recv_data(5).unwrap();
+ let (bytes, _) = backend.recv_data(5).unwrap();
assert_eq!(bytes, 5);
- let (bytes, _, files) = slave.recv_into_buf(0x4).unwrap();
+ let (bytes, _, files) = backend.recv_into_buf(0x4).unwrap();
assert_eq!(bytes, 3);
assert!(files.is_none());
// If the target fd array is too small, extra file descriptors will get lost.
- let len = master
+ let len = frontend
.send_slice(
&buf1[..],
Some(&[fd.as_raw_fd(), fd.as_raw_fd(), fd.as_raw_fd()]),
@@ -836,7 +836,7 @@ mod tests {
.unwrap();
assert_eq!(len, 4);
- let (bytes, _, files) = slave.recv_into_buf(0x4).unwrap();
+ let (bytes, _, files) = backend.recv_into_buf(0x4).unwrap();
assert_eq!(bytes, 4);
assert!(files.is_some());
}
@@ -846,15 +846,15 @@ mod tests {
let path = temp_path();
let listener = Listener::new(&path, true).unwrap();
listener.set_nonblocking(true).unwrap();
- let mut master = Endpoint::::connect(&path).unwrap();
+ let mut frontend = Endpoint::::connect(&path).unwrap();
let sock = listener.accept().unwrap().unwrap();
- let mut slave = Endpoint::::from_stream(sock);
+ let mut backend = Endpoint::::from_stream(sock);
let mut hdr1 =
- VhostUserMsgHeader::new(MasterReq::GET_FEATURES, 0, mem::size_of::() as u32);
+ VhostUserMsgHeader::new(FrontendReq::GET_FEATURES, 0, mem::size_of::() as u32);
hdr1.set_need_reply(true);
let features1 = 0x1u64;
- master.send_message(&hdr1, &features1, None).unwrap();
+ frontend.send_message(&hdr1, &features1, None).unwrap();
let mut features2 = 0u64;
@@ -865,14 +865,14 @@ mod tests {
mem::size_of::(),
)
};
- let (hdr2, bytes, files) = slave.recv_body_into_buf(slice).unwrap();
+ let (hdr2, bytes, files) = backend.recv_body_into_buf(slice).unwrap();
assert_eq!(hdr1, hdr2);
assert_eq!(bytes, 8);
assert_eq!(features1, features2);
assert!(files.is_none());
- master.send_header(&hdr1, None).unwrap();
- let (hdr2, files) = slave.recv_header().unwrap();
+ frontend.send_header(&hdr1, None).unwrap();
+ let (hdr2, files) = backend.recv_header().unwrap();
assert_eq!(hdr1, hdr2);
assert!(files.is_none());
}
@@ -881,13 +881,13 @@ mod tests {
fn partial_message() {
let path = temp_path();
let listener = Listener::new(&path, true).unwrap();
- let mut master = UnixStream::connect(&path).unwrap();
+ let mut frontend = UnixStream::connect(&path).unwrap();
let sock = listener.accept().unwrap().unwrap();
- let mut slave = Endpoint::::from_stream(sock);
+ let mut backend = Endpoint::::from_stream(sock);
- write!(master, "a").unwrap();
- drop(master);
- assert!(matches!(slave.recv_header(), Err(Error::PartialMessage)));
+ write!(frontend, "a").unwrap();
+ drop(frontend);
+ assert!(matches!(backend.recv_header(), Err(Error::PartialMessage)));
}
#[test]
@@ -896,8 +896,8 @@ mod tests {
let listener = Listener::new(&path, true).unwrap();
let _ = UnixStream::connect(&path).unwrap();
let sock = listener.accept().unwrap().unwrap();
- let mut slave = Endpoint::::from_stream(sock);
+ let mut backend = Endpoint::::from_stream(sock);
- assert!(matches!(slave.recv_header(), Err(Error::Disconnected)));
+ assert!(matches!(backend.recv_header(), Err(Error::Disconnected)));
}
}
diff --git a/crates/vhost/src/vhost_user/dummy_slave.rs b/crates/vhost/src/vhost_user/dummy_backend.rs
similarity index 96%
rename from crates/vhost/src/vhost_user/dummy_slave.rs
rename to crates/vhost/src/vhost_user/dummy_backend.rs
index ae728a0..060a344 100644
--- a/crates/vhost/src/vhost_user/dummy_slave.rs
+++ b/crates/vhost/src/vhost_user/dummy_backend.rs
@@ -12,7 +12,7 @@ pub const MAX_MEM_SLOTS: usize = 32;
pub const VIRTIO_FEATURES: u64 = 0x40000003;
#[derive(Default)]
-pub struct DummySlaveReqHandler {
+pub struct DummyBackendReqHandler {
pub owned: bool,
pub features_acked: bool,
pub acked_features: u64,
@@ -28,9 +28,9 @@ pub struct DummySlaveReqHandler {
pub inflight_file: Option,
}
-impl DummySlaveReqHandler {
+impl DummyBackendReqHandler {
pub fn new() -> Self {
- DummySlaveReqHandler {
+ DummyBackendReqHandler {
queue_num: MAX_QUEUE_NUM,
..Default::default()
}
@@ -55,7 +55,7 @@ impl DummySlaveReqHandler {
}
}
-impl VhostUserSlaveReqHandlerMut for DummySlaveReqHandler {
+impl VhostUserBackendReqHandlerMut for DummyBackendReqHandler {
fn set_owner(&mut self) -> Result<()> {
if self.owned {
return Err(Error::InvalidOperation("already claimed"));
@@ -193,10 +193,10 @@ impl VhostUserSlaveReqHandlerMut for DummySlaveReqHandler {
}
fn set_protocol_features(&mut self, features: u64) -> Result<()> {
- // 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.
- // What happens if the master calls set_features() with
+ // What happens if the frontend calls set_features() with
// VHOST_USER_F_PROTOCOL_FEATURES cleared after calling this
// interface?
self.acked_protocol_features = features;
@@ -216,7 +216,7 @@ impl VhostUserSlaveReqHandlerMut for DummySlaveReqHandler {
return Err(Error::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.
diff --git a/crates/vhost/src/vhost_user/master.rs b/crates/vhost/src/vhost_user/frontend.rs
similarity index 77%
rename from crates/vhost/src/vhost_user/master.rs
rename to crates/vhost/src/vhost_user/frontend.rs
index 030e894..af2f2bb 100644
--- a/crates/vhost/src/vhost_user/master.rs
+++ b/crates/vhost/src/vhost_user/frontend.rs
@@ -1,7 +1,7 @@
// Copyright (C) 2019 Alibaba Cloud Computing. All rights reserved.
// SPDX-License-Identifier: Apache-2.0
-//! Traits and Struct for vhost-user master.
+//! Traits and Struct for vhost-user frontend.
use std::fs::File;
use std::mem;
@@ -21,8 +21,8 @@ use crate::backend::{
};
use crate::{Error, Result};
-/// Trait for vhost-user master to provide extra methods not covered by the VhostBackend yet.
-pub trait VhostUserMaster: VhostBackend {
+/// Trait for vhost-user frontend to provide extra methods not covered by the VhostBackend yet.
+pub trait VhostUserFrontend: VhostBackend {
/// Get the protocol feature bitmask from the underlying vhost implementation.
fn get_protocol_features(&mut self) -> Result;
@@ -32,9 +32,9 @@ pub trait VhostUserMaster: VhostBackend {
/// Query how many queues the backend supports.
fn get_queue_num(&mut self) -> Result;
- /// Signal slave to enable or disable corresponding vring.
+ /// Signal backend to enable or disable corresponding vring.
///
- /// Slave must not pass data to/from the backend until ring is enabled by
+ /// 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.
fn set_vring_enable(&mut self, queue_index: usize, enable: bool) -> Result<()>;
@@ -52,8 +52,8 @@ pub trait VhostUserMaster: VhostBackend {
/// destination host to set readonly configuration space fields.
fn set_config(&mut self, offset: u32, flags: VhostUserConfigFlags, buf: &[u8]) -> Result<()>;
- /// Setup slave communication channel.
- fn set_slave_request_fd(&mut self, fd: &dyn AsRawFd) -> Result<()>;
+ /// Setup backend communication channel.
+ fn set_backend_request_fd(&mut self, fd: &dyn AsRawFd) -> Result<()>;
/// Retrieve shared buffer for inflight I/O tracking.
fn get_inflight_fd(
@@ -78,17 +78,17 @@ fn error_code(err: VhostUserError) -> Result {
Err(Error::VhostUserProtocol(err))
}
-/// Struct for the vhost-user master endpoint.
+/// Struct for the vhost-user frontend endpoint.
#[derive(Clone)]
-pub struct Master {
- node: Arc>,
+pub struct Frontend {
+ node: Arc>,
}
-impl Master {
+impl Frontend {
/// Create a new instance.
- fn new(ep: Endpoint, max_queue_num: u64) -> Self {
- Master {
- node: Arc::new(Mutex::new(MasterInternal {
+ fn new(ep: Endpoint, max_queue_num: u64) -> Self {
+ Frontend {
+ node: Arc::new(Mutex::new(FrontendInternal {
main_sock: ep,
virtio_features: 0,
acked_virtio_features: 0,
@@ -102,16 +102,16 @@ impl Master {
}
}
- fn node(&self) -> MutexGuard {
+ fn node(&self) -> MutexGuard {
self.node.lock().unwrap()
}
/// Create a new instance from a Unix stream socket.
pub fn from_stream(sock: UnixStream, max_queue_num: u64) -> Self {
- Self::new(Endpoint::::from_stream(sock), max_queue_num)
+ Self::new(Endpoint::::from_stream(sock), max_queue_num)
}
- /// Create a new vhost-user master endpoint.
+ /// Create a new vhost-user frontend endpoint.
///
/// Will retry as the backend may not be ready to accept the connection.
///
@@ -120,7 +120,7 @@ impl Master {
pub fn connect>(path: P, max_queue_num: u64) -> Result {
let mut retry_count = 5;
let endpoint = loop {
- match Endpoint::::connect(&path) {
+ match Endpoint::::connect(&path) {
Ok(endpoint) => break Ok(endpoint),
Err(e) => match &e {
VhostUserError::SocketConnect(why) => {
@@ -147,11 +147,11 @@ impl Master {
}
}
-impl VhostBackend for Master {
+impl VhostBackend for Frontend {
/// Get from the underlying vhost implementation the feature bitmask.
fn get_features(&self) -> Result {
let mut node = self.node();
- let hdr = node.send_request_header(MasterReq::GET_FEATURES, None)?;
+ let hdr = node.send_request_header(FrontendReq::GET_FEATURES, None)?;
let val = node.recv_reply::(&hdr)?;
node.virtio_features = val.value;
Ok(node.virtio_features)
@@ -161,27 +161,27 @@ impl VhostBackend for Master {
fn set_features(&self, features: u64) -> Result<()> {
let mut node = self.node();
let val = VhostUserU64::new(features);
- let hdr = node.send_request_with_body(MasterReq::SET_FEATURES, &val, None)?;
+ let hdr = node.send_request_with_body(FrontendReq::SET_FEATURES, &val, None)?;
node.acked_virtio_features = features & node.virtio_features;
node.wait_for_ack(&hdr).map_err(|e| e.into())
}
- /// Set the current Master as an owner of the session.
+ /// Set the current Frontend as an owner of the session.
fn set_owner(&self) -> Result<()> {
// We unwrap() the return value to assert that we are not expecting threads to ever fail
// while holding the lock.
let mut node = self.node();
- let hdr = node.send_request_header(MasterReq::SET_OWNER, None)?;
+ let hdr = node.send_request_header(FrontendReq::SET_OWNER, None)?;
node.wait_for_ack(&hdr).map_err(|e| e.into())
}
fn reset_owner(&self) -> Result<()> {
let mut node = self.node();
- let hdr = node.send_request_header(MasterReq::RESET_OWNER, None)?;
+ let hdr = node.send_request_header(FrontendReq::RESET_OWNER, None)?;
node.wait_for_ack(&hdr).map_err(|e| e.into())
}
- /// Set the memory map regions on the slave so it can translate the vring
+ /// Set the memory map regions on the backend so it can translate the vring
/// addresses. In the ancillary data there is an array of file descriptors
fn set_mem_table(&self, regions: &[VhostUserMemoryRegionInfo]) -> Result<()> {
if regions.is_empty() || regions.len() > MAX_ATTACHED_FD_ENTRIES {
@@ -202,7 +202,7 @@ impl VhostBackend for Master {
// SAFETY: Safe because ctx.regions is a valid Vec() at this point.
let (_, payload, _) = unsafe { ctx.regions.align_to::() };
let hdr = node.send_request_with_payload(
- MasterReq::SET_MEM_TABLE,
+ FrontendReq::SET_MEM_TABLE,
&body,
payload,
Some(ctx.fds.as_slice()),
@@ -225,13 +225,13 @@ impl VhostBackend for Master {
mmap_offset: region.mmap_offset,
};
let hdr = node.send_request_with_body(
- MasterReq::SET_LOG_BASE,
+ FrontendReq::SET_LOG_BASE,
&log,
Some(&[region.mmap_handle]),
)?;
node.wait_for_ack(&hdr).map_err(|e| e.into())
} else {
- let _ = node.send_request_with_body(MasterReq::SET_LOG_BASE, &val, None)?;
+ let _ = node.send_request_with_body(FrontendReq::SET_LOG_BASE, &val, None)?;
Ok(())
}
}
@@ -239,7 +239,7 @@ impl VhostBackend for Master {
fn set_log_fd(&self, fd: RawFd) -> Result<()> {
let mut node = self.node();
let fds = [fd];
- let hdr = node.send_request_header(MasterReq::SET_LOG_FD, Some(&fds))?;
+ let hdr = node.send_request_header(FrontendReq::SET_LOG_FD, Some(&fds))?;
node.wait_for_ack(&hdr).map_err(|e| e.into())
}
@@ -251,7 +251,7 @@ impl VhostBackend for Master {
}
let val = VhostUserVringState::new(queue_index as u32, num.into());
- let hdr = node.send_request_with_body(MasterReq::SET_VRING_NUM, &val, None)?;
+ let hdr = node.send_request_with_body(FrontendReq::SET_VRING_NUM, &val, None)?;
node.wait_for_ack(&hdr).map_err(|e| e.into())
}
@@ -265,7 +265,7 @@ impl VhostBackend for Master {
}
let val = VhostUserVringAddr::from_config_data(queue_index as u32, config_data);
- let hdr = node.send_request_with_body(MasterReq::SET_VRING_ADDR, &val, None)?;
+ let hdr = node.send_request_with_body(FrontendReq::SET_VRING_ADDR, &val, None)?;
node.wait_for_ack(&hdr).map_err(|e| e.into())
}
@@ -277,7 +277,7 @@ impl VhostBackend for Master {
}
let val = VhostUserVringState::new(queue_index as u32, base.into());
- let hdr = node.send_request_with_body(MasterReq::SET_VRING_BASE, &val, None)?;
+ let hdr = node.send_request_with_body(FrontendReq::SET_VRING_BASE, &val, None)?;
node.wait_for_ack(&hdr).map_err(|e| e.into())
}
@@ -288,7 +288,7 @@ impl VhostBackend for Master {
}
let req = VhostUserVringState::new(queue_index as u32, 0);
- let hdr = node.send_request_with_body(MasterReq::GET_VRING_BASE, &req, None)?;
+ let hdr = node.send_request_with_body(FrontendReq::GET_VRING_BASE, &req, None)?;
let reply = node.recv_reply::(&hdr)?;
Ok(reply.num)
}
@@ -302,7 +302,8 @@ impl VhostBackend for Master {
if queue_index as u64 >= node.max_queue_num {
return error_code(VhostUserError::InvalidParam);
}
- let hdr = node.send_fd_for_vring(MasterReq::SET_VRING_CALL, queue_index, fd.as_raw_fd())?;
+ let hdr =
+ node.send_fd_for_vring(FrontendReq::SET_VRING_CALL, queue_index, fd.as_raw_fd())?;
node.wait_for_ack(&hdr).map_err(|e| e.into())
}
@@ -315,7 +316,8 @@ impl VhostBackend for Master {
if queue_index as u64 >= node.max_queue_num {
return error_code(VhostUserError::InvalidParam);
}
- let hdr = node.send_fd_for_vring(MasterReq::SET_VRING_KICK, queue_index, fd.as_raw_fd())?;
+ let hdr =
+ node.send_fd_for_vring(FrontendReq::SET_VRING_KICK, queue_index, fd.as_raw_fd())?;
node.wait_for_ack(&hdr).map_err(|e| e.into())
}
@@ -327,16 +329,17 @@ impl VhostBackend for Master {
if queue_index as u64 >= node.max_queue_num {
return error_code(VhostUserError::InvalidParam);
}
- let hdr = node.send_fd_for_vring(MasterReq::SET_VRING_ERR, queue_index, fd.as_raw_fd())?;
+ let hdr =
+ node.send_fd_for_vring(FrontendReq::SET_VRING_ERR, queue_index, fd.as_raw_fd())?;
node.wait_for_ack(&hdr).map_err(|e| e.into())
}
}
-impl VhostUserMaster for Master {
+impl VhostUserFrontend for Frontend {
fn get_protocol_features(&mut self) -> Result {
let mut node = self.node();
node.check_feature(VhostUserVirtioFeatures::PROTOCOL_FEATURES)?;
- let hdr = node.send_request_header(MasterReq::GET_PROTOCOL_FEATURES, None)?;
+ let hdr = node.send_request_header(FrontendReq::GET_PROTOCOL_FEATURES, None)?;
let val = node.recv_reply::(&hdr)?;
node.protocol_features = val.value;
// Should we support forward compatibility?
@@ -351,7 +354,7 @@ impl VhostUserMaster for Master {
let mut node = self.node();
node.check_feature(VhostUserVirtioFeatures::PROTOCOL_FEATURES)?;
let val = VhostUserU64::new(features.bits());
- let hdr = node.send_request_with_body(MasterReq::SET_PROTOCOL_FEATURES, &val, None)?;
+ let hdr = node.send_request_with_body(FrontendReq::SET_PROTOCOL_FEATURES, &val, None)?;
// Don't wait for ACK here because the protocol feature negotiation process hasn't been
// completed yet.
node.acked_protocol_features = features.bits();
@@ -363,7 +366,7 @@ impl VhostUserMaster for Master {
let mut node = self.node();
node.check_proto_feature(VhostUserProtocolFeatures::MQ)?;
- let hdr = node.send_request_header(MasterReq::GET_QUEUE_NUM, None)?;
+ let hdr = node.send_request_header(FrontendReq::GET_QUEUE_NUM, None)?;
let val = node.recv_reply::(&hdr)?;
if val.value > VHOST_USER_MAX_VRINGS {
return error_code(VhostUserError::InvalidMessage);
@@ -385,7 +388,7 @@ impl VhostUserMaster for Master {
let flag = enable.into();
let val = VhostUserVringState::new(queue_index as u32, flag);
- let hdr = node.send_request_with_body(MasterReq::SET_VRING_ENABLE, &val, None)?;
+ let hdr = node.send_request_with_body(FrontendReq::SET_VRING_ENABLE, &val, None)?;
node.wait_for_ack(&hdr).map_err(|e| e.into())
}
@@ -406,15 +409,15 @@ impl VhostUserMaster for Master {
node.check_proto_feature(VhostUserProtocolFeatures::CONFIG)?;
// vhost-user spec states that:
- // "Master payload: virtio device config space"
- // "Slave payload: virtio device config space"
- let hdr = node.send_request_with_payload(MasterReq::GET_CONFIG, &body, buf, None)?;
+ // "Frontend payload: virtio device config space"
+ // "Backend payload: virtio device config space"
+ let hdr = node.send_request_with_payload(FrontendReq::GET_CONFIG, &body, buf, None)?;
let (body_reply, buf_reply, rfds) =
node.recv_reply_with_payload::(&hdr)?;
if rfds.is_some() {
return error_code(VhostUserError::InvalidMessage);
} else if body_reply.size == 0 {
- return error_code(VhostUserError::SlaveInternalError);
+ return error_code(VhostUserError::BackendInternalError);
} else if body_reply.size != body.size
|| body_reply.size as usize != buf.len()
|| body_reply.offset != body.offset
@@ -438,15 +441,15 @@ impl VhostUserMaster for Master {
// depends on VhostUserProtocolFeatures::CONFIG
node.check_proto_feature(VhostUserProtocolFeatures::CONFIG)?;
- let hdr = node.send_request_with_payload(MasterReq::SET_CONFIG, &body, buf, None)?;
+ let hdr = node.send_request_with_payload(FrontendReq::SET_CONFIG, &body, buf, None)?;
node.wait_for_ack(&hdr).map_err(|e| e.into())
}
- fn set_slave_request_fd(&mut self, fd: &dyn AsRawFd) -> Result<()> {
+ fn set_backend_request_fd(&mut self, fd: &dyn AsRawFd) -> Result<()> {
let mut node = self.node();
- node.check_proto_feature(VhostUserProtocolFeatures::SLAVE_REQ)?;
+ node.check_proto_feature(VhostUserProtocolFeatures::BACKEND_REQ)?;
let fds = [fd.as_raw_fd()];
- let hdr = node.send_request_header(MasterReq::SET_SLAVE_REQ_FD, Some(&fds))?;
+ let hdr = node.send_request_header(FrontendReq::SET_BACKEND_REQ_FD, Some(&fds))?;
node.wait_for_ack(&hdr).map_err(|e| e.into())
}
@@ -457,7 +460,7 @@ impl VhostUserMaster for Master {
let mut node = self.node();
node.check_proto_feature(VhostUserProtocolFeatures::INFLIGHT_SHMFD)?;
- let hdr = node.send_request_with_body(MasterReq::GET_INFLIGHT_FD, inflight, None)?;
+ let hdr = node.send_request_with_body(FrontendReq::GET_INFLIGHT_FD, inflight, None)?;
let (inflight, files) = node.recv_reply_with_files::(&hdr)?;
match take_single_file(files) {
@@ -475,7 +478,8 @@ impl VhostUserMaster for Master {
return error_code(VhostUserError::InvalidParam);
}
- let hdr = node.send_request_with_body(MasterReq::SET_INFLIGHT_FD, inflight, Some(&[fd]))?;
+ let hdr =
+ node.send_request_with_body(FrontendReq::SET_INFLIGHT_FD, inflight, Some(&[fd]))?;
node.wait_for_ack(&hdr).map_err(|e| e.into())
}
@@ -483,7 +487,7 @@ impl VhostUserMaster for Master {
let mut node = self.node();
node.check_proto_feature(VhostUserProtocolFeatures::CONFIGURE_MEM_SLOTS)?;
- let hdr = node.send_request_header(MasterReq::GET_MAX_MEM_SLOTS, None)?;
+ let hdr = node.send_request_header(FrontendReq::GET_MAX_MEM_SLOTS, None)?;
let val = node.recv_reply::(&hdr)?;
Ok(val.value)
@@ -498,7 +502,7 @@ impl VhostUserMaster for Master {
let body = region.to_single_region();
let fds = [region.mmap_handle];
- let hdr = node.send_request_with_body(MasterReq::ADD_MEM_REG, &body, Some(&fds))?;
+ let hdr = node.send_request_with_body(FrontendReq::ADD_MEM_REG, &body, Some(&fds))?;
node.wait_for_ack(&hdr).map_err(|e| e.into())
}
@@ -510,19 +514,19 @@ impl VhostUserMaster for Master {
}
let body = region.to_single_region();
- let hdr = node.send_request_with_body(MasterReq::REM_MEM_REG, &body, None)?;
+ let hdr = node.send_request_with_body(FrontendReq::REM_MEM_REG, &body, None)?;
node.wait_for_ack(&hdr).map_err(|e| e.into())
}
}
-impl AsRawFd for Master {
+impl AsRawFd for Frontend {
fn as_raw_fd(&self) -> RawFd {
let node = self.node();
node.main_sock.as_raw_fd()
}
}
-/// Context object to pass guest memory configuration to VhostUserMaster::set_mem_table().
+/// Context object to pass guest memory configuration to VhostUserFrontend::set_mem_table().
struct VhostUserMemoryContext {
regions: VhostUserMemoryPayload,
fds: Vec,
@@ -544,20 +548,20 @@ impl VhostUserMemoryContext {
}
}
-struct MasterInternal {
- // Used to send requests to the slave.
- main_sock: Endpoint,
- // Cached virtio features from the slave.
+struct FrontendInternal {
+ // Used to send requests to the backend.
+ main_sock: Endpoint,
+ // Cached virtio features from the backend.
virtio_features: u64,
// Cached acked virtio features from the driver.
acked_virtio_features: u64,
- // Cached vhost-user protocol features from the slave.
+ // Cached vhost-user protocol features from the backend.
protocol_features: u64,
// Cached vhost-user protocol features.
acked_protocol_features: u64,
// Cached vhost-user protocol features are ready to use.
protocol_features_ready: bool,
- // Cached maxinum number of queues supported from the slave.
+ // Cached maxinum number of queues supported from the backend.
max_queue_num: u64,
// Internal flag to mark failure state.
error: Option,
@@ -565,12 +569,12 @@ struct MasterInternal {
hdr_flags: VhostUserHeaderFlag,
}
-impl MasterInternal {
+impl FrontendInternal {
fn send_request_header(
&mut self,
- code: MasterReq,
+ code: FrontendReq,
fds: Option<&[RawFd]>,
- ) -> VhostUserResult> {
+ ) -> VhostUserResult> {
self.check_state()?;
let hdr = self.new_request_header(code, 0);
self.main_sock.send_header(&hdr, fds)?;
@@ -579,10 +583,10 @@ impl MasterInternal {
fn send_request_with_body(
&mut self,
- code: MasterReq,
+ code: FrontendReq,
msg: &T,
fds: Option<&[RawFd]>,
- ) -> VhostUserResult> {
+ ) -> VhostUserResult> {
if mem::size_of::() > MAX_MSG_SIZE {
return Err(VhostUserError::InvalidParam);
}
@@ -595,11 +599,11 @@ impl MasterInternal {
fn send_request_with_payload(
&mut self,
- code: MasterReq,
+ code: FrontendReq,
msg: &T,
payload: &[u8],
fds: Option<&[RawFd]>,
- ) -> VhostUserResult> {
+ ) -> VhostUserResult> {
let len = mem::size_of::() + payload.len();
if len > MAX_MSG_SIZE {
return Err(VhostUserError::InvalidParam);
@@ -619,10 +623,10 @@ impl MasterInternal {
fn send_fd_for_vring(
&mut self,
- code: MasterReq,
+ code: FrontendReq,
queue_index: usize,
fd: RawFd,
- ) -> VhostUserResult> {
+ ) -> VhostUserResult> {
if queue_index as u64 >= self.max_queue_num {
return Err(VhostUserError::InvalidParam);
}
@@ -639,7 +643,7 @@ impl MasterInternal {
fn recv_reply(
&mut self,
- hdr: &VhostUserMsgHeader,
+ hdr: &VhostUserMsgHeader,
) -> VhostUserResult {
if mem::size_of::() > MAX_MSG_SIZE || hdr.is_reply() {
return Err(VhostUserError::InvalidParam);
@@ -655,7 +659,7 @@ impl MasterInternal {
fn recv_reply_with_files(
&mut self,
- hdr: &VhostUserMsgHeader,
+ hdr: &VhostUserMsgHeader,
) -> VhostUserResult<(T, Option>)> {
if mem::size_of::() > MAX_MSG_SIZE || hdr.is_reply() {
return Err(VhostUserError::InvalidParam);
@@ -671,7 +675,7 @@ impl MasterInternal {
fn recv_reply_with_payload(
&mut self,
- hdr: &VhostUserMsgHeader,
+ hdr: &VhostUserMsgHeader,
) -> VhostUserResult<(T, Vec, Option>)> {
if mem::size_of::