From nobody Sun Feb 8 05:59:10 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 743BEC7EE29 for ; Thu, 8 Jun 2023 11:30:48 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S235894AbjFHLaq (ORCPT ); Thu, 8 Jun 2023 07:30:46 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:47006 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232040AbjFHLai (ORCPT ); Thu, 8 Jun 2023 07:30:38 -0400 Received: from out30-111.freemail.mail.aliyun.com (out30-111.freemail.mail.aliyun.com [115.124.30.111]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 0ED312719 for ; Thu, 8 Jun 2023 04:30:24 -0700 (PDT) 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=ay29a033018046049;MF=jefflexu@linux.alibaba.com;NM=1;PH=DS;RN=5;SR=0;TI=SMTPD_---0Vke9GoT_1686223821; Received: from localhost(mailfrom:jefflexu@linux.alibaba.com fp:SMTPD_---0Vke9GoT_1686223821) by smtp.aliyun-inc.com; Thu, 08 Jun 2023 19:30:22 +0800 From: Jingbo Xu To: hsiangkao@linux.alibaba.com, chao@kernel.org, huyue2@coolpad.com, linux-erofs@lists.ozlabs.org Cc: linux-kernel@vger.kernel.org Subject: [PATCH v6 1/5] erofs: use absolute position in xattr iterator Date: Thu, 8 Jun 2023 19:30:16 +0800 Message-Id: <20230608113020.66626-2-jefflexu@linux.alibaba.com> X-Mailer: git-send-email 2.19.1.6.gb485710b In-Reply-To: <20230608113020.66626-1-jefflexu@linux.alibaba.com> References: <20230608113020.66626-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" Replace blkaddr/ofs with pos in 'struct erofs_xattr_iter'. After erofs_bread() is introduced to replace raw page cache APIs for metadata I/Os handling, xattr_iter_fixup() is no longer needed anymore. In addition, it is also unnecessary to check if the iterated position is span over the block boundary as absolute offset is used instead of blkaddr + offset pairs. Signed-off-by: Jingbo Xu --- fs/erofs/xattr.c | 154 +++++++++++++++++++---------------------------- 1 file changed, 61 insertions(+), 93 deletions(-) diff --git a/fs/erofs/xattr.c b/fs/erofs/xattr.c index d9e041d27a35..d9aaa8016eea 100644 --- a/fs/erofs/xattr.c +++ b/fs/erofs/xattr.c @@ -7,26 +7,11 @@ #include #include "xattr.h" =20 -static inline erofs_blk_t erofs_xattr_blkaddr(struct super_block *sb, - unsigned int xattr_id) -{ - return EROFS_SB(sb)->xattr_blkaddr + - erofs_blknr(sb, xattr_id * sizeof(__u32)); -} - -static inline unsigned int erofs_xattr_blkoff(struct super_block *sb, - unsigned int xattr_id) -{ - return erofs_blkoff(sb, xattr_id * sizeof(__u32)); -} - struct xattr_iter { struct super_block *sb; struct erofs_buf buf; + erofs_off_t pos; void *kaddr; - - erofs_blk_t blkaddr; - unsigned int ofs; }; =20 static int erofs_init_inode_xattrs(struct inode *inode) @@ -82,17 +67,16 @@ static int erofs_init_inode_xattrs(struct inode *inode) =20 it.buf =3D __EROFS_BUF_INITIALIZER; erofs_init_metabuf(&it.buf, sb); - it.blkaddr =3D erofs_blknr(sb, erofs_iloc(inode) + vi->inode_isize); - it.ofs =3D erofs_blkoff(sb, erofs_iloc(inode) + vi->inode_isize); + it.pos =3D erofs_iloc(inode) + vi->inode_isize; =20 /* read in shared xattr array (non-atomic, see kmalloc below) */ - it.kaddr =3D erofs_bread(&it.buf, it.blkaddr, EROFS_KMAP); + it.kaddr =3D erofs_bread(&it.buf, erofs_blknr(sb, it.pos), EROFS_KMAP); if (IS_ERR(it.kaddr)) { ret =3D PTR_ERR(it.kaddr); goto out_unlock; } =20 - ih =3D (struct erofs_xattr_ibody_header *)(it.kaddr + it.ofs); + ih =3D it.kaddr + erofs_blkoff(sb, it.pos); vi->xattr_shared_count =3D ih->h_shared_count; vi->xattr_shared_xattrs =3D kmalloc_array(vi->xattr_shared_count, sizeof(uint), GFP_KERNEL); @@ -103,25 +87,20 @@ static int erofs_init_inode_xattrs(struct inode *inode) } =20 /* let's skip ibody header */ - it.ofs +=3D sizeof(struct erofs_xattr_ibody_header); + it.pos +=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; + it.kaddr =3D erofs_bread(&it.buf, erofs_blknr(sb, it.pos), + 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; } - vi->xattr_shared_xattrs[i] =3D - le32_to_cpu(*(__le32 *)(it.kaddr + it.ofs)); - it.ofs +=3D sizeof(__le32); + vi->xattr_shared_xattrs[i] =3D le32_to_cpu(*(__le32 *) + (it.kaddr + erofs_blkoff(sb, it.pos))); + it.pos +=3D sizeof(__le32); } erofs_put_metabuf(&it.buf); =20 @@ -150,24 +129,11 @@ 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) { struct erofs_inode *const vi =3D EROFS_I(inode); - unsigned int xattr_header_sz, inline_xattr_ofs; + unsigned int xattr_header_sz; =20 xattr_header_sz =3D sizeof(struct erofs_xattr_ibody_header) + sizeof(u32) * vi->xattr_shared_count; @@ -176,11 +142,9 @@ static int inline_xattr_iter_begin(struct xattr_iter *= it, return -ENOATTR; } =20 - inline_xattr_ofs =3D vi->inode_isize + xattr_header_sz; - - it->blkaddr =3D erofs_blknr(it->sb, erofs_iloc(inode) + inline_xattr_ofs); - it->ofs =3D erofs_blkoff(it->sb, erofs_iloc(inode) + inline_xattr_ofs); - it->kaddr =3D erofs_bread(&it->buf, it->blkaddr, EROFS_KMAP); + it->pos =3D erofs_iloc(inode) + vi->inode_isize + xattr_header_sz; + it->kaddr =3D erofs_bread(&it->buf, erofs_blknr(it->sb, it->pos), + EROFS_KMAP); if (IS_ERR(it->kaddr)) return PTR_ERR(it->kaddr); return vi->xattr_isize - xattr_header_sz; @@ -188,27 +152,29 @@ static int inline_xattr_iter_begin(struct xattr_iter = *it, =20 /* * Regardless of success or failure, `xattr_foreach' will end up with - * `ofs' pointing to the next xattr item rather than an arbitrary position. + * `pos' pointing to the next xattr item rather than an arbitrary position. */ static int xattr_foreach(struct xattr_iter *it, const struct xattr_iter_handlers *op, unsigned int *tlimit) { struct erofs_xattr_entry entry; + struct super_block *sb =3D it->sb; unsigned int value_sz, processed, slice; int err; =20 - /* 0. fixup blkaddr, ofs, ipage */ - err =3D xattr_iter_fixup(it); - if (err) - return err; + /* 0. fixup blkaddr, pos */ + it->kaddr =3D erofs_bread(&it->buf, erofs_blknr(sb, it->pos), EROFS_KMAP); + if (IS_ERR(it->kaddr)) + return PTR_ERR(it->kaddr); =20 /* * 1. read xattr entry to the memory, * since we do EROFS_XATTR_ALIGN * therefore entry should be in the page */ - entry =3D *(struct erofs_xattr_entry *)(it->kaddr + it->ofs); + entry =3D *(struct erofs_xattr_entry *) + (it->kaddr + erofs_blkoff(sb, it->pos)); if (tlimit) { unsigned int entry_sz =3D erofs_xattr_entry_size(&entry); =20 @@ -220,40 +186,40 @@ static int xattr_foreach(struct xattr_iter *it, *tlimit -=3D entry_sz; } =20 - it->ofs +=3D sizeof(struct erofs_xattr_entry); + it->pos +=3D sizeof(struct erofs_xattr_entry); value_sz =3D le16_to_cpu(entry.e_value_size); =20 /* handle entry */ err =3D op->entry(it, &entry); if (err) { - it->ofs +=3D entry.e_name_len + value_sz; + it->pos +=3D entry.e_name_len + value_sz; goto out; } =20 - /* 2. handle xattr name (ofs will finally be at the end of name) */ + /* 2. handle xattr name (pos will finally be at the end of name) */ 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; + it->kaddr =3D erofs_bread(&it->buf, erofs_blknr(sb, it->pos), + EROFS_KMAP); + if (IS_ERR(it->kaddr)) { + err =3D PTR_ERR(it->kaddr); + goto out; } =20 - slice =3D min_t(unsigned int, it->sb->s_blocksize - it->ofs, + slice =3D min_t(unsigned int, + sb->s_blocksize - erofs_blkoff(sb, it->pos), entry.e_name_len - processed); =20 /* handle name */ - err =3D op->name(it, processed, it->kaddr + it->ofs, slice); + err =3D op->name(it, processed, + it->kaddr + erofs_blkoff(sb, it->pos), slice); if (err) { - it->ofs +=3D entry.e_name_len - processed + value_sz; + it->pos +=3D entry.e_name_len - processed + value_sz; goto out; } =20 - it->ofs +=3D slice; + it->pos +=3D slice; processed +=3D slice; } =20 @@ -263,31 +229,31 @@ static int xattr_foreach(struct xattr_iter *it, if (op->alloc_buffer) { err =3D op->alloc_buffer(it, value_sz); if (err) { - it->ofs +=3D value_sz; + it->pos +=3D value_sz; goto out; } } =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; + it->kaddr =3D erofs_bread(&it->buf, erofs_blknr(sb, it->pos), + EROFS_KMAP); + if (IS_ERR(it->kaddr)) { + err =3D PTR_ERR(it->kaddr); + goto out; } =20 - slice =3D min_t(unsigned int, it->sb->s_blocksize - it->ofs, + slice =3D min_t(unsigned int, + sb->s_blocksize - erofs_blkoff(sb, it->pos), value_sz - processed); - op->value(it, processed, it->kaddr + it->ofs, slice); - it->ofs +=3D slice; + op->value(it, processed, it->kaddr + erofs_blkoff(sb, it->pos), + slice); + it->pos +=3D slice; processed +=3D slice; } =20 out: /* xattrs should be 4-byte aligned (on-disk constraint) */ - it->ofs =3D EROFS_XATTR_ALIGN(it->ofs); + it->pos =3D EROFS_XATTR_ALIGN(it->pos); return err < 0 ? err : 0; } =20 @@ -399,9 +365,10 @@ static int shared_getxattr(struct inode *inode, struct= getxattr_iter *it) =20 for (i =3D 0; i < vi->xattr_shared_count; ++i) { xsid =3D vi->xattr_shared_xattrs[i]; - it->it.blkaddr =3D erofs_xattr_blkaddr(sb, xsid); - it->it.ofs =3D erofs_xattr_blkoff(sb, xsid); - it->it.kaddr =3D erofs_bread(&it->it.buf, it->it.blkaddr, EROFS_KMAP); + it->it.pos =3D erofs_pos(sb, EROFS_SB(sb)->xattr_blkaddr) + + xsid * sizeof(__u32); + it->it.kaddr =3D erofs_bread(&it->it.buf, + erofs_blknr(sb, it->it.pos), EROFS_KMAP); if (IS_ERR(it->it.kaddr)) return PTR_ERR(it->it.kaddr); =20 @@ -604,9 +571,10 @@ static int shared_listxattr(struct listxattr_iter *it) =20 for (i =3D 0; i < vi->xattr_shared_count; ++i) { xsid =3D vi->xattr_shared_xattrs[i]; - it->it.blkaddr =3D erofs_xattr_blkaddr(sb, xsid); - it->it.ofs =3D erofs_xattr_blkoff(sb, xsid); - it->it.kaddr =3D erofs_bread(&it->it.buf, it->it.blkaddr, EROFS_KMAP); + it->it.pos =3D erofs_pos(sb, EROFS_SB(sb)->xattr_blkaddr) + + xsid * sizeof(__u32); + it->it.kaddr =3D erofs_bread(&it->it.buf, + erofs_blknr(sb, it->it.pos), EROFS_KMAP); if (IS_ERR(it->it.kaddr)) return PTR_ERR(it->it.kaddr); =20 --=20 2.19.1.6.gb485710b