vhost-user-backend
Design
The vhost-user-backend
crate provides a framework to implement vhost-user
backend services,
which includes following external public APIs:
- A daemon control object (
VhostUserDaemon
) to start and stop the service daemon. - A vhost-user backend trait (
VhostUserBackendMut
) to handle vhost-user control messages and virtio messages. - A vring access trait (
VringT
) to access virtio queues, and three implementations of the trait:VringState
,VringMutex
andVringRwLock
.
Usage
The vhost-user-backend
crate provides a framework to implement vhost-user backend services. The main interface provided by vhost-user-backend
library is the struct VhostUserDaemon
:
Create a VhostUserDaemon
Instance
The VhostUserDaemon::new()
creates an instance of VhostUserDaemon
object. The client needs to
pass in an VhostUserBackend
object, which will be used to configure the VhostUserDaemon
instance, handle control messages from the vhost-user master and handle virtio requests from
virtio queues. A group of working threads will be created to handle virtio requests from configured
virtio queues.
Start the VhostUserDaemon
The VhostUserDaemon::start()
method waits for an incoming connection from the vhost-user masters
on the listener
. Once a connection is ready, a main thread will be created to handle vhost-user
messages from the vhost-user master.
Stop the VhostUserDaemon
The VhostUserDaemon::stop()
method waits for the main thread to exit. An exit event must be sent
to the main thread by writing to the exit_event
EventFd before waiting for it to exit.
Threading Model
The main thread and virtio queue working threads will concurrently access the underlying virtio queues, so all virtio queue in multi-threading model. But the main thread only accesses virtio queues for configuration, so client could adopt locking policies to optimize for the virtio queue working threads.
Example
Example code to handle virtio messages from a virtio queue:
License
This project is licensed under
- Apache License, Version 2.0