From mboxrd@z Thu Jan 1 00:00:00 1970 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 lists.ozlabs.org (lists.ozlabs.org [112.213.38.117]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 9E8BCECAAA1 for ; Thu, 15 Sep 2022 12:42:56 +0000 (UTC) Received: from boromir.ozlabs.org (localhost [IPv6:::1]) by lists.ozlabs.org (Postfix) with ESMTP id 4MSxgg18cqz3bsy for ; Thu, 15 Sep 2022 22:42:55 +1000 (AEST) Authentication-Results: lists.ozlabs.org; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=bytedance-com.20210112.gappssmtp.com header.i=@bytedance-com.20210112.gappssmtp.com header.a=rsa-sha256 header.s=20210112 header.b=jqkPqCE3; dkim-atps=neutral Authentication-Results: lists.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=bytedance.com (client-ip=2607:f8b0:4864:20::529; helo=mail-pg1-x529.google.com; envelope-from=zhujia.zj@bytedance.com; receiver=) Authentication-Results: lists.ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=bytedance-com.20210112.gappssmtp.com header.i=@bytedance-com.20210112.gappssmtp.com header.a=rsa-sha256 header.s=20210112 header.b=jqkPqCE3; dkim-atps=neutral Received: from mail-pg1-x529.google.com (mail-pg1-x529.google.com [IPv6:2607:f8b0:4864:20::529]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by lists.ozlabs.org (Postfix) with ESMTPS id 4MSxgb2D35z3bsy for ; Thu, 15 Sep 2022 22:42:50 +1000 (AEST) Received: by mail-pg1-x529.google.com with SMTP id s206so17235497pgs.3 for ; Thu, 15 Sep 2022 05:42:50 -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=xWjAf9wvMTwIsrKn+t2CcTOjGhpgH45SYj+wwCJhngo=; b=jqkPqCE35yUwSiFS4layyrnkw357wLFQjNU/RN8Xg1EPyR1hhKr5rcjmOiunTu58xc Ikj4NQfFFN2nSkhuFVi1VDDFbtaaXoTPVtOweRi54RxKj9IFruQDVJABZf1IkcP20KqK fT5i2ijCDSzDCI9UvSQSgSTAp0go5qZ6MDIgHGKDDPypU4kHGu30diX9XvrLivvFpuzP cXVRIeqPZ6wCP28mPpVOHcpbAsQ1l1cQdI0s0iea6s48BtBmGs+ieUeKYvnGTGDPcSq9 wfUZiy/CjS4WIo+nbq1NFcUuJB0gg9Bub3GCiGCiDK0UpWH5GMDk0Ig0mlT0KSyw9eO2 dhUg== 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=xWjAf9wvMTwIsrKn+t2CcTOjGhpgH45SYj+wwCJhngo=; b=N/nboeLXGnl+NpfdrcKtxehrl2CLjITuPdkxIUduG8hF9OGagEc6xJ+AaktMXHR9vO IEceWUwmCPsXBChWKj/sAXBeTui6B5UL3uGSMpzNNgu52agDf98qsq8gqBqCJjXUMLI5 IqlkcNE5jf+RfaVnmpiZU7Tv5wUWncoqE1fiH06iaddLZ4JDCiwwbKvThXTO7P2+yz4b 5oOBCQSvqewkcWfVlekvzan1vxlX5BRiAbeZAa+wtAx2APLxaCFf9IKTxY6KZp0GUum4 EMls9tlahIvF4Ivnr63dPBytSxWbyN9P1+KdEBsh3fj6ZuDasX0Ak0Ap97l7vPgJLGbM odVg== X-Gm-Message-State: ACgBeo1DG2vl7nBhrodyi0C/LLLZZit0BBWfcpkEKaszxwJReeptOp7O +qQ9MubHTAnh9xWXx/ICuDvoT4jGQ8vwQw== X-Google-Smtp-Source: AA6agR5XMjVI1b1fxEsxrzJECABjHTdCah+A6klG74cl2/JM3hA2zEEHXXJAnQ+hjydGuWqiXsQWGQ== X-Received: by 2002:a05:6a00:cd6:b0:546:d03:3dd7 with SMTP id b22-20020a056a000cd600b005460d033dd7mr12939600pfv.19.1663245768868; Thu, 15 Sep 2022 05:42:48 -0700 (PDT) Received: from C02G705SMD6V.bytedance.net ([61.120.150.76]) by smtp.gmail.com with ESMTPSA id p8-20020a170902780800b001637529493esm12721906pll.66.2022.09.15.05.42.45 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 15 Sep 2022 05:42:48 -0700 (PDT) From: Jia Zhu To: linux-erofs@lists.ozlabs.org Subject: [PATCH V4 5/6] erofs: Support sharing cookies in the same domain Date: Thu, 15 Sep 2022 20:42:12 +0800 Message-Id: <20220915124213.25767-6-zhujia.zj@bytedance.com> X-Mailer: git-send-email 2.37.0 (Apple Git-136) In-Reply-To: <20220915124213.25767-1-zhujia.zj@bytedance.com> References: <20220915124213.25767-1-zhujia.zj@bytedance.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-BeenThere: linux-erofs@lists.ozlabs.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Development of Linux EROFS file system List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: linux-fsdevel@vger.kernel.org, linux-kernel@vger.kernel.org, yinxin.x@bytedance.com Errors-To: linux-erofs-bounces+linux-erofs=archiver.kernel.org@lists.ozlabs.org Sender: "Linux-erofs" 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 | 90 ++++++++++++++++++++++++++++++++++++++++++++- fs/erofs/internal.h | 3 ++ 2 files changed, 91 insertions(+), 2 deletions(-) diff --git a/fs/erofs/fscache.c b/fs/erofs/fscache.c index ff8382df493e..8873a093cf7b 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,14 +578,99 @@ 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) +{ + 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: + fscache_unuse_cookie(ctx->cookie, NULL, NULL); + fscache_relinquish_cookie(ctx->cookie, false); + if (need_inode) + iput(ctx->inode); + kfree(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; + } fscache_unuse_cookie(ctx->cookie, NULL, NULL); fscache_relinquish_cookie(ctx->cookie, false); + erofs_fscache_domain_put(domain); iput(ctx->inode); + kfree(ctx->name); kfree(ctx); } diff --git a/fs/erofs/internal.h b/fs/erofs/internal.h index 88c1a46867b3..8a6f94b27a23 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