On 07/13/2017 09:18 PM, David Sterba wrote:
Currently, the BTRFS_INODE_NOCOMPRESS will prevent any compression on a
given file, except when the mount is force-compress. As users have
reported on IRC, this will also prevent compression when requested by
defrag (btrfs fi defrag -c file).

The nocompress flag is set automatically by filesystem when the ratios
are bad and the user would have to manually drop the bit in order to
make defrag -c work. This is not good from the usability perspective.

This patch will raise priority for the defrag -c over nocompress, ie.
any file with NOCOMPRESS bit set will get defragmented. The bit will
remain untouched.

Alternate option was to also drop the nocompress bit and keep the
decision logic as is, but I think this is not the right solution.


Now the compression set through property will act same as
'-o compress-force'. Before this patch is was like '-o compress'.
I am ok to fix that patch with a new patch.

Reviewed-by: Anand Jain <anand.j...@oracle.com>

Thanks, Anand

Signed-off-by: David Sterba <dste...@suse.com>
---
  fs/btrfs/inode.c | 6 ++++--
  1 file changed, 4 insertions(+), 2 deletions(-)

diff --git a/fs/btrfs/inode.c b/fs/btrfs/inode.c
index 5d3c6ac960fd..ea2f02ec0394 100644
--- a/fs/btrfs/inode.c
+++ b/fs/btrfs/inode.c
@@ -399,12 +399,14 @@ static inline int inode_need_compress(struct inode *inode)
        /* force compress */
        if (btrfs_test_opt(fs_info, FORCE_COMPRESS))
                return 1;
+       /* force compress when called from defrag */
+       if (BTRFS_I(inode)->force_compress)
+               return 1;
        /* bad compression ratios */
        if (BTRFS_I(inode)->flags & BTRFS_INODE_NOCOMPRESS)
                return 0;
        if (btrfs_test_opt(fs_info, COMPRESS) ||
-           BTRFS_I(inode)->flags & BTRFS_INODE_COMPRESS ||
-           BTRFS_I(inode)->force_compress)
+           BTRFS_I(inode)->flags & BTRFS_INODE_COMPRESS)
                return 1;
        return 0;
  }

--
To unsubscribe from this list: send the line "unsubscribe linux-btrfs" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html

Reply via email to