Skip to content

Commit 3c265d7

Browse files
lostjefflehsiangkao
authored andcommitted
erofs: add anonymous inode caching metadata for data blobs
Introduce one anonymous inode for data blobs so that erofs can cache metadata directly within such anonymous inode. Signed-off-by: Jeffle Xu <[email protected]> Reviewed-by: Gao Xiang <[email protected]> Link: https://lore.kernel.org/r/[email protected] Acked-by: Chao Yu <[email protected]> Signed-off-by: Gao Xiang <[email protected]>
1 parent b02c602 commit 3c265d7

File tree

2 files changed

+40
-5
lines changed

2 files changed

+40
-5
lines changed

fs/erofs/fscache.c

Lines changed: 36 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,12 +5,17 @@
55
#include <linux/fscache.h>
66
#include "internal.h"
77

8+
static const struct address_space_operations erofs_fscache_meta_aops = {
9+
};
10+
811
int erofs_fscache_register_cookie(struct super_block *sb,
9-
struct erofs_fscache **fscache, char *name)
12+
struct erofs_fscache **fscache,
13+
char *name, bool need_inode)
1014
{
1115
struct fscache_volume *volume = EROFS_SB(sb)->volume;
1216
struct erofs_fscache *ctx;
1317
struct fscache_cookie *cookie;
18+
int ret;
1419

1520
ctx = kzalloc(sizeof(*ctx), GFP_KERNEL);
1621
if (!ctx)
@@ -20,15 +25,40 @@ int erofs_fscache_register_cookie(struct super_block *sb,
2025
name, strlen(name), NULL, 0, 0);
2126
if (!cookie) {
2227
erofs_err(sb, "failed to get cookie for %s", name);
23-
kfree(name);
24-
return -EINVAL;
28+
ret = -EINVAL;
29+
goto err;
2530
}
2631

2732
fscache_use_cookie(cookie, false);
2833
ctx->cookie = cookie;
2934

35+
if (need_inode) {
36+
struct inode *const inode = new_inode(sb);
37+
38+
if (!inode) {
39+
erofs_err(sb, "failed to get anon inode for %s", name);
40+
ret = -ENOMEM;
41+
goto err_cookie;
42+
}
43+
44+
set_nlink(inode, 1);
45+
inode->i_size = OFFSET_MAX;
46+
inode->i_mapping->a_ops = &erofs_fscache_meta_aops;
47+
mapping_set_gfp_mask(inode->i_mapping, GFP_NOFS);
48+
49+
ctx->inode = inode;
50+
}
51+
3052
*fscache = ctx;
3153
return 0;
54+
55+
err_cookie:
56+
fscache_unuse_cookie(ctx->cookie, NULL, NULL);
57+
fscache_relinquish_cookie(ctx->cookie, false);
58+
ctx->cookie = NULL;
59+
err:
60+
kfree(ctx);
61+
return ret;
3262
}
3363

3464
void erofs_fscache_unregister_cookie(struct erofs_fscache **fscache)
@@ -42,6 +72,9 @@ void erofs_fscache_unregister_cookie(struct erofs_fscache **fscache)
4272
fscache_relinquish_cookie(ctx->cookie, false);
4373
ctx->cookie = NULL;
4474

75+
iput(ctx->inode);
76+
ctx->inode = NULL;
77+
4578
kfree(ctx);
4679
*fscache = NULL;
4780
}

fs/erofs/internal.h

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -99,6 +99,7 @@ struct erofs_sb_lz4_info {
9999

100100
struct erofs_fscache {
101101
struct fscache_cookie *cookie;
102+
struct inode *inode;
102103
};
103104

104105
struct erofs_sb_info {
@@ -607,7 +608,8 @@ int erofs_fscache_register_fs(struct super_block *sb);
607608
void erofs_fscache_unregister_fs(struct super_block *sb);
608609

609610
int erofs_fscache_register_cookie(struct super_block *sb,
610-
struct erofs_fscache **fscache, char *name);
611+
struct erofs_fscache **fscache,
612+
char *name, bool need_inode);
611613
void erofs_fscache_unregister_cookie(struct erofs_fscache **fscache);
612614
#else
613615
static inline int erofs_fscache_register_fs(struct super_block *sb)
@@ -618,7 +620,7 @@ static inline void erofs_fscache_unregister_fs(struct super_block *sb) {}
618620

619621
static inline int erofs_fscache_register_cookie(struct super_block *sb,
620622
struct erofs_fscache **fscache,
621-
char *name)
623+
char *name, bool need_inode)
622624
{
623625
return -EOPNOTSUPP;
624626
}

0 commit comments

Comments
 (0)