Commit ca563dcc authored by Kent Overstreet's avatar Kent Overstreet
Browse files

bcachefs: bch2_trans_unlock() must always be followed by relock() or begin()



We're about to add new asserts for btree_trans locking consistency, and
part of that requires that aren't using the btree_trans while it's
unlocked.

Signed-off-by: default avatarKent Overstreet <kent.overstreet@linux.dev>
parent 4984faff
Loading
Loading
Loading
Loading
+3 −0
Original line number Diff line number Diff line
@@ -2172,6 +2172,9 @@ int bch2_bucket_io_time_reset(struct btree_trans *trans, unsigned dev,
	u64 now;
	int ret = 0;

	if (bch2_trans_relock(trans))
		bch2_trans_begin(trans);

	a = bch2_trans_start_alloc_update(trans, &iter,  POS(dev, bucket_nr));
	ret = PTR_ERR_OR_ZERO(a);
	if (ret)
+4 −0
Original line number Diff line number Diff line
@@ -1342,6 +1342,10 @@ int bch2_alloc_sectors_start_trans(struct btree_trans *trans,

	*wp_ret = wp = writepoint_find(trans, write_point.v);

	ret = bch2_trans_relock(trans);
	if (ret)
		goto err;

	/* metadata may not allocate on cache devices: */
	if (wp->data_type != BCH_DATA_user)
		have_cache = true;
+2 −0
Original line number Diff line number Diff line
@@ -729,6 +729,8 @@ transaction_restart: \
#define for_each_btree_key_upto(_trans, _iter, _btree_id,		\
				_start, _end, _flags, _k, _do)		\
({									\
	bch2_trans_begin(trans);					\
									\
	struct btree_iter _iter;					\
	bch2_trans_iter_init((_trans), &(_iter), (_btree_id),		\
			     (_start), (_flags));			\
+4 −3
Original line number Diff line number Diff line
@@ -737,9 +737,6 @@ static void btree_update_nodes_written(struct btree_update *as)
	 */
	b = READ_ONCE(as->b);
	if (b) {
		btree_path_idx_t path_idx = bch2_path_get_unlocked_mut(trans,
						as->btree_id, b->c.level, b->key.k.p);
		struct btree_path *path = trans->paths + path_idx;
		/*
		 * @b is the node we did the final insert into:
		 *
@@ -763,6 +760,10 @@ static void btree_update_nodes_written(struct btree_update *as)
		 * have here:
		 */
		bch2_trans_unlock(trans);
		bch2_trans_begin(trans);
		btree_path_idx_t path_idx = bch2_path_get_unlocked_mut(trans,
						as->btree_id, b->c.level, b->key.k.p);
		struct btree_path *path = trans->paths + path_idx;
		btree_node_lock_nopath_nofail(trans, &b->c, SIX_LOCK_intent);
		mark_btree_node_locked(trans, path, b->c.level, BTREE_NODE_INTENT_LOCKED);
		path->l[b->c.level].lock_seq = six_lock_seq(&b->c.lock);
+2 −0
Original line number Diff line number Diff line
@@ -386,6 +386,8 @@ static void bch2_update_unwritten_extent(struct btree_trans *trans,
	while (bio_sectors(bio)) {
		unsigned sectors = bio_sectors(bio);

		bch2_trans_begin(trans);

		bch2_trans_iter_init(trans, &iter, update->btree_id, update->op.pos,
				     BTREE_ITER_slots);
		ret = lockrestart_do(trans, ({
Loading