Commit 495fa1a2 authored by Kent Overstreet's avatar Kent Overstreet Committed by Kent Overstreet

bcachefs: Refactor bch2_readdir() a bit

The tweaks to ctx->pos handling are also to help the fuse port
Signed-off-by: default avatarKent Overstreet <kent.overstreet@linux.dev>
parent 3826ee0b
...@@ -354,36 +354,31 @@ int bch2_readdir(struct bch_fs *c, u64 inum, struct dir_context *ctx) ...@@ -354,36 +354,31 @@ int bch2_readdir(struct bch_fs *c, u64 inum, struct dir_context *ctx)
struct btree_iter *iter; struct btree_iter *iter;
struct bkey_s_c k; struct bkey_s_c k;
struct bkey_s_c_dirent dirent; struct bkey_s_c_dirent dirent;
unsigned len;
int ret; int ret;
bch2_trans_init(&trans, c, 0, 0); bch2_trans_init(&trans, c, 0, 0);
for_each_btree_key(&trans, iter, BTREE_ID_DIRENTS, for_each_btree_key(&trans, iter, BTREE_ID_DIRENTS,
POS(inum, ctx->pos), 0, k, ret) { POS(inum, ctx->pos), 0, k, ret) {
if (k.k->p.inode > inum)
break;
if (k.k->type != KEY_TYPE_dirent) if (k.k->type != KEY_TYPE_dirent)
continue; continue;
dirent = bkey_s_c_to_dirent(k); dirent = bkey_s_c_to_dirent(k);
if (bkey_cmp(k.k->p, POS(inum, ctx->pos)) < 0)
continue;
if (k.k->p.inode > inum)
break;
len = bch2_dirent_name_bytes(dirent);
/* /*
* XXX: dir_emit() can fault and block, while we're holding * XXX: dir_emit() can fault and block, while we're holding
* locks * locks
*/ */
if (!dir_emit(ctx, dirent.v->d_name, len, ctx->pos = dirent.k->p.offset;
if (!dir_emit(ctx, dirent.v->d_name,
bch2_dirent_name_bytes(dirent),
le64_to_cpu(dirent.v->d_inum), le64_to_cpu(dirent.v->d_inum),
dirent.v->d_type)) dirent.v->d_type))
break; break;
ctx->pos = dirent.k->p.offset + 1;
ctx->pos = k.k->p.offset + 1;
} }
ret = bch2_trans_exit(&trans) ?: ret; ret = bch2_trans_exit(&trans) ?: 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