Skip to content

Commit

Permalink
ptfs: introduce helper forget_one to reduce duplicated code
Browse files Browse the repository at this point in the history
Rename original forget_one() to forget_one_locked() and introduce new
helper forget_one() to reduce duplicated code.

Signed-off-by: Jiang Liu <[email protected]>
  • Loading branch information
jiangliu committed Nov 15, 2023
1 parent e286177 commit b659ca7
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 9 deletions.
7 changes: 6 additions & 1 deletion src/passthrough/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -749,7 +749,7 @@ impl<S: BitmapSlice + Send + Sync> PassthroughFs<S> {
})
}

fn forget_one(&self, inodes: &mut InodeStore, inode: Inode, count: u64) {
fn forget_one_locked(&self, inodes: &mut InodeStore, inode: Inode, count: u64) {
// ROOT_ID should not be forgotten, or we're not able to access to files any more.
if inode == fuse::ROOT_ID {
return;
Expand Down Expand Up @@ -786,6 +786,11 @@ impl<S: BitmapSlice + Send + Sync> PassthroughFs<S> {
}
}

fn forget_one(&self, inode: Inode, count: u64) {
let mut inodes = self.inode_map.get_map_mut();
self.forget_one_locked(&mut inodes, inode, count)
}

fn do_release(&self, inode: Inode, handle: Handle) -> io::Result<()> {
self.handle_map.release(handle, inode)
}
Expand Down
12 changes: 4 additions & 8 deletions src/passthrough/sync_io.rs
Original file line number Diff line number Diff line change
Expand Up @@ -373,16 +373,14 @@ impl<S: BitmapSlice + Send + Sync> FileSystem for PassthroughFs<S> {
}

fn forget(&self, _ctx: &Context, inode: Inode, count: u64) {
let mut inodes = self.inode_map.get_map_mut();

self.forget_one(&mut inodes, inode, count)
self.forget_one(inode, count)
}

fn batch_forget(&self, _ctx: &Context, requests: Vec<(Inode, u64)>) {
let mut inodes = self.inode_map.get_map_mut();

for (inode, count) in requests {
self.forget_one(&mut inodes, inode, count)
self.forget_one_locked(&mut inodes, inode, count)
}
}

Expand Down Expand Up @@ -465,8 +463,7 @@ impl<S: BitmapSlice + Send + Sync> FileSystem for PassthroughFs<S> {
};

let entry = self.do_lookup(inode, name)?;
let mut inodes = self.inode_map.get_map_mut();
self.forget_one(&mut inodes, entry.inode, 1);
self.forget_one(entry.inode, 1);
entry.inode
};

Expand Down Expand Up @@ -503,8 +500,7 @@ impl<S: BitmapSlice + Send + Sync> FileSystem for PassthroughFs<S> {
// true when size is not large enough to hold entry.
if r == 0 {
// Release the refcount acquired by self.do_lookup().
let mut inodes = self.inode_map.get_map_mut();
self.forget_one(&mut inodes, ino, 1);
self.forget_one(ino, 1);
}
r
})
Expand Down

0 comments on commit b659ca7

Please sign in to comment.