bcachefs: Require snapshot id to be set
authorKent Overstreet <kent.overstreet@gmail.com>
Tue, 16 Mar 2021 02:34:00 +0000 (22:34 -0400)
committerKent Overstreet <kent.overstreet@linux.dev>
Sun, 22 Oct 2023 21:09:13 +0000 (17:09 -0400)
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>
fs/bcachefs/bkey_methods.c
fs/bcachefs/btree_iter.c

index 3133db236b7b7a72129e7d0a476a00a8376d9da6..f7f4139072b5a3cbdabcf43dff85ea2f676de5af 100644 (file)
@@ -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 &&
index b589b96bc9e7ab52b84a3628284f14c4a65854dd..df542a59fe1225dcdfb1c91ee51b6479baeb7cc2 100644 (file)
@@ -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);
 
@@ -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;