Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

Btrfs: check the nodatasum flag when writing compressed files

If mounting with nodatasum option, we won't csum file data for
general write or direct-io write, and this rule should also be
applied when writing compressed files.

Signed-off-by: Li Zefan <lizf@cn.fujitsu.com>
Signed-off-by: Chris Mason <chris.mason@oracle.com>

authored by

Li Zefan and committed by
Chris Mason
e55179b3 77906a50

+10 -4
+10 -4
fs/btrfs/compression.c
··· 338 338 u64 first_byte = disk_start; 339 339 struct block_device *bdev; 340 340 int ret; 341 + int skip_sum = BTRFS_I(inode)->flags & BTRFS_INODE_NODATASUM; 341 342 342 343 WARN_ON(start & ((u64)PAGE_CACHE_SIZE - 1)); 343 344 cb = kmalloc(compressed_bio_size(root, compressed_len), GFP_NOFS); ··· 393 392 ret = btrfs_bio_wq_end_io(root->fs_info, bio, 0); 394 393 BUG_ON(ret); 395 394 396 - ret = btrfs_csum_one_bio(root, inode, bio, start, 1); 397 - BUG_ON(ret); 395 + if (!skip_sum) { 396 + ret = btrfs_csum_one_bio(root, inode, bio, 397 + start, 1); 398 + BUG_ON(ret); 399 + } 398 400 399 401 ret = btrfs_map_bio(root, WRITE, bio, 0, 1); 400 402 BUG_ON(ret); ··· 422 418 ret = btrfs_bio_wq_end_io(root->fs_info, bio, 0); 423 419 BUG_ON(ret); 424 420 425 - ret = btrfs_csum_one_bio(root, inode, bio, start, 1); 426 - BUG_ON(ret); 421 + if (!skip_sum) { 422 + ret = btrfs_csum_one_bio(root, inode, bio, start, 1); 423 + BUG_ON(ret); 424 + } 427 425 428 426 ret = btrfs_map_bio(root, WRITE, bio, 0, 1); 429 427 BUG_ON(ret);