From patchwork Fri Apr 7 14:17:04 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jingbo Xu X-Patchwork-Id: 80859 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:b0ea:0:b0:3b6:4342:cba0 with SMTP id b10csp332574vqo; Fri, 7 Apr 2023 07:42:08 -0700 (PDT) X-Google-Smtp-Source: AKy350bmACfYv9Xe4WnKPqe+jbmc4UgiQQ4WG8ZhWvRNZyF1oxCwvNK+eMmA1OIwLZ5JglRxCVIX X-Received: by 2002:a17:902:cec5:b0:19e:ad18:da5c with SMTP id d5-20020a170902cec500b0019ead18da5cmr4051060plg.37.1680878528585; Fri, 07 Apr 2023 07:42:08 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1680878528; cv=none; d=google.com; s=arc-20160816; b=PUndniL7jhXW1tvZT68MfJo9jPMuOXNmt05+pfaqq0WB7XAX/gdKpFZ8jfbb6WKJVt MmWZpna6EVtHMvuUXfuPD8NtoQ0M30aNGrA0YVKTByp/OEWR303bgJrSd1RAAesdWXDX yaZbTO0ORKlyEbSGTIeRHcqnv0DU0bWspK/udZkM15hXvfU4KdrKm1e6CiC1/IkU7nbG o1viVjMfxC5bEZrl/yR/KfeaxBEj2t/DrAfj0cdq6CHDJS/B2LVsbe1aXpgXeflRVMHQ uskBT9PVNpU8EY21H21BMqulrfQZ+mi3ISa9fhn1MKAUpCjCoobeWT0aTaU8D5Gzi09K +oyw== 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=aHwc9g/r0cUD76i+PG8P6fzNCeQGhyb06ApWSBlCmN0=; b=aAsSvf7Qb+C/vNbYrkMRPFXPYcsec6I5p3HLjNybNGa6bWM5BeNhABZx4L08Qhiegs +46V4LmsI11p1160GW+vJtGf8vfuLnlrbj00QIdwW6eVKKx0QOAs9+Z/787BUagERMlq qLCa/GUdx85RZ4L1cCQfGQG328l79NgU3v+R3rr/2/CwqDvahBOAffftwEEwGyTuYkHO 7+oQkHiL1n+/qLzvFKebMyLhXxVwkorf39cQ7cu3RMB3Cu0yFl6+CgR1a9GTaVqmSU1Q STOeeJn9gSCeXtxPy2TU/S9rbJVs/Z7Hw6bdEQaYqSxBywqP5SdccdDb9tnBR0VZ1Pks 71Kg== 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 n9-20020a170902d2c900b001a199eaf57csi4200545plc.404.2023.04.07.07.41.55; Fri, 07 Apr 2023 07:42:08 -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 S232912AbjDGORY (ORCPT + 99 others); Fri, 7 Apr 2023 10:17:24 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:36636 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230082AbjDGORS (ORCPT ); Fri, 7 Apr 2023 10:17:18 -0400 Received: from out30-98.freemail.mail.aliyun.com (out30-98.freemail.mail.aliyun.com [115.124.30.98]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id B7D4A6EB5 for ; Fri, 7 Apr 2023 07:17:15 -0700 (PDT) X-Alimail-AntiSpam: AC=PASS;BC=-1|-1;BR=01201311R671e4;CH=green;DM=||false|;DS=||;FP=0|-1|-1|-1|0|-1|-1|-1;HT=ay29a033018045176;MF=jefflexu@linux.alibaba.com;NM=1;PH=DS;RN=5;SR=0;TI=SMTPD_---0VfX2QQC_1680877032; Received: from localhost(mailfrom:jefflexu@linux.alibaba.com fp:SMTPD_---0VfX2QQC_1680877032) by smtp.aliyun-inc.com; Fri, 07 Apr 2023 22:17:12 +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 1/7] erofs: keep meta inode into erofs_buf Date: Fri, 7 Apr 2023 22:17:04 +0800 Message-Id: <20230407141710.113882-2-jefflexu@linux.alibaba.com> X-Mailer: git-send-email 2.19.1.6.gb485710b In-Reply-To: <20230407141710.113882-1-jefflexu@linux.alibaba.com> References: <20230407141710.113882-1-jefflexu@linux.alibaba.com> MIME-Version: 1.0 X-Spam-Status: No, score=-8.0 required=5.0 tests=ENV_AND_HDR_SPF_MATCH, RCVD_IN_DNSWL_NONE,RCVD_IN_MSPIKE_H2,SPF_HELO_NONE,SPF_PASS, UNPARSEABLE_RELAY,USER_IN_DEF_SPF_WL autolearn=unavailable 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?1762528884157108545?= X-GMAIL-MSGID: =?utf-8?q?1762528884157108545?= From: Gao Xiang So that erofs_read_metadata() can read metadata from other inodes (e.g. packed inode) as well. Signed-off-by: Gao Xiang --- fs/erofs/data.c | 23 ++++++++++++++--------- fs/erofs/dir.c | 3 ++- fs/erofs/internal.h | 6 ++++-- fs/erofs/namei.c | 4 +++- fs/erofs/super.c | 6 +++--- fs/erofs/zdata.c | 4 ++-- 6 files changed, 28 insertions(+), 18 deletions(-) diff --git a/fs/erofs/data.c b/fs/erofs/data.c index e5458b4c3d0c..aa7f9e4f86fb 100644 --- a/fs/erofs/data.c +++ b/fs/erofs/data.c @@ -31,11 +31,11 @@ void erofs_put_metabuf(struct erofs_buf *buf) * Derive the block size from inode->i_blkbits to make compatible with * anonymous inode in fscache mode. */ -void *erofs_bread(struct erofs_buf *buf, struct inode *inode, - erofs_blk_t blkaddr, enum erofs_kmap_type type) +void *erofs_bread(struct erofs_buf *buf, erofs_blk_t blkaddr, + enum erofs_kmap_type type) { + struct inode *inode = buf->inode; erofs_off_t offset = blkaddr << inode->i_blkbits; - struct address_space *const mapping = inode->i_mapping; pgoff_t index = offset >> PAGE_SHIFT; struct page *page = buf->page; struct folio *folio; @@ -45,7 +45,7 @@ void *erofs_bread(struct erofs_buf *buf, struct inode *inode, erofs_put_metabuf(buf); nofs_flag = memalloc_nofs_save(); - folio = read_cache_folio(mapping, index, NULL, NULL); + folio = read_cache_folio(inode->i_mapping, index, NULL, NULL); memalloc_nofs_restore(nofs_flag); if (IS_ERR(folio)) return folio; @@ -67,14 +67,19 @@ void *erofs_bread(struct erofs_buf *buf, struct inode *inode, return buf->base + (offset & ~PAGE_MASK); } -void *erofs_read_metabuf(struct erofs_buf *buf, struct super_block *sb, - erofs_blk_t blkaddr, enum erofs_kmap_type type) +void erofs_init_metabuf(struct erofs_buf *buf, struct super_block *sb) { if (erofs_is_fscache_mode(sb)) - return erofs_bread(buf, EROFS_SB(sb)->s_fscache->inode, - blkaddr, type); + buf->inode = EROFS_SB(sb)->s_fscache->inode; + else + buf->inode = sb->s_bdev->bd_inode; +} - return erofs_bread(buf, sb->s_bdev->bd_inode, blkaddr, type); +void *erofs_read_metabuf(struct erofs_buf *buf, struct super_block *sb, + erofs_blk_t blkaddr, enum erofs_kmap_type type) +{ + erofs_init_metabuf(buf, sb); + return erofs_bread(buf, blkaddr, type); } static int erofs_map_blocks_flatmode(struct inode *inode, diff --git a/fs/erofs/dir.c b/fs/erofs/dir.c index 963bbed0b699..b80abec0531a 100644 --- a/fs/erofs/dir.c +++ b/fs/erofs/dir.c @@ -58,11 +58,12 @@ static int erofs_readdir(struct file *f, struct dir_context *ctx) int err = 0; bool initial = true; + buf.inode = dir; while (ctx->pos < dirsize) { struct erofs_dirent *de; unsigned int nameoff, maxsize; - de = erofs_bread(&buf, dir, i, EROFS_KMAP); + de = erofs_bread(&buf, i, EROFS_KMAP); if (IS_ERR(de)) { erofs_err(sb, "fail to readdir of logical block %u of nid %llu", i, EROFS_I(dir)->nid); diff --git a/fs/erofs/internal.h b/fs/erofs/internal.h index e30a4fd43ccb..2bcff3194e4a 100644 --- a/fs/erofs/internal.h +++ b/fs/erofs/internal.h @@ -247,6 +247,7 @@ enum erofs_kmap_type { }; struct erofs_buf { + struct inode *inode; struct page *page; void *base; enum erofs_kmap_type kmap_type; @@ -440,8 +441,9 @@ extern const struct iomap_ops z_erofs_iomap_report_ops; void erofs_unmap_metabuf(struct erofs_buf *buf); void erofs_put_metabuf(struct erofs_buf *buf); -void *erofs_bread(struct erofs_buf *buf, struct inode *inode, - erofs_blk_t blkaddr, enum erofs_kmap_type type); +void *erofs_bread(struct erofs_buf *buf, erofs_blk_t blkaddr, + enum erofs_kmap_type type); +void erofs_init_metabuf(struct erofs_buf *buf, struct super_block *sb); void *erofs_read_metabuf(struct erofs_buf *buf, struct super_block *sb, erofs_blk_t blkaddr, enum erofs_kmap_type type); int erofs_map_dev(struct super_block *sb, struct erofs_map_dev *dev); diff --git a/fs/erofs/namei.c b/fs/erofs/namei.c index f091e9a0f0a1..43096bac4c99 100644 --- a/fs/erofs/namei.c +++ b/fs/erofs/namei.c @@ -99,7 +99,8 @@ static void *erofs_find_target_block(struct erofs_buf *target, struct erofs_buf buf = __EROFS_BUF_INITIALIZER; struct erofs_dirent *de; - de = erofs_bread(&buf, dir, mid, EROFS_KMAP); + buf.inode = dir; + de = erofs_bread(&buf, mid, EROFS_KMAP); if (!IS_ERR(de)) { const int nameoff = nameoff_from_disk(de->nameoff, bsz); const int ndirents = nameoff / sizeof(*de); @@ -170,6 +171,7 @@ int erofs_namei(struct inode *dir, const struct qstr *name, erofs_nid_t *nid, qn.name = name->name; qn.end = name->name + name->len; + buf.inode = dir; ndirents = 0; de = erofs_find_target_block(&buf, dir, &qn, &ndirents); diff --git a/fs/erofs/super.c b/fs/erofs/super.c index 9e56a6fb2267..58ffbf410bfb 100644 --- a/fs/erofs/super.c +++ b/fs/erofs/super.c @@ -135,7 +135,7 @@ static void *erofs_read_metadata(struct super_block *sb, struct erofs_buf *buf, int len, i, cnt; *offset = round_up(*offset, 4); - ptr = erofs_read_metabuf(buf, sb, erofs_blknr(sb, *offset), EROFS_KMAP); + ptr = erofs_bread(buf, erofs_blknr(sb, *offset), EROFS_KMAP); if (IS_ERR(ptr)) return ptr; @@ -151,8 +151,7 @@ static void *erofs_read_metadata(struct super_block *sb, struct erofs_buf *buf, for (i = 0; i < len; i += cnt) { cnt = min_t(int, sb->s_blocksize - erofs_blkoff(sb, *offset), len - i); - ptr = erofs_read_metabuf(buf, sb, erofs_blknr(sb, *offset), - EROFS_KMAP); + ptr = erofs_bread(buf, erofs_blknr(sb, *offset), EROFS_KMAP); if (IS_ERR(ptr)) { kfree(buffer); return ptr; @@ -179,6 +178,7 @@ static int erofs_load_compr_cfgs(struct super_block *sb, return -EINVAL; } + erofs_init_metabuf(&buf, sb); offset = EROFS_SUPER_OFFSET + sbi->sb_size; alg = 0; for (algs = sbi->available_compr_algs; algs; algs >>= 1, ++alg) { diff --git a/fs/erofs/zdata.c b/fs/erofs/zdata.c index a90d37c7bdd7..34944e400037 100644 --- a/fs/erofs/zdata.c +++ b/fs/erofs/zdata.c @@ -939,12 +939,12 @@ static int z_erofs_read_fragment(struct inode *inode, erofs_off_t pos, if (!packed_inode) return -EFSCORRUPTED; + buf.inode = packed_inode; pos += EROFS_I(inode)->z_fragmentoff; for (i = 0; i < len; i += cnt) { cnt = min_t(unsigned int, len - i, sb->s_blocksize - erofs_blkoff(sb, pos)); - src = erofs_bread(&buf, packed_inode, - erofs_blknr(sb, pos), EROFS_KMAP); + src = erofs_bread(&buf, erofs_blknr(sb, pos), EROFS_KMAP); if (IS_ERR(src)) { erofs_put_metabuf(&buf); return PTR_ERR(src); From patchwork Fri Apr 7 14:17:05 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jingbo Xu X-Patchwork-Id: 80861 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:b0ea:0:b0:3b6:4342:cba0 with SMTP id b10csp333517vqo; Fri, 7 Apr 2023 07:43:52 -0700 (PDT) X-Google-Smtp-Source: AKy350atA15VCljxAUvvrh1M1J7bGRHFIo1EdXSuwOxnPRfnMXII2BAdOsp2vgA9xHm0m3+xqi9m X-Received: by 2002:aa7:d992:0:b0:504:55b7:6207 with SMTP id u18-20020aa7d992000000b0050455b76207mr2934193eds.36.1680878631784; Fri, 07 Apr 2023 07:43:51 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1680878631; cv=none; d=google.com; s=arc-20160816; b=c286QoTcV5JrBTpwNoCVwcWVvm2t2nmbT2ZELrbbgbeujElqIgFXsweWpWuVnxX4sB qLe3vFEyvjsjDgkPmt9dfeZjsiYU5VfCALdlL9uRJbLlIjVdr2zLSxB8kNbyvVEVs2/X vdu4gyJdVXluNzs6Dg6dNVD2rCe9fna6TLmQKAI/oq0cW+vaPyYPtOFo+CkfOg/tZRDx l2XPkTvNe6SU6d4LOmCIayLSmpIlcVhyW4CHME8C9X6BoyCtlAG54sxBpwHZBwKXhY1O 2kcRcLxPPduQhizbXbVG+OM8o9z/XOWXli7EweCivV42EqDyRMOelO/IEVxqQHPQBTxB J6hw== 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=bAn1bWULqnahn1KUNDW0rRW3+WcRbtQUHgKcUdvZpQc=; b=ulXyVf1BZIDSE3hcOCK6TmT8y8FBqRIfZcU8hOnTTmCaTIJchmhFvVgkuSzO/uNbVe L4n0PveCPSYYUJkh/n35M0SYNlr7a3iQ6oqly3Q+uXJVYPHJ8C92sWEXEuyLfw7X+tkM 6Z537waTZReCn4rEiLJJFQ60Fk/i1SXz0GRYIYZ0j+yfTNLUyocp2bZlbtWdrvEfeGoA wM2O52tq0vqhqQ4qw+1sOz311mdBu/zgna2wmYjM1bPJIn0Msx+kIHQdc35kfno+ivoW +/GpKFc+b0I79535Gi9dWTqS/j3st3i8Yd047AUNmIREhT29DkDGr3XSXv1+z0jAkKj1 DWJw== 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 f26-20020a056402151a00b004acc454abe7si3177885edw.260.2023.04.07.07.43.27; Fri, 07 Apr 2023 07:43:51 -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 S240308AbjDGOR1 (ORCPT + 99 others); Fri, 7 Apr 2023 10:17:27 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:36646 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231349AbjDGORS (ORCPT ); Fri, 7 Apr 2023 10:17:18 -0400 Received: from out30-124.freemail.mail.aliyun.com (out30-124.freemail.mail.aliyun.com [115.124.30.124]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 387876E95 for ; Fri, 7 Apr 2023 07:17:17 -0700 (PDT) X-Alimail-AntiSpam: AC=PASS;BC=-1|-1;BR=01201311R281e4;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_---0VfX8evk_1680877033; Received: from localhost(mailfrom:jefflexu@linux.alibaba.com fp:SMTPD_---0VfX8evk_1680877033) by smtp.aliyun-inc.com; Fri, 07 Apr 2023 22:17:13 +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 2/7] erofs: initialize packed inode after root inode is assigned Date: Fri, 7 Apr 2023 22:17:05 +0800 Message-Id: <20230407141710.113882-3-jefflexu@linux.alibaba.com> X-Mailer: git-send-email 2.19.1.6.gb485710b In-Reply-To: <20230407141710.113882-1-jefflexu@linux.alibaba.com> References: <20230407141710.113882-1-jefflexu@linux.alibaba.com> MIME-Version: 1.0 X-Spam-Status: No, score=-8.0 required=5.0 tests=ENV_AND_HDR_SPF_MATCH, RCVD_IN_DNSWL_NONE,RCVD_IN_MSPIKE_H2,SPF_HELO_NONE,SPF_PASS, UNPARSEABLE_RELAY,USER_IN_DEF_SPF_WL autolearn=unavailable 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?1762528991971331532?= X-GMAIL-MSGID: =?utf-8?q?1762528991971331532?= As commit 8f7acdae2cd4 ("staging: erofs: kill all failure handling in fill_super()"), move the initialization of packed inode after root inode is assigned, so that the iput() in .put_super() is adequate as the failure handling. Otherwise, iput() is also needed in .kill_sb(), in case of the mounting fails halfway. Signed-off-by: Jingbo Xu Reviewed-by: Gao Xiang Reviewed-by: Yue Hu --- fs/erofs/internal.h | 1 + fs/erofs/super.c | 22 +++++++++++----------- 2 files changed, 12 insertions(+), 11 deletions(-) diff --git a/fs/erofs/internal.h b/fs/erofs/internal.h index 2bcff3194e4a..caea9dc1cd82 100644 --- a/fs/erofs/internal.h +++ b/fs/erofs/internal.h @@ -157,6 +157,7 @@ struct erofs_sb_info { /* what we really care is nid, rather than ino.. */ erofs_nid_t root_nid; + erofs_nid_t packed_nid; /* used for statfs, f_files - f_favail */ u64 inos; diff --git a/fs/erofs/super.c b/fs/erofs/super.c index 58ffbf410bfb..325602820dc8 100644 --- a/fs/erofs/super.c +++ b/fs/erofs/super.c @@ -388,17 +388,7 @@ static int erofs_read_superblock(struct super_block *sb) #endif sbi->islotbits = ilog2(sizeof(struct erofs_inode_compact)); sbi->root_nid = le16_to_cpu(dsb->root_nid); -#ifdef CONFIG_EROFS_FS_ZIP - sbi->packed_inode = NULL; - if (erofs_sb_has_fragments(sbi) && dsb->packed_nid) { - sbi->packed_inode = - erofs_iget(sb, le64_to_cpu(dsb->packed_nid)); - if (IS_ERR(sbi->packed_inode)) { - ret = PTR_ERR(sbi->packed_inode); - goto out; - } - } -#endif + sbi->packed_nid = le64_to_cpu(dsb->packed_nid); sbi->inos = le64_to_cpu(dsb->inos); sbi->build_time = le64_to_cpu(dsb->build_time); @@ -820,6 +810,16 @@ static int erofs_fc_fill_super(struct super_block *sb, struct fs_context *fc) erofs_shrinker_register(sb); /* sb->s_umount is already locked, SB_ACTIVE and SB_BORN are not set */ +#ifdef CONFIG_EROFS_FS_ZIP + if (erofs_sb_has_fragments(sbi) && sbi->packed_nid) { + sbi->packed_inode = erofs_iget(sb, sbi->packed_nid); + if (IS_ERR(sbi->packed_inode)) { + err = PTR_ERR(sbi->packed_inode); + sbi->packed_inode = NULL; + return err; + } + } +#endif err = erofs_init_managed_cache(sb); if (err) return err; From patchwork Fri Apr 7 14:17:06 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jingbo Xu X-Patchwork-Id: 80865 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:b0ea:0:b0:3b6:4342:cba0 with SMTP id b10csp335073vqo; Fri, 7 Apr 2023 07:46:32 -0700 (PDT) X-Google-Smtp-Source: AKy350bwXiXM/q3CrePPgivbagLy7A11BgxXLcMnOFy57N6CTAMTwqsuYdJ9WFRctnBSBir23qPQ X-Received: by 2002:a17:906:af78:b0:92f:e7e2:b7b3 with SMTP id os24-20020a170906af7800b0092fe7e2b7b3mr2854559ejb.5.1680878792698; Fri, 07 Apr 2023 07:46:32 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1680878792; cv=none; d=google.com; s=arc-20160816; b=OJVIXNSbnnf1gLWDLrlfA3kGVnYBhXQLUo8bhvMROZU+frDy4WzyAmgR3qlnDotlGN eHvLi82i0PbYEeaRpKYnLiP93IAW5GKxzItmEn8ju6Freq6V8yjiITTXb0i8gBhsHtVR UJbiO6SiaRg1QQQC0NvKnl7iu7nzXrtEFSshYosDQXtfZz7FFKK7/G91L6hHx0N18MhI iO4mXRjDJUFnZsw6VBJn4w5dBgqVWcikOZnK+kYMCphmin1cdj1PejqLshgZRKzz9N9k Iw8PWE82R8oqeh6h2dHedfY9kfBSXcosWFOflrMdSu/OP7BXtTHAcMMhucdwID1084hX H2rQ== 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=f7MGhLbCXsgcUDNvyz6948H9nnYbJiCdkG7GYS5I9CA=; b=sAzdwYbpsQP+60E1PerhtonjGW6kZo8UpyP1rqhNEiR7cRnw79WKmr8fF/2PIIHn2H xgFdHMJ/OAvjMN86C91KVSrIqJsYF/Ue7kT4EiYgngr0tOSWWHaDfnanFDUNY8WtLGXa 4EtgDyQpH4CQwgVMmgqmpwmwjFxBoXoBTVIWh6PCxI5z3PXS32ZlnJazFn8Y9gCtKP7o RrbsId8nBDgH5wsmTZNid3yqY3NGYc27J94UwaBYmdhEjmQqQ8g1RkkoOXgl5WCKi7tR Duuv/bAppCTUcID1pTvpg7y4NSnAvKyWMvE4ZvdS4POTRNx6rLw634DpgzybYn2tu3l4 ZvRw== 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 r4-20020aa7d584000000b0050202fad39dsi633138edq.635.2023.04.07.07.46.07; Fri, 07 Apr 2023 07:46:32 -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 S231349AbjDGOR3 (ORCPT + 99 others); Fri, 7 Apr 2023 10:17:29 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:36656 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231715AbjDGORU (ORCPT ); Fri, 7 Apr 2023 10:17:20 -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 05E016EB7 for ; Fri, 7 Apr 2023 07:17:18 -0700 (PDT) X-Alimail-AntiSpam: AC=PASS;BC=-1|-1;BR=01201311R131e4;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_---0VfXA6.c_1680877034; Received: from localhost(mailfrom:jefflexu@linux.alibaba.com fp:SMTPD_---0VfXA6.c_1680877034) by smtp.aliyun-inc.com; Fri, 07 Apr 2023 22:17:14 +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 3/7] erofs: move packed inode out of the compression part Date: Fri, 7 Apr 2023 22:17:06 +0800 Message-Id: <20230407141710.113882-4-jefflexu@linux.alibaba.com> X-Mailer: git-send-email 2.19.1.6.gb485710b In-Reply-To: <20230407141710.113882-1-jefflexu@linux.alibaba.com> References: <20230407141710.113882-1-jefflexu@linux.alibaba.com> MIME-Version: 1.0 X-Spam-Status: No, score=-8.0 required=5.0 tests=ENV_AND_HDR_SPF_MATCH, RCVD_IN_DNSWL_NONE,RCVD_IN_MSPIKE_H2,SPF_HELO_NONE,SPF_PASS, UNPARSEABLE_RELAY,USER_IN_DEF_SPF_WL autolearn=unavailable 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?1762529160560549721?= X-GMAIL-MSGID: =?utf-8?q?1762529160560549721?= packed inode could be used in more scenarios which are independent of compression in the future. For example, packed inode could be used to keep extra long xattr prefixes with the help of following patches. Signed-off-by: Jingbo Xu Reviewed-by: Gao Xiang Reviewed-by: Yue Hu --- fs/erofs/internal.h | 2 +- fs/erofs/super.c | 4 +--- 2 files changed, 2 insertions(+), 4 deletions(-) diff --git a/fs/erofs/internal.h b/fs/erofs/internal.h index caea9dc1cd82..8b5168f94dd2 100644 --- a/fs/erofs/internal.h +++ b/fs/erofs/internal.h @@ -134,8 +134,8 @@ struct erofs_sb_info { struct inode *managed_cache; struct erofs_sb_lz4_info lz4; - struct inode *packed_inode; #endif /* CONFIG_EROFS_FS_ZIP */ + struct inode *packed_inode; struct erofs_dev_context *devs; struct dax_device *dax_dev; u64 dax_part_off; diff --git a/fs/erofs/super.c b/fs/erofs/super.c index 325602820dc8..8f2f8433db61 100644 --- a/fs/erofs/super.c +++ b/fs/erofs/super.c @@ -810,7 +810,6 @@ static int erofs_fc_fill_super(struct super_block *sb, struct fs_context *fc) erofs_shrinker_register(sb); /* sb->s_umount is already locked, SB_ACTIVE and SB_BORN are not set */ -#ifdef CONFIG_EROFS_FS_ZIP if (erofs_sb_has_fragments(sbi) && sbi->packed_nid) { sbi->packed_inode = erofs_iget(sb, sbi->packed_nid); if (IS_ERR(sbi->packed_inode)) { @@ -819,7 +818,6 @@ static int erofs_fc_fill_super(struct super_block *sb, struct fs_context *fc) return err; } } -#endif err = erofs_init_managed_cache(sb); if (err) return err; @@ -986,9 +984,9 @@ static void erofs_put_super(struct super_block *sb) #ifdef CONFIG_EROFS_FS_ZIP iput(sbi->managed_cache); sbi->managed_cache = NULL; +#endif iput(sbi->packed_inode); sbi->packed_inode = NULL; -#endif erofs_free_dev_context(sbi->devs); sbi->devs = NULL; erofs_fscache_unregister_fs(sb); From patchwork Fri Apr 7 14:17:07 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jingbo Xu X-Patchwork-Id: 80855 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:b0ea:0:b0:3b6:4342:cba0 with SMTP id b10csp320659vqo; Fri, 7 Apr 2023 07:21:44 -0700 (PDT) X-Google-Smtp-Source: AKy350b38rm44tWGt5v1kt+Jl8DSZByZfeihG1mViUmA+6eomjeOt20Yaw9di/sKysjAZvAjcuR3 X-Received: by 2002:a17:906:4dc3:b0:949:55fd:34fb with SMTP id f3-20020a1709064dc300b0094955fd34fbmr2366900ejw.38.1680877304285; Fri, 07 Apr 2023 07:21:44 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1680877304; cv=none; d=google.com; s=arc-20160816; b=I8Lziqjzu8VBsjdfoTscYQVPEm1yt6zpveuz2SyRbBO4zutNVght6KeiZumAMBY1ql lDEfL8Mwx6VnE0SSw5yuVs3vbkuZzqRXPbxLU/qmdide0B1ongcgfoNKlDGUFuu2qNKP UC1Oxg87Ka0hPlzW6UjKfbajdF0qsyz2W2A3aeFmkcaJ9IsPD4C1nBCINoLLE41CDXZg aT3eJ6EpFeJPJS8SSU45hM+hwnkQeDsEX8Er2vWHVRd3hhQLwhCyFSXk5z63iGceOm/r xZXi4pjWnT3TXW5VLf2dpukiWVrOJqCbPPDrQuI/z2R1GEiDmtbWTAw0EcuPS4OpBKL5 WPwg== 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=HesMWEIWT1x3aR6dR1Ii6BleMkkuoMAnDz4d64pEGfg=; b=Xeg/j0JKQInkZeQKMGTLhPkwVB3i+f5e3m69m8z612tBWM/B4U9sYCRMg9Yd6LNT8Y Sbyp9lpzvNyK0xaE3dAkUCKV4sMBAksywJWuuVa9UgjFA2Y1akIBI+Ik6V2P+434tLpD DhNF5R0tDHGn4rwzzxJg5WCBfrTILJesxVg9NQbdeWCqtqkx0E0BeNbl/x9H1zrPzoWf 2RXwRQqqPa7OlAQVC84xKExg+QC8b+CoTYSctwLgK8ljqpO+aE+KIoLKVHuDVDold8e1 KmqLMvEhr3nGxV0zL72k0BMdoEMMJwZGnJ8Gt3y4UwUvyFoM5MjQw05+OGCVIBs0tYDG oofQ== 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 mh7-20020a170906eb8700b008e828688d69si2973896ejb.798.2023.04.07.07.21.20; Fri, 07 Apr 2023 07:21:44 -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 S240652AbjDGORk (ORCPT + 99 others); Fri, 7 Apr 2023 10:17:40 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:36698 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S240066AbjDGORW (ORCPT ); Fri, 7 Apr 2023 10:17:22 -0400 Received: from out30-131.freemail.mail.aliyun.com (out30-131.freemail.mail.aliyun.com [115.124.30.131]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id E9B146EB5 for ; Fri, 7 Apr 2023 07:17:20 -0700 (PDT) X-Alimail-AntiSpam: AC=PASS;BC=-1|-1;BR=01201311R111e4;CH=green;DM=||false|;DS=||;FP=0|-1|-1|-1|0|-1|-1|-1;HT=ay29a033018046056;MF=jefflexu@linux.alibaba.com;NM=1;PH=DS;RN=5;SR=0;TI=SMTPD_---0VfX7DEZ_1680877035; Received: from localhost(mailfrom:jefflexu@linux.alibaba.com fp:SMTPD_---0VfX7DEZ_1680877035) by smtp.aliyun-inc.com; Fri, 07 Apr 2023 22:17:15 +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 4/7] erofs: introduce on-disk format for long xattr name prefixes Date: Fri, 7 Apr 2023 22:17:07 +0800 Message-Id: <20230407141710.113882-5-jefflexu@linux.alibaba.com> X-Mailer: git-send-email 2.19.1.6.gb485710b In-Reply-To: <20230407141710.113882-1-jefflexu@linux.alibaba.com> References: <20230407141710.113882-1-jefflexu@linux.alibaba.com> MIME-Version: 1.0 X-Spam-Status: No, score=-8.0 required=5.0 tests=ENV_AND_HDR_SPF_MATCH, RCVD_IN_DNSWL_NONE,RCVD_IN_MSPIKE_H2,SPF_HELO_NONE,SPF_PASS, UNPARSEABLE_RELAY,USER_IN_DEF_SPF_WL autolearn=unavailable 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?1762527599741332482?= X-GMAIL-MSGID: =?utf-8?q?1762527599741332482?= Besides the predefined xattr name prefixes, introduces long xattr name prefixes, which work similarly as the predefined name prefixes, except that they are user specified. It is especially useful for use cases together with overlayfs like Composefs model, which introduces diverse xattr values with only a few common xattr names (trusted.overlay.redirect, trusted.overlay.digest, and maybe more in the future). That makes the existing predefined prefixes ineffective in both image size and runtime performance. When a user specified long xattr name prefix is used, only the trailing part of the xattr name apart from the long xattr name prefix will be stored in erofs_xattr_entry.e_name. e_name is empty if the xattr name matches exactly as the long xattr name prefix. All long xattr prefixes are stored in the packed or meta inode, which depends if fragments feature is enabled or not. For each long xattr name prefix, the on-disk format is kept as the same as the unique metadata format: ALIGN({__le16 len, data}, 4), where len represents the total size of struct erofs_xattr_long_prefix, followed by data of struct erofs_xattr_long_prefix itself. Each erofs_xattr_long_prefix keeps predefined prefixes (base_index) and the remaining prefix string without the trailing '\0'. Two fields are introduced to the on-disk superblock, where xattr_prefix_count represents the total number of the long xattr name prefixes recorded, and xattr_prefix_start represents the start offset of recorded name prefixes in the packed/meta inode divided by 4. When referring to a long xattr name prefix, the highest bit (bit 7) of erofs_xattr_entry.e_name_index is set, while the lower bits (bit 0-6) as a whole represents the index of the referred long name prefix among all long xattr name prefixes. Signed-off-by: Jingbo Xu Reviewed-by: Gao Xiang --- fs/erofs/erofs_fs.h | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/fs/erofs/erofs_fs.h b/fs/erofs/erofs_fs.h index 44876a97cabd..ea62f83dac40 100644 --- a/fs/erofs/erofs_fs.h +++ b/fs/erofs/erofs_fs.h @@ -76,7 +76,8 @@ struct erofs_super_block { __le16 extra_devices; /* # of devices besides the primary device */ __le16 devt_slotoff; /* startoff = devt_slotoff * devt_slotsize */ __u8 dirblkbits; /* directory block size in bit shift */ - __u8 reserved[5]; + __u8 xattr_prefix_count; /* # of long xattr name prefixes */ + __le32 xattr_prefix_start; /* start of long xattr prefixes */ __le64 packed_nid; /* nid of the special packed inode */ __u8 reserved2[24]; }; @@ -229,6 +230,13 @@ struct erofs_xattr_ibody_header { #define EROFS_XATTR_INDEX_LUSTRE 5 #define EROFS_XATTR_INDEX_SECURITY 6 +/* + * bit 7 of e_name_index is set when it refers to a long xattr name prefix, + * while the remained lower bits represent the index of the prefix. + */ +#define EROFS_XATTR_LONG_PREFIX 0x80 +#define EROFS_XATTR_LONG_PREFIX_MASK 0x7f + /* xattr entry (for both inline & shared xattrs) */ struct erofs_xattr_entry { __u8 e_name_len; /* length of name */ @@ -238,6 +246,12 @@ struct erofs_xattr_entry { char e_name[]; /* attribute name */ }; +/* long xattr name prefix */ +struct erofs_xattr_long_prefix { + __u8 base_index; /* short xattr name prefix index */ + char infix[]; /* infix apart from short prefix */ +}; + static inline unsigned int erofs_xattr_ibody_size(__le16 i_xattr_icount) { if (!i_xattr_icount) From patchwork Fri Apr 7 14:17:08 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jingbo Xu X-Patchwork-Id: 80864 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:b0ea:0:b0:3b6:4342:cba0 with SMTP id b10csp335045vqo; Fri, 7 Apr 2023 07:46:30 -0700 (PDT) X-Google-Smtp-Source: AKy350YETeRq8PI5qCxpa018EiABHCC2OLeE3dT+fGMtwUB4pKr+OfIfuILs5SiPIdi3VVpvfGIE X-Received: by 2002:a17:902:ce8c:b0:19f:e9e7:4cb with SMTP id f12-20020a170902ce8c00b0019fe9e704cbmr3238626plg.45.1680878789862; Fri, 07 Apr 2023 07:46:29 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1680878789; cv=none; d=google.com; s=arc-20160816; b=xbkHPKqB15d9egQAyYiW0CYWtgXNx2VvtLw6lRikZNE8eoYE5yOXitsk0dfFipIbga KWUmM9mDgK2GuYaLUQhMNu+D0WcklnqQouKZzFtAzQ1puGdeav9j3wnVkVSbW9mXT+ME KGM0SfVSC8cOH+qsv0LdIOQJmPdWEmYT5nteSWd6AouGfrkpVrvPQkHbHrKwiTOokPDa uwY7oCE8Bsfh0x885Z2JfaqgBbIZttYDW2eMl8ZlgtcY0SMz4gDqljkgb2+WuT6O8dMx 2ioACstRU7jwyVZwXZQRvlgY02S1R7S1di8GHiF2THfLGxgIF+D/kD5+fstmBikKr7uZ bR+A== 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=+KBwC5C5Df6l8k3jHXq+2wkv61+xrbGywt7z5ZQ5f4A=; b=cwcOhnwj8qNTjdh5QimXXuZEndfXTGEk2MPyiqMaEHVlJ48cXXRrINHNPTMPMoSHR5 BJt/ueumno+k5/WBi+aIKZNsbvO502ukxwtirSPdg6jOaW6MAUpkPd/z7rqqgNeA39Hx UqnohaCLhND1dC9e/KpyKIVf4oOBMVXH9BaK6oVEF6N2g+GaLjoaQILKANHKdrkJbb6P 0dqN4Bo/Wqdd5aItd0STAty5IHzXPJr/8/baXy963iuxPUMf2AmyikJCBNJCBLCEPE2F 62flz+iS/iSSNMO4+3nKFXB5X3c0o8am8o7I0jrySZ+NOcNyk4jzlTMBoEgCrPd8QoGU PNig== 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 kp15-20020a170903280f00b001a1b152a275si3935288plb.32.2023.04.07.07.46.16; Fri, 07 Apr 2023 07:46:29 -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 S240553AbjDGORc (ORCPT + 99 others); Fri, 7 Apr 2023 10:17:32 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:36656 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S239811AbjDGORW (ORCPT ); Fri, 7 Apr 2023 10:17:22 -0400 Received: from out30-110.freemail.mail.aliyun.com (out30-110.freemail.mail.aliyun.com [115.124.30.110]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id C5DA66EB8 for ; Fri, 7 Apr 2023 07:17:19 -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=ay29a033018046059;MF=jefflexu@linux.alibaba.com;NM=1;PH=DS;RN=5;SR=0;TI=SMTPD_---0VfX7DF5_1680877036; Received: from localhost(mailfrom:jefflexu@linux.alibaba.com fp:SMTPD_---0VfX7DF5_1680877036) by smtp.aliyun-inc.com; Fri, 07 Apr 2023 22:17:16 +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 5/7] erofs: add helpers to load long xattr name prefixes Date: Fri, 7 Apr 2023 22:17:08 +0800 Message-Id: <20230407141710.113882-6-jefflexu@linux.alibaba.com> X-Mailer: git-send-email 2.19.1.6.gb485710b In-Reply-To: <20230407141710.113882-1-jefflexu@linux.alibaba.com> References: <20230407141710.113882-1-jefflexu@linux.alibaba.com> MIME-Version: 1.0 X-Spam-Status: No, score=-8.0 required=5.0 tests=ENV_AND_HDR_SPF_MATCH, RCVD_IN_DNSWL_NONE,SPF_HELO_NONE,SPF_PASS,UNPARSEABLE_RELAY, USER_IN_DEF_SPF_WL autolearn=unavailable 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?1762529157769046745?= X-GMAIL-MSGID: =?utf-8?q?1762529157769046745?= Long xattr name prefixes will be scanned upon mounting and the in-memory long xattr name prefix array will be initialized accordingly. Signed-off-by: Jingbo Xu Reviewed-by: Gao Xiang --- fs/erofs/internal.h | 10 ++++++++ fs/erofs/super.c | 6 ++--- fs/erofs/xattr.c | 56 +++++++++++++++++++++++++++++++++++++++++++++ fs/erofs/xattr.h | 4 ++++ 4 files changed, 73 insertions(+), 3 deletions(-) diff --git a/fs/erofs/internal.h b/fs/erofs/internal.h index 8b5168f94dd2..5a9c19654b19 100644 --- a/fs/erofs/internal.h +++ b/fs/erofs/internal.h @@ -117,6 +117,11 @@ struct erofs_fscache { char *name; }; +struct erofs_xattr_prefix_item { + struct erofs_xattr_long_prefix *prefix; + u8 infix_len; +}; + struct erofs_sb_info { struct erofs_mount_opts opt; /* options */ #ifdef CONFIG_EROFS_FS_ZIP @@ -145,6 +150,9 @@ struct erofs_sb_info { u32 meta_blkaddr; #ifdef CONFIG_EROFS_FS_XATTR u32 xattr_blkaddr; + u32 xattr_prefix_start; + u8 xattr_prefix_count; + struct erofs_xattr_prefix_item *xattr_prefixes; #endif u16 device_id_mask; /* valid bits of device id to be used */ @@ -440,6 +448,8 @@ extern const struct iomap_ops z_erofs_iomap_report_ops; #define EROFS_REG_COOKIE_SHARE 0x0001 #define EROFS_REG_COOKIE_NEED_NOEXIST 0x0002 +void *erofs_read_metadata(struct super_block *sb, struct erofs_buf *buf, + erofs_off_t *offset, int *lengthp); void erofs_unmap_metabuf(struct erofs_buf *buf); void erofs_put_metabuf(struct erofs_buf *buf); void *erofs_bread(struct erofs_buf *buf, erofs_blk_t blkaddr, diff --git a/fs/erofs/super.c b/fs/erofs/super.c index 8f2f8433db61..bf396e0c243a 100644 --- a/fs/erofs/super.c +++ b/fs/erofs/super.c @@ -126,10 +126,9 @@ static bool check_layout_compatibility(struct super_block *sb, return true; } -#ifdef CONFIG_EROFS_FS_ZIP /* read variable-sized metadata, offset will be aligned by 4-byte */ -static void *erofs_read_metadata(struct super_block *sb, struct erofs_buf *buf, - erofs_off_t *offset, int *lengthp) +void *erofs_read_metadata(struct super_block *sb, struct erofs_buf *buf, + erofs_off_t *offset, int *lengthp) { u8 *buffer, *ptr; int len, i, cnt; @@ -162,6 +161,7 @@ static void *erofs_read_metadata(struct super_block *sb, struct erofs_buf *buf, return buffer; } +#ifdef CONFIG_EROFS_FS_ZIP static int erofs_load_compr_cfgs(struct super_block *sb, struct erofs_super_block *dsb) { diff --git a/fs/erofs/xattr.c b/fs/erofs/xattr.c index d76b74ece2e5..684571e83a2c 100644 --- a/fs/erofs/xattr.c +++ b/fs/erofs/xattr.c @@ -610,6 +610,62 @@ ssize_t erofs_listxattr(struct dentry *dentry, return ret; } +void erofs_xattr_prefixes_cleanup(struct super_block *sb) +{ + struct erofs_sb_info *sbi = EROFS_SB(sb); + int i; + + if (sbi->xattr_prefixes) { + for (i = 0; i < sbi->xattr_prefix_count; i++) + kfree(sbi->xattr_prefixes[i].prefix); + kfree(sbi->xattr_prefixes); + sbi->xattr_prefixes = NULL; + } +} + +int erofs_xattr_prefixes_init(struct super_block *sb) +{ + struct erofs_sb_info *sbi = EROFS_SB(sb); + struct erofs_buf buf = __EROFS_BUF_INITIALIZER; + erofs_off_t pos = (erofs_off_t)sbi->xattr_prefix_start << 2; + struct erofs_xattr_prefix_item *pfs; + int ret = 0, i, len; + + if (!sbi->xattr_prefix_count) + return 0; + + pfs = kzalloc(sbi->xattr_prefix_count * sizeof(*pfs), GFP_KERNEL); + if (!pfs) + return -ENOMEM; + + if (erofs_sb_has_fragments(sbi)) + buf.inode = sbi->packed_inode; + else + erofs_init_metabuf(&buf, sb); + + for (i = 0; i < sbi->xattr_prefix_count; i++) { + void *ptr = erofs_read_metadata(sb, &buf, &pos, &len); + + if (IS_ERR(ptr)) { + ret = PTR_ERR(ptr); + break; + } else if (len < sizeof(*pfs->prefix) || + len > EROFS_NAME_LEN + sizeof(*pfs->prefix)) { + kfree(ptr); + ret = -EFSCORRUPTED; + break; + } + pfs[i].prefix = ptr; + pfs[i].infix_len = len - sizeof(struct erofs_xattr_long_prefix); + } + + erofs_put_metabuf(&buf); + sbi->xattr_prefixes = pfs; + if (ret) + erofs_xattr_prefixes_cleanup(sb); + return ret; +} + #ifdef CONFIG_EROFS_FS_POSIX_ACL struct posix_acl *erofs_get_acl(struct inode *inode, int type, bool rcu) { diff --git a/fs/erofs/xattr.h b/fs/erofs/xattr.h index a65158cba14f..e1265351aedd 100644 --- a/fs/erofs/xattr.h +++ b/fs/erofs/xattr.h @@ -40,9 +40,13 @@ static inline const struct xattr_handler *erofs_xattr_handler(unsigned int idx) extern const struct xattr_handler *erofs_xattr_handlers[]; +int erofs_xattr_prefixes_init(struct super_block *sb); +void erofs_xattr_prefixes_cleanup(struct super_block *sb); int erofs_getxattr(struct inode *, int, const char *, void *, size_t); ssize_t erofs_listxattr(struct dentry *, char *, size_t); #else +static inline int erofs_xattr_prefixes_init(struct super_block *sb) { return 0; } +static inline void erofs_xattr_prefixes_cleanup(struct super_block *sb) {} static inline int erofs_getxattr(struct inode *inode, int index, const char *name, void *buffer, size_t buffer_size) From patchwork Fri Apr 7 14:17:09 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jingbo Xu X-Patchwork-Id: 80860 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:b0ea:0:b0:3b6:4342:cba0 with SMTP id b10csp333513vqo; Fri, 7 Apr 2023 07:43:51 -0700 (PDT) X-Google-Smtp-Source: AKy350aObYIVgq1feFWBpnvgajOeniZ3czfR6t0BGdKlQnuLy54teHYa83KFsu0hXRSQSRZ2iPhZ X-Received: by 2002:a17:902:fb45:b0:19f:27fd:7cb5 with SMTP id lf5-20020a170902fb4500b0019f27fd7cb5mr2641873plb.10.1680878631438; Fri, 07 Apr 2023 07:43:51 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1680878631; cv=none; d=google.com; s=arc-20160816; b=tvl1i1ebt7ZaW10kiUeBiRuyV7VM/4glm1hL/Rz1opEtwSRjkRigGG37aNKuzWIzBG at+d1JyiGHceYfs6ozB7KeVYnYdtglzzZtlCebua/b6g9JI+shWUnItKtHDC5jjIFlEo mii9OSyk1sER3By/jHgqhrF/ekbbhcF+m/YeeWQ0zVdzVrLr0ptKBMihQu895lgbYMYd IlspMYCj3IPLpGXSU39kB5DC1XM9a2y2QrKoHAywL2oaeoUbMqqGbwMr1A+mswOtCme+ z9/DzTQNzZ0rRPjL25f+4ZbCB0vb0HIdPrDUj6tqReZkiiJCZg+brGakKmhqaoX8OpT0 V6gg== 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=BBgSgIsgBIMZShof6k+cyjUeUDCjizur45G7OYaNhks=; b=Pp5hX3bBnd9k61dcaIq5V0rjfio9V4vz6BoskjvIAGH3mDvcpP98hsEuhkWQgrrX+M eKuibozDAFY46B0uRDi/2TsmPcwQ8bQ1P3bewJUadi9Hw2DX394V6sjvYOdxDJ6tA+H/ ux38dxbyWD14FfTV4ZnRvlWNITeBQ51HyFJkymzHNcaMJNzNHSWZktXsxhbO9Iyep2J7 PHUy8a2axzEyQbRqtqtwXbO9NE4+OFA4oJxAvG26sntcLoHrxjvUiz0rDQ/2a/KwOSl+ rQ/LjHwzgpFd8q4SkAklHtRPl6BL4GQs9aqat1CgW2PnSOSlMr49VPayPZKtsQGde0xp RGbQ== 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 n9-20020a170902d2c900b001a199eaf57csi4200545plc.404.2023.04.07.07.43.38; Fri, 07 Apr 2023 07:43:51 -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 S240601AbjDGORf (ORCPT + 99 others); Fri, 7 Apr 2023 10:17:35 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:36700 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S240080AbjDGORW (ORCPT ); Fri, 7 Apr 2023 10:17:22 -0400 Received: from out30-98.freemail.mail.aliyun.com (out30-98.freemail.mail.aliyun.com [115.124.30.98]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 224BD72BC for ; Fri, 7 Apr 2023 07:17:20 -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=ay29a033018046056;MF=jefflexu@linux.alibaba.com;NM=1;PH=DS;RN=5;SR=0;TI=SMTPD_---0VfX8ext_1680877037; Received: from localhost(mailfrom:jefflexu@linux.alibaba.com fp:SMTPD_---0VfX8ext_1680877037) by smtp.aliyun-inc.com; Fri, 07 Apr 2023 22:17:18 +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 6/7] erofs: handle long xattr name prefixes properly Date: Fri, 7 Apr 2023 22:17:09 +0800 Message-Id: <20230407141710.113882-7-jefflexu@linux.alibaba.com> X-Mailer: git-send-email 2.19.1.6.gb485710b In-Reply-To: <20230407141710.113882-1-jefflexu@linux.alibaba.com> References: <20230407141710.113882-1-jefflexu@linux.alibaba.com> MIME-Version: 1.0 X-Spam-Status: No, score=-8.0 required=5.0 tests=ENV_AND_HDR_SPF_MATCH, RCVD_IN_DNSWL_NONE,RCVD_IN_MSPIKE_H2,SPF_HELO_NONE,SPF_PASS, UNPARSEABLE_RELAY,USER_IN_DEF_SPF_WL autolearn=unavailable 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?1762528991508540829?= X-GMAIL-MSGID: =?utf-8?q?1762528991508540829?= Make .{list,get}xattr routines adapted to long xattr name prefixes. When the bit 7 of erofs_xattr_entry.e_name_index is set, it indicates that it refers to a long xattr name prefix. Signed-off-by: Jingbo Xu Reviewed-by: Gao Xiang Reviewed-by: Gao Xiang --- fs/erofs/xattr.c | 60 +++++++++++++++++++++++++++++++++++++++++------- 1 file changed, 52 insertions(+), 8 deletions(-) diff --git a/fs/erofs/xattr.c b/fs/erofs/xattr.c index 684571e83a2c..8d81593655e8 100644 --- a/fs/erofs/xattr.c +++ b/fs/erofs/xattr.c @@ -301,11 +301,39 @@ struct getxattr_iter { struct qstr name; }; +static int erofs_xattr_long_entrymatch(struct getxattr_iter *it, + struct erofs_xattr_entry *entry) +{ + struct erofs_sb_info *sbi = EROFS_SB(it->it.sb); + u8 idx = entry->e_name_index & EROFS_XATTR_LONG_PREFIX_MASK; + struct erofs_xattr_prefix_item *pf; + + if (idx >= sbi->xattr_prefix_count) + return -ENOATTR; + + pf = &sbi->xattr_prefixes[idx]; + if (it->index != pf->prefix->base_index) + return -ENOATTR; + + if (strncmp(it->name.name, pf->prefix->infix, pf->infix_len)) + return -ENOATTR; + + it->name.name += pf->infix_len; + it->name.len -= pf->infix_len; + if (it->name.len != entry->e_name_len) + return -ENOATTR; + return 0; +} + static int xattr_entrymatch(struct 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); + return (it->index != entry->e_name_index || it->name.len != entry->e_name_len) ? -ENOATTR : 0; } @@ -487,12 +515,26 @@ static int xattr_entrylist(struct xattr_iter *_it, { struct listxattr_iter *it = container_of(_it, struct listxattr_iter, it); - unsigned int prefix_len; - const char *prefix; - - const struct xattr_handler *h = - erofs_xattr_handler(entry->e_name_index); + unsigned int base_index = entry->e_name_index; + unsigned int prefix_len, infix_len = 0; + const char *prefix, *infix = NULL; + const struct xattr_handler *h; + + if (entry->e_name_index & EROFS_XATTR_LONG_PREFIX) { + struct erofs_sb_info *sbi = EROFS_SB(_it->sb); + u8 idx = entry->e_name_index & EROFS_XATTR_LONG_PREFIX_MASK; + struct erofs_xattr_prefix_item *pf; + + if (idx >= sbi->xattr_prefix_count) + return 1; + + pf = &sbi->xattr_prefixes[idx]; + infix = pf->prefix->infix; + infix_len = pf->infix_len; + base_index = pf->prefix->base_index; + } + h = erofs_xattr_handler(base_index); if (!h || (h->list && !h->list(it->dentry))) return 1; @@ -500,16 +542,18 @@ static int xattr_entrylist(struct xattr_iter *_it, prefix_len = strlen(prefix); if (!it->buffer) { - it->buffer_ofs += prefix_len + entry->e_name_len + 1; + it->buffer_ofs += prefix_len + infix_len + + entry->e_name_len + 1; return 1; } - if (it->buffer_ofs + prefix_len + if (it->buffer_ofs + prefix_len + infix_len + + entry->e_name_len + 1 > it->buffer_size) return -ERANGE; memcpy(it->buffer + it->buffer_ofs, prefix, prefix_len); - it->buffer_ofs += prefix_len; + memcpy(it->buffer + it->buffer_ofs + prefix_len, infix, infix_len); + it->buffer_ofs += prefix_len + infix_len; return 0; } From patchwork Fri Apr 7 14:17:10 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jingbo Xu X-Patchwork-Id: 80862 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:b0ea:0:b0:3b6:4342:cba0 with SMTP id b10csp333703vqo; Fri, 7 Apr 2023 07:44:14 -0700 (PDT) X-Google-Smtp-Source: AKy350a55Sr1hN73xGP4AzRR6XFMhqYTVgVBWb9CgnkbjVx/eb0UxLQnkJq9FVOqdda6SkyV4U8Y X-Received: by 2002:a17:906:e297:b0:86f:b99c:ac8d with SMTP id gg23-20020a170906e29700b0086fb99cac8dmr2483459ejb.44.1680878654599; Fri, 07 Apr 2023 07:44:14 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1680878654; cv=none; d=google.com; s=arc-20160816; b=k9RrtXF3VMIhlGrZpdJUJInN5TblwV6B+cXMT6qHAFsszJl1qzcoXSSnoxBqSpUS3U EbqVEhTMjwnA3B6MgBDWjmDW3MCJZEPsBcmLu1ZUEwDCme5HvrPKsfceN+2NMitJIu4a KLyXwyDaqtohA6GugAraPX8C+d23MqjxZamTij/FGTLDU7OvJ9vmgqkGHUXbDSv7cjKz K2zJjo4vZc/pzSrMiEB3j9cJGlVvjroxR8aerR3D+qBtJH0vkLwLJh5Ci74szPJS/sr+ h3werwgIhvu5PkWsGk3Xsm1Wm7qyhyrT5h/blEMIkm+wp4EphYOjOw32W6lBzyicIEuI 5/tw== 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=qiJ0TKyg3QM9NJDMpb6nqTuJHUM74LevTW8D4jS2ijU=; b=wSqrKrYPwjEje4TMfnu+dokZo5wd23xa0Nq9weXza7yk9KBSLNUeaZ7QSHrG3bivqW Qd8m+SXZ8gHgsMNoy0uJFPjtbh7tDI8Uno6Iis9C54FIfZ/c1Nys/SkcbmKltcRdYsec sSFQEhmzy0oi8kfC8BuPCdiI8tCBBQ4BGSjhDB1mXi55pj71sSi2HRd7U8B8RbkxIB1i 4DtshYNNEGVbVjRWpRlxB8j8FUq7cjbxyXfW5+2fgDXXEJfgeCKaGgWT52gT5q6V9wQD 83bWjvBNiY5R+dVcuo3OWVvdQV5UKFWTz4/9sUhgzU+w63Ebfu4E6hRa2e/IDAgsYwwR VROQ== 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 ck10-20020a170906c44a00b0092d5457516asi3243229ejb.589.2023.04.07.07.43.51; Fri, 07 Apr 2023 07:44:14 -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 S240543AbjDGORh (ORCPT + 99 others); Fri, 7 Apr 2023 10:17:37 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:36714 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S240100AbjDGORW (ORCPT ); Fri, 7 Apr 2023 10:17:22 -0400 Received: from out30-124.freemail.mail.aliyun.com (out30-124.freemail.mail.aliyun.com [115.124.30.124]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id ADB9176AA for ; Fri, 7 Apr 2023 07:17:21 -0700 (PDT) X-Alimail-AntiSpam: AC=PASS;BC=-1|-1;BR=01201311R231e4;CH=green;DM=||false|;DS=||;FP=0|-1|-1|-1|0|-1|-1|-1;HT=ay29a033018046050;MF=jefflexu@linux.alibaba.com;NM=1;PH=DS;RN=5;SR=0;TI=SMTPD_---0VfX4iF._1680877038; Received: from localhost(mailfrom:jefflexu@linux.alibaba.com fp:SMTPD_---0VfX4iF._1680877038) by smtp.aliyun-inc.com; Fri, 07 Apr 2023 22:17:19 +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 7/7] erofs: enable long extended attribute name prefixes Date: Fri, 7 Apr 2023 22:17:10 +0800 Message-Id: <20230407141710.113882-8-jefflexu@linux.alibaba.com> X-Mailer: git-send-email 2.19.1.6.gb485710b In-Reply-To: <20230407141710.113882-1-jefflexu@linux.alibaba.com> References: <20230407141710.113882-1-jefflexu@linux.alibaba.com> MIME-Version: 1.0 X-Spam-Status: No, score=-8.0 required=5.0 tests=ENV_AND_HDR_SPF_MATCH, RCVD_IN_DNSWL_NONE,RCVD_IN_MSPIKE_H2,SPF_HELO_NONE,SPF_PASS, UNPARSEABLE_RELAY,USER_IN_DEF_SPF_WL autolearn=unavailable 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?1762529016264187339?= X-GMAIL-MSGID: =?utf-8?q?1762529016264187339?= Let's enable long xattr name prefix feature. Old kernels will just ignore / skip such extended attributes so that in case you don't want to mount such images. Add another incompatible feature as an option for this. Signed-off-by: Jingbo Xu --- fs/erofs/erofs_fs.h | 4 +++- fs/erofs/internal.h | 1 + fs/erofs/super.c | 8 ++++++++ 3 files changed, 12 insertions(+), 1 deletion(-) diff --git a/fs/erofs/erofs_fs.h b/fs/erofs/erofs_fs.h index ea62f83dac40..ac42a7255b39 100644 --- a/fs/erofs/erofs_fs.h +++ b/fs/erofs/erofs_fs.h @@ -27,6 +27,7 @@ #define EROFS_FEATURE_INCOMPAT_ZTAILPACKING 0x00000010 #define EROFS_FEATURE_INCOMPAT_FRAGMENTS 0x00000020 #define EROFS_FEATURE_INCOMPAT_DEDUPE 0x00000020 +#define EROFS_FEATURE_INCOMPAT_XATTR_PREFIXES 0x00000040 #define EROFS_ALL_FEATURE_INCOMPAT \ (EROFS_FEATURE_INCOMPAT_ZERO_PADDING | \ EROFS_FEATURE_INCOMPAT_COMPR_CFGS | \ @@ -36,7 +37,8 @@ EROFS_FEATURE_INCOMPAT_COMPR_HEAD2 | \ EROFS_FEATURE_INCOMPAT_ZTAILPACKING | \ EROFS_FEATURE_INCOMPAT_FRAGMENTS | \ - EROFS_FEATURE_INCOMPAT_DEDUPE) + EROFS_FEATURE_INCOMPAT_DEDUPE | \ + EROFS_FEATURE_INCOMPAT_XATTR_PREFIXES) #define EROFS_SB_EXTSLOT_SIZE 16 diff --git a/fs/erofs/internal.h b/fs/erofs/internal.h index 5a9c19654b19..f675050af2bb 100644 --- a/fs/erofs/internal.h +++ b/fs/erofs/internal.h @@ -285,6 +285,7 @@ EROFS_FEATURE_FUNCS(compr_head2, incompat, INCOMPAT_COMPR_HEAD2) EROFS_FEATURE_FUNCS(ztailpacking, incompat, INCOMPAT_ZTAILPACKING) EROFS_FEATURE_FUNCS(fragments, incompat, INCOMPAT_FRAGMENTS) EROFS_FEATURE_FUNCS(dedupe, incompat, INCOMPAT_DEDUPE) +EROFS_FEATURE_FUNCS(xattr_prefixes, incompat, INCOMPAT_XATTR_PREFIXES) EROFS_FEATURE_FUNCS(sb_chksum, compat, COMPAT_SB_CHKSUM) /* atomic flag definitions */ diff --git a/fs/erofs/super.c b/fs/erofs/super.c index bf396e0c243a..8f85cc6162e2 100644 --- a/fs/erofs/super.c +++ b/fs/erofs/super.c @@ -391,6 +391,9 @@ static int erofs_read_superblock(struct super_block *sb) sbi->packed_nid = le64_to_cpu(dsb->packed_nid); sbi->inos = le64_to_cpu(dsb->inos); + sbi->xattr_prefix_start = le32_to_cpu(dsb->xattr_prefix_start); + sbi->xattr_prefix_count = dsb->xattr_prefix_count; + sbi->build_time = le64_to_cpu(dsb->build_time); sbi->build_time_nsec = le32_to_cpu(dsb->build_time_nsec); @@ -822,6 +825,10 @@ static int erofs_fc_fill_super(struct super_block *sb, struct fs_context *fc) if (err) return err; + err = erofs_xattr_prefixes_init(sb); + if (err) + return err; + err = erofs_register_sysfs(sb); if (err) return err; @@ -981,6 +988,7 @@ static void erofs_put_super(struct super_block *sb) erofs_unregister_sysfs(sb); erofs_shrinker_unregister(sb); + erofs_xattr_prefixes_cleanup(sb); #ifdef CONFIG_EROFS_FS_ZIP iput(sbi->managed_cache); sbi->managed_cache = NULL;