From nobody Wed Sep 10 06:40:43 2025 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 08A72C6379F for ; Tue, 21 Feb 2023 09:17:34 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233657AbjBUJRd (ORCPT ); Tue, 21 Feb 2023 04:17:33 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:56290 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233861AbjBUJR0 (ORCPT ); Tue, 21 Feb 2023 04:17:26 -0500 Received: from out30-113.freemail.mail.aliyun.com (out30-113.freemail.mail.aliyun.com [115.124.30.113]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id A18108693 for ; Tue, 21 Feb 2023 01:17:24 -0800 (PST) X-Alimail-AntiSpam: AC=PASS;BC=-1|-1;BR=01201311R161e4;CH=green;DM=||false|;DS=||;FP=0|-1|-1|-1|0|-1|-1|-1;HT=ay29a033018046060;MF=jefflexu@linux.alibaba.com;NM=1;PH=DS;RN=6;SR=0;TI=SMTPD_---0VcBkPn9_1676971040; Received: from localhost(mailfrom:jefflexu@linux.alibaba.com fp:SMTPD_---0VcBkPn9_1676971040) by smtp.aliyun-inc.com; Tue, 21 Feb 2023 17:17:21 +0800 From: Jingbo Xu To: xiang@kernel.org, chao@kernel.org, linux-erofs@lists.ozlabs.org Cc: huyue2@coolpad.com, zhujia.zj@bytedance.com, linux-kernel@vger.kernel.org Subject: [PATCH 1/2] erofs: pass accurate blob size to prepare_ondemand_read() Date: Tue, 21 Feb 2023 17:17:18 +0800 Message-Id: <20230221091719.126127-2-jefflexu@linux.alibaba.com> X-Mailer: git-send-email 2.19.1.6.gb485710b In-Reply-To: <20230221091719.126127-1-jefflexu@linux.alibaba.com> References: <20230221091719.126127-1-jefflexu@linux.alibaba.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" To make fscache mode support PAGE_SIZE larger than 4KB, the blob image size may be small than the multiples of PAGE_SIZE (as erofs block size is no larger than 4KB), while the file range of the blob requested to read is multiples of PAGE_SIZE and may be larger than the blob image size. Therefore we need the accurate blob size, so that the EOF part could be distinguished and zero-filled then. Signed-off-by: Jingbo Xu --- fs/erofs/fscache.c | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/fs/erofs/fscache.c b/fs/erofs/fscache.c index 87ff35bff8d5..f7a1e147d0f4 100644 --- a/fs/erofs/fscache.c +++ b/fs/erofs/fscache.c @@ -125,7 +125,7 @@ static int erofs_fscache_read_folios_async(struct fscac= he_cookie *cookie, =20 DBG_BUGON(len > req->len - req->submitted); =20 - ret =3D fscache_begin_read_operation(cres, cookie); + ret =3D fscache_begin_wait_operation(cres, cookie, FSCACHE_WANT_READ); if (ret) return ret; =20 @@ -134,8 +134,17 @@ static int erofs_fscache_read_folios_async(struct fsca= che_cookie *cookie, size_t slen =3D len - done; unsigned long flags =3D 1 << NETFS_SREQ_ONDEMAND; =20 + if (sstart >=3D cookie->object_size) { + iov_iter_xarray(&iter, ITER_DEST, &req->mapping->i_pages, + lstart + done, slen); + iov_iter_zero(slen, &iter); + done +=3D slen; + continue; + } + + slen =3D min_t(size_t, slen, cookie->object_size - sstart); source =3D cres->ops->prepare_ondemand_read(cres, - sstart, &slen, LLONG_MAX, &flags, 0); + sstart, &slen, cookie->object_size, &flags, 0); if (WARN_ON(slen =3D=3D 0)) source =3D NETFS_INVALID_READ; if (source !=3D NETFS_READ_FROM_CACHE) { --=20 2.19.1.6.gb485710b From nobody Wed Sep 10 06:40:43 2025 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 21332C61DA3 for ; Tue, 21 Feb 2023 09:17:32 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233884AbjBUJRa (ORCPT ); Tue, 21 Feb 2023 04:17:30 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:56288 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233657AbjBUJR0 (ORCPT ); Tue, 21 Feb 2023 04:17:26 -0500 Received: from out30-112.freemail.mail.aliyun.com (out30-112.freemail.mail.aliyun.com [115.124.30.112]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 0459B13DC0 for ; Tue, 21 Feb 2023 01:17:24 -0800 (PST) X-Alimail-AntiSpam: AC=PASS;BC=-1|-1;BR=01201311R201e4;CH=green;DM=||false|;DS=||;FP=0|-1|-1|-1|0|-1|-1|-1;HT=ay29a033018045192;MF=jefflexu@linux.alibaba.com;NM=1;PH=DS;RN=6;SR=0;TI=SMTPD_---0VcBjLWD_1676971041; Received: from localhost(mailfrom:jefflexu@linux.alibaba.com fp:SMTPD_---0VcBjLWD_1676971041) by smtp.aliyun-inc.com; Tue, 21 Feb 2023 17:17:22 +0800 From: Jingbo Xu To: xiang@kernel.org, chao@kernel.org, linux-erofs@lists.ozlabs.org Cc: huyue2@coolpad.com, zhujia.zj@bytedance.com, linux-kernel@vger.kernel.org Subject: [PATCH 2/2] erofs: set blksize to on-disk blksize for fscache mode Date: Tue, 21 Feb 2023 17:17:19 +0800 Message-Id: <20230221091719.126127-3-jefflexu@linux.alibaba.com> X-Mailer: git-send-email 2.19.1.6.gb485710b In-Reply-To: <20230221091719.126127-1-jefflexu@linux.alibaba.com> References: <20230221091719.126127-1-jefflexu@linux.alibaba.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" Since fscache mode has supported PAGE_SIZE other than 4KB, remove the constraint and set to on-disk blksize. We need to initialize the fscache context for the bootstrap before setting the initial blksize as it will also update anonymous inode's i_blkbits for the bootstrap. Signed-off-by: Jingbo Xu --- fs/erofs/super.c | 38 ++++++++++++++++++++------------------ 1 file changed, 20 insertions(+), 18 deletions(-) diff --git a/fs/erofs/super.c b/fs/erofs/super.c index 89011a4ed274..130e0f6db3c7 100644 --- a/fs/erofs/super.c +++ b/fs/erofs/super.c @@ -709,6 +709,17 @@ static int erofs_fc_fill_pseudo_super(struct super_blo= ck *sb, struct fs_context return simple_fill_super(sb, EROFS_SUPER_MAGIC, &empty_descr); } =20 +static bool erofs_set_block_size(struct super_block *sb, unsigned int blks= zbits) +{ + if (!erofs_is_fscache_mode(sb)) + return sb_set_blocksize(sb, 1 << blkszbits); + + sb->s_blocksize =3D 1 << blkszbits; + sb->s_blocksize_bits =3D blkszbits; + EROFS_SB(sb)->s_fscache->inode->i_blkbits =3D blkszbits; + return true; +} + static int erofs_fc_fill_super(struct super_block *sb, struct fs_context *= fc) { struct inode *inode; @@ -734,11 +745,7 @@ static int erofs_fc_fill_super(struct super_block *sb,= struct fs_context *fc) sbi->domain_id =3D ctx->domain_id; ctx->domain_id =3D NULL; =20 - sbi->blkszbits =3D PAGE_SHIFT; if (erofs_is_fscache_mode(sb)) { - sb->s_blocksize =3D PAGE_SIZE; - sb->s_blocksize_bits =3D PAGE_SHIFT; - err =3D erofs_fscache_register_fs(sb); if (err) return err; @@ -747,29 +754,24 @@ static int erofs_fc_fill_super(struct super_block *sb= , struct fs_context *fc) if (err) return err; } else { - if (!sb_set_blocksize(sb, PAGE_SIZE)) { - errorfc(fc, "failed to set initial blksize"); - return -EINVAL; - } - sbi->dax_dev =3D fs_dax_get_by_bdev(sb->s_bdev, &sbi->dax_part_off, NULL, NULL); } =20 + if (!erofs_set_block_size(sb, PAGE_SHIFT)) { + errorfc(fc, "failed to set initial blksize"); + return -EINVAL; + } + err =3D erofs_read_superblock(sb); if (err) return err; =20 - if (sb->s_blocksize_bits !=3D sbi->blkszbits) { - if (erofs_is_fscache_mode(sb)) { - 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 (sb->s_blocksize_bits !=3D sbi->blkszbits && + !erofs_set_block_size(sb, sbi->blkszbits)) { + errorfc(fc, "failed to set erofs blksize"); + return -EINVAL; } =20 if (test_opt(&sbi->opt, DAX_ALWAYS)) { --=20 2.19.1.6.gb485710b