vhost_user_fs: add the ability to set slave req fd

This adds the missing part of supporting virtiofs dax on the slave end,
that is, receiving a socket pair fd from the master end to set up a
communication channel for sending setupmapping & removemapping messages.

Signed-off-by: Liu Bo <bo.liu@linux.alibaba.com>
This commit is contained in:
Liu Bo
2020-02-12 15:15:04 -08:00
committed by Rob Bradford
parent 3f09eff6c5
commit 59958f0a61
3 changed files with 52 additions and 3 deletions

View File

@@ -20,7 +20,8 @@ use vhost_rs::vhost_user::message::{
VhostUserVirtioFeatures, VhostUserVringAddrFlags, VhostUserVringState,
};
use vhost_rs::vhost_user::{
Error as VhostUserError, Result as VhostUserResult, SlaveListener, VhostUserSlaveReqHandler,
Error as VhostUserError, Result as VhostUserResult, SlaveFsCacheReq, SlaveListener,
VhostUserSlaveReqHandler,
};
use vm_memory::guest_memory::FileOffset;
use vm_memory::{GuestAddress, GuestMemoryMmap};
@@ -103,6 +104,11 @@ pub trait VhostUserBackend: Send + Sync + 'static {
fn exit_event(&self) -> Option<(EventFd, Option<u16>)> {
None
}
/// Set slave fd.
/// A default implementation is provided as we cannot expect all backends
/// to implement this function.
fn set_slave_req_fd(&mut self, _vu_req: SlaveFsCacheReq) {}
}
/// This structure is the public API the backend is allowed to interact with
@@ -779,6 +785,10 @@ impl<S: VhostUserBackend> VhostUserSlaveReqHandler for VhostUserHandler<S> {
.set_config(offset, buf)
.map_err(VhostUserError::ReqHandlerError)
}
fn set_slave_req_fd(&mut self, vu_req: SlaveFsCacheReq) {
self.backend.write().unwrap().set_slave_req_fd(vu_req);
}
}
impl<S: VhostUserBackend> Drop for VhostUserHandler<S> {