]> git.sesse.net Git - bcachefs-tools-debian/blobdiff - libbcachefs/btree_iter.c
Update bcachefs sources to 95ff72a6c1 fixup! mm: Centralize & improve oom reporting...
[bcachefs-tools-debian] / libbcachefs / btree_iter.c
index 5c5e14d1d36019bbc6f60ee9ba9ae21fc58de4c9..a1512eb06914b14ac2432e09d34a8607e09ef4d2 100644 (file)
@@ -3273,11 +3273,14 @@ void __bch2_trans_init(struct btree_trans *trans, struct bch_fs *c,
                       const char *fn)
        __acquires(&c->btree_trans_barrier)
 {
+       struct btree_trans *pos;
+
        BUG_ON(lock_class_is_held(&bch2_btree_node_lock_key));
 
        memset(trans, 0, sizeof(*trans));
        trans->c                = c;
        trans->fn               = fn;
+       trans->task             = current;
 
        bch2_trans_alloc_paths(trans, c);
 
@@ -3293,9 +3296,15 @@ void __bch2_trans_init(struct btree_trans *trans, struct bch_fs *c,
 
        trans->srcu_idx = srcu_read_lock(&c->btree_trans_barrier);
 
-       trans->pid = current->pid;
        mutex_lock(&c->btree_trans_lock);
-       list_add(&trans->list, &c->btree_trans_list);
+       list_for_each_entry(pos, &c->btree_trans_list, list) {
+               if (trans->task->pid < pos->task->pid) {
+                       list_add_tail(&trans->list, &pos->list);
+                       goto list_add_done;
+               }
+       }
+       list_add_tail(&trans->list, &c->btree_trans_list);
+list_add_done:
        mutex_unlock(&c->btree_trans_lock);
 }
 
@@ -3383,73 +3392,55 @@ bch2_btree_path_node_to_text(struct printbuf *out,
        bch2_bpos_to_text(out, btree_node_pos(_b, cached));
 }
 
-static bool trans_has_locks(struct btree_trans *trans)
-{
-       struct btree_path *path;
-
-       trans_for_each_path(trans, path)
-               if (path->nodes_locked)
-                       return true;
-       return false;
-}
-
-void bch2_btree_trans_to_text(struct printbuf *out, struct bch_fs *c)
+void bch2_btree_trans_to_text(struct printbuf *out, struct btree_trans *trans)
 {
-       struct btree_trans *trans;
        struct btree_path *path;
        struct btree *b;
        static char lock_types[] = { 'r', 'i', 'w' };
        unsigned l;
 
-       mutex_lock(&c->btree_trans_lock);
-       list_for_each_entry(trans, &c->btree_trans_list, list) {
-               if (!trans_has_locks(trans))
-                       continue;
-
-               prt_printf(out, "%i %s\n", trans->pid, trans->fn);
+       prt_printf(out, "%i %s\n", trans->task->pid, trans->fn);
 
-               trans_for_each_path(trans, path) {
-                       if (!path->nodes_locked)
-                               continue;
+       trans_for_each_path(trans, path) {
+               if (!path->nodes_locked)
+                       continue;
 
-                       prt_printf(out, "  path %u %c l=%u %s:",
-                              path->idx,
-                              path->cached ? 'c' : 'b',
-                              path->level,
-                              bch2_btree_ids[path->btree_id]);
-                       bch2_bpos_to_text(out, path->pos);
-                       prt_printf(out, "\n");
-
-                       for (l = 0; l < BTREE_MAX_DEPTH; l++) {
-                               if (btree_node_locked(path, l)) {
-                                       prt_printf(out, "    %s l=%u ",
-                                              btree_node_intent_locked(path, l) ? "i" : "r", l);
-                                       bch2_btree_path_node_to_text(out,
-                                                       (void *) path->l[l].b,
-                                                       path->cached);
-                                       prt_printf(out, "\n");
-                               }
+               prt_printf(out, "  path %u %c l=%u %s:",
+                      path->idx,
+                      path->cached ? 'c' : 'b',
+                      path->level,
+                      bch2_btree_ids[path->btree_id]);
+               bch2_bpos_to_text(out, path->pos);
+               prt_printf(out, "\n");
+
+               for (l = 0; l < BTREE_MAX_DEPTH; l++) {
+                       if (btree_node_locked(path, l)) {
+                               prt_printf(out, "    %s l=%u ",
+                                      btree_node_intent_locked(path, l) ? "i" : "r", l);
+                               bch2_btree_path_node_to_text(out,
+                                               (void *) path->l[l].b,
+                                               path->cached);
+                               prt_printf(out, "\n");
                        }
                }
+       }
 
-               b = READ_ONCE(trans->locking);
-               if (b) {
-                       path = &trans->paths[trans->locking_path_idx];
-                       prt_printf(out, "  locking path %u %c l=%u %c %s:",
-                              trans->locking_path_idx,
-                              path->cached ? 'c' : 'b',
-                              trans->locking_level,
-                              lock_types[trans->locking_lock_type],
-                              bch2_btree_ids[trans->locking_btree_id]);
-                       bch2_bpos_to_text(out, trans->locking_pos);
-
-                       prt_printf(out, " node ");
-                       bch2_btree_path_node_to_text(out,
-                                       (void *) b, path->cached);
-                       prt_printf(out, "\n");
-               }
+       b = READ_ONCE(trans->locking);
+       if (b) {
+               path = &trans->paths[trans->locking_path_idx];
+               prt_printf(out, "  locking path %u %c l=%u %c %s:",
+                      trans->locking_path_idx,
+                      path->cached ? 'c' : 'b',
+                      trans->locking_level,
+                      lock_types[trans->locking_lock_type],
+                      bch2_btree_ids[trans->locking_btree_id]);
+               bch2_bpos_to_text(out, trans->locking_pos);
+
+               prt_printf(out, " node ");
+               bch2_btree_path_node_to_text(out,
+                               (void *) b, path->cached);
+               prt_printf(out, "\n");
        }
-       mutex_unlock(&c->btree_trans_lock);
 }
 
 void bch2_fs_btree_iter_exit(struct bch_fs *c)