From patchwork Thu Feb 9 05:18:35 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jingbo Xu X-Patchwork-Id: 54730 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:adf:eb09:0:0:0:0:0 with SMTP id s9csp137762wrn; Wed, 8 Feb 2023 21:20:55 -0800 (PST) X-Google-Smtp-Source: AK7set+nhkr58dd474hq4W7sOJFbwtrxpMGo3Zx2T+Dboq3QSju1n+oz2U9r3t/9Wgu6AOvAtU+z X-Received: by 2002:a17:906:3ecf:b0:879:9c05:f5e8 with SMTP id d15-20020a1709063ecf00b008799c05f5e8mr10344718ejj.62.1675920055053; Wed, 08 Feb 2023 21:20:55 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1675920055; cv=none; d=google.com; s=arc-20160816; b=eZyeqJtLhYS8zJqN5cblukG2zOHv7kgNkXtjn+EF/sxpLhdpIXjHSMu8GV6/MUxrPn GDTHU4WWolYPZ3fUhI5njYR5Pbw+fK8snzFJ4+tzwE2VuBLXsgWqjFswhu4m76HsY0eY /katzIOZNXj10mhkVpeghfPUPbFxJnTLm21BF7Z/ySr8HHGhTQ2pHq5QaACp2uLoBYDf qQjVp7h0fsHAHIAQ0gX4fXoPBvj6j/urf9AZS3leDpO4piFV6qel6e0er8jJmxeH+RVX T8djsGF1ICTaEoCE2zjKGZI5dsA4KriKtcgKZGl6xpxaLz7/AKKUC/VwEXdBbcoKGCxT 16vQ== 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=jDaQh2pKYc3xVR17x/HLWJKDwErYRaGztfVmN+F9j1I=; b=vfI0zCoeuqbQhw8p6KfCnQgg3BSCYo0XkCIF4oSNUv+Bq7HwleyLwyri+/ppkHF7HC TNg0WyPUsUwMxnRGwl8Mhb7xB6efNoPQUGTBPuuQ8Dh4FS3gJc/CUgFBiTPtpHlqHglB 8kR4+y3Ik1ABkc1FGQLneL9EwYh04R9Vd81KDGX2fIYbZzrYnw5Can4bBBk3QLHPryFP nTixitrkRJWxlj22Q5DIQEXfj5MdyvJ5DdRPTUc8neMmTnmeTVL8zClOtwPx6j7IJ0Rt py6RkBrNc0cq31nZKQzFBnDD+dF0tXP2ezEYL2YNoUJoNBjxoL7DQjNHCN5MRAfXtLzR kCfg== 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 p15-20020a170907910f00b008787b6dd91bsi1140719ejq.493.2023.02.08.21.20.32; Wed, 08 Feb 2023 21:20:55 -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 S229862AbjBIFSv (ORCPT + 99 others); Thu, 9 Feb 2023 00:18:51 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:60800 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229738AbjBIFSs (ORCPT ); Thu, 9 Feb 2023 00:18:48 -0500 Received: from out30-113.freemail.mail.aliyun.com (out30-113.freemail.mail.aliyun.com [115.124.30.113]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 6A0AE2CC7A for ; Wed, 8 Feb 2023 21:18:43 -0800 (PST) X-Alimail-AntiSpam: AC=PASS;BC=-1|-1;BR=01201311R591e4;CH=green;DM=||false|;DS=||;FP=0|-1|-1|-1|0|-1|-1|-1;HT=ay29a033018045170;MF=jefflexu@linux.alibaba.com;NM=1;PH=DS;RN=6;SR=0;TI=SMTPD_---0VbEauiy_1675919919; Received: from localhost(mailfrom:jefflexu@linux.alibaba.com fp:SMTPD_---0VbEauiy_1675919919) by smtp.aliyun-inc.com; Thu, 09 Feb 2023 13:18:39 +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 v2 1/4] erofs: remove unused device mapping in meta routine Date: Thu, 9 Feb 2023 13:18:35 +0800 Message-Id: <20230209051838.33297-2-jefflexu@linux.alibaba.com> X-Mailer: git-send-email 2.19.1.6.gb485710b In-Reply-To: <20230209051838.33297-1-jefflexu@linux.alibaba.com> References: <20230209051838.33297-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,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?1757329547815162034?= X-GMAIL-MSGID: =?utf-8?q?1757329547815162034?= 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 Thu Feb 9 05:18:36 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jingbo Xu X-Patchwork-Id: 54731 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:adf:eb09:0:0:0:0:0 with SMTP id s9csp138046wrn; Wed, 8 Feb 2023 21:21:42 -0800 (PST) X-Google-Smtp-Source: AK7set/O+km2pAo4GdIORdWzh5LBp+rg4a7zNz8iPAHKYIfPKgWxKo6dy/jjT/RhVyT/BaS85fn6 X-Received: by 2002:a17:906:fe4c:b0:8aa:be5c:b7c5 with SMTP id wz12-20020a170906fe4c00b008aabe5cb7c5mr9295564ejb.41.1675920102542; Wed, 08 Feb 2023 21:21:42 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1675920102; cv=none; d=google.com; s=arc-20160816; b=pZj/YMKlV4EYLu7cVQ2EzXPnUEC0Jt1RWK7sanByGn5HpvFwhOVXuVLU1OG/s4u/Uc xrE9bkl8B3zkSaJNmP6LrwiaoiBtn09NdJ7RdhfIlYZx8AIBDPXq13mqV/Y2VS/ZWKaU S8gpjCL8tjMu4awwmBSh+8G9mrPflUxaXHg3+FGdg6YQJkt6LsFdGnZuDF/KNB/VhYlJ 5ahH8RXu9jHBS9BO4kv+1cEkCcP6WQPczMONSGEYkzfW+gOzMM1jmfiS8YTEhHV77T1s q8s5ZuTA08ZUzCAFkSb9XYnt5+WlPtYYgeYVRu41ccw4NCNory40zKY8hgsL5HUKtRov W/5g== 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=uRrX5N75p5c7BcaGFsVc/ovyyCQVoeKsg5dR3ximrl0=; b=T4IxRAOiNo6atyR8VYmsORpg2ylbfUdkrnabMOVhF9mp34vazNX8WenDZQjNxvh7qv uGJtUddnpeD8cfWc6r0Htf2JFWEkD2k1WpeCBd2bHKN5ZKc/o4yOZgHXbmSNYmL9nKlK 04Wkq6ZUhS8zwmzDlqLN2edMwiua8yzIYl3MSctYJ9HbKMNBSdqSo8l7YCCW+IpDPk2V A3aac7leKOqUwUFBdi6FXvxkGpMi9zJez8fgvna6dwAJ5bhA63aCRYzS/4Gs7VXRzz23 1nvRzFyBPEQP0SeI74rIkYiVNifR6jYgZ57qQnz+map3k1lZ+pyucGN3jJS1HX+frbbd Uoyg== 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 30-20020a170906209e00b0088b3d988a48si1237162ejq.501.2023.02.08.21.21.20; Wed, 08 Feb 2023 21:21:42 -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 S230011AbjBIFSx (ORCPT + 99 others); Thu, 9 Feb 2023 00:18:53 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:60798 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229739AbjBIFSs (ORCPT ); Thu, 9 Feb 2023 00:18:48 -0500 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 C20C42CFF5 for ; Wed, 8 Feb 2023 21:18:42 -0800 (PST) X-Alimail-AntiSpam: AC=PASS;BC=-1|-1;BR=01201311R191e4;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_---0VbEc.CR_1675919919; Received: from localhost(mailfrom:jefflexu@linux.alibaba.com fp:SMTPD_---0VbEc.CR_1675919919) by smtp.aliyun-inc.com; Thu, 09 Feb 2023 13:18:40 +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 v2 2/4] erofs: maintain cookies of share domain in self-contained list Date: Thu, 9 Feb 2023 13:18:36 +0800 Message-Id: <20230209051838.33297-3-jefflexu@linux.alibaba.com> X-Mailer: git-send-email 2.19.1.6.gb485710b In-Reply-To: <20230209051838.33297-1-jefflexu@linux.alibaba.com> References: <20230209051838.33297-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_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?1757329597298722771?= X-GMAIL-MSGID: =?utf-8?q?1757329597298722771?= 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 mutex 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 Thu Feb 9 05:18:37 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jingbo Xu X-Patchwork-Id: 54732 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:adf:eb09:0:0:0:0:0 with SMTP id s9csp138152wrn; Wed, 8 Feb 2023 21:22:01 -0800 (PST) X-Google-Smtp-Source: AK7set+Ge8MtkKbhMDCYjqm4oPKCSPo7USPi4PHEf7dw/8VTQMd9E0CR8859zitM9gCxqnjbAcSW X-Received: by 2002:a17:907:c12:b0:866:6b08:946b with SMTP id ga18-20020a1709070c1200b008666b08946bmr16353601ejc.39.1675920121252; Wed, 08 Feb 2023 21:22:01 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1675920121; cv=none; d=google.com; s=arc-20160816; b=o0IH54eU858WXqSm/GuFcgPOxxn0WWq/Eb8X3qLaZMNlB+srwC6oJsmbNUdY2UbFxr K4fXXyebI4SGxlkHxRcIUS61K75abWQGx0QbzLZd6MMnjgi95xJILg0X4NjMjZrxujWl y3lUFtzYjVNIyZpPexulclMSprxpCWrYtd4Fu10pMUJC9Lpr65OzcVfOiXdsIUqRGqiF fcTuwm/GVfTgsJUWFSjPgFv4OILRk9hupzD/sSYRmKd20EnOTN7Yj71nx+O1DT6uc2kl FTsRXc02OIRZAgOS35A7FjpsZFSySXUiXqqdgw+UgrA0rsxe2sOry0XwH4t8N1dvJcAS f4ow== 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=Ojn4WbIebvtU/AuKHd8GFk+3oL+Lg8S06yrPxc+pEtA=; b=F9jhISMt45aVWXZXKIq1U9w5O6TH3RuNHn2Mmm3JxCwIdwQ2OLS6UucOHVOW+9LhnS rK8q8j8NYimzDy5XIDFLHABysENJgmbTpxbBU3+MBIZQQJwRBpzZIWnUClAmVmjB7Bs9 r6ZocF57M1sXrBz1PqefeiECl4nvWv5fZIZBnVBXQpY3Z0L57ahBQrzkUMr/b+a29K8F 6KfOZ/hDnZu2LOpouBX2gU0jH/XVmNLvAAsb00DYlLnTENmjJoKipOMNLZQxvWVEq43Y SoYUJ2bh9RfWSMOqjdtXYuLPgGIW8R1IZMF8A2x0vZiMzBU72M1S/Wn58U2ORaukAr90 gpZA== 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 m23-20020aa7d357000000b004a129012df6si1060889edr.150.2023.02.08.21.21.38; Wed, 08 Feb 2023 21:22:01 -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 S229711AbjBIFTD (ORCPT + 99 others); Thu, 9 Feb 2023 00:19:03 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:60804 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229743AbjBIFSu (ORCPT ); Thu, 9 Feb 2023 00:18:50 -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 D92452D15C for ; Wed, 8 Feb 2023 21:18:44 -0800 (PST) X-Alimail-AntiSpam: AC=PASS;BC=-1|-1;BR=01201311R191e4;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=6;SR=0;TI=SMTPD_---0VbEaujl_1675919920; Received: from localhost(mailfrom:jefflexu@linux.alibaba.com fp:SMTPD_---0VbEaujl_1675919920) by smtp.aliyun-inc.com; Thu, 09 Feb 2023 13:18:41 +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 v2 3/4] erofs: relinquish volume with mutex held Date: Thu, 9 Feb 2023 13:18:37 +0800 Message-Id: <20230209051838.33297-4-jefflexu@linux.alibaba.com> X-Mailer: git-send-email 2.19.1.6.gb485710b In-Reply-To: <20230209051838.33297-1-jefflexu@linux.alibaba.com> References: <20230209051838.33297-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_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?1757329616705670651?= X-GMAIL-MSGID: =?utf-8?q?1757329616705670651?= Relinquish fscache volume with mutex held. Otherwise if a new domain is registered when the old domain with the same name gets removed from the list but not relinquished yet, fscache may complain the collision. Signed-off-by: Jingbo Xu Reviewed-by: Jia Zhu --- fs/erofs/fscache.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/fs/erofs/fscache.c b/fs/erofs/fscache.c index 2f5930e177cc..a6f030966147 100644 --- a/fs/erofs/fscache.c +++ b/fs/erofs/fscache.c @@ -328,8 +328,8 @@ static void erofs_fscache_domain_put(struct erofs_domain *domain) kern_unmount(erofs_pseudo_mnt); erofs_pseudo_mnt = NULL; } - mutex_unlock(&erofs_domain_list_lock); fscache_relinquish_volume(domain->volume, NULL, false); + mutex_unlock(&erofs_domain_list_lock); kfree(domain->domain_id); kfree(domain); return; From patchwork Thu Feb 9 05:18:38 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jingbo Xu X-Patchwork-Id: 54734 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:adf:eb09:0:0:0:0:0 with SMTP id s9csp138585wrn; Wed, 8 Feb 2023 21:23:01 -0800 (PST) X-Google-Smtp-Source: AK7set/bn80ByhblBPMPj8tCQd+jwsERKL9HS4dJXUDwTGv9QaoOsUlZs4zYKi6wNgXwZIgkiS7F X-Received: by 2002:a17:907:8686:b0:8aa:be85:fc56 with SMTP id qa6-20020a170907868600b008aabe85fc56mr9728887ejc.47.1675920181155; Wed, 08 Feb 2023 21:23:01 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1675920181; cv=none; d=google.com; s=arc-20160816; b=stJsneOLVh1NyZ84k+RKr5+4xyYGoZhwu2nhk3dBjzBL/ORpKjvrGjeqBu3EVYFgwd 3yqLt2F43dx3bzB62zPIPdCTXhgW5Jq3wmZVYXGqzJEXLNnJUBnzzwjTDH3uz7nMFZFi u8nDBf/G3jHtaRMCmGWFVmIk1IIxdJPrHao2u8f/G56ugxMg/6hUChWw2/4q2SSIJxX5 dC46FoM2auL0T3bK57Sz/c26GpykRR26cttmzFKbCnfOPFaD64fhoyhkFml14z8kb8cx ytIoVNx2rt9xBCKgIAA6jaeN6N0lkwOeG0gMC+vdGi6D8ikeaUOCmDIKX2/2N61AdMw3 qbOA== 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=EgTGAIRuz+TwuNBsq9y90S82RUYXUC/Lnoq6lAj2hi8=; b=XgGj7N2HbqLu0ut3NZIRiYuIXn2iFVYj0oTkh5kovCbErs0t5m4graCazrDHb298Rl A8kopu88TvAGSQyW5ny7gC++PFLGJmTh0C/II4WpXkBisFlb5SAxoQwYrfhmBV+ITeQw Y7c2/SH3yGjLKiX0lfgQwFIyJF3oxZmakFjT9XvsG4xjJTmNxP4K66ONZ0jGuk2yLNA9 jfWxKFc4L5gk2UY5s0dVenasVa7g1hiYa9hEJ2lvkbVTrJsBrxtyWsNFGIl9oOKWRw2W Y+MpuZiapQGGs5Olj2PFoANDI7/iXDGM9Z9t0LG+/+I/5yNbcEUBuzpeSxnr/RPpSdkA 31sA== 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 v11-20020a17090610cb00b00877e020053csi1191424ejv.740.2023.02.08.21.22.37; Wed, 08 Feb 2023 21:23:01 -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 S230173AbjBIFTA (ORCPT + 99 others); Thu, 9 Feb 2023 00:19:00 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:60806 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229765AbjBIFSu (ORCPT ); Thu, 9 Feb 2023 00:18:50 -0500 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 08ACE2D168 for ; Wed, 8 Feb 2023 21:18:45 -0800 (PST) X-Alimail-AntiSpam: AC=PASS;BC=-1|-1;BR=01201311R271e4;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_---0VbEaZFw_1675919921; Received: from localhost(mailfrom:jefflexu@linux.alibaba.com fp:SMTPD_---0VbEaZFw_1675919921) by smtp.aliyun-inc.com; Thu, 09 Feb 2023 13:18:42 +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 v2 4/4] erofs: unify anonymous inodes for blob Date: Thu, 9 Feb 2023 13:18:38 +0800 Message-Id: <20230209051838.33297-5-jefflexu@linux.alibaba.com> X-Mailer: git-send-email 2.19.1.6.gb485710b In-Reply-To: <20230209051838.33297-1-jefflexu@linux.alibaba.com> References: <20230209051838.33297-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,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?1757329679477677470?= X-GMAIL-MSGID: =?utf-8?q?1757329679477677470?= 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 | 85 ++++++++++++++++++--------------------------- fs/erofs/internal.h | 7 ++-- fs/erofs/super.c | 2 ++ 3 files changed, 38 insertions(+), 56 deletions(-) diff --git a/fs/erofs/fscache.c b/fs/erofs/fscache.c index a6f030966147..a9498239163a 100644 --- a/fs/erofs/fscache.c +++ b/fs/erofs/fscache.c @@ -422,14 +422,14 @@ static int erofs_fscache_register_domain(struct super_block *sb) return err; } -static -struct erofs_fscache *erofs_fscache_acquire_cookie(struct super_block *sb, - char *name, - unsigned int flags) +static struct erofs_fscache *erofs_fscache_acquire_cookie(struct super_block *sb, + char *name, unsigned int flags) { struct fscache_volume *volume = EROFS_SB(sb)->volume; struct erofs_fscache *ctx; struct fscache_cookie *cookie; + struct super_block *isb; + struct inode *inode; int ret; ctx = kzalloc(sizeof(*ctx), GFP_KERNEL); @@ -445,33 +445,32 @@ 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; + /* + * Allocate anonymous inode in global pseudo mount for shareable blobs, + * so that they are accessible among erofs fs instances. + */ + isb = flags & EROFS_REG_COOKIE_SHARE ? erofs_pseudo_mnt->mnt_sb : sb; + 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,18 +481,13 @@ 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) +static struct erofs_fscache *erofs_domain_init_cookie(struct super_block *sb, + char *name, unsigned int flags) { - int err; - struct inode *inode; struct erofs_fscache *ctx; struct erofs_domain *domain = EROFS_SB(sb)->domain; @@ -503,35 +497,23 @@ struct erofs_fscache *erofs_fscache_domain_init_cookie(struct super_block *sb, 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 -struct erofs_fscache *erofs_domain_register_cookie(struct super_block *sb, - char *name, - unsigned int flags) +static struct erofs_fscache *erofs_domain_register_cookie(struct super_block *sb, + char *name, unsigned int flags) { struct erofs_fscache *ctx; struct erofs_domain *domain = EROFS_SB(sb)->domain; + flags |= EROFS_REG_COOKIE_SHARE; mutex_lock(&erofs_domain_cookies_lock); list_for_each_entry(ctx, &erofs_domain_cookies_list, node) { if (ctx->domain != domain || strcmp(ctx->name, name)) @@ -546,7 +528,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_domain_init_cookie(sb, name, flags); mutex_unlock(&erofs_domain_cookies_lock); return ctx; } @@ -585,7 +567,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 +586,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..50cd257d04e3 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,8 @@ 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_SHARE 0x0001 +#define EROFS_REG_COOKIE_NEED_NOEXIST 0x0002 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); }