mirror of
https://github.com/cloud-hypervisor/cloud-hypervisor.git
synced 2026-08-05 02:19:16 +00:00
vhost_user_fs: add fs cache request operations
This introduces setupmapping and removemapping methods to server.rs,
passthrough.rs and filesystem.rs in order to support virtiofs dax mode
inside guest.
Since we don't really want the server.rs to know that it is dealing with
vhost-user specifically, this is making it more generic by adding a new
trait which has three functions map()/unmap()/sync() corresponding to
fs_slave_{map, unmap, sync}, server.rs will take anything that implements
the trait.
Signed-off-by: Liu Bo <bo.liu@linux.alibaba.com>
This commit is contained in:
@@ -17,6 +17,7 @@ use std::time::Duration;
|
||||
use libc;
|
||||
use vm_memory::ByteValued;
|
||||
|
||||
use super::fs_cache_req_handler::FsCacheReqHandler;
|
||||
use crate::filesystem::{
|
||||
Context, DirEntry, Entry, FileSystem, FsOptions, GetxattrReply, ListxattrReply, OpenOptions,
|
||||
SetattrValid, ZeroCopyReader, ZeroCopyWriter,
|
||||
@@ -911,6 +912,41 @@ impl FileSystem for PassthroughFs {
|
||||
self.do_unlink(parent, name, 0)
|
||||
}
|
||||
|
||||
fn setupmapping<T: FsCacheReqHandler>(
|
||||
&self,
|
||||
_ctx: Context,
|
||||
inode: Inode,
|
||||
_handle: Handle,
|
||||
foffset: u64,
|
||||
len: u64,
|
||||
flags: u64,
|
||||
moffset: u64,
|
||||
vu_req: &mut T,
|
||||
) -> io::Result<()> {
|
||||
debug!(
|
||||
"setupmapping: ino {:?} foffset {} len {} flags {} moffset {}",
|
||||
inode, foffset, len, flags, moffset
|
||||
);
|
||||
|
||||
let open_flags = if (flags & fuse::SetupmappingFlags::WRITE.bits()) != 0 {
|
||||
libc::O_RDWR
|
||||
} else {
|
||||
libc::O_RDONLY
|
||||
};
|
||||
|
||||
let file = self.open_inode(inode, open_flags as i32)?;
|
||||
(*vu_req).map(foffset, moffset, len, flags, file.as_raw_fd())
|
||||
}
|
||||
|
||||
fn removemapping<T: FsCacheReqHandler>(
|
||||
&self,
|
||||
_ctx: Context,
|
||||
requests: Vec<fuse::RemovemappingOne>,
|
||||
vu_req: &mut T,
|
||||
) -> io::Result<()> {
|
||||
(*vu_req).unmap(requests)
|
||||
}
|
||||
|
||||
fn read<W: io::Write + ZeroCopyWriter>(
|
||||
&self,
|
||||
_ctx: Context,
|
||||
|
||||
Reference in New Issue
Block a user