bcachefs: bch2_btree_path_to_text()
authorKent Overstreet <kent.overstreet@linux.dev>
Sat, 6 Apr 2024 01:32:06 +0000 (21:32 -0400)
committerKent Overstreet <kent.overstreet@linux.dev>
Wed, 8 May 2024 21:29:18 +0000 (17:29 -0400)
Long form version of bch2_btree_path_to_text() - useful in error
messages and tracepoints.

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

index 080cb50168b05d2f9fa908bf367606a0b118740b..ca3b6a0ea1f8e63979fc6296241c1c4f3245036c 100644 (file)
@@ -1426,23 +1426,63 @@ void bch2_dump_trans_updates(struct btree_trans *trans)
        printbuf_exit(&buf);
 }
 
-static void bch2_btree_path_to_text(struct printbuf *out, struct btree_trans *trans, btree_path_idx_t path_idx)
+static void bch2_btree_path_to_text_short(struct printbuf *out, struct btree_trans *trans, btree_path_idx_t path_idx)
 {
        struct btree_path *path = trans->paths + path_idx;
 
-       prt_printf(out, "path: idx %2u ref %u:%u %c %c btree=%s l=%u pos ",
+       prt_printf(out, "path: idx %2u ref %u:%u %c %c %c btree=%s l=%u pos ",
                   path_idx, path->ref, path->intent_ref,
                   path->preserve ? 'P' : ' ',
                   path->should_be_locked ? 'S' : ' ',
+                  path->cached ? 'C' : 'B',
                   bch2_btree_id_str(path->btree_id),
                   path->level);
        bch2_bpos_to_text(out, path->pos);
 
-       prt_printf(out, " locks %u", path->nodes_locked);
 #ifdef TRACK_PATH_ALLOCATED
        prt_printf(out, " %pS", (void *) path->ip_allocated);
 #endif
+}
+
+static const char *btree_node_locked_str(enum btree_node_locked_type t)
+{
+       switch (t) {
+       case BTREE_NODE_UNLOCKED:
+               return "unlocked";
+       case BTREE_NODE_READ_LOCKED:
+               return "read";
+       case BTREE_NODE_INTENT_LOCKED:
+               return "intent";
+       case BTREE_NODE_WRITE_LOCKED:
+               return "write";
+       default:
+               return NULL;
+       }
+}
+
+void bch2_btree_path_to_text(struct printbuf *out, struct btree_trans *trans, btree_path_idx_t path_idx)
+{
+       bch2_btree_path_to_text_short(out, trans, path_idx);
+
+       struct btree_path *path = trans->paths + path_idx;
+
+       prt_printf(out, " uptodate %u locks_want %u", path->uptodate, path->locks_want);
        prt_newline(out);
+
+       printbuf_indent_add(out, 2);
+       for (unsigned l = 0; l < BTREE_MAX_DEPTH; l++) {
+               prt_printf(out, "l=%u locks %s seq %u node ", l,
+                          btree_node_locked_str(btree_node_locked_type(path, l)),
+                          path->l[l].lock_seq);
+
+               int ret = PTR_ERR_OR_ZERO(path->l[l].b);
+               if (ret)
+                       prt_str(out, bch2_err_str(ret));
+               else
+                       prt_printf(out, "%px", path->l[l].b);
+               prt_newline(out);
+       }
+       printbuf_indent_sub(out, 2);
 }
 
 static noinline __cold
@@ -1454,8 +1494,10 @@ void __bch2_trans_paths_to_text(struct printbuf *out, struct btree_trans *trans,
        if (!nosort)
                btree_trans_sort_paths(trans);
 
-       trans_for_each_path_idx_inorder(trans, iter)
-               bch2_btree_path_to_text(out, trans, iter.path_idx);
+       trans_for_each_path_idx_inorder(trans, iter) {
+               bch2_btree_path_to_text_short(out, trans, iter.path_idx);
+               prt_newline(out);
+       }
 }
 
 noinline __cold
index 1c70836dd7cce4988ef8cf166ee0797fd8f8269e..fcf2742b6ad9a5d697f25ddfa5332128351f7f0e 100644 (file)
@@ -861,6 +861,7 @@ __bch2_btree_iter_peek_and_restart(struct btree_trans *trans,
 })
 
 void bch2_trans_updates_to_text(struct printbuf *, struct btree_trans *);
+void bch2_btree_path_to_text(struct printbuf *, struct btree_trans *, btree_path_idx_t);
 void bch2_trans_paths_to_text(struct printbuf *, struct btree_trans *);
 void bch2_dump_trans_updates(struct btree_trans *);
 void bch2_dump_trans_paths_updates(struct btree_trans *);
index 4ee4855395b9b0739a65a7e2b3bf3e00ccf46dd5..8d1c4f78db5eb83c35ba1903c0c74925700b073c 100644 (file)
@@ -836,6 +836,11 @@ void bch2_btree_path_verify_locks(struct btree_path *path)
 {
        unsigned l;
 
+       /*
+        * A path may be uptodate and yet have nothing locked if and only if
+        * there is no node at path->level, which generally means we were
+        * iterating over all nodes and got to the end of the btree
+        */
        if (!path->nodes_locked) {
                BUG_ON(path->uptodate == BTREE_ITER_UPTODATE &&
                       btree_path_node(path, path->level));