Commit | Line | Data |
---|---|---|
2d6fff63 DH |
1 | /* General filesystem caching interface |
2 | * | |
3 | * Copyright (C) 2004-2007 Red Hat, Inc. All Rights Reserved. | |
4 | * Written by David Howells (dhowells@redhat.com) | |
5 | * | |
6 | * This program is free software; you can redistribute it and/or | |
7 | * modify it under the terms of the GNU General Public License | |
8 | * as published by the Free Software Foundation; either version | |
9 | * 2 of the License, or (at your option) any later version. | |
10 | * | |
11 | * NOTE!!! See: | |
12 | * | |
13 | * Documentation/filesystems/caching/netfs-api.txt | |
14 | * | |
15 | * for a description of the network filesystem interface declared here. | |
16 | */ | |
17 | ||
18 | #ifndef _LINUX_FSCACHE_H | |
19 | #define _LINUX_FSCACHE_H | |
20 | ||
21 | #include <linux/fs.h> | |
22 | #include <linux/list.h> | |
23 | #include <linux/pagemap.h> | |
24 | #include <linux/pagevec.h> | |
25 | ||
26 | #if defined(CONFIG_FSCACHE) || defined(CONFIG_FSCACHE_MODULE) | |
27 | #define fscache_available() (1) | |
28 | #define fscache_cookie_valid(cookie) (cookie) | |
29 | #else | |
30 | #define fscache_available() (0) | |
31 | #define fscache_cookie_valid(cookie) (0) | |
32 | #endif | |
33 | ||
34 | ||
35 | /* | |
36 | * overload PG_private_2 to give us PG_fscache - this is used to indicate that | |
37 | * a page is currently backed by a local disk cache | |
38 | */ | |
39 | #define PageFsCache(page) PagePrivate2((page)) | |
40 | #define SetPageFsCache(page) SetPagePrivate2((page)) | |
41 | #define ClearPageFsCache(page) ClearPagePrivate2((page)) | |
42 | #define TestSetPageFsCache(page) TestSetPagePrivate2((page)) | |
43 | #define TestClearPageFsCache(page) TestClearPagePrivate2((page)) | |
44 | ||
45 | /* pattern used to fill dead space in an index entry */ | |
46 | #define FSCACHE_INDEX_DEADFILL_PATTERN 0x79 | |
47 | ||
48 | struct pagevec; | |
49 | struct fscache_cache_tag; | |
50 | struct fscache_cookie; | |
51 | struct fscache_netfs; | |
52 | ||
53 | typedef void (*fscache_rw_complete_t)(struct page *page, | |
54 | void *context, | |
55 | int error); | |
56 | ||
57 | /* result of index entry consultation */ | |
58 | enum fscache_checkaux { | |
59 | FSCACHE_CHECKAUX_OKAY, /* entry okay as is */ | |
60 | FSCACHE_CHECKAUX_NEEDS_UPDATE, /* entry requires update */ | |
61 | FSCACHE_CHECKAUX_OBSOLETE, /* entry requires deletion */ | |
62 | }; | |
63 | ||
64 | /* | |
65 | * fscache cookie definition | |
66 | */ | |
67 | struct fscache_cookie_def { | |
68 | /* name of cookie type */ | |
69 | char name[16]; | |
70 | ||
71 | /* cookie type */ | |
72 | uint8_t type; | |
73 | #define FSCACHE_COOKIE_TYPE_INDEX 0 | |
74 | #define FSCACHE_COOKIE_TYPE_DATAFILE 1 | |
75 | ||
76 | /* select the cache into which to insert an entry in this index | |
77 | * - optional | |
78 | * - should return a cache identifier or NULL to cause the cache to be | |
79 | * inherited from the parent if possible or the first cache picked | |
80 | * for a non-index file if not | |
81 | */ | |
82 | struct fscache_cache_tag *(*select_cache)( | |
83 | const void *parent_netfs_data, | |
84 | const void *cookie_netfs_data); | |
85 | ||
86 | /* get an index key | |
87 | * - should store the key data in the buffer | |
88 | * - should return the amount of amount stored | |
89 | * - not permitted to return an error | |
90 | * - the netfs data from the cookie being used as the source is | |
91 | * presented | |
92 | */ | |
93 | uint16_t (*get_key)(const void *cookie_netfs_data, | |
94 | void *buffer, | |
95 | uint16_t bufmax); | |
96 | ||
97 | /* get certain file attributes from the netfs data | |
98 | * - this function can be absent for an index | |
99 | * - not permitted to return an error | |
100 | * - the netfs data from the cookie being used as the source is | |
101 | * presented | |
102 | */ | |
103 | void (*get_attr)(const void *cookie_netfs_data, uint64_t *size); | |
104 | ||
105 | /* get the auxilliary data from netfs data | |
106 | * - this function can be absent if the index carries no state data | |
107 | * - should store the auxilliary data in the buffer | |
108 | * - should return the amount of amount stored | |
109 | * - not permitted to return an error | |
110 | * - the netfs data from the cookie being used as the source is | |
111 | * presented | |
112 | */ | |
113 | uint16_t (*get_aux)(const void *cookie_netfs_data, | |
114 | void *buffer, | |
115 | uint16_t bufmax); | |
116 | ||
117 | /* consult the netfs about the state of an object | |
118 | * - this function can be absent if the index carries no state data | |
119 | * - the netfs data from the cookie being used as the target is | |
120 | * presented, as is the auxilliary data | |
121 | */ | |
122 | enum fscache_checkaux (*check_aux)(void *cookie_netfs_data, | |
123 | const void *data, | |
124 | uint16_t datalen); | |
125 | ||
126 | /* get an extra reference on a read context | |
127 | * - this function can be absent if the completion function doesn't | |
128 | * require a context | |
129 | */ | |
130 | void (*get_context)(void *cookie_netfs_data, void *context); | |
131 | ||
132 | /* release an extra reference on a read context | |
133 | * - this function can be absent if the completion function doesn't | |
134 | * require a context | |
135 | */ | |
136 | void (*put_context)(void *cookie_netfs_data, void *context); | |
137 | ||
138 | /* indicate pages that now have cache metadata retained | |
139 | * - this function should mark the specified pages as now being cached | |
140 | * - the pages will have been marked with PG_fscache before this is | |
141 | * called, so this is optional | |
142 | */ | |
143 | void (*mark_pages_cached)(void *cookie_netfs_data, | |
144 | struct address_space *mapping, | |
145 | struct pagevec *cached_pvec); | |
146 | ||
147 | /* indicate the cookie is no longer cached | |
148 | * - this function is called when the backing store currently caching | |
149 | * a cookie is removed | |
150 | * - the netfs should use this to clean up any markers indicating | |
151 | * cached pages | |
152 | * - this is mandatory for any object that may have data | |
153 | */ | |
154 | void (*now_uncached)(void *cookie_netfs_data); | |
155 | }; | |
156 | ||
157 | /* | |
158 | * fscache cached network filesystem type | |
159 | * - name, version and ops must be filled in before registration | |
160 | * - all other fields will be set during registration | |
161 | */ | |
162 | struct fscache_netfs { | |
163 | uint32_t version; /* indexing version */ | |
164 | const char *name; /* filesystem name */ | |
165 | struct fscache_cookie *primary_index; | |
166 | struct list_head link; /* internal link */ | |
167 | }; | |
168 | ||
169 | /* | |
170 | * slow-path functions for when there is actually caching available, and the | |
171 | * netfs does actually have a valid token | |
172 | * - these are not to be called directly | |
173 | * - these are undefined symbols when FS-Cache is not configured and the | |
174 | * optimiser takes care of not using them | |
175 | */ | |
0e04d4ce DH |
176 | extern struct fscache_cache_tag *__fscache_lookup_cache_tag(const char *); |
177 | extern void __fscache_release_cache_tag(struct fscache_cache_tag *); | |
2d6fff63 DH |
178 | |
179 | /** | |
180 | * fscache_register_netfs - Register a filesystem as desiring caching services | |
181 | * @netfs: The description of the filesystem | |
182 | * | |
183 | * Register a filesystem as desiring caching services if they're available. | |
184 | * | |
185 | * See Documentation/filesystems/caching/netfs-api.txt for a complete | |
186 | * description. | |
187 | */ | |
188 | static inline | |
189 | int fscache_register_netfs(struct fscache_netfs *netfs) | |
190 | { | |
191 | return 0; | |
192 | } | |
193 | ||
194 | /** | |
195 | * fscache_unregister_netfs - Indicate that a filesystem no longer desires | |
196 | * caching services | |
197 | * @netfs: The description of the filesystem | |
198 | * | |
199 | * Indicate that a filesystem no longer desires caching services for the | |
200 | * moment. | |
201 | * | |
202 | * See Documentation/filesystems/caching/netfs-api.txt for a complete | |
203 | * description. | |
204 | */ | |
205 | static inline | |
206 | void fscache_unregister_netfs(struct fscache_netfs *netfs) | |
207 | { | |
208 | } | |
209 | ||
210 | /** | |
211 | * fscache_lookup_cache_tag - Look up a cache tag | |
212 | * @name: The name of the tag to search for | |
213 | * | |
214 | * Acquire a specific cache referral tag that can be used to select a specific | |
215 | * cache in which to cache an index. | |
216 | * | |
217 | * See Documentation/filesystems/caching/netfs-api.txt for a complete | |
218 | * description. | |
219 | */ | |
220 | static inline | |
221 | struct fscache_cache_tag *fscache_lookup_cache_tag(const char *name) | |
222 | { | |
0e04d4ce DH |
223 | if (fscache_available()) |
224 | return __fscache_lookup_cache_tag(name); | |
225 | else | |
226 | return NULL; | |
2d6fff63 DH |
227 | } |
228 | ||
229 | /** | |
230 | * fscache_release_cache_tag - Release a cache tag | |
231 | * @tag: The tag to release | |
232 | * | |
233 | * Release a reference to a cache referral tag previously looked up. | |
234 | * | |
235 | * See Documentation/filesystems/caching/netfs-api.txt for a complete | |
236 | * description. | |
237 | */ | |
238 | static inline | |
239 | void fscache_release_cache_tag(struct fscache_cache_tag *tag) | |
240 | { | |
0e04d4ce DH |
241 | if (fscache_available()) |
242 | __fscache_release_cache_tag(tag); | |
2d6fff63 DH |
243 | } |
244 | ||
245 | /** | |
246 | * fscache_acquire_cookie - Acquire a cookie to represent a cache object | |
247 | * @parent: The cookie that's to be the parent of this one | |
248 | * @def: A description of the cache object, including callback operations | |
249 | * @netfs_data: An arbitrary piece of data to be kept in the cookie to | |
250 | * represent the cache object to the netfs | |
251 | * | |
252 | * This function is used to inform FS-Cache about part of an index hierarchy | |
253 | * that can be used to locate files. This is done by requesting a cookie for | |
254 | * each index in the path to the file. | |
255 | * | |
256 | * See Documentation/filesystems/caching/netfs-api.txt for a complete | |
257 | * description. | |
258 | */ | |
259 | static inline | |
260 | struct fscache_cookie *fscache_acquire_cookie( | |
261 | struct fscache_cookie *parent, | |
262 | const struct fscache_cookie_def *def, | |
263 | void *netfs_data) | |
264 | { | |
265 | return NULL; | |
266 | } | |
267 | ||
268 | /** | |
269 | * fscache_relinquish_cookie - Return the cookie to the cache, maybe discarding | |
270 | * it | |
271 | * @cookie: The cookie being returned | |
272 | * @retire: True if the cache object the cookie represents is to be discarded | |
273 | * | |
274 | * This function returns a cookie to the cache, forcibly discarding the | |
275 | * associated cache object if retire is set to true. | |
276 | * | |
277 | * See Documentation/filesystems/caching/netfs-api.txt for a complete | |
278 | * description. | |
279 | */ | |
280 | static inline | |
281 | void fscache_relinquish_cookie(struct fscache_cookie *cookie, int retire) | |
282 | { | |
283 | } | |
284 | ||
285 | /** | |
286 | * fscache_update_cookie - Request that a cache object be updated | |
287 | * @cookie: The cookie representing the cache object | |
288 | * | |
289 | * Request an update of the index data for the cache object associated with the | |
290 | * cookie. | |
291 | * | |
292 | * See Documentation/filesystems/caching/netfs-api.txt for a complete | |
293 | * description. | |
294 | */ | |
295 | static inline | |
296 | void fscache_update_cookie(struct fscache_cookie *cookie) | |
297 | { | |
298 | } | |
299 | ||
300 | /** | |
301 | * fscache_pin_cookie - Pin a data-storage cache object in its cache | |
302 | * @cookie: The cookie representing the cache object | |
303 | * | |
304 | * Permit data-storage cache objects to be pinned in the cache. | |
305 | * | |
306 | * See Documentation/filesystems/caching/netfs-api.txt for a complete | |
307 | * description. | |
308 | */ | |
309 | static inline | |
310 | int fscache_pin_cookie(struct fscache_cookie *cookie) | |
311 | { | |
312 | return -ENOBUFS; | |
313 | } | |
314 | ||
315 | /** | |
316 | * fscache_pin_cookie - Unpin a data-storage cache object in its cache | |
317 | * @cookie: The cookie representing the cache object | |
318 | * | |
319 | * Permit data-storage cache objects to be unpinned from the cache. | |
320 | * | |
321 | * See Documentation/filesystems/caching/netfs-api.txt for a complete | |
322 | * description. | |
323 | */ | |
324 | static inline | |
325 | void fscache_unpin_cookie(struct fscache_cookie *cookie) | |
326 | { | |
327 | } | |
328 | ||
329 | /** | |
330 | * fscache_attr_changed - Notify cache that an object's attributes changed | |
331 | * @cookie: The cookie representing the cache object | |
332 | * | |
333 | * Send a notification to the cache indicating that an object's attributes have | |
334 | * changed. This includes the data size. These attributes will be obtained | |
335 | * through the get_attr() cookie definition op. | |
336 | * | |
337 | * See Documentation/filesystems/caching/netfs-api.txt for a complete | |
338 | * description. | |
339 | */ | |
340 | static inline | |
341 | int fscache_attr_changed(struct fscache_cookie *cookie) | |
342 | { | |
343 | return -ENOBUFS; | |
344 | } | |
345 | ||
346 | /** | |
347 | * fscache_reserve_space - Reserve data space for a cached object | |
348 | * @cookie: The cookie representing the cache object | |
349 | * @i_size: The amount of space to be reserved | |
350 | * | |
351 | * Reserve an amount of space in the cache for the cache object attached to a | |
352 | * cookie so that a write to that object within the space can always be | |
353 | * honoured. | |
354 | * | |
355 | * See Documentation/filesystems/caching/netfs-api.txt for a complete | |
356 | * description. | |
357 | */ | |
358 | static inline | |
359 | int fscache_reserve_space(struct fscache_cookie *cookie, loff_t size) | |
360 | { | |
361 | return -ENOBUFS; | |
362 | } | |
363 | ||
364 | /** | |
365 | * fscache_read_or_alloc_page - Read a page from the cache or allocate a block | |
366 | * in which to store it | |
367 | * @cookie: The cookie representing the cache object | |
368 | * @page: The netfs page to fill if possible | |
369 | * @end_io_func: The callback to invoke when and if the page is filled | |
370 | * @context: An arbitrary piece of data to pass on to end_io_func() | |
371 | * @gfp: The conditions under which memory allocation should be made | |
372 | * | |
373 | * Read a page from the cache, or if that's not possible make a potential | |
374 | * one-block reservation in the cache into which the page may be stored once | |
375 | * fetched from the server. | |
376 | * | |
377 | * If the page is not backed by the cache object, or if it there's some reason | |
378 | * it can't be, -ENOBUFS will be returned and nothing more will be done for | |
379 | * that page. | |
380 | * | |
381 | * Else, if that page is backed by the cache, a read will be initiated directly | |
382 | * to the netfs's page and 0 will be returned by this function. The | |
383 | * end_io_func() callback will be invoked when the operation terminates on a | |
384 | * completion or failure. Note that the callback may be invoked before the | |
385 | * return. | |
386 | * | |
387 | * Else, if the page is unbacked, -ENODATA is returned and a block may have | |
388 | * been allocated in the cache. | |
389 | * | |
390 | * See Documentation/filesystems/caching/netfs-api.txt for a complete | |
391 | * description. | |
392 | */ | |
393 | static inline | |
394 | int fscache_read_or_alloc_page(struct fscache_cookie *cookie, | |
395 | struct page *page, | |
396 | fscache_rw_complete_t end_io_func, | |
397 | void *context, | |
398 | gfp_t gfp) | |
399 | { | |
400 | return -ENOBUFS; | |
401 | } | |
402 | ||
403 | /** | |
404 | * fscache_read_or_alloc_pages - Read pages from the cache and/or allocate | |
405 | * blocks in which to store them | |
406 | * @cookie: The cookie representing the cache object | |
407 | * @mapping: The netfs inode mapping to which the pages will be attached | |
408 | * @pages: A list of potential netfs pages to be filled | |
409 | * @end_io_func: The callback to invoke when and if each page is filled | |
410 | * @context: An arbitrary piece of data to pass on to end_io_func() | |
411 | * @gfp: The conditions under which memory allocation should be made | |
412 | * | |
413 | * Read a set of pages from the cache, or if that's not possible, attempt to | |
414 | * make a potential one-block reservation for each page in the cache into which | |
415 | * that page may be stored once fetched from the server. | |
416 | * | |
417 | * If some pages are not backed by the cache object, or if it there's some | |
418 | * reason they can't be, -ENOBUFS will be returned and nothing more will be | |
419 | * done for that pages. | |
420 | * | |
421 | * Else, if some of the pages are backed by the cache, a read will be initiated | |
422 | * directly to the netfs's page and 0 will be returned by this function. The | |
423 | * end_io_func() callback will be invoked when the operation terminates on a | |
424 | * completion or failure. Note that the callback may be invoked before the | |
425 | * return. | |
426 | * | |
427 | * Else, if a page is unbacked, -ENODATA is returned and a block may have | |
428 | * been allocated in the cache. | |
429 | * | |
430 | * Because the function may want to return all of -ENOBUFS, -ENODATA and 0 in | |
431 | * regard to different pages, the return values are prioritised in that order. | |
432 | * Any pages submitted for reading are removed from the pages list. | |
433 | * | |
434 | * See Documentation/filesystems/caching/netfs-api.txt for a complete | |
435 | * description. | |
436 | */ | |
437 | static inline | |
438 | int fscache_read_or_alloc_pages(struct fscache_cookie *cookie, | |
439 | struct address_space *mapping, | |
440 | struct list_head *pages, | |
441 | unsigned *nr_pages, | |
442 | fscache_rw_complete_t end_io_func, | |
443 | void *context, | |
444 | gfp_t gfp) | |
445 | { | |
446 | return -ENOBUFS; | |
447 | } | |
448 | ||
449 | /** | |
450 | * fscache_alloc_page - Allocate a block in which to store a page | |
451 | * @cookie: The cookie representing the cache object | |
452 | * @page: The netfs page to allocate a page for | |
453 | * @gfp: The conditions under which memory allocation should be made | |
454 | * | |
455 | * Request Allocation a block in the cache in which to store a netfs page | |
456 | * without retrieving any contents from the cache. | |
457 | * | |
458 | * If the page is not backed by a file then -ENOBUFS will be returned and | |
459 | * nothing more will be done, and no reservation will be made. | |
460 | * | |
461 | * Else, a block will be allocated if one wasn't already, and 0 will be | |
462 | * returned | |
463 | * | |
464 | * See Documentation/filesystems/caching/netfs-api.txt for a complete | |
465 | * description. | |
466 | */ | |
467 | static inline | |
468 | int fscache_alloc_page(struct fscache_cookie *cookie, | |
469 | struct page *page, | |
470 | gfp_t gfp) | |
471 | { | |
472 | return -ENOBUFS; | |
473 | } | |
474 | ||
475 | /** | |
476 | * fscache_write_page - Request storage of a page in the cache | |
477 | * @cookie: The cookie representing the cache object | |
478 | * @page: The netfs page to store | |
479 | * @gfp: The conditions under which memory allocation should be made | |
480 | * | |
481 | * Request the contents of the netfs page be written into the cache. This | |
482 | * request may be ignored if no cache block is currently allocated, in which | |
483 | * case it will return -ENOBUFS. | |
484 | * | |
485 | * If a cache block was already allocated, a write will be initiated and 0 will | |
486 | * be returned. The PG_fscache_write page bit is set immediately and will then | |
487 | * be cleared at the completion of the write to indicate the success or failure | |
488 | * of the operation. Note that the completion may happen before the return. | |
489 | * | |
490 | * See Documentation/filesystems/caching/netfs-api.txt for a complete | |
491 | * description. | |
492 | */ | |
493 | static inline | |
494 | int fscache_write_page(struct fscache_cookie *cookie, | |
495 | struct page *page, | |
496 | gfp_t gfp) | |
497 | { | |
498 | return -ENOBUFS; | |
499 | } | |
500 | ||
501 | /** | |
502 | * fscache_uncache_page - Indicate that caching is no longer required on a page | |
503 | * @cookie: The cookie representing the cache object | |
504 | * @page: The netfs page that was being cached. | |
505 | * | |
506 | * Tell the cache that we no longer want a page to be cached and that it should | |
507 | * remove any knowledge of the netfs page it may have. | |
508 | * | |
509 | * Note that this cannot cancel any outstanding I/O operations between this | |
510 | * page and the cache. | |
511 | * | |
512 | * See Documentation/filesystems/caching/netfs-api.txt for a complete | |
513 | * description. | |
514 | */ | |
515 | static inline | |
516 | void fscache_uncache_page(struct fscache_cookie *cookie, | |
517 | struct page *page) | |
518 | { | |
519 | } | |
520 | ||
521 | /** | |
522 | * fscache_check_page_write - Ask if a page is being writing to the cache | |
523 | * @cookie: The cookie representing the cache object | |
524 | * @page: The netfs page that is being cached. | |
525 | * | |
526 | * Ask the cache if a page is being written to the cache. | |
527 | * | |
528 | * See Documentation/filesystems/caching/netfs-api.txt for a complete | |
529 | * description. | |
530 | */ | |
531 | static inline | |
532 | bool fscache_check_page_write(struct fscache_cookie *cookie, | |
533 | struct page *page) | |
534 | { | |
535 | return false; | |
536 | } | |
537 | ||
538 | /** | |
539 | * fscache_wait_on_page_write - Wait for a page to complete writing to the cache | |
540 | * @cookie: The cookie representing the cache object | |
541 | * @page: The netfs page that is being cached. | |
542 | * | |
543 | * Ask the cache to wake us up when a page is no longer being written to the | |
544 | * cache. | |
545 | * | |
546 | * See Documentation/filesystems/caching/netfs-api.txt for a complete | |
547 | * description. | |
548 | */ | |
549 | static inline | |
550 | void fscache_wait_on_page_write(struct fscache_cookie *cookie, | |
551 | struct page *page) | |
552 | { | |
553 | } | |
554 | ||
555 | #endif /* _LINUX_FSCACHE_H */ |