]> www.infradead.org Git - users/hch/configfs.git/commitdiff
bcachefs: bch2_trans_node_add no longer uses trans_for_each_path()
authorKent Overstreet <kent.overstreet@linux.dev>
Sun, 10 Dec 2023 22:44:04 +0000 (17:44 -0500)
committerKent Overstreet <kent.overstreet@linux.dev>
Mon, 1 Jan 2024 16:47:41 +0000 (11:47 -0500)
In the future we'll be making trans->paths resizable and potentially
having _many_ more paths (for fsck); we need to start fixing algorithms
that walk each path in a transaction where possible.

Signed-off-by: Kent Overstreet <kent.overstreet@linux.dev>
fs/bcachefs/btree_iter.c
fs/bcachefs/btree_iter.h
fs/bcachefs/btree_update_interior.c

index 2b0dc0ebbba326de6f39ed0b0f2b3abe4ede55f0..6d6963858a830315814cdb0f8f3e0c74332056d4 100644 (file)
@@ -674,14 +674,22 @@ static void bch2_trans_revalidate_updates_in_node(struct btree_trans *trans, str
  * A btree node is being replaced - update the iterator to point to the new
  * node:
  */
-void bch2_trans_node_add(struct btree_trans *trans, struct btree *b)
+void bch2_trans_node_add(struct btree_trans *trans,
+                        struct btree_path *path,
+                        struct btree *b)
 {
-       struct btree_path *path;
+       struct btree_path *prev;
 
-       trans_for_each_path(trans, path)
-               if (path->uptodate == BTREE_ITER_UPTODATE &&
-                   !path->cached &&
-                   btree_path_pos_in_node(path, b)) {
+       BUG_ON(!btree_path_pos_in_node(path, b));
+
+       while ((prev = prev_btree_path(trans, path)) &&
+              btree_path_pos_in_node(prev, b))
+               path = prev;
+
+       for (;
+            path && btree_path_pos_in_node(path, b);
+            path = next_btree_path(trans, path))
+               if (path->uptodate == BTREE_ITER_UPTODATE && !path->cached) {
                        enum btree_node_locked_type t =
                                btree_lock_want(path, b->c.level);
 
index 5be3c1a2c82030f618f1c24fb6e95be567874c90..f7d5f840394022ab5995e35642e1fe773fdbb6fb 100644 (file)
@@ -322,7 +322,7 @@ static inline void bch2_btree_path_downgrade(struct btree_trans *trans,
 
 void bch2_trans_downgrade(struct btree_trans *);
 
-void bch2_trans_node_add(struct btree_trans *trans, struct btree *);
+void bch2_trans_node_add(struct btree_trans *trans, struct btree_path *, struct btree *);
 void bch2_trans_node_reinit_iter(struct btree_trans *, struct btree *);
 
 int __must_check __bch2_btree_iter_traverse(struct btree_iter *iter);
index b3f1f7c9a5f47083ffc58bfaa109045f79ca10e1..cffc66cd481ffd940b7571b37bd6e3694edc823d 100644 (file)
@@ -1601,10 +1601,10 @@ static int btree_split(struct btree_update *as, struct btree_trans *trans,
        bch2_btree_node_free_inmem(trans, path, b);
 
        if (n3)
-               bch2_trans_node_add(trans, n3);
+               bch2_trans_node_add(trans, path, n3);
        if (n2)
-               bch2_trans_node_add(trans, n2);
-       bch2_trans_node_add(trans, n1);
+               bch2_trans_node_add(trans, path2, n2);
+       bch2_trans_node_add(trans, path1, n1);
 
        if (n3)
                six_unlock_intent(&n3->c.lock);
@@ -1913,7 +1913,7 @@ int __bch2_foreground_maybe_merge(struct btree_trans *trans,
        bch2_btree_node_free_inmem(trans, path, b);
        bch2_btree_node_free_inmem(trans, sib_path, m);
 
-       bch2_trans_node_add(trans, n);
+       bch2_trans_node_add(trans, path, n);
 
        bch2_trans_verify_paths(trans);
 
@@ -1985,7 +1985,7 @@ int bch2_btree_node_rewrite(struct btree_trans *trans,
 
        bch2_btree_node_free_inmem(trans, iter->path, b);
 
-       bch2_trans_node_add(trans, n);
+       bch2_trans_node_add(trans, iter->path, n);
        six_unlock_intent(&n->c.lock);
 
        bch2_btree_update_done(as, trans);