Skip to content

Commit 27ca827

Browse files
andypriceAndreas Gruenbacher
authored andcommitted
gfs2: Make sure FITRIM minlen is rounded up to fs block size
Per fstrim(8) we must round up the minlen argument to the fs block size. The current calculation doesn't take into account devices that have a discard granularity and requested minlen less than 1 fs block, so the value can get shifted away to zero in the translation to fs blocks. The zero minlen passed to gfs2_rgrp_send_discards() then allows sb_issue_discard() to be called with nr_sects == 0 which returns -EINVAL and results in gfs2_rgrp_send_discards() returning -EIO. Make sure minlen is never < 1 fs block by taking the max of the requested minlen and the fs block size before comparing to the device's discard granularity and shifting to fs blocks. Fixes: 076f0fa ("GFS2: Fix FITRIM argument handling") Signed-off-by: Andrew Price <anprice@redhat.com> Signed-off-by: Andreas Gruenbacher <agruenba@redhat.com>
1 parent 3bde4c4 commit 27ca827

File tree

1 file changed

+2
-1
lines changed

1 file changed

+2
-1
lines changed

fs/gfs2/rgrp.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1417,7 +1417,8 @@ int gfs2_fitrim(struct file *filp, void __user *argp)
14171417

14181418
start = r.start >> bs_shift;
14191419
end = start + (r.len >> bs_shift);
1420-
minlen = max_t(u64, r.minlen,
1420+
minlen = max_t(u64, r.minlen, sdp->sd_sb.sb_bsize);
1421+
minlen = max_t(u64, minlen,
14211422
q->limits.discard_granularity) >> bs_shift;
14221423

14231424
if (end <= start || minlen > sdp->sd_max_rg_data)

0 commit comments

Comments
 (0)