mirror of
https://github.com/cloud-hypervisor/cloud-hypervisor.git
synced 2025-01-21 20:15:21 +00:00
vhost_user_backend: Add client mode support
Introduce some new code to support running a vhost-user backend as a client instead of the default server mode. Signed-off-by: Sebastien Boeuf <sebastien.boeuf@intel.com>
This commit is contained in:
parent
904aea76ab
commit
a4a0751051
@ -20,6 +20,7 @@ use vhost::vhost_user::message::{
|
||||
VhostUserSingleMemoryRegion, VhostUserVirtioFeatures, VhostUserVringAddrFlags,
|
||||
VhostUserVringState,
|
||||
};
|
||||
use vhost::vhost_user::SlaveReqHandler;
|
||||
use vhost::vhost_user::{
|
||||
Error as VhostUserError, Listener, Result as VhostUserResult, SlaveFsCacheReq, SlaveListener,
|
||||
VhostUserSlaveReqHandlerMut,
|
||||
@ -153,7 +154,7 @@ impl<S: VhostUserBackend> VhostUserDaemon<S> {
|
||||
})
|
||||
}
|
||||
|
||||
/// Connect to the vhost-user socket and run a dedicated thread handling
|
||||
/// Listen to the vhost-user socket and run a dedicated thread handling
|
||||
/// all requests coming through this socket. This runs in an infinite loop
|
||||
/// that should be terminating once the other end of the socket (the VMM)
|
||||
/// disconnects.
|
||||
@ -178,6 +179,27 @@ impl<S: VhostUserBackend> VhostUserDaemon<S> {
|
||||
Ok(())
|
||||
}
|
||||
|
||||
/// Connect to the vhost-user socket and run a dedicated thread handling
|
||||
/// all requests coming through this socket. This runs in an infinite loop
|
||||
/// that should be terminating once the other end of the socket (the VMM)
|
||||
/// hangs up.
|
||||
pub fn start_client(&mut self, socket_path: &str) -> Result<()> {
|
||||
let mut slave_handler = SlaveReqHandler::connect(socket_path, self.handler.clone())
|
||||
.map_err(Error::CreateSlaveReqHandler)?;
|
||||
let handle = thread::Builder::new()
|
||||
.name(self.name.clone())
|
||||
.spawn(move || loop {
|
||||
slave_handler
|
||||
.handle_request()
|
||||
.map_err(Error::HandleRequest)?;
|
||||
})
|
||||
.map_err(Error::StartDaemon)?;
|
||||
|
||||
self.main_thread = Some(handle);
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
||||
/// Wait for the thread handling the vhost-user socket connection to
|
||||
/// terminate.
|
||||
pub fn wait(&mut self) -> Result<()> {
|
||||
|
Loading…
x
Reference in New Issue
Block a user