Commit 056c8311 authored by Josef Bacik's avatar Josef Bacik Committed by David Sterba

btrfs: set BTRFS_FS_STATE_NO_CSUMS if we fail to load the csum root

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: default avatarJosef Bacik <josef@toxicpanda.com>
Reviewed-by: default avatarDavid Sterba <dsterba@suse.com>
Signed-off-by: default avatarDavid Sterba <dsterba@suse.com>
parent 84d2d6c7
...@@ -157,7 +157,8 @@ static int check_compressed_csum(struct btrfs_inode *inode, struct bio *bio, ...@@ -157,7 +157,8 @@ static int check_compressed_csum(struct btrfs_inode *inode, struct bio *bio,
struct compressed_bio *cb = bio->bi_private; struct compressed_bio *cb = bio->bi_private;
u8 *cb_sum = cb->sums; 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; return 0;
shash->tfm = fs_info->csum_shash; shash->tfm = fs_info->csum_shash;
......
...@@ -143,6 +143,8 @@ enum { ...@@ -143,6 +143,8 @@ enum {
BTRFS_FS_STATE_DEV_REPLACING, BTRFS_FS_STATE_DEV_REPLACING,
/* The btrfs_fs_info created for self-tests */ /* The btrfs_fs_info created for self-tests */
BTRFS_FS_STATE_DUMMY_FS_INFO, BTRFS_FS_STATE_DUMMY_FS_INFO,
BTRFS_FS_STATE_NO_CSUMS,
}; };
#define BTRFS_BACKREF_REV_MAX 256 #define BTRFS_BACKREF_REV_MAX 256
......
...@@ -2482,11 +2482,16 @@ static int btrfs_read_roots(struct btrfs_fs_info *fs_info) ...@@ -2482,11 +2482,16 @@ static int btrfs_read_roots(struct btrfs_fs_info *fs_info)
if (!btrfs_test_opt(fs_info, IGNOREBADROOTS)) { if (!btrfs_test_opt(fs_info, IGNOREBADROOTS)) {
ret = PTR_ERR(root); ret = PTR_ERR(root);
goto out; goto out;
} else {
set_bit(BTRFS_FS_STATE_NO_CSUMS,
&fs_info->fs_state);
} }
} else { } else {
set_bit(BTRFS_ROOT_TRACK_DIRTY, &root->state); set_bit(BTRFS_ROOT_TRACK_DIRTY, &root->state);
fs_info->csum_root = root; fs_info->csum_root = root;
} }
} else {
set_bit(BTRFS_FS_STATE_NO_CSUMS, &fs_info->fs_state);
} }
/* /*
......
...@@ -376,7 +376,8 @@ blk_status_t btrfs_lookup_bio_sums(struct inode *inode, struct bio *bio, u8 *dst ...@@ -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; const unsigned int nblocks = orig_len >> fs_info->sectorsize_bits;
int count = 0; 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; return BLK_STS_OK;
/* /*
......
...@@ -2516,7 +2516,7 @@ blk_status_t btrfs_submit_data_bio(struct inode *inode, struct bio *bio, ...@@ -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); int async = !atomic_read(&BTRFS_I(inode)->sync_writers);
skip_sum = (BTRFS_I(inode)->flags & BTRFS_INODE_NODATASUM) || 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))) if (btrfs_is_free_space_inode(BTRFS_I(inode)))
metadata = BTRFS_WQ_ENDIO_FREE_SPACE; metadata = BTRFS_WQ_ENDIO_FREE_SPACE;
...@@ -3314,7 +3314,7 @@ unsigned int btrfs_verify_data_csum(struct btrfs_bio *bbio, ...@@ -3314,7 +3314,7 @@ unsigned int btrfs_verify_data_csum(struct btrfs_bio *bbio,
if (BTRFS_I(inode)->flags & BTRFS_INODE_NODATASUM) if (BTRFS_I(inode)->flags & BTRFS_INODE_NODATASUM)
return 0; return 0;
if (!root->fs_info->csum_root) if (unlikely(test_bit(BTRFS_FS_STATE_NO_CSUMS, &fs_info->fs_state)))
return 0; return 0;
ASSERT(page_offset(page) <= start && ASSERT(page_offset(page) <= start &&
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment