Skip to content

Commit d3c7727

Browse files
author
Kent Overstreet
committed
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: Kent Overstreet <kent.overstreet@linux.dev>
1 parent 01ccee2 commit d3c7727

5 files changed

Lines changed: 31 additions & 12 deletions

File tree

fs/bcachefs/bcachefs_format.h

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2260,7 +2260,8 @@ LE32_BITMASK(JSET_NO_FLUSH, struct jset, flags, 5, 6);
22602260
enum btree_id_flags {
22612261
BTREE_ID_EXTENTS = BIT(0),
22622262
BTREE_ID_SNAPSHOTS = BIT(1),
2263-
BTREE_ID_DATA = BIT(2),
2263+
BTREE_ID_SNAPSHOT_FIELD = BIT(2),
2264+
BTREE_ID_DATA = BIT(3),
22642265
};
22652266

22662267
#define BCH_BTREE_IDS() \
@@ -2315,12 +2316,12 @@ enum btree_id_flags {
23152316
BIT_ULL(KEY_TYPE_bucket_gens)) \
23162317
x(snapshot_trees, 15, 0, \
23172318
BIT_ULL(KEY_TYPE_snapshot_tree)) \
2318-
x(deleted_inodes, 16, BTREE_ID_SNAPSHOTS, \
2319+
x(deleted_inodes, 16, BTREE_ID_SNAPSHOT_FIELD, \
23192320
BIT_ULL(KEY_TYPE_set)) \
23202321
x(logged_ops, 17, 0, \
23212322
BIT_ULL(KEY_TYPE_logged_op_truncate)| \
23222323
BIT_ULL(KEY_TYPE_logged_op_finsert)) \
2323-
x(rebalance_work, 18, BTREE_ID_SNAPSHOTS, \
2324+
x(rebalance_work, 18, BTREE_ID_SNAPSHOT_FIELD, \
23242325
BIT_ULL(KEY_TYPE_set)|BIT_ULL(KEY_TYPE_cookie))
23252326

23262327
enum btree_id {

fs/bcachefs/bkey_methods.c

Lines changed: 14 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -186,15 +186,20 @@ int __bch2_bkey_invalid(struct bch_fs *c, struct bkey_s_c k,
186186
if (type != BKEY_TYPE_btree) {
187187
enum btree_id btree = type - 1;
188188

189-
bkey_fsck_err_on(!btree_type_has_snapshots(btree) &&
190-
k.k->p.snapshot, c, err,
191-
bkey_snapshot_nonzero,
192-
"nonzero snapshot");
193-
194-
bkey_fsck_err_on(btree_type_has_snapshots(btree) &&
195-
!k.k->p.snapshot, c, err,
196-
bkey_snapshot_zero,
197-
"snapshot == 0");
189+
if (btree_type_has_snapshots(btree)) {
190+
bkey_fsck_err_on(!k.k->p.snapshot, c, err,
191+
bkey_snapshot_zero,
192+
"snapshot == 0");
193+
} else if (!btree_type_has_snapshot_field(btree)) {
194+
bkey_fsck_err_on(k.k->p.snapshot, c, err,
195+
bkey_snapshot_nonzero,
196+
"nonzero snapshot");
197+
} else {
198+
/*
199+
* btree uses snapshot field but it's not required to be
200+
* nonzero
201+
*/
202+
}
198203

199204
bkey_fsck_err_on(bkey_eq(k.k->p, POS_MAX), c, err,
200205
bkey_at_pos_max,

fs/bcachefs/btree_iter.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -416,6 +416,7 @@ static inline unsigned __bch2_btree_iter_flags(struct btree_trans *trans,
416416
flags |= BTREE_ITER_IS_EXTENTS;
417417

418418
if (!(flags & __BTREE_ITER_ALL_SNAPSHOTS) &&
419+
!btree_type_has_snapshot_field(btree_id) &&
419420
!btree_type_has_snapshots(btree_id))
420421
flags &= ~BTREE_ITER_ALL_SNAPSHOTS;
421422

fs/bcachefs/btree_trans_commit.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -269,6 +269,7 @@ static inline void btree_insert_entry_checks(struct btree_trans *trans,
269269
BUG_ON(i->level != i->path->level);
270270
BUG_ON(i->btree_id != i->path->btree_id);
271271
EBUG_ON(!i->level &&
272+
btree_type_has_snapshots(i->btree_id) &&
272273
!(i->flags & BTREE_UPDATE_INTERNAL_SNAPSHOT_NODE) &&
273274
test_bit(JOURNAL_REPLAY_DONE, &trans->c->journal.flags) &&
274275
i->k->k.p.snapshot &&

fs/bcachefs/btree_types.h

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -710,6 +710,17 @@ static inline bool btree_type_has_snapshots(enum btree_id id)
710710
return (1U << id) & mask;
711711
}
712712

713+
static inline bool btree_type_has_snapshot_field(enum btree_id id)
714+
{
715+
const unsigned mask = 0
716+
#define x(name, nr, flags, ...) |((!!((flags) & BTREE_ID_SNAPSHOT_FIELD)) << nr)
717+
BCH_BTREE_IDS()
718+
#undef x
719+
;
720+
721+
return (1U << id) & mask;
722+
}
723+
713724
static inline bool btree_type_has_ptrs(enum btree_id id)
714725
{
715726
const unsigned mask = 0

0 commit comments

Comments
 (0)