From nobody Mon Apr 6 20:15:00 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 99BD5C6FA83 for ; Fri, 2 Sep 2022 10:54:26 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S235966AbiIBKyW (ORCPT ); Fri, 2 Sep 2022 06:54:22 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:56410 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231266AbiIBKyN (ORCPT ); Fri, 2 Sep 2022 06:54:13 -0400 Received: from mail-pl1-x634.google.com (mail-pl1-x634.google.com [IPv6:2607:f8b0:4864:20::634]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 92FC4C9270 for ; Fri, 2 Sep 2022 03:54:12 -0700 (PDT) Received: by mail-pl1-x634.google.com with SMTP id l3so1450402plb.10 for ; Fri, 02 Sep 2022 03:54:12 -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=WSGy8JuZtB1pyuGGOt6vRdCmNn8tUcEetPk/ksDWFKg=; b=Wj3S/q7B8Gan3S/BUil/w1zgXVJgnGZFk9DY1ISEhRX861a+dI0bbLwUDboeK2nyuT yM5H76yRuyhNLXxo1C660kdYsaztfOoO9BZ+8ELAEIfJ6Aq0F+BHuTYjwaJKjMmA0xgj kHEoHkFiLt9ddVs8O64lALk2NfhPMvuppzWIxQ4C4EhoZjrdd7qXztHP8omLekIx3N0W +VoBU8A1tyCi0YC9aFZfxTDLlMxzu6WB6Nl9r1CaPTpvYe3m0vg4py1LGrC/yNvBbTUZ qsRk1ymGudIMCyOT/rPjinnAVFIAgv/wzUPE7IsZ5F91eSpAoOYZQylS2tWaWURFB7Ue JY1A== 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=WSGy8JuZtB1pyuGGOt6vRdCmNn8tUcEetPk/ksDWFKg=; b=WvFZISesESsaNTYsqlBD1MbOSZxtRiRjYFcb1csxBMw91fQgJ/NhP+mRWH/CbZtNTd B/J8fdiNX398bFbWilr7/HKdn9dgZzPvIBHHJa1MoPaEKgsn6mfxS/6/MPug3u+v77z7 wN2WA7zE5tnxwKu6Bs8JzQGCqAVWpCoopjkUK/tDoEcQ6BLrBvjlPntVWdIWvEwwND8j m6SlhuX8lsWuwKndy7UiRb4F6riQ/gziE4E+3pkgYpOKA1ibwMKMxlnIn5Vs303VEnns bMza7uJB7b7+boEWfXcJlRlMixz5CIv4RYdQY5SpIj3T56MXiFjCM5QkdWVqsElzM8Op R8gg== X-Gm-Message-State: ACgBeo1U08FLBZIg8RypR85tfULI/EcK6ivzlBx1CTQW8HYR3d9vZPkI 6vu8NVUx/+38kpfdDLDa6wsB9Q== X-Google-Smtp-Source: AA6agR5rfCKb3/V3WdTz2E14dB38FL7AQ1K7gvNoL25/1KczOhYLVFusGaVaI7dDwk3q3G4USKLfkw== X-Received: by 2002:a17:90a:cb14:b0:1fd:c964:f708 with SMTP id z20-20020a17090acb1400b001fdc964f708mr4194965pjt.62.1662116052125; Fri, 02 Sep 2022 03:54:12 -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.07 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 02 Sep 2022 03:54:11 -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 1/5] erofs: add 'domain_id' mount option for on-demand read sementics Date: Fri, 2 Sep 2022 18:53:01 +0800 Message-Id: <20220902105305.79687-2-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: quoted-printable Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" Introduce 'domain_id' mount option to enable shared domain sementics. In which case, the related cookie is shared if two mountpoints in the same domain have the same data blob. Users could specify the name of domain by this mount option. Signed-off-by: Jia Zhu --- fs/erofs/internal.h | 1 + fs/erofs/super.c | 17 +++++++++++++++++ 2 files changed, 18 insertions(+) diff --git a/fs/erofs/internal.h b/fs/erofs/internal.h index cfee49d33b95..fe435d077f1a 100644 --- a/fs/erofs/internal.h +++ b/fs/erofs/internal.h @@ -76,6 +76,7 @@ struct erofs_mount_opts { #endif unsigned int mount_opt; char *fsid; + char *domain_id; }; =20 struct erofs_dev_context { diff --git a/fs/erofs/super.c b/fs/erofs/super.c index 3173debeaa5a..d01109069c6b 100644 --- a/fs/erofs/super.c +++ b/fs/erofs/super.c @@ -440,6 +440,7 @@ enum { Opt_dax_enum, Opt_device, Opt_fsid, + Opt_domain_id, Opt_err }; =20 @@ -465,6 +466,7 @@ static const struct fs_parameter_spec erofs_fs_paramete= rs[] =3D { fsparam_enum("dax", Opt_dax_enum, erofs_dax_param_enums), fsparam_string("device", Opt_device), fsparam_string("fsid", Opt_fsid), + fsparam_string("domain_id", Opt_domain_id), {} }; =20 @@ -568,6 +570,16 @@ static int erofs_fc_parse_param(struct fs_context *fc, return -ENOMEM; #else errorfc(fc, "fsid option not supported"); +#endif + break; + case Opt_domain_id: +#ifdef CONFIG_EROFS_FS_ONDEMAND + kfree(ctx->opt.domain_id); + ctx->opt.domain_id =3D kstrdup(param->string, GFP_KERNEL); + if (!ctx->opt.domain_id) + return -ENOMEM; +#else + errorfc(fc, "domain_id option not supported"); #endif break; default: @@ -695,6 +707,7 @@ static int erofs_fc_fill_super(struct super_block *sb, = struct fs_context *fc) sb->s_fs_info =3D sbi; sbi->opt =3D ctx->opt; ctx->opt.fsid =3D NULL; + ctx->opt.domain_id =3D NULL; sbi->devs =3D ctx->devs; ctx->devs =3D NULL; =20 @@ -838,6 +851,7 @@ static void erofs_fc_free(struct fs_context *fc) =20 erofs_free_dev_context(ctx->devs); kfree(ctx->opt.fsid); + kfree(ctx->opt.domain_id); kfree(ctx); } =20 @@ -892,6 +906,7 @@ static void erofs_kill_sb(struct super_block *sb) erofs_fscache_unregister_cookie(&sbi->s_fscache); erofs_fscache_unregister_fs(sb); kfree(sbi->opt.fsid); + kfree(sbi->opt.domain_id); kfree(sbi); sb->s_fs_info =3D NULL; } @@ -1044,6 +1059,8 @@ static int erofs_show_options(struct seq_file *seq, s= truct dentry *root) #ifdef CONFIG_EROFS_FS_ONDEMAND if (opt->fsid) seq_printf(seq, ",fsid=3D%s", opt->fsid); + if (opt->domain_id) + seq_printf(seq, ",domain_id=3D%s", opt->domain_id); #endif return 0; } --=20 2.20.1 From nobody Mon Apr 6 20:15:00 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 A9EF6C54EE9 for ; Fri, 2 Sep 2022 10:54:30 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S235970AbiIBKy2 (ORCPT ); Fri, 2 Sep 2022 06:54:28 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:56504 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S235960AbiIBKyS (ORCPT ); Fri, 2 Sep 2022 06:54:18 -0400 Received: from mail-pj1-x102a.google.com (mail-pj1-x102a.google.com [IPv6:2607:f8b0:4864:20::102a]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 559FFC9253 for ; Fri, 2 Sep 2022 03:54:17 -0700 (PDT) Received: by mail-pj1-x102a.google.com with SMTP id z3-20020a17090abd8300b001fd803e34f1so5142214pjr.1 for ; Fri, 02 Sep 2022 03:54:17 -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=zk2nhuQ3IgaDvob6zR/vz4weQT1xbu+uln4LzDXMakE=; b=b2wuoQzqqUyA8sgBjUUsmwX1Wxr5983Lnb5Yoeh/N47ZAJ2emwdUyPV4t3j71uiwfy bJpJkd2y7+UPfDA9XIgXz+chEDdfIRzRvkwd5SBDAFfQGU7sM/ierX+hFsVCxuulE08y An6FgTzQumv9rXgUfHMtkDk7hqYs9RuUcAlMQdaJGquuUdnyCoiWwDzmWn33CcuFMIQn rp9NNq3i/+bfVodOGbYxjVcN6rMxBn5OQGihXYaGH7HWw3d/0yjwtjPYLqTFQfKOO6G6 3umi8qwT9p65+urts9YPS4WLgvhtzvF9/9KCweQ/xSdMnw2WOG0tfDTIcMKYjjNUqnXn A4PA== 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=zk2nhuQ3IgaDvob6zR/vz4weQT1xbu+uln4LzDXMakE=; b=XF0S7yGrmktEoXSeq8SABvou5P5AqCWbyb1e5tQFKO4rN3QMxmeD13qfHOba4a3a+4 JMucRIvDOem/jnJHQ51paoXwJcTY3f+MOtDdo9szXvsTX7CxbdNiIOSdgCaSxpbW0GGx 9rGHq1OJ7VTI9Rp38+1UGA1vGRQcjFDm6D/hWfKidEt6FwZnXILxpGMDzxsf7Q82PvX0 Keg88MaoDNdRCAOjfyMJtISgK5FSbQZjTo7rbRbfCJmd8yhX5QeZkBshvukHQVptit+1 ooKEWvCD373fXfKvpHIyrUeGaBJNV/kYCppUd//f0bpJnEIeoM71ywCnMSlOKMWPKGmo 0Ivw== X-Gm-Message-State: ACgBeo1qVTLHTn/F8HGI1mHvwiln8T+08Cwz+d9FAxU3pjPI3lX6hHsr 9KnEvPxYJA+7loLANNSh+/UIPw== X-Google-Smtp-Source: AA6agR7FJjQkb2fUQlTs+ebifWNVHb2U9C9+YOOk4FFJsVDl5s7wUWeZFdfkx9eogUh/nccajxDtog== X-Received: by 2002:a17:902:ec83:b0:174:ce14:ee4 with SMTP id x3-20020a170902ec8300b00174ce140ee4mr22285986plg.17.1662116056806; Fri, 02 Sep 2022 03:54:16 -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.12 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 02 Sep 2022 03:54:16 -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 2/5] erofs: introduce fscache-based domain Date: Fri, 2 Sep 2022 18:53:02 +0800 Message-Id: <20220902105305.79687-3-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: quoted-printable Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" A new fscache-based shared domain mode is going to be introduced for erofs. In which case, same data blobs in same domain will be shared and reused to reduce on-disk space usage. As the first step, we use pseudo mnt to manage and maintain domain's lifecycle. The implementation of sharing blobs will be introduced in subsequent patches. Signed-off-by: Jia Zhu --- fs/erofs/fscache.c | 95 ++++++++++++++++++++++++++++++++++++++++++++- fs/erofs/internal.h | 18 ++++++++- fs/erofs/super.c | 51 ++++++++++++++++++------ 3 files changed, 149 insertions(+), 15 deletions(-) diff --git a/fs/erofs/fscache.c b/fs/erofs/fscache.c index 8e01d89c3319..439dd3cc096a 100644 --- a/fs/erofs/fscache.c +++ b/fs/erofs/fscache.c @@ -1,10 +1,15 @@ // SPDX-License-Identifier: GPL-2.0-or-later /* * Copyright (C) 2022, Alibaba Cloud + * Copyright (C) 2022, Bytedance Inc. All rights reserved. */ #include #include "internal.h" =20 +static DEFINE_MUTEX(erofs_domain_list_lock); +static LIST_HEAD(erofs_domain_list); +static struct vfsmount *erofs_pseudo_mnt; + static struct netfs_io_request *erofs_fscache_alloc_request(struct address= _space *mapping, loff_t start, size_t len) { @@ -417,6 +422,87 @@ const struct address_space_operations erofs_fscache_ac= cess_aops =3D { .readahead =3D erofs_fscache_readahead, }; =20 +static void erofs_fscache_domain_get(struct erofs_domain *domain) +{ + if (!domain) + return; + refcount_inc(&domain->ref); +} + +static void erofs_fscache_domain_put(struct erofs_domain *domain) +{ + if (!domain) + return; + if (refcount_dec_and_test(&domain->ref)) { + fscache_relinquish_volume(domain->volume, NULL, false); + mutex_lock(&erofs_domain_list_lock); + list_del(&domain->list); + mutex_unlock(&erofs_domain_list_lock); + kfree(domain->domain_id); + kfree(domain); + } +} + +static int erofs_fscache_init_domain(struct super_block *sb) +{ + int err; + struct erofs_domain *domain; + struct erofs_sb_info *sbi =3D EROFS_SB(sb); + + domain =3D kzalloc(sizeof(struct erofs_domain), GFP_KERNEL); + if (!domain) + return -ENOMEM; + + domain->domain_id =3D kstrdup(sbi->opt.domain_id, GFP_KERNEL); + if (!domain->domain_id) { + kfree(domain); + return -ENOMEM; + } + sbi->domain =3D domain; + if (!erofs_pseudo_mnt) { + erofs_pseudo_mnt =3D kern_mount(&erofs_fs_type); + if (IS_ERR(erofs_pseudo_mnt)) { + err =3D PTR_ERR(erofs_pseudo_mnt); + goto out; + } + } + err =3D erofs_fscache_register_fs(sb); + if (err) + goto out; + + domain->volume =3D sbi->volume; + refcount_set(&domain->ref, 1); + mutex_init(&domain->mutex); + list_add(&domain->list, &erofs_domain_list); + return 0; +out: + kfree(domain->domain_id); + kfree(domain); + sbi->domain =3D NULL; + return err; +} + +int erofs_fscache_register_domain(struct super_block *sb) +{ + int err; + struct erofs_domain *domain; + struct erofs_sb_info *sbi =3D EROFS_SB(sb); + + mutex_lock(&erofs_domain_list_lock); + list_for_each_entry(domain, &erofs_domain_list, list) { + if (!strcmp(domain->domain_id, sbi->opt.domain_id)) { + erofs_fscache_domain_get(domain); + sbi->domain =3D domain; + sbi->volume =3D domain->volume; + mutex_unlock(&erofs_domain_list_lock); + return 0; + } + } + err =3D erofs_fscache_init_domain(sb); + mutex_unlock(&erofs_domain_list_lock); + return err; +} + int erofs_fscache_register_cookie(struct super_block *sb, struct erofs_fscache **fscache, char *name, bool need_inode) @@ -495,7 +581,8 @@ int erofs_fscache_register_fs(struct super_block *sb) char *name; int ret =3D 0; =20 - name =3D kasprintf(GFP_KERNEL, "erofs,%s", sbi->opt.fsid); + name =3D kasprintf(GFP_KERNEL, "erofs,%s", + sbi->domain ? sbi->domain->domain_id : sbi->opt.fsid); if (!name) return -ENOMEM; =20 @@ -515,6 +602,10 @@ void erofs_fscache_unregister_fs(struct super_block *s= b) { struct erofs_sb_info *sbi =3D EROFS_SB(sb); =20 - fscache_relinquish_volume(sbi->volume, NULL, false); + if (sbi->domain) + erofs_fscache_domain_put(sbi->domain); + else + fscache_relinquish_volume(sbi->volume, NULL, false); sbi->volume =3D NULL; + sbi->domain =3D NULL; } diff --git a/fs/erofs/internal.h b/fs/erofs/internal.h index fe435d077f1a..2790c93ffb83 100644 --- a/fs/erofs/internal.h +++ b/fs/erofs/internal.h @@ -99,6 +99,14 @@ struct erofs_sb_lz4_info { u16 max_pclusterblks; }; =20 +struct erofs_domain { + refcount_t ref; + struct mutex mutex; + struct list_head list; + struct fscache_volume *volume; + char *domain_id; +}; + struct erofs_fscache { struct fscache_cookie *cookie; struct inode *inode; @@ -158,6 +166,7 @@ struct erofs_sb_info { /* fscache support */ struct fscache_volume *volume; struct erofs_fscache *s_fscache; + struct erofs_domain *domain; }; =20 #define EROFS_SB(sb) ((struct erofs_sb_info *)(sb)->s_fs_info) @@ -394,6 +403,7 @@ struct page *erofs_grab_cache_page_nowait(struct addres= s_space *mapping, } =20 extern const struct super_operations erofs_sops; +extern struct file_system_type erofs_fs_type; =20 extern const struct address_space_operations erofs_raw_access_aops; extern const struct address_space_operations z_erofs_aops; @@ -610,6 +620,7 @@ static inline int z_erofs_load_lzma_config(struct super= _block *sb, #ifdef CONFIG_EROFS_FS_ONDEMAND int erofs_fscache_register_fs(struct super_block *sb); void erofs_fscache_unregister_fs(struct super_block *sb); +int erofs_fscache_register_domain(struct super_block *sb); =20 int erofs_fscache_register_cookie(struct super_block *sb, struct erofs_fscache **fscache, @@ -620,10 +631,15 @@ extern const struct address_space_operations erofs_fs= cache_access_aops; #else static inline int erofs_fscache_register_fs(struct super_block *sb) { - return 0; + return -EOPNOTSUPP; } static inline void erofs_fscache_unregister_fs(struct super_block *sb) {} =20 +static inline int erofs_fscache_register_domain(const struct super_block *= sb) +{ + return -EOPNOTSUPP; +} + static inline int erofs_fscache_register_cookie(struct super_block *sb, struct erofs_fscache **fscache, char *name, bool need_inode) diff --git a/fs/erofs/super.c b/fs/erofs/super.c index d01109069c6b..69de1731f454 100644 --- a/fs/erofs/super.c +++ b/fs/erofs/super.c @@ -688,6 +688,13 @@ static const struct export_operations erofs_export_ops= =3D { .get_parent =3D erofs_get_parent, }; =20 +static int erofs_fc_fill_pseudo_super(struct super_block *sb, struct fs_co= ntext *fc) +{ + static const struct tree_descr empty_descr =3D {""}; + + return simple_fill_super(sb, EROFS_SUPER_MAGIC, &empty_descr); +} + static int erofs_fc_fill_super(struct super_block *sb, struct fs_context *= fc) { struct inode *inode; @@ -715,12 +722,17 @@ static int erofs_fc_fill_super(struct super_block *sb= , struct fs_context *fc) sb->s_blocksize =3D EROFS_BLKSIZ; sb->s_blocksize_bits =3D LOG_BLOCK_SIZE; =20 - err =3D erofs_fscache_register_fs(sb); - if (err) - return err; - - err =3D erofs_fscache_register_cookie(sb, &sbi->s_fscache, - sbi->opt.fsid, true); + if (sbi->opt.domain_id) { + err =3D erofs_fscache_register_domain(sb); + if (err) + return err; + } else { + err =3D erofs_fscache_register_fs(sb); + if (err) + return err; + err =3D erofs_fscache_register_cookie(sb, &sbi->s_fscache, + sbi->opt.fsid, true); + } if (err) return err; =20 @@ -798,8 +810,12 @@ static int erofs_fc_get_tree(struct fs_context *fc) { struct erofs_fs_context *ctx =3D fc->fs_private; =20 - if (IS_ENABLED(CONFIG_EROFS_FS_ONDEMAND) && ctx->opt.fsid) - return get_tree_nodev(fc, erofs_fc_fill_super); + if (IS_ENABLED(CONFIG_EROFS_FS_ONDEMAND)) { + if (!ctx && fc->sb_flags & SB_KERNMOUNT) + return get_tree_nodev(fc, erofs_fc_fill_pseudo_super); + if (ctx->opt.fsid) + return get_tree_nodev(fc, erofs_fc_fill_super); + } =20 return get_tree_bdev(fc, erofs_fc_fill_super); } @@ -849,6 +865,8 @@ static void erofs_fc_free(struct fs_context *fc) { struct erofs_fs_context *ctx =3D fc->fs_private; =20 + if (!ctx) + return; erofs_free_dev_context(ctx->devs); kfree(ctx->opt.fsid); kfree(ctx->opt.domain_id); @@ -864,8 +882,12 @@ static const struct fs_context_operations erofs_contex= t_ops =3D { =20 static int erofs_init_fs_context(struct fs_context *fc) { - struct erofs_fs_context *ctx =3D kzalloc(sizeof(*ctx), GFP_KERNEL); + struct erofs_fs_context *ctx; =20 + if (fc->sb_flags & SB_KERNMOUNT) + goto out; + + ctx =3D kzalloc(sizeof(*ctx), GFP_KERNEL); if (!ctx) return -ENOMEM; ctx->devs =3D kzalloc(sizeof(struct erofs_dev_context), GFP_KERNEL); @@ -878,6 +900,7 @@ static int erofs_init_fs_context(struct fs_context *fc) idr_init(&ctx->devs->tree); init_rwsem(&ctx->devs->rwsem); erofs_default_options(ctx); +out: fc->ops =3D &erofs_context_ops; return 0; } @@ -892,6 +915,10 @@ static void erofs_kill_sb(struct super_block *sb) =20 WARN_ON(sb->s_magic !=3D EROFS_SUPER_MAGIC); =20 + if (sb->s_flags & SB_KERNMOUNT) { + kill_litter_super(sb); + return; + } if (erofs_is_fscache_mode(sb)) generic_shutdown_super(sb); else @@ -916,8 +943,8 @@ static void erofs_put_super(struct super_block *sb) { struct erofs_sb_info *const sbi =3D EROFS_SB(sb); =20 - DBG_BUGON(!sbi); - + if (!sbi) + return; erofs_unregister_sysfs(sb); erofs_shrinker_unregister(sb); #ifdef CONFIG_EROFS_FS_ZIP @@ -927,7 +954,7 @@ static void erofs_put_super(struct super_block *sb) erofs_fscache_unregister_cookie(&sbi->s_fscache); } =20 -static struct file_system_type erofs_fs_type =3D { +struct file_system_type erofs_fs_type =3D { .owner =3D THIS_MODULE, .name =3D "erofs", .init_fs_context =3D erofs_init_fs_context, --=20 2.20.1 From nobody Mon Apr 6 20:15:00 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 89D42C38145 for ; Fri, 2 Sep 2022 10:54:45 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S235546AbiIBKym (ORCPT ); Fri, 2 Sep 2022 06:54:42 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:56796 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S235854AbiIBKyj (ORCPT ); Fri, 2 Sep 2022 06:54:39 -0400 Received: from mail-pj1-x1030.google.com (mail-pj1-x1030.google.com [IPv6:2607:f8b0:4864:20::1030]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 35C1EC9910 for ; Fri, 2 Sep 2022 03:54:22 -0700 (PDT) Received: by mail-pj1-x1030.google.com with SMTP id u1-20020a17090a410100b001fff314d14fso1751257pjf.5 for ; Fri, 02 Sep 2022 03:54:22 -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=Jk44PJvjdjdt0bhfpwnVqhAy54lOcNkatPLUifUkm78=; b=KfcOYHlpWUeIQt9wkes3QakVS8YddcaWQ6Bp5getgWzzyA5QFGXOB01D4Byg8lDNNW QJg3+kZ6nXoSJBy2v3dhYD1T2kqsSGg5SQiljr0FiaoOuSKdsR7f/X1KTvjGyVHQ+bIC O7ISw/1864yQHYOFSpM7dVvue4o8mdxEbkQacl82pj3Ul7D7y2pAcmVL4dJcWuepptl3 0nGPQwcoFuiQ3GnBeI5ahRZjWWn2SLY8uhs3KHX/7rCbDGiR2l1kSFm+8or5p3kYoAGu /AHtra/ixW7Cx6Q/R6PZaQvT8b0cU3bezv/5Lkle8JRQb3GSnRLu1sZWWMxph6Jo3Yt5 1xdA== 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=Jk44PJvjdjdt0bhfpwnVqhAy54lOcNkatPLUifUkm78=; b=ME3uwDVGglKlBOvRu6AujYyAhBMNtXgzdd+qiYLDRVxGzD0awe4UihASZmQe0HfSkc 2fs4O1fuItcLsBrm6sL2pUPzZUcy3tAg/3ifrx3H5hq0whebwbwPDCYQ3ZqyLh8dJxZK CTYKaExS7Foz54DdsO4J/uhE6Js3XUhDklNKVcNC6Uab7trNOJYNv4g9tQ/ILOApXpWE 4G+ial64PE+TAuMRRXexTaq2MQK/m8oTKPiUKediE43M4I4vIwNVrT6DEjWy4bOxUqFR v5CcF19hsPB6UCiB1+jwMgfVW5PIgHUeviBv0rvIQICuyEvDQNEPprMVA7vF2uaWfndR JvFw== X-Gm-Message-State: ACgBeo2Joj7xHhdPcpAItQEkEbv409chXpERR/rxFcHB7Y7W7lX4wers Fwc7+Wn2f57vOVMf39dVw2SDbg== X-Google-Smtp-Source: AA6agR5CbDJIoLJsxTWDazQnnhaRRZ4gyoM6tAijLRSZKvM0KW8YTXmAGSJZKg4IxsUEjuUkRPQdzw== X-Received: by 2002:a17:903:1106:b0:172:9801:cb96 with SMTP id n6-20020a170903110600b001729801cb96mr34926139plh.91.1662116061708; Fri, 02 Sep 2022 03:54:21 -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.17 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 02 Sep 2022 03:54:21 -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 3/5] erofs: add 'domain_id' prefix when register sysfs Date: Fri, 2 Sep 2022 18:53:03 +0800 Message-Id: <20220902105305.79687-4-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: quoted-printable Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" In shared domain mount procedure, add 'domain_id' prefix to register sysfs entry. Thus we could distinguish mounts that don't use shared domain. Signed-off-by: Jia Zhu --- fs/erofs/sysfs.c | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/fs/erofs/sysfs.c b/fs/erofs/sysfs.c index c1383e508bbe..c0031d7bd817 100644 --- a/fs/erofs/sysfs.c +++ b/fs/erofs/sysfs.c @@ -201,12 +201,21 @@ static struct kobject erofs_feat =3D { int erofs_register_sysfs(struct super_block *sb) { struct erofs_sb_info *sbi =3D EROFS_SB(sb); + char *name =3D NULL; int err; =20 + if (erofs_is_fscache_mode(sb)) { + name =3D kasprintf(GFP_KERNEL, "%s%s%s", sbi->opt.domain_id ? + sbi->opt.domain_id : "", sbi->opt.domain_id ? "," : "", + sbi->opt.fsid); + if (!name) + return -ENOMEM; + } sbi->s_kobj.kset =3D &erofs_root; init_completion(&sbi->s_kobj_unregister); err =3D kobject_init_and_add(&sbi->s_kobj, &erofs_sb_ktype, NULL, "%s", - erofs_is_fscache_mode(sb) ? sbi->opt.fsid : sb->s_id); + name ? name : sb->s_id); + kfree(name); if (err) goto put_sb_kobj; return 0; --=20 2.20.1 From nobody Mon Apr 6 20:15:00 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 A9A9BECAAD5 for ; Fri, 2 Sep 2022 10:54:49 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S236009AbiIBKys (ORCPT ); Fri, 2 Sep 2022 06:54:48 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:56816 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S235974AbiIBKyk (ORCPT ); Fri, 2 Sep 2022 06:54:40 -0400 Received: from mail-pj1-x1035.google.com (mail-pj1-x1035.google.com [IPv6:2607:f8b0:4864:20::1035]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 7E057C993B for ; Fri, 2 Sep 2022 03:54:27 -0700 (PDT) Received: by mail-pj1-x1035.google.com with SMTP id z9-20020a17090a468900b001ffff693b27so378941pjf.2 for ; Fri, 02 Sep 2022 03:54:27 -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=AuN/fB7WFgyGdRo1r9YkRNBbxG011D/UvehVb1XsFR8=; b=kbfzT2ZCnk1BzCZUOZaSAPZHcn9bDeZoIcCQhUlUv1pniGRGW5nNiT5GTdes8JMaV3 Y95kFlCTrSr2u/ho8LKBpM7nw0xPrCdk5y+RnYRy4rVkIvtbQBJe18GV3ATAHVdkwr6g jSlOLST7OCNNH/NBnvg2ORdfU6UIClzGfrTGx0ck4MdCrOdafFpH5+xU1lxMWQDU5H5b OZgJCmeJ4kGZJg7H4rvp49s+pALBQsNpqQWYlWdSYYyp6YhHMq6twrHzRoJROmbqq3KU iKyDIr8yonTBNEgRk4efSFsvao3qAC2QRKQTyK1/UMwBaOQJAAYjeuDvjBaLxNRXe0mX eJ5w== 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=AuN/fB7WFgyGdRo1r9YkRNBbxG011D/UvehVb1XsFR8=; b=uzruEBFzCQ2xRZCSIgcTeqH7TDsR4ZRG3i2zh5HFopVmieWiTRD+rCa+5VU2Lm3Tok Uv18HP5GgK3GG1Sziwgu5lnh9o1bbCbw7mwpJtsUCGwf64MNsaULt6M+zDwDpNKSINtw h6kHxAOor+y2JkFBEFJepxK4lVZGZsyw/Umv522HD5/gbrxa1OHQa+eFXdhFbIq1qyev SBDit0DiYyunY5HgpHHnjBHENLf55zMNMK61uOH/Jt5aNDpmS+xzUMru3Y6QSqwHZbXu eCu3Lx8zWdwxiRpZTgIWkq3wqPB6b+OT2Qz+PKBU82rRXtErppsBVi0NU/H2zQ/Ctv29 /xQA== X-Gm-Message-State: ACgBeo201vvF8vK848tHJ/kbinzIoL3ExRlnqsyyyuhH2cr05OJjD68I PYxYjVpXfY65O98jbEctSUGX4w== X-Google-Smtp-Source: AA6agR6QGCXjeNASveGGnc4rOolzyZrMO6wMXa37BzI3m3bNUn3hb0Yu28Yt2LmUN5gFf7V7aMdZ9A== X-Received: by 2002:a17:90b:4aca:b0:1fe:686:fbf3 with SMTP id mh10-20020a17090b4aca00b001fe0686fbf3mr4194388pjb.174.1662116066994; Fri, 02 Sep 2022 03:54:26 -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.22 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 02 Sep 2022 03:54:26 -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 4/5] erofs: remove duplicated unregister_cookie Date: Fri, 2 Sep 2022 18:53:04 +0800 Message-Id: <20220902105305.79687-5-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: quoted-printable Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" In erofs umount scenario, erofs_fscache_unregister_cookie() is called twice in kill_sb() and put_super(). It works for original semantics, cause 'ctx' will be set to NULL in put_super() and will not be unregister again in kill_sb(). However, in shared domain scenario, we use refcount to maintain the lifecycle of cookie. Unregister the cookie twice will cause it to be released early. For the above reasons, this patch removes duplicate unregister_cookie and move fscache_unregister_* before shotdown_super() to prevent busy inode(ctx->inode) when umount. Signed-off-by: Jia Zhu --- fs/erofs/super.c | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/fs/erofs/super.c b/fs/erofs/super.c index 69de1731f454..667a78f0ee70 100644 --- a/fs/erofs/super.c +++ b/fs/erofs/super.c @@ -919,19 +919,20 @@ static void erofs_kill_sb(struct super_block *sb) kill_litter_super(sb); return; } - if (erofs_is_fscache_mode(sb)) - generic_shutdown_super(sb); - else - kill_block_super(sb); - sbi =3D EROFS_SB(sb); if (!sbi) return; =20 + if (erofs_is_fscache_mode(sb)) { + erofs_fscache_unregister_cookie(&sbi->s_fscache); + erofs_fscache_unregister_fs(sb); + generic_shutdown_super(sb); + } else { + kill_block_super(sb); + } + erofs_free_dev_context(sbi->devs); fs_put_dax(sbi->dax_dev, NULL); - erofs_fscache_unregister_cookie(&sbi->s_fscache); - erofs_fscache_unregister_fs(sb); kfree(sbi->opt.fsid); kfree(sbi->opt.domain_id); kfree(sbi); @@ -951,7 +952,6 @@ static void erofs_put_super(struct super_block *sb) iput(sbi->managed_cache); sbi->managed_cache =3D NULL; #endif - erofs_fscache_unregister_cookie(&sbi->s_fscache); } =20 struct file_system_type erofs_fs_type =3D { --=20 2.20.1 From nobody Mon Apr 6 20:15:00 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 1BB46ECAAD5 for ; Fri, 2 Sep 2022 10:55:04 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S235482AbiIBKy7 (ORCPT ); Fri, 2 Sep 2022 06:54:59 -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-Google-Smtp-Source: AA6agR5ys7kCNuYBLszHsMp707kVrAarVSZrzYdKxepFPo9Ogdt9dOBDXKfD0986/w+xjOMoXqlXOQ== 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: 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 | 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 =3D *fscache; + struct erofs_domain *domain; =20 if (!ctx) return; + domain =3D 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); + } =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); @@ -609,3 +624,61 @@ void erofs_fscache_unregister_fs(struct super_block *s= b) sbi->volume =3D NULL; sbi->domain =3D 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 =3D EROFS_SB(sb); + struct erofs_domain *domain =3D sbi->domain; + + ret =3D erofs_fscache_register_cookie(sb, &ctx, name, need_inode); + if (ret) + return ret; + + ctx->name =3D kstrdup(name, GFP_KERNEL); + if (!ctx->name) + return -ENOMEM; + + inode =3D new_inode(erofs_pseudo_mnt->mnt_sb); + if (!inode) { + kfree(ctx->name); + return -ENOMEM; + } + + ctx->domain =3D domain; + ctx->anon_inode =3D inode; + inode->i_private =3D ctx; + erofs_fscache_domain_get(domain); + *fscache =3D 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 =3D EROFS_SB(sb); + struct erofs_domain *domain =3D sbi->domain; + struct super_block *psb =3D erofs_pseudo_mnt->mnt_sb; + + mutex_lock(&domain->mutex); + list_for_each_entry(inode, &psb->s_inodes, i_sb_list) { + ctx =3D inode->i_private; + if (!ctx) + continue; + if (!strcmp(ctx->name, name)) { + *fscache =3D ctx; + igrab(inode); + mutex_unlock(&domain->mutex); + return 0; + } + } + err =3D 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; }; =20 struct erofs_sb_info { @@ -625,6 +628,9 @@ int erofs_fscache_register_domain(struct super_block *s= b); 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); =20 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; +} =20 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, st= ruct super_block *sb, } =20 if (erofs_is_fscache_mode(sb)) { - ret =3D erofs_fscache_register_cookie(sb, &dif->fscache, - dif->path, false); + if (sbi->opt.domain_id) + ret =3D erofs_domain_register_cookie(sb, &dif->fscache, dif->path, + false); + else + ret =3D 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 =3D erofs_fscache_register_domain(sb); if (err) return err; + err =3D erofs_domain_register_cookie(sb, &sbi->s_fscache, + sbi->opt.fsid, true); } else { err =3D erofs_fscache_register_fs(sb); if (err) --=20 2.20.1