Linux 4.13.16
[linux/fpc-iii.git] / include / linux / fscache.h
blob115bb81912ccc8759a54d206487cc8936e2a90c7
1 /* General filesystem caching interface
3 * Copyright (C) 2004-2007 Red Hat, Inc. All Rights Reserved.
4 * Written by David Howells (dhowells@redhat.com)
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.
11 * NOTE!!! See:
13 * Documentation/filesystems/caching/netfs-api.txt
15 * for a description of the network filesystem interface declared here.
18 #ifndef _LINUX_FSCACHE_H
19 #define _LINUX_FSCACHE_H
21 #include <linux/fs.h>
22 #include <linux/list.h>
23 #include <linux/pagemap.h>
24 #include <linux/pagevec.h>
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
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
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))
45 /* pattern used to fill dead space in an index entry */
46 #define FSCACHE_INDEX_DEADFILL_PATTERN 0x79
48 struct pagevec;
49 struct fscache_cache_tag;
50 struct fscache_cookie;
51 struct fscache_netfs;
53 typedef void (*fscache_rw_complete_t)(struct page *page,
54 void *context,
55 int error);
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 */
65 * fscache cookie definition
67 struct fscache_cookie_def {
68 /* name of cookie type */
69 char name[16];
71 /* cookie type */
72 uint8_t type;
73 #define FSCACHE_COOKIE_TYPE_INDEX 0
74 #define FSCACHE_COOKIE_TYPE_DATAFILE 1
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
82 struct fscache_cache_tag *(*select_cache)(
83 const void *parent_netfs_data,
84 const void *cookie_netfs_data);
86 /* get an index key
87 * - should store the key data in the buffer
88 * - should return the amount of data stored
89 * - not permitted to return an error
90 * - the netfs data from the cookie being used as the source is
91 * presented
93 uint16_t (*get_key)(const void *cookie_netfs_data,
94 void *buffer,
95 uint16_t bufmax);
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
103 void (*get_attr)(const void *cookie_netfs_data, uint64_t *size);
105 /* get the auxiliary data from netfs data
106 * - this function can be absent if the index carries no state data
107 * - should store the auxiliary 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
113 uint16_t (*get_aux)(const void *cookie_netfs_data,
114 void *buffer,
115 uint16_t bufmax);
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 auxiliary data
122 enum fscache_checkaux (*check_aux)(void *cookie_netfs_data,
123 const void *data,
124 uint16_t datalen);
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
130 void (*get_context)(void *cookie_netfs_data, void *context);
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
136 void (*put_context)(void *cookie_netfs_data, void *context);
138 /* indicate page that now have cache metadata retained
139 * - this function should mark the specified page as now being cached
140 * - the page will have been marked with PG_fscache before this is
141 * called, so this is optional
143 void (*mark_page_cached)(void *cookie_netfs_data,
144 struct address_space *mapping,
145 struct page *page);
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
154 void (*now_uncached)(void *cookie_netfs_data);
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
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 */
170 * data file or index object cookie
171 * - a file will only appear in one cache
172 * - a request to cache a file may or may not be honoured, subject to
173 * constraints such as disk space
174 * - indices are created on disk just-in-time
176 struct fscache_cookie {
177 atomic_t usage; /* number of users of this cookie */
178 atomic_t n_children; /* number of children of this cookie */
179 atomic_t n_active; /* number of active users of netfs ptrs */
180 spinlock_t lock;
181 spinlock_t stores_lock; /* lock on page store tree */
182 struct hlist_head backing_objects; /* object(s) backing this file/index */
183 const struct fscache_cookie_def *def; /* definition */
184 struct fscache_cookie *parent; /* parent of this entry */
185 void *netfs_data; /* back pointer to netfs */
186 struct radix_tree_root stores; /* pages to be stored on this cookie */
187 #define FSCACHE_COOKIE_PENDING_TAG 0 /* pages tag: pending write to cache */
188 #define FSCACHE_COOKIE_STORING_TAG 1 /* pages tag: writing to cache */
190 unsigned long flags;
191 #define FSCACHE_COOKIE_LOOKING_UP 0 /* T if non-index cookie being looked up still */
192 #define FSCACHE_COOKIE_NO_DATA_YET 1 /* T if new object with no cached data yet */
193 #define FSCACHE_COOKIE_UNAVAILABLE 2 /* T if cookie is unavailable (error, etc) */
194 #define FSCACHE_COOKIE_INVALIDATING 3 /* T if cookie is being invalidated */
195 #define FSCACHE_COOKIE_RELINQUISHED 4 /* T if cookie has been relinquished */
196 #define FSCACHE_COOKIE_ENABLED 5 /* T if cookie is enabled */
197 #define FSCACHE_COOKIE_ENABLEMENT_LOCK 6 /* T if cookie is being en/disabled */
200 static inline bool fscache_cookie_enabled(struct fscache_cookie *cookie)
202 return test_bit(FSCACHE_COOKIE_ENABLED, &cookie->flags);
206 * slow-path functions for when there is actually caching available, and the
207 * netfs does actually have a valid token
208 * - these are not to be called directly
209 * - these are undefined symbols when FS-Cache is not configured and the
210 * optimiser takes care of not using them
212 extern int __fscache_register_netfs(struct fscache_netfs *);
213 extern void __fscache_unregister_netfs(struct fscache_netfs *);
214 extern struct fscache_cache_tag *__fscache_lookup_cache_tag(const char *);
215 extern void __fscache_release_cache_tag(struct fscache_cache_tag *);
217 extern struct fscache_cookie *__fscache_acquire_cookie(
218 struct fscache_cookie *,
219 const struct fscache_cookie_def *,
220 void *, bool);
221 extern void __fscache_relinquish_cookie(struct fscache_cookie *, bool);
222 extern int __fscache_check_consistency(struct fscache_cookie *);
223 extern void __fscache_update_cookie(struct fscache_cookie *);
224 extern int __fscache_attr_changed(struct fscache_cookie *);
225 extern void __fscache_invalidate(struct fscache_cookie *);
226 extern void __fscache_wait_on_invalidate(struct fscache_cookie *);
227 extern int __fscache_read_or_alloc_page(struct fscache_cookie *,
228 struct page *,
229 fscache_rw_complete_t,
230 void *,
231 gfp_t);
232 extern int __fscache_read_or_alloc_pages(struct fscache_cookie *,
233 struct address_space *,
234 struct list_head *,
235 unsigned *,
236 fscache_rw_complete_t,
237 void *,
238 gfp_t);
239 extern int __fscache_alloc_page(struct fscache_cookie *, struct page *, gfp_t);
240 extern int __fscache_write_page(struct fscache_cookie *, struct page *, gfp_t);
241 extern void __fscache_uncache_page(struct fscache_cookie *, struct page *);
242 extern bool __fscache_check_page_write(struct fscache_cookie *, struct page *);
243 extern void __fscache_wait_on_page_write(struct fscache_cookie *, struct page *);
244 extern bool __fscache_maybe_release_page(struct fscache_cookie *, struct page *,
245 gfp_t);
246 extern void __fscache_uncache_all_inode_pages(struct fscache_cookie *,
247 struct inode *);
248 extern void __fscache_readpages_cancel(struct fscache_cookie *cookie,
249 struct list_head *pages);
250 extern void __fscache_disable_cookie(struct fscache_cookie *, bool);
251 extern void __fscache_enable_cookie(struct fscache_cookie *,
252 bool (*)(void *), void *);
255 * fscache_register_netfs - Register a filesystem as desiring caching services
256 * @netfs: The description of the filesystem
258 * Register a filesystem as desiring caching services if they're available.
260 * See Documentation/filesystems/caching/netfs-api.txt for a complete
261 * description.
263 static inline
264 int fscache_register_netfs(struct fscache_netfs *netfs)
266 if (fscache_available())
267 return __fscache_register_netfs(netfs);
268 else
269 return 0;
273 * fscache_unregister_netfs - Indicate that a filesystem no longer desires
274 * caching services
275 * @netfs: The description of the filesystem
277 * Indicate that a filesystem no longer desires caching services for the
278 * moment.
280 * See Documentation/filesystems/caching/netfs-api.txt for a complete
281 * description.
283 static inline
284 void fscache_unregister_netfs(struct fscache_netfs *netfs)
286 if (fscache_available())
287 __fscache_unregister_netfs(netfs);
291 * fscache_lookup_cache_tag - Look up a cache tag
292 * @name: The name of the tag to search for
294 * Acquire a specific cache referral tag that can be used to select a specific
295 * cache in which to cache an index.
297 * See Documentation/filesystems/caching/netfs-api.txt for a complete
298 * description.
300 static inline
301 struct fscache_cache_tag *fscache_lookup_cache_tag(const char *name)
303 if (fscache_available())
304 return __fscache_lookup_cache_tag(name);
305 else
306 return NULL;
310 * fscache_release_cache_tag - Release a cache tag
311 * @tag: The tag to release
313 * Release a reference to a cache referral tag previously looked up.
315 * See Documentation/filesystems/caching/netfs-api.txt for a complete
316 * description.
318 static inline
319 void fscache_release_cache_tag(struct fscache_cache_tag *tag)
321 if (fscache_available())
322 __fscache_release_cache_tag(tag);
326 * fscache_acquire_cookie - Acquire a cookie to represent a cache object
327 * @parent: The cookie that's to be the parent of this one
328 * @def: A description of the cache object, including callback operations
329 * @netfs_data: An arbitrary piece of data to be kept in the cookie to
330 * represent the cache object to the netfs
331 * @enable: Whether or not to enable a data cookie immediately
333 * This function is used to inform FS-Cache about part of an index hierarchy
334 * that can be used to locate files. This is done by requesting a cookie for
335 * each index in the path to the file.
337 * See Documentation/filesystems/caching/netfs-api.txt for a complete
338 * description.
340 static inline
341 struct fscache_cookie *fscache_acquire_cookie(
342 struct fscache_cookie *parent,
343 const struct fscache_cookie_def *def,
344 void *netfs_data,
345 bool enable)
347 if (fscache_cookie_valid(parent) && fscache_cookie_enabled(parent))
348 return __fscache_acquire_cookie(parent, def, netfs_data,
349 enable);
350 else
351 return NULL;
355 * fscache_relinquish_cookie - Return the cookie to the cache, maybe discarding
356 * it
357 * @cookie: The cookie being returned
358 * @retire: True if the cache object the cookie represents is to be discarded
360 * This function returns a cookie to the cache, forcibly discarding the
361 * associated cache object if retire is set to true.
363 * See Documentation/filesystems/caching/netfs-api.txt for a complete
364 * description.
366 static inline
367 void fscache_relinquish_cookie(struct fscache_cookie *cookie, bool retire)
369 if (fscache_cookie_valid(cookie))
370 __fscache_relinquish_cookie(cookie, retire);
374 * fscache_check_consistency - Request that if the cache is updated
375 * @cookie: The cookie representing the cache object
377 * Request an consistency check from fscache, which passes the request
378 * to the backing cache.
380 * Returns 0 if consistent and -ESTALE if inconsistent. May also
381 * return -ENOMEM and -ERESTARTSYS.
383 static inline
384 int fscache_check_consistency(struct fscache_cookie *cookie)
386 if (fscache_cookie_valid(cookie) && fscache_cookie_enabled(cookie))
387 return __fscache_check_consistency(cookie);
388 else
389 return 0;
393 * fscache_update_cookie - Request that a cache object be updated
394 * @cookie: The cookie representing the cache object
396 * Request an update of the index data for the cache object associated with the
397 * cookie.
399 * See Documentation/filesystems/caching/netfs-api.txt for a complete
400 * description.
402 static inline
403 void fscache_update_cookie(struct fscache_cookie *cookie)
405 if (fscache_cookie_valid(cookie) && fscache_cookie_enabled(cookie))
406 __fscache_update_cookie(cookie);
410 * fscache_pin_cookie - Pin a data-storage cache object in its cache
411 * @cookie: The cookie representing the cache object
413 * Permit data-storage cache objects to be pinned in the cache.
415 * See Documentation/filesystems/caching/netfs-api.txt for a complete
416 * description.
418 static inline
419 int fscache_pin_cookie(struct fscache_cookie *cookie)
421 return -ENOBUFS;
425 * fscache_pin_cookie - Unpin a data-storage cache object in its cache
426 * @cookie: The cookie representing the cache object
428 * Permit data-storage cache objects to be unpinned from the cache.
430 * See Documentation/filesystems/caching/netfs-api.txt for a complete
431 * description.
433 static inline
434 void fscache_unpin_cookie(struct fscache_cookie *cookie)
439 * fscache_attr_changed - Notify cache that an object's attributes changed
440 * @cookie: The cookie representing the cache object
442 * Send a notification to the cache indicating that an object's attributes have
443 * changed. This includes the data size. These attributes will be obtained
444 * through the get_attr() cookie definition op.
446 * See Documentation/filesystems/caching/netfs-api.txt for a complete
447 * description.
449 static inline
450 int fscache_attr_changed(struct fscache_cookie *cookie)
452 if (fscache_cookie_valid(cookie) && fscache_cookie_enabled(cookie))
453 return __fscache_attr_changed(cookie);
454 else
455 return -ENOBUFS;
459 * fscache_invalidate - Notify cache that an object needs invalidation
460 * @cookie: The cookie representing the cache object
462 * Notify the cache that an object is needs to be invalidated and that it
463 * should abort any retrievals or stores it is doing on the cache. The object
464 * is then marked non-caching until such time as the invalidation is complete.
466 * This can be called with spinlocks held.
468 * See Documentation/filesystems/caching/netfs-api.txt for a complete
469 * description.
471 static inline
472 void fscache_invalidate(struct fscache_cookie *cookie)
474 if (fscache_cookie_valid(cookie) && fscache_cookie_enabled(cookie))
475 __fscache_invalidate(cookie);
479 * fscache_wait_on_invalidate - Wait for invalidation to complete
480 * @cookie: The cookie representing the cache object
482 * Wait for the invalidation of an object to complete.
484 * See Documentation/filesystems/caching/netfs-api.txt for a complete
485 * description.
487 static inline
488 void fscache_wait_on_invalidate(struct fscache_cookie *cookie)
490 if (fscache_cookie_valid(cookie))
491 __fscache_wait_on_invalidate(cookie);
495 * fscache_reserve_space - Reserve data space for a cached object
496 * @cookie: The cookie representing the cache object
497 * @i_size: The amount of space to be reserved
499 * Reserve an amount of space in the cache for the cache object attached to a
500 * cookie so that a write to that object within the space can always be
501 * honoured.
503 * See Documentation/filesystems/caching/netfs-api.txt for a complete
504 * description.
506 static inline
507 int fscache_reserve_space(struct fscache_cookie *cookie, loff_t size)
509 return -ENOBUFS;
513 * fscache_read_or_alloc_page - Read a page from the cache or allocate a block
514 * in which to store it
515 * @cookie: The cookie representing the cache object
516 * @page: The netfs page to fill if possible
517 * @end_io_func: The callback to invoke when and if the page is filled
518 * @context: An arbitrary piece of data to pass on to end_io_func()
519 * @gfp: The conditions under which memory allocation should be made
521 * Read a page from the cache, or if that's not possible make a potential
522 * one-block reservation in the cache into which the page may be stored once
523 * fetched from the server.
525 * If the page is not backed by the cache object, or if it there's some reason
526 * it can't be, -ENOBUFS will be returned and nothing more will be done for
527 * that page.
529 * Else, if that page is backed by the cache, a read will be initiated directly
530 * to the netfs's page and 0 will be returned by this function. The
531 * end_io_func() callback will be invoked when the operation terminates on a
532 * completion or failure. Note that the callback may be invoked before the
533 * return.
535 * Else, if the page is unbacked, -ENODATA is returned and a block may have
536 * been allocated in the cache.
538 * See Documentation/filesystems/caching/netfs-api.txt for a complete
539 * description.
541 static inline
542 int fscache_read_or_alloc_page(struct fscache_cookie *cookie,
543 struct page *page,
544 fscache_rw_complete_t end_io_func,
545 void *context,
546 gfp_t gfp)
548 if (fscache_cookie_valid(cookie) && fscache_cookie_enabled(cookie))
549 return __fscache_read_or_alloc_page(cookie, page, end_io_func,
550 context, gfp);
551 else
552 return -ENOBUFS;
556 * fscache_read_or_alloc_pages - Read pages from the cache and/or allocate
557 * blocks in which to store them
558 * @cookie: The cookie representing the cache object
559 * @mapping: The netfs inode mapping to which the pages will be attached
560 * @pages: A list of potential netfs pages to be filled
561 * @nr_pages: Number of pages to be read and/or allocated
562 * @end_io_func: The callback to invoke when and if each page is filled
563 * @context: An arbitrary piece of data to pass on to end_io_func()
564 * @gfp: The conditions under which memory allocation should be made
566 * Read a set of pages from the cache, or if that's not possible, attempt to
567 * make a potential one-block reservation for each page in the cache into which
568 * that page may be stored once fetched from the server.
570 * If some pages are not backed by the cache object, or if it there's some
571 * reason they can't be, -ENOBUFS will be returned and nothing more will be
572 * done for that pages.
574 * Else, if some of the pages are backed by the cache, a read will be initiated
575 * directly to the netfs's page and 0 will be returned by this function. The
576 * end_io_func() callback will be invoked when the operation terminates on a
577 * completion or failure. Note that the callback may be invoked before the
578 * return.
580 * Else, if a page is unbacked, -ENODATA is returned and a block may have
581 * been allocated in the cache.
583 * Because the function may want to return all of -ENOBUFS, -ENODATA and 0 in
584 * regard to different pages, the return values are prioritised in that order.
585 * Any pages submitted for reading are removed from the pages list.
587 * See Documentation/filesystems/caching/netfs-api.txt for a complete
588 * description.
590 static inline
591 int fscache_read_or_alloc_pages(struct fscache_cookie *cookie,
592 struct address_space *mapping,
593 struct list_head *pages,
594 unsigned *nr_pages,
595 fscache_rw_complete_t end_io_func,
596 void *context,
597 gfp_t gfp)
599 if (fscache_cookie_valid(cookie) && fscache_cookie_enabled(cookie))
600 return __fscache_read_or_alloc_pages(cookie, mapping, pages,
601 nr_pages, end_io_func,
602 context, gfp);
603 else
604 return -ENOBUFS;
608 * fscache_alloc_page - Allocate a block in which to store a page
609 * @cookie: The cookie representing the cache object
610 * @page: The netfs page to allocate a page for
611 * @gfp: The conditions under which memory allocation should be made
613 * Request Allocation a block in the cache in which to store a netfs page
614 * without retrieving any contents from the cache.
616 * If the page is not backed by a file then -ENOBUFS will be returned and
617 * nothing more will be done, and no reservation will be made.
619 * Else, a block will be allocated if one wasn't already, and 0 will be
620 * returned
622 * See Documentation/filesystems/caching/netfs-api.txt for a complete
623 * description.
625 static inline
626 int fscache_alloc_page(struct fscache_cookie *cookie,
627 struct page *page,
628 gfp_t gfp)
630 if (fscache_cookie_valid(cookie) && fscache_cookie_enabled(cookie))
631 return __fscache_alloc_page(cookie, page, gfp);
632 else
633 return -ENOBUFS;
637 * fscache_readpages_cancel - Cancel read/alloc on pages
638 * @cookie: The cookie representing the inode's cache object.
639 * @pages: The netfs pages that we canceled write on in readpages()
641 * Uncache/unreserve the pages reserved earlier in readpages() via
642 * fscache_readpages_or_alloc() and similar. In most successful caches in
643 * readpages() this doesn't do anything. In cases when the underlying netfs's
644 * readahead failed we need to clean up the pagelist (unmark and uncache).
646 * This function may sleep as it may have to clean up disk state.
648 static inline
649 void fscache_readpages_cancel(struct fscache_cookie *cookie,
650 struct list_head *pages)
652 if (fscache_cookie_valid(cookie))
653 __fscache_readpages_cancel(cookie, pages);
657 * fscache_write_page - Request storage of a page in the cache
658 * @cookie: The cookie representing the cache object
659 * @page: The netfs page to store
660 * @gfp: The conditions under which memory allocation should be made
662 * Request the contents of the netfs page be written into the cache. This
663 * request may be ignored if no cache block is currently allocated, in which
664 * case it will return -ENOBUFS.
666 * If a cache block was already allocated, a write will be initiated and 0 will
667 * be returned. The PG_fscache_write page bit is set immediately and will then
668 * be cleared at the completion of the write to indicate the success or failure
669 * of the operation. Note that the completion may happen before the return.
671 * See Documentation/filesystems/caching/netfs-api.txt for a complete
672 * description.
674 static inline
675 int fscache_write_page(struct fscache_cookie *cookie,
676 struct page *page,
677 gfp_t gfp)
679 if (fscache_cookie_valid(cookie) && fscache_cookie_enabled(cookie))
680 return __fscache_write_page(cookie, page, gfp);
681 else
682 return -ENOBUFS;
686 * fscache_uncache_page - Indicate that caching is no longer required on a page
687 * @cookie: The cookie representing the cache object
688 * @page: The netfs page that was being cached.
690 * Tell the cache that we no longer want a page to be cached and that it should
691 * remove any knowledge of the netfs page it may have.
693 * Note that this cannot cancel any outstanding I/O operations between this
694 * page and the cache.
696 * See Documentation/filesystems/caching/netfs-api.txt for a complete
697 * description.
699 static inline
700 void fscache_uncache_page(struct fscache_cookie *cookie,
701 struct page *page)
703 if (fscache_cookie_valid(cookie))
704 __fscache_uncache_page(cookie, page);
708 * fscache_check_page_write - Ask if a page is being writing to the cache
709 * @cookie: The cookie representing the cache object
710 * @page: The netfs page that is being cached.
712 * Ask the cache if a page is being written to the cache.
714 * See Documentation/filesystems/caching/netfs-api.txt for a complete
715 * description.
717 static inline
718 bool fscache_check_page_write(struct fscache_cookie *cookie,
719 struct page *page)
721 if (fscache_cookie_valid(cookie))
722 return __fscache_check_page_write(cookie, page);
723 return false;
727 * fscache_wait_on_page_write - Wait for a page to complete writing to the cache
728 * @cookie: The cookie representing the cache object
729 * @page: The netfs page that is being cached.
731 * Ask the cache to wake us up when a page is no longer being written to the
732 * cache.
734 * See Documentation/filesystems/caching/netfs-api.txt for a complete
735 * description.
737 static inline
738 void fscache_wait_on_page_write(struct fscache_cookie *cookie,
739 struct page *page)
741 if (fscache_cookie_valid(cookie))
742 __fscache_wait_on_page_write(cookie, page);
746 * fscache_maybe_release_page - Consider releasing a page, cancelling a store
747 * @cookie: The cookie representing the cache object
748 * @page: The netfs page that is being cached.
749 * @gfp: The gfp flags passed to releasepage()
751 * Consider releasing a page for the vmscan algorithm, on behalf of the netfs's
752 * releasepage() call. A storage request on the page may cancelled if it is
753 * not currently being processed.
755 * The function returns true if the page no longer has a storage request on it,
756 * and false if a storage request is left in place. If true is returned, the
757 * page will have been passed to fscache_uncache_page(). If false is returned
758 * the page cannot be freed yet.
760 static inline
761 bool fscache_maybe_release_page(struct fscache_cookie *cookie,
762 struct page *page,
763 gfp_t gfp)
765 if (fscache_cookie_valid(cookie) && PageFsCache(page))
766 return __fscache_maybe_release_page(cookie, page, gfp);
767 return false;
771 * fscache_uncache_all_inode_pages - Uncache all an inode's pages
772 * @cookie: The cookie representing the inode's cache object.
773 * @inode: The inode to uncache pages from.
775 * Uncache all the pages in an inode that are marked PG_fscache, assuming them
776 * to be associated with the given cookie.
778 * This function may sleep. It will wait for pages that are being written out
779 * and will wait whilst the PG_fscache mark is removed by the cache.
781 static inline
782 void fscache_uncache_all_inode_pages(struct fscache_cookie *cookie,
783 struct inode *inode)
785 if (fscache_cookie_valid(cookie))
786 __fscache_uncache_all_inode_pages(cookie, inode);
790 * fscache_disable_cookie - Disable a cookie
791 * @cookie: The cookie representing the cache object
792 * @invalidate: Invalidate the backing object
794 * Disable a cookie from accepting further alloc, read, write, invalidate,
795 * update or acquire operations. Outstanding operations can still be waited
796 * upon and pages can still be uncached and the cookie relinquished.
798 * This will not return until all outstanding operations have completed.
800 * If @invalidate is set, then the backing object will be invalidated and
801 * detached, otherwise it will just be detached.
803 static inline
804 void fscache_disable_cookie(struct fscache_cookie *cookie, bool invalidate)
806 if (fscache_cookie_valid(cookie) && fscache_cookie_enabled(cookie))
807 __fscache_disable_cookie(cookie, invalidate);
811 * fscache_enable_cookie - Reenable a cookie
812 * @cookie: The cookie representing the cache object
813 * @can_enable: A function to permit enablement once lock is held
814 * @data: Data for can_enable()
816 * Reenable a previously disabled cookie, allowing it to accept further alloc,
817 * read, write, invalidate, update or acquire operations. An attempt will be
818 * made to immediately reattach the cookie to a backing object.
820 * The can_enable() function is called (if not NULL) once the enablement lock
821 * is held to rule on whether enablement is still permitted to go ahead.
823 static inline
824 void fscache_enable_cookie(struct fscache_cookie *cookie,
825 bool (*can_enable)(void *data),
826 void *data)
828 if (fscache_cookie_valid(cookie) && !fscache_cookie_enabled(cookie))
829 __fscache_enable_cookie(cookie, can_enable, data);
832 #endif /* _LINUX_FSCACHE_H */