vhost_user_backend: Pass a backend that can be modified

This patch modifies the library so that a consumer can update the
backend after it's been passed to the daemon.

Signed-off-by: Sebastien Boeuf <sebastien.boeuf@intel.com>
This commit is contained in:
Sebastien Boeuf
2019-09-23 12:54:24 -07:00
parent f14ab872ec
commit 347611b0c7
+6 -7
View File
@@ -115,7 +115,7 @@ impl<S: VhostUserBackend> VhostUserDaemon<S> {
/// listening onto registered event. Those events can be vring events or /// listening onto registered event. Those events can be vring events or
/// custom events from the backend, but they get to be registered later /// custom events from the backend, but they get to be registered later
/// during the sequence. /// during the sequence.
pub fn new(name: String, sock_path: String, backend: S) -> Result<Self> { pub fn new(name: String, sock_path: String, backend: Arc<RwLock<S>>) -> Result<Self> {
let handler = Arc::new(Mutex::new( let handler = Arc::new(Mutex::new(
VhostUserHandler::new(backend).map_err(Error::NewVhostUserHandler)?, VhostUserHandler::new(backend).map_err(Error::NewVhostUserHandler)?,
)); ));
@@ -497,17 +497,16 @@ struct VhostUserHandler<S: VhostUserBackend> {
} }
impl<S: VhostUserBackend> VhostUserHandler<S> { impl<S: VhostUserBackend> VhostUserHandler<S> {
fn new(backend: S) -> VhostUserHandlerResult<Self> { fn new(backend: Arc<RwLock<S>>) -> VhostUserHandlerResult<Self> {
let num_queues = backend.num_queues(); let num_queues = backend.read().unwrap().num_queues();
let max_queue_size = backend.max_queue_size(); let max_queue_size = backend.read().unwrap().max_queue_size();
let arc_backend = Arc::new(RwLock::new(backend));
let vrings = vec![Arc::new(RwLock::new(Vring::new(max_queue_size as u16))); num_queues]; let vrings = vec![Arc::new(RwLock::new(Vring::new(max_queue_size as u16))); num_queues];
// Create the epoll file descriptor // Create the epoll file descriptor
let epoll_fd = epoll::create(true).map_err(VhostUserHandlerError::EpollCreateFd)?; let epoll_fd = epoll::create(true).map_err(VhostUserHandlerError::EpollCreateFd)?;
let vring_handler = Arc::new(RwLock::new(VringEpollHandler { let vring_handler = Arc::new(RwLock::new(VringEpollHandler {
backend: arc_backend.clone(), backend: backend.clone(),
vrings: vrings.clone(), vrings: vrings.clone(),
mem: None, mem: None,
epoll_fd, epoll_fd,
@@ -522,7 +521,7 @@ impl<S: VhostUserBackend> VhostUserHandler<S> {
.map_err(VhostUserHandlerError::SpawnVringWorker)?; .map_err(VhostUserHandlerError::SpawnVringWorker)?;
Ok(VhostUserHandler { Ok(VhostUserHandler {
backend: arc_backend, backend,
vring_handler, vring_handler,
owned: false, owned: false,
features_acked: false, features_acked: false,