Skip to content

Commit b02c602

Browse files
lostjefflehsiangkao
authored andcommitted
erofs: add fscache context helper functions
Introduce a context structure for managing data blobs, and helper functions for initializing and cleaning up this context structure. 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 c6be2bd commit b02c602

File tree

2 files changed

+60
-0
lines changed

2 files changed

+60
-0
lines changed

fs/erofs/fscache.c

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,47 @@
55
#include <linux/fscache.h>
66
#include "internal.h"
77

8+
int erofs_fscache_register_cookie(struct super_block *sb,
9+
struct erofs_fscache **fscache, char *name)
10+
{
11+
struct fscache_volume *volume = EROFS_SB(sb)->volume;
12+
struct erofs_fscache *ctx;
13+
struct fscache_cookie *cookie;
14+
15+
ctx = kzalloc(sizeof(*ctx), GFP_KERNEL);
16+
if (!ctx)
17+
return -ENOMEM;
18+
19+
cookie = fscache_acquire_cookie(volume, FSCACHE_ADV_WANT_CACHE_SIZE,
20+
name, strlen(name), NULL, 0, 0);
21+
if (!cookie) {
22+
erofs_err(sb, "failed to get cookie for %s", name);
23+
kfree(name);
24+
return -EINVAL;
25+
}
26+
27+
fscache_use_cookie(cookie, false);
28+
ctx->cookie = cookie;
29+
30+
*fscache = ctx;
31+
return 0;
32+
}
33+
34+
void erofs_fscache_unregister_cookie(struct erofs_fscache **fscache)
35+
{
36+
struct erofs_fscache *ctx = *fscache;
37+
38+
if (!ctx)
39+
return;
40+
41+
fscache_unuse_cookie(ctx->cookie, NULL, NULL);
42+
fscache_relinquish_cookie(ctx->cookie, false);
43+
ctx->cookie = NULL;
44+
45+
kfree(ctx);
46+
*fscache = NULL;
47+
}
48+
849
int erofs_fscache_register_fs(struct super_block *sb)
950
{
1051
struct erofs_sb_info *sbi = EROFS_SB(sb);

fs/erofs/internal.h

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -97,6 +97,10 @@ struct erofs_sb_lz4_info {
9797
u16 max_pclusterblks;
9898
};
9999

100+
struct erofs_fscache {
101+
struct fscache_cookie *cookie;
102+
};
103+
100104
struct erofs_sb_info {
101105
struct erofs_mount_opts opt; /* options */
102106
#ifdef CONFIG_EROFS_FS_ZIP
@@ -601,12 +605,27 @@ static inline int z_erofs_load_lzma_config(struct super_block *sb,
601605
#ifdef CONFIG_EROFS_FS_ONDEMAND
602606
int erofs_fscache_register_fs(struct super_block *sb);
603607
void erofs_fscache_unregister_fs(struct super_block *sb);
608+
609+
int erofs_fscache_register_cookie(struct super_block *sb,
610+
struct erofs_fscache **fscache, char *name);
611+
void erofs_fscache_unregister_cookie(struct erofs_fscache **fscache);
604612
#else
605613
static inline int erofs_fscache_register_fs(struct super_block *sb)
606614
{
607615
return 0;
608616
}
609617
static inline void erofs_fscache_unregister_fs(struct super_block *sb) {}
618+
619+
static inline int erofs_fscache_register_cookie(struct super_block *sb,
620+
struct erofs_fscache **fscache,
621+
char *name)
622+
{
623+
return -EOPNOTSUPP;
624+
}
625+
626+
static inline void erofs_fscache_unregister_cookie(struct erofs_fscache **fscache)
627+
{
628+
}
610629
#endif
611630

612631
#define EFSCORRUPTED EUCLEAN /* Filesystem is corrupted */

0 commit comments

Comments
 (0)