[PATCH v2] erofs: fix blksize < PAGE_SIZE in fileio mode

Hongzhen Luo hongzhen at linux.alibaba.com
Tue Oct 15 17:40:07 AEDT 2024


In fileio mode, when blcksize is not equal to PAGE_SIZE,
erofs will attempt to set the block size of sb->s_bdev,
which will trigger a panic. This patch fixes this.

Fixes: fb176750266a ("erofs: add file-backed mount support")

Signed-off-by: Hongzhen Luo <hongzhen at linux.alibaba.com>
---
v2: Add support for blocksize < PAGE_SIZE in file-backed mount mode.
v1: https://lore.kernel.org/linux-erofs/20241015033601.3206952-1-hongzhen@linux.alibaba.com/
---
 fs/erofs/super.c | 12 +++++++++---
 1 file changed, 9 insertions(+), 3 deletions(-)

diff --git a/fs/erofs/super.c b/fs/erofs/super.c
index 320d586c3896..abe2d85512dd 100644
--- a/fs/erofs/super.c
+++ b/fs/erofs/super.c
@@ -631,9 +631,15 @@ static int erofs_fc_fill_super(struct super_block *sb, struct fs_context *fc)
 			errorfc(fc, "unsupported blksize for fscache mode");
 			return -EINVAL;
 		}
-		if (!sb_set_blocksize(sb, 1 << sbi->blkszbits)) {
-			errorfc(fc, "failed to set erofs blksize");
-			return -EINVAL;
+
+		if (erofs_is_fileio_mode(sbi)) {
+			sb->s_blocksize = (1 << sbi->blkszbits);
+			sb->s_blocksize_bits = sbi->blkszbits;
+		} else {
+			if (!sb_set_blocksize(sb, 1 << sbi->blkszbits)) {
+				errorfc(fc, "failed to set erofs blksize");
+				return -EINVAL;
+			}
 		}
 	}
 
-- 
2.43.5



More information about the Linux-erofs mailing list