Skip to content

Add notify_inval_inode and extend get_rootfs to return fs_idx for umount #211

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 29 additions & 0 deletions src/api/server/sync_io.rs
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,36 @@ impl<F: FileSystem + Sync> Server<F> {
.map_err(Error::FailedToWrite)?;
buffer_writer.commit(None).map_err(Error::InvalidMessage)
}
/// Notify the kernel that an inode's data has been invalidated.
#[cfg(feature = "fusedev")]
pub fn notify_inval_inode<S: BitmapSlice>(
&self,
mut w: FuseDevWriter<'_, S>,
ino: u64,
off: u64,
len: u64,
) -> Result<usize> {
let mut buffer_writer = w.split_at(0).map_err(Error::FailedToSplitWriter)?;
let mut header = OutHeader::default();
let mut inode = NotifyInvalInodeOut::default();

header.unique = 0;
header.error = NotifyOpcode::InvalInode as i32;
header.len = std::mem::size_of::<OutHeader>() as u32
+ std::mem::size_of::<NotifyInvalInodeOut>() as u32;

inode.ino = ino;
inode.off = off as i64;
inode.len = len as i64;

buffer_writer
.write_obj(header)
.map_err(Error::FailedToWrite)?;
buffer_writer
.write_obj(inode)
.map_err(Error::FailedToWrite)?;
buffer_writer.commit(None).map_err(Error::InvalidMessage)
}
#[cfg(feature = "fusedev")]
/// Send a resend notification message to the kernel via FUSE. This function should be invoked as part of
/// the crash recovery routine. Given that FUSE initialization does not occur again during recovery,
Expand Down
17 changes: 9 additions & 8 deletions src/api/vfs/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -496,8 +496,8 @@ impl Vfs {
Ok((inode, parent))
}

/// Get the mounted backend file system alongside the path if there's one.
pub fn get_rootfs(&self, path: &str) -> VfsResult<Option<Arc<BackFileSystem>>> {
/// Get the mounted backend file system and its fs_idx alongside the path if there's one.
pub fn get_rootfs(&self, path: &str) -> VfsResult<Option<(Arc<BackFileSystem>, u8)>> {
// Serialize mount operations. Do not expect poisoned lock here.
let _guard = self.lock.lock().unwrap();
let inode = match self.root.path_walk(path).map_err(VfsError::PathWalk)? {
Expand All @@ -506,9 +506,10 @@ impl Vfs {
};

if let Some(mnt) = self.mountpoints.load().get(&inode) {
Ok(Some(self.get_fs_by_idx(mnt.fs_idx).map_err(|e| {
VfsError::NotFound(format!("fs index {}, {:?}", mnt.fs_idx, e))
})?))
let fs = self
.get_fs_by_idx(mnt.fs_idx)
.map_err(|e| VfsError::NotFound(format!("fs index {}, {:?}", mnt.fs_idx, e)))?;
Ok(Some((fs, mnt.fs_idx)))
} else {
// Pseudo fs dir inode exists, but that no backend is ever mounted
// is a normal case.
Expand Down Expand Up @@ -1582,9 +1583,9 @@ mod tests {
assert!(vfs.mount(Box::new(fs1), "/x/y/z").is_ok());
assert!(vfs.mount(Box::new(fs2), "/x/y").is_ok());

let m1 = vfs.get_rootfs("/x/y/z").unwrap().unwrap();
let (m1, _) = vfs.get_rootfs("/x/y/z").unwrap().unwrap();
assert!(m1.as_any().is::<FakeFileSystemOne>());
let m2 = vfs.get_rootfs("/x/y").unwrap().unwrap();
let (m2, _) = vfs.get_rootfs("/x/y").unwrap().unwrap();
assert!(m2.as_any().is::<FakeFileSystemTwo>());

assert!(vfs.umount("/x/y/z").is_ok());
Expand All @@ -1605,7 +1606,7 @@ mod tests {
assert!(vfs.mount(Box::new(fs1), "/x/y").is_ok());
assert!(vfs.mount(Box::new(fs2), "/x/y").is_ok());

let m1 = vfs.get_rootfs("/x/y").unwrap().unwrap();
let (m1, _) = vfs.get_rootfs("/x/y").unwrap().unwrap();
assert!(m1.as_any().is::<FakeFileSystemTwo>());

assert!(vfs.umount("/x/y").is_ok());
Expand Down
2 changes: 1 addition & 1 deletion src/passthrough/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1032,7 +1032,7 @@ mod tests {
fs.import().unwrap();
vfs.mount(Box::new(fs), "/submnt/A").unwrap();

let p_fs = vfs.get_rootfs("/submnt/A").unwrap().unwrap();
let (p_fs, _) = vfs.get_rootfs("/submnt/A").unwrap().unwrap();
let any_fs = p_fs.deref().as_any();
any_fs
.downcast_ref::<PassthroughFs>()
Expand Down
Loading