pub struct VhostUserDaemon<T: VhostUserBackend> { /* private fields */ }
Expand description
Implement a simple framework to run a vhost-user service daemon.
This structure is the public API the backend is allowed to interact with in order to run a fully functional vhost-user daemon.
Implementations§
Source§impl<T> VhostUserDaemon<T>
impl<T> VhostUserDaemon<T>
Sourcepub fn new(
name: String,
backend: T,
atomic_mem: GuestMemoryAtomic<GuestMemoryMmap<T::Bitmap>>,
) -> Result<Self>
pub fn new( name: String, backend: T, atomic_mem: GuestMemoryAtomic<GuestMemoryMmap<T::Bitmap>>, ) -> Result<Self>
Create the daemon instance, providing the backend implementation of VhostUserBackend
.
Under the hood, this will start a dedicated thread responsible for listening onto registered event. Those events can be vring events or custom events from the backend, but they get to be registered later during the sequence.
Sourcepub fn start_client(&mut self, socket_path: &str) -> Result<()>
pub fn start_client(&mut self, socket_path: &str) -> Result<()>
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.
Sourcepub fn start(&mut self, listener: Listener) -> Result<()>
pub fn start(&mut self, listener: Listener) -> Result<()>
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.
Note: A convenience function VhostUserDaemon::serve exists that may be a better option than this for simple use-cases.
Sourcepub fn wait(&mut self) -> Result<()>
pub fn wait(&mut self) -> Result<()>
Wait for the thread handling the vhost-user socket connection to terminate.
Note: A convenience function VhostUserDaemon::serve exists that may be a better option than this for simple use-cases.
Sourcepub fn serve<P: AsRef<Path>>(&mut self, socket: P) -> Result<()>
pub fn serve<P: AsRef<Path>>(&mut self, socket: P) -> Result<()>
Bind to socket, handle a single connection and shutdown
This is a convenience function that provides an easy way to handle the following actions without needing to call the low-level functions:
- Create a listener
- Start listening
- Handle a single event
- Send the exit event to all handler threads
Internal Err
results that indicate a device disconnect will be treated
as success and Ok(())
will be returned in those cases.
Note: See VhostUserDaemon::start and VhostUserDaemon::wait if you need more flexibility.
Sourcepub fn get_epoll_handlers(&self) -> Vec<Arc<VringEpollHandler<T>>>
pub fn get_epoll_handlers(&self) -> Vec<Arc<VringEpollHandler<T>>>
Retrieve the vring epoll handler.
This is necessary to perform further actions like registering and unregistering some extra event file descriptors.