From 6bd1305735bc4346e0ca6cc0ff27517e8bab8f0d Mon Sep 17 00:00:00 2001 From: Kent Overstreet Date: Sun, 31 Mar 2019 17:37:30 -0400 Subject: bcachefs: Fsck locking improvements Signed-off-by: Kent Overstreet --- fs/bcachefs/dirent.c | 19 +++++++++++++------ 1 file changed, 13 insertions(+), 6 deletions(-) (limited to 'fs/bcachefs/dirent.c') diff --git a/fs/bcachefs/dirent.c b/fs/bcachefs/dirent.c index 672a94936179..4479a9f55ddf 100644 --- a/fs/bcachefs/dirent.c +++ b/fs/bcachefs/dirent.c @@ -329,17 +329,18 @@ out: return inum; } -int bch2_empty_dir(struct bch_fs *c, u64 dir_inum) +int bch2_empty_dir_trans(struct btree_trans *trans, u64 dir_inum) { - struct btree_trans trans; struct btree_iter *iter; struct bkey_s_c k; int ret = 0; - bch2_trans_init(&trans, c); + iter = bch2_trans_get_iter(trans, BTREE_ID_DIRENTS, + POS(dir_inum, 0), 0); + if (IS_ERR(iter)) + return PTR_ERR(iter); - for_each_btree_key(&trans, iter, BTREE_ID_DIRENTS, - POS(dir_inum, 0), 0, k) { + for_each_btree_key_continue(iter, 0, k) { if (k.k->p.inode > dir_inum) break; @@ -348,11 +349,17 @@ int bch2_empty_dir(struct bch_fs *c, u64 dir_inum) break; } } - bch2_trans_exit(&trans); + bch2_trans_iter_put(trans, iter); return ret; } +int bch2_empty_dir(struct bch_fs *c, u64 dir_inum) +{ + return bch2_trans_do(c, NULL, 0, + bch2_empty_dir_trans(&trans, dir_inum)); +} + int bch2_readdir(struct bch_fs *c, struct file *file, struct dir_context *ctx) { -- cgit v1.2.3