• Shilong Wang's avatar
    Btrfs: fix incorrect compression ratio detection · 4bcbb332
    Shilong Wang authored
    Steps to reproduce:
     # mkfs.btrfs -f /dev/sdb
     # mount -t btrfs /dev/sdb /mnt -o compress=lzo
     # dd if=/dev/zero of=/mnt/data bs=$((33*4096)) count=1
    
    after previous steps, inode will be detected as bad compression ratio,
    and NOCOMPRESS flag will be set for that inode.
    
    Reason is that compress have a max limit pages every time(128K), if a
    132k write in, it will be splitted into two write(128k+4k), this bug
    is a leftover for commit 68bb462d(Btrfs: don't compress for a small write)
    
    Fix this problem by checking every time before compression, if it is a
    small write(<=blocksize), we bail out and fall into nocompression directly.
    Signed-off-by: default avatarWang Shilong <wangshilong1991@gmail.com>
    Reviewed-by: default avatarMiao Xie <miaox@cn.fujitsu.com>
    Signed-off-by: default avatarChris Mason <clm@fb.com>
    4bcbb332
inode.c 251 KB