bcachefs: Clean up bch2_btree_and_journal_walk()
authorKent Overstreet <kent.overstreet@gmail.com>
Thu, 29 Apr 2021 19:37:47 +0000 (15:37 -0400)
committerKent Overstreet <kent.overstreet@linux.dev>
Sun, 22 Oct 2023 21:09:02 +0000 (17:09 -0400)
Signed-off-by: Kent Overstreet <kent.overstreet@gmail.com>
Signed-off-by: Kent Overstreet <kent.overstreet@linux.dev>
fs/bcachefs/alloc_background.c
fs/bcachefs/alloc_background.h
fs/bcachefs/ec.c
fs/bcachefs/ec.h
fs/bcachefs/recovery.c
fs/bcachefs/recovery.h

index 2d532fe4d30b0f2cdac3ef5bd089be0b1c1ba280..996b1afd138026bae295120938d2116bedf80024 100644 (file)
@@ -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);
index ad15a80602c0c53d3d3205f7f0f1bfd62984694e..9cadfdb5b83df30211082a06851131c25d5b197b 100644 (file)
@@ -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)
 {
index 7d681a7254c4cdd0e322bc60f3985a409da459f4..4fc774631d20c0bbe2d0f21264b13cadc1415b04 100644 (file)
@@ -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);
 
index 744e51eaf327e66577b768479b384d25c07a88db..e79626b59509a3082ecef7f06acba9afbabeb21f 100644 (file)
@@ -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);
index a9ccd14effe7297fc61cf2dc9217719bdc342d90..b35b297d4446891a2aa812e8c31746602e8e3be9 100644 (file)
@@ -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");
index fa91851b9ed7a2e890cb498b9012fe451c327813..e5565e4f335a535d27e960ab35571b21ca07171d 100644 (file)
@@ -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 *);