summaryrefslogtreecommitdiffstats
path: root/fs/erofs/fscache.c
diff options
context:
space:
mode:
authorJia Zhu <zhujia.zj@bytedance.com>2022-09-18 12:34:52 +0800
committerGao Xiang <hsiangkao@linux.alibaba.com>2022-09-20 08:01:53 +0800
commite1de2da0b7ac2dc0120c2ba8c7044788611933ea (patch)
treec1324abb4ccab111fea04341c8f97b4b5c874cf8 /fs/erofs/fscache.c
parent1015c1016c231b26d4e2c9b3da65b6c043eb97a3 (diff)
downloadlinux-e1de2da0b7ac2dc0120c2ba8c7044788611933ea.tar.bz2
erofs: code clean up for fscache
Some cleanups. No logic changes. Suggested-by: Jingbo Xu <jefflexu@linux.alibaba.com> Signed-off-by: Jia Zhu <zhujia.zj@bytedance.com> Reviewed-by: Jingbo Xu <jefflexu@linux.alibaba.com> Link: https://lore.kernel.org/r/20220918043456.147-3-zhujia.zj@bytedance.com Signed-off-by: Gao Xiang <hsiangkao@linux.alibaba.com>
Diffstat (limited to 'fs/erofs/fscache.c')
-rw-r--r--fs/erofs/fscache.c39
1 files changed, 19 insertions, 20 deletions
diff --git a/fs/erofs/fscache.c b/fs/erofs/fscache.c
index b5fd9d71e67f..1eb63987e815 100644
--- a/fs/erofs/fscache.c
+++ b/fs/erofs/fscache.c
@@ -421,9 +421,8 @@ const struct address_space_operations erofs_fscache_access_aops = {
.readahead = erofs_fscache_readahead,
};
-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 = EROFS_SB(sb)->volume;
struct erofs_fscache *ctx;
@@ -432,7 +431,7 @@ int erofs_fscache_register_cookie(struct super_block *sb,
ctx = kzalloc(sizeof(*ctx), GFP_KERNEL);
if (!ctx)
- return -ENOMEM;
+ return ERR_PTR(-ENOMEM);
cookie = fscache_acquire_cookie(volume, FSCACHE_ADV_WANT_CACHE_SIZE,
name, strlen(name), NULL, 0, 0);
@@ -462,42 +461,33 @@ int erofs_fscache_register_cookie(struct super_block *sb,
ctx->inode = inode;
}
- *fscache = ctx;
- return 0;
+ return ctx;
err_cookie:
fscache_unuse_cookie(ctx->cookie, NULL, NULL);
fscache_relinquish_cookie(ctx->cookie, false);
- ctx->cookie = NULL;
err:
kfree(ctx);
- return ret;
+ return ERR_PTR(ret);
}
-void erofs_fscache_unregister_cookie(struct erofs_fscache **fscache)
+void erofs_fscache_unregister_cookie(struct erofs_fscache *ctx)
{
- struct erofs_fscache *ctx = *fscache;
-
if (!ctx)
return;
fscache_unuse_cookie(ctx->cookie, NULL, NULL);
fscache_relinquish_cookie(ctx->cookie, false);
- ctx->cookie = NULL;
-
iput(ctx->inode);
- ctx->inode = NULL;
-
kfree(ctx);
- *fscache = NULL;
}
int erofs_fscache_register_fs(struct super_block *sb)
{
struct erofs_sb_info *sbi = EROFS_SB(sb);
struct fscache_volume *volume;
+ struct erofs_fscache *fscache;
char *name;
- int ret = 0;
name = kasprintf(GFP_KERNEL, "erofs,%s", sbi->opt.fsid);
if (!name)
@@ -506,19 +496,28 @@ int erofs_fscache_register_fs(struct super_block *sb)
volume = fscache_acquire_volume(name, NULL, NULL, 0);
if (IS_ERR_OR_NULL(volume)) {
erofs_err(sb, "failed to register volume for %s", name);
- ret = volume ? PTR_ERR(volume) : -EOPNOTSUPP;
- volume = NULL;
+ kfree(name);
+ return volume ? PTR_ERR(volume) : -EOPNOTSUPP;
}
sbi->volume = volume;
kfree(name);
- return ret;
+
+ fscache = 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 = fscache;
+ return 0;
}
void erofs_fscache_unregister_fs(struct super_block *sb)
{
struct erofs_sb_info *sbi = EROFS_SB(sb);
+ erofs_fscache_unregister_cookie(sbi->s_fscache);
fscache_relinquish_volume(sbi->volume, NULL, false);
+ sbi->s_fscache = NULL;
sbi->volume = NULL;
}