Skip to main content

VhostUserDaemon

Struct VhostUserDaemon 

Source
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>
where T: VhostUserBackend + Clone + 'static, T::Bitmap: BitmapReplace + NewBitmap + Clone + Send + Sync, T::Vring: Clone + Send + Sync,

Source

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.

Source

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.

Source

pub fn start(&mut self, listener: &mut 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.

Source

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.

Source

pub fn shutdown_handle(&self) -> Option<ShutdownHandle>

Returns a handle to shut down the daemon, or None if not connected.

Source

pub fn request_shutdown(&self)

Shut down the connection to unblock the daemon thread.

Source

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.

Source

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.

Trait Implementations§

Source§

impl<T: VhostUserBackend> Drop for VhostUserDaemon<T>

Source§

fn drop(&mut self)

Executes the destructor for this type. Read more
Source§

fn pin_drop(self: Pin<&mut Self>)

🔬This is a nightly-only experimental API. (pin_ergonomics)
Execute the destructor for this type, but different to Drop::drop, it requires self to be pinned. Read more

Auto Trait Implementations§

§

impl<T> !RefUnwindSafe for VhostUserDaemon<T>

§

impl<T> !UnwindSafe for VhostUserDaemon<T>

§

impl<T> Freeze for VhostUserDaemon<T>
where Arc<Mutex<VhostUserHandler<T>>>: Freeze,

§

impl<T> Send for VhostUserDaemon<T>
where Arc<Mutex<VhostUserHandler<T>>>: Send,

§

impl<T> Sync for VhostUserDaemon<T>
where Arc<Mutex<VhostUserHandler<T>>>: Sync,

§

impl<T> Unpin for VhostUserDaemon<T>
where Arc<Mutex<VhostUserHandler<T>>>: Unpin,

§

impl<T> UnsafeUnpin for VhostUserDaemon<T>
where Arc<Mutex<VhostUserHandler<T>>>: UnsafeUnpin,

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = !

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, !>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.