summaryrefslogtreecommitdiff
path: root/fs/erofs/fscache.c
diff options
context:
space:
mode:
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;
}