Received: by 2002:a05:6358:489b:b0:bb:da1:e618 with SMTP id x27csp1898150rwn; Fri, 16 Sep 2022 02:31:32 -0700 (PDT) X-Google-Smtp-Source: AMsMyM4lRKhqZvPV4u0WlQrHUO0R6IZhNX7CCkNjeJ+/+AsdqZG3pA9lruH41fvg58+GtDZFCH2Y X-Received: by 2002:a17:90a:658a:b0:202:f03b:6426 with SMTP id k10-20020a17090a658a00b00202f03b6426mr15545054pjj.66.1663320692538; Fri, 16 Sep 2022 02:31:32 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1663320692; cv=none; d=google.com; s=arc-20160816; b=viU1M/xRo5ImRzAqE/XNzxpeYPGb0sPvJHZwAU1JkPROQWiG0oYfVrOs9paE1ymy2V loNOkqekuHJ0vGXqh7wn7sEb+E89xd8xrWPGtV/S2ojNMHibDKoin+IelA9/j5ZUG6/r SUTOFVlZdsBolPsSQeYhU2c9RLpVgH+hWvR6LC5AVrTVUMtk3ZAW1FPZZPiP09zL3EgJ WfQlakP5OEeHmmKE0jEKO0qaBdMr41Lk5LHV2PAID090YtG7XOypwMOH/y3HYQs3JX3D pqQhMcpGQXVkvUGHSPS6lajWI67vixyB4vg8721aTXfO8t5vtp7vkcTsVXJNx4eSWLt0 my/g== 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 :dkim-signature; bh=WujN6b69hBLbBl5JiKiO3Hx91SbLnwPc9Vm4CnthUKc=; b=B03WnbeesVYoATl8dQWmbBisyYkKDfjDK3UjrFkzKaSsmMhgSlv27ueKKWW51YN2zA t+btge0U9A2t3a4mUWu7i4mnpF+EUN3qI08ggqlHP8XTAXwSvyxYCzd2q9OGTUsuXjJC SxtyuNTw5DSMK3gfDaA5OOICnYMTAFTzmobCh4D3jULHaOoq4WCNPJ4TD68tramDhf2m nime+XiAUkl5scKBydUQ4LErHkxH8uWSeiR8WllTdnriwnqxBHYWzuoSFv8/dPJ5MR4h 5QCMthjxDKD384FkjSS5G3hXbJ+fzCGQ5R2G8yccMUL/GWy330Io3xqGtwe7azAlc4hM mKVg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@bytedance-com.20210112.gappssmtp.com header.s=20210112 header.b=Q9qhc+C3; 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 ob7-20020a17090b390700b00202acc2169csi2324128pjb.118.2022.09.16.02.31.21; Fri, 16 Sep 2022 02:31: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; dkim=pass header.i=@bytedance-com.20210112.gappssmtp.com header.s=20210112 header.b=Q9qhc+C3; 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 S231250AbiIPJBB (ORCPT + 99 others); Fri, 16 Sep 2022 05:01:01 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:43434 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231181AbiIPJAe (ORCPT ); Fri, 16 Sep 2022 05:00:34 -0400 Received: from mail-pg1-x52a.google.com (mail-pg1-x52a.google.com [IPv6:2607:f8b0:4864:20::52a]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 6E00C2715D for ; Fri, 16 Sep 2022 02:00:10 -0700 (PDT) Received: by mail-pg1-x52a.google.com with SMTP id s206so19779782pgs.3 for ; Fri, 16 Sep 2022 02:00:10 -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=WujN6b69hBLbBl5JiKiO3Hx91SbLnwPc9Vm4CnthUKc=; b=Q9qhc+C3cxqmsergSUYPmPyZAVN8RvRQcUMtaRqmm+ti3YKlXq4I1p7VimdJTka3co srzSVu2/D+odNyjDADYNFKbwKuWyoou/cUBuiedsU6EvqvEKslEnJn58RI21x5RGS3X0 Xt9d7MVvNeKu3s/fUpvpVxRA3jdv8E1YDjGKYBEHC3q1DCrMkjTWLuNMneKraA+NNmiI iX7+GNBq4qak7WSGqlkph9VoGNiGwY+WTx/06VU9yrj3YGpS0Cv6jsvNqdZ2LNMUiiQI LPeDR3TW6WoZsj+4dBsBzKVPCZqTn/UucimDwYuv6olV2Fm660O2qOGYEWbU5y4eHQ2C nwAg== 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=WujN6b69hBLbBl5JiKiO3Hx91SbLnwPc9Vm4CnthUKc=; b=iryOeBGMs7kxXaKuZYPPIoXpf3ZBK6dLxOeSgwZdvDfLOaqEbPcmO4D5xNUFOHHmpD e55UbeIxLEEY+kd8kxOvI//ABksM6pP2oggss5pdFSUpjmf2Vd87hflmoU3EhmvPaGCo SmePOBniXUliNJ/HfGkkcKLN0HgF0/SwAv0MHXYSX4G42uzbrFcJ/LSTCPbuCgjl+vFJ nWyY+h60v8G8+jISyF61HbthRBgM5HGopYW/XEuvRa6zaaEr1+R24olnLdmuA1Bd5XWR RSTC+vYgTysILTjQLu3tN5SWSoUlYqSznnSC6HtjvZHmG5pdTw2cj7EY8Xm9pmfm3s/C nSNQ== X-Gm-Message-State: ACrzQf3G7lObiFLxdM1GyjABZvwxI6ea54WFoLF6t/s5yJ7gbhpvYyna vOuSPVUlaJ7qDEaz6SRems1mUg== X-Received: by 2002:a63:69c7:0:b0:41c:590a:62dc with SMTP id e190-20020a6369c7000000b0041c590a62dcmr3539732pgc.388.1663318809204; Fri, 16 Sep 2022 02:00:09 -0700 (PDT) Received: from C02G705SMD6V.bytedance.net ([61.120.150.76]) by smtp.gmail.com with ESMTPSA id u11-20020a17090a450b00b001fd7fe7d369sm970578pjg.54.2022.09.16.02.00.05 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 16 Sep 2022 02:00:08 -0700 (PDT) From: Jia Zhu To: linux-erofs@lists.ozlabs.org Cc: linux-fsdevel@vger.kernel.org, linux-kernel@vger.kernel.org, yinxin.x@bytedance.com, jefflexu@linux.alibaba.com, Jia Zhu Subject: [PATCH V5 5/6] erofs: Support sharing cookies in the same domain Date: Fri, 16 Sep 2022 16:59:39 +0800 Message-Id: <20220916085940.89392-6-zhujia.zj@bytedance.com> X-Mailer: git-send-email 2.37.0 (Apple Git-136) In-Reply-To: <20220916085940.89392-1-zhujia.zj@bytedance.com> References: <20220916085940.89392-1-zhujia.zj@bytedance.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,RCVD_IN_DNSWL_NONE,SPF_HELO_NONE,SPF_PASS 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 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 | 99 ++++++++++++++++++++++++++++++++++++++++++--- fs/erofs/internal.h | 3 ++ 2 files changed, 96 insertions(+), 6 deletions(-) diff --git a/fs/erofs/fscache.c b/fs/erofs/fscache.c index 4a7346b9fa73..d52d3d0ce9af 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; @@ -527,8 +528,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; @@ -577,17 +578,103 @@ struct erofs_fscache *erofs_fscache_register_cookie(struct super_block *sb, return ERR_PTR(ret); } -void erofs_fscache_unregister_cookie(struct erofs_fscache *ctx) +static void erofs_fscache_relinquish_cookie(struct erofs_fscache *ctx) { - if (!ctx) - return; - fscache_unuse_cookie(ctx->cookie, NULL, NULL); fscache_relinquish_cookie(ctx->cookie, false); iput(ctx->inode); + kfree(ctx->name); kfree(ctx); } +static +struct erofs_fscache *erofs_fscache_domain_init_cookie(struct super_block *sb, + char *name, bool need_inode) +{ + int err; + struct inode *inode; + struct erofs_fscache *ctx; + struct erofs_domain *domain = EROFS_SB(sb)->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) { + err = -ENOMEM; + goto out; + } + + inode = new_inode(erofs_pseudo_mnt->mnt_sb); + if (!inode) { + kfree(ctx->name); + err = -ENOMEM; + goto out; + } + + ctx->domain = domain; + ctx->anon_inode = inode; + 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, bool need_inode) +{ + 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); + list_for_each_entry(inode, &psb->s_inodes, i_sb_list) { + ctx = inode->i_private; + if (!ctx || ctx->domain != domain || strcmp(ctx->name, name)) + continue; + 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) +{ + if (EROFS_SB(sb)->opt.domain_id) + return erofs_domain_register_cookie(sb, name, need_inode); + return erofs_fscache_acquire_cookie(sb, name, need_inode); +} + +void erofs_fscache_unregister_cookie(struct erofs_fscache *ctx) +{ + bool drop; + struct erofs_domain *domain; + + 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; + } + + erofs_fscache_relinquish_cookie(ctx); + erofs_fscache_domain_put(domain); +} + int erofs_fscache_register_fs(struct super_block *sb) { int ret; diff --git a/fs/erofs/internal.h b/fs/erofs/internal.h index 273fb35170e2..0f63830c9056 100644 --- a/fs/erofs/internal.h +++ b/fs/erofs/internal.h @@ -109,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 { -- 2.20.1