btrfs: set BTRFS_FS_STATE_NO_CSUMS if we fail to load the csum root
authorJosef Bacik <josef@toxicpanda.com>
Fri, 5 Nov 2021 20:45:47 +0000 (16:45 -0400)
committerDavid Sterba <dsterba@suse.com>
Mon, 3 Jan 2022 14:09:49 +0000 (15:09 +0100)
We have a few places where we skip doing csums if we mounted with one of
the rescue options that ignores bad csum roots.  In the future when
there are multiple csum roots it'll be costly to check and see if there
are any missing csum roots, so simply add a flag to indicate the fs
should skip loading csums in case of errors.

Signed-off-by: Josef Bacik <josef@toxicpanda.com>
Reviewed-by: David Sterba <dsterba@suse.com>
Signed-off-by: David Sterba <dsterba@suse.com>
fs/btrfs/compression.c
fs/btrfs/ctree.h
fs/btrfs/disk-io.c
fs/btrfs/file-item.c
fs/btrfs/inode.c

index 32da97c..e776956 100644 (file)
@@ -157,7 +157,8 @@ static int check_compressed_csum(struct btrfs_inode *inode, struct bio *bio,
        struct compressed_bio *cb = bio->bi_private;
        u8 *cb_sum = cb->sums;
 
-       if (!fs_info->csum_root || (inode->flags & BTRFS_INODE_NODATASUM))
+       if ((inode->flags & BTRFS_INODE_NODATASUM) ||
+           test_bit(BTRFS_FS_STATE_NO_CSUMS, &fs_info->fs_state))
                return 0;
 
        shash->tfm = fs_info->csum_shash;
index aa4f0ad..1d4cdd1 100644 (file)
@@ -143,6 +143,8 @@ enum {
        BTRFS_FS_STATE_DEV_REPLACING,
        /* The btrfs_fs_info created for self-tests */
        BTRFS_FS_STATE_DUMMY_FS_INFO,
+
+       BTRFS_FS_STATE_NO_CSUMS,
 };
 
 #define BTRFS_BACKREF_REV_MAX          256
index 1b69f8e..19cea74 100644 (file)
@@ -2482,11 +2482,16 @@ static int btrfs_read_roots(struct btrfs_fs_info *fs_info)
                        if (!btrfs_test_opt(fs_info, IGNOREBADROOTS)) {
                                ret = PTR_ERR(root);
                                goto out;
+                       } else {
+                               set_bit(BTRFS_FS_STATE_NO_CSUMS,
+                                       &fs_info->fs_state);
                        }
                } else {
                        set_bit(BTRFS_ROOT_TRACK_DIRTY, &root->state);
                        fs_info->csum_root = root;
                }
+       } else {
+               set_bit(BTRFS_FS_STATE_NO_CSUMS, &fs_info->fs_state);
        }
 
        /*
index 3acc8b2..2517b00 100644 (file)
@@ -376,7 +376,8 @@ blk_status_t btrfs_lookup_bio_sums(struct inode *inode, struct bio *bio, u8 *dst
        const unsigned int nblocks = orig_len >> fs_info->sectorsize_bits;
        int count = 0;
 
-       if (!fs_info->csum_root || (BTRFS_I(inode)->flags & BTRFS_INODE_NODATASUM))
+       if ((BTRFS_I(inode)->flags & BTRFS_INODE_NODATASUM) ||
+           test_bit(BTRFS_FS_STATE_NO_CSUMS, &fs_info->fs_state))
                return BLK_STS_OK;
 
        /*
index 91f7ed2..2ea28f8 100644 (file)
@@ -2516,7 +2516,7 @@ blk_status_t btrfs_submit_data_bio(struct inode *inode, struct bio *bio,
        int async = !atomic_read(&BTRFS_I(inode)->sync_writers);
 
        skip_sum = (BTRFS_I(inode)->flags & BTRFS_INODE_NODATASUM) ||
-                  !fs_info->csum_root;
+               test_bit(BTRFS_FS_STATE_NO_CSUMS, &fs_info->fs_state);
 
        if (btrfs_is_free_space_inode(BTRFS_I(inode)))
                metadata = BTRFS_WQ_ENDIO_FREE_SPACE;
@@ -3314,7 +3314,7 @@ unsigned int btrfs_verify_data_csum(struct btrfs_bio *bbio,
        if (BTRFS_I(inode)->flags & BTRFS_INODE_NODATASUM)
                return 0;
 
-       if (!root->fs_info->csum_root)
+       if (unlikely(test_bit(BTRFS_FS_STATE_NO_CSUMS, &fs_info->fs_state)))
                return 0;
 
        ASSERT(page_offset(page) <= start &&