Received: by 2002:a05:6358:489b:b0:bb:da1:e618 with SMTP id x27csp738673rwn; Thu, 15 Sep 2022 05:57:20 -0700 (PDT) X-Google-Smtp-Source: AA6agR4NcLutfLTo0DG8JuUxGI3H/KO532Vq8PsBdZPeSRKAt60Q9JfD3aTU1cnehU1lec3oE5/b X-Received: by 2002:a05:6402:3509:b0:452:20c7:5a95 with SMTP id b9-20020a056402350900b0045220c75a95mr14143324edd.427.1663246639778; Thu, 15 Sep 2022 05:57:19 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1663246639; cv=none; d=google.com; s=arc-20160816; b=dZ7QaaheskbVaFlIcCTV00/WBNt+s4Aku0CQ79v0N1p75mKXLBb+TZli+JRKQabkxA glLbvAzM4J/DJMFVVCWQUmNwQ5jYv2fFZ4M2Rj2zDafnGBRV7mfGMtTVIJZFk3v1evt8 EwqLtHwteFPhoED4JVXsYtRVQ4dXymwieIHD3HEDC7eKugPstuMIuf2UpbHSweau1/Rk XQPIe6/5UYxG6bkT7AUIZsV69hCONodBVQQPfjFo4m4a1bVNB+Iwr286UubdA2j6hT4x Y0hOu/PpWv98PRGUU0t1YrdOFBXlnFi1UhdAIjb2+uHyaaR7yPdvMrFhBU8SI2Wuiekp NhBA== 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=xWjAf9wvMTwIsrKn+t2CcTOjGhpgH45SYj+wwCJhngo=; b=SQOtYm6V/3BjdcI5cpyCwci4dIZMv9RRQCfGCvmmFb7x4mRqle4DWR5c9JlvMR/k4b HJy08B8ZDqcxCQOYe+9RP/zEfgXClEEhHOFsqAuq6r52/IcO/eWReHHJldF1GpLYoeoU YZEiDha2Npxs6GWKgY/T7R6MqmnIPqEnfraOzWZ++ldwsS8iarDAAonXsznn1PJdTnZt RVeqxndPl2B8pVvLWb4belCUdFipAvw7fL1letvHdnpArjgBCdzdOpV1Qjc5YWtUsbC4 7uTJBGfoDqfoxxuPcfIuPU7zAm5lO5zCXz7mnJaFZPnWdLjc1mWo4ao5J4Ey/IQpD7Gf QchA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@bytedance-com.20210112.gappssmtp.com header.s=20210112 header.b=jqkPqCE3; 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 gs38-20020a1709072d2600b007804f3dafbesi2074115ejc.587.2022.09.15.05.56.53; Thu, 15 Sep 2022 05:57:19 -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=jqkPqCE3; 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 S230172AbiIOMna (ORCPT + 99 others); Thu, 15 Sep 2022 08:43:30 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:38612 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230110AbiIOMm6 (ORCPT ); Thu, 15 Sep 2022 08:42:58 -0400 Received: from mail-pg1-x529.google.com (mail-pg1-x529.google.com [IPv6:2607:f8b0:4864:20::529]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id DAC2340577 for ; Thu, 15 Sep 2022 05:42:49 -0700 (PDT) Received: by mail-pg1-x529.google.com with SMTP id q9so8096103pgq.8 for ; Thu, 15 Sep 2022 05:42:49 -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=R8AwjMNPi7DG/fRHxgdX6TUd+tgrisBd3Zp9HxOoH/flg7SoL4gZLZ3uClSaUmYyR7 Ci5o/jxQmNi0xo6IG8RBRKkWuI1OAue2sKdO5RH9SYArY1KgpyEymuwDpnaHRspJAAXg m4YDVgIBv47P1JhAOK+Gqm2HU6nRtCIhBNCAKRLoPk6EbUGVRnIR11P+PNEl33R1/JXf Fnw5e0jMh+KHJF3v7f09oY6BzhISdbz5EDtOyfhg/9NHTJ3AbNBYp1AMESW0RnDgrm4+ p1B+2b+fMUToltsRF40Zrik89xgy0D6pihbfLIt2g3JLvQkmP87nkFY9uSjPZ3RSjWDM L1Tg== X-Gm-Message-State: ACgBeo2Jv4Tv1zKuR6+CvKUKSnvfkHpAWPQVCY6w2P1T4hXoN/nbbiBD wVXqFra8G/0g0Ru0aXu2RLf2tpgBEJYIxA== 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 Cc: linux-fsdevel@vger.kernel.org, linux-kernel@vger.kernel.org, yinxin.x@bytedance.com, jefflexu@linux.alibaba.com, Jia Zhu 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-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 | 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