From b659ca79837f9b7e8240ba7a06b430cea09b67b9 Mon Sep 17 00:00:00 2001 From: Jiang Liu Date: Tue, 14 Nov 2023 14:14:24 +0800 Subject: [PATCH] ptfs: introduce helper forget_one to reduce duplicated code Rename original forget_one() to forget_one_locked() and introduce new helper forget_one() to reduce duplicated code. Signed-off-by: Jiang Liu --- src/passthrough/mod.rs | 7 ++++++- src/passthrough/sync_io.rs | 12 ++++-------- 2 files changed, 10 insertions(+), 9 deletions(-) diff --git a/src/passthrough/mod.rs b/src/passthrough/mod.rs index c246328f2..0567bf1e7 100644 --- a/src/passthrough/mod.rs +++ b/src/passthrough/mod.rs @@ -749,7 +749,7 @@ impl PassthroughFs { }) } - 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; @@ -786,6 +786,11 @@ impl PassthroughFs { } } + 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) } diff --git a/src/passthrough/sync_io.rs b/src/passthrough/sync_io.rs index 7eb6520f1..9df92c61a 100644 --- a/src/passthrough/sync_io.rs +++ b/src/passthrough/sync_io.rs @@ -373,16 +373,14 @@ impl FileSystem for PassthroughFs { } 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) } } @@ -465,8 +463,7 @@ impl FileSystem for PassthroughFs { }; 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 }; @@ -503,8 +500,7 @@ impl FileSystem for PassthroughFs { // 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 })