From nobody Sun Apr 5 16:33:04 2026 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 9A680ECAAD3 for ; Wed, 14 Sep 2022 10:52:22 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229592AbiINKwU (ORCPT ); Wed, 14 Sep 2022 06:52:20 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:40332 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230073AbiINKvg (ORCPT ); Wed, 14 Sep 2022 06:51:36 -0400 Received: from mail-pj1-x1036.google.com (mail-pj1-x1036.google.com [IPv6:2607:f8b0:4864:20::1036]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id D2D0F647E1 for ; Wed, 14 Sep 2022 03:51:13 -0700 (PDT) Received: by mail-pj1-x1036.google.com with SMTP id fv3so14193519pjb.0 for ; Wed, 14 Sep 2022 03:51:13 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bytedance-com.20210112.gappssmtp.com; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date; bh=imR5y18ryUCktyAigdc0+MY99yMqYjGRbnJ4cSNTikw=; b=cn0ZpcYXk/kqyPdR7OatSX13r/+Xy1i+0/HByaAP+/RcxVpTb8RPtcj5PBdQtxtVlS C64alLZznwcghZj0W56bhfqoJUlA8XEOV10Ou1ZNweI//KGA6sHUs//7EeH2oVxaeyfD UiKpQ9n71whV8rE5+5TveZz+clfw4t0IWD1tRVEmKlnu3b4xfM1Nmt5GxGigmZIUNwRP GPjL7zQYDipgVCtACzlZ9IWv1FBkDYpGuHKckZ0d4czUntdG3yRUE8W086F9IAKJfzZG dt+48ozwedhEpIY+yhPYsQeXC3ryQ4SIGmk4i0XT7ArcnMP/R9OnIApGc1Tz5Qh2p6gl SSGg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date; bh=imR5y18ryUCktyAigdc0+MY99yMqYjGRbnJ4cSNTikw=; b=p+9efzIKtXaXw9slqO4NxBNWmMaM//v7aWWfLmsvjxQVXmsl4hAmuPmuu8oR25XkD6 PPWpB3Kp8pZbBlXU07G8Zk2EtRJ8vikX7orQyS8OLVhZaIlJqa1bZgQmN+WnpuSa9ahH cC9Qb7YUURLkezCSv3Bi7A1qx7+lq0sb0OE0QfAhrpKcbZEvexVTDGY6zMGi9o0z2l9Y PCPIHkLTcjsjP3GLcETR8ywucRTI8coADdgvRE7BJA7DjZSIKWlu2UO07fLDsm0xv7IE URJ3xFU/8r33q1mg1A0jx38OWMQvhW/7o6Zem1EvkhNdI+OIih0MI3h24mrgKvbvKYd2 wH5g== X-Gm-Message-State: ACgBeo2Zj4MDSlDjK/hzdapp4Ju+e0D2FCTEgpCTNU6yY1YVvNejeQiw tl7XqIAP65nVEDE/Ex/CJwEcNA== X-Google-Smtp-Source: AA6agR74HSXRqf39Tac77t/yqR9dwmYkhneSUTjl4+pqYGMp1qcuCe6wUhi5W957o2Y5Qu/FYox1Mg== X-Received: by 2002:a17:902:edd5:b0:174:a6e6:51f4 with SMTP id q21-20020a170902edd500b00174a6e651f4mr36165450plk.82.1663152673277; Wed, 14 Sep 2022 03:51:13 -0700 (PDT) Received: from C02G705SMD6V.bytedance.net ([2400:8800:1f02:83:4000:0:1:2]) by smtp.gmail.com with ESMTPSA id x13-20020a170902ec8d00b0016dc2366722sm10537042plg.77.2022.09.14.03.51.09 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 14 Sep 2022 03:51:12 -0700 (PDT) From: Jia Zhu To: 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, jefflexu@linux.alibaba.com, huyue2@coolpad.com, Jia Zhu Subject: [PATCH V3 6/6] erofs: Support sharing cookies in the same domain Date: Wed, 14 Sep 2022 18:50:41 +0800 Message-Id: <20220914105041.42970-7-zhujia.zj@bytedance.com> X-Mailer: git-send-email 2.37.0 (Apple Git-136) In-Reply-To: <20220914105041.42970-1-zhujia.zj@bytedance.com> References: <20220914105041.42970-1-zhujia.zj@bytedance.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" 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" =20 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; =20 @@ -504,7 +505,6 @@ static int erofs_fscache_init_domain(struct super_block= *sb) =20 domain->volume =3D sbi->volume; refcount_set(&domain->ref, 1); - mutex_init(&domain->mutex); list_add(&domain->list, &erofs_domain_list); return 0; out: @@ -534,8 +534,8 @@ static int erofs_fscache_register_domain(struct super_b= lock *sb) return err; } =20 -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 =3D EROFS_SB(sb)->volume; struct erofs_fscache *ctx; @@ -585,13 +585,96 @@ struct erofs_fscache *erofs_fscache_register_cookie(s= truct super_block *sb, return ERR_PTR(ret); } =20 +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 =3D EROFS_SB(sb); + struct erofs_domain *domain =3D sbi->domain; + + ctx =3D erofs_fscache_acquire_cookie(sb, name, need_inode); + if (IS_ERR(ctx)) + return ctx; + + ctx->name =3D kstrdup(name, GFP_KERNEL); + if (!ctx->name) + return ERR_PTR(-ENOMEM); + + inode =3D new_inode(erofs_pseudo_mnt->mnt_sb); + if (!inode) { + kfree(ctx->name); + return ERR_PTR(-ENOMEM); + } + + ctx->domain =3D domain; + ctx->anon_inode =3D inode; + inode->i_private =3D 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 =3D EROFS_SB(sb); + struct erofs_domain *domain =3D sbi->domain; + struct super_block *psb =3D erofs_pseudo_mnt->mnt_sb; + + mutex_lock(&erofs_domain_cookies_lock); + list_for_each_entry(inode, &psb->s_inodes, i_sb_list) { + ctx =3D inode->i_private; + if (!ctx) + continue; + if (ctx->domain =3D=3D domain && !strcmp(ctx->name, name)) { + igrab(inode); + mutex_unlock(&erofs_domain_cookies_lock); + return ctx; + } + } + ctx =3D 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 =3D 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 =3D 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); + } =20 fscache_unuse_cookie(ctx->cookie, NULL, NULL); fscache_relinquish_cookie(ctx->cookie, false); + erofs_fscache_domain_put(domain); ctx->cookie =3D NULL; =20 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 { =20 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; }; =20 struct erofs_sb_info { --=20 2.20.1