From patchwork Thu Jun 1 02:43:42 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jingbo Xu X-Patchwork-Id: 101661 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:994d:0:b0:3d9:f83d:47d9 with SMTP id k13csp13331vqr; Wed, 31 May 2023 19:58:04 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ6D9RLD/kYCHz7oxl43N0nLKj7TgRZpSX4/cnM1h8rpFj6XXZvvvYOG2PlSkeU7GA1HE8M8 X-Received: by 2002:a05:6830:1246:b0:6af:78cc:e475 with SMTP id s6-20020a056830124600b006af78cce475mr4415204otp.24.1685588283797; Wed, 31 May 2023 19:58:03 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1685588283; cv=none; d=google.com; s=arc-20160816; b=Lf6TjuE/v56YtaN3L1aYzRXcLwVx4xiPc8Xif6AKKESQbmvdJjlUthrQkVyfmD5kmY nGML28/IqzUcXfwDhglE0Aa3ZOGwxzQL9DTyS9ph5MMnL+HrVklNvOvGxbDM6YaEJf31 +1CYw+XG2Z4Ezk+/3ZguN9EgIe/TxKDlFOy7NAzNpbiIMG3xF13JBcSxYezGIneDR2Rr d3Ly0212sKRHQ+lm9AAS7PIqRyhQA5wJ3URuEf0b1Smdh0hWJyH82LLwGYBcMfviQPU6 wJyb5cI2ZsLpmBRWu1rCAMES6uaYCpW4aV5Ls0a8q/AaEnuXSdYTABo+NVFscrB1cbIj nNWQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from; bh=TVCtU6g2wa6bNdhgiVDO4vf1NjuGdGauKHsjsEyrGZU=; b=TwsKAHcyF1nthskm13BO8n3iiJ/xaOzNM+OFzmjqYATpfczQufae4j0VwRzFsFlUpv HwoxC5R01xcRrf1od2Yin0ecok9ye2KIxdBLlIbLhKZghrbvB4TpFGyYl7W37nh6jc1H NC6O+T1LVv6U7ZGcQPKn19x5tcLwg/lJqXWbyGxICWg3jlFhCejxG5LaeYnT3m+qKVLR U41xuPuShzWtx9v+J0IQbRr5waPzh/E0DHqeaF7Davboc3WQkzRp5i9wT7XUak+G6b8z wzI+ub0KNUS0+IrMy/8jv+NQ+EQlleaUqZjRccvBHMwVL9TJw9M2BTLT3hv4AVJpcunp Tphg== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=alibaba.com Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id o27-20020a637e5b000000b0053fec1cf2dcsi804114pgn.28.2023.05.31.19.57.49; Wed, 31 May 2023 19:58:03 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=alibaba.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231191AbjFACn4 (ORCPT + 99 others); Wed, 31 May 2023 22:43:56 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:33098 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230492AbjFACny (ORCPT ); Wed, 31 May 2023 22:43:54 -0400 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 7B98012C for ; Wed, 31 May 2023 19:43:52 -0700 (PDT) X-Alimail-AntiSpam: AC=PASS;BC=-1|-1;BR=01201311R121e4;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-8yUv_1685587428; Received: from localhost(mailfrom:jefflexu@linux.alibaba.com fp:SMTPD_---0Vk-8yUv_1685587428) by smtp.aliyun-inc.com; Thu, 01 Jun 2023 10:43:49 +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 1/6] erofs: convert erofs_read_metabuf() to erofs_bread() for xattr Date: Thu, 1 Jun 2023 10:43:42 +0800 Message-Id: <20230601024347.108469-2-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 X-Spam-Status: No, score=-9.9 required=5.0 tests=BAYES_00, ENV_AND_HDR_SPF_MATCH,RCVD_IN_DNSWL_NONE,SPF_HELO_NONE,SPF_PASS, T_FILL_THIS_FORM_SHORT,T_SCC_BODY_TEXT_LINE,UNPARSEABLE_RELAY, USER_IN_DEF_SPF_WL autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1767467420096384630?= X-GMAIL-MSGID: =?utf-8?q?1767467420096384630?= buf->inode is constant once initialized during erofs_buf's lifetime. Thus call erofs_init_metabuf() and erofs_bread() separately to avoid the repetition of assigning buf->inode when iterating xattrs. Signed-off-by: Jingbo Xu Reviewed-by: Gao Xiang --- fs/erofs/xattr.c | 25 +++++++++++-------------- 1 file changed, 11 insertions(+), 14 deletions(-) diff --git a/fs/erofs/xattr.c b/fs/erofs/xattr.c index bbfe7ce170d2..d9e041d27a35 100644 --- a/fs/erofs/xattr.c +++ b/fs/erofs/xattr.c @@ -81,11 +81,12 @@ static int erofs_init_inode_xattrs(struct inode *inode) } it.buf = __EROFS_BUF_INITIALIZER; + erofs_init_metabuf(&it.buf, sb); it.blkaddr = erofs_blknr(sb, erofs_iloc(inode) + vi->inode_isize); it.ofs = erofs_blkoff(sb, erofs_iloc(inode) + vi->inode_isize); /* read in shared xattr array (non-atomic, see kmalloc below) */ - it.kaddr = erofs_read_metabuf(&it.buf, sb, it.blkaddr, EROFS_KMAP); + it.kaddr = erofs_bread(&it.buf, it.blkaddr, EROFS_KMAP); if (IS_ERR(it.kaddr)) { ret = PTR_ERR(it.kaddr); goto out_unlock; @@ -109,8 +110,7 @@ static int erofs_init_inode_xattrs(struct inode *inode) /* cannot be unaligned */ DBG_BUGON(it.ofs != sb->s_blocksize); - it.kaddr = erofs_read_metabuf(&it.buf, sb, ++it.blkaddr, - EROFS_KMAP); + it.kaddr = erofs_bread(&it.buf, ++it.blkaddr, EROFS_KMAP); if (IS_ERR(it.kaddr)) { kfree(vi->xattr_shared_xattrs); vi->xattr_shared_xattrs = NULL; @@ -156,8 +156,7 @@ static inline int xattr_iter_fixup(struct xattr_iter *it) return 0; it->blkaddr += erofs_blknr(it->sb, it->ofs); - it->kaddr = erofs_read_metabuf(&it->buf, it->sb, it->blkaddr, - EROFS_KMAP); + it->kaddr = erofs_bread(&it->buf, it->blkaddr, EROFS_KMAP); if (IS_ERR(it->kaddr)) return PTR_ERR(it->kaddr); it->ofs = erofs_blkoff(it->sb, it->ofs); @@ -181,8 +180,7 @@ static int inline_xattr_iter_begin(struct xattr_iter *it, it->blkaddr = erofs_blknr(it->sb, erofs_iloc(inode) + inline_xattr_ofs); it->ofs = erofs_blkoff(it->sb, erofs_iloc(inode) + inline_xattr_ofs); - it->kaddr = erofs_read_metabuf(&it->buf, inode->i_sb, it->blkaddr, - EROFS_KMAP); + it->kaddr = erofs_bread(&it->buf, it->blkaddr, EROFS_KMAP); if (IS_ERR(it->kaddr)) return PTR_ERR(it->kaddr); return vi->xattr_isize - xattr_header_sz; @@ -403,8 +401,7 @@ static int shared_getxattr(struct inode *inode, struct getxattr_iter *it) xsid = vi->xattr_shared_xattrs[i]; it->it.blkaddr = erofs_xattr_blkaddr(sb, xsid); it->it.ofs = erofs_xattr_blkoff(sb, xsid); - it->it.kaddr = erofs_read_metabuf(&it->it.buf, sb, - it->it.blkaddr, EROFS_KMAP); + it->it.kaddr = erofs_bread(&it->it.buf, it->it.blkaddr, EROFS_KMAP); if (IS_ERR(it->it.kaddr)) return PTR_ERR(it->it.kaddr); @@ -444,13 +441,14 @@ int erofs_getxattr(struct inode *inode, int index, if (it.name.len > EROFS_NAME_LEN) return -ERANGE; + it.it.sb = inode->i_sb; it.it.buf = __EROFS_BUF_INITIALIZER; + erofs_init_metabuf(&it.it.buf, it.it.sb); it.name.name = name; it.buffer = buffer; it.buffer_size = buffer_size; - it.it.sb = inode->i_sb; ret = inline_getxattr(inode, &it); if (ret == -ENOATTR) ret = shared_getxattr(inode, &it); @@ -608,8 +606,7 @@ static int shared_listxattr(struct listxattr_iter *it) xsid = vi->xattr_shared_xattrs[i]; it->it.blkaddr = erofs_xattr_blkaddr(sb, xsid); it->it.ofs = erofs_xattr_blkoff(sb, xsid); - it->it.kaddr = erofs_read_metabuf(&it->it.buf, sb, - it->it.blkaddr, EROFS_KMAP); + it->it.kaddr = erofs_bread(&it->it.buf, it->it.blkaddr, EROFS_KMAP); if (IS_ERR(it->it.kaddr)) return PTR_ERR(it->it.kaddr); @@ -632,14 +629,14 @@ ssize_t erofs_listxattr(struct dentry *dentry, if (ret) return ret; + it.it.sb = dentry->d_sb; it.it.buf = __EROFS_BUF_INITIALIZER; + erofs_init_metabuf(&it.it.buf, it.it.sb); it.dentry = dentry; it.buffer = buffer; it.buffer_size = buffer_size; it.buffer_ofs = 0; - it.it.sb = dentry->d_sb; - ret = inline_listxattr(&it); if (ret >= 0 || ret == -ENOATTR) ret = shared_listxattr(&it); From patchwork Thu Jun 1 02:43:43 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jingbo Xu X-Patchwork-Id: 101660 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:994d:0:b0:3d9:f83d:47d9 with SMTP id k13csp12788vqr; Wed, 31 May 2023 19:55:31 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ7uzkUgZgC3FlcZ4NTO/kJCyCUHXwkK/W+sGaGj4NXX8fVeVKf09XJgtMBa7zY2Vo2Cg/i9 X-Received: by 2002:a05:6358:c23:b0:127:7e69:d3c0 with SMTP id f35-20020a0563580c2300b001277e69d3c0mr4662308rwj.11.1685588131625; Wed, 31 May 2023 19:55:31 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1685588131; cv=none; d=google.com; s=arc-20160816; b=V3hTFGJ54NCbriugPn7fx1vskzkcltOruNh8gsjUqfT3t7CPFnLsfTJJzmEP3fkKgA BEGCWLeJYDE47wah02URO4mo2Zcmk1Awr9I1oZnHCT4YkgaooNMOnQmrb9aiaCqlcx3r 4fK+Kyxdr4oRw22NFWEda8+yFSK6CR5hA5wqGoAg5FdRY6mLppRljtEZckv0klydvNvN DxN8LVtfvsx8s69q/vv2wjm68aZT16qm8Unm1ZFMKvAfh2hTwrtId/6HZNSjd3WczP4N Y4KBGsA5WK52dU5bXBHKoP8hu5iKpX+lXapaAbDhyxp+QBnzmN4kSPySjT4H5zzGKAHc CtKQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from; bh=MPdZfxDJOPXH8qwRvX5Kc7sJqQIHmaDVecrSvRqDyB4=; b=Z+s9Gvtdz5mnsHnddgfcBubdb6ImIOP6eK+KSquM9hbEc0pUqGQUgF22pbsmcD22YX A2AOMVaGzFhaNmi8BYMla1ctxBvRiCLUXAiaB1kNbvkFnueHWBKqTRNZtpB1/RSjO6yB fAXUD3OCU2Ftc2L8/YdRGzQJcoSyCJgnSQOpcBME+ekN55AN15rIWL5IC3fSWecMJkrd rHc7j5WU+LzJvrxEb8RQgEYiPK1OgOrV6b9NXN+Y+IU8qGYbKy/L7RTK/V6WgrqkilC9 JHVnPT2CAW1WjY0YEvXi7bUP5oUnfJLG+6rweT4Ev00bAlLJAmcbjOavEoc/V8Cv2Wi2 HEdA== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=alibaba.com Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id u2-20020a17090a400200b00256917c7851si328600pjc.107.2023.05.31.19.55.17; Wed, 31 May 2023 19:55:31 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=alibaba.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231224AbjFACn7 (ORCPT + 99 others); Wed, 31 May 2023 22:43:59 -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 X-Spam-Status: No, score=-9.9 required=5.0 tests=BAYES_00, ENV_AND_HDR_SPF_MATCH,RCVD_IN_DNSWL_NONE,SPF_HELO_NONE,SPF_PASS, T_SCC_BODY_TEXT_LINE,UNPARSEABLE_RELAY,USER_IN_DEF_SPF_WL autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1767467260870307556?= X-GMAIL-MSGID: =?utf-8?q?1767467260870307556?= 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; }; +static inline int erofs_xattr_iter_fixup(struct xattr_iter *it, bool nospan) +{ + if (it->ofs < it->sb->s_blocksize) + return 0; + + if (nospan && it->ofs != it->sb->s_blocksize) { + DBG_BUGON(1); + return -EFSCORRUPTED; + } + + it->blkaddr += erofs_blknr(it->sb, it->ofs); + it->kaddr = erofs_bread(&it->buf, it->blkaddr, EROFS_KMAP); + if (IS_ERR(it->kaddr)) + return PTR_ERR(it->kaddr); + it->ofs = erofs_blkoff(it->sb, it->ofs); + return 0; +} + static int erofs_init_inode_xattrs(struct inode *inode) { struct erofs_inode *const vi = EROFS_I(inode); @@ -80,6 +98,7 @@ static int erofs_init_inode_xattrs(struct inode *inode) goto out_unlock; } + it.sb = sb; it.buf = __EROFS_BUF_INITIALIZER; erofs_init_metabuf(&it.buf, sb); it.blkaddr = erofs_blknr(sb, erofs_iloc(inode) + vi->inode_isize); @@ -106,18 +125,11 @@ static int erofs_init_inode_xattrs(struct inode *inode) it.ofs += sizeof(struct erofs_xattr_ibody_header); for (i = 0; i < vi->xattr_shared_count; ++i) { - if (it.ofs >= sb->s_blocksize) { - /* cannot be unaligned */ - DBG_BUGON(it.ofs != sb->s_blocksize); - - it.kaddr = erofs_bread(&it.buf, ++it.blkaddr, EROFS_KMAP); - if (IS_ERR(it.kaddr)) { - kfree(vi->xattr_shared_xattrs); - vi->xattr_shared_xattrs = NULL; - ret = PTR_ERR(it.kaddr); - goto out_unlock; - } - it.ofs = 0; + ret = erofs_xattr_iter_fixup(&it, true); + if (ret) { + kfree(vi->xattr_shared_xattrs); + vi->xattr_shared_xattrs = NULL; + goto out_unlock; } vi->xattr_shared_xattrs[i] = le32_to_cpu(*(__le32 *)(it.kaddr + it.ofs)); @@ -150,19 +162,6 @@ struct xattr_iter_handlers { unsigned int len); }; -static inline int xattr_iter_fixup(struct xattr_iter *it) -{ - if (it->ofs < it->sb->s_blocksize) - return 0; - - it->blkaddr += erofs_blknr(it->sb, it->ofs); - it->kaddr = erofs_bread(&it->buf, it->blkaddr, EROFS_KMAP); - if (IS_ERR(it->kaddr)) - return PTR_ERR(it->kaddr); - it->ofs = 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; /* 0. fixup blkaddr, ofs, ipage */ - err = xattr_iter_fixup(it); + err = erofs_xattr_iter_fixup(it, false); if (err) return err; @@ -234,14 +233,9 @@ static int xattr_foreach(struct xattr_iter *it, processed = 0; while (processed < entry.e_name_len) { - if (it->ofs >= it->sb->s_blocksize) { - DBG_BUGON(it->ofs > it->sb->s_blocksize); - - err = xattr_iter_fixup(it); - if (err) - goto out; - it->ofs = 0; - } + err = erofs_xattr_iter_fixup(it, true); + if (err) + goto out; slice = 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, } while (processed < value_sz) { - if (it->ofs >= it->sb->s_blocksize) { - DBG_BUGON(it->ofs > it->sb->s_blocksize); - - err = xattr_iter_fixup(it); - if (err) - goto out; - it->ofs = 0; - } + err = erofs_xattr_iter_fixup(it, true); + if (err) + goto out; slice = min_t(unsigned int, it->sb->s_blocksize - it->ofs, value_sz - processed); From patchwork Thu Jun 1 02:43:44 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jingbo Xu X-Patchwork-Id: 101659 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:994d:0:b0:3d9:f83d:47d9 with SMTP id k13csp11752vqr; Wed, 31 May 2023 19:50:50 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ7hghnsovbnt/96aNUuC5TlRYuwsZYoyV7uLBUYi60rRTFghETZBIFTs2CjvChgRlx8DBKr X-Received: by 2002:a05:6870:e7d6:b0:19e:a0df:414a with SMTP id q22-20020a056870e7d600b0019ea0df414amr4423355oak.25.1685587850328; Wed, 31 May 2023 19:50:50 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1685587850; cv=none; d=google.com; s=arc-20160816; b=MU84bEQI1TKSNI/R2RFuMuhCE1HWQycmo3mqe49Xm6ovX00178IM96Yr85ThRd7/5a D/v14IuV/h0avKnXVUoirQvd+TQ+EGpnkNLZeDZylHXWmVwm6vRVTsrBX93raDEfkh0d DECKVdkzHLsE7JQu3k+MFhCNX8vz8MZISp/3Nt5TmZYZT1gpa+o3cX8RScxn9u1Fd4tq y5EyWnRGXSRxAmWgpElWC3b3AFdW88wQOE+kOqGetm4Vtiox5PvU5Zh4IxtNr5gwdpxo 4a3bQXS/prmm+ipP/iV86IjryLhDsBhDLCap9msw7bOOGS7duJ2QRzdx8T/AyUgxFfKX h0SA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from; bh=nwpKKSGihCsl1sZsXzce9jrdguFdfUN/Cs8DO/VGiGg=; b=G9J1KYbjSvAmRqVu1SNXuq5YflsOXMbbh5C8aJ4b4kYjKGfXfIcBV0NZ+qnKFmb9F/ QWCCqXiC6gz0O3AltMU3l1pOo/arqNbLRwZNGzVA0FGeiA5MJOWHo7sNRJXGSS6+8fto mv5BOJX5f731O917gqIMWtiNZUawJ9cGD/zvtMa1OqbxqHfp+/B4mDHL7lRVw/c8Ly8q G/xWOk+QOPij22D4SR7RYaDGUdfkLtmMemdjiwg9UxXZitp1YlPXZctGGO/YdMzdmEBR qmCmAFO/kxArySmtOudY0mDL1WS7GKELf7E9wF8eiIc15+M6e1xqogwFK+490V4ZDodB 5e/Q== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=alibaba.com Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id j5-20020a170903024500b001ab16128039si2154974plh.213.2023.05.31.19.50.35; Wed, 31 May 2023 19:50:50 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=alibaba.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231238AbjFACoG (ORCPT + 99 others); Wed, 31 May 2023 22:44:06 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:33160 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231213AbjFACn5 (ORCPT ); Wed, 31 May 2023 22:43:57 -0400 Received: from out30-130.freemail.mail.aliyun.com (out30-130.freemail.mail.aliyun.com [115.124.30.130]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id AC532126 for ; Wed, 31 May 2023 19:43:54 -0700 (PDT) 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=ay29a033018046059;MF=jefflexu@linux.alibaba.com;NM=1;PH=DS;RN=5;SR=0;TI=SMTPD_---0Vk-8yVs_1685587431; Received: from localhost(mailfrom:jefflexu@linux.alibaba.com fp:SMTPD_---0Vk-8yVs_1685587431) by smtp.aliyun-inc.com; Thu, 01 Jun 2023 10:43:51 +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 3/6] erofs: unify xattr_iter structures Date: Thu, 1 Jun 2023 10:43:44 +0800 Message-Id: <20230601024347.108469-4-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 X-Spam-Status: No, score=-9.9 required=5.0 tests=BAYES_00, ENV_AND_HDR_SPF_MATCH,RCVD_IN_DNSWL_NONE,SPF_HELO_NONE,SPF_PASS, T_FILL_THIS_FORM_SHORT,T_SCC_BODY_TEXT_LINE,UNPARSEABLE_RELAY, USER_IN_DEF_SPF_WL autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1767466965813721231?= X-GMAIL-MSGID: =?utf-8?q?1767466965813721231?= Unify xattr_iter/listxattr_iter/getxattr_iter structures into erofs_xattr_iter structure. This is in preparation for the following further cleanup. Signed-off-by: Jingbo Xu Reviewed-by: Gao Xiang --- fs/erofs/xattr.c | 149 ++++++++++++++++++++--------------------------- 1 file changed, 63 insertions(+), 86 deletions(-) diff --git a/fs/erofs/xattr.c b/fs/erofs/xattr.c index 0fd574e94c8b..a691d539ae4f 100644 --- a/fs/erofs/xattr.c +++ b/fs/erofs/xattr.c @@ -20,16 +20,25 @@ static inline unsigned int erofs_xattr_blkoff(struct super_block *sb, return erofs_blkoff(sb, xattr_id * sizeof(__u32)); } -struct xattr_iter { +struct erofs_xattr_iter { struct super_block *sb; struct erofs_buf buf; void *kaddr; - erofs_blk_t blkaddr; unsigned int ofs; + + char *buffer; + int buffer_size, buffer_ofs; + + /* getxattr */ + int index, infix_len; + struct qstr name; + + /* listxattr */ + struct dentry *dentry; }; -static inline int erofs_xattr_iter_fixup(struct xattr_iter *it, bool nospan) +static inline int erofs_xattr_iter_fixup(struct erofs_xattr_iter *it, bool nospan) { if (it->ofs < it->sb->s_blocksize) return 0; @@ -50,7 +59,7 @@ static inline int erofs_xattr_iter_fixup(struct xattr_iter *it, bool nospan) static int erofs_init_inode_xattrs(struct inode *inode) { struct erofs_inode *const vi = EROFS_I(inode); - struct xattr_iter it; + struct erofs_xattr_iter it; unsigned int i; struct erofs_xattr_ibody_header *ih; struct super_block *sb = inode->i_sb; @@ -154,15 +163,15 @@ static int erofs_init_inode_xattrs(struct inode *inode) * and need to be handled */ struct xattr_iter_handlers { - int (*entry)(struct xattr_iter *_it, struct erofs_xattr_entry *entry); - int (*name)(struct xattr_iter *_it, unsigned int processed, char *buf, + int (*entry)(struct erofs_xattr_iter *it, struct erofs_xattr_entry *entry); + int (*name)(struct erofs_xattr_iter *it, unsigned int processed, char *buf, unsigned int len); - int (*alloc_buffer)(struct xattr_iter *_it, unsigned int value_sz); - void (*value)(struct xattr_iter *_it, unsigned int processed, char *buf, + int (*alloc_buffer)(struct erofs_xattr_iter *it, unsigned int value_sz); + void (*value)(struct erofs_xattr_iter *it, unsigned int processed, char *buf, unsigned int len); }; -static int inline_xattr_iter_begin(struct xattr_iter *it, +static int inline_xattr_iter_begin(struct erofs_xattr_iter *it, struct inode *inode) { struct erofs_inode *const vi = EROFS_I(inode); @@ -189,7 +198,7 @@ static int inline_xattr_iter_begin(struct xattr_iter *it, * Regardless of success or failure, `xattr_foreach' will end up with * `ofs' pointing to the next xattr item rather than an arbitrary position. */ -static int xattr_foreach(struct xattr_iter *it, +static int xattr_foreach(struct erofs_xattr_iter *it, const struct xattr_iter_handlers *op, unsigned int *tlimit) { @@ -280,18 +289,10 @@ static int xattr_foreach(struct xattr_iter *it, return err < 0 ? err : 0; } -struct getxattr_iter { - struct xattr_iter it; - - char *buffer; - int buffer_size, index, infix_len; - struct qstr name; -}; - -static int erofs_xattr_long_entrymatch(struct getxattr_iter *it, +static int erofs_xattr_long_entrymatch(struct erofs_xattr_iter *it, struct erofs_xattr_entry *entry) { - struct erofs_sb_info *sbi = EROFS_SB(it->it.sb); + struct erofs_sb_info *sbi = EROFS_SB(it->sb); struct erofs_xattr_prefix_item *pf = sbi->xattr_prefixes + (entry->e_name_index & EROFS_XATTR_LONG_PREFIX_MASK); @@ -309,11 +310,9 @@ static int erofs_xattr_long_entrymatch(struct getxattr_iter *it, return 0; } -static int xattr_entrymatch(struct xattr_iter *_it, +static int xattr_entrymatch(struct erofs_xattr_iter *it, struct erofs_xattr_entry *entry) { - struct getxattr_iter *it = container_of(_it, struct getxattr_iter, it); - /* should also match the infix for long name prefixes */ if (entry->e_name_index & EROFS_XATTR_LONG_PREFIX) return erofs_xattr_long_entrymatch(it, entry); @@ -325,32 +324,27 @@ static int xattr_entrymatch(struct xattr_iter *_it, return 0; } -static int xattr_namematch(struct xattr_iter *_it, +static int xattr_namematch(struct erofs_xattr_iter *it, unsigned int processed, char *buf, unsigned int len) { - struct getxattr_iter *it = container_of(_it, struct getxattr_iter, it); - if (memcmp(buf, it->name.name + it->infix_len + processed, len)) return -ENOATTR; return 0; } -static int xattr_checkbuffer(struct xattr_iter *_it, +static int xattr_checkbuffer(struct erofs_xattr_iter *it, unsigned int value_sz) { - struct getxattr_iter *it = container_of(_it, struct getxattr_iter, it); int err = it->buffer_size < value_sz ? -ERANGE : 0; it->buffer_size = value_sz; return !it->buffer ? 1 : err; } -static void xattr_copyvalue(struct xattr_iter *_it, +static void xattr_copyvalue(struct erofs_xattr_iter *it, unsigned int processed, char *buf, unsigned int len) { - struct getxattr_iter *it = container_of(_it, struct getxattr_iter, it); - memcpy(it->buffer + processed, buf, len); } @@ -361,40 +355,40 @@ static const struct xattr_iter_handlers find_xattr_handlers = { .value = xattr_copyvalue }; -static int inline_getxattr(struct inode *inode, struct getxattr_iter *it) +static int inline_getxattr(struct inode *inode, struct erofs_xattr_iter *it) { int ret; unsigned int remaining; - ret = inline_xattr_iter_begin(&it->it, inode); + ret = inline_xattr_iter_begin(it, inode); if (ret < 0) return ret; remaining = ret; while (remaining) { - ret = xattr_foreach(&it->it, &find_xattr_handlers, &remaining); + ret = xattr_foreach(it, &find_xattr_handlers, &remaining); if (ret != -ENOATTR) break; } return ret ? ret : it->buffer_size; } -static int shared_getxattr(struct inode *inode, struct getxattr_iter *it) +static int shared_getxattr(struct inode *inode, struct erofs_xattr_iter *it) { struct erofs_inode *const vi = EROFS_I(inode); - struct super_block *const sb = it->it.sb; + struct super_block *const sb = it->sb; unsigned int i, xsid; int ret = -ENOATTR; for (i = 0; i < vi->xattr_shared_count; ++i) { xsid = vi->xattr_shared_xattrs[i]; - it->it.blkaddr = erofs_xattr_blkaddr(sb, xsid); - it->it.ofs = erofs_xattr_blkoff(sb, xsid); - it->it.kaddr = erofs_bread(&it->it.buf, it->it.blkaddr, EROFS_KMAP); - if (IS_ERR(it->it.kaddr)) - return PTR_ERR(it->it.kaddr); + it->blkaddr = erofs_xattr_blkaddr(sb, xsid); + it->ofs = erofs_xattr_blkoff(sb, xsid); + it->kaddr = erofs_bread(&it->buf, it->blkaddr, EROFS_KMAP); + if (IS_ERR(it->kaddr)) + return PTR_ERR(it->kaddr); - ret = xattr_foreach(&it->it, &find_xattr_handlers, NULL); + ret = xattr_foreach(it, &find_xattr_handlers, NULL); if (ret != -ENOATTR) break; } @@ -416,7 +410,7 @@ int erofs_getxattr(struct inode *inode, int index, void *buffer, size_t buffer_size) { int ret; - struct getxattr_iter it; + struct erofs_xattr_iter it; if (!name) return -EINVAL; @@ -426,22 +420,21 @@ int erofs_getxattr(struct inode *inode, int index, return ret; it.index = index; - it.name.len = strlen(name); + it.name = (struct qstr)QSTR_INIT(name, strlen(name)); if (it.name.len > EROFS_NAME_LEN) return -ERANGE; - it.it.sb = inode->i_sb; - it.it.buf = __EROFS_BUF_INITIALIZER; - erofs_init_metabuf(&it.it.buf, it.it.sb); - it.name.name = name; - + it.sb = inode->i_sb; + it.buf = __EROFS_BUF_INITIALIZER; + erofs_init_metabuf(&it.buf, it.sb); it.buffer = buffer; it.buffer_size = buffer_size; + it.buffer_ofs = 0; ret = inline_getxattr(inode, &it); if (ret == -ENOATTR) ret = shared_getxattr(inode, &it); - erofs_put_metabuf(&it.it.buf); + erofs_put_metabuf(&it.buf); return ret; } @@ -487,25 +480,15 @@ const struct xattr_handler *erofs_xattr_handlers[] = { NULL, }; -struct listxattr_iter { - struct xattr_iter it; - - struct dentry *dentry; - char *buffer; - int buffer_size, buffer_ofs; -}; - -static int xattr_entrylist(struct xattr_iter *_it, +static int xattr_entrylist(struct erofs_xattr_iter *it, struct erofs_xattr_entry *entry) { - struct listxattr_iter *it = - container_of(_it, struct listxattr_iter, it); unsigned int base_index = entry->e_name_index; unsigned int prefix_len, infix_len = 0; const char *prefix, *infix = NULL; if (entry->e_name_index & EROFS_XATTR_LONG_PREFIX) { - struct erofs_sb_info *sbi = EROFS_SB(_it->sb); + struct erofs_sb_info *sbi = EROFS_SB(it->sb); struct erofs_xattr_prefix_item *pf = sbi->xattr_prefixes + (entry->e_name_index & EROFS_XATTR_LONG_PREFIX_MASK); @@ -537,23 +520,17 @@ static int xattr_entrylist(struct xattr_iter *_it, return 0; } -static int xattr_namelist(struct xattr_iter *_it, +static int xattr_namelist(struct erofs_xattr_iter *it, unsigned int processed, char *buf, unsigned int len) { - struct listxattr_iter *it = - container_of(_it, struct listxattr_iter, it); - memcpy(it->buffer + it->buffer_ofs, buf, len); it->buffer_ofs += len; return 0; } -static int xattr_skipvalue(struct xattr_iter *_it, +static int xattr_skipvalue(struct erofs_xattr_iter *it, unsigned int value_sz) { - struct listxattr_iter *it = - container_of(_it, struct listxattr_iter, it); - it->buffer[it->buffer_ofs++] = '\0'; return 1; } @@ -565,41 +542,41 @@ static const struct xattr_iter_handlers list_xattr_handlers = { .value = NULL }; -static int inline_listxattr(struct listxattr_iter *it) +static int inline_listxattr(struct erofs_xattr_iter *it) { int ret; unsigned int remaining; - ret = inline_xattr_iter_begin(&it->it, d_inode(it->dentry)); + ret = inline_xattr_iter_begin(it, d_inode(it->dentry)); if (ret < 0) return ret; remaining = ret; while (remaining) { - ret = xattr_foreach(&it->it, &list_xattr_handlers, &remaining); + ret = xattr_foreach(it, &list_xattr_handlers, &remaining); if (ret) break; } return ret ? ret : it->buffer_ofs; } -static int shared_listxattr(struct listxattr_iter *it) +static int shared_listxattr(struct erofs_xattr_iter *it) { struct inode *const inode = d_inode(it->dentry); struct erofs_inode *const vi = EROFS_I(inode); - struct super_block *const sb = it->it.sb; + struct super_block *const sb = it->sb; unsigned int i, xsid; int ret = 0; for (i = 0; i < vi->xattr_shared_count; ++i) { xsid = vi->xattr_shared_xattrs[i]; - it->it.blkaddr = erofs_xattr_blkaddr(sb, xsid); - it->it.ofs = erofs_xattr_blkoff(sb, xsid); - it->it.kaddr = erofs_bread(&it->it.buf, it->it.blkaddr, EROFS_KMAP); - if (IS_ERR(it->it.kaddr)) - return PTR_ERR(it->it.kaddr); + it->blkaddr = erofs_xattr_blkaddr(sb, xsid); + it->ofs = erofs_xattr_blkoff(sb, xsid); + it->kaddr = erofs_bread(&it->buf, it->blkaddr, EROFS_KMAP); + if (IS_ERR(it->kaddr)) + return PTR_ERR(it->kaddr); - ret = xattr_foreach(&it->it, &list_xattr_handlers, NULL); + ret = xattr_foreach(it, &list_xattr_handlers, NULL); if (ret) break; } @@ -610,7 +587,7 @@ ssize_t erofs_listxattr(struct dentry *dentry, char *buffer, size_t buffer_size) { int ret; - struct listxattr_iter it; + struct erofs_xattr_iter it; ret = erofs_init_inode_xattrs(d_inode(dentry)); if (ret == -ENOATTR) @@ -618,9 +595,9 @@ ssize_t erofs_listxattr(struct dentry *dentry, if (ret) return ret; - it.it.sb = dentry->d_sb; - it.it.buf = __EROFS_BUF_INITIALIZER; - erofs_init_metabuf(&it.it.buf, it.it.sb); + it.sb = dentry->d_sb; + it.buf = __EROFS_BUF_INITIALIZER; + erofs_init_metabuf(&it.buf, it.sb); it.dentry = dentry; it.buffer = buffer; it.buffer_size = buffer_size; @@ -629,7 +606,7 @@ ssize_t erofs_listxattr(struct dentry *dentry, ret = inline_listxattr(&it); if (ret >= 0 || ret == -ENOATTR) ret = shared_listxattr(&it); - erofs_put_metabuf(&it.it.buf); + erofs_put_metabuf(&it.buf); return ret; } From patchwork Thu Jun 1 02:43:45 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jingbo Xu X-Patchwork-Id: 101664 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:994d:0:b0:3d9:f83d:47d9 with SMTP id k13csp15308vqr; Wed, 31 May 2023 20:04:15 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ7fAYYNcgBwerQNFVUUzJZk2Z/yE83zAAojTMuMTB5qsq9xymaYh1C3NBOwydZ9gjRypH/4 X-Received: by 2002:a05:6870:8a21:b0:19a:7824:108e with SMTP id p33-20020a0568708a2100b0019a7824108emr6792369oaq.31.1685588655695; Wed, 31 May 2023 20:04:15 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1685588655; cv=none; d=google.com; s=arc-20160816; b=kdS8chT458NXVKzn2LeH6vYP6/4Pnc6n/HUcKLyDZoMGeWGvlL2AK0bdTt63ORUghy We6oe8+nsiZY5Hpxh4UgKXZOtnkDY1WMwDiSn8AcKvxzL852prXT9Vns0gAx9kuELRrV 6Sujhq6Gq7MuXgxGVBFbaK6xWDtF6zTg1v0QyTVUwZ7ff850e9Jx1rHg8cdAiKQfpD7a w+dNoEvdXaJa8r5qLuvjK1ckmEYeTecaoPaMIpkSZUKHIZja7hCk7SD/+21gNHZ0BjEf hY61R/jhjrvFjwPUHLH06reSWJjOCJ95m8iyl7O55ajmb0gPgHasC/FtvEcitUC6oHDb 9ztw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from; bh=VFIDkTiWXRAEW+1a1v5TeaeYlAw1WQYflb+M2WVtqtk=; b=HDKyFBzeLDkYj5GhbMc7LhX+vgplxfTjIHV2Pskk4zRPIarcPahqHOgnLPskzlh4I0 /CiIPQ9CSOVMryIGE0EA/i9aN4+Qq9liTfcZnoRpm0qHhVo9n3e8xhsjIvoNSZCcHvwY rStdC8JfP4JVI6FbpecwAsdvFKhj3wjCq3qtu/7XZT2u92idQwiGcr5M4+spMNmRbJF8 jmizH1My2KYORL+dv84ZHjxvfZMuV3JdUhbkota4j806kzZsswbsVD+1JwfwUd6vGgkU lY0pWlzvR0cVjqwp6MIYKvb3OO2mc16L51bA5fUWlpVXeyyP2Q7USCl8TIf4rKBifLS+ y/ow== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=alibaba.com Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id j186-20020a638bc3000000b0053fc757bb07si2035195pge.554.2023.05.31.20.04.03; Wed, 31 May 2023 20:04:15 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=alibaba.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231290AbjFACoK (ORCPT + 99 others); Wed, 31 May 2023 22:44:10 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:33176 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231216AbjFACn5 (ORCPT ); Wed, 31 May 2023 22:43:57 -0400 Received: from out30-99.freemail.mail.aliyun.com (out30-99.freemail.mail.aliyun.com [115.124.30.99]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 641FC107 for ; Wed, 31 May 2023 19:43:56 -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=ay29a033018045168;MF=jefflexu@linux.alibaba.com;NM=1;PH=DS;RN=5;SR=0;TI=SMTPD_---0Vk-9KrE_1685587432; Received: from localhost(mailfrom:jefflexu@linux.alibaba.com fp:SMTPD_---0Vk-9KrE_1685587432) by smtp.aliyun-inc.com; Thu, 01 Jun 2023 10:43:53 +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 4/6] erofs: make the size of read data stored in buffer_ofs Date: Thu, 1 Jun 2023 10:43:45 +0800 Message-Id: <20230601024347.108469-5-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 X-Spam-Status: No, score=-9.9 required=5.0 tests=BAYES_00, ENV_AND_HDR_SPF_MATCH,RCVD_IN_DNSWL_NONE,SPF_HELO_NONE,SPF_PASS, T_SCC_BODY_TEXT_LINE,UNPARSEABLE_RELAY,USER_IN_DEF_SPF_WL autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1767467810544354440?= X-GMAIL-MSGID: =?utf-8?q?1767467810544354440?= Since now xattr_iter structures have been unified, make the size of the read data stored in buffer_ofs. Don't bother reusing buffer_size for this use, which may be confusing. This is in preparation for the following further cleanup. Signed-off-by: Jingbo Xu Reviewed-by: Gao Xiang --- fs/erofs/xattr.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/fs/erofs/xattr.c b/fs/erofs/xattr.c index a691d539ae4f..19f9bf67440c 100644 --- a/fs/erofs/xattr.c +++ b/fs/erofs/xattr.c @@ -337,7 +337,7 @@ static int xattr_checkbuffer(struct erofs_xattr_iter *it, { int err = it->buffer_size < value_sz ? -ERANGE : 0; - it->buffer_size = value_sz; + it->buffer_ofs = value_sz; return !it->buffer ? 1 : err; } @@ -370,7 +370,7 @@ static int inline_getxattr(struct inode *inode, struct erofs_xattr_iter *it) if (ret != -ENOATTR) break; } - return ret ? ret : it->buffer_size; + return ret ? ret : it->buffer_ofs; } static int shared_getxattr(struct inode *inode, struct erofs_xattr_iter *it) @@ -392,7 +392,7 @@ static int shared_getxattr(struct inode *inode, struct erofs_xattr_iter *it) if (ret != -ENOATTR) break; } - return ret ? ret : it->buffer_size; + return ret ? ret : it->buffer_ofs; } static bool erofs_xattr_user_list(struct dentry *dentry) From patchwork Thu Jun 1 02:43:46 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jingbo Xu X-Patchwork-Id: 101681 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:994d:0:b0:3d9:f83d:47d9 with SMTP id k13csp18756vqr; Wed, 31 May 2023 20:15:44 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ6SaDQIUwe2AYSByrPcV6b7bncBxbaMCqGoyDlV7hA/5uLaDjieekxTXFITg824mU4TDH5S X-Received: by 2002:a05:620a:9048:b0:75b:23a1:3647 with SMTP id rl8-20020a05620a904800b0075b23a13647mr7937406qkn.8.1685589344034; Wed, 31 May 2023 20:15:44 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1685589343; cv=none; d=google.com; s=arc-20160816; b=01+kL9cQV2UYLF5yGCQTv3l1W3S1gHl0+RNx64s5vQWqFWwbAh0RfsrP/SOtf/tkCN d2RTbxN/TUusWhiSvsLa/ktIHloudud7jnwK+2zhrlf77KHpyCcypgFBVtcLV6Vtba4b V20fvat0l9a6AN+JVC4guY0AELW0aZejIW4B0xSlDuC6tiGI+3703EI2QC6mD+uYQrGY eea5YbypNHz+/doyQEuzSXwTVAUyUm30zuGa81KcfAOMoNLSucC1qI7Qo1bRI5vsxxvq yMnpggdOfTC7rXa0hTQVHI+VYEJ9vQMAG7NNQMJ+6prt3PpGf6zSdePihfXuA2uSoavU yFQw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from; bh=T4DCc4NW/i4vV0ABcOUcrGJuR1+DJ6VdpzyfQXZYJPQ=; b=qJ+Owk+qWqK9CPOp7cAl7+fDxmhJLPAoN1J21OCvewNi8RxNNL98uPCw9r1VtCQxLT yFPNv1UzNa8B5cTiffQXTka22auj43plQFyZGPqXnEjjcK7y99soOXYM991+paXeGfKa xpA99JkZR2oEwVM1antbUoJa5Ea6aeIDbVp/G92YkFfnCvwtUblW6UK5Zkq9qzmiPh5m a114RfbYx4KvjD40J9a0UtwXuQEG26XUGICU0Co4yUUa9DGTuYROO995wwBylh8GHJwL IlNFqkRhFxh45dOx5uvOw1cNCCZ9udZJh1nsVp+qOu5pGSHu3jCnAC4wN6wzuh9k4r4G 692w== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=alibaba.com Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id d92-20020a17090a6f6500b00256ae6cfd31si384538pjk.101.2023.05.31.20.15.32; Wed, 31 May 2023 20:15:43 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=alibaba.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231304AbjFACoO (ORCPT + 99 others); Wed, 31 May 2023 22:44:14 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:33350 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231231AbjFACoF (ORCPT ); Wed, 31 May 2023 22:44:05 -0400 Received: from out30-130.freemail.mail.aliyun.com (out30-130.freemail.mail.aliyun.com [115.124.30.130]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id AC0BE128 for ; Wed, 31 May 2023 19:43:56 -0700 (PDT) X-Alimail-AntiSpam: AC=PASS;BC=-1|-1;BR=01201311R571e4;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_---0VjzsOKZ_1685587433; Received: from localhost(mailfrom:jefflexu@linux.alibaba.com fp:SMTPD_---0VjzsOKZ_1685587433) by smtp.aliyun-inc.com; Thu, 01 Jun 2023 10:43:54 +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 5/6] erofs: unify inline/share xattr iterators for listxattr/getxattr Date: Thu, 1 Jun 2023 10:43:46 +0800 Message-Id: <20230601024347.108469-6-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 X-Spam-Status: No, score=-9.9 required=5.0 tests=BAYES_00, ENV_AND_HDR_SPF_MATCH,RCVD_IN_DNSWL_NONE,SPF_HELO_NONE,SPF_PASS, T_SCC_BODY_TEXT_LINE,UNPARSEABLE_RELAY,USER_IN_DEF_SPF_WL autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1767468531815868989?= X-GMAIL-MSGID: =?utf-8?q?1767468531815868989?= Make inline_getxattr() and inline_listxattr() unified as iter_inline_xattr(), shared_getxattr() and shared_listxattr() unified as iter_shared_xattr(). After the unification, both iter_inline_xattr() and iter_shared_xattr() return 0 on success, and negative error on failure. One thing worth noting is that, the logic of returning it->buffer_ofs when there's no shared xattrs in shared_listxattr() is moved to erofs_listxattr() to make the unification possible. The only difference is that, semantically the old behavior will return ENOATTR rather than it->buffer_ofs if ENOATTR encountered when listxattr is parsing upon a specific shared xattr, while now the new behavior will return it->buffer_ofs in this case. This is not an issue, as listxattr upon a specific xattr won't return ENOATTR. Signed-off-by: Jingbo Xu --- fs/erofs/xattr.c | 209 ++++++++++++++++++----------------------------- 1 file changed, 78 insertions(+), 131 deletions(-) diff --git a/fs/erofs/xattr.c b/fs/erofs/xattr.c index 19f9bf67440c..64180e83a63e 100644 --- a/fs/erofs/xattr.c +++ b/fs/erofs/xattr.c @@ -7,19 +7,6 @@ #include #include "xattr.h" -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 erofs_xattr_iter { struct super_block *sb; struct erofs_buf buf; @@ -171,29 +158,6 @@ struct xattr_iter_handlers { unsigned int len); }; -static int inline_xattr_iter_begin(struct erofs_xattr_iter *it, - struct inode *inode) -{ - struct erofs_inode *const vi = EROFS_I(inode); - unsigned int xattr_header_sz, inline_xattr_ofs; - - xattr_header_sz = sizeof(struct erofs_xattr_ibody_header) + - sizeof(u32) * vi->xattr_shared_count; - if (xattr_header_sz >= vi->xattr_isize) { - DBG_BUGON(xattr_header_sz > vi->xattr_isize); - return -ENOATTR; - } - - inline_xattr_ofs = vi->inode_isize + xattr_header_sz; - - it->blkaddr = erofs_blknr(it->sb, erofs_iloc(inode) + inline_xattr_ofs); - it->ofs = erofs_blkoff(it->sb, erofs_iloc(inode) + inline_xattr_ofs); - it->kaddr = erofs_bread(&it->buf, it->blkaddr, EROFS_KMAP); - if (IS_ERR(it->kaddr)) - return PTR_ERR(it->kaddr); - return vi->xattr_isize - xattr_header_sz; -} - /* * Regardless of success or failure, `xattr_foreach' will end up with * `ofs' pointing to the next xattr item rather than an arbitrary position. @@ -355,46 +319,6 @@ static const struct xattr_iter_handlers find_xattr_handlers = { .value = xattr_copyvalue }; -static int inline_getxattr(struct inode *inode, struct erofs_xattr_iter *it) -{ - int ret; - unsigned int remaining; - - ret = inline_xattr_iter_begin(it, inode); - if (ret < 0) - return ret; - - remaining = ret; - while (remaining) { - ret = xattr_foreach(it, &find_xattr_handlers, &remaining); - if (ret != -ENOATTR) - break; - } - return ret ? ret : it->buffer_ofs; -} - -static int shared_getxattr(struct inode *inode, struct erofs_xattr_iter *it) -{ - struct erofs_inode *const vi = EROFS_I(inode); - struct super_block *const sb = it->sb; - unsigned int i, xsid; - int ret = -ENOATTR; - - for (i = 0; i < vi->xattr_shared_count; ++i) { - xsid = vi->xattr_shared_xattrs[i]; - it->blkaddr = erofs_xattr_blkaddr(sb, xsid); - it->ofs = erofs_xattr_blkoff(sb, xsid); - it->kaddr = erofs_bread(&it->buf, it->blkaddr, EROFS_KMAP); - if (IS_ERR(it->kaddr)) - return PTR_ERR(it->kaddr); - - ret = xattr_foreach(it, &find_xattr_handlers, NULL); - if (ret != -ENOATTR) - break; - } - return ret ? ret : it->buffer_ofs; -} - static bool erofs_xattr_user_list(struct dentry *dentry) { return test_opt(&EROFS_SB(dentry->d_sb)->opt, XATTR_USER); @@ -405,39 +329,6 @@ static bool erofs_xattr_trusted_list(struct dentry *dentry) return capable(CAP_SYS_ADMIN); } -int erofs_getxattr(struct inode *inode, int index, - const char *name, - void *buffer, size_t buffer_size) -{ - int ret; - struct erofs_xattr_iter it; - - if (!name) - return -EINVAL; - - ret = erofs_init_inode_xattrs(inode); - if (ret) - return ret; - - it.index = index; - it.name = (struct qstr)QSTR_INIT(name, strlen(name)); - if (it.name.len > EROFS_NAME_LEN) - return -ERANGE; - - it.sb = inode->i_sb; - it.buf = __EROFS_BUF_INITIALIZER; - erofs_init_metabuf(&it.buf, it.sb); - it.buffer = buffer; - it.buffer_size = buffer_size; - it.buffer_ofs = 0; - - ret = inline_getxattr(inode, &it); - if (ret == -ENOATTR) - ret = shared_getxattr(inode, &it); - erofs_put_metabuf(&it.buf); - return ret; -} - static int erofs_xattr_generic_get(const struct xattr_handler *handler, struct dentry *unused, struct inode *inode, const char *name, void *buffer, size_t size) @@ -542,45 +433,98 @@ static const struct xattr_iter_handlers list_xattr_handlers = { .value = NULL }; -static int inline_listxattr(struct erofs_xattr_iter *it) +static int erofs_iter_inline_xattr(struct erofs_xattr_iter *it, + struct inode *inode, bool getxattr) { + struct erofs_inode *const vi = EROFS_I(inode); + const struct xattr_iter_handlers *op; + unsigned int xattr_header_sz, remaining; + erofs_off_t pos; int ret; - unsigned int remaining; - ret = inline_xattr_iter_begin(it, d_inode(it->dentry)); - if (ret < 0) - return ret; + xattr_header_sz = sizeof(struct erofs_xattr_ibody_header) + + sizeof(u32) * vi->xattr_shared_count; + if (xattr_header_sz >= vi->xattr_isize) { + DBG_BUGON(xattr_header_sz > vi->xattr_isize); + return -ENOATTR; + } + + pos = erofs_iloc(inode) + vi->inode_isize + xattr_header_sz; + it->blkaddr = erofs_blknr(it->sb, pos); + it->ofs = erofs_blkoff(it->sb, pos); + it->kaddr = erofs_read_metabuf(&it->buf, it->sb, it->blkaddr, EROFS_KMAP); + if (IS_ERR(it->kaddr)) + return PTR_ERR(it->kaddr); + + remaining = vi->xattr_isize - xattr_header_sz; + op = getxattr ? &find_xattr_handlers : &list_xattr_handlers; - remaining = ret; while (remaining) { - ret = xattr_foreach(it, &list_xattr_handlers, &remaining); - if (ret) + ret = xattr_foreach(it, op, &remaining); + if ((getxattr && ret != -ENOATTR) || (!getxattr && ret)) break; } - return ret ? ret : it->buffer_ofs; + return ret; } -static int shared_listxattr(struct erofs_xattr_iter *it) +static int erofs_iter_shared_xattr(struct erofs_xattr_iter *it, + struct inode *inode, bool getxattr) { - struct inode *const inode = d_inode(it->dentry); struct erofs_inode *const vi = EROFS_I(inode); struct super_block *const sb = it->sb; + const struct xattr_iter_handlers *op; unsigned int i, xsid; - int ret = 0; + int ret = -ENOATTR; + + op = getxattr ? &find_xattr_handlers : &list_xattr_handlers; for (i = 0; i < vi->xattr_shared_count; ++i) { xsid = vi->xattr_shared_xattrs[i]; - it->blkaddr = erofs_xattr_blkaddr(sb, xsid); - it->ofs = erofs_xattr_blkoff(sb, xsid); + it->blkaddr = EROFS_SB(sb)->xattr_blkaddr + + erofs_blknr(sb, xsid * sizeof(__u32)); + it->ofs = erofs_blkoff(sb, xsid * sizeof(__u32)); it->kaddr = erofs_bread(&it->buf, it->blkaddr, EROFS_KMAP); if (IS_ERR(it->kaddr)) return PTR_ERR(it->kaddr); - ret = xattr_foreach(it, &list_xattr_handlers, NULL); - if (ret) + ret = xattr_foreach(it, op, NULL); + if ((getxattr && ret != -ENOATTR) || (!getxattr && ret)) break; } - return ret ? ret : it->buffer_ofs; + return ret; +} + +int erofs_getxattr(struct inode *inode, int index, + const char *name, + void *buffer, size_t buffer_size) +{ + int ret; + struct erofs_xattr_iter it; + + if (!name) + return -EINVAL; + + ret = erofs_init_inode_xattrs(inode); + if (ret) + return ret; + + it.index = index; + it.name = (struct qstr)QSTR_INIT(name, strlen(name)); + if (it.name.len > EROFS_NAME_LEN) + return -ERANGE; + + it.sb = inode->i_sb; + it.buf = __EROFS_BUF_INITIALIZER; + erofs_init_metabuf(&it.buf, it.sb); + it.buffer = buffer; + it.buffer_size = buffer_size; + it.buffer_ofs = 0; + + ret = erofs_iter_inline_xattr(&it, inode, true); + if (ret == -ENOATTR) + ret = erofs_iter_shared_xattr(&it, inode, true); + erofs_put_metabuf(&it.buf); + return ret ? ret : it.buffer_ofs; } ssize_t erofs_listxattr(struct dentry *dentry, @@ -588,8 +532,9 @@ ssize_t erofs_listxattr(struct dentry *dentry, { int ret; struct erofs_xattr_iter it; + struct inode *inode = d_inode(dentry); - ret = erofs_init_inode_xattrs(d_inode(dentry)); + ret = erofs_init_inode_xattrs(inode); if (ret == -ENOATTR) return 0; if (ret) @@ -603,11 +548,13 @@ ssize_t erofs_listxattr(struct dentry *dentry, it.buffer_size = buffer_size; it.buffer_ofs = 0; - ret = inline_listxattr(&it); - if (ret >= 0 || ret == -ENOATTR) - ret = shared_listxattr(&it); + ret = erofs_iter_inline_xattr(&it, inode, false); + if (!ret || ret == -ENOATTR) + ret = erofs_iter_shared_xattr(&it, inode, false); + if (ret == -ENOATTR) + ret = 0; erofs_put_metabuf(&it.buf); - return ret; + return ret ? ret : it.buffer_ofs; } void erofs_xattr_prefixes_cleanup(struct super_block *sb) From patchwork Thu Jun 1 02:43:47 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jingbo Xu X-Patchwork-Id: 101667 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:994d:0:b0:3d9:f83d:47d9 with SMTP id k13csp15331vqr; Wed, 31 May 2023 20:04:20 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ7iGBUXW/swG4Qeqbab7RPIpizxFkhAm8OJVeBh8FMN5A4DwUxDXnI/V3Q2YR54hRsphYci X-Received: by 2002:a17:902:8341:b0:1b1:9d43:ad4a with SMTP id z1-20020a170902834100b001b19d43ad4amr145597pln.44.1685588659922; Wed, 31 May 2023 20:04:19 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1685588659; cv=none; d=google.com; s=arc-20160816; b=Qjrvqsvh1/6rPjIhUysukRfikll0FKNuhx1/wLApcMEqmx3vzOlqpffcL4hmJZxyLG jt1cRyMztYhEQqS1irsjElLQZeiAAZiqltrkEzDv1bF4noS8A4o73CPhyd6+Kns1ldjf YFNCD2hRwFf8J4T/oxuAGoj0+V5GPP2YkIDBFX1Vexr9ySOYIp9BcFPhItXPFibn7kV3 niX9DYYtTEZWsZvbqyU+3TJe67FdhpPyGg4WFfhzJiWrN8jiGYhK1gXapkkzF1HWqSML 2ivPWOlOj/UCFnp8A/49VtxzFQl+yl48Xe4c8hZ3424sI5U5mH+cc/twuXl7L9ZYXEbu 5bMQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from; bh=empQeI+ChgmShHIfK+YGozbxcZuXGo8F8GxLFPgU7r0=; b=LtHXoEsnirFkVKxlrui48qeigHsEbf7wVWoqAQhYjy0WBLaxdVko+0Qd2w7jTUH80S BTxY5EnXsip85/qZZa8rj2PX4WiQmftjlANV6NyRRaaVlfmWe4g+WSdF/UKrCS5WHwTl CVsq9DLVDGa0xg7OkrzGpmVxAAJE+e4/FTzC33tPe1FqHiWnja+VISkG7KBNWymp8nAG vRbfOJMeCIksqwdpzPPWxWu3Hwf+b+YZ6+coWAAg1SUeSg5qPrBwBcFpzCIMNM9ALfK4 HwHn/M18JJDpTdBHu188T9YF8odZH1k/HFXeaCe5BA9kkYg2XEF5hObgSnvbdb2C6UD9 a8CA== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=alibaba.com Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id u10-20020a17090341ca00b001b04c773ce2si2067473ple.541.2023.05.31.20.04.07; Wed, 31 May 2023 20:04:19 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=alibaba.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231237AbjFACoR (ORCPT + 99 others); Wed, 31 May 2023 22:44:17 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:33198 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231241AbjFACoF (ORCPT ); Wed, 31 May 2023 22:44:05 -0400 Received: from out30-97.freemail.mail.aliyun.com (out30-97.freemail.mail.aliyun.com [115.124.30.97]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id F2F42137 for ; Wed, 31 May 2023 19:43:57 -0700 (PDT) X-Alimail-AntiSpam: AC=PASS;BC=-1|-1;BR=01201311R121e4;CH=green;DM=||false|;DS=||;FP=0|-1|-1|-1|0|-1|-1|-1;HT=ay29a033018045168;MF=jefflexu@linux.alibaba.com;NM=1;PH=DS;RN=5;SR=0;TI=SMTPD_---0VjzsOLE_1685587434; Received: from localhost(mailfrom:jefflexu@linux.alibaba.com fp:SMTPD_---0VjzsOLE_1685587434) by smtp.aliyun-inc.com; Thu, 01 Jun 2023 10:43:55 +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 6/6] erofs: use separate xattr parsers for listxattr/getxattr Date: Thu, 1 Jun 2023 10:43:47 +0800 Message-Id: <20230601024347.108469-7-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 X-Spam-Status: No, score=-9.9 required=5.0 tests=BAYES_00, ENV_AND_HDR_SPF_MATCH,RCVD_IN_DNSWL_NONE,SPF_HELO_NONE,SPF_PASS, T_SCC_BODY_TEXT_LINE,UNPARSEABLE_RELAY,USER_IN_DEF_SPF_WL autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1767467814834845565?= X-GMAIL-MSGID: =?utf-8?q?1767467814834845565?= There's a callback styled xattr parser, i.e. xattr_foreach(), which is shared among listxattr and getxattr. Convert it to two separate xattr parsers for listxattr and getxattr. Signed-off-by: Jingbo Xu --- fs/erofs/xattr.c | 359 +++++++++++++++++++---------------------------- 1 file changed, 142 insertions(+), 217 deletions(-) diff --git a/fs/erofs/xattr.c b/fs/erofs/xattr.c index 64180e83a63e..1b65e74cb4a0 100644 --- a/fs/erofs/xattr.c +++ b/fs/erofs/xattr.c @@ -12,7 +12,7 @@ struct erofs_xattr_iter { struct erofs_buf buf; void *kaddr; erofs_blk_t blkaddr; - unsigned int ofs; + unsigned int ofs, next_ofs; char *buffer; int buffer_size, buffer_ofs; @@ -142,183 +142,6 @@ static int erofs_init_inode_xattrs(struct inode *inode) return ret; } -/* - * the general idea for these return values is - * if 0 is returned, go on processing the current xattr; - * 1 (> 0) is returned, skip this round to process the next xattr; - * -err (< 0) is returned, an error (maybe ENOXATTR) occurred - * and need to be handled - */ -struct xattr_iter_handlers { - int (*entry)(struct erofs_xattr_iter *it, struct erofs_xattr_entry *entry); - int (*name)(struct erofs_xattr_iter *it, unsigned int processed, char *buf, - unsigned int len); - int (*alloc_buffer)(struct erofs_xattr_iter *it, unsigned int value_sz); - void (*value)(struct erofs_xattr_iter *it, unsigned int processed, char *buf, - unsigned int len); -}; - -/* - * Regardless of success or failure, `xattr_foreach' will end up with - * `ofs' pointing to the next xattr item rather than an arbitrary position. - */ -static int xattr_foreach(struct erofs_xattr_iter *it, - const struct xattr_iter_handlers *op, - unsigned int *tlimit) -{ - struct erofs_xattr_entry entry; - unsigned int value_sz, processed, slice; - int err; - - /* 0. fixup blkaddr, ofs, ipage */ - err = erofs_xattr_iter_fixup(it, false); - if (err) - return err; - - /* - * 1. read xattr entry to the memory, - * since we do EROFS_XATTR_ALIGN - * therefore entry should be in the page - */ - entry = *(struct erofs_xattr_entry *)(it->kaddr + it->ofs); - if (tlimit) { - unsigned int entry_sz = erofs_xattr_entry_size(&entry); - - /* xattr on-disk corruption: xattr entry beyond xattr_isize */ - if (*tlimit < entry_sz) { - DBG_BUGON(1); - return -EFSCORRUPTED; - } - *tlimit -= entry_sz; - } - - it->ofs += sizeof(struct erofs_xattr_entry); - value_sz = le16_to_cpu(entry.e_value_size); - - /* handle entry */ - err = op->entry(it, &entry); - if (err) { - it->ofs += entry.e_name_len + value_sz; - goto out; - } - - /* 2. handle xattr name (ofs will finally be at the end of name) */ - processed = 0; - - while (processed < entry.e_name_len) { - err = erofs_xattr_iter_fixup(it, true); - if (err) - goto out; - - slice = min_t(unsigned int, it->sb->s_blocksize - it->ofs, - entry.e_name_len - processed); - - /* handle name */ - err = op->name(it, processed, it->kaddr + it->ofs, slice); - if (err) { - it->ofs += entry.e_name_len - processed + value_sz; - goto out; - } - - it->ofs += slice; - processed += slice; - } - - /* 3. handle xattr value */ - processed = 0; - - if (op->alloc_buffer) { - err = op->alloc_buffer(it, value_sz); - if (err) { - it->ofs += value_sz; - goto out; - } - } - - while (processed < value_sz) { - err = erofs_xattr_iter_fixup(it, true); - if (err) - goto out; - - slice = min_t(unsigned int, it->sb->s_blocksize - it->ofs, - value_sz - processed); - op->value(it, processed, it->kaddr + it->ofs, slice); - it->ofs += slice; - processed += slice; - } - -out: - /* xattrs should be 4-byte aligned (on-disk constraint) */ - it->ofs = EROFS_XATTR_ALIGN(it->ofs); - return err < 0 ? err : 0; -} - -static int erofs_xattr_long_entrymatch(struct erofs_xattr_iter *it, - struct erofs_xattr_entry *entry) -{ - struct erofs_sb_info *sbi = EROFS_SB(it->sb); - struct erofs_xattr_prefix_item *pf = sbi->xattr_prefixes + - (entry->e_name_index & EROFS_XATTR_LONG_PREFIX_MASK); - - if (pf >= sbi->xattr_prefixes + sbi->xattr_prefix_count) - return -ENOATTR; - - if (it->index != pf->prefix->base_index || - it->name.len != entry->e_name_len + pf->infix_len) - return -ENOATTR; - - if (memcmp(it->name.name, pf->prefix->infix, pf->infix_len)) - return -ENOATTR; - - it->infix_len = pf->infix_len; - return 0; -} - -static int xattr_entrymatch(struct erofs_xattr_iter *it, - struct erofs_xattr_entry *entry) -{ - /* should also match the infix for long name prefixes */ - if (entry->e_name_index & EROFS_XATTR_LONG_PREFIX) - return erofs_xattr_long_entrymatch(it, entry); - - if (it->index != entry->e_name_index || - it->name.len != entry->e_name_len) - return -ENOATTR; - it->infix_len = 0; - return 0; -} - -static int xattr_namematch(struct erofs_xattr_iter *it, - unsigned int processed, char *buf, unsigned int len) -{ - if (memcmp(buf, it->name.name + it->infix_len + processed, len)) - return -ENOATTR; - return 0; -} - -static int xattr_checkbuffer(struct erofs_xattr_iter *it, - unsigned int value_sz) -{ - int err = it->buffer_size < value_sz ? -ERANGE : 0; - - it->buffer_ofs = value_sz; - return !it->buffer ? 1 : err; -} - -static void xattr_copyvalue(struct erofs_xattr_iter *it, - unsigned int processed, - char *buf, unsigned int len) -{ - memcpy(it->buffer + processed, buf, len); -} - -static const struct xattr_iter_handlers find_xattr_handlers = { - .entry = xattr_entrymatch, - .name = xattr_namematch, - .alloc_buffer = xattr_checkbuffer, - .value = xattr_copyvalue -}; - static bool erofs_xattr_user_list(struct dentry *dentry) { return test_opt(&EROFS_SB(dentry->d_sb)->opt, XATTR_USER); @@ -371,20 +194,57 @@ const struct xattr_handler *erofs_xattr_handlers[] = { NULL, }; -static int xattr_entrylist(struct erofs_xattr_iter *it, - struct erofs_xattr_entry *entry) +static int erofs_xattr_body(struct erofs_xattr_iter *it, + unsigned int len, bool copy) { - unsigned int base_index = entry->e_name_index; - unsigned int prefix_len, infix_len = 0; + unsigned int slice, processed = 0; + void *buf; + int err; + + while (processed < len) { + err = erofs_xattr_iter_fixup(it, true); + if (err) + return err; + + buf = it->kaddr + it->ofs; + slice = min_t(unsigned int, it->sb->s_blocksize - it->ofs, + len - processed); + if (copy) { + memcpy(it->buffer + it->buffer_ofs, buf, slice); + it->buffer_ofs += slice; + } else if (memcmp(it->name.name + it->infix_len + processed, + buf, slice)) { + return -ENOATTR; + } + it->ofs += slice; + processed += slice; + } + return 0; +} + +/* + * Wen returning 0 or ENOATTR, erofs_[list|get]xattr_foreach() will end up + * with `ofs' pointing to the next xattr item rather than an arbitrary position. + */ +static int erofs_listxattr_foreach(struct erofs_xattr_iter *it) +{ + struct erofs_xattr_entry entry; + unsigned int base_index, prefix_len, infix_len = 0; const char *prefix, *infix = NULL; + int err; - if (entry->e_name_index & EROFS_XATTR_LONG_PREFIX) { + /* 1. handle xattr entry */ + entry = *(struct erofs_xattr_entry *)(it->kaddr + it->ofs); + it->ofs += sizeof(struct erofs_xattr_entry); + base_index = entry.e_name_index; + + if (entry.e_name_index & EROFS_XATTR_LONG_PREFIX) { struct erofs_sb_info *sbi = EROFS_SB(it->sb); struct erofs_xattr_prefix_item *pf = sbi->xattr_prefixes + - (entry->e_name_index & EROFS_XATTR_LONG_PREFIX_MASK); + (entry.e_name_index & EROFS_XATTR_LONG_PREFIX_MASK); if (pf >= sbi->xattr_prefixes + sbi->xattr_prefix_count) - return 1; + goto out; infix = pf->prefix->infix; infix_len = pf->infix_len; base_index = pf->prefix->base_index; @@ -392,53 +252,99 @@ static int xattr_entrylist(struct erofs_xattr_iter *it, prefix = erofs_xattr_prefix(base_index, it->dentry); if (!prefix) - return 1; + goto out; prefix_len = strlen(prefix); if (!it->buffer) { - it->buffer_ofs += prefix_len + infix_len + - entry->e_name_len + 1; - return 1; + it->buffer_ofs += prefix_len + infix_len + entry.e_name_len + 1; + goto out; } if (it->buffer_ofs + prefix_len + infix_len + - + entry->e_name_len + 1 > it->buffer_size) + entry.e_name_len + 1 > it->buffer_size) return -ERANGE; memcpy(it->buffer + it->buffer_ofs, prefix, prefix_len); memcpy(it->buffer + it->buffer_ofs + prefix_len, infix, infix_len); it->buffer_ofs += prefix_len + infix_len; - return 0; -} -static int xattr_namelist(struct erofs_xattr_iter *it, - unsigned int processed, char *buf, unsigned int len) -{ - memcpy(it->buffer + it->buffer_ofs, buf, len); - it->buffer_ofs += len; + /* 2. handle xattr name (err can't be ENOATTR) */ + err = erofs_xattr_body(it, entry.e_name_len, true); + if (err) + return err; + + it->buffer[it->buffer_ofs++] = '\0'; + it->ofs += le16_to_cpu(entry.e_value_size); + it->ofs = EROFS_XATTR_ALIGN(it->ofs); + return 0; +out: + it->ofs = it->next_ofs; return 0; } -static int xattr_skipvalue(struct erofs_xattr_iter *it, - unsigned int value_sz) +static int erofs_getxattr_foreach(struct erofs_xattr_iter *it) { - it->buffer[it->buffer_ofs++] = '\0'; - return 1; -} + struct erofs_xattr_entry entry; + unsigned int value_sz; + int err; -static const struct xattr_iter_handlers list_xattr_handlers = { - .entry = xattr_entrylist, - .name = xattr_namelist, - .alloc_buffer = xattr_skipvalue, - .value = NULL -}; + /* 1. handle xattr entry */ + entry = *(struct erofs_xattr_entry *)(it->kaddr + it->ofs); + it->ofs += sizeof(struct erofs_xattr_entry); + value_sz = le16_to_cpu(entry.e_value_size); + + err = -ENOATTR; + /* should also match the infix for long name prefixes */ + if (entry.e_name_index & EROFS_XATTR_LONG_PREFIX) { + struct erofs_sb_info *sbi = EROFS_SB(it->sb); + struct erofs_xattr_prefix_item *pf = sbi->xattr_prefixes + + (entry.e_name_index & EROFS_XATTR_LONG_PREFIX_MASK); + + if (pf >= sbi->xattr_prefixes + sbi->xattr_prefix_count) + goto out; + + if (it->index != pf->prefix->base_index || + it->name.len != entry.e_name_len + pf->infix_len) + goto out; + + if (memcmp(it->name.name, pf->prefix->infix, pf->infix_len)) + goto out; + + it->infix_len = pf->infix_len; + } else { + if (it->index != entry.e_name_index || + it->name.len != entry.e_name_len) + goto out; + it->infix_len = 0; + } + + /* 2. handle xattr name */ + err = erofs_xattr_body(it, entry.e_name_len, false); + if (err) + goto out; + + /* 3. handle xattr value */ + if (!it->buffer) { + it->buffer_ofs = value_sz; + goto out; /* err == 0 */ + } + if (it->buffer_size < value_sz) + return -ERANGE; + + /* no need normalizing ofs on error (err can't be ENOATTR) */ + err = erofs_xattr_body(it, value_sz, true); + it->ofs = EROFS_XATTR_ALIGN(it->ofs); + return err; +out: + it->ofs = it->next_ofs; + return err; +} static int erofs_iter_inline_xattr(struct erofs_xattr_iter *it, struct inode *inode, bool getxattr) { struct erofs_inode *const vi = EROFS_I(inode); - const struct xattr_iter_handlers *op; - unsigned int xattr_header_sz, remaining; + unsigned int xattr_header_sz, remaining, entry_sz; erofs_off_t pos; int ret; @@ -457,10 +363,24 @@ static int erofs_iter_inline_xattr(struct erofs_xattr_iter *it, return PTR_ERR(it->kaddr); remaining = vi->xattr_isize - xattr_header_sz; - op = getxattr ? &find_xattr_handlers : &list_xattr_handlers; - while (remaining) { - ret = xattr_foreach(it, op, &remaining); + ret = erofs_xattr_iter_fixup(it, false); + if (ret) + return ret; + + entry_sz = erofs_xattr_entry_size(it->kaddr + it->ofs); + /* xattr on-disk corruption: xattr entry beyond xattr_isize */ + if (remaining < entry_sz) { + DBG_BUGON(1); + return -EFSCORRUPTED; + } + remaining -= entry_sz; + it->next_ofs = it->ofs + entry_sz; + + if (getxattr) + ret = erofs_getxattr_foreach(it); + else + ret = erofs_listxattr_foreach(it); if ((getxattr && ret != -ENOATTR) || (!getxattr && ret)) break; } @@ -472,12 +392,9 @@ static int erofs_iter_shared_xattr(struct erofs_xattr_iter *it, { struct erofs_inode *const vi = EROFS_I(inode); struct super_block *const sb = it->sb; - const struct xattr_iter_handlers *op; unsigned int i, xsid; int ret = -ENOATTR; - op = getxattr ? &find_xattr_handlers : &list_xattr_handlers; - for (i = 0; i < vi->xattr_shared_count; ++i) { xsid = vi->xattr_shared_xattrs[i]; it->blkaddr = EROFS_SB(sb)->xattr_blkaddr + @@ -487,7 +404,15 @@ static int erofs_iter_shared_xattr(struct erofs_xattr_iter *it, if (IS_ERR(it->kaddr)) return PTR_ERR(it->kaddr); - ret = xattr_foreach(it, op, NULL); + ret = erofs_xattr_iter_fixup(it, false); + if (ret) + return ret; + it->next_ofs = it->ofs + erofs_xattr_entry_size(it->kaddr + it->ofs); + + if (getxattr) + ret = erofs_getxattr_foreach(it); + else + ret = erofs_listxattr_foreach(it); if ((getxattr && ret != -ENOATTR) || (!getxattr && ret)) break; }