From nobody Sun Apr 5 16:33:03 2026 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id DEE4EECAAD3 for ; Wed, 14 Sep 2022 10:51:26 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230029AbiINKvZ (ORCPT ); Wed, 14 Sep 2022 06:51:25 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:39718 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229972AbiINKvN (ORCPT ); Wed, 14 Sep 2022 06:51:13 -0400 Received: from mail-pf1-x432.google.com (mail-pf1-x432.google.com [IPv6:2607:f8b0:4864:20::432]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id D832A77E9A for ; Wed, 14 Sep 2022 03:50:58 -0700 (PDT) Received: by mail-pf1-x432.google.com with SMTP id a80so5942158pfa.4 for ; Wed, 14 Sep 2022 03:50:58 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bytedance-com.20210112.gappssmtp.com; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date; bh=mLKoFPsfe1DGX67jxmoOMM6ui+KnXFQNQxxyiB6uJvQ=; b=wuB6Y8o7aBM+itTdXuxbD9c9ov2tLG0Re7l2uBZ7YsxJr9YLMuY+rQpmy0KcyxH43B CDaMvLmDbhoGhdUma+3KR6N4jNBW9P1Smph3Nh7+cPODdEDuWVJhIRB8YcszkwsUmktU n/zWlKad//6cofQRLkqmyjCiTqdiQbw2N2rNXggm6veLySgMwOdc2bYlObleX+Yi2sO/ DI3gAK7pcEO/vnSPYVqArRxAinRjQI7NvBu02rFPpSvKtpp+9FGVxkrd0fsBGujWd47V 51qsMnezq/zeoKKoydcDXO7GdsPp7dNIEi9ka0UaRSAt7Mb5LK1bGRVH0njwarepSHyn 8t8g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date; bh=mLKoFPsfe1DGX67jxmoOMM6ui+KnXFQNQxxyiB6uJvQ=; b=sxxBUlJtm+ILDBVbrCD+JvX9phhuhp8B0EupfDi9nHKjQAU7Fsl/nj++bF40T7vEdn 6yXK/9/s671mrGchAGE/Zz0WXS8EhjIwVL3HRK+1z+B5T0r4tzk76Dkcuxmi+QsB8kfH OpXDsFHPIRNdezpK1jdcymHxzpm+8jjAoKCbEe+xBFhD/kbCydlKGMahi5f3L7vuISUL 8ORI8wdTuUYOiDN5lXnJ/VYS+mTPxhv3FYbFru7qBUvcVcHAXyayQQScAyK9Gsaci4QT 1I2h4xEFOatxvgWAfahb5LOF9yZ1jSwpC3Ny33W20NUBQ1kd0tXWzOS0op26CcxLCRnr DUiw== X-Gm-Message-State: ACgBeo0esOxcouOwoyBTvnjZLeiur2WkmxGRzG2ibo3JWlnRdbNYFx7E UXhHEShIw7rMie0+ADgGwGZSYA== X-Google-Smtp-Source: AA6agR4fp34wrjI43Hdysv4EUHq0KqK4ftDpRUIqIM0HnWzgjWPBkYz+EgLGamHV3dSau08iBdku4Q== X-Received: by 2002:a63:e305:0:b0:439:6e0c:f81e with SMTP id f5-20020a63e305000000b004396e0cf81emr1144234pgh.50.1663152657977; Wed, 14 Sep 2022 03:50:57 -0700 (PDT) Received: from C02G705SMD6V.bytedance.net ([2400:8800:1f02:83:4000:0:1:2]) by smtp.gmail.com with ESMTPSA id x13-20020a170902ec8d00b0016dc2366722sm10537042plg.77.2022.09.14.03.50.54 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 14 Sep 2022 03:50:57 -0700 (PDT) From: Jia Zhu To: linux-erofs@lists.ozlabs.org, xiang@kernel.org, chao@kernel.org Cc: linux-fsdevel@vger.kernel.org, linux-kernel@vger.kernel.org, yinxin.x@bytedance.com, jefflexu@linux.alibaba.com, huyue2@coolpad.com, Jia Zhu Subject: [PATCH V3 2/6] erofs: code clean up for fscache Date: Wed, 14 Sep 2022 18:50:37 +0800 Message-Id: <20220914105041.42970-3-zhujia.zj@bytedance.com> X-Mailer: git-send-email 2.37.0 (Apple Git-136) In-Reply-To: <20220914105041.42970-1-zhujia.zj@bytedance.com> References: <20220914105041.42970-1-zhujia.zj@bytedance.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" Some cleanups. No logic changes. Signed-off-by: Jingbo Xu Signed-off-by: Jia Zhu --- fs/erofs/fscache.c | 26 +++++++++++++++----------- fs/erofs/internal.h | 17 ++++++++--------- fs/erofs/super.c | 22 +++++++++------------- 3 files changed, 32 insertions(+), 33 deletions(-) diff --git a/fs/erofs/fscache.c b/fs/erofs/fscache.c index 8e01d89c3319..4159cf781924 100644 --- a/fs/erofs/fscache.c +++ b/fs/erofs/fscache.c @@ -417,9 +417,8 @@ const struct address_space_operations erofs_fscache_acc= ess_aops =3D { .readahead =3D erofs_fscache_readahead, }; =20 -int erofs_fscache_register_cookie(struct super_block *sb, - struct erofs_fscache **fscache, - char *name, bool need_inode) +struct erofs_fscache *erofs_fscache_register_cookie(struct super_block *sb, + char *name, bool need_inode) { struct fscache_volume *volume =3D EROFS_SB(sb)->volume; struct erofs_fscache *ctx; @@ -428,7 +427,7 @@ int erofs_fscache_register_cookie(struct super_block *s= b, =20 ctx =3D kzalloc(sizeof(*ctx), GFP_KERNEL); if (!ctx) - return -ENOMEM; + return ERR_PTR(-ENOMEM); =20 cookie =3D fscache_acquire_cookie(volume, FSCACHE_ADV_WANT_CACHE_SIZE, name, strlen(name), NULL, 0, 0); @@ -458,8 +457,7 @@ int erofs_fscache_register_cookie(struct super_block *s= b, ctx->inode =3D inode; } =20 - *fscache =3D ctx; - return 0; + return ctx; =20 err_cookie: fscache_unuse_cookie(ctx->cookie, NULL, NULL); @@ -467,13 +465,11 @@ int erofs_fscache_register_cookie(struct super_block = *sb, ctx->cookie =3D NULL; err: kfree(ctx); - return ret; + return ERR_PTR(ret); } =20 -void erofs_fscache_unregister_cookie(struct erofs_fscache **fscache) +void erofs_fscache_unregister_cookie(struct erofs_fscache *ctx) { - struct erofs_fscache *ctx =3D *fscache; - if (!ctx) return; =20 @@ -485,13 +481,13 @@ void erofs_fscache_unregister_cookie(struct erofs_fsc= ache **fscache) ctx->inode =3D NULL; =20 kfree(ctx); - *fscache =3D NULL; } =20 int erofs_fscache_register_fs(struct super_block *sb) { struct erofs_sb_info *sbi =3D EROFS_SB(sb); struct fscache_volume *volume; + struct erofs_fscache *fscache; char *name; int ret =3D 0; =20 @@ -508,6 +504,12 @@ int erofs_fscache_register_fs(struct super_block *sb) =20 sbi->volume =3D volume; kfree(name); + + fscache =3D erofs_fscache_register_cookie(sb, sbi->opt.fsid, true); + if (IS_ERR(fscache)) + return PTR_ERR(fscache); + + sbi->s_fscache =3D fscache; return ret; } =20 @@ -515,6 +517,8 @@ void erofs_fscache_unregister_fs(struct super_block *sb) { struct erofs_sb_info *sbi =3D EROFS_SB(sb); =20 + erofs_fscache_unregister_cookie(sbi->s_fscache); fscache_relinquish_volume(sbi->volume, NULL, false); + sbi->s_fscache =3D NULL; sbi->volume =3D NULL; } diff --git a/fs/erofs/internal.h b/fs/erofs/internal.h index cfee49d33b95..aa71eb65e965 100644 --- a/fs/erofs/internal.h +++ b/fs/erofs/internal.h @@ -610,27 +610,26 @@ static inline int z_erofs_load_lzma_config(struct sup= er_block *sb, int erofs_fscache_register_fs(struct super_block *sb); void erofs_fscache_unregister_fs(struct super_block *sb); =20 -int erofs_fscache_register_cookie(struct super_block *sb, - struct erofs_fscache **fscache, - char *name, bool need_inode); -void erofs_fscache_unregister_cookie(struct erofs_fscache **fscache); +struct erofs_fscache *erofs_fscache_register_cookie(struct super_block *sb, + char *name, bool need_inode); +void erofs_fscache_unregister_cookie(struct erofs_fscache *fscache); =20 extern const struct address_space_operations erofs_fscache_access_aops; #else static inline int erofs_fscache_register_fs(struct super_block *sb) { - return 0; + return -EOPNOTSUPP; } static inline void erofs_fscache_unregister_fs(struct super_block *sb) {} =20 -static inline int erofs_fscache_register_cookie(struct super_block *sb, - struct erofs_fscache **fscache, - char *name, bool need_inode) +static inline +struct erofs_fscache *erofs_fscache_register_cookie(struct super_block *sb, + char *name, bool need_inode) { return -EOPNOTSUPP; } =20 -static inline void erofs_fscache_unregister_cookie(struct erofs_fscache **= fscache) +static inline void erofs_fscache_unregister_cookie(struct erofs_fscache *f= scache) { } #endif diff --git a/fs/erofs/super.c b/fs/erofs/super.c index 9716d355a63e..7aa57dcebf31 100644 --- a/fs/erofs/super.c +++ b/fs/erofs/super.c @@ -224,10 +224,10 @@ static int erofs_init_device(struct erofs_buf *buf, s= truct super_block *sb, struct erofs_device_info *dif, erofs_off_t *pos) { struct erofs_sb_info *sbi =3D EROFS_SB(sb); + struct erofs_fscache *fscache; struct erofs_deviceslot *dis; struct block_device *bdev; void *ptr; - int ret; =20 ptr =3D erofs_read_metabuf(buf, sb, erofs_blknr(*pos), EROFS_KMAP); if (IS_ERR(ptr)) @@ -245,10 +245,10 @@ static int erofs_init_device(struct erofs_buf *buf, s= truct super_block *sb, } =20 if (erofs_is_fscache_mode(sb)) { - ret =3D erofs_fscache_register_cookie(sb, &dif->fscache, - dif->path, false); - if (ret) - return ret; + fscache =3D erofs_fscache_register_cookie(sb, dif->path, false); + if (IS_ERR(fscache)) + return PTR_ERR(fscache); + dif->fscache =3D fscache; } else { bdev =3D blkdev_get_by_path(dif->path, FMODE_READ | FMODE_EXCL, sb->s_type); @@ -706,11 +706,6 @@ static int erofs_fc_fill_super(struct super_block *sb,= struct fs_context *fc) if (err) return err; =20 - err =3D erofs_fscache_register_cookie(sb, &sbi->s_fscache, - sbi->opt.fsid, true); - if (err) - return err; - err =3D super_setup_bdi(sb); if (err) return err; @@ -817,7 +812,8 @@ static int erofs_release_device_info(int id, void *ptr,= void *data) fs_put_dax(dif->dax_dev, NULL); if (dif->bdev) blkdev_put(dif->bdev, FMODE_READ | FMODE_EXCL); - erofs_fscache_unregister_cookie(&dif->fscache); + erofs_fscache_unregister_cookie(dif->fscache); + dif->fscache =3D NULL; kfree(dif->path); kfree(dif); return 0; @@ -889,7 +885,6 @@ static void erofs_kill_sb(struct super_block *sb) =20 erofs_free_dev_context(sbi->devs); fs_put_dax(sbi->dax_dev, NULL); - erofs_fscache_unregister_cookie(&sbi->s_fscache); erofs_fscache_unregister_fs(sb); kfree(sbi->opt.fsid); kfree(sbi); @@ -909,7 +904,8 @@ static void erofs_put_super(struct super_block *sb) iput(sbi->managed_cache); sbi->managed_cache =3D NULL; #endif - erofs_fscache_unregister_cookie(&sbi->s_fscache); + erofs_fscache_unregister_cookie(sbi->s_fscache); + sbi->s_fscache =3D NULL; } =20 static struct file_system_type erofs_fs_type =3D { --=20 2.20.1