Skip to content

Commit 1bd96c9

Browse files
fdmananakdave
authored andcommitted
btrfs: reject encoded write if inode has nodatasum flag set
Currently we allow an encoded write against inodes that have the NODATASUM flag set, either because they are NOCOW files or they were created while the filesystem was mounted with "-o nodatasum". This results in having compressed extents without corresponding checksums, which is a filesystem inconsistency reported by 'btrfs check'. For example, running btrfs/281 with MOUNT_OPTIONS="-o nodatacow" triggers this and 'btrfs check' errors out with: [1/7] checking root items [2/7] checking extents [3/7] checking free space tree [4/7] checking fs roots root 256 inode 257 errors 1040, bad file extent, some csum missing root 256 inode 258 errors 1040, bad file extent, some csum missing ERROR: errors found in fs roots (...) So reject encoded writes if the target inode has NODATASUM set. CC: stable@vger.kernel.org # 6.1+ Reviewed-by: Johannes Thumshirn <johannes.thumshirn@wdc.com> Signed-off-by: Filipe Manana <fdmanana@suse.com> Reviewed-by: David Sterba <dsterba@suse.com> Signed-off-by: David Sterba <dsterba@suse.com>
1 parent feefe1f commit 1bd96c9

File tree

1 file changed

+7
-0
lines changed

1 file changed

+7
-0
lines changed

fs/btrfs/inode.c

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10288,6 +10288,13 @@ ssize_t btrfs_do_encoded_write(struct kiocb *iocb, struct iov_iter *from,
1028810288
if (encoded->encryption != BTRFS_ENCODED_IO_ENCRYPTION_NONE)
1028910289
return -EINVAL;
1029010290

10291+
/*
10292+
* Compressed extents should always have checksums, so error out if we
10293+
* have a NOCOW file or inode was created while mounted with NODATASUM.
10294+
*/
10295+
if (inode->flags & BTRFS_INODE_NODATASUM)
10296+
return -EINVAL;
10297+
1029110298
orig_count = iov_iter_count(from);
1029210299

1029310300
/* The extent size must be sane. */

0 commit comments

Comments
 (0)