]> git.ipfire.org Git - thirdparty/kernel/linux.git/commitdiff
bcachefs: bch2_trans_verify_not_unlocked_or_in_restart()
authorKent Overstreet <kent.overstreet@linux.dev>
Sun, 27 Oct 2024 23:32:40 +0000 (19:32 -0400)
committerKent Overstreet <kent.overstreet@linux.dev>
Sat, 21 Dec 2024 06:36:16 +0000 (01:36 -0500)
Fold two asserts into one.

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

index acf70aaf2fd2999929720aa567c877bc6184a057..1efc77fc9abf719fc3aaf35cd8f9a3199569eab3 100644 (file)
@@ -327,7 +327,7 @@ out:
 void bch2_assert_pos_locked(struct btree_trans *trans, enum btree_id id,
                            struct bpos pos)
 {
-       bch2_trans_verify_not_unlocked(trans);
+       bch2_trans_verify_not_unlocked_or_in_restart(trans);
 
        struct btree_path *path;
        struct trans_for_each_path_inorder_iter iter;
@@ -1265,7 +1265,7 @@ __bch2_btree_path_set_pos(struct btree_trans *trans,
 {
        int cmp = bpos_cmp(new_pos, trans->paths[path_idx].pos);
 
-       bch2_trans_verify_not_in_restart(trans);
+       bch2_trans_verify_not_unlocked_or_in_restart(trans);
        EBUG_ON(!trans->paths[path_idx].ref);
 
        trace_btree_path_set_pos(trans, trans->paths + path_idx, &new_pos);
@@ -1425,7 +1425,7 @@ void __noreturn bch2_trans_restart_error(struct btree_trans *trans, u32 restart_
              (void *) trans->last_begin_ip);
 }
 
-void __noreturn bch2_trans_in_restart_error(struct btree_trans *trans)
+static void __noreturn bch2_trans_in_restart_error(struct btree_trans *trans)
 {
 #ifdef CONFIG_BCACHEFS_DEBUG
        struct printbuf buf = PRINTBUF;
@@ -1440,10 +1440,16 @@ void __noreturn bch2_trans_in_restart_error(struct btree_trans *trans)
 #endif
 }
 
-void __noreturn bch2_trans_unlocked_error(struct btree_trans *trans)
+void __noreturn bch2_trans_unlocked_or_in_restart_error(struct btree_trans *trans)
 {
-       panic("trans should be locked, unlocked by %pS\n",
-             (void *) trans->last_unlock_ip);
+       if (trans->restarted)
+               bch2_trans_in_restart_error(trans);
+
+       if (!trans->locked)
+               panic("trans should be locked, unlocked by %pS\n",
+                     (void *) trans->last_unlock_ip);
+
+       BUG();
 }
 
 noinline __cold
@@ -1724,8 +1730,7 @@ btree_path_idx_t bch2_path_get(struct btree_trans *trans,
        struct trans_for_each_path_inorder_iter iter;
        btree_path_idx_t path_pos = 0, path_idx;
 
-       bch2_trans_verify_not_unlocked(trans);
-       bch2_trans_verify_not_in_restart(trans);
+       bch2_trans_verify_not_unlocked_or_in_restart(trans);
        bch2_trans_verify_locks(trans);
 
        btree_trans_sort_paths(trans);
@@ -1877,7 +1882,7 @@ bch2_btree_iter_traverse(struct btree_iter *iter)
        struct btree_trans *trans = iter->trans;
        int ret;
 
-       bch2_trans_verify_not_unlocked(trans);
+       bch2_trans_verify_not_unlocked_or_in_restart(trans);
 
        iter->path = bch2_btree_path_set_pos(trans, iter->path,
                                        btree_iter_search_key(iter),
@@ -1952,7 +1957,7 @@ struct btree *bch2_btree_iter_next_node(struct btree_iter *iter)
        int ret;
 
        EBUG_ON(trans->paths[iter->path].cached);
-       bch2_trans_verify_not_in_restart(trans);
+       bch2_trans_verify_not_unlocked_or_in_restart(trans);
        bch2_btree_iter_verify(iter);
 
        ret = bch2_btree_path_traverse(trans, iter->path, iter->flags);
@@ -2161,8 +2166,7 @@ struct bkey_s_c btree_trans_peek_key_cache(struct btree_iter *iter, struct bpos
        struct bkey_s_c k;
        int ret;
 
-       bch2_trans_verify_not_in_restart(trans);
-       bch2_trans_verify_not_unlocked(trans);
+       bch2_trans_verify_not_unlocked_or_in_restart(trans);
 
        if ((iter->flags & BTREE_ITER_key_cache_fill) &&
            bpos_eq(iter->pos, pos))
@@ -2302,7 +2306,7 @@ struct bkey_s_c bch2_btree_iter_peek_upto(struct btree_iter *iter, struct bpos e
        struct bpos iter_pos;
        int ret;
 
-       bch2_trans_verify_not_unlocked(trans);
+       bch2_trans_verify_not_unlocked_or_in_restart(trans);
        EBUG_ON((iter->flags & BTREE_ITER_filter_snapshots) && bkey_eq(end, POS_MAX));
 
        if (iter->update_path) {
@@ -2475,7 +2479,7 @@ struct bkey_s_c bch2_btree_iter_peek_prev(struct btree_iter *iter)
        btree_path_idx_t saved_path = 0;
        int ret;
 
-       bch2_trans_verify_not_unlocked(trans);
+       bch2_trans_verify_not_unlocked_or_in_restart(trans);
        EBUG_ON(btree_iter_path(trans, iter)->cached ||
                btree_iter_path(trans, iter)->level);
 
@@ -2614,7 +2618,7 @@ struct bkey_s_c bch2_btree_iter_peek_slot(struct btree_iter *iter)
        struct bkey_s_c k;
        int ret;
 
-       bch2_trans_verify_not_unlocked(trans);
+       bch2_trans_verify_not_unlocked_or_in_restart(trans);
        bch2_btree_iter_verify(iter);
        bch2_btree_iter_verify_entry_exit(iter);
        EBUG_ON(btree_iter_path(trans, iter)->level && (iter->flags & BTREE_ITER_with_key_cache));
@@ -3136,7 +3140,7 @@ u32 bch2_trans_begin(struct btree_trans *trans)
                trans->notrace_relock_fail = false;
        }
 
-       bch2_trans_verify_not_unlocked(trans);
+       bch2_trans_verify_not_unlocked_or_in_restart(trans);
        return trans->restart_count;
 }
 
index 36899c6b134e5e2785ef871c2ed362d00fa309f3..6b1c46e954328d4337cc72d59edc6147d725e130 100644 (file)
@@ -236,12 +236,12 @@ int __must_check bch2_btree_path_traverse_one(struct btree_trans *,
                                              btree_path_idx_t,
                                              unsigned, unsigned long);
 
-static inline void bch2_trans_verify_not_unlocked(struct btree_trans *);
+static inline void bch2_trans_verify_not_unlocked_or_in_restart(struct btree_trans *);
 
 static inline int __must_check bch2_btree_path_traverse(struct btree_trans *trans,
                                          btree_path_idx_t path, unsigned flags)
 {
-       bch2_trans_verify_not_unlocked(trans);
+       bch2_trans_verify_not_unlocked_or_in_restart(trans);
 
        if (trans->paths[path].uptodate < BTREE_ITER_NEED_RELOCK)
                return 0;
@@ -326,20 +326,12 @@ static inline void bch2_trans_verify_not_restarted(struct btree_trans *trans,
                bch2_trans_restart_error(trans, restart_count);
 }
 
-void __noreturn bch2_trans_in_restart_error(struct btree_trans *);
+void __noreturn bch2_trans_unlocked_or_in_restart_error(struct btree_trans *);
 
-static inline void bch2_trans_verify_not_in_restart(struct btree_trans *trans)
+static inline void bch2_trans_verify_not_unlocked_or_in_restart(struct btree_trans *trans)
 {
-       if (trans->restarted)
-               bch2_trans_in_restart_error(trans);
-}
-
-void __noreturn bch2_trans_unlocked_error(struct btree_trans *);
-
-static inline void bch2_trans_verify_not_unlocked(struct btree_trans *trans)
-{
-       if (!trans->locked)
-               bch2_trans_unlocked_error(trans);
+       if (trans->restarted || !trans->locked)
+               bch2_trans_unlocked_or_in_restart_error(trans);
 }
 
 __always_inline
index 7c07f9fa9add3d9c9bf6045166992ecc14634053..ca4aeefd631e07dda8637c475f264c29a707c931 100644 (file)
@@ -282,7 +282,7 @@ static inline int btree_node_lock(struct btree_trans *trans,
        int ret = 0;
 
        EBUG_ON(level >= BTREE_MAX_DEPTH);
-       bch2_trans_verify_not_unlocked(trans);
+       bch2_trans_verify_not_unlocked_or_in_restart(trans);
 
        if (likely(six_trylock_type(&b->lock, type)) ||
            btree_node_lock_increment(trans, b, level, (enum btree_node_locked_type) type) ||
index 3aca746d08f6c9d37a5b27ce5dd122136cc4a5d4..cf313477567a56227110f90abebec21ad31ad8be 100644 (file)
@@ -619,8 +619,7 @@ bch2_trans_commit_write_locked(struct btree_trans *trans, unsigned flags,
        unsigned u64s = 0;
        int ret = 0;
 
-       bch2_trans_verify_not_unlocked(trans);
-       bch2_trans_verify_not_in_restart(trans);
+       bch2_trans_verify_not_unlocked_or_in_restart(trans);
 
        if (race_fault()) {
                trace_and_count(c, trans_restart_fault_inject, trans, trace_ip);
@@ -1008,8 +1007,7 @@ int __bch2_trans_commit(struct btree_trans *trans, unsigned flags)
        struct bch_fs *c = trans->c;
        int ret = 0;
 
-       bch2_trans_verify_not_unlocked(trans);
-       bch2_trans_verify_not_in_restart(trans);
+       bch2_trans_verify_not_unlocked_or_in_restart(trans);
 
        if (!trans->nr_updates &&
            !trans->journal_entries_u64s)
@@ -1070,8 +1068,7 @@ int __bch2_trans_commit(struct btree_trans *trans, unsigned flags)
        }
 retry:
        errored_at = NULL;
-       bch2_trans_verify_not_unlocked(trans);
-       bch2_trans_verify_not_in_restart(trans);
+       bch2_trans_verify_not_unlocked_or_in_restart(trans);
        if (likely(!(flags & BCH_TRANS_COMMIT_no_journal_res)))
                memset(&trans->journal_res, 0, sizeof(trans->journal_res));
        memset(&trans->fs_usage_delta, 0, sizeof(trans->fs_usage_delta));
index 865c4724d550b29fd488cfd3e5c3a2a6cb5d62f7..c11babe31f54e12b89e68652e0b426f2e05c2839 100644 (file)
@@ -1960,8 +1960,7 @@ int __bch2_foreground_maybe_merge(struct btree_trans *trans,
        u64 start_time = local_clock();
        int ret = 0;
 
-       bch2_trans_verify_not_in_restart(trans);
-       bch2_trans_verify_not_unlocked(trans);
+       bch2_trans_verify_not_unlocked_or_in_restart(trans);
        BUG_ON(!trans->paths[path].should_be_locked);
        BUG_ON(!btree_node_locked(&trans->paths[path], level));
 
index 10f400957f21a2f29d59a2dd2a2740eb398bbd4d..1c6cf3e2e6a971e39d37d151936570a6efa90f49 100644 (file)
@@ -159,7 +159,7 @@ static inline int bch2_foreground_maybe_merge(struct btree_trans *trans,
                                              unsigned level,
                                              unsigned flags)
 {
-       bch2_trans_verify_not_unlocked(trans);
+       bch2_trans_verify_not_unlocked_or_in_restart(trans);
 
        return  bch2_foreground_maybe_merge_sibling(trans, path, level, flags,
                                                    btree_prev_sib) ?: