Skip to content

Commit

Permalink
vhost: Adopt new backend naming
Browse files Browse the repository at this point in the history
Following vhost-user specification, replace
all uses of master/slave with backend/frontend
in the vhost crate.

Signed-off-by: Albert Esteve <aesteve@redhat.com>
  • Loading branch information
aesteve-rh authored and stefano-garzarella committed Sep 13, 2023
1 parent 5c9bef6 commit 4db81ad
Show file tree
Hide file tree
Showing 19 changed files with 829 additions and 812 deletions.
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"
}
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"
1 change: 1 addition & 0 deletions crates/vhost/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/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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]
Expand Down
6 changes: 3 additions & 3 deletions crates/vhost/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
18 changes: 9 additions & 9 deletions crates/vhost/docs/vhost_architecture.drawio
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,10 @@
<mxCell id="44" value="" style="rounded=0;whiteSpace=wrap;html=1;labelBackgroundColor=none;sketch=0;fontSize=25;fontColor=#FF00FF;fillColor=none;strokeColor=#4D4D4D;strokeWidth=5;" vertex="1" parent="1">
<mxGeometry x="-10" y="37" width="1250" height="670" as="geometry"/>
</mxCell>
<mxCell id="2" value="&lt;pre style=&quot;font-family: &amp;quot;jetbrains mono&amp;quot;, monospace; font-size: 16.5pt;&quot;&gt;MasterReqHandler&lt;/pre&gt;" style="rounded=0;whiteSpace=wrap;html=1;fontStyle=1;labelBackgroundColor=none;fontColor=#FF00FF;strokeColor=#FF00FF;" parent="1" vertex="1">
<mxCell id="2" value="&lt;pre style=&quot;font-family: &amp;quot;jetbrains mono&amp;quot;, monospace; font-size: 16.5pt;&quot;&gt;FrontendReqHandler&lt;/pre&gt;" style="rounded=0;whiteSpace=wrap;html=1;fontStyle=1;labelBackgroundColor=none;fontColor=#FF00FF;strokeColor=#FF00FF;" parent="1" vertex="1">
<mxGeometry x="830" y="477" width="220" height="50" as="geometry"/>
</mxCell>
<mxCell id="4" value="&lt;pre style=&quot;font-size: 16.5pt; font-weight: 700; font-family: &amp;quot;jetbrains mono&amp;quot;, monospace;&quot;&gt;VhostUserMasterReqHandler&lt;/pre&gt;" style="rounded=1;whiteSpace=wrap;html=1;labelBackgroundColor=none;fontColor=#FF00FF;strokeColor=#FF00FF;" parent="1" vertex="1">
<mxCell id="4" value="&lt;pre style=&quot;font-size: 16.5pt; font-weight: 700; font-family: &amp;quot;jetbrains mono&amp;quot;, monospace;&quot;&gt;VhostUserFrontendReqHandler&lt;/pre&gt;" style="rounded=1;whiteSpace=wrap;html=1;labelBackgroundColor=none;fontColor=#FF00FF;strokeColor=#FF00FF;" parent="1" vertex="1">
<mxGeometry x="840" y="597" width="360" height="60" as="geometry"/>
</mxCell>
<mxCell id="6" style="edgeStyle=orthogonalEdgeStyle;rounded=0;orthogonalLoop=1;jettySize=auto;html=1;exitX=0;exitY=0.5;exitDx=0;exitDy=0;entryX=1;entryY=0.5;entryDx=0;entryDy=0;labelBackgroundColor=none;fontColor=#FF00FF;strokeColor=#FF00FF;" edge="1" parent="1" source="5" target="2">
Expand All @@ -27,10 +27,10 @@
</Array>
</mxGeometry>
</mxCell>
<mxCell id="5" value="&lt;pre style=&quot;font-family: &amp;quot;jetbrains mono&amp;quot;, monospace; font-size: 16.5pt;&quot;&gt;&lt;pre style=&quot;font-family: &amp;quot;jetbrains mono&amp;quot; , monospace ; font-size: 16.5pt&quot;&gt;Slave&lt;/pre&gt;&lt;/pre&gt;" style="rounded=0;whiteSpace=wrap;html=1;fontStyle=1;labelBackgroundColor=none;fontColor=#FF00FF;strokeColor=#FF00FF;" parent="1" vertex="1">
<mxCell id="5" value="&lt;pre style=&quot;font-family: &amp;quot;jetbrains mono&amp;quot;, monospace; font-size: 16.5pt;&quot;&gt;&lt;pre style=&quot;font-family: &amp;quot;jetbrains mono&amp;quot; , monospace ; font-size: 16.5pt&quot;&gt;Backend&lt;/pre&gt;&lt;/pre&gt;" style="rounded=0;whiteSpace=wrap;html=1;fontStyle=1;labelBackgroundColor=none;fontColor=#FF00FF;strokeColor=#FF00FF;" parent="1" vertex="1">
<mxGeometry x="1715" y="767" width="220" height="50" as="geometry"/>
</mxCell>
<mxCell id="7" value="&lt;pre style=&quot;font-size: 16.5pt; font-weight: 700; font-family: &amp;quot;jetbrains mono&amp;quot;, monospace;&quot;&gt;VhostUserMasterReqHandlerMut&lt;/pre&gt;" style="rounded=1;whiteSpace=wrap;html=1;labelBackgroundColor=none;fontColor=#FF00FF;strokeColor=#FF00FF;" vertex="1" parent="1">
<mxCell id="7" value="&lt;pre style=&quot;font-size: 16.5pt; font-weight: 700; font-family: &amp;quot;jetbrains mono&amp;quot;, monospace;&quot;&gt;VhostUserFrontendReqHandlerMut&lt;/pre&gt;" style="rounded=1;whiteSpace=wrap;html=1;labelBackgroundColor=none;fontColor=#FF00FF;strokeColor=#FF00FF;" vertex="1" parent="1">
<mxGeometry x="1630" y="657" width="390" height="60" as="geometry"/>
</mxCell>
<mxCell id="8" style="edgeStyle=orthogonalEdgeStyle;rounded=0;orthogonalLoop=1;jettySize=auto;html=1;exitX=0.5;exitY=1;exitDx=0;exitDy=0;labelBackgroundColor=none;fontColor=#FF00FF;strokeColor=#FF00FF;" edge="1" parent="1" source="2" target="4">
Expand All @@ -39,13 +39,13 @@
<mxPoint x="680" y="717" as="targetPoint"/>
</mxGeometry>
</mxCell>
<mxCell id="10" value="&lt;pre style=&quot;font-family: &amp;quot;jetbrains mono&amp;quot;, monospace; font-size: 16.5pt;&quot;&gt;&lt;pre style=&quot;font-family: &amp;quot;jetbrains mono&amp;quot; , monospace ; font-size: 16.5pt&quot;&gt;SlaveListener&lt;/pre&gt;&lt;/pre&gt;" style="rounded=0;whiteSpace=wrap;html=1;fontStyle=1;labelBackgroundColor=none;fontColor=#FF00FF;strokeColor=#FF00FF;" vertex="1" parent="1">
<mxCell id="10" value="&lt;pre style=&quot;font-family: &amp;quot;jetbrains mono&amp;quot;, monospace; font-size: 16.5pt;&quot;&gt;&lt;pre style=&quot;font-family: &amp;quot;jetbrains mono&amp;quot; , monospace ; font-size: 16.5pt&quot;&gt;BackendListener&lt;/pre&gt;&lt;/pre&gt;" style="rounded=0;whiteSpace=wrap;html=1;fontStyle=1;labelBackgroundColor=none;fontColor=#FF00FF;strokeColor=#FF00FF;" vertex="1" parent="1">
<mxGeometry x="1360" y="472" width="190" height="50" as="geometry"/>
</mxCell>
<mxCell id="11" value="&lt;pre style=&quot;font-family: &amp;quot;jetbrains mono&amp;quot;, monospace; font-size: 16.5pt;&quot;&gt;&lt;pre style=&quot;font-family: &amp;quot;jetbrains mono&amp;quot; , monospace ; font-size: 16.5pt&quot;&gt;&lt;pre style=&quot;font-family: &amp;quot;jetbrains mono&amp;quot; , monospace ; font-size: 16.5pt&quot;&gt;SlaveReqHandler&lt;/pre&gt;&lt;/pre&gt;&lt;/pre&gt;" style="rounded=0;whiteSpace=wrap;html=1;fontStyle=1;labelBackgroundColor=none;fontColor=#FF00FF;strokeColor=#FF00FF;" vertex="1" parent="1">
<mxCell id="11" value="&lt;pre style=&quot;font-family: &amp;quot;jetbrains mono&amp;quot;, monospace; font-size: 16.5pt;&quot;&gt;&lt;pre style=&quot;font-family: &amp;quot;jetbrains mono&amp;quot; , monospace ; font-size: 16.5pt&quot;&gt;&lt;pre style=&quot;font-family: &amp;quot;jetbrains mono&amp;quot; , monospace ; font-size: 16.5pt&quot;&gt;BackendReqHandler&lt;/pre&gt;&lt;/pre&gt;&lt;/pre&gt;" style="rounded=0;whiteSpace=wrap;html=1;fontStyle=1;labelBackgroundColor=none;fontColor=#FF00FF;strokeColor=#FF00FF;" vertex="1" parent="1">
<mxGeometry x="1712" y="387" width="210" height="50" as="geometry"/>
</mxCell>
<mxCell id="14" value="&lt;pre style=&quot;font-size: 16.5pt; font-weight: 700; font-family: &amp;quot;jetbrains mono&amp;quot;, monospace;&quot;&gt;&lt;pre style=&quot;font-family: &amp;quot;jetbrains mono&amp;quot;, monospace; font-size: 16.5pt;&quot;&gt;VhostUserSlaveReqHandler&lt;/pre&gt;&lt;/pre&gt;" style="rounded=1;whiteSpace=wrap;html=1;labelBackgroundColor=none;fontColor=#FF00FF;strokeColor=#FF00FF;" vertex="1" parent="1">
<mxCell id="14" value="&lt;pre style=&quot;font-size: 16.5pt; font-weight: 700; font-family: &amp;quot;jetbrains mono&amp;quot;, monospace;&quot;&gt;&lt;pre style=&quot;font-family: &amp;quot;jetbrains mono&amp;quot;, monospace; font-size: 16.5pt;&quot;&gt;VhostUserBackendReqHandler&lt;/pre&gt;&lt;/pre&gt;" style="rounded=1;whiteSpace=wrap;html=1;labelBackgroundColor=none;fontColor=#FF00FF;strokeColor=#FF00FF;" vertex="1" parent="1">
<mxGeometry x="1652" y="537" width="330" height="60" as="geometry"/>
</mxCell>
<mxCell id="15" style="edgeStyle=orthogonalEdgeStyle;rounded=0;orthogonalLoop=1;jettySize=auto;html=1;exitX=0.5;exitY=1;exitDx=0;exitDy=0;entryX=0.5;entryY=0;entryDx=0;entryDy=0;labelBackgroundColor=none;fontColor=#FF00FF;strokeColor=#FF00FF;" edge="1" parent="1" source="11" target="14">
Expand All @@ -63,7 +63,7 @@
<mxCell id="18" value="&lt;pre style=&quot;font-family: &amp;quot;jetbrains mono&amp;quot;, monospace; font-size: 16.5pt;&quot;&gt;VhostVdpaBackend&lt;/pre&gt;" style="rounded=0;whiteSpace=wrap;html=1;fontStyle=1;labelBackgroundColor=none;fontColor=#808080;strokeColor=#808080;" vertex="1" parent="1">
<mxGeometry x="270" y="387" width="220" height="50" as="geometry"/>
</mxCell>
<mxCell id="19" value="&lt;pre style=&quot;font-family: &amp;quot;jetbrains mono&amp;quot; , monospace ; font-size: 16.5pt&quot;&gt;Master&lt;/pre&gt;" style="rounded=0;whiteSpace=wrap;html=1;fontStyle=1;labelBackgroundColor=none;fontColor=#FF00FF;strokeColor=#FF00FF;" vertex="1" parent="1">
<mxCell id="19" value="&lt;pre style=&quot;font-family: &amp;quot;jetbrains mono&amp;quot; , monospace ; font-size: 16.5pt&quot;&gt;Frontend&lt;/pre&gt;" style="rounded=0;whiteSpace=wrap;html=1;fontStyle=1;labelBackgroundColor=none;fontColor=#FF00FF;strokeColor=#FF00FF;" vertex="1" parent="1">
<mxGeometry x="820" y="387" width="220" height="50" as="geometry"/>
</mxCell>
<mxCell id="20" value="&lt;pre style=&quot;font-family: &amp;quot;jetbrains mono&amp;quot; , monospace ; font-size: 16.5pt&quot;&gt;VhostSoftBackend&lt;/pre&gt;" style="rounded=0;whiteSpace=wrap;html=1;fontStyle=1;labelBackgroundColor=none;fontColor=#808080;strokeColor=#808080;" vertex="1" parent="1">
Expand Down Expand Up @@ -126,7 +126,7 @@
<mxCell id="36" value="&lt;pre style=&quot;font-family: &amp;quot;jetbrains mono&amp;quot; , monospace ; font-size: 16.5pt&quot;&gt;&lt;pre style=&quot;font-family: &amp;quot;jetbrains mono&amp;quot; , monospace ; font-size: 16.5pt&quot;&gt;Message&lt;/pre&gt;&lt;/pre&gt;" style="rounded=0;whiteSpace=wrap;html=1;fontStyle=1;labelBackgroundColor=none;fontColor=#FF00FF;strokeColor=#FF00FF;" vertex="1" parent="1">
<mxGeometry x="1360" y="632" width="190" height="50" as="geometry"/>
</mxCell>
<mxCell id="37" value="&lt;pre style=&quot;font-size: 16.5pt ; font-weight: 700 ; font-family: &amp;quot;jetbrains mono&amp;quot; , monospace&quot;&gt;&lt;pre style=&quot;font-family: &amp;quot;jetbrains mono&amp;quot; , monospace ; font-size: 16.5pt&quot;&gt;VhostUserMaster&lt;/pre&gt;&lt;/pre&gt;" style="rounded=1;whiteSpace=wrap;html=1;labelBackgroundColor=none;strokeColor=#FF33FF;fontColor=#FF00FF;" vertex="1" parent="1">
<mxCell id="37" value="&lt;pre style=&quot;font-size: 16.5pt ; font-weight: 700 ; font-family: &amp;quot;jetbrains mono&amp;quot; , monospace&quot;&gt;&lt;pre style=&quot;font-family: &amp;quot;jetbrains mono&amp;quot; , monospace ; font-size: 16.5pt&quot;&gt;VhostUserFrontend&lt;/pre&gt;&lt;/pre&gt;" style="rounded=1;whiteSpace=wrap;html=1;labelBackgroundColor=none;strokeColor=#FF33FF;fontColor=#FF00FF;" vertex="1" parent="1">
<mxGeometry x="980" y="257" width="230" height="60" as="geometry"/>
</mxCell>
<mxCell id="38" style="edgeStyle=orthogonalEdgeStyle;rounded=0;orthogonalLoop=1;jettySize=auto;html=1;exitX=0.5;exitY=0;exitDx=0;exitDy=0;labelBackgroundColor=none;entryX=0.5;entryY=1;entryDx=0;entryDy=0;strokeColor=#00994D;" edge="1" parent="1" source="19" target="16">
Expand Down
4 changes: 2 additions & 2 deletions crates/vhost/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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)]
Expand Down
86 changes: 86 additions & 0 deletions crates/vhost/src/vhost_user/backend.rs
Original file line number Diff line number Diff line change
@@ -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<S: VhostUserBackendReqHandler> {
listener: Listener,
backend: Option<Arc<S>>,
}

/// Sets up a listener for incoming frontend connections, and handles construction
/// of a Backend on success.
impl<S: VhostUserBackendReqHandler> BackendListener<S> {
/// Create a unix domain socket for incoming frontend connections.
pub fn new(listener: Listener, backend: Arc<S>) -> Result<Self> {
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<Option<BackendReqHandler<S>>> {
if let Some(fd) = self.listener.accept()? {
return Ok(Some(BackendReqHandler::new(
Endpoint::<FrontendReq>::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();
}
}
Loading

0 comments on commit 4db81ad

Please sign in to comment.