From patchwork Wed Feb 8 07:16:18 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jingbo Xu X-Patchwork-Id: 54228 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:adf:eb09:0:0:0:0:0 with SMTP id s9csp3307652wrn; Tue, 7 Feb 2023 23:19:30 -0800 (PST) X-Google-Smtp-Source: AK7set+0VbRs0WSm0+pMnpy9Mrxf+1NQUJqlFTavr6SRK9vJUlkpgGF5xof3iysCWJGpA7OaGLZi X-Received: by 2002:a05:6a20:42a1:b0:be:c5de:7157 with SMTP id o33-20020a056a2042a100b000bec5de7157mr7596294pzj.53.1675840770145; Tue, 07 Feb 2023 23:19:30 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1675840770; cv=none; d=google.com; s=arc-20160816; b=wrP+2v3Kf0GS2FgGh2Ales7hPd5Kon69idB9/52JosUhOF7w4LqjFmjDHp1pc1aPOP 0We7nhRiDx/+G/gNvaJc0k5UzvNikHy4DARoU5fBb3izsdLV18wnX2ZIM6avO7raqsFu r7cVjMiGN0eHu/VTJuTl7QLJUWcAThnKJLsvfPB0dg3WrmsRpmWH1Hkd/q12C4bNmZMV CIQD8SN2RxNz0tXfMuTt6nCeD8TCiJNs9q1Ra2TAtZnqCNv1ECoWRhANOaTt6hSsKI6L /jkI74QlCqeL4bRHU6u69uvC7th2Us5Ul+KbNFLRc1qMLcV6graVU252qQdLxcwjN7To wdFw== 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=6liYWvXbFVSO9GX0bALl3wArvk7Nwqb+FGxnmsJFVOA=; b=vnO1EK8kO/FYOUUwFd32FVoySV09Rk/2jvWxAv6ARhT6Lhpb1ImhloU2adRMnkL6Pb PxGVo5Ccp6w5rxeAbvualeF6MVZ8JSSgNLf+Cd4NKS8AhvnbJmDzgb35HIQu3bZfBmSp puBQK/AYqevDCQgPcDwEYR93G3UBb6+rf/b5JNHAzysWIN9JRuRjKaRkU7M75VM1kywR bzZXu/ioL8IFv9bHTRXIZ2KCbL8pN5XCAIAtVQxvy+OzN4Qy29b/O4tsMyV7+GmwGvKn hygFO+BMkLyy+epWSDMfzwqf1Vh8lhwYGrUPV3SNaaWtFAme0krgdW0tP8FIKLaW4aOK 4M4g== 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 v135-20020a63618d000000b004faee2d046esi8372415pgb.582.2023.02.07.23.19.16; Tue, 07 Feb 2023 23:19:30 -0800 (PST) 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 S229895AbjBHHQ0 (ORCPT + 99 others); Wed, 8 Feb 2023 02:16:26 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:46156 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229949AbjBHHQY (ORCPT ); Wed, 8 Feb 2023 02:16:24 -0500 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 28D5123C53 for ; Tue, 7 Feb 2023 23:16:21 -0800 (PST) X-Alimail-AntiSpam: AC=PASS;BC=-1|-1;BR=01201311R211e4;CH=green;DM=||false|;DS=||;FP=0|-1|-1|-1|0|-1|-1|-1;HT=ay29a033018045192;MF=jefflexu@linux.alibaba.com;NM=1;PH=DS;RN=6;SR=0;TI=SMTPD_---0VbAXJMh_1675840579; Received: from localhost(mailfrom:jefflexu@linux.alibaba.com fp:SMTPD_---0VbAXJMh_1675840579) by smtp.aliyun-inc.com; Wed, 08 Feb 2023 15:16:19 +0800 From: Jingbo Xu To: xiang@kernel.org, chao@kernel.org, linux-erofs@lists.ozlabs.org, zhujia.zj@bytedance.com Cc: huyue2@coolpad.com, linux-kernel@vger.kernel.org Subject: [PATCH 1/4] erofs: remove unused device mapping in meta routine Date: Wed, 8 Feb 2023 15:16:18 +0800 Message-Id: <404848a1e43ff2d585c91e222beae4de8b9fb5f3.1675840368.git.jefflexu@linux.alibaba.com> X-Mailer: git-send-email 2.19.1.6.gb485710b In-Reply-To: References: MIME-Version: 1.0 X-Spam-Status: No, score=-9.9 required=5.0 tests=BAYES_00, ENV_AND_HDR_SPF_MATCH,RCVD_IN_MSPIKE_H2,SPF_HELO_NONE,SPF_PASS, 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?1757246411529015003?= X-GMAIL-MSGID: =?utf-8?q?1757246411529015003?= Currently metadata is always on bootstrap, and thus device mapping is not needed so far. Remove the redundant device mapping in the meta routine. Signed-off-by: Jingbo Xu Reviewed-by: Jia Zhu --- fs/erofs/fscache.c | 17 ++++------------- 1 file changed, 4 insertions(+), 13 deletions(-) diff --git a/fs/erofs/fscache.c b/fs/erofs/fscache.c index 014e20962376..03de4dc99302 100644 --- a/fs/erofs/fscache.c +++ b/fs/erofs/fscache.c @@ -164,18 +164,8 @@ static int erofs_fscache_read_folios_async(struct fscache_cookie *cookie, static int erofs_fscache_meta_read_folio(struct file *data, struct folio *folio) { int ret; - struct super_block *sb = folio_mapping(folio)->host->i_sb; + struct erofs_fscache *ctx = folio_mapping(folio)->host->i_private; struct erofs_fscache_request *req; - struct erofs_map_dev mdev = { - .m_deviceid = 0, - .m_pa = folio_pos(folio), - }; - - ret = erofs_map_dev(sb, &mdev); - if (ret) { - folio_unlock(folio); - return ret; - } req = erofs_fscache_req_alloc(folio_mapping(folio), folio_pos(folio), folio_size(folio)); @@ -184,8 +174,8 @@ static int erofs_fscache_meta_read_folio(struct file *data, struct folio *folio) return PTR_ERR(req); } - ret = erofs_fscache_read_folios_async(mdev.m_fscache->cookie, - req, mdev.m_pa, folio_size(folio)); + ret = erofs_fscache_read_folios_async(ctx->cookie, req, + folio_pos(folio), folio_size(folio)); if (ret) req->error = ret; @@ -469,6 +459,7 @@ struct erofs_fscache *erofs_fscache_acquire_cookie(struct super_block *sb, inode->i_size = OFFSET_MAX; inode->i_mapping->a_ops = &erofs_fscache_meta_aops; mapping_set_gfp_mask(inode->i_mapping, GFP_NOFS); + inode->i_private = ctx; ctx->inode = inode; } From patchwork Wed Feb 8 07:16:23 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jingbo Xu X-Patchwork-Id: 54229 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:adf:eb09:0:0:0:0:0 with SMTP id s9csp3307690wrn; Tue, 7 Feb 2023 23:19:36 -0800 (PST) X-Google-Smtp-Source: AK7set9h90X0ZzokR/Y9BIsS0U60cEaoM8AK9YlC6ZSmSYi58O3HbL+u58PgTWno/OxKONQ5APH8 X-Received: by 2002:aa7:8f04:0:b0:5a8:47e5:bbad with SMTP id x4-20020aa78f04000000b005a847e5bbadmr489370pfr.28.1675840776055; Tue, 07 Feb 2023 23:19:36 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1675840776; cv=none; d=google.com; s=arc-20160816; b=iPxYSoMPlC0G+WBJ1pnixWj+8+dD8cEdrg49LSW+x54DuTUX5H71hCoGTXpLyloN1L 9c1SbwcwqayXVStifSWsAcxyBVjHzExB7U4nC/z8ffmTf49cPmD8jvxpa2iK1pfAQfAG tmVxdTKSkeoowS7Gn88WFL+Ykirx0YhH8mWuAtAE34HHm5a7T/RegOKBEvk7tjyl0wgB 42ylHq/2zIroDSB6yIh4O3M/22oqp+wQv7rikkXLg1YTz+L4j6c4e9713HAupR3fgcD9 iVdVHeRHXhjYm4bHg0B+CJ10m5CcEmGHfUS35U6FUzjt4sJaFipfOeTWA8MNlmmW54EQ ai+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=3z6Y53q8Q1Dii9Romofged574f7PbB1WxiL69hZV2H0=; b=KM9gKcy4VRulylCDhUShs7twSlDUa/KXsC7gDg5E31WKX6T0+5jHur6zTscrviwRug gK3xQ8RHu2OJtmvJ0F397m7Ou0WdmpTg4CJuCpZYaj4Of9jujniEoN0C8fG8tz6U9LQ3 4sVhNgxOEEk7hIkAM5Jix+6pH8DkK6Z3Iv31919v4s+Bep5UlNGMzHhU+PvxOS8beLcU 70MZgGGK5z62V614Efw9tquZuk8ymQK22uew0CsCEDOSp+QRqDJKuuqvZv8iLkgFkAV6 nlj9v949KJq5Xs0aQKVa7ktJXBNAOqeZDY05/FwbrTIFMYxPkEh9pBc7t4vEio/X6gGZ vOdg== 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 o9-20020a056a00214900b0058dea7e1e6esi16164563pfk.281.2023.02.07.23.19.23; Tue, 07 Feb 2023 23:19:36 -0800 (PST) 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 S230351AbjBHHQi (ORCPT + 99 others); Wed, 8 Feb 2023 02:16:38 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:46156 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230252AbjBHHQh (ORCPT ); Wed, 8 Feb 2023 02:16:37 -0500 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 0B24E30EAD for ; Tue, 7 Feb 2023 23:16:27 -0800 (PST) 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=6;SR=0;TI=SMTPD_---0VbAXJP5_1675840583; Received: from localhost(mailfrom:jefflexu@linux.alibaba.com fp:SMTPD_---0VbAXJP5_1675840583) by smtp.aliyun-inc.com; Wed, 08 Feb 2023 15:16:24 +0800 From: Jingbo Xu To: xiang@kernel.org, chao@kernel.org, linux-erofs@lists.ozlabs.org, zhujia.zj@bytedance.com Cc: huyue2@coolpad.com, linux-kernel@vger.kernel.org Subject: [PATCH 2/4] erofs: maintain cookies of share domain in self-contained list Date: Wed, 8 Feb 2023 15:16:23 +0800 Message-Id: <99618b85e5802aacf498387b48c61f1307c6f1f7.1675840368.git.jefflexu@linux.alibaba.com> X-Mailer: git-send-email 2.19.1.6.gb485710b In-Reply-To: References: MIME-Version: 1.0 X-Spam-Status: No, score=-9.9 required=5.0 tests=BAYES_00, ENV_AND_HDR_SPF_MATCH,SPF_HELO_NONE,SPF_PASS,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?1757246417438785718?= X-GMAIL-MSGID: =?utf-8?q?1757246417438785718?= We'd better not touch sb->s_inodes list and inode->i_count directly. Let's maintain cookies of share domain in a self-contained list in erofs. Besides, relinquish cookie with the mutext held. Otherwise if a cookie is registered when the old cookie with the same name in the same domain has been removed from the list but not relinquished yet, fscache may complain "Duplicate cookie detected". Signed-off-by: Jingbo Xu Reviewed-by: Jia Zhu --- fs/erofs/fscache.c | 48 ++++++++++++++++++++++----------------------- fs/erofs/internal.h | 4 ++++ 2 files changed, 27 insertions(+), 25 deletions(-) diff --git a/fs/erofs/fscache.c b/fs/erofs/fscache.c index 03de4dc99302..2f5930e177cc 100644 --- a/fs/erofs/fscache.c +++ b/fs/erofs/fscache.c @@ -7,8 +7,11 @@ #include "internal.h" static DEFINE_MUTEX(erofs_domain_list_lock); -static DEFINE_MUTEX(erofs_domain_cookies_lock); static LIST_HEAD(erofs_domain_list); + +static DEFINE_MUTEX(erofs_domain_cookies_lock); +static LIST_HEAD(erofs_domain_cookies_list); + static struct vfsmount *erofs_pseudo_mnt; struct erofs_fscache_request { @@ -318,8 +321,6 @@ const struct address_space_operations erofs_fscache_access_aops = { static void erofs_fscache_domain_put(struct erofs_domain *domain) { - if (!domain) - return; mutex_lock(&erofs_domain_list_lock); if (refcount_dec_and_test(&domain->ref)) { list_del(&domain->list); @@ -434,6 +435,8 @@ struct erofs_fscache *erofs_fscache_acquire_cookie(struct super_block *sb, ctx = kzalloc(sizeof(*ctx), GFP_KERNEL); if (!ctx) return ERR_PTR(-ENOMEM); + INIT_LIST_HEAD(&ctx->node); + refcount_set(&ctx->ref, 1); cookie = fscache_acquire_cookie(volume, FSCACHE_ADV_WANT_CACHE_SIZE, name, strlen(name), NULL, 0, 0); @@ -479,6 +482,7 @@ static void erofs_fscache_relinquish_cookie(struct erofs_fscache *ctx) fscache_unuse_cookie(ctx->cookie, NULL, NULL); fscache_relinquish_cookie(ctx->cookie, false); iput(ctx->inode); + iput(ctx->anon_inode); kfree(ctx->name); kfree(ctx); } @@ -511,6 +515,7 @@ struct erofs_fscache *erofs_fscache_domain_init_cookie(struct super_block *sb, ctx->domain = domain; ctx->anon_inode = inode; + list_add(&ctx->node, &erofs_domain_cookies_list); inode->i_private = ctx; refcount_inc(&domain->ref); return ctx; @@ -524,29 +529,23 @@ struct erofs_fscache *erofs_domain_register_cookie(struct super_block *sb, char *name, unsigned int flags) { - struct inode *inode; struct erofs_fscache *ctx; struct erofs_domain *domain = EROFS_SB(sb)->domain; - struct super_block *psb = erofs_pseudo_mnt->mnt_sb; mutex_lock(&erofs_domain_cookies_lock); - spin_lock(&psb->s_inode_list_lock); - list_for_each_entry(inode, &psb->s_inodes, i_sb_list) { - ctx = inode->i_private; - if (!ctx || ctx->domain != domain || strcmp(ctx->name, name)) + list_for_each_entry(ctx, &erofs_domain_cookies_list, node) { + if (ctx->domain != domain || strcmp(ctx->name, name)) continue; if (!(flags & EROFS_REG_COOKIE_NEED_NOEXIST)) { - igrab(inode); + refcount_inc(&ctx->ref); } else { erofs_err(sb, "%s already exists in domain %s", name, domain->domain_id); ctx = ERR_PTR(-EEXIST); } - spin_unlock(&psb->s_inode_list_lock); mutex_unlock(&erofs_domain_cookies_lock); return ctx; } - spin_unlock(&psb->s_inode_list_lock); ctx = erofs_fscache_domain_init_cookie(sb, name, flags); mutex_unlock(&erofs_domain_cookies_lock); return ctx; @@ -563,23 +562,22 @@ struct erofs_fscache *erofs_fscache_register_cookie(struct super_block *sb, void erofs_fscache_unregister_cookie(struct erofs_fscache *ctx) { - bool drop; - struct erofs_domain *domain; + struct erofs_domain *domain = NULL; if (!ctx) return; - domain = ctx->domain; - if (domain) { - mutex_lock(&erofs_domain_cookies_lock); - drop = atomic_read(&ctx->anon_inode->i_count) == 1; - iput(ctx->anon_inode); - mutex_unlock(&erofs_domain_cookies_lock); - if (!drop) - return; - } + if (!ctx->domain) + return erofs_fscache_relinquish_cookie(ctx); - erofs_fscache_relinquish_cookie(ctx); - erofs_fscache_domain_put(domain); + mutex_lock(&erofs_domain_cookies_lock); + if (refcount_dec_and_test(&ctx->ref)) { + domain = ctx->domain; + list_del(&ctx->node); + erofs_fscache_relinquish_cookie(ctx); + } + mutex_unlock(&erofs_domain_cookies_lock); + if (domain) + erofs_fscache_domain_put(domain); } int erofs_fscache_register_fs(struct super_block *sb) diff --git a/fs/erofs/internal.h b/fs/erofs/internal.h index 48a2f33de15a..8358cf5f731e 100644 --- a/fs/erofs/internal.h +++ b/fs/erofs/internal.h @@ -109,7 +109,11 @@ struct erofs_fscache { struct fscache_cookie *cookie; struct inode *inode; struct inode *anon_inode; + + /* used for share domain mode */ struct erofs_domain *domain; + struct list_head node; + refcount_t ref; char *name; }; From patchwork Wed Feb 8 07:16:28 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jingbo Xu X-Patchwork-Id: 54230 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:adf:eb09:0:0:0:0:0 with SMTP id s9csp3307789wrn; Tue, 7 Feb 2023 23:19:54 -0800 (PST) X-Google-Smtp-Source: AK7set/Dlw4Ul4ZBQNXdxpr96GQd8VKLOP295Kk9dfQUWchXCvfsUJp1wztRfdBe3+x1la5vorqX X-Received: by 2002:a05:6a21:300b:b0:bf:1f42:2b0 with SMTP id yd11-20020a056a21300b00b000bf1f4202b0mr4941253pzb.18.1675840793978; Tue, 07 Feb 2023 23:19:53 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1675840793; cv=none; d=google.com; s=arc-20160816; b=vFX+3YnmykTIqlvpu55CJ+uEYcq29DW60zLty3GCLSy35sQe1mFNGptKqS82HL/Wju 8I3fT5ICboYn0vCQbbE+0j/JrUHBLzD0HP8eNxlTEzNU4hRPnMlMPmPNgtzbwiRdtlNV 0k3qA/elcjp9LmnTEE1g++5WhVFKafnp916dpTLdKNiOwdo+HOttFrNbUdZNeeUHxDY5 mdpLkSc0ac3Hq2o4PLY9CVQqEVnhFaMYlrRSqTM0+YvnGPB58lxqAAvuYK3cXrekqAuU XmVnNBrFzIVEwJExoqEAu5cfaTQNuDBPA62jNXq7vazGakjw+wkZOULdn7beleHTyISS UxfQ== 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=3X8mPzVmLwuoY1gWyahAVFL8As9X2DWaGtVqViqvFRs=; b=Yy+YijNN4MCPllgoetVvAyYAOTZfUgoE6wxvhS7OOxW3hB89KhjVtuXrgKf0JZuwkq RFeppmMqRO9nblyg+7B1JxlEgxbUANft5RG5OIbC/aN5lGG0g/wWK/0vnXeAcdNOILc6 MV/J380Nod+iWJr4+Cn4V/zzf9yT/ncH4MjMxd4hFZRgsWV3dYw8j5JLqz0pGj0yuMdg CHmuZACjhZri7ETlnWx2gMHXYEeL7ZAi/x5K7tx2cgOwdnOuyNQpXtGlPGy/Ixf2TYXM IEASQVB5kJRs/P88v4Kn5vBvPFaJPL8ZTt0Y7o/vAuFIPa+4GsvNRNN5xtVWwX+Ctx0O 2ERQ== 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 r16-20020a638f50000000b00439d86cf509si16227510pgn.645.2023.02.07.23.19.41; Tue, 07 Feb 2023 23:19:53 -0800 (PST) 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 S230360AbjBHHQs (ORCPT + 99 others); Wed, 8 Feb 2023 02:16:48 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:46680 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230366AbjBHHQp (ORCPT ); Wed, 8 Feb 2023 02:16:45 -0500 Received: from out30-119.freemail.mail.aliyun.com (out30-119.freemail.mail.aliyun.com [115.124.30.119]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 9BEF33400D for ; Tue, 7 Feb 2023 23:16:33 -0800 (PST) X-Alimail-AntiSpam: AC=PASS;BC=-1|-1;BR=01201311R101e4;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=6;SR=0;TI=SMTPD_---0VbAhOmj_1675840589; Received: from localhost(mailfrom:jefflexu@linux.alibaba.com fp:SMTPD_---0VbAhOmj_1675840589) by smtp.aliyun-inc.com; Wed, 08 Feb 2023 15:16:29 +0800 From: Jingbo Xu To: xiang@kernel.org, chao@kernel.org, linux-erofs@lists.ozlabs.org, zhujia.zj@bytedance.com Cc: huyue2@coolpad.com, linux-kernel@vger.kernel.org Subject: [PATCH 3/4] erofs: unify anonymous inodes for blob Date: Wed, 8 Feb 2023 15:16:28 +0800 Message-Id: X-Mailer: git-send-email 2.19.1.6.gb485710b In-Reply-To: References: MIME-Version: 1.0 X-Spam-Status: No, score=-9.9 required=5.0 tests=BAYES_00, ENV_AND_HDR_SPF_MATCH,SPF_HELO_NONE,SPF_PASS,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?1757246436133476416?= X-GMAIL-MSGID: =?utf-8?q?1757246436133476416?= Currently there're two anonymous inodes (inode and anon_inode in struct erofs_fscache) for each blob. The former was introduced as the address_space of page cache for bootstrap. The latter was initially introduced as both the address_space of page cache and also a sentinel in the shared domain. Since now the management of cookies in share domain has been decoupled with the anonymous inode, there's no need to maintain an extra anonymous inode. Let's unify these two anonymous inodes. Besides, in non-share-domain mode only bootstrap will allocate anonymous inode. To simplify the implementation, always allocate anonymous inode for both bootstrap and data blobs. Similarly release anonymous inodes for data blobs when .put_super() is called, or we'll get "VFS: Busy inodes after unmount." warning. Also remove the redundant set_nlink() when initializing the anonymous inode, since i_nlink has already been initialized to 1 when the inode gets allocated. Signed-off-by: Jingbo Xu Reviewed-by: Jia Zhu --- fs/erofs/fscache.c | 70 ++++++++++++++++----------------------------- fs/erofs/internal.h | 6 ++-- fs/erofs/super.c | 2 ++ 3 files changed, 28 insertions(+), 50 deletions(-) diff --git a/fs/erofs/fscache.c b/fs/erofs/fscache.c index 2f5930e177cc..8353a5fe8c71 100644 --- a/fs/erofs/fscache.c +++ b/fs/erofs/fscache.c @@ -424,12 +424,12 @@ static int erofs_fscache_register_domain(struct super_block *sb) static struct erofs_fscache *erofs_fscache_acquire_cookie(struct super_block *sb, - char *name, - unsigned int flags) + struct super_block *isb, char *name) { struct fscache_volume *volume = EROFS_SB(sb)->volume; struct erofs_fscache *ctx; struct fscache_cookie *cookie; + struct inode *inode; int ret; ctx = kzalloc(sizeof(*ctx), GFP_KERNEL); @@ -445,33 +445,27 @@ struct erofs_fscache *erofs_fscache_acquire_cookie(struct super_block *sb, ret = -EINVAL; goto err; } - fscache_use_cookie(cookie, false); - ctx->cookie = cookie; - - if (flags & EROFS_REG_COOKIE_NEED_INODE) { - struct inode *const inode = new_inode(sb); - - if (!inode) { - erofs_err(sb, "failed to get anon inode for %s", name); - ret = -ENOMEM; - goto err_cookie; - } - - set_nlink(inode, 1); - inode->i_size = OFFSET_MAX; - inode->i_mapping->a_ops = &erofs_fscache_meta_aops; - mapping_set_gfp_mask(inode->i_mapping, GFP_NOFS); - inode->i_private = ctx; - ctx->inode = inode; + inode = new_inode(isb); + if (!inode) { + erofs_err(sb, "failed to get anon inode for %s", name); + ret = -ENOMEM; + goto err_cookie; } + inode->i_size = OFFSET_MAX; + inode->i_mapping->a_ops = &erofs_fscache_meta_aops; + mapping_set_gfp_mask(inode->i_mapping, GFP_NOFS); + inode->i_private = ctx; + + ctx->cookie = cookie; + ctx->inode = inode; return ctx; err_cookie: - fscache_unuse_cookie(ctx->cookie, NULL, NULL); - fscache_relinquish_cookie(ctx->cookie, false); + fscache_unuse_cookie(cookie, NULL, NULL); + fscache_relinquish_cookie(cookie, false); err: kfree(ctx); return ERR_PTR(ret); @@ -482,46 +476,31 @@ static void erofs_fscache_relinquish_cookie(struct erofs_fscache *ctx) fscache_unuse_cookie(ctx->cookie, NULL, NULL); fscache_relinquish_cookie(ctx->cookie, false); iput(ctx->inode); - iput(ctx->anon_inode); kfree(ctx->name); kfree(ctx); } static struct erofs_fscache *erofs_fscache_domain_init_cookie(struct super_block *sb, - char *name, - unsigned int flags) + char *name) { - int err; - struct inode *inode; struct erofs_fscache *ctx; struct erofs_domain *domain = EROFS_SB(sb)->domain; - ctx = erofs_fscache_acquire_cookie(sb, name, flags); + ctx = erofs_fscache_acquire_cookie(sb, erofs_pseudo_mnt->mnt_sb, name); if (IS_ERR(ctx)) return ctx; ctx->name = kstrdup(name, GFP_KERNEL); if (!ctx->name) { - err = -ENOMEM; - goto out; - } - - inode = new_inode(erofs_pseudo_mnt->mnt_sb); - if (!inode) { - err = -ENOMEM; - goto out; + erofs_fscache_relinquish_cookie(ctx); + return ERR_PTR(-ENOMEM); } + refcount_inc(&domain->ref); ctx->domain = domain; - ctx->anon_inode = inode; list_add(&ctx->node, &erofs_domain_cookies_list); - inode->i_private = ctx; - refcount_inc(&domain->ref); return ctx; -out: - erofs_fscache_relinquish_cookie(ctx); - return ERR_PTR(err); } static @@ -546,7 +525,7 @@ struct erofs_fscache *erofs_domain_register_cookie(struct super_block *sb, mutex_unlock(&erofs_domain_cookies_lock); return ctx; } - ctx = erofs_fscache_domain_init_cookie(sb, name, flags); + ctx = erofs_fscache_domain_init_cookie(sb, name); mutex_unlock(&erofs_domain_cookies_lock); return ctx; } @@ -557,7 +536,7 @@ struct erofs_fscache *erofs_fscache_register_cookie(struct super_block *sb, { if (EROFS_SB(sb)->domain_id) return erofs_domain_register_cookie(sb, name, flags); - return erofs_fscache_acquire_cookie(sb, name, flags); + return erofs_fscache_acquire_cookie(sb, sb, name); } void erofs_fscache_unregister_cookie(struct erofs_fscache *ctx) @@ -585,7 +564,7 @@ int erofs_fscache_register_fs(struct super_block *sb) int ret; struct erofs_sb_info *sbi = EROFS_SB(sb); struct erofs_fscache *fscache; - unsigned int flags; + unsigned int flags = 0; if (sbi->domain_id) ret = erofs_fscache_register_domain(sb); @@ -604,7 +583,6 @@ int erofs_fscache_register_fs(struct super_block *sb) * * Acquired domain/volume will be relinquished in kill_sb() on error. */ - flags = EROFS_REG_COOKIE_NEED_INODE; if (sbi->domain_id) flags |= EROFS_REG_COOKIE_NEED_NOEXIST; fscache = erofs_fscache_register_cookie(sb, sbi->fsid, flags); diff --git a/fs/erofs/internal.h b/fs/erofs/internal.h index 8358cf5f731e..125e4aa8d295 100644 --- a/fs/erofs/internal.h +++ b/fs/erofs/internal.h @@ -107,8 +107,7 @@ struct erofs_domain { struct erofs_fscache { struct fscache_cookie *cookie; - struct inode *inode; - struct inode *anon_inode; + struct inode *inode; /* anonymous indoe for the blob */ /* used for share domain mode */ struct erofs_domain *domain; @@ -450,8 +449,7 @@ extern const struct file_operations erofs_dir_fops; extern const struct iomap_ops z_erofs_iomap_report_ops; /* flags for erofs_fscache_register_cookie() */ -#define EROFS_REG_COOKIE_NEED_INODE 1 -#define EROFS_REG_COOKIE_NEED_NOEXIST 2 +#define EROFS_REG_COOKIE_NEED_NOEXIST 1 void erofs_unmap_metabuf(struct erofs_buf *buf); void erofs_put_metabuf(struct erofs_buf *buf); diff --git a/fs/erofs/super.c b/fs/erofs/super.c index 715efa94eed4..19b1ae79cec4 100644 --- a/fs/erofs/super.c +++ b/fs/erofs/super.c @@ -968,6 +968,8 @@ static void erofs_put_super(struct super_block *sb) 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 Wed Feb 8 07:17:15 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jingbo Xu X-Patchwork-Id: 54236 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:adf:eb09:0:0:0:0:0 with SMTP id s9csp3308790wrn; Tue, 7 Feb 2023 23:22:38 -0800 (PST) X-Google-Smtp-Source: AK7set+KEOvjNFpTi7BdboQ5fbDHyHNSQhIWUsd4IrFfFoiUpk/oBuMsQNequT52CvK34Cgi3rvR X-Received: by 2002:a17:902:c649:b0:199:1160:9564 with SMTP id s9-20020a170902c64900b0019911609564mr4778358pls.45.1675840958240; Tue, 07 Feb 2023 23:22:38 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1675840958; cv=none; d=google.com; s=arc-20160816; b=uRbHAL/a76Sq7c2skOpXQ6ZU5xOY4fTwY3nba6kMyYYV/YOJH4g07yMbrG8+CoWkEV eDI9bkSHDWRto4YYJay7TMDFae0RCq4+YRGg428kxgRhiJmgkfnMSjfME48EOEbEGszP LRttaZFa4aaGik8HcNqo48dY2Yo7ajz796WsEpeZfgx4RAFm2Vk1npDrOtmKnH3LSzKd d+nXC41M1yXkPmqSYwm/L/h0lw5oRZFGB9lOJJA8EvfWNQRSNIAOG6D1cijdTzL4QMWA u5qhX2q49R2uB5BgZ+Cxq0dxb080BuA8T3wvkK9yKXRfEkmezT90QtyX1hT2spSogoJI 8pWg== 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=S02yTf8CrEw8M+RxdMBDPeMrybs9jY2JSJVR+sGVeiE=; b=ro624kZaocFXWu6FarRpX6hGclwHG99hveMwVlgtpm6aAL/aEdDXZHmtw8JUqxi4WU 33DRflnfZH9/UHGMXGoARWQQ9mzSU9u+GD7+ADD0uh0d+2faMPeAlMyXyzUdiqUMkkgW 8n7WKnhjg7FIYtJTelXTG/wXaIXqtyB0f0g8gpSFLLanO9CxzNIlNZhGUxazuOxerzjY exjZXrFXjYiGB5ujBxSvC3/VAiBUF45bW5nUmcsq2yv98ihg9JDisVhS3/6OEnc+12yR 0rKuC6jEFPt3t5HcdKU9T5Akx+FWjPelTu8mEyoVz8uqekAZKLg5ZjUCwQiJ7wfHdy8C dU7A== 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 bi3-20020a170902bf0300b0019479636f8csi4700856plb.20.2023.02.07.23.22.25; Tue, 07 Feb 2023 23:22:38 -0800 (PST) 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 S229557AbjBHHSN (ORCPT + 99 others); Wed, 8 Feb 2023 02:18:13 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:47502 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230252AbjBHHR7 (ORCPT ); Wed, 8 Feb 2023 02:17:59 -0500 Received: from out30-132.freemail.mail.aliyun.com (out30-132.freemail.mail.aliyun.com [115.124.30.132]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id A0F5821A34 for ; Tue, 7 Feb 2023 23:17:32 -0800 (PST) X-Alimail-AntiSpam: AC=PASS;BC=-1|-1;BR=01201311R211e4;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=7;SR=0;TI=SMTPD_---0VbAZ945_1675840635; Received: from localhost(mailfrom:jefflexu@linux.alibaba.com fp:SMTPD_---0VbAZ945_1675840635) by smtp.aliyun-inc.com; Wed, 08 Feb 2023 15:17:16 +0800 From: Jingbo Xu To: xiang@kernel.org, chao@kernel.org, linux-erofs@lists.ozlabs.org, zhujia.zj@bytedance.com, houtao1@huawei.com Cc: huyue2@coolpad.com, linux-kernel@vger.kernel.org Subject: [PATCH 4/4] erofs: simplify the name collision checking in share domain mode Date: Wed, 8 Feb 2023 15:17:15 +0800 Message-Id: <489d47915bcc71ef3c3ec7b8a437ec6e09c4c3db.1675840368.git.jefflexu@linux.alibaba.com> X-Mailer: git-send-email 2.19.1.6.gb485710b In-Reply-To: References: 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,RCVD_IN_MSPIKE_H2, SPF_HELO_NONE,SPF_PASS,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?1757246608365898698?= X-GMAIL-MSGID: =?utf-8?q?1757246608365898698?= When share domain is enabled, data blobs can be shared among filesystem instances in the same domain for data deduplication, while bootstrap blobs are always dedicated to the corresponding filesystem instance, and have no need to be shared. In the initial implementation of share domain (commit 7d41963759fe ("erofs: Support sharing cookies in the same domain")), bootstrap blobs are also in the share domain, and thus can be referenced by the following filesystem instances. In this case, mounting twice with the same fsid and domain_id will trigger warning in sysfs. Commit 27f2a2dcc626 ("erofs: check the uniqueness of fsid in shared domain in advance") fixes this by introducing the name collision checking. This patch attempts to fix the above issue in another simpler way. Since the bootstrap blobs have no need to be shared, move them out of the share domain, so that one bootstrap blob can not be referenced by other filesystem instances. Attempt to mount twice with the same fsid and domain_id will fail with info of duplicate cookies, which is consistent with the behavior in non-share-domain mode. Signed-off-by: Jingbo Xu Reviewed-by: Jia Zhu --- fs/erofs/fscache.c | 36 ++++++++---------------------------- fs/erofs/internal.h | 4 ++-- fs/erofs/super.c | 2 +- 3 files changed, 11 insertions(+), 31 deletions(-) diff --git a/fs/erofs/fscache.c b/fs/erofs/fscache.c index 8353a5fe8c71..8da6e05e9d23 100644 --- a/fs/erofs/fscache.c +++ b/fs/erofs/fscache.c @@ -505,25 +505,18 @@ struct erofs_fscache *erofs_fscache_domain_init_cookie(struct super_block *sb, static struct erofs_fscache *erofs_domain_register_cookie(struct super_block *sb, - char *name, - unsigned int flags) + char *name) { struct erofs_fscache *ctx; struct erofs_domain *domain = EROFS_SB(sb)->domain; mutex_lock(&erofs_domain_cookies_lock); list_for_each_entry(ctx, &erofs_domain_cookies_list, node) { - if (ctx->domain != domain || strcmp(ctx->name, name)) - continue; - if (!(flags & EROFS_REG_COOKIE_NEED_NOEXIST)) { + if (ctx->domain == domain && !strcmp(ctx->name, name)) { refcount_inc(&ctx->ref); - } else { - erofs_err(sb, "%s already exists in domain %s", name, - domain->domain_id); - ctx = ERR_PTR(-EEXIST); + mutex_unlock(&erofs_domain_cookies_lock); + return ctx; } - mutex_unlock(&erofs_domain_cookies_lock); - return ctx; } ctx = erofs_fscache_domain_init_cookie(sb, name); mutex_unlock(&erofs_domain_cookies_lock); @@ -531,11 +524,10 @@ struct erofs_fscache *erofs_domain_register_cookie(struct super_block *sb, } struct erofs_fscache *erofs_fscache_register_cookie(struct super_block *sb, - char *name, - unsigned int flags) + char *name) { if (EROFS_SB(sb)->domain_id) - return erofs_domain_register_cookie(sb, name, flags); + return erofs_domain_register_cookie(sb, name); return erofs_fscache_acquire_cookie(sb, sb, name); } @@ -564,7 +556,6 @@ int erofs_fscache_register_fs(struct super_block *sb) int ret; struct erofs_sb_info *sbi = EROFS_SB(sb); struct erofs_fscache *fscache; - unsigned int flags = 0; if (sbi->domain_id) ret = erofs_fscache_register_domain(sb); @@ -573,19 +564,8 @@ int erofs_fscache_register_fs(struct super_block *sb) if (ret) return ret; - /* - * When shared domain is enabled, using NEED_NOEXIST to guarantee - * the primary data blob (aka fsid) is unique in the shared domain. - * - * For non-shared-domain case, fscache_acquire_volume() invoked by - * erofs_fscache_register_volume() has already guaranteed - * the uniqueness of primary data blob. - * - * Acquired domain/volume will be relinquished in kill_sb() on error. - */ - if (sbi->domain_id) - flags |= EROFS_REG_COOKIE_NEED_NOEXIST; - fscache = erofs_fscache_register_cookie(sb, sbi->fsid, flags); + /* acquired domain/volume will be relinquished in kill_sb() on error */ + fscache = erofs_fscache_acquire_cookie(sb, sb, sbi->fsid); if (IS_ERR(fscache)) return PTR_ERR(fscache); diff --git a/fs/erofs/internal.h b/fs/erofs/internal.h index 125e4aa8d295..fded736bc3d5 100644 --- a/fs/erofs/internal.h +++ b/fs/erofs/internal.h @@ -570,7 +570,7 @@ int erofs_fscache_register_fs(struct super_block *sb); void erofs_fscache_unregister_fs(struct super_block *sb); struct erofs_fscache *erofs_fscache_register_cookie(struct super_block *sb, - char *name, unsigned int flags); + char *name); void erofs_fscache_unregister_cookie(struct erofs_fscache *fscache); #else static inline int erofs_fscache_register_fs(struct super_block *sb) @@ -581,7 +581,7 @@ static inline void erofs_fscache_unregister_fs(struct super_block *sb) {} static inline struct erofs_fscache *erofs_fscache_register_cookie(struct super_block *sb, - char *name, unsigned int flags) + char *name) { return ERR_PTR(-EOPNOTSUPP); } diff --git a/fs/erofs/super.c b/fs/erofs/super.c index 19b1ae79cec4..8706ca34f26a 100644 --- a/fs/erofs/super.c +++ b/fs/erofs/super.c @@ -244,7 +244,7 @@ static int erofs_init_device(struct erofs_buf *buf, struct super_block *sb, } if (erofs_is_fscache_mode(sb)) { - fscache = erofs_fscache_register_cookie(sb, dif->path, 0); + fscache = erofs_fscache_register_cookie(sb, dif->path); if (IS_ERR(fscache)) return PTR_ERR(fscache); dif->fscache = fscache;