[PATCH] block: loop: set discard_granularity as PAGE_SIZE if sb->s_blocksize is 0

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



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@xxxxxxxxxx>
Reported-by: Pei Zhang <pezhang@xxxxxxxxxx>
Signed-off-by: Ming Lei <ming.lei@xxxxxxxxxx>
---
 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




[Index of Archives]     [Linux RAID]     [Linux SCSI]     [Linux ATA RAID]     [IDE]     [Linux Wireless]     [Linux Kernel]     [ATH6KL]     [Linux Bluetooth]     [Linux Netdev]     [Kernel Newbies]     [Security]     [Git]     [Netfilter]     [Bugtraq]     [Yosemite News]     [MIPS Linux]     [ARM Linux]     [Linux Security]     [Device Mapper]

  Powered by Linux