提交 2f3f78e9 编写于 作者: A Andrew Price 提交者: Zheng Zengkai

gfs2: Make sure FITRIM minlen is rounded up to fs block size

stable inclusion
from stable-v5.10.110
commit c73af4bc8a9183dbdaba631df9cf42ea06e00f61
bugzilla: https://gitee.com/openeuler/kernel/issues/I574AL

Reference: https://git.kernel.org/pub/scm/linux/kernel/git/stable/linux.git/commit/?id=c73af4bc8a9183dbdaba631df9cf42ea06e00f61

--------------------------------

commit 27ca8273 upstream.

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: 076f0faa ("GFS2: Fix FITRIM argument handling")
Signed-off-by: NAndrew Price <anprice@redhat.com>
Signed-off-by: NAndreas Gruenbacher <agruenba@redhat.com>
Signed-off-by: NGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Signed-off-by: NYu Liao <liaoyu15@huawei.com>
Reviewed-by: NWei Li <liwei391@huawei.com>
Signed-off-by: NZheng Zengkai <zhengzengkai@huawei.com>
上级 f8e7189c
...@@ -1389,7 +1389,8 @@ int gfs2_fitrim(struct file *filp, void __user *argp) ...@@ -1389,7 +1389,8 @@ int gfs2_fitrim(struct file *filp, void __user *argp)
start = r.start >> bs_shift; start = r.start >> bs_shift;
end = start + (r.len >> bs_shift); end = start + (r.len >> bs_shift);
minlen = max_t(u64, r.minlen, minlen = max_t(u64, r.minlen, sdp->sd_sb.sb_bsize);
minlen = max_t(u64, minlen,
q->limits.discard_granularity) >> bs_shift; q->limits.discard_granularity) >> bs_shift;
if (end <= start || minlen > sdp->sd_max_rg_data) if (end <= start || minlen > sdp->sd_max_rg_data)
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册