5
5
#include <linux/fscache.h>
6
6
#include "internal.h"
7
7
8
+ static const struct address_space_operations erofs_fscache_meta_aops = {
9
+ };
10
+
8
11
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 )
10
14
{
11
15
struct fscache_volume * volume = EROFS_SB (sb )-> volume ;
12
16
struct erofs_fscache * ctx ;
13
17
struct fscache_cookie * cookie ;
18
+ int ret ;
14
19
15
20
ctx = kzalloc (sizeof (* ctx ), GFP_KERNEL );
16
21
if (!ctx )
@@ -20,15 +25,40 @@ int erofs_fscache_register_cookie(struct super_block *sb,
20
25
name , strlen (name ), NULL , 0 , 0 );
21
26
if (!cookie ) {
22
27
erofs_err (sb , "failed to get cookie for %s" , name );
23
- kfree ( name ) ;
24
- return - EINVAL ;
28
+ ret = - EINVAL ;
29
+ goto err ;
25
30
}
26
31
27
32
fscache_use_cookie (cookie , false);
28
33
ctx -> cookie = cookie ;
29
34
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
+
30
52
* fscache = ctx ;
31
53
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 ;
32
62
}
33
63
34
64
void erofs_fscache_unregister_cookie (struct erofs_fscache * * fscache )
@@ -42,6 +72,9 @@ void erofs_fscache_unregister_cookie(struct erofs_fscache **fscache)
42
72
fscache_relinquish_cookie (ctx -> cookie , false);
43
73
ctx -> cookie = NULL ;
44
74
75
+ iput (ctx -> inode );
76
+ ctx -> inode = NULL ;
77
+
45
78
kfree (ctx );
46
79
* fscache = NULL ;
47
80
}
0 commit comments