From nobody Fri Apr 3 02:28:04 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 3AA2EC32771 for ; Sun, 18 Sep 2022 04:35:20 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229647AbiIREfO (ORCPT ); Sun, 18 Sep 2022 00:35:14 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:40372 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229586AbiIREfI (ORCPT ); Sun, 18 Sep 2022 00:35:08 -0400 Received: from mail-pg1-x52e.google.com (mail-pg1-x52e.google.com [IPv6:2607:f8b0:4864:20::52e]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 89DA613D5E for ; Sat, 17 Sep 2022 21:35:06 -0700 (PDT) Received: by mail-pg1-x52e.google.com with SMTP id h188so23914879pgc.12 for ; Sat, 17 Sep 2022 21:35: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=vnrn5Lz0Sq4BDA+kMPiBQA0vIKB2GCJKPoPvtdJGVII=; b=eVaRVfx5a2MVEdsHGLTKj56DVEcrAKgua7VGnhGuCRo54sfJnqUIYr+XO+BbkdT1Zb 91p7t3DNLn1Y10DnRA1xNP7ubPYrptiSSv2pIPQF69SV6FIJgoaI8Edoz6Ve2lI6NGO9 I/3cXdD8eXFSUYB1836GY6jTk7pDfHZzDePuSyAF07ooCWihJS40cNU+8pY9OP1loa05 4xK1oEcStoUp7wLXga4FUZZoX4zPkuGym5UVGGI/0YGuwaLJXhOP1nwB7FvQdY5GFOCW FdfyQ+JLR2Aj5TNnYdI3QtZcfxS/5ZRWv0lkwl/b1ZQKnvdGNU6XsZZ6dVIkwEPRJdUj +Fdg== 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=vnrn5Lz0Sq4BDA+kMPiBQA0vIKB2GCJKPoPvtdJGVII=; b=yqimG6TnFhhhg9r/31A7fOlSxpGWhNWXwmEvzjkN6MJO6oOp7l+a5TQ+NRc1fBiOqf j1VgCER6NTZvMimSXVZX8VfK16+8QLJasurOAwaiU5ISh1S2u94JQJsETOlbnAy78fW/ jCePGS1FewT5mZLslFs27L5Fvnh526Kc807KRILyvWVBlukPZ8e9Z+DuoBU2JGBpAxk+ 1BqoMSidUM/bdc68LO8991P2ywGsLBBsvjxApAbvfsLU864O76wqoFLO1jEFsK2OjLqq lna1cbTNCrZER3bAxw+r6ND8KaCglhFUji6Wfeq93rvGCPZKwwAsoDIKzyOlxuYSNDBU m3wA== X-Gm-Message-State: ACrzQf1o/4zDYgER8+2feFr15oqvAM29V5zBcNxhycStjw+fmugDmBH4 l0KErFjWnav4IMzWOOzeaZTPzQ== X-Google-Smtp-Source: AMsMyM76iQB6B2cNhDHRqLO41Da7t2u4Ij4woRMn+qQFywM/+pG/hclaTdhS/4IoVJYsYMH7aOEmsw== X-Received: by 2002:a63:42c7:0:b0:438:e0dc:cc09 with SMTP id p190-20020a6342c7000000b00438e0dccc09mr10797694pga.128.1663475706078; Sat, 17 Sep 2022 21:35:06 -0700 (PDT) Received: from localhost.localdomain ([111.201.134.95]) by smtp.gmail.com with ESMTPSA id l63-20020a622542000000b0054b5239f7fesm3955248pfl.210.2022.09.17.21.35.03 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 17 Sep 2022 21:35:05 -0700 (PDT) From: Jia Zhu To: linux-erofs@lists.ozlabs.org Cc: linux-fsdevel@vger.kernel.org, linux-kernel@vger.kernel.org, yinxin.x@bytedance.com, jefflexu@linux.alibaba.com, Jia Zhu Subject: [PATCH V6 1/6] erofs: use kill_anon_super() to kill super in fscache mode Date: Sun, 18 Sep 2022 12:34:51 +0800 Message-Id: <20220918043456.147-2-zhujia.zj@bytedance.com> X-Mailer: git-send-email 2.37.0 (Apple Git-136) In-Reply-To: <20220918043456.147-1-zhujia.zj@bytedance.com> References: <20220918043456.147-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. Fixes: 9c0cc9c729657 ("erofs: add 'fsid' mount option") Suggested-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 02:28:04 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 84AD6C6FA8B for ; Sun, 18 Sep 2022 04:35:20 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229586AbiIREfR (ORCPT ); Sun, 18 Sep 2022 00:35:17 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:40484 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229552AbiIREfK (ORCPT ); Sun, 18 Sep 2022 00:35:10 -0400 Received: from mail-pl1-x633.google.com (mail-pl1-x633.google.com [IPv6:2607:f8b0:4864:20::633]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id E2A1315A39 for ; Sat, 17 Sep 2022 21:35:08 -0700 (PDT) Received: by mail-pl1-x633.google.com with SMTP id t3so25084254ply.2 for ; Sat, 17 Sep 2022 21:35:08 -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=A/aoDsk49ETFUaGu6ntYPDp5Xpa3glyWzoYuA85stpo=; b=61PHmhzxDjMs06OEy3Cb1sztffy0FZOHZCqFyM6w2PJ/XFUpo97cM+5wNAwiN6TtBO fzy1o7cenhEgpWgMVxov1vtcB70zgPt0gHAG2/qeb7Nefh+ezr4gLsqsK2b1tlsoGKyT 5/qfa44PhkZm000renBu0LIAsqj3ZsJkysOWwzdJqPKfXb0mjoXGw3nqfCGvn80B95ha UWUdu6g+vtwG2PtxJIkSspk3MT9DfLXHDV/OAe4cc6hVmzQ6WcI6/xLN59NLuL6X1eFD rIsM5fkH8sliEY1Cmk/aCjjVXgoAql1yduupzTFihK1RUipimMY4m3sXSAGf2SRazNr+ tBaw== 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=A/aoDsk49ETFUaGu6ntYPDp5Xpa3glyWzoYuA85stpo=; b=1CYYr5a/mO62lKYL7RGvRHjcw71jhl47tNh96edjvdnxucC3fQwI1pIxyZJU+6iw1F 8n/GeuW7Lyvhisv236mEE8fpNYfkKiVFxl/GXGU1siERnhCH+isdmtce1FUMevkr1u0q LQ4CVdApAg2bZGQCtuSTnHkx+4UkR2L5UnmbZrrgz4CAz/2jcXjMdxfIuyCH9mtR0lk+ LnPSRbUxwTADRUvjQK5gG6FFj4kq3qjacN5zHkM6DoMGK+6hdKp4npys8pJod0yFKZdP dvCH+9G1M+UspQNRUqXsX2Ty0o03VUfxxWNep6BIyGd6Jl6bocg/D0dIxRSiEd0LMxKU wF7A== X-Gm-Message-State: ACrzQf3Y2JYf8vMHd953IS2b2uaLrmQhOcESMvfwfmXVQxW+815aP+TT SEisBcwIYEd6C+yOAsgN3tg7Mg== X-Google-Smtp-Source: AMsMyM6JXjtVoeByE0sNx+bWugwWJQan1z688+nSCVSRqAdmymrapUIy4SsElW+AtLZHzSQLVayrPA== X-Received: by 2002:a17:902:d4cf:b0:178:1e39:31ff with SMTP id o15-20020a170902d4cf00b001781e3931ffmr6996051plg.137.1663475708271; Sat, 17 Sep 2022 21:35:08 -0700 (PDT) Received: from localhost.localdomain ([111.201.134.95]) by smtp.gmail.com with ESMTPSA id l63-20020a622542000000b0054b5239f7fesm3955248pfl.210.2022.09.17.21.35.06 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 17 Sep 2022 21:35:07 -0700 (PDT) From: Jia Zhu To: linux-erofs@lists.ozlabs.org Cc: linux-fsdevel@vger.kernel.org, linux-kernel@vger.kernel.org, yinxin.x@bytedance.com, jefflexu@linux.alibaba.com, Jia Zhu Subject: [PATCH V6 2/6] erofs: code clean up for fscache Date: Sun, 18 Sep 2022 12:34:52 +0800 Message-Id: <20220918043456.147-3-zhujia.zj@bytedance.com> X-Mailer: git-send-email 2.37.0 (Apple Git-136) In-Reply-To: <20220918043456.147-1-zhujia.zj@bytedance.com> References: <20220918043456.147-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. Suggested-by: Jingbo Xu Signed-off-by: Jia Zhu Reviewed-by: Jingbo Xu --- fs/erofs/fscache.c | 39 +++++++++++++++++++-------------------- fs/erofs/internal.h | 19 +++++++++---------- fs/erofs/super.c | 21 ++++++++------------- 3 files changed, 36 insertions(+), 43 deletions(-) diff --git a/fs/erofs/fscache.c b/fs/erofs/fscache.c index 8e01d89c3319..d3a90103abb7 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,42 +457,33 @@ int erofs_fscache_register_cookie(struct super_block = *sb, ctx->inode =3D inode; } =20 - *fscache =3D ctx; - return 0; + return ctx; =20 err_cookie: fscache_unuse_cookie(ctx->cookie, NULL, NULL); fscache_relinquish_cookie(ctx->cookie, false); - 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 fscache_unuse_cookie(ctx->cookie, NULL, NULL); fscache_relinquish_cookie(ctx->cookie, false); - ctx->cookie =3D NULL; - iput(ctx->inode); - ctx->inode =3D NULL; - 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 name =3D kasprintf(GFP_KERNEL, "erofs,%s", sbi->opt.fsid); if (!name) @@ -502,19 +492,28 @@ int erofs_fscache_register_fs(struct super_block *sb) 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; + kfree(name); + return volume ? PTR_ERR(volume) : -EOPNOTSUPP; } =20 sbi->volume =3D volume; kfree(name); - return ret; + + fscache =3D erofs_fscache_register_cookie(sb, sbi->opt.fsid, true); + /* acquired volume will be relinquished in kill_sb() */ + if (IS_ERR(fscache)) + return PTR_ERR(fscache); + + sbi->s_fscache =3D fscache; + return 0; } =20 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..b36850dd7813 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; + return ERR_PTR(-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..884e7ed3d760 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,7 @@ 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_fs(sb); } =20 static struct file_system_type erofs_fs_type =3D { --=20 2.20.1 From nobody Fri Apr 3 02:28:04 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 38635C32771 for ; Sun, 18 Sep 2022 04:35:40 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229458AbiIREfg (ORCPT ); Sun, 18 Sep 2022 00:35:36 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:40580 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229632AbiIREfM (ORCPT ); Sun, 18 Sep 2022 00:35:12 -0400 Received: from mail-pj1-x1033.google.com (mail-pj1-x1033.google.com [IPv6:2607:f8b0:4864:20::1033]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 53096167E5 for ; Sat, 17 Sep 2022 21:35:11 -0700 (PDT) Received: by mail-pj1-x1033.google.com with SMTP id q62-20020a17090a17c400b00202a3497516so3156519pja.1 for ; Sat, 17 Sep 2022 21:35:11 -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=Zz/+Lsdw1NAyt93VpvNl+aPHSPA2CVkBmnUTlKe09/0=; b=Vpal278u2LJ58CGPsEPXqpT0AKbQZCricS4GhbO5+/GBcyr4GKzoi5Qa9e5QNMO2pf w2lPfIK28i3YkAuuaj2/4CImxJf8O6kumBc1rKMr06vxh+8zIdP96KGV3t74Ww5hf+fy v1vBmYRqADaDd+/Hh0QGVTHhkBhEWOTkKg1hBXK5ZjrKikjwBc2Q+jjPIPz37RCZOiuz jPMgcqNZ1AY9dPLgeqdTNrgrWIuoRV69eib0jXc6UUAXSwEkb7bFdeC3RqXyrtWCDhFq wuuvvL6Kr11VxV7fYvzIjSGciTRSuykd65Shkt00XCHD03XFz2LF9RJ4WpE235AxUNXH ERKg== 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=Zz/+Lsdw1NAyt93VpvNl+aPHSPA2CVkBmnUTlKe09/0=; b=pFGLnQe90CBzR0T876bC2oZoOly42V1LQ0DdjdGaRV+U8m8i8TwEVaVssFALRZoGhG F9qvIQl1BNFMh9UNAUqcUetqse5zSQA4EO2aoFaaPYQCjsjXW3i7MU5Sln3Lc4LdsPcK kd03O+M90lVhjzGY6qpyTKjuGmSmesPbMrdWmyTcbjvpbhCKa6W+GqCCokndBWN1cDuo aFHUZkEgegYXlua+NA94fQuodI46w1y9l7VDex0sjHC/lxl2wvk+Wp+g7W45oYyq8mpY Tu97tQYr6BqCapa8GvNkQP70e+wTlrAWIXZNrSKzEUMyZhI+MnoJxywwxbdSUKfFFnaN Vikw== X-Gm-Message-State: ACrzQf3vzTmyU/fBGCLlO3GfDSzDD93zT6RBdOU3kL6BCHcFXuBnQ5Xu oEx/V32ADzw3rZWpAb2fiDhpdeEl47rCwCK7 X-Google-Smtp-Source: AMsMyM6u/ABaKXp7fzLz3VnxEa03VfPh5BNRwHrMVloqKWw4UuRDLgvkR1FkRwo9HxTCHp1mCYkz6Q== X-Received: by 2002:a17:903:1cc:b0:178:44cd:e9e with SMTP id e12-20020a17090301cc00b0017844cd0e9emr7132332plh.158.1663475710647; Sat, 17 Sep 2022 21:35:10 -0700 (PDT) Received: from localhost.localdomain ([111.201.134.95]) by smtp.gmail.com with ESMTPSA id l63-20020a622542000000b0054b5239f7fesm3955248pfl.210.2022.09.17.21.35.08 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 17 Sep 2022 21:35:10 -0700 (PDT) From: Jia Zhu To: linux-erofs@lists.ozlabs.org Cc: linux-fsdevel@vger.kernel.org, linux-kernel@vger.kernel.org, yinxin.x@bytedance.com, jefflexu@linux.alibaba.com, Jia Zhu Subject: [PATCH V6 3/6] erofs: introduce fscache-based domain Date: Sun, 18 Sep 2022 12:34:53 +0800 Message-Id: <20220918043456.147-4-zhujia.zj@bytedance.com> X-Mailer: git-send-email 2.37.0 (Apple Git-136) In-Reply-To: <20220918043456.147-1-zhujia.zj@bytedance.com> References: <20220918043456.147-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. The implementation of sharing blobs will be introduced in subsequent patches. Signed-off-by: Jia Zhu Reviewed-by: Jingbo Xu --- fs/erofs/fscache.c | 129 ++++++++++++++++++++++++++++++++++++++------ fs/erofs/internal.h | 9 ++++ 2 files changed, 121 insertions(+), 17 deletions(-) diff --git a/fs/erofs/fscache.c b/fs/erofs/fscache.c index d3a90103abb7..9c82284e66ee 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,99 @@ const struct address_space_operations erofs_fscache_ac= cess_aops =3D { .readahead =3D erofs_fscache_readahead, }; =20 +static void erofs_fscache_domain_put(struct erofs_domain *domain) +{ + if (!domain) + return; + mutex_lock(&erofs_domain_list_lock); + if (refcount_dec_and_test(&domain->ref)) { + list_del(&domain->list); + mutex_unlock(&erofs_domain_list_lock); + fscache_relinquish_volume(domain->volume, NULL, false); + kfree(domain->domain_id); + kfree(domain); + return; + } + mutex_unlock(&erofs_domain_list_lock); +} + +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; + + name =3D kasprintf(GFP_KERNEL, "erofs,%s", + domain_id ? domain_id : 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; + } + + err =3D erofs_fscache_register_volume(sb); + if (err) + goto out; + + domain->volume =3D sbi->volume; + refcount_set(&domain->ref, 1); + list_add(&domain->list, &erofs_domain_list); + sbi->domain =3D domain; + return 0; +out: + kfree(domain->domain_id); + kfree(domain); + 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 domain; + sbi->volume =3D domain->volume; + refcount_inc(&domain->ref); + 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) { @@ -480,27 +577,19 @@ void erofs_fscache_unregister_cookie(struct erofs_fsc= ache *ctx) =20 int erofs_fscache_register_fs(struct super_block *sb) { + int ret; struct erofs_sb_info *sbi =3D EROFS_SB(sb); - struct fscache_volume *volume; struct erofs_fscache *fscache; - char *name; - - name =3D kasprintf(GFP_KERNEL, "erofs,%s", sbi->opt.fsid); - if (!name) - return -ENOMEM; =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); - kfree(name); - return volume ? PTR_ERR(volume) : -EOPNOTSUPP; - } - - sbi->volume =3D volume; - kfree(name); + if (sbi->opt.domain_id) + ret =3D erofs_fscache_register_domain(sb); + else + ret =3D erofs_fscache_register_volume(sb); + if (ret) + return ret; =20 + /* acquired domain/volume will be relinquished in kill_sb() on error */ fscache =3D erofs_fscache_register_cookie(sb, sbi->opt.fsid, true); - /* acquired volume will be relinquished in kill_sb() */ if (IS_ERR(fscache)) return PTR_ERR(fscache); =20 @@ -513,7 +602,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); + + if (sbi->domain) + erofs_fscache_domain_put(sbi->domain); + else + fscache_relinquish_volume(sbi->volume, NULL, false); + sbi->s_fscache =3D NULL; sbi->volume =3D NULL; + sbi->domain =3D NULL; } diff --git a/fs/erofs/internal.h b/fs/erofs/internal.h index b36850dd7813..4c11313a072f 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 { @@ -98,6 +99,13 @@ struct erofs_sb_lz4_info { u16 max_pclusterblks; }; =20 +struct erofs_domain { + refcount_t ref; + struct list_head list; + struct fscache_volume *volume; + char *domain_id; +}; + struct erofs_fscache { struct fscache_cookie *cookie; struct inode *inode; @@ -157,6 +165,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 02:28:04 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 2A839C6FA86 for ; Sun, 18 Sep 2022 04:35:46 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229492AbiIREfn (ORCPT ); Sun, 18 Sep 2022 00:35:43 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:40728 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229650AbiIREfO (ORCPT ); Sun, 18 Sep 2022 00:35:14 -0400 Received: from mail-pl1-x636.google.com (mail-pl1-x636.google.com [IPv6:2607:f8b0:4864:20::636]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 69A19175B2 for ; Sat, 17 Sep 2022 21:35:13 -0700 (PDT) Received: by mail-pl1-x636.google.com with SMTP id w13so9431443plp.1 for ; Sat, 17 Sep 2022 21:35: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=y6Z4QOKHCiEESumRJUmDeS9lxU9MKoynA0yak47BDUs=; b=Omx/AStHDVgnuuMGtA4QKr8D4JqpEFOSMifYkwBBlHe5o2WFqrLFvpkUGRUzNT2u52 KWe9paJQb/9+2gFTAcFqwH51Cj90SXr4tPwhda/E+I8BXJr9sMfeUfyvzdQP4NAbZJ/e 4qqePmzMtQ5SC505Mr0+rywrt2rxERFPQ741ma8WrotmJSyBtBRZw5epbrrFyyD3YMmQ zOWc3+8K+codgL0X8nwLfBLvTXmAUZw/G5Yed7TFhiSn1beadVMkVeleSlYKgqw/y+fQ jrwK5KKqgLbA64eqoIEi27bN3He+bbIGj59ZYufIo+FyiaIVvPrTvxRYo8cZAvUgbG5z HI/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=y6Z4QOKHCiEESumRJUmDeS9lxU9MKoynA0yak47BDUs=; b=Guhw6ZGaMozz8+kB/wFzunI944iSdD7527jSa5isHvAT+HSaTRKTj13fYGwiqZR0rL FDBHf0RhF6eynMPE5j5WYgc1+EbZca6vvbjCHXi+pNVVyWI96SIP5X8D3uMF8qwK83tY 1SIcOB2KYzpVWBdjAsZcg1lEqotT0YUe/P137THKXTty+QHTs3k2gV56Bt3zdTFjrf6n FmeK19FVp8v2eoGAswqsaJgl0eT5bgSjS2s/nJD7qp+vgnUPTyhakRKQ1i3Knwg5puBY 7BVQnrxqG1FLOtR1MYb1kSjmrljsHMZIivtggnTZKEckW2rBlF0zuTvECCFFa0aYLbw0 la8Q== X-Gm-Message-State: ACrzQf0SzUaZJCgywLH1+jofRhiu1Z0ie+/w/fIGQtVarPkPHu05V7XH QfzFEPg7BxyTFlAlwhS/SRlSAg== X-Google-Smtp-Source: AMsMyM5oX0r429mRm3f6dArn+jaI0JIlsOoInPWK9gObBdp0a+c0KzhrT2Q03NIVwGJ3ziTbgCjuAA== X-Received: by 2002:a17:90a:e7d1:b0:200:94fd:967a with SMTP id kb17-20020a17090ae7d100b0020094fd967amr13055990pjb.57.1663475712889; Sat, 17 Sep 2022 21:35:12 -0700 (PDT) Received: from localhost.localdomain ([111.201.134.95]) by smtp.gmail.com with ESMTPSA id l63-20020a622542000000b0054b5239f7fesm3955248pfl.210.2022.09.17.21.35.10 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 17 Sep 2022 21:35:12 -0700 (PDT) From: Jia Zhu To: linux-erofs@lists.ozlabs.org Cc: linux-fsdevel@vger.kernel.org, linux-kernel@vger.kernel.org, yinxin.x@bytedance.com, jefflexu@linux.alibaba.com, Jia Zhu Subject: [PATCH V6 4/6] erofs: introduce a pseudo mnt to manage shared cookies Date: Sun, 18 Sep 2022 12:34:54 +0800 Message-Id: <20220918043456.147-5-zhujia.zj@bytedance.com> X-Mailer: git-send-email 2.37.0 (Apple Git-136) In-Reply-To: <20220918043456.147-1-zhujia.zj@bytedance.com> References: <20220918043456.147-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 Reviewed-by: Jingbo Xu --- fs/erofs/fscache.c | 13 +++++++++++++ fs/erofs/internal.h | 1 + fs/erofs/super.c | 33 +++++++++++++++++++++++++++++++-- 3 files changed, 45 insertions(+), 2 deletions(-) diff --git a/fs/erofs/fscache.c b/fs/erofs/fscache.c index 9c82284e66ee..4a7346b9fa73 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) @@ -428,6 +429,10 @@ static void erofs_fscache_domain_put(struct erofs_doma= in *domain) mutex_lock(&erofs_domain_list_lock); if (refcount_dec_and_test(&domain->ref)) { 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); fscache_relinquish_volume(domain->volume, NULL, false); kfree(domain->domain_id); @@ -482,6 +487,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); list_add(&domain->list, &erofs_domain_list); diff --git a/fs/erofs/internal.h b/fs/erofs/internal.h index 4c11313a072f..273fb35170e2 100644 --- a/fs/erofs/internal.h +++ b/fs/erofs/internal.h @@ -402,6 +402,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 884e7ed3d760..ab746181ae08 100644 --- a/fs/erofs/super.c +++ b/fs/erofs/super.c @@ -676,6 +676,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; @@ -776,6 +783,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; @@ -844,10 +856,21 @@ 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; + + /* pseudo mount for anon inodes */ + 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); @@ -874,6 +897,12 @@ static void erofs_kill_sb(struct super_block *sb) =20 WARN_ON(sb->s_magic !=3D EROFS_SUPER_MAGIC); =20 + /* pseudo mount for anon inodes */ + if (sb->s_flags & SB_KERNMOUNT) { + kill_anon_super(sb); + return; + } + if (erofs_is_fscache_mode(sb)) kill_anon_super(sb); else @@ -907,7 +936,7 @@ static void erofs_put_super(struct super_block *sb) erofs_fscache_unregister_fs(sb); } =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 02:28:04 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 451EAC6FA86 for ; Sun, 18 Sep 2022 04:35:50 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229473AbiIREfs (ORCPT ); Sun, 18 Sep 2022 00:35:48 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:41892 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229454AbiIREfc (ORCPT ); Sun, 18 Sep 2022 00:35:32 -0400 Received: from mail-pf1-x42f.google.com (mail-pf1-x42f.google.com [IPv6:2607:f8b0:4864:20::42f]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 9108418376 for ; Sat, 17 Sep 2022 21:35:15 -0700 (PDT) Received: by mail-pf1-x42f.google.com with SMTP id d82so25009308pfd.10 for ; Sat, 17 Sep 2022 21:35:15 -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=3XqQQvKG0uG83TPRNIliCiOs6LD7q8fdw/Z9yA8GyaY=; b=Vc9gjv79iAU7D8+P6qKuD4awJtAs0DmiUBcCXkosJhBjZub2dGX9kqeYLEEWZsm+ba lDmeCnflYYTrp5YXrxobi6kIoVhjmcZZDTJIV4E2K5g2DuAdgxpu0liyrIRf96Zwg+r9 L8XCyKYtfk7pv/oypK40NjUrezc04AJfAJRDUthpagfBI3HneUZiCH+Gy4XVP9gARqIH UoPqXLeAcaEthgVZ/ng+zb9FXg6ezXO3J+47/xIjFiFXvhSPOKeftZP/Y8BT/levRiRM 6r225D4nRafs+VbxN3sVP1G875H1LmIgI+7W42EjqU1vyNxvUqzkBP8TuQdk1Atc9LY1 1Ung== 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=3XqQQvKG0uG83TPRNIliCiOs6LD7q8fdw/Z9yA8GyaY=; b=MSx9xZBzwr5ETivBb+wlyfoS6Nze1AnJs4Z61WxODqZQ1bh0b+vXhiFxmP12ZBFMm1 X8M6tRdULUW4BzkYqOffEIX57X02rVFgsQTyIPdufj9S108gtgqhN2LwSf84eAUyhRAl 9Gaa3/TGuttPl8lkGHoLdZNbEA5a0/thLLlYfJQpEXyevxZhj/3DjoLgSJRQrQmE6NJX 9DDSPPt4a7cj+6oiDfK0ss6jd70LEQaVIlkqnZ0z8SIbyzj5NdwWHeyd4zuVntu/8qs6 +bj1J3gMh6p/u7JXbq5lwn6+r3uym6XFrW1vabiQZ0DHwros21hZLQDaMvQPk9nxoFc8 1cXg== X-Gm-Message-State: ACrzQf3Vngy1UruSC+INGO5XSarG7+LSmz7Vb0c28tkaljh2S+A/EnML riRrCZ+2KBkcUiR0ZB9tNt33pg== X-Google-Smtp-Source: AMsMyM5scqCHflHacZpDomf4TNrFiB9yWTBub7wegqlGCpFSfK1O46mJ0+pgOxwA/I11ieNOVNwB2Q== X-Received: by 2002:a63:d54b:0:b0:42c:299e:255 with SMTP id v11-20020a63d54b000000b0042c299e0255mr10683406pgi.282.1663475715101; Sat, 17 Sep 2022 21:35:15 -0700 (PDT) Received: from localhost.localdomain ([111.201.134.95]) by smtp.gmail.com with ESMTPSA id l63-20020a622542000000b0054b5239f7fesm3955248pfl.210.2022.09.17.21.35.13 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 17 Sep 2022 21:35:14 -0700 (PDT) From: Jia Zhu To: linux-erofs@lists.ozlabs.org Cc: linux-fsdevel@vger.kernel.org, linux-kernel@vger.kernel.org, yinxin.x@bytedance.com, jefflexu@linux.alibaba.com, Jia Zhu Subject: [PATCH V6 5/6] erofs: Support sharing cookies in the same domain Date: Sun, 18 Sep 2022 12:34:55 +0800 Message-Id: <20220918043456.147-6-zhujia.zj@bytedance.com> X-Mailer: git-send-email 2.37.0 (Apple Git-136) In-Reply-To: <20220918043456.147-1-zhujia.zj@bytedance.com> References: <20220918043456.147-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 Reviewed-by: Jingbo Xu --- fs/erofs/fscache.c | 98 ++++++++++++++++++++++++++++++++++++++++++--- fs/erofs/internal.h | 3 ++ 2 files changed, 95 insertions(+), 6 deletions(-) diff --git a/fs/erofs/fscache.c b/fs/erofs/fscache.c index 4a7346b9fa73..a4ee1b430b55 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 @@ -527,8 +528,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; @@ -577,17 +578,102 @@ struct erofs_fscache *erofs_fscache_register_cookie(= struct super_block *sb, return ERR_PTR(ret); } =20 -void erofs_fscache_unregister_cookie(struct erofs_fscache *ctx) +static void erofs_fscache_relinquish_cookie(struct erofs_fscache *ctx) { - if (!ctx) - return; - fscache_unuse_cookie(ctx->cookie, NULL, NULL); fscache_relinquish_cookie(ctx->cookie, false); iput(ctx->inode); + kfree(ctx->name); kfree(ctx); } =20 +static +struct erofs_fscache *erofs_fscache_domain_init_cookie(struct super_block = *sb, + char *name, bool need_inode) +{ + int err; + struct inode *inode; + struct erofs_fscache *ctx; + struct erofs_domain *domain =3D EROFS_SB(sb)->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) { + err =3D -ENOMEM; + goto out; + } + + inode =3D new_inode(erofs_pseudo_mnt->mnt_sb); + if (!inode) { + err =3D -ENOMEM; + goto out; + } + + ctx->domain =3D domain; + ctx->anon_inode =3D inode; + inode->i_private =3D ctx; + refcount_inc(&domain->ref); + return ctx; +out: + erofs_fscache_relinquish_cookie(ctx); + return ERR_PTR(err); +} + +static +struct erofs_fscache *erofs_domain_register_cookie(struct super_block *sb, + char *name, bool need_inode) +{ + struct inode *inode; + struct erofs_fscache *ctx; + struct erofs_domain *domain =3D EROFS_SB(sb)->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 || ctx->domain !=3D domain || strcmp(ctx->name, name)) + continue; + 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) +{ + if (EROFS_SB(sb)->opt.domain_id) + return erofs_domain_register_cookie(sb, name, need_inode); + return erofs_fscache_acquire_cookie(sb, name, need_inode); +} + +void erofs_fscache_unregister_cookie(struct erofs_fscache *ctx) +{ + bool drop; + struct erofs_domain *domain; + + if (!ctx) + return; + domain =3D ctx->domain; + if (domain) { + mutex_lock(&erofs_domain_cookies_lock); + drop =3D atomic_read(&ctx->anon_inode->i_count) =3D=3D 1; + iput(ctx->anon_inode); + mutex_unlock(&erofs_domain_cookies_lock); + if (!drop) + return; + } + + erofs_fscache_relinquish_cookie(ctx); + erofs_fscache_domain_put(domain); +} + int erofs_fscache_register_fs(struct super_block *sb) { int ret; diff --git a/fs/erofs/internal.h b/fs/erofs/internal.h index 273fb35170e2..0f63830c9056 100644 --- a/fs/erofs/internal.h +++ b/fs/erofs/internal.h @@ -109,6 +109,9 @@ struct erofs_domain { struct erofs_fscache { struct fscache_cookie *cookie; struct inode *inode; + struct inode *anon_inode; + struct erofs_domain *domain; + char *name; }; =20 struct erofs_sb_info { --=20 2.20.1 From nobody Fri Apr 3 02:28:04 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 BF0B2C32771 for ; Sun, 18 Sep 2022 04:35:54 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229723AbiIREfx (ORCPT ); Sun, 18 Sep 2022 00:35:53 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:40668 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229627AbiIREfe (ORCPT ); Sun, 18 Sep 2022 00:35:34 -0400 Received: from mail-pf1-x435.google.com (mail-pf1-x435.google.com [IPv6:2607:f8b0:4864:20::435]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 7A3DB19C1E for ; Sat, 17 Sep 2022 21:35:18 -0700 (PDT) Received: by mail-pf1-x435.google.com with SMTP id a29so1397644pfk.5 for ; Sat, 17 Sep 2022 21:35:18 -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=iEzb9HK8KHfeOzls8+GISrwCsRaN3ytpe+kCbEKskwk=; b=CWJqlJ7gEsYsOLsiP2WWpkb9s1kZy/bxZQeXnu0GIf/Ue+HKSTw/EySPUPRrGSqueo Db81JZXT8VzLThJYZJn402lsGgr1YSitD9jRhfQ1xyhCc3HKDVtU1rqs+VnyaPOpRUWR 79UrfF7O1SwxgnN1BW/vB4M92xa0bnVsYlYepfGGhlW4eZjU9FctRqTXisnN+lj6xOVF tAS8rQHNtAHcYbqXXHus4DyASfZITaOtJEcGC+ys73yWl4rnXexhrxRx/N3LI4IWeSZg 9pmKCKPVHGnemrAjdUqNsfgQbZknUafmERT965ixXwFChNgHS2Grj8tzubMUCAKLYIzI +fqg== 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=iEzb9HK8KHfeOzls8+GISrwCsRaN3ytpe+kCbEKskwk=; b=ozP6y8uzL7STTcZiRPR0zIh4ZN6Teza6BTBzPGGayK9Agi2DOSwxYHEBECxbx1kpoE APIfXCopc9VmKrBm5Iudas2kHlCES7U8NpwgZ8GL+1x3YsVscWEDj/QiyP/pQSMwxKLY 8Wvdhdj2vISj/gr4Rrh3/AMipFFRg/nFWIgT5S4uexXL8S8SELt3ehvxk4pn5xIU6JGW DvKrgOOe9BKdGGhMDr6edz9XPiEwba1opcRFdnp9nFposimVHs/SDydLX1csGULL4kmp fMl1i42tVSJbvaV0JfPBchltIZFqg//NduM+/9vx+gVUsjhNb3W1s/WH2LVNs9lqFEq5 B9Kw== X-Gm-Message-State: ACrzQf3I3E/xK9UJWI9Lr0OMzRdqYbmJcK00J/SH2spl6AKNX6Lkvfh/ FE3RVCkP1aK3Pe5+AokfKWInew== X-Google-Smtp-Source: AMsMyM5OM+GSIDMjPS563NZpmFIkiTSy1EbecWmdfgbwd9JhhEpDWYcdgksBu5UjAh5wepil2sXjLg== X-Received: by 2002:a05:6a00:230d:b0:53d:c198:6ad7 with SMTP id h13-20020a056a00230d00b0053dc1986ad7mr12953655pfh.67.1663475717343; Sat, 17 Sep 2022 21:35:17 -0700 (PDT) Received: from localhost.localdomain ([111.201.134.95]) by smtp.gmail.com with ESMTPSA id l63-20020a622542000000b0054b5239f7fesm3955248pfl.210.2022.09.17.21.35.15 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 17 Sep 2022 21:35:17 -0700 (PDT) From: Jia Zhu To: linux-erofs@lists.ozlabs.org Cc: linux-fsdevel@vger.kernel.org, linux-kernel@vger.kernel.org, yinxin.x@bytedance.com, jefflexu@linux.alibaba.com, Jia Zhu Subject: [PATCH V6 6/6] erofs: introduce 'domain_id' mount option Date: Sun, 18 Sep 2022 12:34:56 +0800 Message-Id: <20220918043456.147-7-zhujia.zj@bytedance.com> X-Mailer: git-send-email 2.37.0 (Apple Git-136) In-Reply-To: <20220918043456.147-1-zhujia.zj@bytedance.com> References: <20220918043456.147-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 Reviewed-by: Jingbo Xu --- fs/erofs/super.c | 17 +++++++++++++++++ fs/erofs/sysfs.c | 19 +++++++++++++++++-- 2 files changed, 34 insertions(+), 2 deletions(-) diff --git a/fs/erofs/super.c b/fs/erofs/super.c index ab746181ae08..9f7fe6c04e65 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: @@ -702,6 +714,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 @@ -846,6 +859,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 @@ -916,6 +930,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; } @@ -1068,6 +1083,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