Message ID | 20230605084519.580346-2-hch@lst.de (mailing list archive) |
---|---|
State | New, archived |
Headers | show |
Series | [1/2] btrfs: factor out a btrfs_inode_is_nodatasum helper | expand |
On Mon, Jun 05, 2023 at 10:45:18AM +0200, Christoph Hellwig wrote: > Split out a helper to check if an inode needs nodatasum treatment. > > Signed-off-by: Christoph Hellwig <hch@lst.de> > --- > fs/btrfs/bio.c | 3 +-- > fs/btrfs/btrfs_inode.h | 7 +++++++ > fs/btrfs/file-item.c | 3 +-- > 3 files changed, 9 insertions(+), 4 deletions(-) > > diff --git a/fs/btrfs/bio.c b/fs/btrfs/bio.c > index c9b4aa339b4b07..627d06fbb4c425 100644 > --- a/fs/btrfs/bio.c > +++ b/fs/btrfs/bio.c > @@ -659,8 +659,7 @@ static bool btrfs_submit_chunk(struct btrfs_bio *bbio, int mirror_num) > * Csum items for reloc roots have already been cloned at this > * point, so they are handled as part of the no-checksum case. > */ > - if (inode && !(inode->flags & BTRFS_INODE_NODATASUM) && > - !test_bit(BTRFS_FS_STATE_NO_CSUMS, &fs_info->fs_state) && > + if (inode && !btrfs_inode_is_nodatasum(inode) && > !btrfs_is_data_reloc_root(inode->root)) { > if (should_async_write(bbio) && > btrfs_wq_submit_bio(bbio, bioc, &smap, mirror_num)) > diff --git a/fs/btrfs/btrfs_inode.h b/fs/btrfs/btrfs_inode.h > index 8abf96cfea8fae..713439d62adda3 100644 > --- a/fs/btrfs/btrfs_inode.h > +++ b/fs/btrfs/btrfs_inode.h > @@ -535,4 +535,11 @@ void btrfs_update_inode_bytes(struct btrfs_inode *inode, const u64 add_bytes, > const u64 del_bytes); > void btrfs_assert_inode_range_clean(struct btrfs_inode *inode, u64 start, u64 end); > > +static inline bool btrfs_inode_is_nodatasum(struct btrfs_inode *inode) > +{ > + return (inode->flags & BTRFS_INODE_NODATASUM) || > + test_bit(BTRFS_FS_STATE_NO_CSUMS, > + &inode->root->fs_info->fs_state); This mixes inode and filesystem but the function only talks about an inode. Also BTRFS_FS_STATE_NO_CSUMS is an exceptional state, more like a rescue state to allow accessing filesytem with broken checksums and it is supposed to stand out in the conditions, not be hidden in a helper.
diff --git a/fs/btrfs/bio.c b/fs/btrfs/bio.c index c9b4aa339b4b07..627d06fbb4c425 100644 --- a/fs/btrfs/bio.c +++ b/fs/btrfs/bio.c @@ -659,8 +659,7 @@ static bool btrfs_submit_chunk(struct btrfs_bio *bbio, int mirror_num) * Csum items for reloc roots have already been cloned at this * point, so they are handled as part of the no-checksum case. */ - if (inode && !(inode->flags & BTRFS_INODE_NODATASUM) && - !test_bit(BTRFS_FS_STATE_NO_CSUMS, &fs_info->fs_state) && + if (inode && !btrfs_inode_is_nodatasum(inode) && !btrfs_is_data_reloc_root(inode->root)) { if (should_async_write(bbio) && btrfs_wq_submit_bio(bbio, bioc, &smap, mirror_num)) diff --git a/fs/btrfs/btrfs_inode.h b/fs/btrfs/btrfs_inode.h index 8abf96cfea8fae..713439d62adda3 100644 --- a/fs/btrfs/btrfs_inode.h +++ b/fs/btrfs/btrfs_inode.h @@ -535,4 +535,11 @@ void btrfs_update_inode_bytes(struct btrfs_inode *inode, const u64 add_bytes, const u64 del_bytes); void btrfs_assert_inode_range_clean(struct btrfs_inode *inode, u64 start, u64 end); +static inline bool btrfs_inode_is_nodatasum(struct btrfs_inode *inode) +{ + return (inode->flags & BTRFS_INODE_NODATASUM) || + test_bit(BTRFS_FS_STATE_NO_CSUMS, + &inode->root->fs_info->fs_state); +} + #endif diff --git a/fs/btrfs/file-item.c b/fs/btrfs/file-item.c index 2e7d5ec6c9a68c..5e6603e76e5ac0 100644 --- a/fs/btrfs/file-item.c +++ b/fs/btrfs/file-item.c @@ -355,8 +355,7 @@ blk_status_t btrfs_lookup_bio_sums(struct btrfs_bio *bbio) blk_status_t ret = BLK_STS_OK; u32 bio_offset = 0; - if ((inode->flags & BTRFS_INODE_NODATASUM) || - test_bit(BTRFS_FS_STATE_NO_CSUMS, &fs_info->fs_state)) + if (btrfs_inode_is_nodatasum(inode)) return BLK_STS_OK; /*
Split out a helper to check if an inode needs nodatasum treatment. Signed-off-by: Christoph Hellwig <hch@lst.de> --- fs/btrfs/bio.c | 3 +-- fs/btrfs/btrfs_inode.h | 7 +++++++ fs/btrfs/file-item.c | 3 +-- 3 files changed, 9 insertions(+), 4 deletions(-)