diff options
author | Abhishek Kulkarni <adkulkar@umail.iu.edu> | 2009-09-23 14:00:27 -0400 |
---|---|---|
committer | Eric Van Hensbergen <ericvh@strongmad.austin.ibm.com> | 2009-09-23 14:03:46 -0400 |
commit | 60e78d2c993e58d890596d951fff77d5965adcd6 (patch) | |
tree | 3d53ed7254c613ef8d8de36fdceda25bc493f4f7 /fs/9p/cache.h | |
parent | 637d020a02cd734bf27acfc56c6d942cddd9eb80 (diff) |
9p: Add fscache support to 9p
This patch adds a persistent, read-only caching facility for
9p clients using the FS-Cache caching backend.
When the fscache facility is enabled, each inode is associated
with a corresponding vcookie which is an index into the FS-Cache
indexing tree. The FS-Cache indexing tree is indexed at 3 levels:
- session object associated with each mount.
- inode/vcookie
- actual data (pages)
A cache tag is chosen randomly for each session. These tags can
be read off /sys/fs/9p/caches and can be passed as a mount-time
parameter to re-attach to the specified caching session.
Signed-off-by: Abhishek Kulkarni <adkulkar@umail.iu.edu>
Signed-off-by: Eric Van Hensbergen <ericvh@gmail.com>
Diffstat (limited to 'fs/9p/cache.h')
-rw-r--r-- | fs/9p/cache.h | 176 |
1 files changed, 176 insertions, 0 deletions
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 | |||
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 */ | ||