]> git.baikalelectronics.ru Git - kernel.git/commitdiff
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 32da97c3c19db41fc3bd0222afcd11d60cabbc06..e776956d5bc9296b238ec16f34444129c0e74871 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 aa4f0ad558d41e15541cf8bd651b95fb3fb7886a..1d4cdd1d153cc8172d190a380437232d0be56d89 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 1b69f8e52939d01681e5c809bc43dd628886b053..19cea74a848f02d02321c464d4434e900ed1a4fd 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 3acc8b2b5b8495d688f129fd50e48fe5d2283836..2517b0050b9916689839a4ef50433d8f34f94118 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 91f7ed27e421755004cfabe680b2d9df1e7afb54..2ea28f8a4a43875680cb74f8db1fe46d66675ad8 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 &&