All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] btrfs: inode: Don't compress if NODATASUM or NODATACOW set
@ 2018-05-14  7:02 Qu Wenruo
  2018-05-14  8:10 ` Nikolay Borisov
  2018-05-14 16:52 ` David Sterba
  0 siblings, 2 replies; 18+ messages in thread
From: Qu Wenruo @ 2018-05-14  7:02 UTC (permalink / raw)
  To: linux-btrfs

As btrfs(5) specified:

	Note
	If nodatacow or nodatasum are enabled, compression is disabled.

If NODATASUM or NODATACOW set, we should not compress the extent.

And in fact, we have bug report about corrupted compressed extent
leading to memory corruption in mail list.
Although it's mostly buggy lzo implementation causing the problem, btrfs
still needs to be fixed to meet the specification.

Reported-by: James Harvey <jamespharvey20@gmail.com>
Signed-off-by: Qu Wenruo <wqu@suse.com>
---
 fs/btrfs/inode.c | 8 ++++++++
 1 file changed, 8 insertions(+)

diff --git a/fs/btrfs/inode.c b/fs/btrfs/inode.c
index d241285a0d2a..dbef3f404559 100644
--- a/fs/btrfs/inode.c
+++ b/fs/btrfs/inode.c
@@ -396,6 +396,14 @@ static inline int inode_need_compress(struct inode *inode, u64 start, u64 end)
 {
 	struct btrfs_fs_info *fs_info = btrfs_sb(inode->i_sb);
 
+	/*
+	 * Btrfs doesn't support compression without csum or CoW.
+	 * This should have the highest priority.
+	 */
+	if (BTRFS_I(inode)->flags & BTRFS_INODE_NODATACOW ||
+	    BTRFS_I(inode)->flags & BTRFS_INODE_NODATASUM)
+		return 0;
+
 	/* force compress */
 	if (btrfs_test_opt(fs_info, FORCE_COMPRESS))
 		return 1;
-- 
2.17.0


^ permalink raw reply related	[flat|nested] 18+ messages in thread

end of thread, other threads:[~2018-05-15 18:21 UTC | newest]

Thread overview: 18+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2018-05-14  7:02 [PATCH] btrfs: inode: Don't compress if NODATASUM or NODATACOW set Qu Wenruo
2018-05-14  8:10 ` Nikolay Borisov
2018-05-14  8:20   ` Roman Mamedov
2018-05-14  8:36     ` Nikolay Borisov
2018-05-14  9:31       ` james harvey
2018-05-14  9:39       ` Roman Mamedov
2018-05-14  9:46         ` Nikolay Borisov
2018-05-14 16:49           ` David Sterba
2018-05-14  9:30     ` james harvey
2018-05-14 10:35       ` Qu Wenruo
2018-05-14 22:24         ` james harvey
2018-05-15  0:15         ` james harvey
2018-05-14  8:24   ` Qu Wenruo
2018-05-14 16:52 ` David Sterba
2018-05-14 20:46   ` Timofey Titovets
2018-05-15 18:18     ` David Sterba
2018-05-14 22:29   ` james harvey
2018-05-15  1:35   ` Qu Wenruo

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.