]> git.baikalelectronics.ru Git - kernel.git/commit
block: loop:use kstatfs.f_bsize of backing file to set discard granularity
authorMing Lei <ming.lei@redhat.com>
Wed, 26 Jan 2022 03:58:30 +0000 (11:58 +0800)
committerJens Axboe <axboe@kernel.dk>
Fri, 11 Feb 2022 22:10:49 +0000 (15:10 -0700)
commitb8660b9fad782e45bafa3f4c5aa01805cf0cde0a
treed6038c855d863a83b254063fd3f6bea8887a1bad
parent61c7c0d1b37fbe9d9d0787c762eed5bfd5fdc9be
block: loop:use kstatfs.f_bsize of backing file to set discard granularity

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>
drivers/block/loop.c