summaryrefslogtreecommitdiff
path: root/src/vhost_user
diff options
context:
space:
mode:
authorLiu Bo <bo.liu@linux.alibaba.com>2020-03-13 12:19:33 -0700
committerAndreea Florescu <andreea.florescu15@gmail.com>2020-09-04 17:59:53 +0300
commit791de4996372270ae88e6303bb5664f0c886b3f8 (patch)
tree45491777dc1929d88ef2d138e6654600ecd0fd42 /src/vhost_user
parent1b52709afde702c991f4708dd6f19315ed9ae227 (diff)
downloadvmm_vhost-791de4996372270ae88e6303bb5664f0c886b3f8.tar.gz
vhost-user: add FS_IO request
This is defined by vhost-user-fs (virtio-fs), can be used by a client to ask VMM to perform a read/write from an fd directly to GPA. Signed-off-by: Liu Bo <bo.liu@linux.alibaba.com>
Diffstat (limited to 'src/vhost_user')
-rw-r--r--src/vhost_user/master_req_handler.rs17
-rw-r--r--src/vhost_user/message.rs4
2 files changed, 19 insertions, 2 deletions
diff --git a/src/vhost_user/master_req_handler.rs b/src/vhost_user/master_req_handler.rs
index 5664cd2..ca54ff4 100644
--- a/src/vhost_user/master_req_handler.rs
+++ b/src/vhost_user/master_req_handler.rs
@@ -39,6 +39,13 @@ pub trait VhostUserMasterReqHandler {
fn fs_slave_sync(&mut self, _fs: &VhostUserFSSlaveMsg) -> HandlerResult<()> {
Err(std::io::Error::from_raw_os_error(libc::ENOSYS))
}
+
+ /// Handle virtio-fs file IO requests from the slave.
+ fn fs_slave_io(&mut self, _fs: &VhostUserFSSlaveMsg, fd: RawFd) -> HandlerResult<()> {
+ // Safe because we have just received the rawfd from kernel.
+ unsafe { libc::close(fd) };
+ Err(std::io::Error::from_raw_os_error(libc::ENOSYS))
+ }
}
/// A vhost-user master request endpoint which relays all received requests from the slave to the
@@ -142,6 +149,14 @@ impl<S: VhostUserMasterReqHandler> MasterReqHandler<S> {
.fs_slave_sync(msg)
.map_err(Error::ReqHandlerError)
}
+ SlaveReq::FS_IO => {
+ let msg = self.extract_msg_body::<VhostUserFSSlaveMsg>(&hdr, size, &buf)?;
+ self.backend
+ .lock()
+ .unwrap()
+ .fs_slave_io(msg, rfds.unwrap()[0])
+ .map_err(Error::ReqHandlerError)
+ }
_ => Err(Error::InvalidMessage),
};
@@ -179,7 +194,7 @@ impl<S: VhostUserMasterReqHandler> MasterReqHandler<S> {
rfds: Option<Vec<RawFd>>,
) -> Result<Option<Vec<RawFd>>> {
match hdr.get_code() {
- SlaveReq::FS_MAP => {
+ SlaveReq::FS_MAP | SlaveReq::FS_IO => {
// Expect an fd set with a single fd.
match rfds {
None => Err(Error::InvalidMessage),
diff --git a/src/vhost_user/message.rs b/src/vhost_user/message.rs
index 7c4f292..ccaa6b8 100644
--- a/src/vhost_user/message.rs
+++ b/src/vhost_user/message.rs
@@ -150,8 +150,10 @@ pub enum SlaveReq {
FS_UNMAP = 5,
/// Virtio-fs draft: sync file content.
FS_SYNC = 6,
+ /// Virtio-fs draft: perform a read/write from an fd directly to GPA.
+ FS_IO = 7,
/// Upper bound of valid commands.
- MAX_CMD = 7,
+ MAX_CMD = 8,
}
impl Into<u32> for SlaveReq {