Commit ac1019d3 authored by Kent Overstreet's avatar Kent Overstreet Committed by Kent Overstreet

bcachefs: Clean up bch2_btree_and_journal_walk()

Signed-off-by: default avatarKent Overstreet <kent.overstreet@gmail.com>
Signed-off-by: default avatarKent Overstreet <kent.overstreet@linux.dev>
parent e68031fb
...@@ -261,16 +261,14 @@ void bch2_alloc_to_text(struct printbuf *out, struct bch_fs *c, ...@@ -261,16 +261,14 @@ void bch2_alloc_to_text(struct printbuf *out, struct bch_fs *c,
#undef x #undef x
} }
static int bch2_alloc_read_fn(struct bch_fs *c, enum btree_id id, static int bch2_alloc_read_fn(struct bch_fs *c, struct bkey_s_c k)
unsigned level, struct bkey_s_c k)
{ {
struct bch_dev *ca; struct bch_dev *ca;
struct bucket *g; struct bucket *g;
struct bkey_alloc_unpacked u; struct bkey_alloc_unpacked u;
if (level || if (k.k->type != KEY_TYPE_alloc &&
(k.k->type != KEY_TYPE_alloc && k.k->type != KEY_TYPE_alloc_v2)
k.k->type != KEY_TYPE_alloc_v2))
return 0; return 0;
ca = bch_dev_bkey_exists(c, k.k->p.inode); 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, ...@@ -289,13 +287,12 @@ static int bch2_alloc_read_fn(struct bch_fs *c, enum btree_id id,
return 0; 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; int ret;
down_read(&c->gc_lock); down_read(&c->gc_lock);
ret = bch2_btree_and_journal_walk(c, journal_keys, BTREE_ID_alloc, ret = bch2_btree_and_journal_walk(c, BTREE_ID_alloc, bch2_alloc_read_fn);
NULL, bch2_alloc_read_fn);
up_read(&c->gc_lock); up_read(&c->gc_lock);
if (ret) { if (ret) {
bch_err(c, "error reading alloc info: %i", 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); ...@@ -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, \ .val_to_text = bch2_alloc_to_text, \
} }
struct journal_keys; int bch2_alloc_read(struct bch_fs *);
int bch2_alloc_read(struct bch_fs *, struct journal_keys *);
static inline void bch2_wake_allocator(struct bch_dev *ca) static inline void bch2_wake_allocator(struct bch_dev *ca)
{ {
......
...@@ -1630,26 +1630,22 @@ int bch2_stripes_write(struct bch_fs *c, unsigned flags) ...@@ -1630,26 +1630,22 @@ int bch2_stripes_write(struct bch_fs *c, unsigned flags)
return ret; return ret;
} }
static int bch2_stripes_read_fn(struct bch_fs *c, enum btree_id id, static int bch2_stripes_read_fn(struct bch_fs *c, struct bkey_s_c k)
unsigned level, struct bkey_s_c k)
{ {
int ret = 0; 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) ?: ret = __ec_stripe_mem_alloc(c, k.k->p.offset, GFP_KERNEL) ?:
bch2_mark_key(c, k, 0, 0, NULL, 0, bch2_mark_key(c, k, 0, 0, NULL, 0,
BTREE_TRIGGER_NOATOMIC); BTREE_TRIGGER_NOATOMIC);
if (ret)
return 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, int ret = bch2_btree_and_journal_walk(c, BTREE_ID_stripes,
NULL, bch2_stripes_read_fn); bch2_stripes_read_fn);
if (ret) if (ret)
bch_err(c, "error reading stripes: %i", ret); bch_err(c, "error reading stripes: %i", ret);
......
...@@ -215,8 +215,7 @@ void bch2_ec_flush_new_stripes(struct bch_fs *); ...@@ -215,8 +215,7 @@ void bch2_ec_flush_new_stripes(struct bch_fs *);
void bch2_stripes_heap_start(struct bch_fs *); void bch2_stripes_heap_start(struct bch_fs *);
struct journal_keys; int bch2_stripes_read(struct bch_fs *);
int bch2_stripes_read(struct bch_fs *, struct journal_keys *);
int bch2_stripes_write(struct bch_fs *, unsigned); int bch2_stripes_write(struct bch_fs *, unsigned);
int bch2_ec_mem_alloc(struct bch_fs *, bool); 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, ...@@ -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, 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, enum btree_id btree_id,
btree_walk_node_fn node_fn,
btree_walk_key_fn key_fn) btree_walk_key_fn key_fn)
{ {
struct btree_and_journal_iter iter; 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 ...@@ -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); bch2_btree_and_journal_iter_init_node_iter(&iter, c, b);
while ((k = bch2_btree_and_journal_iter_peek(&iter)).k) { 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) { if (b->c.level) {
bch2_bkey_buf_reassemble(&tmp, c, k); bch2_bkey_buf_reassemble(&tmp, c, k);
bch2_btree_and_journal_iter_advance(&iter);
child = bch2_btree_node_get_noiter(c, tmp.k, child = bch2_btree_node_get_noiter(c, tmp.k,
b->c.btree_id, b->c.level - 1, b->c.btree_id, b->c.level - 1,
false); false);
...@@ -357,26 +349,25 @@ static int bch2_btree_and_journal_walk_recurse(struct bch_fs *c, struct btree *b ...@@ -357,26 +349,25 @@ static int bch2_btree_and_journal_walk_recurse(struct bch_fs *c, struct btree *b
btree_and_journal_iter_prefetch(c, b, iter); btree_and_journal_iter_prefetch(c, b, iter);
ret = (node_fn ? node_fn(c, b) : 0) ?: ret = bch2_btree_and_journal_walk_recurse(c, child,
bch2_btree_and_journal_walk_recurse(c, child, btree_id, key_fn);
journal_keys, btree_id, node_fn, key_fn);
six_unlock_read(&child->c.lock); six_unlock_read(&child->c.lock);
} else {
ret = key_fn(c, k);
}
if (ret) if (ret)
break; break;
} else {
bch2_btree_and_journal_iter_advance(&iter); bch2_btree_and_journal_iter_advance(&iter);
} }
}
bch2_btree_and_journal_iter_exit(&iter); bch2_btree_and_journal_iter_exit(&iter);
bch2_bkey_buf_exit(&tmp, c); bch2_bkey_buf_exit(&tmp, c);
return ret; return ret;
} }
int bch2_btree_and_journal_walk(struct bch_fs *c, struct journal_keys *journal_keys, int bch2_btree_and_journal_walk(struct bch_fs *c, enum btree_id btree_id,
enum btree_id btree_id,
btree_walk_node_fn node_fn,
btree_walk_key_fn key_fn) btree_walk_key_fn key_fn)
{ {
struct btree *b = c->btree_roots[btree_id].b; 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 ...@@ -386,10 +377,7 @@ int bch2_btree_and_journal_walk(struct bch_fs *c, struct journal_keys *journal_k
return 0; return 0;
six_lock_read(&b->c.lock, NULL, NULL); six_lock_read(&b->c.lock, NULL, NULL);
ret = (node_fn ? node_fn(c, b) : 0) ?: ret = bch2_btree_and_journal_walk_recurse(c, b, btree_id, key_fn);
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));
six_unlock_read(&b->c.lock); six_unlock_read(&b->c.lock);
return ret; return ret;
...@@ -1120,14 +1108,14 @@ int bch2_fs_recovery(struct bch_fs *c) ...@@ -1120,14 +1108,14 @@ int bch2_fs_recovery(struct bch_fs *c)
bch_verbose(c, "starting alloc read"); bch_verbose(c, "starting alloc read");
err = "error reading allocation information"; err = "error reading allocation information";
ret = bch2_alloc_read(c, &c->journal_keys); ret = bch2_alloc_read(c);
if (ret) if (ret)
goto err; goto err;
bch_verbose(c, "alloc read done"); bch_verbose(c, "alloc read done");
bch_verbose(c, "starting stripes_read"); bch_verbose(c, "starting stripes_read");
err = "error reading stripes"; err = "error reading stripes";
ret = bch2_stripes_read(c, &c->journal_keys); ret = bch2_stripes_read(c);
if (ret) if (ret)
goto err; goto err;
bch_verbose(c, "stripes_read done"); bch_verbose(c, "stripes_read done");
......
...@@ -45,12 +45,9 @@ void bch2_btree_and_journal_iter_init_node_iter(struct btree_and_journal_iter *, ...@@ -45,12 +45,9 @@ void bch2_btree_and_journal_iter_init_node_iter(struct btree_and_journal_iter *,
struct bch_fs *, struct bch_fs *,
struct btree *); 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, struct bkey_s_c k);
typedef int (*btree_walk_key_fn)(struct bch_fs *c, enum btree_id id,
unsigned level, struct bkey_s_c k);
int bch2_btree_and_journal_walk(struct bch_fs *, struct journal_keys *, enum btree_id, int bch2_btree_and_journal_walk(struct bch_fs *, enum btree_id, btree_walk_key_fn);
btree_walk_node_fn, btree_walk_key_fn);
void bch2_journal_keys_free(struct journal_keys *); void bch2_journal_keys_free(struct journal_keys *);
void bch2_journal_entries_free(struct list_head *); void bch2_journal_entries_free(struct list_head *);
......
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