blob: ec16fcdc3a679907226810d3d9e94bb07217f781 [file] [log] [blame]
Abhishek Kulkarni60e78d22009-09-23 13:00:27 -05001/*
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);
Aneesh Kumar K.V2efda792011-02-28 17:03:56 +053067extern void __v9fs_fscache_wait_on_page_write(struct inode *inode,
68 struct page *page);
Abhishek Kulkarni60e78d22009-09-23 13:00:27 -050069/**
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
Aneesh Kumar K.V2efda792011-02-28 17:03:56 +0530134static inline void v9fs_fscache_wait_on_page_write(struct inode *inode,
135 struct page *page)
136{
137 return __v9fs_fscache_wait_on_page_write(inode, page);
138}
139
Abhishek Kulkarni60e78d22009-09-23 13:00:27 -0500140#else /* CONFIG_9P_FSCACHE */
141
142static inline int v9fs_cache_register(void)
143{
144 return 1;
145}
146
147static inline void v9fs_cache_unregister(void) {}
148
149static inline int v9fs_fscache_release_page(struct page *page,
150 gfp_t gfp) {
151 return 1;
152}
153
154static inline void v9fs_fscache_invalidate_page(struct page *page) {}
155
156static inline int v9fs_readpage_from_fscache(struct inode *inode,
157 struct page *page)
158{
159 return -ENOBUFS;
160}
161
162static inline int v9fs_readpages_from_fscache(struct inode *inode,
163 struct address_space *mapping,
164 struct list_head *pages,
165 unsigned *nr_pages)
166{
167 return -ENOBUFS;
168}
169
170static inline void v9fs_readpage_to_fscache(struct inode *inode,
171 struct page *page)
172{}
173
174static inline void v9fs_uncache_page(struct inode *inode, struct page *page)
175{}
176
177static inline void v9fs_vcookie_set_qid(struct inode *inode,
178 struct p9_qid *qid)
179{}
180
Aneesh Kumar K.V2efda792011-02-28 17:03:56 +0530181static inline void v9fs_fscache_wait_on_page_write(struct inode *inode,
182 struct page *page)
183{
184 return;
185}
186
Abhishek Kulkarni60e78d22009-09-23 13:00:27 -0500187#endif /* CONFIG_9P_FSCACHE */
188#endif /* _9P_CACHE_H */