]>
Commit | Line | Data |
---|---|---|
60e78d2c AK |
1 | /* |
2 | * V9FS cache definitions. | |
3 | * | |
4 | * Copyright (C) 2009 by Abhishek Kulkarni <[email protected]> | |
5 | * | |
6 | * This program is free software; you can redistribute it and/or modify | |
7 | * it under the terms of the GNU General Public License version 2 | |
8 | * as published by the Free Software Foundation. | |
9 | * | |
10 | * This program is distributed in the hope that it will be useful, | |
11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | |
12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
13 | * GNU General Public License for more details. | |
14 | * | |
15 | * You should have received a copy of the GNU General Public License | |
16 | * along with this program; if not, write to: | |
17 | * Free Software Foundation | |
18 | * 51 Franklin Street, Fifth Floor | |
19 | * Boston, MA 02111-1301 USA | |
20 | * | |
21 | */ | |
22 | ||
23 | #ifndef _9P_CACHE_H | |
24 | #ifdef CONFIG_9P_FSCACHE | |
25 | #include <linux/fscache.h> | |
26 | #include <linux/spinlock.h> | |
27 | ||
28 | extern struct kmem_cache *vcookie_cache; | |
29 | ||
30 | struct v9fs_cookie { | |
31 | spinlock_t lock; | |
32 | struct inode inode; | |
33 | struct fscache_cookie *fscache; | |
34 | struct p9_qid *qid; | |
35 | }; | |
36 | ||
37 | static inline struct v9fs_cookie *v9fs_inode2cookie(const struct inode *inode) | |
38 | { | |
39 | return container_of(inode, struct v9fs_cookie, inode); | |
40 | } | |
41 | ||
42 | extern struct fscache_netfs v9fs_cache_netfs; | |
43 | extern const struct fscache_cookie_def v9fs_cache_session_index_def; | |
44 | extern const struct fscache_cookie_def v9fs_cache_inode_index_def; | |
45 | ||
46 | extern void v9fs_cache_session_get_cookie(struct v9fs_session_info *v9ses); | |
47 | extern void v9fs_cache_session_put_cookie(struct v9fs_session_info *v9ses); | |
48 | ||
49 | extern void v9fs_cache_inode_get_cookie(struct inode *inode); | |
50 | extern void v9fs_cache_inode_put_cookie(struct inode *inode); | |
51 | extern void v9fs_cache_inode_flush_cookie(struct inode *inode); | |
52 | extern void v9fs_cache_inode_set_cookie(struct inode *inode, struct file *filp); | |
53 | extern void v9fs_cache_inode_reset_cookie(struct inode *inode); | |
54 | ||
55 | extern int __v9fs_cache_register(void); | |
56 | extern void __v9fs_cache_unregister(void); | |
57 | ||
58 | extern int __v9fs_fscache_release_page(struct page *page, gfp_t gfp); | |
59 | extern void __v9fs_fscache_invalidate_page(struct page *page); | |
60 | extern int __v9fs_readpage_from_fscache(struct inode *inode, | |
61 | struct page *page); | |
62 | extern int __v9fs_readpages_from_fscache(struct inode *inode, | |
63 | struct address_space *mapping, | |
64 | struct list_head *pages, | |
65 | unsigned *nr_pages); | |
66 | extern void __v9fs_readpage_to_fscache(struct inode *inode, struct page *page); | |
67 | ||
68 | ||
69 | /** | |
70 | * v9fs_cache_register - Register v9fs file system with the cache | |
71 | */ | |
72 | static inline int v9fs_cache_register(void) | |
73 | { | |
74 | return __v9fs_cache_register(); | |
75 | } | |
76 | ||
77 | /** | |
78 | * v9fs_cache_unregister - Unregister v9fs from the cache | |
79 | */ | |
80 | static inline void v9fs_cache_unregister(void) | |
81 | { | |
82 | __v9fs_cache_unregister(); | |
83 | } | |
84 | ||
85 | static inline int v9fs_fscache_release_page(struct page *page, | |
86 | gfp_t gfp) | |
87 | { | |
88 | return __v9fs_fscache_release_page(page, gfp); | |
89 | } | |
90 | ||
91 | static inline void v9fs_fscache_invalidate_page(struct page *page) | |
92 | { | |
93 | __v9fs_fscache_invalidate_page(page); | |
94 | } | |
95 | ||
96 | static inline int v9fs_readpage_from_fscache(struct inode *inode, | |
97 | struct page *page) | |
98 | { | |
99 | return __v9fs_readpage_from_fscache(inode, page); | |
100 | } | |
101 | ||
102 | static inline int v9fs_readpages_from_fscache(struct inode *inode, | |
103 | struct address_space *mapping, | |
104 | struct list_head *pages, | |
105 | unsigned *nr_pages) | |
106 | { | |
107 | return __v9fs_readpages_from_fscache(inode, mapping, pages, | |
108 | nr_pages); | |
109 | } | |
110 | ||
111 | static inline void v9fs_readpage_to_fscache(struct inode *inode, | |
112 | struct page *page) | |
113 | { | |
114 | if (PageFsCache(page)) | |
115 | __v9fs_readpage_to_fscache(inode, page); | |
116 | } | |
117 | ||
118 | static inline void v9fs_uncache_page(struct inode *inode, struct page *page) | |
119 | { | |
120 | struct v9fs_cookie *vcookie = v9fs_inode2cookie(inode); | |
121 | fscache_uncache_page(vcookie->fscache, page); | |
122 | BUG_ON(PageFsCache(page)); | |
123 | } | |
124 | ||
125 | static inline void v9fs_vcookie_set_qid(struct inode *inode, | |
126 | struct p9_qid *qid) | |
127 | { | |
128 | struct v9fs_cookie *vcookie = v9fs_inode2cookie(inode); | |
129 | spin_lock(&vcookie->lock); | |
130 | vcookie->qid = qid; | |
131 | spin_unlock(&vcookie->lock); | |
132 | } | |
133 | ||
134 | #else /* CONFIG_9P_FSCACHE */ | |
135 | ||
136 | static inline int v9fs_cache_register(void) | |
137 | { | |
138 | return 1; | |
139 | } | |
140 | ||
141 | static inline void v9fs_cache_unregister(void) {} | |
142 | ||
143 | static inline int v9fs_fscache_release_page(struct page *page, | |
144 | gfp_t gfp) { | |
145 | return 1; | |
146 | } | |
147 | ||
148 | static inline void v9fs_fscache_invalidate_page(struct page *page) {} | |
149 | ||
150 | static inline int v9fs_readpage_from_fscache(struct inode *inode, | |
151 | struct page *page) | |
152 | { | |
153 | return -ENOBUFS; | |
154 | } | |
155 | ||
156 | static inline int v9fs_readpages_from_fscache(struct inode *inode, | |
157 | struct address_space *mapping, | |
158 | struct list_head *pages, | |
159 | unsigned *nr_pages) | |
160 | { | |
161 | return -ENOBUFS; | |
162 | } | |
163 | ||
164 | static inline void v9fs_readpage_to_fscache(struct inode *inode, | |
165 | struct page *page) | |
166 | {} | |
167 | ||
168 | static inline void v9fs_uncache_page(struct inode *inode, struct page *page) | |
169 | {} | |
170 | ||
171 | static inline void v9fs_vcookie_set_qid(struct inode *inode, | |
172 | struct p9_qid *qid) | |
173 | {} | |
174 | ||
175 | #endif /* CONFIG_9P_FSCACHE */ | |
176 | #endif /* _9P_CACHE_H */ |