aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--fs/9p/Kconfig9
-rw-r--r--fs/9p/Makefile3
-rw-r--r--fs/9p/cache.c474
-rw-r--r--fs/9p/cache.h176
-rw-r--r--fs/9p/v9fs.c196
-rw-r--r--fs/9p/v9fs.h13
-rw-r--r--fs/9p/v9fs_vfs.h6
-rw-r--r--fs/9p/vfs_addr.c88
-rw-r--r--fs/9p/vfs_file.c10
-rw-r--r--fs/9p/vfs_inode.c57
-rw-r--r--fs/9p/vfs_super.c16
-rw-r--r--include/net/9p/9p.h3
12 files changed, 1009 insertions, 42 deletions
diff --git a/fs/9p/Kconfig b/fs/9p/Kconfig
index 74e0723e90bc..795233702a4e 100644
--- a/fs/9p/Kconfig
+++ b/fs/9p/Kconfig
@@ -8,3 +8,12 @@ config 9P_FS
8 See <http://v9fs.sf.net> for more information. 8 See <http://v9fs.sf.net> for more information.
9 9
10 If unsure, say N. 10 If unsure, say N.
11
12config 9P_FSCACHE
13 bool "Enable 9P client caching support (EXPERIMENTAL)"
14 depends on EXPERIMENTAL
15 depends on 9P_FS=m && FSCACHE || 9P_FS=y && FSCACHE=y
16 help
17 Choose Y here to enable persistent, read-only local
18 caching support for 9p clients using FS-Cache
19
diff --git a/fs/9p/Makefile b/fs/9p/Makefile
index bc7f0d1551e6..1a940ec7af61 100644
--- a/fs/9p/Makefile
+++ b/fs/9p/Makefile
@@ -8,5 +8,6 @@ obj-$(CONFIG_9P_FS) := 9p.o
8 vfs_dir.o \ 8 vfs_dir.o \
9 vfs_dentry.o \ 9 vfs_dentry.o \
10 v9fs.o \ 10 v9fs.o \
11 fid.o \ 11 fid.o
12 12
139p-$(CONFIG_9P_FSCACHE) += cache.o
diff --git a/fs/9p/cache.c b/fs/9p/cache.c
new file mode 100644
index 000000000000..51c94e26a346
--- /dev/null
+++ b/fs/9p/cache.c
@@ -0,0 +1,474 @@
1/*
2 * V9FS cache definitions.
3 *
4 * Copyright (C) 2009 by Abhishek Kulkarni <adkulkar@umail.iu.edu>
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#include <linux/jiffies.h>
24#include <linux/file.h>
25#include <linux/stat.h>
26#include <linux/sched.h>
27#include <linux/fs.h>
28#include <net/9p/9p.h>
29
30#include "v9fs.h"
31#include "cache.h"
32
33#define CACHETAG_LEN 11
34
35struct kmem_cache *vcookie_cache;
36
37struct fscache_netfs v9fs_cache_netfs = {
38 .name = "9p",
39 .version = 0,
40};
41
42static void init_once(void *foo)
43{
44 struct v9fs_cookie *vcookie = (struct v9fs_cookie *) foo;
45 vcookie->fscache = NULL;
46 vcookie->qid = NULL;
47 inode_init_once(&vcookie->inode);
48}
49
50/**
51 * v9fs_init_vcookiecache - initialize a cache for vcookies to maintain
52 * vcookie to inode mapping
53 *
54 * Returns 0 on success.
55 */
56
57static int v9fs_init_vcookiecache(void)
58{
59 vcookie_cache = kmem_cache_create("vcookie_cache",
60 sizeof(struct v9fs_cookie),
61 0, (SLAB_RECLAIM_ACCOUNT|
62 SLAB_MEM_SPREAD),
63 init_once);
64 if (!vcookie_cache)
65 return -ENOMEM;
66
67 return 0;
68}
69
70/**
71 * v9fs_destroy_vcookiecache - destroy the cache of vcookies
72 *
73 */
74
75static void v9fs_destroy_vcookiecache(void)
76{
77 kmem_cache_destroy(vcookie_cache);
78}
79
80int __v9fs_cache_register(void)
81{
82 int ret;
83 ret = v9fs_init_vcookiecache();
84 if (ret < 0)
85 return ret;
86
87 return fscache_register_netfs(&v9fs_cache_netfs);
88}
89
90void __v9fs_cache_unregister(void)
91{
92 v9fs_destroy_vcookiecache();
93 fscache_unregister_netfs(&v9fs_cache_netfs);
94}
95
96/**
97 * v9fs_random_cachetag - Generate a random tag to be associated
98 * with a new cache session.
99 *
100 * The value of jiffies is used for a fairly randomly cache tag.
101 */
102
103static
104int v9fs_random_cachetag(struct v9fs_session_info *v9ses)
105{
106 v9ses->cachetag = kmalloc(CACHETAG_LEN, GFP_KERNEL);
107 if (!v9ses->cachetag)
108 return -ENOMEM;
109
110 return scnprintf(v9ses->cachetag, CACHETAG_LEN, "%lu", jiffies);
111}
112
113static uint16_t v9fs_cache_session_get_key(const void *cookie_netfs_data,
114 void *buffer, uint16_t bufmax)
115{
116 struct v9fs_session_info *v9ses;
117 uint16_t klen = 0;
118
119 v9ses = (struct v9fs_session_info *)cookie_netfs_data;
120 P9_DPRINTK(P9_DEBUG_FSC, "session %p buf %p size %u", v9ses,
121 buffer, bufmax);
122
123 if (v9ses->cachetag)
124 klen = strlen(v9ses->cachetag);
125
126 if (klen > bufmax)
127 return 0;
128
129 memcpy(buffer, v9ses->cachetag, klen);
130 P9_DPRINTK(P9_DEBUG_FSC, "cache session tag %s", v9ses->cachetag);
131 return klen;
132}
133
134const struct fscache_cookie_def v9fs_cache_session_index_def = {
135 .name = "9P.session",
136 .type = FSCACHE_COOKIE_TYPE_INDEX,
137 .get_key = v9fs_cache_session_get_key,
138};
139
140void v9fs_cache_session_get_cookie(struct v9fs_session_info *v9ses)
141{
142 /* If no cache session tag was specified, we generate a random one. */
143 if (!v9ses->cachetag)
144 v9fs_random_cachetag(v9ses);
145
146 v9ses->fscache = fscache_acquire_cookie(v9fs_cache_netfs.primary_index,
147 &v9fs_cache_session_index_def,
148 v9ses);
149 P9_DPRINTK(P9_DEBUG_FSC, "session %p get cookie %p", v9ses,
150 v9ses->fscache);
151}
152
153void v9fs_cache_session_put_cookie(struct v9fs_session_info *v9ses)
154{
155 P9_DPRINTK(P9_DEBUG_FSC, "session %p put cookie %p", v9ses,
156 v9ses->fscache);
157 fscache_relinquish_cookie(v9ses->fscache, 0);
158 v9ses->fscache = NULL;
159}
160
161
162static uint16_t v9fs_cache_inode_get_key(const void *cookie_netfs_data,
163 void *buffer, uint16_t bufmax)
164{
165 const struct v9fs_cookie *vcookie = cookie_netfs_data;
166 memcpy(buffer, &vcookie->qid->path, sizeof(vcookie->qid->path));
167
168 P9_DPRINTK(P9_DEBUG_FSC, "inode %p get key %llu", &vcookie->inode,
169 vcookie->qid->path);
170 return sizeof(vcookie->qid->path);
171}
172
173static void v9fs_cache_inode_get_attr(const void *cookie_netfs_data,
174 uint64_t *size)
175{
176 const struct v9fs_cookie *vcookie = cookie_netfs_data;
177 *size = i_size_read(&vcookie->inode);
178
179 P9_DPRINTK(P9_DEBUG_FSC, "inode %p get attr %llu", &vcookie->inode,
180 *size);
181}
182
183static uint16_t v9fs_cache_inode_get_aux(const void *cookie_netfs_data,
184 void *buffer, uint16_t buflen)
185{
186 const struct v9fs_cookie *vcookie = cookie_netfs_data;
187 memcpy(buffer, &vcookie->qid->version, sizeof(vcookie->qid->version));
188
189 P9_DPRINTK(P9_DEBUG_FSC, "inode %p get aux %u", &vcookie->inode,
190 vcookie->qid->version);
191 return sizeof(vcookie->qid->version);
192}
193
194static enum
195fscache_checkaux v9fs_cache_inode_check_aux(void *cookie_netfs_data,
196 const void *buffer,
197 uint16_t buflen)
198{
199 const struct v9fs_cookie *vcookie = cookie_netfs_data;
200
201 if (buflen != sizeof(vcookie->qid->version))
202 return FSCACHE_CHECKAUX_OBSOLETE;
203
204 if (memcmp(buffer, &vcookie->qid->version,
205 sizeof(vcookie->qid->version)))
206 return FSCACHE_CHECKAUX_OBSOLETE;
207
208 return FSCACHE_CHECKAUX_OKAY;
209}
210
211static void v9fs_cache_inode_now_uncached(void *cookie_netfs_data)
212{
213 struct v9fs_cookie *vcookie = cookie_netfs_data;
214 struct pagevec pvec;
215 pgoff_t first;
216 int loop, nr_pages;
217
218 pagevec_init(&pvec, 0);
219 first = 0;
220
221 for (;;) {
222 nr_pages = pagevec_lookup(&pvec, vcookie->inode.i_mapping,
223 first,
224 PAGEVEC_SIZE - pagevec_count(&pvec));
225 if (!nr_pages)
226 break;
227
228 for (loop = 0; loop < nr_pages; loop++)
229 ClearPageFsCache(pvec.pages[loop]);
230
231 first = pvec.pages[nr_pages - 1]->index + 1;
232
233 pvec.nr = nr_pages;
234 pagevec_release(&pvec);
235 cond_resched();
236 }
237}
238
239const struct fscache_cookie_def v9fs_cache_inode_index_def = {
240 .name = "9p.inode",
241 .type = FSCACHE_COOKIE_TYPE_DATAFILE,
242 .get_key = v9fs_cache_inode_get_key,
243 .get_attr = v9fs_cache_inode_get_attr,
244 .get_aux = v9fs_cache_inode_get_aux,
245 .check_aux = v9fs_cache_inode_check_aux,
246 .now_uncached = v9fs_cache_inode_now_uncached,
247};
248
249void v9fs_cache_inode_get_cookie(struct inode *inode)
250{
251 struct v9fs_cookie *vcookie;
252 struct v9fs_session_info *v9ses;
253
254 if (!S_ISREG(inode->i_mode))
255 return;
256
257 vcookie = v9fs_inode2cookie(inode);
258 if (vcookie->fscache)
259 return;
260
261 v9ses = v9fs_inode2v9ses(inode);
262 vcookie->fscache = fscache_acquire_cookie(v9ses->fscache,
263 &v9fs_cache_inode_index_def,
264 vcookie);
265
266 P9_DPRINTK(P9_DEBUG_FSC, "inode %p get cookie %p", inode,
267 vcookie->fscache);
268}
269
270void v9fs_cache_inode_put_cookie(struct inode *inode)
271{
272 struct v9fs_cookie *vcookie = v9fs_inode2cookie(inode);
273
274 if (!vcookie->fscache)
275 return;
276 P9_DPRINTK(P9_DEBUG_FSC, "inode %p put cookie %p", inode,
277 vcookie->fscache);
278
279 fscache_relinquish_cookie(vcookie->fscache, 0);
280 vcookie->fscache = NULL;
281}
282
283void v9fs_cache_inode_flush_cookie(struct inode *inode)
284{
285 struct v9fs_cookie *vcookie = v9fs_inode2cookie(inode);
286
287 if (!vcookie->fscache)
288 return;
289 P9_DPRINTK(P9_DEBUG_FSC, "inode %p flush cookie %p", inode,
290 vcookie->fscache);
291
292 fscache_relinquish_cookie(vcookie->fscache, 1);
293 vcookie->fscache = NULL;
294}
295
296void v9fs_cache_inode_set_cookie(struct inode *inode, struct file *filp)
297{
298 struct v9fs_cookie *vcookie = v9fs_inode2cookie(inode);
299 struct p9_fid *fid;
300
301 if (!vcookie->fscache)
302 return;
303
304 spin_lock(&vcookie->lock);
305 fid = filp->private_data;
306 if ((filp->f_flags & O_ACCMODE) != O_RDONLY)
307 v9fs_cache_inode_flush_cookie(inode);
308 else
309 v9fs_cache_inode_get_cookie(inode);
310
311 spin_unlock(&vcookie->lock);
312}
313
314void v9fs_cache_inode_reset_cookie(struct inode *inode)
315{
316 struct v9fs_cookie *vcookie = v9fs_inode2cookie(inode);
317 struct v9fs_session_info *v9ses;
318 struct fscache_cookie *old;
319
320 if (!vcookie->fscache)
321 return;
322
323 old = vcookie->fscache;
324
325 spin_lock(&vcookie->lock);
326 fscache_relinquish_cookie(vcookie->fscache, 1);
327
328 v9ses = v9fs_inode2v9ses(inode);
329 vcookie->fscache = fscache_acquire_cookie(v9ses->fscache,
330 &v9fs_cache_inode_index_def,
331 vcookie);
332
333 P9_DPRINTK(P9_DEBUG_FSC, "inode %p revalidating cookie old %p new %p",
334 inode, old, vcookie->fscache);
335
336 spin_unlock(&vcookie->lock);
337}
338
339int __v9fs_fscache_release_page(struct page *page, gfp_t gfp)
340{
341 struct inode *inode = page->mapping->host;
342 struct v9fs_cookie *vcookie = v9fs_inode2cookie(inode);
343
344 BUG_ON(!vcookie->fscache);
345
346 if (PageFsCache(page)) {
347 if (fscache_check_page_write(vcookie->fscache, page)) {
348 if (!(gfp & __GFP_WAIT))
349 return 0;
350 fscache_wait_on_page_write(vcookie->fscache, page);
351 }
352
353 fscache_uncache_page(vcookie->fscache, page);
354 ClearPageFsCache(page);
355 }
356
357 return 1;
358}
359
360void __v9fs_fscache_invalidate_page(struct page *page)
361{
362 struct inode *inode = page->mapping->host;
363 struct v9fs_cookie *vcookie = v9fs_inode2cookie(inode);
364
365 BUG_ON(!vcookie->fscache);
366
367 if (PageFsCache(page)) {
368 fscache_wait_on_page_write(vcookie->fscache, page);
369 BUG_ON(!PageLocked(page));
370 fscache_uncache_page(vcookie->fscache, page);
371 ClearPageFsCache(page);
372 }
373}
374
375static void v9fs_vfs_readpage_complete(struct page *page, void *data,
376 int error)
377{
378 if (!error)
379 SetPageUptodate(page);
380
381 unlock_page(page);
382}
383
384/**
385 * __v9fs_readpage_from_fscache - read a page from cache
386 *
387 * Returns 0 if the pages are in cache and a BIO is submitted,
388 * 1 if the pages are not in cache and -error otherwise.
389 */
390
391int __v9fs_readpage_from_fscache(struct inode *inode, struct page *page)
392{
393 int ret;
394 const struct v9fs_cookie *vcookie = v9fs_inode2cookie(inode);
395
396 P9_DPRINTK(P9_DEBUG_FSC, "inode %p page %p", inode, page);
397 if (!vcookie->fscache)
398 return -ENOBUFS;
399
400 ret = fscache_read_or_alloc_page(vcookie->fscache,
401 page,
402 v9fs_vfs_readpage_complete,
403 NULL,
404 GFP_KERNEL);
405 switch (ret) {
406 case -ENOBUFS:
407 case -ENODATA:
408 P9_DPRINTK(P9_DEBUG_FSC, "page/inode not in cache %d", ret);
409 return 1;
410 case 0:
411 P9_DPRINTK(P9_DEBUG_FSC, "BIO submitted");
412 return ret;
413 default:
414 P9_DPRINTK(P9_DEBUG_FSC, "ret %d", ret);
415 return ret;
416 }
417}
418
419/**
420 * __v9fs_readpages_from_fscache - read multiple pages from cache
421 *
422 * Returns 0 if the pages are in cache and a BIO is submitted,
423 * 1 if the pages are not in cache and -error otherwise.
424 */
425
426int __v9fs_readpages_from_fscache(struct inode *inode,
427 struct address_space *mapping,
428 struct list_head *pages,
429 unsigned *nr_pages)
430{
431 int ret;
432 const struct v9fs_cookie *vcookie = v9fs_inode2cookie(inode);
433
434 P9_DPRINTK(P9_DEBUG_FSC, "inode %p pages %u", inode, *nr_pages);
435 if (!vcookie->fscache)
436 return -ENOBUFS;
437
438 ret = fscache_read_or_alloc_pages(vcookie->fscache,
439 mapping, pages, nr_pages,
440 v9fs_vfs_readpage_complete,
441 NULL,
442 mapping_gfp_mask(mapping));
443 switch (ret) {
444 case -ENOBUFS:
445 case -ENODATA:
446 P9_DPRINTK(P9_DEBUG_FSC, "pages/inodes not in cache %d", ret);
447 return 1;
448 case 0:
449 BUG_ON(!list_empty(pages));
450 BUG_ON(*nr_pages != 0);
451 P9_DPRINTK(P9_DEBUG_FSC, "BIO submitted");
452 return ret;
453 default:
454 P9_DPRINTK(P9_DEBUG_FSC, "ret %d", ret);
455 return ret;
456 }
457}
458
459/**
460 * __v9fs_readpage_to_fscache - write a page to the cache
461 *
462 */
463
464void __v9fs_readpage_to_fscache(struct inode *inode, struct page *page)
465{
466 int ret;
467 const struct v9fs_cookie *vcookie = v9fs_inode2cookie(inode);
468
469 P9_DPRINTK(P9_DEBUG_FSC, "inode %p page %p", inode, page);
470 ret = fscache_write_page(vcookie->fscache, page, GFP_KERNEL);
471 P9_DPRINTK(P9_DEBUG_FSC, "ret = %d", ret);
472 if (ret != 0)
473 v9fs_uncache_page(inode, page);
474}
diff --git a/fs/9p/cache.h b/fs/9p/cache.h
new file mode 100644
index 000000000000..a94192bfaee8
--- /dev/null
+++ b/fs/9p/cache.h
@@ -0,0 +1,176 @@
1/*
2 * V9FS cache definitions.
3 *
4 * Copyright (C) 2009 by Abhishek Kulkarni <adkulkar@umail.iu.edu>
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
28extern struct kmem_cache *vcookie_cache;
29
30struct v9fs_cookie {
31 spinlock_t lock;
32 struct inode inode;
33 struct fscache_cookie *fscache;
34 struct p9_qid *qid;
35};
36
37static inline struct v9fs_cookie *v9fs_inode2cookie(const struct inode *inode)
38{
39 return container_of(inode, struct v9fs_cookie, inode);
40}
41
42extern struct fscache_netfs v9fs_cache_netfs;
43extern const struct fscache_cookie_def v9fs_cache_session_index_def;
44extern const struct fscache_cookie_def v9fs_cache_inode_index_def;
45
46extern void v9fs_cache_session_get_cookie(struct v9fs_session_info *v9ses);
47extern void v9fs_cache_session_put_cookie(struct v9fs_session_info *v9ses);
48
49extern void v9fs_cache_inode_get_cookie(struct inode *inode);
50extern void v9fs_cache_inode_put_cookie(struct inode *inode);
51extern void v9fs_cache_inode_flush_cookie(struct inode *inode);
52extern void v9fs_cache_inode_set_cookie(struct inode *inode, struct file *filp);
53extern void v9fs_cache_inode_reset_cookie(struct inode *inode);
54
55extern int __v9fs_cache_register(void);
56extern void __v9fs_cache_unregister(void);
57
58extern int __v9fs_fscache_release_page(struct page *page, gfp_t gfp);
59extern void __v9fs_fscache_invalidate_page(struct page *page);
60extern int __v9fs_readpage_from_fscache(struct inode *inode,
61 struct page *page);
62extern int __v9fs_readpages_from_fscache(struct inode *inode,
63 struct address_space *mapping,
64 struct list_head *pages,
65 unsigned *nr_pages);
66extern 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 */
72static 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 */
80static inline void v9fs_cache_unregister(void)
81{
82 __v9fs_cache_unregister();
83}
84
85static inline int v9fs_fscache_release_page(struct page *page,
86 gfp_t gfp)
87{
88 return __v9fs_fscache_release_page(page, gfp);
89}
90
91static inline void v9fs_fscache_invalidate_page(struct page *page)
92{
93 __v9fs_fscache_invalidate_page(page);
94}
95
96static inline int v9fs_readpage_from_fscache(struct inode *inode,
97 struct page *page)
98{
99 return __v9fs_readpage_from_fscache(inode, page);
100}
101
102static 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
111static 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
118static 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
125static 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
136static inline int v9fs_cache_register(void)
137{
138 return 1;
139}
140
141static inline void v9fs_cache_unregister(void) {}
142
143static inline int v9fs_fscache_release_page(struct page *page,
144 gfp_t gfp) {
145 return 1;
146}
147
148static inline void v9fs_fscache_invalidate_page(struct page *page) {}
149
150static inline int v9fs_readpage_from_fscache(struct inode *inode,
151 struct page *page)
152{
153 return -ENOBUFS;
154}
155
156static 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
164static inline void v9fs_readpage_to_fscache(struct inode *inode,
165 struct page *page)
166{}
167
168static inline void v9fs_uncache_page(struct inode *inode, struct page *page)
169{}
170
171static 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 */
diff --git a/fs/9p/v9fs.c b/fs/9p/v9fs.c
index f7003cfac63d..cf62b05e296a 100644
--- a/fs/9p/v9fs.c
+++ b/fs/9p/v9fs.c
@@ -34,21 +34,25 @@
34#include <net/9p/transport.h> 34#include <net/9p/transport.h>
35#include "v9fs.h" 35#include "v9fs.h"
36#include "v9fs_vfs.h" 36#include "v9fs_vfs.h"
37#include "cache.h"
38
39static DEFINE_SPINLOCK(v9fs_sessionlist_lock);
40static LIST_HEAD(v9fs_sessionlist);
37 41
38/* 42/*
39 * Option Parsing (code inspired by NFS code) 43 * Option Parsing (code inspired by NFS code)
40 * NOTE: each transport will parse its own options 44 * NOTE: each transport will parse its own options
41 */ 45 */
42 46
43enum { 47enum {
44 /* Options that take integer arguments */ 48 /* Options that take integer arguments */
45 Opt_debug, Opt_dfltuid, Opt_dfltgid, Opt_afid, 49 Opt_debug, Opt_dfltuid, Opt_dfltgid, Opt_afid,
46 /* String options */ 50 /* String options */
47 Opt_uname, Opt_remotename, Opt_trans, 51 Opt_uname, Opt_remotename, Opt_trans, Opt_cache, Opt_cachetag,
48 /* Options that take no arguments */ 52 /* Options that take no arguments */
49 Opt_nodevmap, 53 Opt_nodevmap,
50 /* Cache options */ 54 /* Cache options */
51 Opt_cache_loose, 55 Opt_cache_loose, Opt_fscache,
52 /* Access options */ 56 /* Access options */
53 Opt_access, 57 Opt_access,
54 /* Error token */ 58 /* Error token */
@@ -63,8 +67,10 @@ static const match_table_t tokens = {
63 {Opt_uname, "uname=%s"}, 67 {Opt_uname, "uname=%s"},
64 {Opt_remotename, "aname=%s"}, 68 {Opt_remotename, "aname=%s"},
65 {Opt_nodevmap, "nodevmap"}, 69 {Opt_nodevmap, "nodevmap"},
66 {Opt_cache_loose, "cache=loose"}, 70 {Opt_cache, "cache=%s"},
67 {Opt_cache_loose, "loose"}, 71 {Opt_cache_loose, "loose"},
72 {Opt_fscache, "fscache"},
73 {Opt_cachetag, "cachetag=%s"},
68 {Opt_access, "access=%s"}, 74 {Opt_access, "access=%s"},
69 {Opt_err, NULL} 75 {Opt_err, NULL}
70}; 76};
@@ -89,16 +95,16 @@ static int v9fs_parse_options(struct v9fs_session_info *v9ses, char *opts)
89 v9ses->afid = ~0; 95 v9ses->afid = ~0;
90 v9ses->debug = 0; 96 v9ses->debug = 0;
91 v9ses->cache = 0; 97 v9ses->cache = 0;
98#ifdef CONFIG_9P_FSCACHE
99 v9ses->cachetag = NULL;
100#endif
92 101
93 if (!opts) 102 if (!opts)
94 return 0; 103 return 0;
95 104
96 options = kstrdup(opts, GFP_KERNEL); 105 options = kstrdup(opts, GFP_KERNEL);
97 if (!options) { 106 if (!options)
98 P9_DPRINTK(P9_DEBUG_ERROR, 107 goto fail_option_alloc;
99 "failed to allocate copy of option string\n");
100 return -ENOMEM;
101 }
102 108
103 while ((p = strsep(&options, ",")) != NULL) { 109 while ((p = strsep(&options, ",")) != NULL) {
104 int token; 110 int token;
@@ -143,16 +149,33 @@ static int v9fs_parse_options(struct v9fs_session_info *v9ses, char *opts)
143 case Opt_cache_loose: 149 case Opt_cache_loose:
144 v9ses->cache = CACHE_LOOSE; 150 v9ses->cache = CACHE_LOOSE;
145 break; 151 break;
152 case Opt_fscache:
153 v9ses->cache = CACHE_FSCACHE;
154 break;
155 case Opt_cachetag:
156#ifdef CONFIG_9P_FSCACHE
157 v9ses->cachetag = match_strdup(&args[0]);
158#endif
159 break;
160 case Opt_cache:
161 s = match_strdup(&args[0]);
162 if (!s)
163 goto fail_option_alloc;
164
165 if (strcmp(s, "loose") == 0)
166 v9ses->cache = CACHE_LOOSE;
167 else if (strcmp(s, "fscache") == 0)
168 v9ses->cache = CACHE_FSCACHE;
169 else
170 v9ses->cache = CACHE_NONE;
171 kfree(s);
172 break;
146 173
147 case Opt_access: 174 case Opt_access:
148 s = match_strdup(&args[0]); 175 s = match_strdup(&args[0]);
149 if (!s) { 176 if (!s)
150 P9_DPRINTK(P9_DEBUG_ERROR, 177 goto fail_option_alloc;
151 "failed to allocate copy" 178
152 " of option argument\n");
153 ret = -ENOMEM;
154 break;
155 }
156 v9ses->flags &= ~V9FS_ACCESS_MASK; 179 v9ses->flags &= ~V9FS_ACCESS_MASK;
157 if (strcmp(s, "user") == 0) 180 if (strcmp(s, "user") == 0)
158 v9ses->flags |= V9FS_ACCESS_USER; 181 v9ses->flags |= V9FS_ACCESS_USER;
@@ -173,6 +196,11 @@ static int v9fs_parse_options(struct v9fs_session_info *v9ses, char *opts)
173 } 196 }
174 kfree(options); 197 kfree(options);
175 return ret; 198 return ret;
199
200fail_option_alloc:
201 P9_DPRINTK(P9_DEBUG_ERROR,
202 "failed to allocate copy of option argument\n");
203 return -ENOMEM;
176} 204}
177 205
178/** 206/**
@@ -200,6 +228,10 @@ struct p9_fid *v9fs_session_init(struct v9fs_session_info *v9ses,
200 return ERR_PTR(-ENOMEM); 228 return ERR_PTR(-ENOMEM);
201 } 229 }
202 230
231 spin_lock(&v9fs_sessionlist_lock);
232 list_add(&v9ses->slist, &v9fs_sessionlist);
233 spin_unlock(&v9fs_sessionlist_lock);
234
203 v9ses->flags = V9FS_EXTENDED | V9FS_ACCESS_USER; 235 v9ses->flags = V9FS_EXTENDED | V9FS_ACCESS_USER;
204 strcpy(v9ses->uname, V9FS_DEFUSER); 236 strcpy(v9ses->uname, V9FS_DEFUSER);
205 strcpy(v9ses->aname, V9FS_DEFANAME); 237 strcpy(v9ses->aname, V9FS_DEFANAME);
@@ -249,6 +281,11 @@ struct p9_fid *v9fs_session_init(struct v9fs_session_info *v9ses,
249 else 281 else
250 fid->uid = ~0; 282 fid->uid = ~0;
251 283
284#ifdef CONFIG_9P_FSCACHE
285 /* register the session for caching */
286 v9fs_cache_session_get_cookie(v9ses);
287#endif
288
252 return fid; 289 return fid;
253 290
254error: 291error:
@@ -268,8 +305,18 @@ void v9fs_session_close(struct v9fs_session_info *v9ses)
268 v9ses->clnt = NULL; 305 v9ses->clnt = NULL;
269 } 306 }
270 307
308#ifdef CONFIG_9P_FSCACHE
309 if (v9ses->fscache) {
310 v9fs_cache_session_put_cookie(v9ses);
311 kfree(v9ses->cachetag);
312 }
313#endif
271 __putname(v9ses->uname); 314 __putname(v9ses->uname);
272 __putname(v9ses->aname); 315 __putname(v9ses->aname);
316
317 spin_lock(&v9fs_sessionlist_lock);
318 list_del(&v9ses->slist);
319 spin_unlock(&v9fs_sessionlist_lock);
273} 320}
274 321
275/** 322/**
@@ -286,25 +333,132 @@ void v9fs_session_cancel(struct v9fs_session_info *v9ses) {
286 333
287extern int v9fs_error_init(void); 334extern int v9fs_error_init(void);
288 335
336static struct kobject *v9fs_kobj;
337
338#ifdef CONFIG_9P_FSCACHE
289/** 339/**
290 * v9fs_init - Initialize module 340 * caches_show - list caches associated with a session
341 *
342 * Returns the size of buffer written.
343 */
344
345static ssize_t caches_show(struct kobject *kobj,
346 struct kobj_attribute *attr,
347 char *buf)
348{
349 ssize_t n = 0, count = 0, limit = PAGE_SIZE;
350 struct v9fs_session_info *v9ses;
351
352 spin_lock(&v9fs_sessionlist_lock);
353 list_for_each_entry(v9ses, &v9fs_sessionlist, slist) {
354 if (v9ses->cachetag) {
355 n = snprintf(buf, limit, "%s\n", v9ses->cachetag);
356 if (n < 0) {
357 count = n;
358 break;
359 }
360
361 count += n;
362 limit -= n;
363 }
364 }
365
366 spin_unlock(&v9fs_sessionlist_lock);
367 return count;
368}
369
370static struct kobj_attribute v9fs_attr_cache = __ATTR_RO(caches);
371#endif /* CONFIG_9P_FSCACHE */
372
373static struct attribute *v9fs_attrs[] = {
374#ifdef CONFIG_9P_FSCACHE
375 &v9fs_attr_cache.attr,
376#endif
377 NULL,
378};
379
380static struct attribute_group v9fs_attr_group = {
381 .attrs = v9fs_attrs,
382};
383
384/**
385 * v9fs_sysfs_init - Initialize the v9fs sysfs interface
386 *
387 */
388
389static int v9fs_sysfs_init(void)
390{
391 v9fs_kobj = kobject_create_and_add("9p", fs_kobj);
392 if (!v9fs_kobj)
393 return -ENOMEM;
394
395 if (sysfs_create_group(v9fs_kobj, &v9fs_attr_group)) {
396 kobject_put(v9fs_kobj);
397 return -ENOMEM;
398 }
399
400 return 0;
401}
402
403/**
404 * v9fs_sysfs_cleanup - Unregister the v9fs sysfs interface
405 *
406 */
407
408static void v9fs_sysfs_cleanup(void)
409{
410 sysfs_remove_group(v9fs_kobj, &v9fs_attr_group);
411 kobject_put(v9fs_kobj);
412}
413
414/**
415 * init_v9fs - Initialize module
291 * 416 *
292 */ 417 */
293 418
294static int __init init_v9fs(void) 419static int __init init_v9fs(void)
295{ 420{
421 int err;
296 printk(KERN_INFO "Installing v9fs 9p2000 file system support\n"); 422 printk(KERN_INFO "Installing v9fs 9p2000 file system support\n");
297 /* TODO: Setup list of registered trasnport modules */ 423 /* TODO: Setup list of registered trasnport modules */
298 return register_filesystem(&v9fs_fs_type); 424 err = register_filesystem(&v9fs_fs_type);
425 if (err < 0) {
426 printk(KERN_ERR "Failed to register filesystem\n");
427 return err;
428 }
429
430 err = v9fs_cache_register();
431 if (err < 0) {
432 printk(KERN_ERR "Failed to register v9fs for caching\n");
433 goto out_fs_unreg;
434 }
435
436 err = v9fs_sysfs_init();
437 if (err < 0) {
438 printk(KERN_ERR "Failed to register with sysfs\n");
439 goto out_sysfs_cleanup;
440 }
441
442 return 0;
443
444out_sysfs_cleanup:
445 v9fs_sysfs_cleanup();
446
447out_fs_unreg:
448 unregister_filesystem(&v9fs_fs_type);
449
450 return err;
299} 451}
300 452
301/** 453/**
302 * v9fs_init - shutdown module 454 * exit_v9fs - shutdown module
303 * 455 *
304 */ 456 */
305 457
306static void __exit exit_v9fs(void) 458static void __exit exit_v9fs(void)
307{ 459{
460 v9fs_sysfs_cleanup();
461 v9fs_cache_unregister();
308 unregister_filesystem(&v9fs_fs_type); 462 unregister_filesystem(&v9fs_fs_type);
309} 463}
310 464
diff --git a/fs/9p/v9fs.h b/fs/9p/v9fs.h
index 38762bf102a9..019f4ccb70c1 100644
--- a/fs/9p/v9fs.h
+++ b/fs/9p/v9fs.h
@@ -51,6 +51,7 @@ enum p9_session_flags {
51enum p9_cache_modes { 51enum p9_cache_modes {
52 CACHE_NONE, 52 CACHE_NONE,
53 CACHE_LOOSE, 53 CACHE_LOOSE,
54 CACHE_FSCACHE,
54}; 55};
55 56
56/** 57/**
@@ -60,6 +61,8 @@ enum p9_cache_modes {
60 * @debug: debug level 61 * @debug: debug level
61 * @afid: authentication handle 62 * @afid: authentication handle
62 * @cache: cache mode of type &p9_cache_modes 63 * @cache: cache mode of type &p9_cache_modes
64 * @cachetag: the tag of the cache associated with this session
65 * @fscache: session cookie associated with FS-Cache
63 * @options: copy of options string given by user 66 * @options: copy of options string given by user
64 * @uname: string user name to mount hierarchy as 67 * @uname: string user name to mount hierarchy as
65 * @aname: mount specifier for remote hierarchy 68 * @aname: mount specifier for remote hierarchy
@@ -68,7 +71,7 @@ enum p9_cache_modes {
68 * @dfltgid: default numeric groupid to mount hierarchy as 71 * @dfltgid: default numeric groupid to mount hierarchy as
69 * @uid: if %V9FS_ACCESS_SINGLE, the numeric uid which mounted the hierarchy 72 * @uid: if %V9FS_ACCESS_SINGLE, the numeric uid which mounted the hierarchy
70 * @clnt: reference to 9P network client instantiated for this session 73 * @clnt: reference to 9P network client instantiated for this session
71 * @debugfs_dir: reference to debugfs_dir which can be used for add'l debug 74 * @slist: reference to list of registered 9p sessions
72 * 75 *
73 * This structure holds state for each session instance established during 76 * This structure holds state for each session instance established during
74 * a sys_mount() . 77 * a sys_mount() .
@@ -84,6 +87,10 @@ struct v9fs_session_info {
84 unsigned short debug; 87 unsigned short debug;
85 unsigned int afid; 88 unsigned int afid;
86 unsigned int cache; 89 unsigned int cache;
90#ifdef CONFIG_9P_FSCACHE
91 char *cachetag;
92 struct fscache_cookie *fscache;
93#endif
87 94
88 char *uname; /* user name to mount as */ 95 char *uname; /* user name to mount as */
89 char *aname; /* name of remote hierarchy being mounted */ 96 char *aname; /* name of remote hierarchy being mounted */
@@ -92,11 +99,9 @@ struct v9fs_session_info {
92 unsigned int dfltgid; /* default gid for legacy support */ 99 unsigned int dfltgid; /* default gid for legacy support */
93 u32 uid; /* if ACCESS_SINGLE, the uid that has access */ 100 u32 uid; /* if ACCESS_SINGLE, the uid that has access */
94 struct p9_client *clnt; /* 9p client */ 101 struct p9_client *clnt; /* 9p client */
95 struct dentry *debugfs_dir; 102 struct list_head slist; /* list of sessions registered with v9fs */
96}; 103};
97 104
98extern struct dentry *v9fs_debugfs_root;
99
100struct p9_fid *v9fs_session_init(struct v9fs_session_info *, const char *, 105struct p9_fid *v9fs_session_init(struct v9fs_session_info *, const char *,
101 char *); 106 char *);
102void v9fs_session_close(struct v9fs_session_info *v9ses); 107void v9fs_session_close(struct v9fs_session_info *v9ses);
diff --git a/fs/9p/v9fs_vfs.h b/fs/9p/v9fs_vfs.h
index f0c7de78e205..3a7560e35865 100644
--- a/fs/9p/v9fs_vfs.h
+++ b/fs/9p/v9fs_vfs.h
@@ -44,7 +44,13 @@ extern const struct file_operations v9fs_dir_operations;
44extern const struct dentry_operations v9fs_dentry_operations; 44extern const struct dentry_operations v9fs_dentry_operations;
45extern const struct dentry_operations v9fs_cached_dentry_operations; 45extern const struct dentry_operations v9fs_cached_dentry_operations;
46 46
47#ifdef CONFIG_9P_FSCACHE
48struct inode *v9fs_alloc_inode(struct super_block *sb);
49void v9fs_destroy_inode(struct inode *inode);
50#endif
51
47struct inode *v9fs_get_inode(struct super_block *sb, int mode); 52struct inode *v9fs_get_inode(struct super_block *sb, int mode);
53void v9fs_clear_inode(struct inode *inode);
48ino_t v9fs_qid2ino(struct p9_qid *qid); 54ino_t v9fs_qid2ino(struct p9_qid *qid);
49void v9fs_stat2inode(struct p9_wstat *, struct inode *, struct super_block *); 55void v9fs_stat2inode(struct p9_wstat *, struct inode *, struct super_block *);
50int v9fs_dir_release(struct inode *inode, struct file *filp); 56int v9fs_dir_release(struct inode *inode, struct file *filp);
diff --git a/fs/9p/vfs_addr.c b/fs/9p/vfs_addr.c
index 92828281a30b..90e38449f4b3 100644
--- a/fs/9p/vfs_addr.c
+++ b/fs/9p/vfs_addr.c
@@ -38,6 +38,7 @@
38 38
39#include "v9fs.h" 39#include "v9fs.h"
40#include "v9fs_vfs.h" 40#include "v9fs_vfs.h"
41#include "cache.h"
41 42
42/** 43/**
43 * v9fs_vfs_readpage - read an entire page in from 9P 44 * v9fs_vfs_readpage - read an entire page in from 9P
@@ -52,18 +53,31 @@ static int v9fs_vfs_readpage(struct file *filp, struct page *page)
52 int retval; 53 int retval;
53 loff_t offset; 54 loff_t offset;
54 char *buffer; 55 char *buffer;
56 struct inode *inode;
55 57
58 inode = page->mapping->host;
56 P9_DPRINTK(P9_DEBUG_VFS, "\n"); 59 P9_DPRINTK(P9_DEBUG_VFS, "\n");
60
61 BUG_ON(!PageLocked(page));
62
63 retval = v9fs_readpage_from_fscache(inode, page);
64 if (retval == 0)
65 return retval;
66
57 buffer = kmap(page); 67 buffer = kmap(page);
58 offset = page_offset(page); 68 offset = page_offset(page);
59 69
60 retval = v9fs_file_readn(filp, buffer, NULL, PAGE_CACHE_SIZE, offset); 70 retval = v9fs_file_readn(filp, buffer, NULL, PAGE_CACHE_SIZE, offset);
61 if (retval < 0) 71 if (retval < 0) {
72 v9fs_uncache_page(inode, page);
62 goto done; 73 goto done;
74 }
63 75
64 memset(buffer + retval, 0, PAGE_CACHE_SIZE - retval); 76 memset(buffer + retval, 0, PAGE_CACHE_SIZE - retval);
65 flush_dcache_page(page); 77 flush_dcache_page(page);
66 SetPageUptodate(page); 78 SetPageUptodate(page);
79
80 v9fs_readpage_to_fscache(inode, page);
67 retval = 0; 81 retval = 0;
68 82
69done: 83done:
@@ -72,6 +86,78 @@ done:
72 return retval; 86 return retval;
73} 87}
74 88
89/**
90 * v9fs_vfs_readpages - read a set of pages from 9P
91 *
92 * @filp: file being read
93 * @mapping: the address space
94 * @pages: list of pages to read
95 * @nr_pages: count of pages to read
96 *
97 */
98
99static int v9fs_vfs_readpages(struct file *filp, struct address_space *mapping,
100 struct list_head *pages, unsigned nr_pages)
101{
102 int ret = 0;
103 struct inode *inode;
104
105 inode = mapping->host;
106 P9_DPRINTK(P9_DEBUG_VFS, "inode: %p file: %p\n", inode, filp);
107
108 ret = v9fs_readpages_from_fscache(inode, mapping, pages, &nr_pages);
109 if (ret == 0)
110 return ret;
111
112 ret = read_cache_pages(mapping, pages, (void *)v9fs_vfs_readpage, filp);
113 P9_DPRINTK(P9_DEBUG_VFS, " = %d\n", ret);
114 return ret;
115}
116
117/**
118 * v9fs_release_page - release the private state associated with a page
119 *
120 * Returns 1 if the page can be released, false otherwise.
121 */
122
123static int v9fs_release_page(struct page *page, gfp_t gfp)
124{
125 if (PagePrivate(page))
126 return 0;
127
128 return v9fs_fscache_release_page(page, gfp);
129}
130
131/**
132 * v9fs_invalidate_page - Invalidate a page completely or partially
133 *
134 * @page: structure to page
135 * @offset: offset in the page
136 */
137
138static void v9fs_invalidate_page(struct page *page, unsigned long offset)
139{
140 if (offset == 0)
141 v9fs_fscache_invalidate_page(page);
142}
143
144/**
145 * v9fs_launder_page - Writeback a dirty page
146 * Since the writes go directly to the server, we simply return a 0
147 * here to indicate success.
148 *
149 * Returns 0 on success.
150 */
151
152static int v9fs_launder_page(struct page *page)
153{
154 return 0;
155}
156
75const struct address_space_operations v9fs_addr_operations = { 157const struct address_space_operations v9fs_addr_operations = {
76 .readpage = v9fs_vfs_readpage, 158 .readpage = v9fs_vfs_readpage,
159 .readpages = v9fs_vfs_readpages,
160 .releasepage = v9fs_release_page,
161 .invalidatepage = v9fs_invalidate_page,
162 .launder_page = v9fs_launder_page,
77}; 163};
diff --git a/fs/9p/vfs_file.c b/fs/9p/vfs_file.c
index cafaa46434ba..3902bf43a088 100644
--- a/fs/9p/vfs_file.c
+++ b/fs/9p/vfs_file.c
@@ -41,6 +41,7 @@
41#include "v9fs.h" 41#include "v9fs.h"
42#include "v9fs_vfs.h" 42#include "v9fs_vfs.h"
43#include "fid.h" 43#include "fid.h"
44#include "cache.h"
44 45
45static const struct file_operations v9fs_cached_file_operations; 46static const struct file_operations v9fs_cached_file_operations;
46 47
@@ -86,6 +87,10 @@ int v9fs_file_open(struct inode *inode, struct file *file)
86 /* enable cached file options */ 87 /* enable cached file options */
87 if(file->f_op == &v9fs_file_operations) 88 if(file->f_op == &v9fs_file_operations)
88 file->f_op = &v9fs_cached_file_operations; 89 file->f_op = &v9fs_cached_file_operations;
90
91#ifdef CONFIG_9P_FSCACHE
92 v9fs_cache_inode_set_cookie(inode, file);
93#endif
89 } 94 }
90 95
91 return 0; 96 return 0;
@@ -238,8 +243,9 @@ v9fs_file_write(struct file *filp, const char __user * data,
238 if (total > 0) { 243 if (total > 0) {
239 pg_start = origin >> PAGE_CACHE_SHIFT; 244 pg_start = origin >> PAGE_CACHE_SHIFT;
240 pg_end = (origin + total - 1) >> PAGE_CACHE_SHIFT; 245 pg_end = (origin + total - 1) >> PAGE_CACHE_SHIFT;
241 invalidate_inode_pages2_range(inode->i_mapping, pg_start, 246 if (inode->i_mapping && inode->i_mapping->nrpages)
242 pg_end); 247 invalidate_inode_pages2_range(inode->i_mapping,
248 pg_start, pg_end);
243 *offset += total; 249 *offset += total;
244 i_size_write(inode, i_size_read(inode) + total); 250 i_size_write(inode, i_size_read(inode) + total);
245 inode->i_blocks = (i_size_read(inode) + 512 - 1) >> 9; 251 inode->i_blocks = (i_size_read(inode) + 512 - 1) >> 9;
diff --git a/fs/9p/vfs_inode.c b/fs/9p/vfs_inode.c
index f3bfa87926bd..5947628aefef 100644
--- a/fs/9p/vfs_inode.c
+++ b/fs/9p/vfs_inode.c
@@ -40,6 +40,7 @@
40#include "v9fs.h" 40#include "v9fs.h"
41#include "v9fs_vfs.h" 41#include "v9fs_vfs.h"
42#include "fid.h" 42#include "fid.h"
43#include "cache.h"
43 44
44static const struct inode_operations v9fs_dir_inode_operations; 45static const struct inode_operations v9fs_dir_inode_operations;
45static const struct inode_operations v9fs_dir_inode_operations_ext; 46static const struct inode_operations v9fs_dir_inode_operations_ext;
@@ -197,6 +198,39 @@ v9fs_blank_wstat(struct p9_wstat *wstat)
197 wstat->extension = NULL; 198 wstat->extension = NULL;
198} 199}
199 200
201#ifdef CONFIG_9P_FSCACHE
202/**
203 * v9fs_alloc_inode - helper function to allocate an inode
204 * This callback is executed before setting up the inode so that we
205 * can associate a vcookie with each inode.
206 *
207 */
208
209struct inode *v9fs_alloc_inode(struct super_block *sb)
210{
211 struct v9fs_cookie *vcookie;
212 vcookie = (struct v9fs_cookie *)kmem_cache_alloc(vcookie_cache,
213 GFP_KERNEL);
214 if (!vcookie)
215 return NULL;
216
217 vcookie->fscache = NULL;
218 vcookie->qid = NULL;
219 spin_lock_init(&vcookie->lock);
220 return &vcookie->inode;
221}
222
223/**
224 * v9fs_destroy_inode - destroy an inode
225 *
226 */
227
228void v9fs_destroy_inode(struct inode *inode)
229{
230 kmem_cache_free(vcookie_cache, v9fs_inode2cookie(inode));
231}
232#endif
233
200/** 234/**
201 * v9fs_get_inode - helper function to setup an inode 235 * v9fs_get_inode - helper function to setup an inode
202 * @sb: superblock 236 * @sb: superblock
@@ -326,6 +360,21 @@ error:
326} 360}
327*/ 361*/
328 362
363
364/**
365 * v9fs_clear_inode - release an inode
366 * @inode: inode to release
367 *
368 */
369void v9fs_clear_inode(struct inode *inode)
370{
371 filemap_fdatawrite(inode->i_mapping);
372
373#ifdef CONFIG_9P_FSCACHE
374 v9fs_cache_inode_put_cookie(inode);
375#endif
376}
377
329/** 378/**
330 * v9fs_inode_from_fid - populate an inode by issuing a attribute request 379 * v9fs_inode_from_fid - populate an inode by issuing a attribute request
331 * @v9ses: session information 380 * @v9ses: session information
@@ -356,8 +405,14 @@ v9fs_inode_from_fid(struct v9fs_session_info *v9ses, struct p9_fid *fid,
356 405
357 v9fs_stat2inode(st, ret, sb); 406 v9fs_stat2inode(st, ret, sb);
358 ret->i_ino = v9fs_qid2ino(&st->qid); 407 ret->i_ino = v9fs_qid2ino(&st->qid);
408
409#ifdef CONFIG_9P_FSCACHE
410 v9fs_vcookie_set_qid(ret, &st->qid);
411 v9fs_cache_inode_get_cookie(ret);
412#endif
359 p9stat_free(st); 413 p9stat_free(st);
360 kfree(st); 414 kfree(st);
415
361 return ret; 416 return ret;
362 417
363error: 418error:
@@ -751,7 +806,7 @@ v9fs_vfs_getattr(struct vfsmount *mnt, struct dentry *dentry,
751 P9_DPRINTK(P9_DEBUG_VFS, "dentry: %p\n", dentry); 806 P9_DPRINTK(P9_DEBUG_VFS, "dentry: %p\n", dentry);
752 err = -EPERM; 807 err = -EPERM;
753 v9ses = v9fs_inode2v9ses(dentry->d_inode); 808 v9ses = v9fs_inode2v9ses(dentry->d_inode);
754 if (v9ses->cache == CACHE_LOOSE) 809 if (v9ses->cache == CACHE_LOOSE || v9ses->cache == CACHE_FSCACHE)
755 return simple_getattr(mnt, dentry, stat); 810 return simple_getattr(mnt, dentry, stat);
756 811
757 fid = v9fs_fid_lookup(dentry); 812 fid = v9fs_fid_lookup(dentry);
diff --git a/fs/9p/vfs_super.c b/fs/9p/vfs_super.c
index 8961f1a8f668..14a86448572c 100644
--- a/fs/9p/vfs_super.c
+++ b/fs/9p/vfs_super.c
@@ -44,21 +44,9 @@
44#include "v9fs_vfs.h" 44#include "v9fs_vfs.h"
45#include "fid.h" 45#include "fid.h"
46 46
47static void v9fs_clear_inode(struct inode *);
48static const struct super_operations v9fs_super_ops; 47static const struct super_operations v9fs_super_ops;
49 48
50/** 49/**
51 * v9fs_clear_inode - release an inode
52 * @inode: inode to release
53 *
54 */
55
56static void v9fs_clear_inode(struct inode *inode)
57{
58 filemap_fdatawrite(inode->i_mapping);
59}
60
61/**
62 * v9fs_set_super - set the superblock 50 * v9fs_set_super - set the superblock
63 * @s: super block 51 * @s: super block
64 * @data: file system specific data 52 * @data: file system specific data
@@ -220,6 +208,10 @@ v9fs_umount_begin(struct super_block *sb)
220} 208}
221 209
222static const struct super_operations v9fs_super_ops = { 210static const struct super_operations v9fs_super_ops = {
211#ifdef CONFIG_9P_FSCACHE
212 .alloc_inode = v9fs_alloc_inode,
213 .destroy_inode = v9fs_destroy_inode,
214#endif
223 .statfs = simple_statfs, 215 .statfs = simple_statfs,
224 .clear_inode = v9fs_clear_inode, 216 .clear_inode = v9fs_clear_inode,
225 .show_options = generic_show_options, 217 .show_options = generic_show_options,
diff --git a/include/net/9p/9p.h b/include/net/9p/9p.h
index b77c1478c99f..a7fb54808a23 100644
--- a/include/net/9p/9p.h
+++ b/include/net/9p/9p.h
@@ -38,6 +38,8 @@
38 * @P9_DEBUG_SLABS: memory management tracing 38 * @P9_DEBUG_SLABS: memory management tracing
39 * @P9_DEBUG_FCALL: verbose dump of protocol messages 39 * @P9_DEBUG_FCALL: verbose dump of protocol messages
40 * @P9_DEBUG_FID: fid allocation/deallocation tracking 40 * @P9_DEBUG_FID: fid allocation/deallocation tracking
41 * @P9_DEBUG_PKT: packet marshalling/unmarshalling
42 * @P9_DEBUG_FSC: FS-cache tracing
41 * 43 *
42 * These flags are passed at mount time to turn on various levels of 44 * These flags are passed at mount time to turn on various levels of
43 * verbosity and tracing which will be output to the system logs. 45 * verbosity and tracing which will be output to the system logs.
@@ -54,6 +56,7 @@ enum p9_debug_flags {
54 P9_DEBUG_FCALL = (1<<8), 56 P9_DEBUG_FCALL = (1<<8),
55 P9_DEBUG_FID = (1<<9), 57 P9_DEBUG_FID = (1<<9),
56 P9_DEBUG_PKT = (1<<10), 58 P9_DEBUG_PKT = (1<<10),
59 P9_DEBUG_FSC = (1<<11),
57}; 60};
58 61
59#ifdef CONFIG_NET_9P_DEBUG 62#ifdef CONFIG_NET_9P_DEBUG