Received: by 2002:a05:6358:489b:b0:bb:da1:e618 with SMTP id x27csp465394rwn; Thu, 15 Sep 2022 01:12:21 -0700 (PDT) X-Google-Smtp-Source: AA6agR72yGP0VGi5AZK84Vi7GPT1ebjk1vqjbAFwOKt1b98xrPRNAfWuAuLlnFgf3snA43JG/Unn X-Received: by 2002:a17:907:2e02:b0:77c:5020:b8ef with SMTP id ig2-20020a1709072e0200b0077c5020b8efmr15142417ejc.299.1663229540750; Thu, 15 Sep 2022 01:12:20 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1663229540; cv=none; d=google.com; s=arc-20160816; b=wSogX5wLIpm2hn6OzFx66tXkdAYHC7erBIj2+HShjSBjbqyhTYdeaQW7UE/CdK2kPs dK11dMw4xS5PwvsIBHm4PkEqFQE9p60h37Huda84T6X6NWJyEuOv2FfAsk7doyjNXci5 rvJDxYQJQ8KxFBedtXhl8ldvEFPSz+Y0gMQb2hE3QqJenPF0e5VL7gKyFNnJ0NxUXt4B MTFGVX6To2Z+vQaNxzfRabJbIaRZdSzUqoSh6y7oQ3nmjx0YacSUATXtc02ordGbqYIj 43DJxopeooK2tgXonuo3/Ph/+BcayeZRLsOA5plNaWZlPhjf4r28+U1b7D/XxiHjGNja qA7A== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:in-reply-to:from :references:cc:to:subject:user-agent:mime-version:date:message-id :dkim-signature; bh=LIWBWWFb8yy1MssxtI6bn2YpTDb4Q6/dddLLzhJ4bpQ=; b=Rj6G1fwvqDxspuydl+l7kPZVFxL6bhOeSUetrbfoO0KcCMGFs0ognDKU6xnuqeb/LC jWjJ8dAMfJQVI/YvKOxylet9I8n49rQdoqj0iNYaXK9xhGDP8lWMnTlW/KRK3uzz1A6U qpulIt3CA1rhCN9YeO4mAmfUbyV9qWS/Z8sEefL9veOfv9zS7s9znyGDQ7CzAsCF66BT HIJYCk9qhEwc/6SobeJRtAG+7Oo6VsW3D9m+2WNVLmOdRmGKFEASROuieMmuX+uAC9OF HImjWgUUgBsnoOHYtXqQvAN/i8lWJUUsucO1qugOR7Ckan5I3Rfkd+cp8WG4xV01+FOo sXjA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@bytedance-com.20210112.gappssmtp.com header.s=20210112 header.b=wNo7hBk9; 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=bytedance.com Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id j8-20020a50ed08000000b0044e86981ea9si9758894eds.390.2022.09.15.01.11.54; Thu, 15 Sep 2022 01:12:20 -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; dkim=pass header.i=@bytedance-com.20210112.gappssmtp.com header.s=20210112 header.b=wNo7hBk9; 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=bytedance.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230032AbiIOH1U (ORCPT + 99 others); Thu, 15 Sep 2022 03:27:20 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:54126 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229916AbiIOH07 (ORCPT ); Thu, 15 Sep 2022 03:26:59 -0400 Received: from mail-pg1-x534.google.com (mail-pg1-x534.google.com [IPv6:2607:f8b0:4864:20::534]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id ADE0B8E998 for ; Thu, 15 Sep 2022 00:26:48 -0700 (PDT) Received: by mail-pg1-x534.google.com with SMTP id t65so16536174pgt.2 for ; Thu, 15 Sep 2022 00:26:48 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bytedance-com.20210112.gappssmtp.com; s=20210112; h=content-transfer-encoding:in-reply-to:from:references:cc:to:subject :user-agent:mime-version:date:message-id:from:to:cc:subject:date; bh=LIWBWWFb8yy1MssxtI6bn2YpTDb4Q6/dddLLzhJ4bpQ=; b=wNo7hBk9fMWUOj/3ynTodNOVDRJXMwJmtYMzu04+LkzdaP8h61LFrdZcor4jT7Jgpn GVtl/I+x5gEYJoKS/hILQc4cQC/gdv2L15Aeke7THm1rbLKET+QYlZT4sWxZTbnSYmFC DkNUc2Wnppf+b2eMb6jyQL5PKRw+6meelewWknLf/YQBdlrdPaGKyC6KyfLXR/QfbIeH G4AibeCjUYLsGX9KHjadMcHPHcO/v9NyIbCZn6Me1c8AgmJSOjNI5Fhulf6SOBTage9N 4WkFmgh8JyxyMYpm4xuRrmb+5IQj7gGiZXXVcu+OILkMHcVx+5Ir8Zf60WNFYcivJ/Uw 9q9w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:in-reply-to:from:references:cc:to:subject :user-agent:mime-version:date:message-id:x-gm-message-state:from:to :cc:subject:date; bh=LIWBWWFb8yy1MssxtI6bn2YpTDb4Q6/dddLLzhJ4bpQ=; b=PaeLs9IZbqEcYTpVclmZO4BznH/ApDaq2w8CM2qjT01WNVQ4Sztcbp7vVs4rkehW8r pFq6q49+j5z9cjYkalwScvCwHU+vNucWsjsKTUvoRjfzfFPMw88kFaXoFGM0Omb3adTA 4t3HMkr48c1MkIAz1+h/4Myusls5lygnTbKH5LKFJXszE5dzl1AkaN/TX+of7XrlflOx zPP5DIkJc9lG63Af71N9jATWBv5T7QrS+iBIQ1g53fP5v5xJBWE+xOh6Suumm2qRvJPr X3HVL9NYQEHoCZuGThgVx245uEtkQFusEJYVvsZLJDoC5E8InSVOWGsJ8PwisZeeQYQx nTMA== X-Gm-Message-State: ACgBeo1nBbZLRuRfgFJgq87W3THTBcKYIslAnZ7bePO5GdqbIxTTfPaw a0L6JojQBci1UN1+0Y7OCAg5LA== X-Received: by 2002:a63:e25:0:b0:41c:30f7:c39c with SMTP id d37-20020a630e25000000b0041c30f7c39cmr34809101pgl.147.1663226802094; Thu, 15 Sep 2022 00:26:42 -0700 (PDT) Received: from [10.76.37.214] ([61.120.150.76]) by smtp.gmail.com with ESMTPSA id h29-20020a056a00001d00b0053e9ecf58f0sm11715954pfk.20.2022.09.15.00.26.38 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Thu, 15 Sep 2022 00:26:41 -0700 (PDT) Message-ID: Date: Thu, 15 Sep 2022 15:26:35 +0800 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.15; rv:91.0) Gecko/20100101 Thunderbird/91.13.0 Subject: Re: [External] Re: [PATCH V3 6/6] erofs: Support sharing cookies in the same domain To: JeffleXu , linux-erofs@lists.ozlabs.org, xiang@kernel.org, chao@kernel.org Cc: linux-fsdevel@vger.kernel.org, linux-kernel@vger.kernel.org, yinxin.x@bytedance.com, huyue2@coolpad.com References: <20220914105041.42970-1-zhujia.zj@bytedance.com> <20220914105041.42970-7-zhujia.zj@bytedance.com> <82473542-7810-3474-3f78-b61f9927d682@linux.alibaba.com> From: Jia Zhu In-Reply-To: <82473542-7810-3474-3f78-b61f9927d682@linux.alibaba.com> Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-3.5 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,NICE_REPLY_A,RCVD_IN_DNSWL_NONE,SPF_HELO_NONE,SPF_PASS, T_SCC_BODY_TEXT_LINE 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 在 2022/9/15 14:53, JeffleXu 写道: > > > On 9/14/22 6:50 PM, Jia Zhu wrote: >> Several erofs filesystems can belong to one domain, and data blobs can >> be shared among these erofs filesystems of same domain. >> >> Users could specify domain_id mount option to create or join into a >> domain. >> >> Signed-off-by: Jia Zhu >> --- >> fs/erofs/fscache.c | 89 +++++++++++++++++++++++++++++++++++++++++++-- >> fs/erofs/internal.h | 4 +- >> 2 files changed, 89 insertions(+), 4 deletions(-) >> >> diff --git a/fs/erofs/fscache.c b/fs/erofs/fscache.c >> index 4e0a441afb7d..e9ae1ee963e2 100644 >> --- a/fs/erofs/fscache.c >> +++ b/fs/erofs/fscache.c >> @@ -7,6 +7,7 @@ >> #include "internal.h" >> >> static DEFINE_MUTEX(erofs_domain_list_lock); >> +static DEFINE_MUTEX(erofs_domain_cookies_lock); >> static LIST_HEAD(erofs_domain_list); >> static struct vfsmount *erofs_pseudo_mnt; >> >> @@ -504,7 +505,6 @@ static int erofs_fscache_init_domain(struct super_block *sb) >> >> domain->volume = sbi->volume; >> refcount_set(&domain->ref, 1); >> - mutex_init(&domain->mutex); > > This needs to be folded into patch 4. Thanks. > > >> list_add(&domain->list, &erofs_domain_list); >> return 0; >> out: >> @@ -534,8 +534,8 @@ static int erofs_fscache_register_domain(struct super_block *sb) >> return err; >> } >> >> -struct erofs_fscache *erofs_fscache_register_cookie(struct super_block *sb, >> - char *name, bool need_inode) >> +struct erofs_fscache *erofs_fscache_acquire_cookie(struct super_block *sb, >> + char *name, bool need_inode) >> { >> struct fscache_volume *volume = EROFS_SB(sb)->volume; >> struct erofs_fscache *ctx; >> @@ -585,13 +585,96 @@ struct erofs_fscache *erofs_fscache_register_cookie(struct super_block *sb, >> return ERR_PTR(ret); >> } >> >> +static >> +struct erofs_fscache *erofs_fscache_domain_init_cookie(struct super_block *sb, >> + char *name, bool need_inode) >> +{ >> + struct inode *inode; >> + struct erofs_fscache *ctx; >> + struct erofs_sb_info *sbi = EROFS_SB(sb); >> + struct erofs_domain *domain = sbi->domain; >> + >> + ctx = erofs_fscache_acquire_cookie(sb, name, need_inode); >> + if (IS_ERR(ctx)) >> + return ctx; >> + >> + ctx->name = kstrdup(name, GFP_KERNEL); >> + if (!ctx->name) >> + return ERR_PTR(-ENOMEM); > > The previously registered erofs_fscache needs to be cleaned up in the > error path. Thanks for catching this. I'll fix it in next version. > >> + >> + inode = new_inode(erofs_pseudo_mnt->mnt_sb); >> + if (!inode) { >> + kfree(ctx->name); >> + return ERR_PTR(-ENOMEM); >> + } > > Ditto. > >> + >> + ctx->domain = domain; >> + ctx->anon_inode = inode; >> + inode->i_private = ctx; >> + erofs_fscache_domain_get(domain); >> + return ctx; >> +} >> + >> +static >> +struct erofs_fscache *erofs_domain_register_cookie(struct super_block *sb, >> + char *name, bool need_inode) >> +{ >> + struct inode *inode; >> + struct erofs_fscache *ctx; >> + struct erofs_sb_info *sbi = EROFS_SB(sb); >> + struct erofs_domain *domain = sbi->domain; >> + struct super_block *psb = erofs_pseudo_mnt->mnt_sb; >> + >> + mutex_lock(&erofs_domain_cookies_lock); >> + list_for_each_entry(inode, &psb->s_inodes, i_sb_list) { >> + ctx = inode->i_private; >> + if (!ctx) >> + continue; >> + if (ctx->domain == domain && !strcmp(ctx->name, name)) { >> + igrab(inode); >> + mutex_unlock(&erofs_domain_cookies_lock); >> + return ctx; >> + } >> + } >> + ctx = erofs_fscache_domain_init_cookie(sb, name, need_inode); >> + mutex_unlock(&erofs_domain_cookies_lock); >> + return ctx; >> +} >> + >> +struct erofs_fscache *erofs_fscache_register_cookie(struct super_block *sb, >> + char *name, bool need_inode) >> +{ >> + struct erofs_sb_info *sbi = EROFS_SB(sb); >> + >> + if (sbi->opt.domain_id) >> + return erofs_domain_register_cookie(sb, name, need_inode); >> + else >> + return erofs_fscache_acquire_cookie(sb, name, need_inode); >> +} >> + >> void erofs_fscache_unregister_cookie(struct erofs_fscache *ctx) >> { >> + struct erofs_domain *domain; >> + >> if (!ctx) >> return; >> + domain = ctx->domain; >> + if (domain) { >> + mutex_lock(&erofs_domain_cookies_lock); >> + /* Cookie is still in use */ >> + if (atomic_read(&ctx->anon_inode->i_count) > 1) { >> + iput(ctx->anon_inode); >> + mutex_unlock(&erofs_domain_cookies_lock); >> + return; >> + } >> + iput(ctx->anon_inode); >> + kfree(ctx->name); >> + mutex_unlock(&erofs_domain_cookies_lock); > > 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; This code style is more intuitive, I'll revise it, thanks. >> + } >> > fscache_unuse_cookie(ctx->cookie, NULL, NULL); >> fscache_relinquish_cookie(ctx->cookie, false); >> + erofs_fscache_domain_put(domain); >> ctx->cookie = NULL; > > fscache_unuse_cookie(ctx->cookie, NULL, NULL); > fscache_relinquish_cookie(ctx->cookie, false); > erofs_fscache_domain_put(domain); > kfree(ctx->name); > >> >> iput(ctx->inode); >> diff --git a/fs/erofs/internal.h b/fs/erofs/internal.h >> index 4dd0b545755a..8a6f94b27a23 100644 >> --- a/fs/erofs/internal.h >> +++ b/fs/erofs/internal.h >> @@ -101,7 +101,6 @@ struct erofs_sb_lz4_info { >> >> struct erofs_domain { >> refcount_t ref; >> - struct mutex mutex; >> struct list_head list; >> struct fscache_volume *volume; >> char *domain_id; >> @@ -110,6 +109,9 @@ struct erofs_domain { >> struct erofs_fscache { >> struct fscache_cookie *cookie; >> struct inode *inode; >> + struct inode *anon_inode; >> + struct erofs_domain *domain; >> + char *name; >> }; >> >> struct erofs_sb_info { >