bcachefs: Improve btree_key_cache_flush_pos()
authorKent Overstreet <kent.overstreet@gmail.com>
Wed, 12 Jan 2022 05:49:23 +0000 (00:49 -0500)
committerKent Overstreet <kent.overstreet@linux.dev>
Sun, 22 Oct 2023 21:09:23 +0000 (17:09 -0400)
btree_key_cache_flush_pos() uses BTREE_ITER_CACHED_NOFILL - but it
wasn't checking for !ck->valid. It does check for the entry being dirty,
so it shouldn't matter, but this refactor it a bit and adds and
assertion.

Signed-off-by: Kent Overstreet <kent.overstreet@gmail.com>
fs/bcachefs/btree_key_cache.c

index 684919125b2f0895ff4a91ef800ff0fa7c18344d..ba50cad14757192ce0a611d3d408b2caa4a8d694 100644 (file)
@@ -390,16 +390,20 @@ static int btree_key_cache_flush_pos(struct btree_trans *trans,
                goto out;
 
        ck = (void *) c_iter.path->l[0].b;
-       if (!ck ||
-           (journal_seq && ck->journal.seq != journal_seq))
+       if (!ck)
                goto out;
 
        if (!test_bit(BKEY_CACHED_DIRTY, &ck->flags)) {
-               if (!evict)
-                       goto out;
-               goto evict;
+               if (evict)
+                       goto evict;
+               goto out;
        }
 
+       BUG_ON(!ck->valid);
+
+       if (journal_seq && ck->journal.seq != journal_seq)
+               goto out;
+
        /*
         * Since journal reclaim depends on us making progress here, and the
         * allocator/copygc depend on journal reclaim making progress, we need