From nobody Fri Apr 3 08:22:43 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 E53BCECAAD8 for ; Wed, 14 Sep 2022 10:51:15 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229822AbiINKvO (ORCPT ); Wed, 14 Sep 2022 06:51:14 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:39298 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229968AbiINKvA (ORCPT ); Wed, 14 Sep 2022 06:51:00 -0400 Received: from mail-pf1-x434.google.com (mail-pf1-x434.google.com [IPv6:2607:f8b0:4864:20::434]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id AF75C62A80 for ; Wed, 14 Sep 2022 03:50:54 -0700 (PDT) Received: by mail-pf1-x434.google.com with SMTP id y136so14532873pfb.3 for ; Wed, 14 Sep 2022 03:50:54 -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=Wc6UqN2rBrRPIKRWEZkd/HK/BLX6Fc+iydsV3In6uJs=; b=oOrs1LpYB0NxT5AuspZSwCGv3oFKdg6VgFR8OpUnYS8lvjCNyjNb/6jMklnwW1HBGG jI/xowxQ77fW1KZdkpQYusZAof47Be5v/T65EGudfxhj6viEnmeUtuyU7h3liWHDO8fE lC9lPZZ1gL1c/pG/d08McSFu81TO3OX20KtJu1juI83ho9KOwBhj74EvxOx5tzd9ofwY cwm9FABc2VC+ElY//cOiWMCQBVXGAXyigc9SV5QPWg3+AW7sUeHh9/nTxz5nTq+pU+Vv Wy4EE34SYw/R4YMCJiD56PdZZharxDBstXYdsBEDc4DM84Rl3fDPFYlpa+TODRsI/wun rh3w== 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=Wc6UqN2rBrRPIKRWEZkd/HK/BLX6Fc+iydsV3In6uJs=; b=52bD9L4FhJbIoq3SfU9+jOP/gY+r68j/4sXh5h5SKRixjKpjstjNCffXWOS2SJHqaD xbdHJECPVmdEdJ2Mtrh/EhigIkf99OmfsLYWtszntpVOzYiH4e0399PiNp7nTqBgLhAm r495fRHIk3pvoAmGLpRPim5HYOoqCR99/sRPFfo35CEN9rBD2yowaFs4rmOIMc69Q/b+ phgHz+uBRm8YweUCbLoUmqEiEof0yRf4KoPGM47gbuGfasQJPuo3Z+c0XreVFL/Avew/ 0tqrfx9leH/ty6nm2/REG+/S9uZ9hZmCQo3SvocR1CsdbCTFTaCs3mj6kOwwzeHOG2FR Si7A== X-Gm-Message-State: ACgBeo2cYiIPaZQ1FsmT+/yR1N0gvcILRKXoR9dVhqKNAvdZb3e8bd61 j2r03Rtnb5s3KwFzZeU6HTKIJg== X-Google-Smtp-Source: AA6agR6IR4Tl5gCLaL9fQ77Ogd5yC58UKWzNowxeQQLx0k6N3fYtgtwq1tRtRPwePR65gLmmmdj8UA== X-Received: by 2002:a65:6048:0:b0:412:73c7:cca9 with SMTP id a8-20020a656048000000b0041273c7cca9mr32293293pgp.257.1663152654247; Wed, 14 Sep 2022 03:50:54 -0700 (PDT) Received: from C02G705SMD6V.bytedance.net ([2400:8800:1f02:83:4000:0:1:2]) by smtp.gmail.com with ESMTPSA id x13-20020a170902ec8d00b0016dc2366722sm10537042plg.77.2022.09.14.03.50.50 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 14 Sep 2022 03:50:53 -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 V3 1/6] erofs: use kill_anon_super() to kill super in fscache mode Date: Wed, 14 Sep 2022 18:50:36 +0800 Message-Id: <20220914105041.42970-2-zhujia.zj@bytedance.com> X-Mailer: git-send-email 2.37.0 (Apple Git-136) In-Reply-To: <20220914105041.42970-1-zhujia.zj@bytedance.com> References: <20220914105041.42970-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" Use kill_anon_super() instead of generic_shutdown_super() since the mount() in erofs fscache mode uses get_tree_nodev() and associated anon bdev needs to be freed. Signed-off-by: Jingbo Xu Signed-off-by: Jia Zhu Reviewed-by: Jingbo Xu --- fs/erofs/super.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/fs/erofs/super.c b/fs/erofs/super.c index 3173debeaa5a..9716d355a63e 100644 --- a/fs/erofs/super.c +++ b/fs/erofs/super.c @@ -879,7 +879,7 @@ static void erofs_kill_sb(struct super_block *sb) WARN_ON(sb->s_magic !=3D EROFS_SUPER_MAGIC); =20 if (erofs_is_fscache_mode(sb)) - generic_shutdown_super(sb); + kill_anon_super(sb); else kill_block_super(sb); =20 --=20 2.20.1 From nobody Fri Apr 3 08:22:43 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 DEE4EECAAD3 for ; Wed, 14 Sep 2022 10:51:26 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230029AbiINKvZ (ORCPT ); Wed, 14 Sep 2022 06:51:25 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:39718 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229972AbiINKvN (ORCPT ); Wed, 14 Sep 2022 06:51:13 -0400 Received: from mail-pf1-x432.google.com (mail-pf1-x432.google.com [IPv6:2607:f8b0:4864:20::432]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id D832A77E9A for ; Wed, 14 Sep 2022 03:50:58 -0700 (PDT) Received: by mail-pf1-x432.google.com with SMTP id a80so5942158pfa.4 for ; Wed, 14 Sep 2022 03:50:58 -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=mLKoFPsfe1DGX67jxmoOMM6ui+KnXFQNQxxyiB6uJvQ=; b=wuB6Y8o7aBM+itTdXuxbD9c9ov2tLG0Re7l2uBZ7YsxJr9YLMuY+rQpmy0KcyxH43B CDaMvLmDbhoGhdUma+3KR6N4jNBW9P1Smph3Nh7+cPODdEDuWVJhIRB8YcszkwsUmktU n/zWlKad//6cofQRLkqmyjCiTqdiQbw2N2rNXggm6veLySgMwOdc2bYlObleX+Yi2sO/ DI3gAK7pcEO/vnSPYVqArRxAinRjQI7NvBu02rFPpSvKtpp+9FGVxkrd0fsBGujWd47V 51qsMnezq/zeoKKoydcDXO7GdsPp7dNIEi9ka0UaRSAt7Mb5LK1bGRVH0njwarepSHyn 8t8g== 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=mLKoFPsfe1DGX67jxmoOMM6ui+KnXFQNQxxyiB6uJvQ=; b=sxxBUlJtm+ILDBVbrCD+JvX9phhuhp8B0EupfDi9nHKjQAU7Fsl/nj++bF40T7vEdn 6yXK/9/s671mrGchAGE/Zz0WXS8EhjIwVL3HRK+1z+B5T0r4tzk76Dkcuxmi+QsB8kfH OpXDsFHPIRNdezpK1jdcymHxzpm+8jjAoKCbEe+xBFhD/kbCydlKGMahi5f3L7vuISUL 8ORI8wdTuUYOiDN5lXnJ/VYS+mTPxhv3FYbFru7qBUvcVcHAXyayQQScAyK9Gsaci4QT 1I2h4xEFOatxvgWAfahb5LOF9yZ1jSwpC3Ny33W20NUBQ1kd0tXWzOS0op26CcxLCRnr DUiw== X-Gm-Message-State: ACgBeo0esOxcouOwoyBTvnjZLeiur2WkmxGRzG2ibo3JWlnRdbNYFx7E UXhHEShIw7rMie0+ADgGwGZSYA== X-Google-Smtp-Source: AA6agR4fp34wrjI43Hdysv4EUHq0KqK4ftDpRUIqIM0HnWzgjWPBkYz+EgLGamHV3dSau08iBdku4Q== X-Received: by 2002:a63:e305:0:b0:439:6e0c:f81e with SMTP id f5-20020a63e305000000b004396e0cf81emr1144234pgh.50.1663152657977; Wed, 14 Sep 2022 03:50:57 -0700 (PDT) Received: from C02G705SMD6V.bytedance.net ([2400:8800:1f02:83:4000:0:1:2]) by smtp.gmail.com with ESMTPSA id x13-20020a170902ec8d00b0016dc2366722sm10537042plg.77.2022.09.14.03.50.54 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 14 Sep 2022 03:50:57 -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 V3 2/6] erofs: code clean up for fscache Date: Wed, 14 Sep 2022 18:50:37 +0800 Message-Id: <20220914105041.42970-3-zhujia.zj@bytedance.com> X-Mailer: git-send-email 2.37.0 (Apple Git-136) In-Reply-To: <20220914105041.42970-1-zhujia.zj@bytedance.com> References: <20220914105041.42970-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" Some cleanups. No logic changes. Signed-off-by: Jingbo Xu Signed-off-by: Jia Zhu --- fs/erofs/fscache.c | 26 +++++++++++++++----------- fs/erofs/internal.h | 17 ++++++++--------- fs/erofs/super.c | 22 +++++++++------------- 3 files changed, 32 insertions(+), 33 deletions(-) diff --git a/fs/erofs/fscache.c b/fs/erofs/fscache.c index 8e01d89c3319..4159cf781924 100644 --- a/fs/erofs/fscache.c +++ b/fs/erofs/fscache.c @@ -417,9 +417,8 @@ const struct address_space_operations erofs_fscache_acc= ess_aops =3D { .readahead =3D erofs_fscache_readahead, }; =20 -int erofs_fscache_register_cookie(struct super_block *sb, - struct erofs_fscache **fscache, - char *name, bool need_inode) +struct erofs_fscache *erofs_fscache_register_cookie(struct super_block *sb, + char *name, bool need_inode) { struct fscache_volume *volume =3D EROFS_SB(sb)->volume; struct erofs_fscache *ctx; @@ -428,7 +427,7 @@ int erofs_fscache_register_cookie(struct super_block *s= b, =20 ctx =3D kzalloc(sizeof(*ctx), GFP_KERNEL); if (!ctx) - return -ENOMEM; + return ERR_PTR(-ENOMEM); =20 cookie =3D fscache_acquire_cookie(volume, FSCACHE_ADV_WANT_CACHE_SIZE, name, strlen(name), NULL, 0, 0); @@ -458,8 +457,7 @@ int erofs_fscache_register_cookie(struct super_block *s= b, ctx->inode =3D inode; } =20 - *fscache =3D ctx; - return 0; + return ctx; =20 err_cookie: fscache_unuse_cookie(ctx->cookie, NULL, NULL); @@ -467,13 +465,11 @@ int erofs_fscache_register_cookie(struct super_block = *sb, ctx->cookie =3D NULL; err: kfree(ctx); - return ret; + return ERR_PTR(ret); } =20 -void erofs_fscache_unregister_cookie(struct erofs_fscache **fscache) +void erofs_fscache_unregister_cookie(struct erofs_fscache *ctx) { - struct erofs_fscache *ctx =3D *fscache; - if (!ctx) return; =20 @@ -485,13 +481,13 @@ void erofs_fscache_unregister_cookie(struct erofs_fsc= ache **fscache) ctx->inode =3D NULL; =20 kfree(ctx); - *fscache =3D NULL; } =20 int erofs_fscache_register_fs(struct super_block *sb) { struct erofs_sb_info *sbi =3D EROFS_SB(sb); struct fscache_volume *volume; + struct erofs_fscache *fscache; char *name; int ret =3D 0; =20 @@ -508,6 +504,12 @@ int erofs_fscache_register_fs(struct super_block *sb) =20 sbi->volume =3D volume; kfree(name); + + fscache =3D erofs_fscache_register_cookie(sb, sbi->opt.fsid, true); + if (IS_ERR(fscache)) + return PTR_ERR(fscache); + + sbi->s_fscache =3D fscache; return ret; } =20 @@ -515,6 +517,8 @@ void erofs_fscache_unregister_fs(struct super_block *sb) { struct erofs_sb_info *sbi =3D EROFS_SB(sb); =20 + erofs_fscache_unregister_cookie(sbi->s_fscache); fscache_relinquish_volume(sbi->volume, NULL, false); + sbi->s_fscache =3D NULL; sbi->volume =3D NULL; } diff --git a/fs/erofs/internal.h b/fs/erofs/internal.h index cfee49d33b95..aa71eb65e965 100644 --- a/fs/erofs/internal.h +++ b/fs/erofs/internal.h @@ -610,27 +610,26 @@ static inline int z_erofs_load_lzma_config(struct sup= er_block *sb, int erofs_fscache_register_fs(struct super_block *sb); void erofs_fscache_unregister_fs(struct super_block *sb); =20 -int erofs_fscache_register_cookie(struct super_block *sb, - struct erofs_fscache **fscache, - char *name, bool need_inode); -void erofs_fscache_unregister_cookie(struct erofs_fscache **fscache); +struct erofs_fscache *erofs_fscache_register_cookie(struct super_block *sb, + 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; #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_cookie(struct super_block *sb, - struct erofs_fscache **fscache, - char *name, bool need_inode) +static inline +struct erofs_fscache *erofs_fscache_register_cookie(struct super_block *sb, + char *name, bool need_inode) { return -EOPNOTSUPP; } =20 -static inline void erofs_fscache_unregister_cookie(struct erofs_fscache **= fscache) +static inline void erofs_fscache_unregister_cookie(struct erofs_fscache *f= scache) { } #endif diff --git a/fs/erofs/super.c b/fs/erofs/super.c index 9716d355a63e..7aa57dcebf31 100644 --- a/fs/erofs/super.c +++ b/fs/erofs/super.c @@ -224,10 +224,10 @@ static int erofs_init_device(struct erofs_buf *buf, s= truct super_block *sb, struct erofs_device_info *dif, erofs_off_t *pos) { struct erofs_sb_info *sbi =3D EROFS_SB(sb); + struct erofs_fscache *fscache; struct erofs_deviceslot *dis; struct block_device *bdev; void *ptr; - int ret; =20 ptr =3D erofs_read_metabuf(buf, sb, erofs_blknr(*pos), EROFS_KMAP); if (IS_ERR(ptr)) @@ -245,10 +245,10 @@ static int erofs_init_device(struct erofs_buf *buf, s= truct super_block *sb, } =20 if (erofs_is_fscache_mode(sb)) { - ret =3D erofs_fscache_register_cookie(sb, &dif->fscache, - dif->path, false); - if (ret) - return ret; + fscache =3D erofs_fscache_register_cookie(sb, dif->path, false); + if (IS_ERR(fscache)) + return PTR_ERR(fscache); + dif->fscache =3D fscache; } else { bdev =3D blkdev_get_by_path(dif->path, FMODE_READ | FMODE_EXCL, sb->s_type); @@ -706,11 +706,6 @@ static int erofs_fc_fill_super(struct super_block *sb,= struct fs_context *fc) if (err) return err; =20 - err =3D erofs_fscache_register_cookie(sb, &sbi->s_fscache, - sbi->opt.fsid, true); - if (err) - return err; - err =3D super_setup_bdi(sb); if (err) return err; @@ -817,7 +812,8 @@ static int erofs_release_device_info(int id, void *ptr,= void *data) fs_put_dax(dif->dax_dev, NULL); if (dif->bdev) blkdev_put(dif->bdev, FMODE_READ | FMODE_EXCL); - erofs_fscache_unregister_cookie(&dif->fscache); + erofs_fscache_unregister_cookie(dif->fscache); + dif->fscache =3D NULL; kfree(dif->path); kfree(dif); return 0; @@ -889,7 +885,6 @@ static void erofs_kill_sb(struct super_block *sb) =20 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); @@ -909,7 +904,8 @@ 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); + erofs_fscache_unregister_cookie(sbi->s_fscache); + sbi->s_fscache =3D NULL; } =20 static struct file_system_type erofs_fs_type =3D { --=20 2.20.1 From nobody Fri Apr 3 08:22:43 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 528C2ECAAD8 for ; Wed, 14 Sep 2022 10:51:39 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230085AbiINKvh (ORCPT ); Wed, 14 Sep 2022 06:51:37 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:39838 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229987AbiINKvS (ORCPT ); Wed, 14 Sep 2022 06:51:18 -0400 Received: from mail-pl1-x635.google.com (mail-pl1-x635.google.com [IPv6:2607:f8b0:4864:20::635]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id DF2897B7A6 for ; Wed, 14 Sep 2022 03:51:02 -0700 (PDT) Received: by mail-pl1-x635.google.com with SMTP id t3so14742264ply.2 for ; Wed, 14 Sep 2022 03:51:02 -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=q3TsfZkeKJw5XNsDWUMmFDs6Gnk1XCvOAhXnXaSVyI4=; b=05u3YH9R0psRe49MO2FNU8/5dfjtU6+uA3PESMKlS7YdPzozmMNv6CugV4OxDP/9qa 7XoEXoB3qcWpKYfZnhvS7qMIKQ6O29eYjYHE2HTXR6BhgbzG6FQpmmwIJzcKbE1d7pvx 3DGyqwP+3s5UBMrH0K5OXRRcb0SBYu+G1eMuJXb9/ybkkUH41iO6yqo26f7Zz5GC42Pi 8dzPXef/azuIbsGrG6WIxcrSlwv/r2YMGF2ViVMNyn1ehUXLHrXo0HS9mZSX/2HFioBJ fnHgiAMK/irWYa+C5+YiEhjlvG6iI9yoVNpw6dqtXSdpfps0lWx/L/3ePy1N+gMmPQep c6pw== 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=q3TsfZkeKJw5XNsDWUMmFDs6Gnk1XCvOAhXnXaSVyI4=; b=0FFcpIeAzO55GIZ3HTaEb5WzsGbd39xaFJ5WOh/RKGGOpzR8qM+U/emOrAAV+lUKn0 d3j7CnWxr+mMF7MIKyLrsw+KNYVVE2UMvvhQOtARgmaRO9bUVqIVmq5emXJwn+0UjIRx XMiLRX9EundiqlutlhRrU6uyZfy06jLPzQmdOoJWnoylAwEaIHIM1R2vcEvDG+NkB44X q9bEdhoq81SIOUwpB+07BQVzDzXQdJTTLihFcng13NbOl/SwgCYLv/2Z8qsa2OacGWa8 caOXgrPnjthHdnHfmb27iEx5RcbRUj3EpSHEjDkYZ+vH1X/zfwjWRfOISDP0jOT5A6wG ImZQ== X-Gm-Message-State: ACrzQf2j8NPnWN0LH0qoVi6NIfhqajSl2UdcCCbYygZ8e7y+Plqb+v7i uBdnxFuXGA1VIUrrA7cON2JC5g== X-Google-Smtp-Source: AA6agR7NDk5OHRM9Rd6OftgJi3/gHYY1TyxgEHCKEeThw53Wb1mA8mROSozj5Sh4+p9vi/4BBbPuig== X-Received: by 2002:a17:90b:3808:b0:202:c5ba:d71b with SMTP id mq8-20020a17090b380800b00202c5bad71bmr4102692pjb.18.1663152661702; Wed, 14 Sep 2022 03:51:01 -0700 (PDT) Received: from C02G705SMD6V.bytedance.net ([2400:8800:1f02:83:4000:0:1:2]) by smtp.gmail.com with ESMTPSA id x13-20020a170902ec8d00b0016dc2366722sm10537042plg.77.2022.09.14.03.50.58 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 14 Sep 2022 03:51:01 -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 V3 3/6] erofs: introduce 'domain_id' mount option Date: Wed, 14 Sep 2022 18:50:38 +0800 Message-Id: <20220914105041.42970-4-zhujia.zj@bytedance.com> X-Mailer: git-send-email 2.37.0 (Apple Git-136) In-Reply-To: <20220914105041.42970-1-zhujia.zj@bytedance.com> References: <20220914105041.42970-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 +++++++++++++++++ fs/erofs/sysfs.c | 19 +++++++++++++++++-- 3 files changed, 35 insertions(+), 2 deletions(-) diff --git a/fs/erofs/internal.h b/fs/erofs/internal.h index aa71eb65e965..2d129c6b3027 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 7aa57dcebf31..856758ee4869 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 @@ -834,6 +847,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 @@ -887,6 +901,7 @@ static void erofs_kill_sb(struct super_block *sb) fs_put_dax(sbi->dax_dev, NULL); erofs_fscache_unregister_fs(sb); kfree(sbi->opt.fsid); + kfree(sbi->opt.domain_id); kfree(sbi); sb->s_fs_info =3D NULL; } @@ -1040,6 +1055,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; } diff --git a/fs/erofs/sysfs.c b/fs/erofs/sysfs.c index c1383e508bbe..341fb43ad587 100644 --- a/fs/erofs/sysfs.c +++ b/fs/erofs/sysfs.c @@ -201,12 +201,27 @@ 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; + char *str =3D NULL; int err; =20 + if (erofs_is_fscache_mode(sb)) { + if (sbi->opt.domain_id) { + str =3D kasprintf(GFP_KERNEL, "%s,%s", sbi->opt.domain_id, + sbi->opt.fsid); + if (!str) + return -ENOMEM; + name =3D str; + } else { + name =3D sbi->opt.fsid; + } + } else { + name =3D sb->s_id; + } 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); + err =3D kobject_init_and_add(&sbi->s_kobj, &erofs_sb_ktype, NULL, "%s", n= ame); + kfree(str); if (err) goto put_sb_kobj; return 0; --=20 2.20.1 From nobody Fri Apr 3 08:22:43 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 AE6FEECAAD3 for ; Wed, 14 Sep 2022 10:51:45 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230100AbiINKvn (ORCPT ); Wed, 14 Sep 2022 06:51:43 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:40070 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230031AbiINKv0 (ORCPT ); Wed, 14 Sep 2022 06:51:26 -0400 Received: from mail-pl1-x62c.google.com (mail-pl1-x62c.google.com [IPv6:2607:f8b0:4864:20::62c]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 5416F7CABF for ; Wed, 14 Sep 2022 03:51:06 -0700 (PDT) Received: by mail-pl1-x62c.google.com with SMTP id s18so8779497plr.4 for ; Wed, 14 Sep 2022 03:51:06 -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=8McC9dsHojc4NyE65toTstywUmp/NndsAZvxbDSio0Q=; b=zGdqejR9YMZ1NQME8AnBkbg16ephrXZmwwVcx2COtNRdsx2dO4n9pAhyd0Krg3/kOe woHdAbQ3c/JG+CBmygqmsGziLRmt/T1Pmm6W+e51MkRybekCSU8Tvl1dv3B/p+XOulzN KzkGag/2Ilj6YVGwmbQs+z7DDu151i0YZwB+pmUKLgH0FOPzM/9pL5KUY/cexUd5mJz4 3GPsqpHhHJi7Ed6VtXbpK6hc2NARGq4rTnnn5r+I289urSlN1B0BARQDiNncKU+4C8vp fZMvtLE6C8vPA7u1N0dQ8+24V0Ig8TwwW1ali9fpb6D9YqziCVy2Gj69RZer20b0APjU iSHQ== 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=8McC9dsHojc4NyE65toTstywUmp/NndsAZvxbDSio0Q=; b=QP6xVLbl9LmZHWoGWLSCZnh6nr/0HYqnlntUHOkvPJtaWHpkP8uqvCJwIfcuSrHEav ooIg1Qur/orWV5Ksay/+dTpZ3Xq6iB8UhdBEa3+dntjpnFhqhSgB0XjxD6IrSvDn44Pk I+3XdngCmR61gFirnwEe0QMHeKYl7PSi5LD89mIIynhihUjZH/trrt1cqEh+j0RuYWIa KHKVXp0iQdEM0ceC1gNqZoxTpkc53O7/4JGb5MMFY0aIdouo3ceJQhP//tNh0QFFnxTk JTl6JFD9AkNDaa1eUZzdiRURarGyVesDvL02SSRVrQ/wKwL5MJBDHEf7N1uHTc8tc8Ms JrnQ== X-Gm-Message-State: ACrzQf1ER+093en7+sOmg5ZkVpNYsbuYiugMJfUI+Ya4D3GFn8kazi5i qBTvxCRhXjJkrAeExQ2mjr7Y6w== X-Google-Smtp-Source: AMsMyM7Re2VNLh6tWmIDLba8vHJ7cUt5xyjLC++rV5FO5XvDwdSLPNP+RieQ+jTsgtkU4MLbrc2VCw== X-Received: by 2002:a17:90a:7642:b0:200:4a5e:1227 with SMTP id s2-20020a17090a764200b002004a5e1227mr4019174pjl.91.1663152665397; Wed, 14 Sep 2022 03:51:05 -0700 (PDT) Received: from C02G705SMD6V.bytedance.net ([2400:8800:1f02:83:4000:0:1:2]) by smtp.gmail.com with ESMTPSA id x13-20020a170902ec8d00b0016dc2366722sm10537042plg.77.2022.09.14.03.51.02 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 14 Sep 2022 03:51:05 -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 V3 4/6] erofs: introduce fscache-based domain Date: Wed, 14 Sep 2022 18:50:39 +0800 Message-Id: <20220914105041.42970-5-zhujia.zj@bytedance.com> X-Mailer: git-send-email 2.37.0 (Apple Git-136) In-Reply-To: <20220914105041.42970-1-zhujia.zj@bytedance.com> References: <20220914105041.42970-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 | 134 ++++++++++++++++++++++++++++++++++++++------ fs/erofs/internal.h | 9 +++ 2 files changed, 127 insertions(+), 16 deletions(-) diff --git a/fs/erofs/fscache.c b/fs/erofs/fscache.c index 4159cf781924..b2100dc67cde 100644 --- a/fs/erofs/fscache.c +++ b/fs/erofs/fscache.c @@ -1,10 +1,14 @@ // 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 netfs_io_request *erofs_fscache_alloc_request(struct address= _space *mapping, loff_t start, size_t len) { @@ -417,6 +421,106 @@ const struct address_space_operations erofs_fscache_a= ccess_aops =3D { .readahead =3D erofs_fscache_readahead, }; =20 +static +struct erofs_domain *erofs_fscache_domain_get(struct erofs_domain *domain) +{ + refcount_inc(&domain->ref); + return domain; +} + +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_register_volume(struct super_block *sb) +{ + struct erofs_sb_info *sbi =3D EROFS_SB(sb); + char *domain_id =3D sbi->opt.domain_id; + struct fscache_volume *volume; + char *name; + int ret =3D 0; + + if (domain_id) + name =3D kasprintf(GFP_KERNEL, "erofs,%s", domain_id); + else + name =3D kasprintf(GFP_KERNEL, "erofs,%s", sbi->opt.fsid); + if (!name) + return -ENOMEM; + + volume =3D fscache_acquire_volume(name, NULL, NULL, 0); + if (IS_ERR_OR_NULL(volume)) { + erofs_err(sb, "failed to register volume for %s", name); + ret =3D volume ? PTR_ERR(volume) : -EOPNOTSUPP; + volume =3D NULL; + } + + sbi->volume =3D volume; + kfree(name); + return ret; +} + +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; + err =3D erofs_fscache_register_volume(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; +} + +static 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)) { + sbi->domain =3D erofs_fscache_domain_get(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; +} + struct erofs_fscache *erofs_fscache_register_cookie(struct super_block *sb, char *name, bool need_inode) { @@ -486,24 +590,16 @@ void erofs_fscache_unregister_cookie(struct erofs_fsc= ache *ctx) int erofs_fscache_register_fs(struct super_block *sb) { struct erofs_sb_info *sbi =3D EROFS_SB(sb); - struct fscache_volume *volume; struct erofs_fscache *fscache; - char *name; - int ret =3D 0; + int ret; =20 - name =3D kasprintf(GFP_KERNEL, "erofs,%s", sbi->opt.fsid); - if (!name) - return -ENOMEM; + if (sbi->opt.domain_id) + ret =3D erofs_fscache_register_domain(sb); + else + ret =3D erofs_fscache_register_volume(sb); =20 - volume =3D fscache_acquire_volume(name, NULL, NULL, 0); - if (IS_ERR_OR_NULL(volume)) { - erofs_err(sb, "failed to register volume for %s", name); - ret =3D volume ? PTR_ERR(volume) : -EOPNOTSUPP; - volume =3D NULL; - } - - sbi->volume =3D volume; - kfree(name); + if (ret) + return ret; =20 fscache =3D erofs_fscache_register_cookie(sb, sbi->opt.fsid, true); if (IS_ERR(fscache)) @@ -518,7 +614,13 @@ void erofs_fscache_unregister_fs(struct super_block *s= b) struct erofs_sb_info *sbi =3D EROFS_SB(sb); =20 erofs_fscache_unregister_cookie(sbi->s_fscache); - fscache_relinquish_volume(sbi->volume, NULL, false); sbi->s_fscache =3D NULL; + + 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 2d129c6b3027..5ce6889d6f1d 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) --=20 2.20.1 From nobody Fri Apr 3 08:22:43 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 AEFEEECAAD3 for ; Wed, 14 Sep 2022 10:52:02 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230043AbiINKwB (ORCPT ); Wed, 14 Sep 2022 06:52:01 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:40236 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230014AbiINKvc (ORCPT ); Wed, 14 Sep 2022 06:51:32 -0400 Received: from mail-pj1-x102f.google.com (mail-pj1-x102f.google.com [IPv6:2607:f8b0:4864:20::102f]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 313177D7BA for ; Wed, 14 Sep 2022 03:51:10 -0700 (PDT) Received: by mail-pj1-x102f.google.com with SMTP id fv3so14193394pjb.0 for ; Wed, 14 Sep 2022 03:51:09 -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=IrNJXJy2Qfp61vWuuO+NXKEK9HBiciqOqk0BOw7bdEk=; b=HuHz/O1NbGKWuzT134PJzmW4zHJ9Ig1Ewm9e5IpSywIIu5wXuE418wYKvpALrR6v4I RN7Z37cPxS3wS5zFO6uzGT3yNiNRagQ4W+L73PwsPmemfYytu9gHuLZRgDmBMwTI9TJ0 iH3rFVMW/PKg1BmZYzFycEtLWDXQYrdei2lIymMgw3CRgq/DpZSy0zCoMqzMBADF/Owa aYwO67wj1v8KhA+8mM4bfl1/Mc8MD7ljvNR2qDE+cIHud8tu/dXFyzZybV+KuBWKKRv4 afZKFGtzDMxVMR8d89LGYr9MPzfdKnwNBxhBd0q4iwTveTZpe2edFeJh5taI+rOnGtOf vZ+g== 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=IrNJXJy2Qfp61vWuuO+NXKEK9HBiciqOqk0BOw7bdEk=; b=OXjktUZWa/o0GwnO+O9KPgX/DOi8jFWQuLx2fCJnZwc4FtN4ayTEOVL1juXHh2jAyD m6CCJ5BYacBwXeAp/TtzrEppFfOXq3ShMamoMu73lBxMc+cZlsEbgmJUIAjjnsuJnih3 HAnLwfFtWdmSWOGUjjybyL4HO1kptM1DScrGma+7R/ToWyIOFCQvnz2GK7ToiXlc1ME8 YMZcD2MSkofpgxKPwJAXgP29wTiqVxRYFk7bCF1mrut1rGMcwCBJewMunPvkugGX0ep8 jBV0okbjDl3XkV1DrZjoOvCIVqSOHyxqJFzK/pXZ5AYVinYUqb2g2XKAPhY7jTNCyMKh n59g== X-Gm-Message-State: ACgBeo3TnYiEXHBqHx7lkMxuEpIHu+hQfXfp5bS9OBkz0U/3P4FAM+ql jVreaiFJ+JgS3P0FL4eOtVN6Vw== X-Google-Smtp-Source: AA6agR7zIf6cTNMutEmLYBBSDrMiX8sfjaJDTX66cNjrRwG7LFaLG1XSqM4sbjMoWE5vt1C4y9Ht1g== X-Received: by 2002:a17:902:c944:b0:178:4568:9f99 with SMTP id i4-20020a170902c94400b0017845689f99mr8157121pla.98.1663152669412; Wed, 14 Sep 2022 03:51:09 -0700 (PDT) Received: from C02G705SMD6V.bytedance.net ([2400:8800:1f02:83:4000:0:1:2]) by smtp.gmail.com with ESMTPSA id x13-20020a170902ec8d00b0016dc2366722sm10537042plg.77.2022.09.14.03.51.05 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 14 Sep 2022 03:51:09 -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 V3 5/6] erofs: introduce a pseudo mnt to manage shared cookies Date: Wed, 14 Sep 2022 18:50:40 +0800 Message-Id: <20220914105041.42970-6-zhujia.zj@bytedance.com> X-Mailer: git-send-email 2.37.0 (Apple Git-136) In-Reply-To: <20220914105041.42970-1-zhujia.zj@bytedance.com> References: <20220914105041.42970-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" Use a pseudo mnt to manage shared cookies. Signed-off-by: Jia Zhu --- fs/erofs/fscache.c | 13 +++++++++++++ fs/erofs/internal.h | 1 + fs/erofs/super.c | 31 +++++++++++++++++++++++++++++-- 3 files changed, 43 insertions(+), 2 deletions(-) diff --git a/fs/erofs/fscache.c b/fs/erofs/fscache.c index b2100dc67cde..4e0a441afb7d 100644 --- a/fs/erofs/fscache.c +++ b/fs/erofs/fscache.c @@ -8,6 +8,7 @@ =20 static DEFINE_MUTEX(erofs_domain_list_lock); static LIST_HEAD(erofs_domain_list); +static struct vfsmount *erofs_pseudo_mnt; =20 static struct netfs_io_request *erofs_fscache_alloc_request(struct address= _space *mapping, loff_t start, size_t len) @@ -436,6 +437,10 @@ static void erofs_fscache_domain_put(struct erofs_doma= in *domain) fscache_relinquish_volume(domain->volume, NULL, false); mutex_lock(&erofs_domain_list_lock); list_del(&domain->list); + if (list_empty(&erofs_domain_list)) { + kern_unmount(erofs_pseudo_mnt); + erofs_pseudo_mnt =3D NULL; + } mutex_unlock(&erofs_domain_list_lock); kfree(domain->domain_id); kfree(domain); @@ -489,6 +494,14 @@ static int erofs_fscache_init_domain(struct super_bloc= k *sb) if (err) goto out; =20 + 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; + } + } + domain->volume =3D sbi->volume; refcount_set(&domain->ref, 1); mutex_init(&domain->mutex); diff --git a/fs/erofs/internal.h b/fs/erofs/internal.h index 5ce6889d6f1d..4dd0b545755a 100644 --- a/fs/erofs/internal.h +++ b/fs/erofs/internal.h @@ -403,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; diff --git a/fs/erofs/super.c b/fs/erofs/super.c index 856758ee4869..ced1d2fd6e4b 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; @@ -789,6 +796,11 @@ static int erofs_fc_fill_super(struct super_block *sb,= struct fs_context *fc) return 0; } =20 +static int erofs_fc_anon_get_tree(struct fs_context *fc) +{ + return get_tree_nodev(fc, erofs_fc_fill_pseudo_super); +} + static int erofs_fc_get_tree(struct fs_context *fc) { struct erofs_fs_context *ctx =3D fc->fs_private; @@ -858,10 +870,20 @@ static const struct fs_context_operations erofs_conte= xt_ops =3D { .free =3D erofs_fc_free, }; =20 +static const struct fs_context_operations erofs_anon_context_ops =3D { + .get_tree =3D erofs_fc_anon_get_tree, +}; + 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; + + if (fc->sb_flags & SB_KERNMOUNT) { + fc->ops =3D &erofs_anon_context_ops; + return 0; + } =20 + ctx =3D kzalloc(sizeof(*ctx), GFP_KERNEL); if (!ctx) return -ENOMEM; ctx->devs =3D kzalloc(sizeof(struct erofs_dev_context), GFP_KERNEL); @@ -888,6 +910,11 @@ 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)) kill_anon_super(sb); else @@ -923,7 +950,7 @@ static void erofs_put_super(struct super_block *sb) sbi->s_fscache =3D NULL; } =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 Fri Apr 3 08:22:43 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 9A680ECAAD3 for ; Wed, 14 Sep 2022 10:52:22 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229592AbiINKwU (ORCPT ); Wed, 14 Sep 2022 06:52:20 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:40332 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230073AbiINKvg (ORCPT ); Wed, 14 Sep 2022 06:51:36 -0400 Received: from mail-pj1-x1036.google.com (mail-pj1-x1036.google.com [IPv6:2607:f8b0:4864:20::1036]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id D2D0F647E1 for ; Wed, 14 Sep 2022 03:51:13 -0700 (PDT) Received: by mail-pj1-x1036.google.com with SMTP id fv3so14193519pjb.0 for ; Wed, 14 Sep 2022 03:51:13 -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=imR5y18ryUCktyAigdc0+MY99yMqYjGRbnJ4cSNTikw=; b=cn0ZpcYXk/kqyPdR7OatSX13r/+Xy1i+0/HByaAP+/RcxVpTb8RPtcj5PBdQtxtVlS C64alLZznwcghZj0W56bhfqoJUlA8XEOV10Ou1ZNweI//KGA6sHUs//7EeH2oVxaeyfD UiKpQ9n71whV8rE5+5TveZz+clfw4t0IWD1tRVEmKlnu3b4xfM1Nmt5GxGigmZIUNwRP GPjL7zQYDipgVCtACzlZ9IWv1FBkDYpGuHKckZ0d4czUntdG3yRUE8W086F9IAKJfzZG dt+48ozwedhEpIY+yhPYsQeXC3ryQ4SIGmk4i0XT7ArcnMP/R9OnIApGc1Tz5Qh2p6gl SSGg== 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=imR5y18ryUCktyAigdc0+MY99yMqYjGRbnJ4cSNTikw=; b=p+9efzIKtXaXw9slqO4NxBNWmMaM//v7aWWfLmsvjxQVXmsl4hAmuPmuu8oR25XkD6 PPWpB3Kp8pZbBlXU07G8Zk2EtRJ8vikX7orQyS8OLVhZaIlJqa1bZgQmN+WnpuSa9ahH cC9Qb7YUURLkezCSv3Bi7A1qx7+lq0sb0OE0QfAhrpKcbZEvexVTDGY6zMGi9o0z2l9Y PCPIHkLTcjsjP3GLcETR8ywucRTI8coADdgvRE7BJA7DjZSIKWlu2UO07fLDsm0xv7IE URJ3xFU/8r33q1mg1A0jx38OWMQvhW/7o6Zem1EvkhNdI+OIih0MI3h24mrgKvbvKYd2 wH5g== X-Gm-Message-State: ACgBeo2Zj4MDSlDjK/hzdapp4Ju+e0D2FCTEgpCTNU6yY1YVvNejeQiw tl7XqIAP65nVEDE/Ex/CJwEcNA== X-Google-Smtp-Source: AA6agR74HSXRqf39Tac77t/yqR9dwmYkhneSUTjl4+pqYGMp1qcuCe6wUhi5W957o2Y5Qu/FYox1Mg== X-Received: by 2002:a17:902:edd5:b0:174:a6e6:51f4 with SMTP id q21-20020a170902edd500b00174a6e651f4mr36165450plk.82.1663152673277; Wed, 14 Sep 2022 03:51:13 -0700 (PDT) Received: from C02G705SMD6V.bytedance.net ([2400:8800:1f02:83:4000:0:1:2]) by smtp.gmail.com with ESMTPSA id x13-20020a170902ec8d00b0016dc2366722sm10537042plg.77.2022.09.14.03.51.09 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 14 Sep 2022 03:51:12 -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 V3 6/6] erofs: Support sharing cookies in the same domain Date: Wed, 14 Sep 2022 18:50:41 +0800 Message-Id: <20220914105041.42970-7-zhujia.zj@bytedance.com> X-Mailer: git-send-email 2.37.0 (Apple Git-136) In-Reply-To: <20220914105041.42970-1-zhujia.zj@bytedance.com> References: <20220914105041.42970-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 | 89 +++++++++++++++++++++++++++++++++++++++++++-- fs/erofs/internal.h | 4 +- 2 files changed, 89 insertions(+), 4 deletions(-) diff --git a/fs/erofs/fscache.c b/fs/erofs/fscache.c index 4e0a441afb7d..e9ae1ee963e2 100644 --- a/fs/erofs/fscache.c +++ b/fs/erofs/fscache.c @@ -7,6 +7,7 @@ #include "internal.h" =20 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; =20 @@ -504,7 +505,6 @@ static int erofs_fscache_init_domain(struct super_block= *sb) =20 domain->volume =3D sbi->volume; refcount_set(&domain->ref, 1); - mutex_init(&domain->mutex); list_add(&domain->list, &erofs_domain_list); return 0; out: @@ -534,8 +534,8 @@ static int erofs_fscache_register_domain(struct super_b= lock *sb) return err; } =20 -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 =3D EROFS_SB(sb)->volume; struct erofs_fscache *ctx; @@ -585,13 +585,96 @@ struct erofs_fscache *erofs_fscache_register_cookie(s= truct super_block *sb, return ERR_PTR(ret); } =20 +static +struct erofs_fscache *erofs_fscache_domain_init_cookie(struct super_block = *sb, + char *name, bool need_inode) +{ + struct inode *inode; + struct erofs_fscache *ctx; + struct erofs_sb_info *sbi =3D EROFS_SB(sb); + struct erofs_domain *domain =3D sbi->domain; + + ctx =3D erofs_fscache_acquire_cookie(sb, name, need_inode); + if (IS_ERR(ctx)) + return ctx; + + ctx->name =3D kstrdup(name, GFP_KERNEL); + if (!ctx->name) + return ERR_PTR(-ENOMEM); + + inode =3D new_inode(erofs_pseudo_mnt->mnt_sb); + if (!inode) { + kfree(ctx->name); + return ERR_PTR(-ENOMEM); + } + + ctx->domain =3D domain; + ctx->anon_inode =3D inode; + inode->i_private =3D ctx; + erofs_fscache_domain_get(domain); + return ctx; +} + +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_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(&erofs_domain_cookies_lock); + list_for_each_entry(inode, &psb->s_inodes, i_sb_list) { + ctx =3D inode->i_private; + if (!ctx) + continue; + if (ctx->domain =3D=3D domain && !strcmp(ctx->name, name)) { + igrab(inode); + mutex_unlock(&erofs_domain_cookies_lock); + return ctx; + } + } + ctx =3D 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) +{ + struct erofs_sb_info *sbi =3D EROFS_SB(sb); + + if (sbi->opt.domain_id) + return erofs_domain_register_cookie(sb, name, need_inode); + else + return erofs_fscache_acquire_cookie(sb, name, need_inode); +} + void erofs_fscache_unregister_cookie(struct erofs_fscache *ctx) { + struct erofs_domain *domain; + if (!ctx) return; + domain =3D ctx->domain; + if (domain) { + mutex_lock(&erofs_domain_cookies_lock); + /* Cookie is still in use */ + if (atomic_read(&ctx->anon_inode->i_count) > 1) { + iput(ctx->anon_inode); + mutex_unlock(&erofs_domain_cookies_lock); + return; + } + iput(ctx->anon_inode); + kfree(ctx->name); + mutex_unlock(&erofs_domain_cookies_lock); + } =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); diff --git a/fs/erofs/internal.h b/fs/erofs/internal.h index 4dd0b545755a..8a6f94b27a23 100644 --- a/fs/erofs/internal.h +++ b/fs/erofs/internal.h @@ -101,7 +101,6 @@ struct erofs_sb_lz4_info { =20 struct erofs_domain { refcount_t ref; - struct mutex mutex; struct list_head list; struct fscache_volume *volume; char *domain_id; @@ -110,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; }; =20 struct erofs_sb_info { --=20 2.20.1