bcachefs: bch2_trans_verify_not_unlocked_or_in_restart()
Fold two asserts into one. Signed-off-by: Kent Overstreet <kent.overstreet@linux.dev>
This commit is contained in:
parent
a71a1fac90
commit
b318882022
6 changed files with 32 additions and 40 deletions
|
@ -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;
|
||||
}
|
||||
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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) ||
|
||||
|
|
|
@ -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));
|
||||
|
|
|
@ -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));
|
||||
|
||||
|
|
|
@ -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) ?:
|
||||
|
|
Loading…
Add table
Reference in a new issue