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

bcachefs: rebalance_work btree is not a snapshots btree



rebalance_work entries may refer to entries in the extents btree, which
is a snapshots btree, or they may also refer to entries in the reflink
btree, which is not.

Hence rebalance_work keys may use the snapshot field but it's not
required to be nonzero - add a new btree flag to reflect this.

Signed-off-by: default avatarKent Overstreet <kent.overstreet@linux.dev>
parent 01ccee22
Loading
Loading
Loading
Loading
+4 −3
Original line number Diff line number Diff line
@@ -2260,7 +2260,8 @@ LE32_BITMASK(JSET_NO_FLUSH, struct jset, flags, 5, 6);
enum btree_id_flags {
	BTREE_ID_EXTENTS	= BIT(0),
	BTREE_ID_SNAPSHOTS	= BIT(1),
	BTREE_ID_DATA		= BIT(2),
	BTREE_ID_SNAPSHOT_FIELD	= BIT(2),
	BTREE_ID_DATA		= BIT(3),
};

#define BCH_BTREE_IDS()								\
@@ -2315,12 +2316,12 @@ enum btree_id_flags {
	  BIT_ULL(KEY_TYPE_bucket_gens))					\
	x(snapshot_trees,	15,	0,					\
	  BIT_ULL(KEY_TYPE_snapshot_tree))					\
	x(deleted_inodes,	16,	BTREE_ID_SNAPSHOTS,			\
	x(deleted_inodes,	16,	BTREE_ID_SNAPSHOT_FIELD,		\
	  BIT_ULL(KEY_TYPE_set))						\
	x(logged_ops,		17,	0,					\
	  BIT_ULL(KEY_TYPE_logged_op_truncate)|					\
	  BIT_ULL(KEY_TYPE_logged_op_finsert))					\
	x(rebalance_work,	18,	BTREE_ID_SNAPSHOTS,			\
	x(rebalance_work,	18,	BTREE_ID_SNAPSHOT_FIELD,		\
	  BIT_ULL(KEY_TYPE_set)|BIT_ULL(KEY_TYPE_cookie))

enum btree_id {
+14 −9
Original line number Diff line number Diff line
@@ -186,15 +186,20 @@ int __bch2_bkey_invalid(struct bch_fs *c, struct bkey_s_c k,
	if (type != BKEY_TYPE_btree) {
		enum btree_id btree = type - 1;

		bkey_fsck_err_on(!btree_type_has_snapshots(btree) &&
				 k.k->p.snapshot, c, err,
				 bkey_snapshot_nonzero,
				 "nonzero snapshot");

		bkey_fsck_err_on(btree_type_has_snapshots(btree) &&
				 !k.k->p.snapshot, c, err,
		if (btree_type_has_snapshots(btree)) {
			bkey_fsck_err_on(!k.k->p.snapshot, c, err,
					 bkey_snapshot_zero,
					 "snapshot == 0");
		} else if (!btree_type_has_snapshot_field(btree)) {
			bkey_fsck_err_on(k.k->p.snapshot, c, err,
					 bkey_snapshot_nonzero,
					 "nonzero snapshot");
		} else {
			/*
			 * btree uses snapshot field but it's not required to be
			 * nonzero
			 */
		}

		bkey_fsck_err_on(bkey_eq(k.k->p, POS_MAX), c, err,
				 bkey_at_pos_max,
+1 −0
Original line number Diff line number Diff line
@@ -416,6 +416,7 @@ static inline unsigned __bch2_btree_iter_flags(struct btree_trans *trans,
		flags |= BTREE_ITER_IS_EXTENTS;

	if (!(flags & __BTREE_ITER_ALL_SNAPSHOTS) &&
	    !btree_type_has_snapshot_field(btree_id) &&
	    !btree_type_has_snapshots(btree_id))
		flags &= ~BTREE_ITER_ALL_SNAPSHOTS;

+1 −0
Original line number Diff line number Diff line
@@ -269,6 +269,7 @@ static inline void btree_insert_entry_checks(struct btree_trans *trans,
	BUG_ON(i->level		!= i->path->level);
	BUG_ON(i->btree_id	!= i->path->btree_id);
	EBUG_ON(!i->level &&
		btree_type_has_snapshots(i->btree_id) &&
		!(i->flags & BTREE_UPDATE_INTERNAL_SNAPSHOT_NODE) &&
		test_bit(JOURNAL_REPLAY_DONE, &trans->c->journal.flags) &&
		i->k->k.p.snapshot &&
+11 −0
Original line number Diff line number Diff line
@@ -710,6 +710,17 @@ static inline bool btree_type_has_snapshots(enum btree_id id)
	return (1U << id) & mask;
}

static inline bool btree_type_has_snapshot_field(enum btree_id id)
{
	const unsigned mask = 0
#define x(name, nr, flags, ...)	|((!!((flags) & BTREE_ID_SNAPSHOT_FIELD)) << nr)
	BCH_BTREE_IDS()
#undef x
	;

	return (1U << id) & mask;
}

static inline bool btree_type_has_ptrs(enum btree_id id)
{
	const unsigned mask = 0