mirror of
https://mirrors.bfsu.edu.cn/git/linux.git
synced 2025-01-10 15:54:39 +08:00
bcachefs: Clean up bch2_btree_and_journal_walk()
Signed-off-by: Kent Overstreet <kent.overstreet@gmail.com> Signed-off-by: Kent Overstreet <kent.overstreet@linux.dev>
This commit is contained in:
parent
e68031fb46
commit
ac1019d32b
@ -261,16 +261,14 @@ void bch2_alloc_to_text(struct printbuf *out, struct bch_fs *c,
|
||||
#undef x
|
||||
}
|
||||
|
||||
static int bch2_alloc_read_fn(struct bch_fs *c, enum btree_id id,
|
||||
unsigned level, struct bkey_s_c k)
|
||||
static int bch2_alloc_read_fn(struct bch_fs *c, struct bkey_s_c k)
|
||||
{
|
||||
struct bch_dev *ca;
|
||||
struct bucket *g;
|
||||
struct bkey_alloc_unpacked u;
|
||||
|
||||
if (level ||
|
||||
(k.k->type != KEY_TYPE_alloc &&
|
||||
k.k->type != KEY_TYPE_alloc_v2))
|
||||
if (k.k->type != KEY_TYPE_alloc &&
|
||||
k.k->type != KEY_TYPE_alloc_v2)
|
||||
return 0;
|
||||
|
||||
ca = bch_dev_bkey_exists(c, k.k->p.inode);
|
||||
@ -289,13 +287,12 @@ static int bch2_alloc_read_fn(struct bch_fs *c, enum btree_id id,
|
||||
return 0;
|
||||
}
|
||||
|
||||
int bch2_alloc_read(struct bch_fs *c, struct journal_keys *journal_keys)
|
||||
int bch2_alloc_read(struct bch_fs *c)
|
||||
{
|
||||
int ret;
|
||||
|
||||
down_read(&c->gc_lock);
|
||||
ret = bch2_btree_and_journal_walk(c, journal_keys, BTREE_ID_alloc,
|
||||
NULL, bch2_alloc_read_fn);
|
||||
ret = bch2_btree_and_journal_walk(c, BTREE_ID_alloc, bch2_alloc_read_fn);
|
||||
up_read(&c->gc_lock);
|
||||
if (ret) {
|
||||
bch_err(c, "error reading alloc info: %i", ret);
|
||||
|
@ -91,8 +91,7 @@ void bch2_alloc_to_text(struct printbuf *, struct bch_fs *, struct bkey_s_c);
|
||||
.val_to_text = bch2_alloc_to_text, \
|
||||
}
|
||||
|
||||
struct journal_keys;
|
||||
int bch2_alloc_read(struct bch_fs *, struct journal_keys *);
|
||||
int bch2_alloc_read(struct bch_fs *);
|
||||
|
||||
static inline void bch2_wake_allocator(struct bch_dev *ca)
|
||||
{
|
||||
|
@ -1630,26 +1630,22 @@ int bch2_stripes_write(struct bch_fs *c, unsigned flags)
|
||||
return ret;
|
||||
}
|
||||
|
||||
static int bch2_stripes_read_fn(struct bch_fs *c, enum btree_id id,
|
||||
unsigned level, struct bkey_s_c k)
|
||||
static int bch2_stripes_read_fn(struct bch_fs *c, struct bkey_s_c k)
|
||||
{
|
||||
int ret = 0;
|
||||
|
||||
if (k.k->type == KEY_TYPE_stripe) {
|
||||
if (k.k->type == KEY_TYPE_stripe)
|
||||
ret = __ec_stripe_mem_alloc(c, k.k->p.offset, GFP_KERNEL) ?:
|
||||
bch2_mark_key(c, k, 0, 0, NULL, 0,
|
||||
BTREE_TRIGGER_NOATOMIC);
|
||||
if (ret)
|
||||
return ret;
|
||||
}
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
int bch2_stripes_read(struct bch_fs *c, struct journal_keys *journal_keys)
|
||||
int bch2_stripes_read(struct bch_fs *c)
|
||||
{
|
||||
int ret = bch2_btree_and_journal_walk(c, journal_keys, BTREE_ID_stripes,
|
||||
NULL, bch2_stripes_read_fn);
|
||||
int ret = bch2_btree_and_journal_walk(c, BTREE_ID_stripes,
|
||||
bch2_stripes_read_fn);
|
||||
if (ret)
|
||||
bch_err(c, "error reading stripes: %i", ret);
|
||||
|
||||
|
@ -215,8 +215,7 @@ void bch2_ec_flush_new_stripes(struct bch_fs *);
|
||||
|
||||
void bch2_stripes_heap_start(struct bch_fs *);
|
||||
|
||||
struct journal_keys;
|
||||
int bch2_stripes_read(struct bch_fs *, struct journal_keys *);
|
||||
int bch2_stripes_read(struct bch_fs *);
|
||||
int bch2_stripes_write(struct bch_fs *, unsigned);
|
||||
|
||||
int bch2_ec_mem_alloc(struct bch_fs *, bool);
|
||||
|
@ -323,9 +323,7 @@ static void btree_and_journal_iter_prefetch(struct bch_fs *c, struct btree *b,
|
||||
}
|
||||
|
||||
static int bch2_btree_and_journal_walk_recurse(struct bch_fs *c, struct btree *b,
|
||||
struct journal_keys *journal_keys,
|
||||
enum btree_id btree_id,
|
||||
btree_walk_node_fn node_fn,
|
||||
btree_walk_key_fn key_fn)
|
||||
{
|
||||
struct btree_and_journal_iter iter;
|
||||
@ -338,15 +336,9 @@ static int bch2_btree_and_journal_walk_recurse(struct bch_fs *c, struct btree *b
|
||||
bch2_btree_and_journal_iter_init_node_iter(&iter, c, b);
|
||||
|
||||
while ((k = bch2_btree_and_journal_iter_peek(&iter)).k) {
|
||||
ret = key_fn(c, btree_id, b->c.level, k);
|
||||
if (ret)
|
||||
break;
|
||||
|
||||
if (b->c.level) {
|
||||
bch2_bkey_buf_reassemble(&tmp, c, k);
|
||||
|
||||
bch2_btree_and_journal_iter_advance(&iter);
|
||||
|
||||
child = bch2_btree_node_get_noiter(c, tmp.k,
|
||||
b->c.btree_id, b->c.level - 1,
|
||||
false);
|
||||
@ -357,16 +349,17 @@ static int bch2_btree_and_journal_walk_recurse(struct bch_fs *c, struct btree *b
|
||||
|
||||
btree_and_journal_iter_prefetch(c, b, iter);
|
||||
|
||||
ret = (node_fn ? node_fn(c, b) : 0) ?:
|
||||
bch2_btree_and_journal_walk_recurse(c, child,
|
||||
journal_keys, btree_id, node_fn, key_fn);
|
||||
ret = bch2_btree_and_journal_walk_recurse(c, child,
|
||||
btree_id, key_fn);
|
||||
six_unlock_read(&child->c.lock);
|
||||
|
||||
if (ret)
|
||||
break;
|
||||
} else {
|
||||
bch2_btree_and_journal_iter_advance(&iter);
|
||||
ret = key_fn(c, k);
|
||||
}
|
||||
|
||||
if (ret)
|
||||
break;
|
||||
|
||||
bch2_btree_and_journal_iter_advance(&iter);
|
||||
}
|
||||
|
||||
bch2_btree_and_journal_iter_exit(&iter);
|
||||
@ -374,9 +367,7 @@ static int bch2_btree_and_journal_walk_recurse(struct bch_fs *c, struct btree *b
|
||||
return ret;
|
||||
}
|
||||
|
||||
int bch2_btree_and_journal_walk(struct bch_fs *c, struct journal_keys *journal_keys,
|
||||
enum btree_id btree_id,
|
||||
btree_walk_node_fn node_fn,
|
||||
int bch2_btree_and_journal_walk(struct bch_fs *c, enum btree_id btree_id,
|
||||
btree_walk_key_fn key_fn)
|
||||
{
|
||||
struct btree *b = c->btree_roots[btree_id].b;
|
||||
@ -386,10 +377,7 @@ int bch2_btree_and_journal_walk(struct bch_fs *c, struct journal_keys *journal_k
|
||||
return 0;
|
||||
|
||||
six_lock_read(&b->c.lock, NULL, NULL);
|
||||
ret = (node_fn ? node_fn(c, b) : 0) ?:
|
||||
bch2_btree_and_journal_walk_recurse(c, b, journal_keys, btree_id,
|
||||
node_fn, key_fn) ?:
|
||||
key_fn(c, btree_id, b->c.level + 1, bkey_i_to_s_c(&b->key));
|
||||
ret = bch2_btree_and_journal_walk_recurse(c, b, btree_id, key_fn);
|
||||
six_unlock_read(&b->c.lock);
|
||||
|
||||
return ret;
|
||||
@ -1120,14 +1108,14 @@ use_clean:
|
||||
|
||||
bch_verbose(c, "starting alloc read");
|
||||
err = "error reading allocation information";
|
||||
ret = bch2_alloc_read(c, &c->journal_keys);
|
||||
ret = bch2_alloc_read(c);
|
||||
if (ret)
|
||||
goto err;
|
||||
bch_verbose(c, "alloc read done");
|
||||
|
||||
bch_verbose(c, "starting stripes_read");
|
||||
err = "error reading stripes";
|
||||
ret = bch2_stripes_read(c, &c->journal_keys);
|
||||
ret = bch2_stripes_read(c);
|
||||
if (ret)
|
||||
goto err;
|
||||
bch_verbose(c, "stripes_read done");
|
||||
|
@ -45,12 +45,9 @@ void bch2_btree_and_journal_iter_init_node_iter(struct btree_and_journal_iter *,
|
||||
struct bch_fs *,
|
||||
struct btree *);
|
||||
|
||||
typedef int (*btree_walk_node_fn)(struct bch_fs *c, struct btree *b);
|
||||
typedef int (*btree_walk_key_fn)(struct bch_fs *c, enum btree_id id,
|
||||
unsigned level, struct bkey_s_c k);
|
||||
typedef int (*btree_walk_key_fn)(struct bch_fs *c, struct bkey_s_c k);
|
||||
|
||||
int bch2_btree_and_journal_walk(struct bch_fs *, struct journal_keys *, enum btree_id,
|
||||
btree_walk_node_fn, btree_walk_key_fn);
|
||||
int bch2_btree_and_journal_walk(struct bch_fs *, enum btree_id, btree_walk_key_fn);
|
||||
|
||||
void bch2_journal_keys_free(struct journal_keys *);
|
||||
void bch2_journal_entries_free(struct list_head *);
|
||||
|
Loading…
Reference in New Issue
Block a user