From: Dave Chinner <dchinner@xxxxxxxxxx> Untested, probably doesn't work, just a quick hack to indicate how this could be done with the new bcachefs inode cache. Signed-off-by: Dave Chinner <dchinner@xxxxxxxxxx> --- fs/bcachefs/fs.c | 41 +++++++++++++++++++++++++++++++++++++++++ 1 file changed, 41 insertions(+) diff --git a/fs/bcachefs/fs.c b/fs/bcachefs/fs.c index 4a1bb07a2574..7708ec2b68c1 100644 --- a/fs/bcachefs/fs.c +++ b/fs/bcachefs/fs.c @@ -1814,6 +1814,46 @@ void bch2_evict_subvolume_inodes(struct bch_fs *c, snapshot_id_list *s) darray_exit(&grabbed); } +static int +bch2_iter_vfs_inodes( + struct super_block *sb, + ino_iter_fn iter_fn, + void *private_data, + int flags) +{ + struct bch_inode_info *inode, *old_inode = NULL; + int ret = 0; + + mutex_lock(&c->vfs_inodes_lock); + list_for_each_entry(inode, &c->vfs_inodes_list, ei_vfs_inode_list) { + if (!super_iter_iget(&inode->v, flags)) + continue; + + if (!(flags & INO_ITER_UNSAFE)) + mutex_unlock(&c->vfs_inodes_lock); + + ret = iter_fn(VFS_I(ip), private_data); + cond_resched(); + + if (!(flags & INO_ITER_UNSAFE)) { + if (old_inode) + iput(&old_inode->v); + old_inode = inode; + mutex_lock(&c->vfs_inodes_lock); + } + + if (ret == INO_ITER_ABORT) { + ret = 0; + break; + } + if (ret < 0) + break; + } + if (old_inode) + iput(&old_inode->v); + return ret; +} + static int bch2_statfs(struct dentry *dentry, struct kstatfs *buf) { struct super_block *sb = dentry->d_sb; @@ -1995,6 +2035,7 @@ static const struct super_operations bch_super_operations = { .put_super = bch2_put_super, .freeze_fs = bch2_freeze, .unfreeze_fs = bch2_unfreeze, + .iter_vfs_inodes = bch2_iter_vfs_inodes }; static int bch2_set_super(struct super_block *s, void *data) -- 2.45.2