Ming Lei 1ccc12f224 block: loop:use kstatfs.f_bsize of backing file to set discard granularity
[ Upstream commit 06582bc86d7f48d35cd044098ca1e246e8c7c52e ]

If backing file's filesystem has implemented ->fallocate(), we think the
loop device can support discard, then pass sb->s_blocksize as
discard_granularity. However, some underlying FS, such as overlayfs,
doesn't set sb->s_blocksize, and causes discard_granularity to be set as
zero, then the warning in __blkdev_issue_discard() is triggered.

Christoph suggested to pass kstatfs.f_bsize as discard granularity, and
this way is fine because kstatfs.f_bsize means 'Optimal transfer block
size', which still matches with definition of discard granularity.

So fix the issue by setting discard_granularity as kstatfs.f_bsize if it
is available, otherwise claims discard isn't supported.

Cc: Christoph Hellwig <hch@lst.de>
Cc: Vivek Goyal <vgoyal@redhat.com>
Reported-by: Pei Zhang <pezhang@redhat.com>
Signed-off-by: Ming Lei <ming.lei@redhat.com>
Reviewed-by: Christoph Hellwig <hch@lst.de>
Link: https://lore.kernel.org/r/20220126035830.296465-1-ming.lei@redhat.com
Signed-off-by: Jens Axboe <axboe@kernel.dk>
Signed-off-by: Sasha Levin <sashal@kernel.org>
2022-03-08 19:12:30 +01:00
..
2021-06-30 12:21:16 -07:00
2021-09-02 15:09:46 -07:00
2021-06-30 12:21:16 -07:00
2021-10-17 06:51:19 -06:00
2021-09-02 15:09:46 -07:00
2021-09-03 22:14:40 -06:00
2021-03-24 06:57:40 -06:00
2021-08-02 13:37:27 -06:00
2021-08-16 10:50:33 -06:00
2021-06-11 11:53:02 -06:00
2021-06-11 11:53:03 -06:00
2021-06-30 12:21:16 -07:00