Message ID | 787204cda3fa8259bb7763c558a910cf7a2e609b.1712837044.git.fdmanana@suse.com (mailing list archive) |
---|---|
State | New, archived |
Headers | show |
Series | btrfs: add a shrinker for extent maps | expand |
在 2024/4/12 01:49, fdmanana@kernel.org 写道: > From: Filipe Manana <fdmanana@suse.com> > > Currently btrfs_prune_dentries() has open code to find the first inode in > a root with a minimum inode number. Remove that code and make it use the > helper btrfs_find_first_inode() for that task. > > Signed-off-by: Filipe Manana <fdmanana@suse.com> Reviewed-by: Qu Wenruo <wqu@suse.com> Thanks, Qu > --- > fs/btrfs/inode.c | 66 ++++++++++-------------------------------------- > 1 file changed, 14 insertions(+), 52 deletions(-) > > diff --git a/fs/btrfs/inode.c b/fs/btrfs/inode.c > index 9dc41334c3a3..2dae4e975e80 100644 > --- a/fs/btrfs/inode.c > +++ b/fs/btrfs/inode.c > @@ -4436,64 +4436,26 @@ static noinline int may_destroy_subvol(struct btrfs_root *root) > static void btrfs_prune_dentries(struct btrfs_root *root) > { > struct btrfs_fs_info *fs_info = root->fs_info; > - struct rb_node *node; > - struct rb_node *prev; > - struct btrfs_inode *entry; > - struct inode *inode; > - u64 objectid = 0; > + struct btrfs_inode *inode; > + u64 min_ino = 0; > > if (!BTRFS_FS_ERROR(fs_info)) > WARN_ON(btrfs_root_refs(&root->root_item) != 0); > > - spin_lock(&root->inode_lock); > -again: > - node = root->inode_tree.rb_node; > - prev = NULL; > - while (node) { > - prev = node; > - entry = rb_entry(node, struct btrfs_inode, rb_node); > - > - if (objectid < btrfs_ino(entry)) > - node = node->rb_left; > - else if (objectid > btrfs_ino(entry)) > - node = node->rb_right; > - else > - break; > - } > - if (!node) { > - while (prev) { > - entry = rb_entry(prev, struct btrfs_inode, rb_node); > - if (objectid <= btrfs_ino(entry)) { > - node = prev; > - break; > - } > - prev = rb_next(prev); > - } > - } > - while (node) { > - entry = rb_entry(node, struct btrfs_inode, rb_node); > - objectid = btrfs_ino(entry) + 1; > - inode = igrab(&entry->vfs_inode); > - if (inode) { > - spin_unlock(&root->inode_lock); > - if (atomic_read(&inode->i_count) > 1) > - d_prune_aliases(inode); > - /* > - * btrfs_drop_inode will have it removed from the inode > - * cache when its usage count hits zero. > - */ > - iput(inode); > - cond_resched(); > - spin_lock(&root->inode_lock); > - goto again; > - } > - > - if (cond_resched_lock(&root->inode_lock)) > - goto again; > + inode = btrfs_find_first_inode(root, min_ino); > + while (inode) { > + if (atomic_read(&inode->vfs_inode.i_count) > 1) > + d_prune_aliases(&inode->vfs_inode); > > - node = rb_next(node); > + min_ino = btrfs_ino(inode) + 1; > + /* > + * btrfs_drop_inode() will have it removed from the inode > + * cache when its usage count hits zero. > + */ > + iput(&inode->vfs_inode); > + cond_resched(); > + inode = btrfs_find_first_inode(root, min_ino); > } > - spin_unlock(&root->inode_lock); > } > > int btrfs_delete_subvolume(struct btrfs_inode *dir, struct dentry *dentry)
diff --git a/fs/btrfs/inode.c b/fs/btrfs/inode.c index 9dc41334c3a3..2dae4e975e80 100644 --- a/fs/btrfs/inode.c +++ b/fs/btrfs/inode.c @@ -4436,64 +4436,26 @@ static noinline int may_destroy_subvol(struct btrfs_root *root) static void btrfs_prune_dentries(struct btrfs_root *root) { struct btrfs_fs_info *fs_info = root->fs_info; - struct rb_node *node; - struct rb_node *prev; - struct btrfs_inode *entry; - struct inode *inode; - u64 objectid = 0; + struct btrfs_inode *inode; + u64 min_ino = 0; if (!BTRFS_FS_ERROR(fs_info)) WARN_ON(btrfs_root_refs(&root->root_item) != 0); - spin_lock(&root->inode_lock); -again: - node = root->inode_tree.rb_node; - prev = NULL; - while (node) { - prev = node; - entry = rb_entry(node, struct btrfs_inode, rb_node); - - if (objectid < btrfs_ino(entry)) - node = node->rb_left; - else if (objectid > btrfs_ino(entry)) - node = node->rb_right; - else - break; - } - if (!node) { - while (prev) { - entry = rb_entry(prev, struct btrfs_inode, rb_node); - if (objectid <= btrfs_ino(entry)) { - node = prev; - break; - } - prev = rb_next(prev); - } - } - while (node) { - entry = rb_entry(node, struct btrfs_inode, rb_node); - objectid = btrfs_ino(entry) + 1; - inode = igrab(&entry->vfs_inode); - if (inode) { - spin_unlock(&root->inode_lock); - if (atomic_read(&inode->i_count) > 1) - d_prune_aliases(inode); - /* - * btrfs_drop_inode will have it removed from the inode - * cache when its usage count hits zero. - */ - iput(inode); - cond_resched(); - spin_lock(&root->inode_lock); - goto again; - } - - if (cond_resched_lock(&root->inode_lock)) - goto again; + inode = btrfs_find_first_inode(root, min_ino); + while (inode) { + if (atomic_read(&inode->vfs_inode.i_count) > 1) + d_prune_aliases(&inode->vfs_inode); - node = rb_next(node); + min_ino = btrfs_ino(inode) + 1; + /* + * btrfs_drop_inode() will have it removed from the inode + * cache when its usage count hits zero. + */ + iput(&inode->vfs_inode); + cond_resched(); + inode = btrfs_find_first_inode(root, min_ino); } - spin_unlock(&root->inode_lock); } int btrfs_delete_subvolume(struct btrfs_inode *dir, struct dentry *dentry)