bcachefs: Put bkey invalid check in commit path in a more useful place
authorKent Overstreet <kent.overstreet@linux.dev>
Wed, 23 Aug 2023 00:29:35 +0000 (20:29 -0400)
committerKent Overstreet <kent.overstreet@linux.dev>
Sun, 22 Oct 2023 21:10:11 +0000 (17:10 -0400)
When doing updates early in recovery, before we can go RW, we still want
to check that keys are valid at commit time - this moves key invalid
checking to before the "btree updates to journal" path.

Signed-off-by: Kent Overstreet <kent.overstreet@linux.dev>
fs/bcachefs/btree_trans_commit.c

index f498513..eafb038 100644 (file)
@@ -817,25 +817,6 @@ static inline int do_bch2_trans_commit(struct btree_trans *trans, unsigned flags
        struct btree_insert_entry *i;
        int ret = 0, u64s_delta = 0;
 
-#ifdef CONFIG_BCACHEFS_DEBUG
-       trans_for_each_update(trans, i) {
-               struct printbuf buf = PRINTBUF;
-               enum bkey_invalid_flags invalid_flags = 0;
-
-               if (!(flags & BTREE_INSERT_JOURNAL_REPLAY))
-                       invalid_flags |= BKEY_INVALID_WRITE|BKEY_INVALID_COMMIT;
-
-               if (unlikely(bch2_bkey_invalid(c, bkey_i_to_s_c(i->k),
-                                              i->bkey_type, invalid_flags, &buf)))
-                       ret = bch2_trans_commit_bkey_invalid(trans, flags, i, &buf);
-               btree_insert_entry_checks(trans, i);
-               printbuf_exit(&buf);
-
-               if (ret)
-                       return ret;
-       }
-#endif
-
        trans_for_each_update(trans, i) {
                if (i->cached)
                        continue;
@@ -1048,6 +1029,25 @@ int __bch2_trans_commit(struct btree_trans *trans, unsigned flags)
        if (ret)
                goto out_reset;
 
+#ifdef CONFIG_BCACHEFS_DEBUG
+       trans_for_each_update(trans, i) {
+               struct printbuf buf = PRINTBUF;
+               enum bkey_invalid_flags invalid_flags = 0;
+
+               if (!(flags & BTREE_INSERT_JOURNAL_REPLAY))
+                       invalid_flags |= BKEY_INVALID_WRITE|BKEY_INVALID_COMMIT;
+
+               if (unlikely(bch2_bkey_invalid(c, bkey_i_to_s_c(i->k),
+                                              i->bkey_type, invalid_flags, &buf)))
+                       ret = bch2_trans_commit_bkey_invalid(trans, flags, i, &buf);
+               btree_insert_entry_checks(trans, i);
+               printbuf_exit(&buf);
+
+               if (ret)
+                       return ret;
+       }
+#endif
+
        if (unlikely(!test_bit(BCH_FS_MAY_GO_RW, &c->flags))) {
                ret = do_bch2_trans_commit_to_journal_replay(trans);
                goto out_reset;