Skip to content

Commit 056c831

Browse files
josefbacikkdave
authored andcommitted
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: Josef Bacik <[email protected]> Reviewed-by: David Sterba <[email protected]> Signed-off-by: David Sterba <[email protected]>
1 parent 84d2d6c commit 056c831

File tree

5 files changed

+13
-4
lines changed

5 files changed

+13
-4
lines changed

fs/btrfs/compression.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -157,7 +157,8 @@ static int check_compressed_csum(struct btrfs_inode *inode, struct bio *bio,
157157
struct compressed_bio *cb = bio->bi_private;
158158
u8 *cb_sum = cb->sums;
159159

160-
if (!fs_info->csum_root || (inode->flags & BTRFS_INODE_NODATASUM))
160+
if ((inode->flags & BTRFS_INODE_NODATASUM) ||
161+
test_bit(BTRFS_FS_STATE_NO_CSUMS, &fs_info->fs_state))
161162
return 0;
162163

163164
shash->tfm = fs_info->csum_shash;

fs/btrfs/ctree.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -143,6 +143,8 @@ enum {
143143
BTRFS_FS_STATE_DEV_REPLACING,
144144
/* The btrfs_fs_info created for self-tests */
145145
BTRFS_FS_STATE_DUMMY_FS_INFO,
146+
147+
BTRFS_FS_STATE_NO_CSUMS,
146148
};
147149

148150
#define BTRFS_BACKREF_REV_MAX 256

fs/btrfs/disk-io.c

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2482,11 +2482,16 @@ static int btrfs_read_roots(struct btrfs_fs_info *fs_info)
24822482
if (!btrfs_test_opt(fs_info, IGNOREBADROOTS)) {
24832483
ret = PTR_ERR(root);
24842484
goto out;
2485+
} else {
2486+
set_bit(BTRFS_FS_STATE_NO_CSUMS,
2487+
&fs_info->fs_state);
24852488
}
24862489
} else {
24872490
set_bit(BTRFS_ROOT_TRACK_DIRTY, &root->state);
24882491
fs_info->csum_root = root;
24892492
}
2493+
} else {
2494+
set_bit(BTRFS_FS_STATE_NO_CSUMS, &fs_info->fs_state);
24902495
}
24912496

24922497
/*

fs/btrfs/file-item.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -376,7 +376,8 @@ blk_status_t btrfs_lookup_bio_sums(struct inode *inode, struct bio *bio, u8 *dst
376376
const unsigned int nblocks = orig_len >> fs_info->sectorsize_bits;
377377
int count = 0;
378378

379-
if (!fs_info->csum_root || (BTRFS_I(inode)->flags & BTRFS_INODE_NODATASUM))
379+
if ((BTRFS_I(inode)->flags & BTRFS_INODE_NODATASUM) ||
380+
test_bit(BTRFS_FS_STATE_NO_CSUMS, &fs_info->fs_state))
380381
return BLK_STS_OK;
381382

382383
/*

fs/btrfs/inode.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2516,7 +2516,7 @@ blk_status_t btrfs_submit_data_bio(struct inode *inode, struct bio *bio,
25162516
int async = !atomic_read(&BTRFS_I(inode)->sync_writers);
25172517

25182518
skip_sum = (BTRFS_I(inode)->flags & BTRFS_INODE_NODATASUM) ||
2519-
!fs_info->csum_root;
2519+
test_bit(BTRFS_FS_STATE_NO_CSUMS, &fs_info->fs_state);
25202520

25212521
if (btrfs_is_free_space_inode(BTRFS_I(inode)))
25222522
metadata = BTRFS_WQ_ENDIO_FREE_SPACE;
@@ -3314,7 +3314,7 @@ unsigned int btrfs_verify_data_csum(struct btrfs_bio *bbio,
33143314
if (BTRFS_I(inode)->flags & BTRFS_INODE_NODATASUM)
33153315
return 0;
33163316

3317-
if (!root->fs_info->csum_root)
3317+
if (unlikely(test_bit(BTRFS_FS_STATE_NO_CSUMS, &fs_info->fs_state)))
33183318
return 0;
33193319

33203320
ASSERT(page_offset(page) <= start &&

0 commit comments

Comments
 (0)