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; }