Skip to content

Commit

Permalink
bcachefs: Require snapshot id to be set
Browse files Browse the repository at this point in the history
Now that all the existing code has been converted for snapshots, this
patch changes the code for initializing a btree iterator to require a
snapshot to be specified, and also change bkey_invalid() to allow for
non U32_MAX snapshot IDs.

Signed-off-by: Kent Overstreet <kent.overstreet@gmail.com>
  • Loading branch information
koverstreet authored and Kent Overstreet committed Oct 22, 2023
1 parent 6f83cb8 commit a861c72
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 13 deletions.
2 changes: 1 addition & 1 deletion fs/bcachefs/bkey_methods.c
Original file line number Diff line number Diff line change
Expand Up @@ -182,7 +182,7 @@ const char *__bch2_bkey_invalid(struct bch_fs *c, struct bkey_s_c k,

if (type != BKEY_TYPE_btree &&
btree_type_has_snapshots(type) &&
k.k->p.snapshot != U32_MAX)
!k.k->p.snapshot)
return "invalid snapshot field";

if (type != BKEY_TYPE_btree &&
Expand Down
20 changes: 8 additions & 12 deletions fs/bcachefs/btree_iter.c
Original file line number Diff line number Diff line change
Expand Up @@ -677,6 +677,9 @@ static void bch2_btree_iter_verify(struct btree_iter *iter)

static void bch2_btree_iter_verify_entry_exit(struct btree_iter *iter)
{
BUG_ON((iter->flags & BTREE_ITER_FILTER_SNAPSHOTS) &&
!iter->pos.snapshot);

BUG_ON(!(iter->flags & BTREE_ITER_ALL_SNAPSHOTS) &&
iter->pos.snapshot != iter->snapshot);

Expand Down Expand Up @@ -2522,20 +2525,13 @@ static void __bch2_trans_iter_init(struct btree_trans *trans,
btree_node_type_is_extents(btree_id))
flags |= BTREE_ITER_IS_EXTENTS;

if (!btree_type_has_snapshots(btree_id) &&
!(flags & __BTREE_ITER_ALL_SNAPSHOTS))
if (!(flags & __BTREE_ITER_ALL_SNAPSHOTS) &&
!btree_type_has_snapshots(btree_id))
flags &= ~BTREE_ITER_ALL_SNAPSHOTS;
#if 0
/* let's have this be explicitly set: */
if ((flags & BTREE_ITER_TYPE) != BTREE_ITER_NODES &&
btree_type_has_snapshots(btree_id) &&
!(flags & BTREE_ITER_ALL_SNAPSHOTS))
flags |= BTREE_ITER_FILTER_SNAPSHOTS;
#endif

if (!(flags & BTREE_ITER_ALL_SNAPSHOTS))
pos.snapshot = btree_type_has_snapshots(btree_id)
? U32_MAX : 0;
if (!(flags & BTREE_ITER_ALL_SNAPSHOTS) &&
btree_type_has_snapshots(btree_id))
flags |= BTREE_ITER_FILTER_SNAPSHOTS;

iter->trans = trans;
iter->path = NULL;
Expand Down

0 comments on commit a861c72

Please sign in to comment.