Commit 462f494b authored by Kent Overstreet's avatar Kent Overstreet

bcachefs: Fix lockdep splat in bch2_readdir

dir_emit() can fault (taking mmap_lock); thus we can't be holding btree
locks.
Signed-off-by: default avatarKent Overstreet <kent.overstreet@linux.dev>
parent b6898917
// SPDX-License-Identifier: GPL-2.0 // SPDX-License-Identifier: GPL-2.0
#include "bcachefs.h" #include "bcachefs.h"
#include "bkey_buf.h"
#include "bkey_methods.h" #include "bkey_methods.h"
#include "btree_update.h" #include "btree_update.h"
#include "extents.h" #include "extents.h"
...@@ -504,8 +505,10 @@ int bch2_readdir(struct bch_fs *c, subvol_inum inum, struct dir_context *ctx) ...@@ -504,8 +505,10 @@ int bch2_readdir(struct bch_fs *c, subvol_inum inum, struct dir_context *ctx)
struct bkey_s_c_dirent dirent; struct bkey_s_c_dirent dirent;
subvol_inum target; subvol_inum target;
u32 snapshot; u32 snapshot;
struct bkey_buf sk;
int ret; int ret;
bch2_bkey_buf_init(&sk);
bch2_trans_init(&trans, c, 0, 0); bch2_trans_init(&trans, c, 0, 0);
retry: retry:
bch2_trans_begin(&trans); bch2_trans_begin(&trans);
...@@ -528,10 +531,11 @@ int bch2_readdir(struct bch_fs *c, subvol_inum inum, struct dir_context *ctx) ...@@ -528,10 +531,11 @@ int bch2_readdir(struct bch_fs *c, subvol_inum inum, struct dir_context *ctx)
if (ret) if (ret)
continue; continue;
/* /* dir_emit() can fault and block: */
* XXX: dir_emit() can fault and block, while we're holding bch2_bkey_buf_reassemble(&sk, c, k);
* locks dirent = bkey_i_to_s_c_dirent(sk.k);
*/ bch2_trans_unlock(&trans);
ctx->pos = dirent.k->p.offset; ctx->pos = dirent.k->p.offset;
if (!dir_emit(ctx, dirent.v->d_name, if (!dir_emit(ctx, dirent.v->d_name,
bch2_dirent_name_bytes(dirent), bch2_dirent_name_bytes(dirent),
...@@ -554,6 +558,7 @@ int bch2_readdir(struct bch_fs *c, subvol_inum inum, struct dir_context *ctx) ...@@ -554,6 +558,7 @@ int bch2_readdir(struct bch_fs *c, subvol_inum inum, struct dir_context *ctx)
goto retry; goto retry;
bch2_trans_exit(&trans); bch2_trans_exit(&trans);
bch2_bkey_buf_exit(&sk, c);
return ret; return ret;
} }
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment