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

ext4: enable FITRIM ioctl on bigalloc file system

With a minor tweaks regarding minimum extent size to discard and
discarded bytes reporting the FITRIM can be enabled on bigalloc file
system and it works without any problem.

This patch fixes minlen handling and discarded bytes reporting to
take into consideration bigalloc enabled file systems and finally
removes the restriction and allow FITRIM to be used on file system with
bigalloc feature enabled.

Reviewed-by: Carlos Maiolino <cmaiolino@redhat.com>
Signed-off-by: Lukas Czerner <lczerner@redhat.com>
Signed-off-by: "Theodore Ts'o" <tytso@mit.edu>

authored by

Lukas Czerner and committed by
Theodore Ts'o
aaf7d73e b71fc079

+3 -9
-7
fs/ext4/ioctl.c
··· 404 404 if (!blk_queue_discard(q)) 405 405 return -EOPNOTSUPP; 406 406 407 - if (EXT4_HAS_RO_COMPAT_FEATURE(sb, 408 - EXT4_FEATURE_RO_COMPAT_BIGALLOC)) { 409 - ext4_msg(sb, KERN_ERR, 410 - "FITRIM not supported with bigalloc"); 411 - return -EOPNOTSUPP; 412 - } 413 - 414 407 if (copy_from_user(&range, (struct fstrim_range __user *)arg, 415 408 sizeof(range))) 416 409 return -EFAULT;
+3 -2
fs/ext4/mballoc.c
··· 4990 4990 4991 4991 start = range->start >> sb->s_blocksize_bits; 4992 4992 end = start + (range->len >> sb->s_blocksize_bits) - 1; 4993 - minlen = range->minlen >> sb->s_blocksize_bits; 4993 + minlen = EXT4_NUM_B2C(EXT4_SB(sb), 4994 + range->minlen >> sb->s_blocksize_bits); 4994 4995 4995 4996 if (unlikely(minlen > EXT4_CLUSTERS_PER_GROUP(sb)) || 4996 4997 unlikely(start >= max_blks)) ··· 5051 5050 atomic_set(&EXT4_SB(sb)->s_last_trim_minblks, minlen); 5052 5051 5053 5052 out: 5054 - range->len = trimmed * sb->s_blocksize; 5053 + range->len = EXT4_C2B(EXT4_SB(sb), trimmed) << sb->s_blocksize_bits; 5055 5054 return ret; 5056 5055 }