Received: by 2002:a05:6358:45e:b0:b5:b6eb:e1f9 with SMTP id 30csp1801919rwe; Fri, 2 Sep 2022 04:12:34 -0700 (PDT) X-Google-Smtp-Source: AA6agR7MzcfdaEKJStjBq/1B/Yowz7TxMa7hIqX5d2XnqZs0QW+jWtbnVOtyGgI/Ro6dRRmjIr7A X-Received: by 2002:a50:baa1:0:b0:43e:5e95:3eda with SMTP id x30-20020a50baa1000000b0043e5e953edamr33008652ede.340.1662117154364; Fri, 02 Sep 2022 04:12:34 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1662117154; cv=none; d=google.com; s=arc-20160816; b=hDIGaIflNMIS1WDp+OXOCC2noccuNjf/iGSyPAl5DW3eNnGOSlkMrKyHMHT7aG6srs 64vI37XdrUKHi0WYhL5oHW2/BWOqQPThae9tF/UuA7dQALXVevCDcKjZ+ASFiXhwLQja tAXlf5lT1DV6wR9g5TQtJ/Gz8yCdKQpvvhWIDHRxZgicOVvBA+gboy3RB5LQxeokIgQE yZpyND4N70k431Znkh0wjtA8pI/HGBeno+pyP13ZGWYKaCCs9FUHaXB2I7Uzt+jmJK0i ppOGAMmMmwp6+w7Vm0PsZ6+zcXE/rcinfaNsz/SaV9hKbZjmvDUNo2Ey0ielPqjjR8Eg bS8A== 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=l4+dx0/DUjpRvb0jfu2V1EYJ8pnYiC4nCrgUYZUGywU=; b=E8uU/nEG7gWD48GmbvGwpw8uZk8EXJiuDF/p5j/bfv9blIaiXTdP/Sy40bSuFtlTJx FNXgJRwJPNfc7oTjaqA3g+cKhXlsUennAQvABeQovTaxPIPokL7r/RrRqa6tI7/DxBEu xWya+NWS9X0FM3678UsIIHtup/xPpQTGTwQuwdNFwGmc6xT1SBPeIlhTPDASGComoU8q Ma8Sx82c8cHgNFNXJnT85mLu08Ymwk8cFaae35709NO9SMJ0RYCYs8wZJMGYx3mgMCMf HeopZAUMDRVjlE95T2pUxYMjwMhi5NBsImnVce/1CDi1P/LQQLck8Wc6vWgFpVRHYl3L CwVw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@bytedance-com.20210112.gappssmtp.com header.s=20210112 header.b=tMZC6ljQ; 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 n9-20020a05640205c900b004478a2d1abbsi1687255edx.531.2022.09.02.04.12.06; Fri, 02 Sep 2022 04:12:34 -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=tMZC6ljQ; 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 S234563AbiIBKy6 (ORCPT + 99 others); Fri, 2 Sep 2022 06:54:58 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:56808 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S235858AbiIBKyl (ORCPT ); Fri, 2 Sep 2022 06:54:41 -0400 Received: from mail-pj1-x102e.google.com (mail-pj1-x102e.google.com [IPv6:2607:f8b0:4864:20::102e]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 6C887CAC5A for ; Fri, 2 Sep 2022 03:54:32 -0700 (PDT) Received: by mail-pj1-x102e.google.com with SMTP id p8-20020a17090ad30800b001fdfc8c7567so7396344pju.1 for ; Fri, 02 Sep 2022 03:54:32 -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=l4+dx0/DUjpRvb0jfu2V1EYJ8pnYiC4nCrgUYZUGywU=; b=tMZC6ljQ/8gi9Jph6jESoxaGzBhUEKBu46ntA4lY1CAjffDzI68/+QKa8mWhfaY+QS H6Hdkl5udm0HIOJIVg1gb1BhiE1dz90rQbQ6fBuF+DocdTMwUirhIB4f09RuhIc/62x6 ty1a0xQSRgl97M8YG/zN4kcx4RODxhXLmNsk26nYWSuYBlzN6CQpjZVvYyR3eqKaOu5B Y/XaJfZ91xpqbDUzrAJg4yHkp7BTZQJsvZnj63QDu9081EC9fF/X1lJporKqY/rEaYtx UTCalW+4S+hXWiiqMgfJtPHSkP/+OqMFYiVrEzUeTMFTjtLak3MyHuzrHusfYkE7wfqM jbBA== 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=l4+dx0/DUjpRvb0jfu2V1EYJ8pnYiC4nCrgUYZUGywU=; b=6lEIJQQDxqq61a+f1oqFnelVPxb/exfrmedVkvpg46Sk1GwU9mxtmdwm+zmj9/rj1X hIGeTU3/RanfPuRFira66AQRMtpkC4+BQSPX5Ht+D89aTuWsvKw8IfNgkVYiWSZXv59l wVyQhGOuPL3a6IgSjqOrNoLEd8fQHAENYs/3nvakIv4NK440mISqQ15YXBYK8XbLUPtO YRNK+leqGcBfXDhuHa557PnDlm3VVUnXnaabl20Axcj5Qfa1vFexzncF8VZV7tmyixAt xxg07XTsiuX7zSzBKNMEoZLs9rQZwnQRjaMvQ3t9geSTcTiyXm5/x6sKwtmg42uHMev3 xMug== X-Gm-Message-State: ACgBeo0Fvt7ULUjbnOvlFy3cgb/OOmPbZux19YsCBu1Y8fzpoEhHKRHa Cv/knKm9p3pNohs4kyIrRZp9yw== X-Received: by 2002:a17:902:8e88:b0:172:d1f8:efcb with SMTP id bg8-20020a1709028e8800b00172d1f8efcbmr34060235plb.27.1662116071906; Fri, 02 Sep 2022 03:54:31 -0700 (PDT) Received: from C02G705SMD6V.bytedance.net ([61.120.150.76]) by smtp.gmail.com with ESMTPSA id e4-20020a63d944000000b0041b29fd0626sm1128681pgj.88.2022.09.02.03.54.27 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 02 Sep 2022 03:54:31 -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 V2 5/5] erofs: support fscache based shared domain Date: Fri, 2 Sep 2022 18:53:05 +0800 Message-Id: <20220902105305.79687-6-zhujia.zj@bytedance.com> X-Mailer: git-send-email 2.32.1 (Apple Git-133) In-Reply-To: <20220902105305.79687-1-zhujia.zj@bytedance.com> References: <20220902105305.79687-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, T_SCC_BODY_TEXT_LINE 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 | 73 +++++++++++++++++++++++++++++++++++++++++++++ fs/erofs/internal.h | 12 ++++++++ fs/erofs/super.c | 10 +++++-- 3 files changed, 93 insertions(+), 2 deletions(-) diff --git a/fs/erofs/fscache.c b/fs/erofs/fscache.c index 439dd3cc096a..c01845808ede 100644 --- a/fs/erofs/fscache.c +++ b/fs/erofs/fscache.c @@ -559,12 +559,27 @@ int erofs_fscache_register_cookie(struct super_block *sb, void erofs_fscache_unregister_cookie(struct erofs_fscache **fscache) { struct erofs_fscache *ctx = *fscache; + struct erofs_domain *domain; if (!ctx) return; + domain = ctx->domain; + if (domain) { + mutex_lock(&domain->mutex); + /* Cookie is still in use */ + if (atomic_read(&ctx->anon_inode->i_count) > 1) { + iput(ctx->anon_inode); + mutex_unlock(&domain->mutex); + return; + } + iput(ctx->anon_inode); + kfree(ctx->name); + mutex_unlock(&domain->mutex); + } fscache_unuse_cookie(ctx->cookie, NULL, NULL); fscache_relinquish_cookie(ctx->cookie, false); + erofs_fscache_domain_put(domain); ctx->cookie = NULL; iput(ctx->inode); @@ -609,3 +624,61 @@ void erofs_fscache_unregister_fs(struct super_block *sb) sbi->volume = NULL; sbi->domain = NULL; } + +static int erofs_fscache_domain_init_cookie(struct super_block *sb, + struct erofs_fscache **fscache, char *name, bool need_inode) +{ + int ret; + struct inode *inode; + struct erofs_fscache *ctx; + struct erofs_sb_info *sbi = EROFS_SB(sb); + struct erofs_domain *domain = sbi->domain; + + ret = erofs_fscache_register_cookie(sb, &ctx, name, need_inode); + if (ret) + return ret; + + ctx->name = kstrdup(name, GFP_KERNEL); + if (!ctx->name) + return -ENOMEM; + + inode = new_inode(erofs_pseudo_mnt->mnt_sb); + if (!inode) { + kfree(ctx->name); + return -ENOMEM; + } + + ctx->domain = domain; + ctx->anon_inode = inode; + inode->i_private = ctx; + erofs_fscache_domain_get(domain); + *fscache = ctx; + return 0; +} + +int erofs_domain_register_cookie(struct super_block *sb, + struct erofs_fscache **fscache, char *name, bool need_inode) +{ + int err; + 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(&domain->mutex); + list_for_each_entry(inode, &psb->s_inodes, i_sb_list) { + ctx = inode->i_private; + if (!ctx) + continue; + if (!strcmp(ctx->name, name)) { + *fscache = ctx; + igrab(inode); + mutex_unlock(&domain->mutex); + return 0; + } + } + err = erofs_fscache_domain_init_cookie(sb, fscache, name, need_inode); + mutex_unlock(&domain->mutex); + return err; +} diff --git a/fs/erofs/internal.h b/fs/erofs/internal.h index 2790c93ffb83..efa4f4ad77cc 100644 --- a/fs/erofs/internal.h +++ b/fs/erofs/internal.h @@ -110,6 +110,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 { @@ -625,6 +628,9 @@ int erofs_fscache_register_domain(struct super_block *sb); int erofs_fscache_register_cookie(struct super_block *sb, struct erofs_fscache **fscache, char *name, bool need_inode); +int erofs_domain_register_cookie(struct super_block *sb, + struct erofs_fscache **fscache, + char *name, bool need_inode); void erofs_fscache_unregister_cookie(struct erofs_fscache **fscache); extern const struct address_space_operations erofs_fscache_access_aops; @@ -646,6 +652,12 @@ static inline int erofs_fscache_register_cookie(struct super_block *sb, { return -EOPNOTSUPP; } +static inline int erofs_domain_register_cookie(struct super_block *sb, + struct erofs_fscache **fscache, + char *name, bool need_inode) +{ + return -EOPNOTSUPP; +} static inline void erofs_fscache_unregister_cookie(struct erofs_fscache **fscache) { diff --git a/fs/erofs/super.c b/fs/erofs/super.c index 667a78f0ee70..11c5ba84567c 100644 --- a/fs/erofs/super.c +++ b/fs/erofs/super.c @@ -245,8 +245,12 @@ static int erofs_init_device(struct erofs_buf *buf, struct super_block *sb, } if (erofs_is_fscache_mode(sb)) { - ret = erofs_fscache_register_cookie(sb, &dif->fscache, - dif->path, false); + if (sbi->opt.domain_id) + ret = erofs_domain_register_cookie(sb, &dif->fscache, dif->path, + false); + else + ret = erofs_fscache_register_cookie(sb, &dif->fscache, dif->path, + false); if (ret) return ret; } else { @@ -726,6 +730,8 @@ static int erofs_fc_fill_super(struct super_block *sb, struct fs_context *fc) err = erofs_fscache_register_domain(sb); if (err) return err; + err = erofs_domain_register_cookie(sb, &sbi->s_fscache, + sbi->opt.fsid, true); } else { err = erofs_fscache_register_fs(sb); if (err) -- 2.20.1