From nobody Sun Apr 5 13:07:33 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 869D0ECAAA1 for ; Thu, 15 Sep 2022 12:42:46 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230144AbiIOMmo (ORCPT ); Thu, 15 Sep 2022 08:42:44 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:37788 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229908AbiIOMmd (ORCPT ); Thu, 15 Sep 2022 08:42:33 -0400 Received: from mail-pl1-x631.google.com (mail-pl1-x631.google.com [IPv6:2607:f8b0:4864:20::631]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 463B7617C for ; Thu, 15 Sep 2022 05:42:33 -0700 (PDT) Received: by mail-pl1-x631.google.com with SMTP id v1so18221878plo.9 for ; Thu, 15 Sep 2022 05:42:33 -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=Qyyly0y8hqdRh/t9nYiYaAraDfG9P+e3ebneuWywx+A=; b=et8SUZfoNeMLnBl0MYEBpYeDFeu37dGfFrRRjQ3AaSxd8mtSowHWfpGGv23g3PclEl rgBoVJGjypKu0gzrIGPI32O/YAaVP3IBo2CqI3GwpG50VYJCT/VLn/PefDTSP4ScGOeV 8gw76ga6vh3F0wTgV/EJQOyXCnDggxUUWVUSahI18DNxw3/pIw+4CYWKjOJdgx/RcVFw njw6xSqeSSHJlZIjWtf+8vvHJiTjTyOwuj4vJOpIU8M+1LOlig0Mc60vsGYkEYADlGgJ BIzUJSej46PeT0PMCaFJFwlU4nASJaiHY5B42BznFYhPOAqMqaQK1C5O2MQk/8bS78i6 RbTA== 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=Qyyly0y8hqdRh/t9nYiYaAraDfG9P+e3ebneuWywx+A=; b=ad2TtnxHJNrh1kBgBNpDMQC+E/1iFmA4dK6yIrYeAeTSqqwmfZu1sz+ZZ7+2V107He 72igf5syuGpWPcunwqe72gaDJizxv0QBiMgesaiEhdrM8pqnp99ZHJkxt9/IOnXVYhas cw02IUjeOmP1hqdbUPrI9IAlXHwmQoqD4rOm15wzrXQ12yJYE/F4w9wjlNASnl4hKoGp /+l+7Oefdbnu+Kz60zO4VzwFkhUxrLO/l6eDFIKVkDJyaOfmY6CtiuSavmVCX4+v59sA PP7P+v+y249VZz10b3ygo/hD9JhGthVy1ZnBZ9tcgcHGAABHJHlqZw8J9VAs1hnCIgto 2RdQ== X-Gm-Message-State: ACrzQf1SpkraHIR/0FB0qE8G+YYmgesAvHgAERfqEOaO5J5+pFaN1MkR BPDgnbnYzIZGKSivHIT60LkDgg== X-Google-Smtp-Source: AMsMyM6L9o52U6lZPoVzHgkmu9KCrPUsx4XZmvaJZ+/KCAxjWxbWhbI2BTZHjNqBttWAXeWa68I2HQ== X-Received: by 2002:a17:90a:db8b:b0:203:1de7:eaaf with SMTP id h11-20020a17090adb8b00b002031de7eaafmr8232679pjv.168.1663245752797; Thu, 15 Sep 2022 05:42:32 -0700 (PDT) Received: from C02G705SMD6V.bytedance.net ([61.120.150.76]) by smtp.gmail.com with ESMTPSA id p8-20020a170902780800b001637529493esm12721906pll.66.2022.09.15.05.42.29 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 15 Sep 2022 05:42:32 -0700 (PDT) From: Jia Zhu To: linux-erofs@lists.ozlabs.org Cc: linux-fsdevel@vger.kernel.org, linux-kernel@vger.kernel.org, yinxin.x@bytedance.com, jefflexu@linux.alibaba.com, Jia Zhu Subject: [PATCH V4 1/6] erofs: use kill_anon_super() to kill super in fscache mode Date: Thu, 15 Sep 2022 20:42:08 +0800 Message-Id: <20220915124213.25767-2-zhujia.zj@bytedance.com> X-Mailer: git-send-email 2.37.0 (Apple Git-136) In-Reply-To: <20220915124213.25767-1-zhujia.zj@bytedance.com> References: <20220915124213.25767-1-zhujia.zj@bytedance.com> MIME-Version: 1.0 Content-Transfer-Encoding: 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. 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 Sun Apr 5 13:07:33 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 70E47ECAAD3 for ; Thu, 15 Sep 2022 12:43:03 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230239AbiIOMnB (ORCPT ); Thu, 15 Sep 2022 08:43:01 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:37990 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230160AbiIOMmu (ORCPT ); Thu, 15 Sep 2022 08:42:50 -0400 Received: from mail-pf1-x431.google.com (mail-pf1-x431.google.com [IPv6:2607:f8b0:4864:20::431]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id A974489CFA for ; Thu, 15 Sep 2022 05:42:38 -0700 (PDT) Received: by mail-pf1-x431.google.com with SMTP id a80so9356108pfa.4 for ; Thu, 15 Sep 2022 05:42:38 -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=t5M7NGDngN2+Zs7ekggybVds5iPQe8oTPjWTdXRHUpI=; b=yMB1ygNra22/dbB0LtinX5144RnJbP9QRbAMuXVq5qwgke2ZDqiUIlIkg373jaw409 ky5nHLN+VRcOUPJKsbcqA6nX6ejCJDGnV/EZJx9Mdqiuc1HnEaMEwLMr0iCRD0aIftj+ L7Trba18ZKseDR23Wwn2d0kJP/GdzkOvXi8Ao1b5rZ4NOf8X63ggOtslfSgJ3eN0csts sKDusv3Mk0t0UUcRn+Bze7XLFmwVgjmv8Pn7Q7iW2gy5ZKCSjy9trv3ugk6E24JZPoYb l9gPP7E67+SsDIvX8LXpLpLW98y4QmgeuyDvyp3a5Pp6srZEK71u4IBrHSKl+eKM3Suk Wemw== 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=t5M7NGDngN2+Zs7ekggybVds5iPQe8oTPjWTdXRHUpI=; b=AYxmcZ8cHAD+KzkrFf8dHBht5PrVUuaeq3GAOu+fQzj5zKGeKdtUkbGUrcA0Prsw1w N0FLib/nBYKBbMac/uuyAgceGYWzLXdi30pUtZieC20s2ZUGNah7wrSX3zrLlS0VMzT3 CRP3t4QkDPPZMfpq9fgc5o4WUpwCLCTAnQ5j56YsNYeevtVnD3RqgAvIHgwKXhBzuxcp Mh/GXyRlBb6Nu2BM9XjWzb+Sc0Q0qWnRiW7sCopeY9ChVSvrIRWse9L0wE6IVOkB9l4p ZI2KWhaUloqBj1q3J7dNQOotot4zDt90CnJSr3jRIkBIHWgLaiePQ75uMiVuOT0+Ly9I by8g== X-Gm-Message-State: ACgBeo3Qto1hhJCSqeRQwbffeXOeQXNP2Zu6DhKaz6fTEP0hdDDGdoSq GHKmua+bq19oITvMemR3elA2bU4SCOSIBw== X-Google-Smtp-Source: AA6agR6/XAjdH9+npfmFldAa27FSTWW5L+DsOFy757wu75dK8NFSHbGVIh2sRGCJTxkzf4PehyCZ/g== X-Received: by 2002:a63:8848:0:b0:434:b5d7:b4fa with SMTP id l69-20020a638848000000b00434b5d7b4famr35413685pgd.181.1663245757953; Thu, 15 Sep 2022 05:42:37 -0700 (PDT) Received: from C02G705SMD6V.bytedance.net ([61.120.150.76]) by smtp.gmail.com with ESMTPSA id p8-20020a170902780800b001637529493esm12721906pll.66.2022.09.15.05.42.33 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 15 Sep 2022 05:42:37 -0700 (PDT) From: Jia Zhu To: linux-erofs@lists.ozlabs.org Cc: linux-fsdevel@vger.kernel.org, linux-kernel@vger.kernel.org, yinxin.x@bytedance.com, jefflexu@linux.alibaba.com, Jia Zhu Subject: [PATCH V4 2/6] erofs: code clean up for fscache Date: Thu, 15 Sep 2022 20:42:09 +0800 Message-Id: <20220915124213.25767-3-zhujia.zj@bytedance.com> X-Mailer: git-send-email 2.37.0 (Apple Git-136) In-Reply-To: <20220915124213.25767-1-zhujia.zj@bytedance.com> References: <20220915124213.25767-1-zhujia.zj@bytedance.com> MIME-Version: 1.0 Content-Transfer-Encoding: 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 --- fs/erofs/fscache.c | 36 ++++++++++++++++++------------------ fs/erofs/internal.h | 17 ++++++++--------- fs/erofs/super.c | 22 +++++++++------------- 3 files changed, 35 insertions(+), 40 deletions(-) diff --git a/fs/erofs/fscache.c b/fs/erofs/fscache.c index 8e01d89c3319..d72e2a7ea6ab 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,40 +457,32 @@ 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 @@ -502,12 +493,19 @@ 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); + + 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 ret; } =20 @@ -515,6 +513,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..79e871c04fe2 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_fs(sb); + sbi->s_fscache =3D NULL; } =20 static struct file_system_type erofs_fs_type =3D { --=20 2.20.1 From nobody Sun Apr 5 13:07:33 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 1916AECAAA1 for ; Thu, 15 Sep 2022 12:43:07 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230280AbiIOMnF (ORCPT ); Thu, 15 Sep 2022 08:43:05 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:38128 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230173AbiIOMmy (ORCPT ); Thu, 15 Sep 2022 08:42:54 -0400 Received: from mail-pl1-x629.google.com (mail-pl1-x629.google.com [IPv6:2607:f8b0:4864:20::629]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 4670817E30 for ; Thu, 15 Sep 2022 05:42:42 -0700 (PDT) Received: by mail-pl1-x629.google.com with SMTP id k21so7682691pls.11 for ; Thu, 15 Sep 2022 05:42:42 -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=kfHhRT289dkV3NHpaBsTSxMODd6npbx86OOQkUDFZG8=; b=CqsODZW/GWVVMDfU7M0v+xEIBfpXZbXfrx9vanoDgo1+XYUuBd58fyoXCOKgLMlVkm J0sp3fW8Q3Pb4YwPVscAFCMF3mjO0nkhJLHVOza7N8CvdsWG8kCGQd4NxpbUyCjQNyUe KibKNTOdgSMV3m19mL6MlItVSK+VqtycNzX/kR/oiqdHqPrn2q+ts+PQVxGbFA61HWOt UmuBeouX/bZm3f1O3se6JAwLKE6dxvXpIRhOLSo4KPzdwKvKFR5n0WQ9ey12mC1jTEB8 5qiH3pT3YmXJT8bbZBwtvvTTc25JKvlbTehA03RDg9izJY8fY86b25PVymzsCFU3JOtv Ufhw== 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=kfHhRT289dkV3NHpaBsTSxMODd6npbx86OOQkUDFZG8=; b=dXju0y3Pi0XjxAwB2pf8Fdj6NPevPpQXy/XXHAAiWw/jsV5oeJjzLIyxa1RtrLFvoL c3BOXbzr9a+57pnvgxFnLE6DrRsF8ok5LCFs6Wes8V40IgNc9/fxKTRFpeEifOMBiJFr pBx3jsw2T+hGNcS2sTiLWaEQSdqsO76J1BTwI9AHAaWbz6u73gJMMTan/p4kPqEE+u7w ObpFGgDmaYny5HWiN18H8ON1rKQQWMbmrZVe9FdGM7pgZ/4Dby5SAIpl596tKwvZD6PB de/unddIuYBvNKukdgSEv4x7ONPbR222yBKFSFKxrO7tj/JxJrb5/A5em2f+iR2Qu74B itWw== X-Gm-Message-State: ACrzQf3zHl2NKmk/nLwjyWkFLxfl4sM1hmaS0NRE4TKlr6KKXh+Ubhnj b8nWUGohvhhdHte+a8IBiMVkPDVNdVaASA== X-Google-Smtp-Source: AMsMyM6WpHNPGFcW0e8BCUEcni/nSFpOFKy9gW9ojucyMUWyZv1iEpnm6FJWtMkn0mJHk5V4oV/KZw== X-Received: by 2002:a17:90b:1bcd:b0:203:27a3:6d0f with SMTP id oa13-20020a17090b1bcd00b0020327a36d0fmr6192310pjb.234.1663245761657; Thu, 15 Sep 2022 05:42:41 -0700 (PDT) Received: from C02G705SMD6V.bytedance.net ([61.120.150.76]) by smtp.gmail.com with ESMTPSA id p8-20020a170902780800b001637529493esm12721906pll.66.2022.09.15.05.42.38 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 15 Sep 2022 05:42:41 -0700 (PDT) From: Jia Zhu To: linux-erofs@lists.ozlabs.org Cc: linux-fsdevel@vger.kernel.org, linux-kernel@vger.kernel.org, yinxin.x@bytedance.com, jefflexu@linux.alibaba.com, Jia Zhu Subject: [PATCH V4 3/6] erofs: introduce fscache-based domain Date: Thu, 15 Sep 2022 20:42:10 +0800 Message-Id: <20220915124213.25767-4-zhujia.zj@bytedance.com> X-Mailer: git-send-email 2.37.0 (Apple Git-136) In-Reply-To: <20220915124213.25767-1-zhujia.zj@bytedance.com> References: <20220915124213.25767-1-zhujia.zj@bytedance.com> MIME-Version: 1.0 Content-Transfer-Encoding: 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 --- fs/erofs/fscache.c | 130 ++++++++++++++++++++++++++++++++++++++------ fs/erofs/internal.h | 9 +++ 2 files changed, 121 insertions(+), 18 deletions(-) diff --git a/fs/erofs/fscache.c b/fs/erofs/fscache.c index d72e2a7ea6ab..10d3f0511f15 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); + fscache_relinquish_volume(domain->volume, NULL, false); + mutex_unlock(&erofs_domain_list_lock); + 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) { @@ -481,27 +578,18 @@ 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; - - 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); - kfree(name); - return volume ? PTR_ERR(volume) : -EOPNOTSUPP; - } + int ret; =20 - 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() if error occu= rs */ 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 @@ -514,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 aa71eb65e965..7f0939f4005b 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 Sun Apr 5 13:07:33 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 BF4A8ECAAA1 for ; Thu, 15 Sep 2022 12:43:12 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230245AbiIOMnJ (ORCPT ); Thu, 15 Sep 2022 08:43:09 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:38298 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229923AbiIOMm5 (ORCPT ); Thu, 15 Sep 2022 08:42:57 -0400 Received: from mail-pj1-x1030.google.com (mail-pj1-x1030.google.com [IPv6:2607:f8b0:4864:20::1030]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id BFE879A9EF for ; Thu, 15 Sep 2022 05:42:45 -0700 (PDT) Received: by mail-pj1-x1030.google.com with SMTP id x1-20020a17090ab00100b001fda21bbc90so22222533pjq.3 for ; Thu, 15 Sep 2022 05:42:45 -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=N+8Ic9syGTC1u0a/MXotLVtHNCtWkf7iFn7tvbMZmlY=; b=CHGyfbuDxEYsmMOBtJ5Xs/wDe6c91lFi6Xew7HSn99TcDb2lO22OKPoyVOtbn3MS/1 Bo73PbLBArqJ0Sa+pDi19plOEapcqrlfeXff+lTxwRhp3tH9lnBF0OR2sS0KjbuhfAp9 n2/LkHyiCaKigFN/GBELZWSLM9R3IacTlcu7eptgFVKWJak3WylBP3MkZGRvTXL41DBO 2RxDXhpjM91fR9BWYAkfEy1m51pLajgNOvLpoTBOBQ9bSImNQJZ14NuOdV4MLu1oQOQ+ kuiTkouHlmwyNkmGXfSiiDkhPLDlOgtsTWyg3vXtG7wz9yxvM4tF1D5kKGDrGi7/XE/9 FIuQ== 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=N+8Ic9syGTC1u0a/MXotLVtHNCtWkf7iFn7tvbMZmlY=; b=wKbYks9mfmE9hQJ2PTzQmUCJ0Hu7mufiDKHDtTQOYpTqhtFDavhPv6Bs0s67pYRfrB segOg3UZ/ezG+fKa2UgYrdrkZxYYXpUZ6SOdKKyyGupAeXlnWNKBWuOwoRaWLUYNu6Wy ssJLFyQG+ES0I5XRy+uMwVsPEvllsgqSAs5wAXlLbFpOBMGHpiRZnT+j2mE39khBDu48 9eXUomDSGlV76MQTeNL+dydAs8hHnXtRMk99kr2/2fTLNkQG1/v/k9YPWsvRAQq0UL1S R/f/ZJnR4hRoqtcH1ZQUsBlZpTxSwurglt9V16qisWHMXZRFXFSNkG91bHp9D9mU2p7Z iv1Q== X-Gm-Message-State: ACrzQf1ZNeJR128/M+VbVypaJ0qBJM4PdToSbq1CWKZTGF3ABpT5Caqh E8tz/oOZqnpevHQhNMD+4S8EiemA8Pnlyw== X-Google-Smtp-Source: AMsMyM6LaCBySorEeXuS16yk8C5aL7BUcb/n97QGo/YbEfpMk60hXSn1IPytvrKulSbxhuXVxleeFg== X-Received: by 2002:a17:90a:c70b:b0:200:4366:d047 with SMTP id o11-20020a17090ac70b00b002004366d047mr10660743pjt.240.1663245765338; Thu, 15 Sep 2022 05:42:45 -0700 (PDT) Received: from C02G705SMD6V.bytedance.net ([61.120.150.76]) by smtp.gmail.com with ESMTPSA id p8-20020a170902780800b001637529493esm12721906pll.66.2022.09.15.05.42.42 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 15 Sep 2022 05:42:44 -0700 (PDT) From: Jia Zhu To: linux-erofs@lists.ozlabs.org Cc: linux-fsdevel@vger.kernel.org, linux-kernel@vger.kernel.org, yinxin.x@bytedance.com, jefflexu@linux.alibaba.com, Jia Zhu Subject: [PATCH V4 4/6] erofs: introduce a pseudo mnt to manage shared cookies Date: Thu, 15 Sep 2022 20:42:11 +0800 Message-Id: <20220915124213.25767-5-zhujia.zj@bytedance.com> X-Mailer: git-send-email 2.37.0 (Apple Git-136) In-Reply-To: <20220915124213.25767-1-zhujia.zj@bytedance.com> References: <20220915124213.25767-1-zhujia.zj@bytedance.com> MIME-Version: 1.0 Content-Transfer-Encoding: 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 10d3f0511f15..ff8382df493e 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) @@ -429,6 +430,10 @@ static void erofs_fscache_domain_put(struct erofs_doma= in *domain) if (refcount_dec_and_test(&domain->ref)) { list_del(&domain->list); fscache_relinquish_volume(domain->volume, NULL, false); + 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); @@ -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 7f0939f4005b..88c1a46867b3 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 79e871c04fe2..24bac58285e8 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,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); @@ -874,6 +896,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 @@ -908,7 +935,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 Sun Apr 5 13:07:33 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 95B8DECAAD3 for ; Thu, 15 Sep 2022 12:43:33 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230318AbiIOMnc (ORCPT ); Thu, 15 Sep 2022 08:43:32 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:38612 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230110AbiIOMm6 (ORCPT ); Thu, 15 Sep 2022 08:42:58 -0400 Received: from mail-pg1-x529.google.com (mail-pg1-x529.google.com [IPv6:2607:f8b0:4864:20::529]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id DAC2340577 for ; Thu, 15 Sep 2022 05:42:49 -0700 (PDT) Received: by mail-pg1-x529.google.com with SMTP id q9so8096103pgq.8 for ; Thu, 15 Sep 2022 05:42:49 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bytedance-com.20210112.gappssmtp.com; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date; bh=xWjAf9wvMTwIsrKn+t2CcTOjGhpgH45SYj+wwCJhngo=; b=jqkPqCE35yUwSiFS4layyrnkw357wLFQjNU/RN8Xg1EPyR1hhKr5rcjmOiunTu58xc Ikj4NQfFFN2nSkhuFVi1VDDFbtaaXoTPVtOweRi54RxKj9IFruQDVJABZf1IkcP20KqK fT5i2ijCDSzDCI9UvSQSgSTAp0go5qZ6MDIgHGKDDPypU4kHGu30diX9XvrLivvFpuzP cXVRIeqPZ6wCP28mPpVOHcpbAsQ1l1cQdI0s0iea6s48BtBmGs+ieUeKYvnGTGDPcSq9 wfUZiy/CjS4WIo+nbq1NFcUuJB0gg9Bub3GCiGCiDK0UpWH5GMDk0Ig0mlT0KSyw9eO2 dhUg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date; bh=xWjAf9wvMTwIsrKn+t2CcTOjGhpgH45SYj+wwCJhngo=; b=R8AwjMNPi7DG/fRHxgdX6TUd+tgrisBd3Zp9HxOoH/flg7SoL4gZLZ3uClSaUmYyR7 Ci5o/jxQmNi0xo6IG8RBRKkWuI1OAue2sKdO5RH9SYArY1KgpyEymuwDpnaHRspJAAXg m4YDVgIBv47P1JhAOK+Gqm2HU6nRtCIhBNCAKRLoPk6EbUGVRnIR11P+PNEl33R1/JXf Fnw5e0jMh+KHJF3v7f09oY6BzhISdbz5EDtOyfhg/9NHTJ3AbNBYp1AMESW0RnDgrm4+ p1B+2b+fMUToltsRF40Zrik89xgy0D6pihbfLIt2g3JLvQkmP87nkFY9uSjPZ3RSjWDM L1Tg== X-Gm-Message-State: ACgBeo2Jv4Tv1zKuR6+CvKUKSnvfkHpAWPQVCY6w2P1T4hXoN/nbbiBD wVXqFra8G/0g0Ru0aXu2RLf2tpgBEJYIxA== X-Google-Smtp-Source: AA6agR5XMjVI1b1fxEsxrzJECABjHTdCah+A6klG74cl2/JM3hA2zEEHXXJAnQ+hjydGuWqiXsQWGQ== X-Received: by 2002:a05:6a00:cd6:b0:546:d03:3dd7 with SMTP id b22-20020a056a000cd600b005460d033dd7mr12939600pfv.19.1663245768868; Thu, 15 Sep 2022 05:42:48 -0700 (PDT) Received: from C02G705SMD6V.bytedance.net ([61.120.150.76]) by smtp.gmail.com with ESMTPSA id p8-20020a170902780800b001637529493esm12721906pll.66.2022.09.15.05.42.45 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 15 Sep 2022 05:42:48 -0700 (PDT) From: Jia Zhu To: linux-erofs@lists.ozlabs.org Cc: linux-fsdevel@vger.kernel.org, linux-kernel@vger.kernel.org, yinxin.x@bytedance.com, jefflexu@linux.alibaba.com, Jia Zhu Subject: [PATCH V4 5/6] erofs: Support sharing cookies in the same domain Date: Thu, 15 Sep 2022 20:42:12 +0800 Message-Id: <20220915124213.25767-6-zhujia.zj@bytedance.com> X-Mailer: git-send-email 2.37.0 (Apple Git-136) In-Reply-To: <20220915124213.25767-1-zhujia.zj@bytedance.com> References: <20220915124213.25767-1-zhujia.zj@bytedance.com> MIME-Version: 1.0 Content-Transfer-Encoding: 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 | 90 ++++++++++++++++++++++++++++++++++++++++++++- fs/erofs/internal.h | 3 ++ 2 files changed, 91 insertions(+), 2 deletions(-) diff --git a/fs/erofs/fscache.c b/fs/erofs/fscache.c index ff8382df493e..8873a093cf7b 100644 --- a/fs/erofs/fscache.c +++ b/fs/erofs/fscache.c @@ -7,6 +7,7 @@ #include "internal.h" =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,14 +578,99 @@ 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) +{ + 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) { + kfree(ctx->name); + 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: + fscache_unuse_cookie(ctx->cookie, NULL, NULL); + fscache_relinquish_cookie(ctx->cookie, false); + if (need_inode) + iput(ctx->inode); + kfree(ctx); + return ERR_PTR(err); +} + +static +struct erofs_fscache *erofs_domain_register_cookie(struct super_block *sb, + char *name, bool need_inode) +{ + struct inode *inode; + struct erofs_fscache *ctx; + struct erofs_domain *domain =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; + } =20 fscache_unuse_cookie(ctx->cookie, NULL, NULL); fscache_relinquish_cookie(ctx->cookie, false); + erofs_fscache_domain_put(domain); iput(ctx->inode); + kfree(ctx->name); kfree(ctx); } =20 diff --git a/fs/erofs/internal.h b/fs/erofs/internal.h index 88c1a46867b3..8a6f94b27a23 100644 --- a/fs/erofs/internal.h +++ b/fs/erofs/internal.h @@ -109,6 +109,9 @@ struct erofs_domain { struct erofs_fscache { struct fscache_cookie *cookie; struct inode *inode; + struct inode *anon_inode; + struct erofs_domain *domain; + char *name; }; =20 struct erofs_sb_info { --=20 2.20.1 From nobody Sun Apr 5 13:07:33 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 25698ECAAD3 for ; Thu, 15 Sep 2022 12:43:49 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230246AbiIOMnq (ORCPT ); Thu, 15 Sep 2022 08:43:46 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:38192 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230234AbiIOMnB (ORCPT ); Thu, 15 Sep 2022 08:43:01 -0400 Received: from mail-pl1-x62a.google.com (mail-pl1-x62a.google.com [IPv6:2607:f8b0:4864:20::62a]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 36C529CCDC for ; Thu, 15 Sep 2022 05:42:53 -0700 (PDT) Received: by mail-pl1-x62a.google.com with SMTP id c2so18228334plo.3 for ; Thu, 15 Sep 2022 05:42:53 -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=dBZRlmedpxhbheR4+YN0HocAk5E9pqe8yTyKp+a8Jvo=; b=wGL+P0AnD/GNLjjT24uVsLIZwCjtnS68EAO2WcfTxZFkhvVT/imehV4PqGdD9u11lo mHxyBtFq9duyXZIiKcqegXgI67PQGZyv1FARnxfLtJPl//LGhPBirrHxsHZMHRB9DLAz Wb7SJ6apxY7SF8Pc2g4Gg9+1s6+QI4I1vJhNBvhqpUPnYW8DdTU5YdGxp5D1QKIZck9/ L6U90aBZFVaRvvbGZrdF+ClZ5VxK0ZlwgZF9Wnhn6CBxbM6PAoQhJS5v/pkDOz2mIlAa Su3CDhC0H6wTECs2IS+AbHhCLSS2SpIfTFUYeIOdDAxrJ+UmNxGT+M5DuFAWmGzDqJWT +yqg== 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=dBZRlmedpxhbheR4+YN0HocAk5E9pqe8yTyKp+a8Jvo=; b=FLLuob4YAw0OFz01ycHZNo30eGYZEGHJQf32UIN4vk8/2zrq3UK2NpjoFDxLSu/wrS 2HTzU+9wCim+LkdDx0bGXggUhCRUSApQW6kdoLqtMMS2qHyw6KZ2Db0slH6X9la3UwB1 hd1hpDtQh2mUT4dY2Z900GnqZ9qbfrNHgqG4QgKU+a6+baJYpaYlUDJYP2TjGdyDvNFP JQelo1vwY9NYzjWP04V+vNBP6UzOZ7Wxj179HTncWN4vQaefzBDWccVu/+vwHU+ZAe1F m91I4Mrp/zIIawojzs4bq2oKBLG1gFAd5yZGIDFUXWoc8oMumXKAKusM/K7nbPJ5JHzm BO8g== X-Gm-Message-State: ACrzQf2Z2y1yVp1yF6/IlBorzvkA3Az5uJhb9zPVJMu2ULO8DIjManX9 aB3su3O9SGUtVFFJCOlEY6bdog== X-Google-Smtp-Source: AMsMyM7YeUekbjwUyKbeSAZ971uM0weIsXJ7+N2Y2Xx6JX3tiNRAUFd1xpMZLNwBX63dFYLT7STQeg== X-Received: by 2002:a17:903:22c9:b0:178:18a1:d170 with SMTP id y9-20020a17090322c900b0017818a1d170mr4343590plg.2.1663245772723; Thu, 15 Sep 2022 05:42:52 -0700 (PDT) Received: from C02G705SMD6V.bytedance.net ([61.120.150.76]) by smtp.gmail.com with ESMTPSA id p8-20020a170902780800b001637529493esm12721906pll.66.2022.09.15.05.42.49 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 15 Sep 2022 05:42:52 -0700 (PDT) From: Jia Zhu To: linux-erofs@lists.ozlabs.org Cc: linux-fsdevel@vger.kernel.org, linux-kernel@vger.kernel.org, yinxin.x@bytedance.com, jefflexu@linux.alibaba.com, Jia Zhu Subject: [PATCH V4 6/6] erofs: introduce 'domain_id' mount option Date: Thu, 15 Sep 2022 20:42:13 +0800 Message-Id: <20220915124213.25767-7-zhujia.zj@bytedance.com> X-Mailer: git-send-email 2.37.0 (Apple Git-136) In-Reply-To: <20220915124213.25767-1-zhujia.zj@bytedance.com> References: <20220915124213.25767-1-zhujia.zj@bytedance.com> MIME-Version: 1.0 Content-Transfer-Encoding: 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/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 24bac58285e8..5e55c4fe6220 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 @@ -914,6 +928,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; } @@ -1067,6 +1082,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