-
Notifications
You must be signed in to change notification settings - Fork 70
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
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
1 parent
5c9bef6
commit 4db81ad
Showing
19 changed files
with
829 additions
and
812 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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" | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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" | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -4,6 +4,7 @@ | |
### Added | ||
|
||
### Changed | ||
- Change uses of master/slave for frontend/backend in the codebase. | ||
|
||
### Fixed | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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(); | ||
} | ||
} |
Oops, something went wrong.