linux-block.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] block: loop: set discard_granularity as PAGE_SIZE if sb->s_blocksize is 0
@ 2022-01-24 10:06 Ming Lei
  2022-01-24 13:36 ` Vivek Goyal
  2022-01-24 14:05 ` Christoph Hellwig
  0 siblings, 2 replies; 4+ messages in thread
From: Ming Lei @ 2022-01-24 10:06 UTC (permalink / raw)
  To: Jens Axboe; +Cc: linux-block, Ming Lei, Vivek Goyal, Pei Zhang

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.

Fix the issue by setting discard_granularity as PAGE_SIZE in this case
since PAGE_SIZE is the most common data unit for FS.

Cc: Vivek Goyal <vgoyal@redhat.com>
Reported-by: Pei Zhang <pezhang@redhat.com>
Signed-off-by: Ming Lei <ming.lei@redhat.com>
---
 drivers/block/loop.c | 4 ++++
 1 file changed, 4 insertions(+)

diff --git a/drivers/block/loop.c b/drivers/block/loop.c
index b1b05c45c07c..8c15bfab7e1a 100644
--- a/drivers/block/loop.c
+++ b/drivers/block/loop.c
@@ -776,6 +776,10 @@ static void loop_config_discard(struct loop_device *lo)
 	} else {
 		max_discard_sectors = UINT_MAX >> 9;
 		granularity = inode->i_sb->s_blocksize;
+
+		/* Take PAGE_SIZE if the FS doesn't provide us one hint */
+		if (!granularity)
+			granularity = PAGE_SIZE;
 	}
 
 	if (max_discard_sectors) {
-- 
2.31.1


^ permalink raw reply related	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2022-01-24 15:22 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2022-01-24 10:06 [PATCH] block: loop: set discard_granularity as PAGE_SIZE if sb->s_blocksize is 0 Ming Lei
2022-01-24 13:36 ` Vivek Goyal
2022-01-24 14:05 ` Christoph Hellwig
2022-01-24 15:22   ` Vivek Goyal

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).