All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] btrfs: do not allow -o compress-force to override per-inode settings
@ 2020-11-30 13:46 Josef Bacik
  2020-11-30 14:08 ` Roman Mamedov
  0 siblings, 1 reply; 10+ messages in thread
From: Josef Bacik @ 2020-11-30 13:46 UTC (permalink / raw)
  To: linux-btrfs, kernel-team

Previously, we would set BTRFS_INODE_NOCOMPRESS if compression resulted
in larger buffers, meaning that the data probably wasn't great to be
compressed.  This would sometimes make the wrong decision, and thus end
up disabling compression in cases where we still wanted it in general.
Thus the -o compress-force option.

However some time later we got chattr -c, which is a user way of
indicating that the file shouldn't be compressed.  This is at odds with
-o compress-force.  We should be honoring what the user wants, which is
to disable compression.  The rub here is our setting of NOCOMPRESS when
we can't compress the file.

But, the way the code works, if we have -o compress-force we'll never
set NOCOMPRESS ourselves, it'll only be set by the user.  I think this
is a reasonable set of behaviors, if NOCOMPRESS is set on the inode then
we assume it was done at the users behest, and honor it no matter what.

Signed-off-by: Josef Bacik <josef@toxicpanda.com>
---
 fs/btrfs/inode.c | 9 ++++-----
 1 file changed, 4 insertions(+), 5 deletions(-)

diff --git a/fs/btrfs/inode.c b/fs/btrfs/inode.c
index 0ce42d52d53e..6609b5679d27 100644
--- a/fs/btrfs/inode.c
+++ b/fs/btrfs/inode.c
@@ -479,15 +479,15 @@ static inline int inode_need_compress(struct btrfs_inode *inode, u64 start,
 			btrfs_ino(inode));
 		return 0;
 	}
+	/* bad compression ratios, or we were set with chattr -c. */
+	if (inode->flags & BTRFS_INODE_NOCOMPRESS)
+		return 0;
 	/* force compress */
 	if (btrfs_test_opt(fs_info, FORCE_COMPRESS))
 		return 1;
 	/* defrag ioctl */
 	if (inode->defrag_compress)
 		return 1;
-	/* bad compression ratios */
-	if (inode->flags & BTRFS_INODE_NOCOMPRESS)
-		return 0;
 	if (btrfs_test_opt(fs_info, COMPRESS) ||
 	    inode->flags & BTRFS_INODE_COMPRESS ||
 	    inode->prop_compress)
@@ -1304,8 +1304,7 @@ static int cow_file_range_async(struct btrfs_inode *inode,
 
 	unlock_extent(&inode->io_tree, start, end);
 
-	if (inode->flags & BTRFS_INODE_NOCOMPRESS &&
-	    !btrfs_test_opt(fs_info, FORCE_COMPRESS)) {
+	if (inode->flags & BTRFS_INODE_NOCOMPRESS) {
 		num_chunks = 1;
 		should_compress = false;
 	} else {
-- 
2.26.2


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

end of thread, other threads:[~2020-11-30 17:30 UTC | newest]

Thread overview: 10+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-11-30 13:46 [PATCH] btrfs: do not allow -o compress-force to override per-inode settings Josef Bacik
2020-11-30 14:08 ` Roman Mamedov
2020-11-30 14:27   ` Amy Parker
2020-11-30 14:50   ` Josef Bacik
2020-11-30 15:01     ` Roman Mamedov
2020-11-30 15:10       ` Josef Bacik
2020-11-30 15:17         ` Roman Mamedov
2020-11-30 15:04     ` Hugo Mills
2020-11-30 15:12       ` Josef Bacik
2020-11-30 17:28       ` sys

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.