From nobody Sun Feb 8 09:30:44 2026 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 40401C77B7A for ; Thu, 1 Jun 2023 02:44:02 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231226AbjFACoB (ORCPT ); Wed, 31 May 2023 22:44:01 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:33130 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231172AbjFACnz (ORCPT ); Wed, 31 May 2023 22:43:55 -0400 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 BAC1F8E for ; Wed, 31 May 2023 19:43:53 -0700 (PDT) X-Alimail-AntiSpam: AC=PASS;BC=-1|-1;BR=01201311R621e4;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=5;SR=0;TI=SMTPD_---0Vk-3FxL_1685587430; Received: from localhost(mailfrom:jefflexu@linux.alibaba.com fp:SMTPD_---0Vk-3FxL_1685587430) by smtp.aliyun-inc.com; Thu, 01 Jun 2023 10:43:50 +0800 From: Jingbo Xu To: xiang@kernel.org, chao@kernel.org, huyue2@coolpad.com, linux-erofs@lists.ozlabs.org Cc: linux-kernel@vger.kernel.org Subject: [PATCH v5 2/6] erofs: enhance erofs_xattr_iter_fixup() helper Date: Thu, 1 Jun 2023 10:43:43 +0800 Message-Id: <20230601024347.108469-3-jefflexu@linux.alibaba.com> X-Mailer: git-send-email 2.19.1.6.gb485710b In-Reply-To: <20230601024347.108469-1-jefflexu@linux.alibaba.com> References: <20230601024347.108469-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" Enhance erofs_xattr_iter_fixup() helper so that it could be reused in the situation where it.ofs could not span the block boundary. Signed-off-by: Jingbo Xu Reviewed-by: Gao Xiang --- fs/erofs/xattr.c | 73 ++++++++++++++++++++---------------------------- 1 file changed, 31 insertions(+), 42 deletions(-) diff --git a/fs/erofs/xattr.c b/fs/erofs/xattr.c index d9e041d27a35..0fd574e94c8b 100644 --- a/fs/erofs/xattr.c +++ b/fs/erofs/xattr.c @@ -29,6 +29,24 @@ struct xattr_iter { unsigned int ofs; }; =20 +static inline int erofs_xattr_iter_fixup(struct xattr_iter *it, bool nospa= n) +{ + if (it->ofs < it->sb->s_blocksize) + return 0; + + if (nospan && it->ofs !=3D it->sb->s_blocksize) { + DBG_BUGON(1); + return -EFSCORRUPTED; + } + + it->blkaddr +=3D erofs_blknr(it->sb, it->ofs); + it->kaddr =3D erofs_bread(&it->buf, it->blkaddr, EROFS_KMAP); + if (IS_ERR(it->kaddr)) + return PTR_ERR(it->kaddr); + it->ofs =3D erofs_blkoff(it->sb, it->ofs); + return 0; +} + static int erofs_init_inode_xattrs(struct inode *inode) { struct erofs_inode *const vi =3D EROFS_I(inode); @@ -80,6 +98,7 @@ static int erofs_init_inode_xattrs(struct inode *inode) goto out_unlock; } =20 + it.sb =3D sb; it.buf =3D __EROFS_BUF_INITIALIZER; erofs_init_metabuf(&it.buf, sb); it.blkaddr =3D erofs_blknr(sb, erofs_iloc(inode) + vi->inode_isize); @@ -106,18 +125,11 @@ static int erofs_init_inode_xattrs(struct inode *inod= e) it.ofs +=3D sizeof(struct erofs_xattr_ibody_header); =20 for (i =3D 0; i < vi->xattr_shared_count; ++i) { - if (it.ofs >=3D sb->s_blocksize) { - /* cannot be unaligned */ - DBG_BUGON(it.ofs !=3D sb->s_blocksize); - - it.kaddr =3D erofs_bread(&it.buf, ++it.blkaddr, EROFS_KMAP); - if (IS_ERR(it.kaddr)) { - kfree(vi->xattr_shared_xattrs); - vi->xattr_shared_xattrs =3D NULL; - ret =3D PTR_ERR(it.kaddr); - goto out_unlock; - } - it.ofs =3D 0; + ret =3D erofs_xattr_iter_fixup(&it, true); + if (ret) { + kfree(vi->xattr_shared_xattrs); + vi->xattr_shared_xattrs =3D NULL; + goto out_unlock; } vi->xattr_shared_xattrs[i] =3D le32_to_cpu(*(__le32 *)(it.kaddr + it.ofs)); @@ -150,19 +162,6 @@ struct xattr_iter_handlers { unsigned int len); }; =20 -static inline int xattr_iter_fixup(struct xattr_iter *it) -{ - if (it->ofs < it->sb->s_blocksize) - return 0; - - it->blkaddr +=3D erofs_blknr(it->sb, it->ofs); - it->kaddr =3D erofs_bread(&it->buf, it->blkaddr, EROFS_KMAP); - if (IS_ERR(it->kaddr)) - return PTR_ERR(it->kaddr); - it->ofs =3D erofs_blkoff(it->sb, it->ofs); - return 0; -} - static int inline_xattr_iter_begin(struct xattr_iter *it, struct inode *inode) { @@ -199,7 +198,7 @@ static int xattr_foreach(struct xattr_iter *it, int err; =20 /* 0. fixup blkaddr, ofs, ipage */ - err =3D xattr_iter_fixup(it); + err =3D erofs_xattr_iter_fixup(it, false); if (err) return err; =20 @@ -234,14 +233,9 @@ static int xattr_foreach(struct xattr_iter *it, processed =3D 0; =20 while (processed < entry.e_name_len) { - if (it->ofs >=3D it->sb->s_blocksize) { - DBG_BUGON(it->ofs > it->sb->s_blocksize); - - err =3D xattr_iter_fixup(it); - if (err) - goto out; - it->ofs =3D 0; - } + err =3D erofs_xattr_iter_fixup(it, true); + if (err) + goto out; =20 slice =3D min_t(unsigned int, it->sb->s_blocksize - it->ofs, entry.e_name_len - processed); @@ -269,14 +263,9 @@ static int xattr_foreach(struct xattr_iter *it, } =20 while (processed < value_sz) { - if (it->ofs >=3D it->sb->s_blocksize) { - DBG_BUGON(it->ofs > it->sb->s_blocksize); - - err =3D xattr_iter_fixup(it); - if (err) - goto out; - it->ofs =3D 0; - } + err =3D erofs_xattr_iter_fixup(it, true); + if (err) + goto out; =20 slice =3D min_t(unsigned int, it->sb->s_blocksize - it->ofs, value_sz - processed); --=20 2.19.1.6.gb485710b