David Howells | 2d6fff6 | 2009-04-03 16:42:36 +0100 | [diff] [blame] | 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 |
Suresh Jayaraman | ab0cfb9 | 2010-07-06 18:12:39 +0530 | [diff] [blame] | 88 | * - should return the amount of data stored |
David Howells | 2d6fff6 | 2009-04-03 16:42:36 +0100 | [diff] [blame] | 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 | |
Lucas De Marchi | 25985ed | 2011-03-30 22:57:33 -0300 | [diff] [blame] | 105 | /* get the auxiliary data from netfs data |
David Howells | 2d6fff6 | 2009-04-03 16:42:36 +0100 | [diff] [blame] | 106 | * - this function can be absent if the index carries no state data |
Lucas De Marchi | 25985ed | 2011-03-30 22:57:33 -0300 | [diff] [blame] | 107 | * - should store the auxiliary data in the buffer |
David Howells | 2d6fff6 | 2009-04-03 16:42:36 +0100 | [diff] [blame] | 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 |
Lucas De Marchi | 25985ed | 2011-03-30 22:57:33 -0300 | [diff] [blame] | 120 | * presented, as is the auxiliary data |
David Howells | 2d6fff6 | 2009-04-03 16:42:36 +0100 | [diff] [blame] | 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 | |
David Howells | c4d6d8d | 2012-12-20 21:52:32 +0000 | [diff] [blame] | 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 |
David Howells | 2d6fff6 | 2009-04-03 16:42:36 +0100 | [diff] [blame] | 141 | * called, so this is optional |
| 142 | */ |
David Howells | c4d6d8d | 2012-12-20 21:52:32 +0000 | [diff] [blame] | 143 | void (*mark_page_cached)(void *cookie_netfs_data, |
| 144 | struct address_space *mapping, |
| 145 | struct page *page); |
David Howells | 2d6fff6 | 2009-04-03 16:42:36 +0100 | [diff] [blame] | 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 | */ |
David Howells | 726dd7f | 2009-04-03 16:42:38 +0100 | [diff] [blame] | 176 | extern int __fscache_register_netfs(struct fscache_netfs *); |
| 177 | extern void __fscache_unregister_netfs(struct fscache_netfs *); |
David Howells | 0e04d4c | 2009-04-03 16:42:37 +0100 | [diff] [blame] | 178 | extern struct fscache_cache_tag *__fscache_lookup_cache_tag(const char *); |
| 179 | extern void __fscache_release_cache_tag(struct fscache_cache_tag *); |
David Howells | 2d6fff6 | 2009-04-03 16:42:36 +0100 | [diff] [blame] | 180 | |
David Howells | ccc4fc3 | 2009-04-03 16:42:38 +0100 | [diff] [blame] | 181 | extern struct fscache_cookie *__fscache_acquire_cookie( |
| 182 | struct fscache_cookie *, |
| 183 | const struct fscache_cookie_def *, |
| 184 | void *); |
| 185 | extern void __fscache_relinquish_cookie(struct fscache_cookie *, int); |
David Howells | da9803b | 2013-08-21 17:29:38 -0400 | [diff] [blame^] | 186 | extern int __fscache_check_consistency(struct fscache_cookie *); |
David Howells | ccc4fc3 | 2009-04-03 16:42:38 +0100 | [diff] [blame] | 187 | extern void __fscache_update_cookie(struct fscache_cookie *); |
David Howells | b510882 | 2009-04-03 16:42:39 +0100 | [diff] [blame] | 188 | extern int __fscache_attr_changed(struct fscache_cookie *); |
David Howells | ef778e7 | 2012-12-20 21:52:36 +0000 | [diff] [blame] | 189 | extern void __fscache_invalidate(struct fscache_cookie *); |
| 190 | extern void __fscache_wait_on_invalidate(struct fscache_cookie *); |
David Howells | b510882 | 2009-04-03 16:42:39 +0100 | [diff] [blame] | 191 | extern int __fscache_read_or_alloc_page(struct fscache_cookie *, |
| 192 | struct page *, |
| 193 | fscache_rw_complete_t, |
| 194 | void *, |
| 195 | gfp_t); |
| 196 | extern int __fscache_read_or_alloc_pages(struct fscache_cookie *, |
| 197 | struct address_space *, |
| 198 | struct list_head *, |
| 199 | unsigned *, |
| 200 | fscache_rw_complete_t, |
| 201 | void *, |
| 202 | gfp_t); |
| 203 | extern int __fscache_alloc_page(struct fscache_cookie *, struct page *, gfp_t); |
| 204 | extern int __fscache_write_page(struct fscache_cookie *, struct page *, gfp_t); |
| 205 | extern void __fscache_uncache_page(struct fscache_cookie *, struct page *); |
| 206 | extern bool __fscache_check_page_write(struct fscache_cookie *, struct page *); |
| 207 | extern void __fscache_wait_on_page_write(struct fscache_cookie *, struct page *); |
David Howells | 201a154 | 2009-11-19 18:11:35 +0000 | [diff] [blame] | 208 | extern bool __fscache_maybe_release_page(struct fscache_cookie *, struct page *, |
| 209 | gfp_t); |
David Howells | c902ce1 | 2011-07-07 12:19:48 +0100 | [diff] [blame] | 210 | extern void __fscache_uncache_all_inode_pages(struct fscache_cookie *, |
| 211 | struct inode *); |
David Howells | ccc4fc3 | 2009-04-03 16:42:38 +0100 | [diff] [blame] | 212 | |
David Howells | 2d6fff6 | 2009-04-03 16:42:36 +0100 | [diff] [blame] | 213 | /** |
| 214 | * fscache_register_netfs - Register a filesystem as desiring caching services |
| 215 | * @netfs: The description of the filesystem |
| 216 | * |
| 217 | * Register a filesystem as desiring caching services if they're available. |
| 218 | * |
| 219 | * See Documentation/filesystems/caching/netfs-api.txt for a complete |
| 220 | * description. |
| 221 | */ |
| 222 | static inline |
| 223 | int fscache_register_netfs(struct fscache_netfs *netfs) |
| 224 | { |
David Howells | 726dd7f | 2009-04-03 16:42:38 +0100 | [diff] [blame] | 225 | if (fscache_available()) |
| 226 | return __fscache_register_netfs(netfs); |
| 227 | else |
| 228 | return 0; |
David Howells | 2d6fff6 | 2009-04-03 16:42:36 +0100 | [diff] [blame] | 229 | } |
| 230 | |
| 231 | /** |
| 232 | * fscache_unregister_netfs - Indicate that a filesystem no longer desires |
| 233 | * caching services |
| 234 | * @netfs: The description of the filesystem |
| 235 | * |
| 236 | * Indicate that a filesystem no longer desires caching services for the |
| 237 | * moment. |
| 238 | * |
| 239 | * See Documentation/filesystems/caching/netfs-api.txt for a complete |
| 240 | * description. |
| 241 | */ |
| 242 | static inline |
| 243 | void fscache_unregister_netfs(struct fscache_netfs *netfs) |
| 244 | { |
David Howells | 726dd7f | 2009-04-03 16:42:38 +0100 | [diff] [blame] | 245 | if (fscache_available()) |
| 246 | __fscache_unregister_netfs(netfs); |
David Howells | 2d6fff6 | 2009-04-03 16:42:36 +0100 | [diff] [blame] | 247 | } |
| 248 | |
| 249 | /** |
| 250 | * fscache_lookup_cache_tag - Look up a cache tag |
| 251 | * @name: The name of the tag to search for |
| 252 | * |
| 253 | * Acquire a specific cache referral tag that can be used to select a specific |
| 254 | * cache in which to cache an index. |
| 255 | * |
| 256 | * See Documentation/filesystems/caching/netfs-api.txt for a complete |
| 257 | * description. |
| 258 | */ |
| 259 | static inline |
| 260 | struct fscache_cache_tag *fscache_lookup_cache_tag(const char *name) |
| 261 | { |
David Howells | 0e04d4c | 2009-04-03 16:42:37 +0100 | [diff] [blame] | 262 | if (fscache_available()) |
| 263 | return __fscache_lookup_cache_tag(name); |
| 264 | else |
| 265 | return NULL; |
David Howells | 2d6fff6 | 2009-04-03 16:42:36 +0100 | [diff] [blame] | 266 | } |
| 267 | |
| 268 | /** |
| 269 | * fscache_release_cache_tag - Release a cache tag |
| 270 | * @tag: The tag to release |
| 271 | * |
| 272 | * Release a reference to a cache referral tag previously looked up. |
| 273 | * |
| 274 | * See Documentation/filesystems/caching/netfs-api.txt for a complete |
| 275 | * description. |
| 276 | */ |
| 277 | static inline |
| 278 | void fscache_release_cache_tag(struct fscache_cache_tag *tag) |
| 279 | { |
David Howells | 0e04d4c | 2009-04-03 16:42:37 +0100 | [diff] [blame] | 280 | if (fscache_available()) |
| 281 | __fscache_release_cache_tag(tag); |
David Howells | 2d6fff6 | 2009-04-03 16:42:36 +0100 | [diff] [blame] | 282 | } |
| 283 | |
| 284 | /** |
| 285 | * fscache_acquire_cookie - Acquire a cookie to represent a cache object |
| 286 | * @parent: The cookie that's to be the parent of this one |
| 287 | * @def: A description of the cache object, including callback operations |
| 288 | * @netfs_data: An arbitrary piece of data to be kept in the cookie to |
| 289 | * represent the cache object to the netfs |
| 290 | * |
| 291 | * This function is used to inform FS-Cache about part of an index hierarchy |
| 292 | * that can be used to locate files. This is done by requesting a cookie for |
| 293 | * each index in the path to the file. |
| 294 | * |
| 295 | * See Documentation/filesystems/caching/netfs-api.txt for a complete |
| 296 | * description. |
| 297 | */ |
| 298 | static inline |
| 299 | struct fscache_cookie *fscache_acquire_cookie( |
| 300 | struct fscache_cookie *parent, |
| 301 | const struct fscache_cookie_def *def, |
| 302 | void *netfs_data) |
| 303 | { |
David Howells | ccc4fc3 | 2009-04-03 16:42:38 +0100 | [diff] [blame] | 304 | if (fscache_cookie_valid(parent)) |
| 305 | return __fscache_acquire_cookie(parent, def, netfs_data); |
| 306 | else |
| 307 | return NULL; |
David Howells | 2d6fff6 | 2009-04-03 16:42:36 +0100 | [diff] [blame] | 308 | } |
| 309 | |
| 310 | /** |
| 311 | * fscache_relinquish_cookie - Return the cookie to the cache, maybe discarding |
| 312 | * it |
| 313 | * @cookie: The cookie being returned |
| 314 | * @retire: True if the cache object the cookie represents is to be discarded |
| 315 | * |
| 316 | * This function returns a cookie to the cache, forcibly discarding the |
| 317 | * associated cache object if retire is set to true. |
| 318 | * |
| 319 | * See Documentation/filesystems/caching/netfs-api.txt for a complete |
| 320 | * description. |
| 321 | */ |
| 322 | static inline |
| 323 | void fscache_relinquish_cookie(struct fscache_cookie *cookie, int retire) |
| 324 | { |
David Howells | ccc4fc3 | 2009-04-03 16:42:38 +0100 | [diff] [blame] | 325 | if (fscache_cookie_valid(cookie)) |
| 326 | __fscache_relinquish_cookie(cookie, retire); |
David Howells | 2d6fff6 | 2009-04-03 16:42:36 +0100 | [diff] [blame] | 327 | } |
| 328 | |
| 329 | /** |
David Howells | da9803b | 2013-08-21 17:29:38 -0400 | [diff] [blame^] | 330 | * fscache_check_consistency - Request that if the cache is updated |
| 331 | * @cookie: The cookie representing the cache object |
| 332 | * |
| 333 | * Request an consistency check from fscache, which passes the request |
| 334 | * to the backing cache. |
| 335 | * |
| 336 | * Returns 0 if consistent and -ESTALE if inconsistent. May also |
| 337 | * return -ENOMEM and -ERESTARTSYS. |
| 338 | */ |
| 339 | static inline |
| 340 | int fscache_check_consistency(struct fscache_cookie *cookie) |
| 341 | { |
| 342 | if (fscache_cookie_valid(cookie)) |
| 343 | return __fscache_check_consistency(cookie); |
| 344 | else |
| 345 | return 0; |
| 346 | } |
| 347 | |
| 348 | /** |
David Howells | 2d6fff6 | 2009-04-03 16:42:36 +0100 | [diff] [blame] | 349 | * fscache_update_cookie - Request that a cache object be updated |
| 350 | * @cookie: The cookie representing the cache object |
| 351 | * |
| 352 | * Request an update of the index data for the cache object associated with the |
| 353 | * cookie. |
| 354 | * |
| 355 | * See Documentation/filesystems/caching/netfs-api.txt for a complete |
| 356 | * description. |
| 357 | */ |
| 358 | static inline |
| 359 | void fscache_update_cookie(struct fscache_cookie *cookie) |
| 360 | { |
David Howells | ccc4fc3 | 2009-04-03 16:42:38 +0100 | [diff] [blame] | 361 | if (fscache_cookie_valid(cookie)) |
| 362 | __fscache_update_cookie(cookie); |
David Howells | 2d6fff6 | 2009-04-03 16:42:36 +0100 | [diff] [blame] | 363 | } |
| 364 | |
| 365 | /** |
| 366 | * fscache_pin_cookie - Pin a data-storage cache object in its cache |
| 367 | * @cookie: The cookie representing the cache object |
| 368 | * |
| 369 | * Permit data-storage cache objects to be pinned in the cache. |
| 370 | * |
| 371 | * See Documentation/filesystems/caching/netfs-api.txt for a complete |
| 372 | * description. |
| 373 | */ |
| 374 | static inline |
| 375 | int fscache_pin_cookie(struct fscache_cookie *cookie) |
| 376 | { |
| 377 | return -ENOBUFS; |
| 378 | } |
| 379 | |
| 380 | /** |
| 381 | * fscache_pin_cookie - Unpin a data-storage cache object in its cache |
| 382 | * @cookie: The cookie representing the cache object |
| 383 | * |
| 384 | * Permit data-storage cache objects to be unpinned from the cache. |
| 385 | * |
| 386 | * See Documentation/filesystems/caching/netfs-api.txt for a complete |
| 387 | * description. |
| 388 | */ |
| 389 | static inline |
| 390 | void fscache_unpin_cookie(struct fscache_cookie *cookie) |
| 391 | { |
| 392 | } |
| 393 | |
| 394 | /** |
| 395 | * fscache_attr_changed - Notify cache that an object's attributes changed |
| 396 | * @cookie: The cookie representing the cache object |
| 397 | * |
| 398 | * Send a notification to the cache indicating that an object's attributes have |
| 399 | * changed. This includes the data size. These attributes will be obtained |
| 400 | * through the get_attr() cookie definition op. |
| 401 | * |
| 402 | * See Documentation/filesystems/caching/netfs-api.txt for a complete |
| 403 | * description. |
| 404 | */ |
| 405 | static inline |
| 406 | int fscache_attr_changed(struct fscache_cookie *cookie) |
| 407 | { |
David Howells | b510882 | 2009-04-03 16:42:39 +0100 | [diff] [blame] | 408 | if (fscache_cookie_valid(cookie)) |
| 409 | return __fscache_attr_changed(cookie); |
| 410 | else |
| 411 | return -ENOBUFS; |
David Howells | 2d6fff6 | 2009-04-03 16:42:36 +0100 | [diff] [blame] | 412 | } |
| 413 | |
| 414 | /** |
David Howells | ef778e7 | 2012-12-20 21:52:36 +0000 | [diff] [blame] | 415 | * fscache_invalidate - Notify cache that an object needs invalidation |
| 416 | * @cookie: The cookie representing the cache object |
| 417 | * |
| 418 | * Notify the cache that an object is needs to be invalidated and that it |
| 419 | * should abort any retrievals or stores it is doing on the cache. The object |
| 420 | * is then marked non-caching until such time as the invalidation is complete. |
| 421 | * |
| 422 | * This can be called with spinlocks held. |
| 423 | * |
| 424 | * See Documentation/filesystems/caching/netfs-api.txt for a complete |
| 425 | * description. |
| 426 | */ |
| 427 | static inline |
| 428 | void fscache_invalidate(struct fscache_cookie *cookie) |
| 429 | { |
| 430 | if (fscache_cookie_valid(cookie)) |
| 431 | __fscache_invalidate(cookie); |
| 432 | } |
| 433 | |
| 434 | /** |
| 435 | * fscache_wait_on_invalidate - Wait for invalidation to complete |
| 436 | * @cookie: The cookie representing the cache object |
| 437 | * |
| 438 | * Wait for the invalidation of an object to complete. |
| 439 | * |
| 440 | * See Documentation/filesystems/caching/netfs-api.txt for a complete |
| 441 | * description. |
| 442 | */ |
| 443 | static inline |
| 444 | void fscache_wait_on_invalidate(struct fscache_cookie *cookie) |
| 445 | { |
| 446 | if (fscache_cookie_valid(cookie)) |
| 447 | __fscache_wait_on_invalidate(cookie); |
| 448 | } |
| 449 | |
| 450 | /** |
David Howells | 2d6fff6 | 2009-04-03 16:42:36 +0100 | [diff] [blame] | 451 | * fscache_reserve_space - Reserve data space for a cached object |
| 452 | * @cookie: The cookie representing the cache object |
| 453 | * @i_size: The amount of space to be reserved |
| 454 | * |
| 455 | * Reserve an amount of space in the cache for the cache object attached to a |
| 456 | * cookie so that a write to that object within the space can always be |
| 457 | * honoured. |
| 458 | * |
| 459 | * See Documentation/filesystems/caching/netfs-api.txt for a complete |
| 460 | * description. |
| 461 | */ |
| 462 | static inline |
| 463 | int fscache_reserve_space(struct fscache_cookie *cookie, loff_t size) |
| 464 | { |
| 465 | return -ENOBUFS; |
| 466 | } |
| 467 | |
| 468 | /** |
| 469 | * fscache_read_or_alloc_page - Read a page from the cache or allocate a block |
| 470 | * in which to store it |
| 471 | * @cookie: The cookie representing the cache object |
| 472 | * @page: The netfs page to fill if possible |
| 473 | * @end_io_func: The callback to invoke when and if the page is filled |
| 474 | * @context: An arbitrary piece of data to pass on to end_io_func() |
| 475 | * @gfp: The conditions under which memory allocation should be made |
| 476 | * |
| 477 | * Read a page from the cache, or if that's not possible make a potential |
| 478 | * one-block reservation in the cache into which the page may be stored once |
| 479 | * fetched from the server. |
| 480 | * |
| 481 | * If the page is not backed by the cache object, or if it there's some reason |
| 482 | * it can't be, -ENOBUFS will be returned and nothing more will be done for |
| 483 | * that page. |
| 484 | * |
| 485 | * Else, if that page is backed by the cache, a read will be initiated directly |
| 486 | * to the netfs's page and 0 will be returned by this function. The |
| 487 | * end_io_func() callback will be invoked when the operation terminates on a |
| 488 | * completion or failure. Note that the callback may be invoked before the |
| 489 | * return. |
| 490 | * |
| 491 | * Else, if the page is unbacked, -ENODATA is returned and a block may have |
| 492 | * been allocated in the cache. |
| 493 | * |
| 494 | * See Documentation/filesystems/caching/netfs-api.txt for a complete |
| 495 | * description. |
| 496 | */ |
| 497 | static inline |
| 498 | int fscache_read_or_alloc_page(struct fscache_cookie *cookie, |
| 499 | struct page *page, |
| 500 | fscache_rw_complete_t end_io_func, |
| 501 | void *context, |
| 502 | gfp_t gfp) |
| 503 | { |
David Howells | b510882 | 2009-04-03 16:42:39 +0100 | [diff] [blame] | 504 | if (fscache_cookie_valid(cookie)) |
| 505 | return __fscache_read_or_alloc_page(cookie, page, end_io_func, |
| 506 | context, gfp); |
| 507 | else |
| 508 | return -ENOBUFS; |
David Howells | 2d6fff6 | 2009-04-03 16:42:36 +0100 | [diff] [blame] | 509 | } |
| 510 | |
| 511 | /** |
| 512 | * fscache_read_or_alloc_pages - Read pages from the cache and/or allocate |
| 513 | * blocks in which to store them |
| 514 | * @cookie: The cookie representing the cache object |
| 515 | * @mapping: The netfs inode mapping to which the pages will be attached |
| 516 | * @pages: A list of potential netfs pages to be filled |
Suresh Jayaraman | 49a3df8 | 2010-07-06 18:29:45 +0530 | [diff] [blame] | 517 | * @nr_pages: Number of pages to be read and/or allocated |
David Howells | 2d6fff6 | 2009-04-03 16:42:36 +0100 | [diff] [blame] | 518 | * @end_io_func: The callback to invoke when and if each page is filled |
| 519 | * @context: An arbitrary piece of data to pass on to end_io_func() |
| 520 | * @gfp: The conditions under which memory allocation should be made |
| 521 | * |
| 522 | * Read a set of pages from the cache, or if that's not possible, attempt to |
| 523 | * make a potential one-block reservation for each page in the cache into which |
| 524 | * that page may be stored once fetched from the server. |
| 525 | * |
| 526 | * If some pages are not backed by the cache object, or if it there's some |
| 527 | * reason they can't be, -ENOBUFS will be returned and nothing more will be |
| 528 | * done for that pages. |
| 529 | * |
| 530 | * Else, if some of the pages are backed by the cache, a read will be initiated |
| 531 | * directly to the netfs's page and 0 will be returned by this function. The |
| 532 | * end_io_func() callback will be invoked when the operation terminates on a |
| 533 | * completion or failure. Note that the callback may be invoked before the |
| 534 | * return. |
| 535 | * |
| 536 | * Else, if a page is unbacked, -ENODATA is returned and a block may have |
| 537 | * been allocated in the cache. |
| 538 | * |
| 539 | * Because the function may want to return all of -ENOBUFS, -ENODATA and 0 in |
| 540 | * regard to different pages, the return values are prioritised in that order. |
| 541 | * Any pages submitted for reading are removed from the pages list. |
| 542 | * |
| 543 | * See Documentation/filesystems/caching/netfs-api.txt for a complete |
| 544 | * description. |
| 545 | */ |
| 546 | static inline |
| 547 | int fscache_read_or_alloc_pages(struct fscache_cookie *cookie, |
| 548 | struct address_space *mapping, |
| 549 | struct list_head *pages, |
| 550 | unsigned *nr_pages, |
| 551 | fscache_rw_complete_t end_io_func, |
| 552 | void *context, |
| 553 | gfp_t gfp) |
| 554 | { |
David Howells | b510882 | 2009-04-03 16:42:39 +0100 | [diff] [blame] | 555 | if (fscache_cookie_valid(cookie)) |
| 556 | return __fscache_read_or_alloc_pages(cookie, mapping, pages, |
| 557 | nr_pages, end_io_func, |
| 558 | context, gfp); |
| 559 | else |
| 560 | return -ENOBUFS; |
David Howells | 2d6fff6 | 2009-04-03 16:42:36 +0100 | [diff] [blame] | 561 | } |
| 562 | |
| 563 | /** |
| 564 | * fscache_alloc_page - Allocate a block in which to store a page |
| 565 | * @cookie: The cookie representing the cache object |
| 566 | * @page: The netfs page to allocate a page for |
| 567 | * @gfp: The conditions under which memory allocation should be made |
| 568 | * |
| 569 | * Request Allocation a block in the cache in which to store a netfs page |
| 570 | * without retrieving any contents from the cache. |
| 571 | * |
| 572 | * If the page is not backed by a file then -ENOBUFS will be returned and |
| 573 | * nothing more will be done, and no reservation will be made. |
| 574 | * |
| 575 | * Else, a block will be allocated if one wasn't already, and 0 will be |
| 576 | * returned |
| 577 | * |
| 578 | * See Documentation/filesystems/caching/netfs-api.txt for a complete |
| 579 | * description. |
| 580 | */ |
| 581 | static inline |
| 582 | int fscache_alloc_page(struct fscache_cookie *cookie, |
| 583 | struct page *page, |
| 584 | gfp_t gfp) |
| 585 | { |
David Howells | b510882 | 2009-04-03 16:42:39 +0100 | [diff] [blame] | 586 | if (fscache_cookie_valid(cookie)) |
| 587 | return __fscache_alloc_page(cookie, page, gfp); |
| 588 | else |
| 589 | return -ENOBUFS; |
David Howells | 2d6fff6 | 2009-04-03 16:42:36 +0100 | [diff] [blame] | 590 | } |
| 591 | |
| 592 | /** |
| 593 | * fscache_write_page - Request storage of a page in the cache |
| 594 | * @cookie: The cookie representing the cache object |
| 595 | * @page: The netfs page to store |
| 596 | * @gfp: The conditions under which memory allocation should be made |
| 597 | * |
| 598 | * Request the contents of the netfs page be written into the cache. This |
| 599 | * request may be ignored if no cache block is currently allocated, in which |
| 600 | * case it will return -ENOBUFS. |
| 601 | * |
| 602 | * If a cache block was already allocated, a write will be initiated and 0 will |
| 603 | * be returned. The PG_fscache_write page bit is set immediately and will then |
| 604 | * be cleared at the completion of the write to indicate the success or failure |
| 605 | * of the operation. Note that the completion may happen before the return. |
| 606 | * |
| 607 | * See Documentation/filesystems/caching/netfs-api.txt for a complete |
| 608 | * description. |
| 609 | */ |
| 610 | static inline |
| 611 | int fscache_write_page(struct fscache_cookie *cookie, |
| 612 | struct page *page, |
| 613 | gfp_t gfp) |
| 614 | { |
David Howells | b510882 | 2009-04-03 16:42:39 +0100 | [diff] [blame] | 615 | if (fscache_cookie_valid(cookie)) |
| 616 | return __fscache_write_page(cookie, page, gfp); |
| 617 | else |
| 618 | return -ENOBUFS; |
David Howells | 2d6fff6 | 2009-04-03 16:42:36 +0100 | [diff] [blame] | 619 | } |
| 620 | |
| 621 | /** |
| 622 | * fscache_uncache_page - Indicate that caching is no longer required on a page |
| 623 | * @cookie: The cookie representing the cache object |
| 624 | * @page: The netfs page that was being cached. |
| 625 | * |
| 626 | * Tell the cache that we no longer want a page to be cached and that it should |
| 627 | * remove any knowledge of the netfs page it may have. |
| 628 | * |
| 629 | * Note that this cannot cancel any outstanding I/O operations between this |
| 630 | * page and the cache. |
| 631 | * |
| 632 | * See Documentation/filesystems/caching/netfs-api.txt for a complete |
| 633 | * description. |
| 634 | */ |
| 635 | static inline |
| 636 | void fscache_uncache_page(struct fscache_cookie *cookie, |
| 637 | struct page *page) |
| 638 | { |
David Howells | b510882 | 2009-04-03 16:42:39 +0100 | [diff] [blame] | 639 | if (fscache_cookie_valid(cookie)) |
| 640 | __fscache_uncache_page(cookie, page); |
David Howells | 2d6fff6 | 2009-04-03 16:42:36 +0100 | [diff] [blame] | 641 | } |
| 642 | |
| 643 | /** |
| 644 | * fscache_check_page_write - Ask if a page is being writing to the cache |
| 645 | * @cookie: The cookie representing the cache object |
| 646 | * @page: The netfs page that is being cached. |
| 647 | * |
| 648 | * Ask the cache if a page is being written to the cache. |
| 649 | * |
| 650 | * See Documentation/filesystems/caching/netfs-api.txt for a complete |
| 651 | * description. |
| 652 | */ |
| 653 | static inline |
| 654 | bool fscache_check_page_write(struct fscache_cookie *cookie, |
| 655 | struct page *page) |
| 656 | { |
David Howells | b510882 | 2009-04-03 16:42:39 +0100 | [diff] [blame] | 657 | if (fscache_cookie_valid(cookie)) |
| 658 | return __fscache_check_page_write(cookie, page); |
David Howells | 2d6fff6 | 2009-04-03 16:42:36 +0100 | [diff] [blame] | 659 | return false; |
| 660 | } |
| 661 | |
| 662 | /** |
| 663 | * fscache_wait_on_page_write - Wait for a page to complete writing to the cache |
| 664 | * @cookie: The cookie representing the cache object |
| 665 | * @page: The netfs page that is being cached. |
| 666 | * |
| 667 | * Ask the cache to wake us up when a page is no longer being written to the |
| 668 | * cache. |
| 669 | * |
| 670 | * See Documentation/filesystems/caching/netfs-api.txt for a complete |
| 671 | * description. |
| 672 | */ |
| 673 | static inline |
| 674 | void fscache_wait_on_page_write(struct fscache_cookie *cookie, |
| 675 | struct page *page) |
| 676 | { |
David Howells | b510882 | 2009-04-03 16:42:39 +0100 | [diff] [blame] | 677 | if (fscache_cookie_valid(cookie)) |
| 678 | __fscache_wait_on_page_write(cookie, page); |
David Howells | 2d6fff6 | 2009-04-03 16:42:36 +0100 | [diff] [blame] | 679 | } |
| 680 | |
David Howells | 201a154 | 2009-11-19 18:11:35 +0000 | [diff] [blame] | 681 | /** |
| 682 | * fscache_maybe_release_page - Consider releasing a page, cancelling a store |
| 683 | * @cookie: The cookie representing the cache object |
| 684 | * @page: The netfs page that is being cached. |
| 685 | * @gfp: The gfp flags passed to releasepage() |
| 686 | * |
| 687 | * Consider releasing a page for the vmscan algorithm, on behalf of the netfs's |
| 688 | * releasepage() call. A storage request on the page may cancelled if it is |
| 689 | * not currently being processed. |
| 690 | * |
| 691 | * The function returns true if the page no longer has a storage request on it, |
| 692 | * and false if a storage request is left in place. If true is returned, the |
| 693 | * page will have been passed to fscache_uncache_page(). If false is returned |
| 694 | * the page cannot be freed yet. |
| 695 | */ |
| 696 | static inline |
| 697 | bool fscache_maybe_release_page(struct fscache_cookie *cookie, |
| 698 | struct page *page, |
| 699 | gfp_t gfp) |
| 700 | { |
| 701 | if (fscache_cookie_valid(cookie) && PageFsCache(page)) |
| 702 | return __fscache_maybe_release_page(cookie, page, gfp); |
| 703 | return false; |
| 704 | } |
| 705 | |
David Howells | c902ce1 | 2011-07-07 12:19:48 +0100 | [diff] [blame] | 706 | /** |
| 707 | * fscache_uncache_all_inode_pages - Uncache all an inode's pages |
| 708 | * @cookie: The cookie representing the inode's cache object. |
| 709 | * @inode: The inode to uncache pages from. |
| 710 | * |
| 711 | * Uncache all the pages in an inode that are marked PG_fscache, assuming them |
| 712 | * to be associated with the given cookie. |
| 713 | * |
| 714 | * This function may sleep. It will wait for pages that are being written out |
| 715 | * and will wait whilst the PG_fscache mark is removed by the cache. |
| 716 | */ |
| 717 | static inline |
| 718 | void fscache_uncache_all_inode_pages(struct fscache_cookie *cookie, |
| 719 | struct inode *inode) |
| 720 | { |
| 721 | if (fscache_cookie_valid(cookie)) |
| 722 | __fscache_uncache_all_inode_pages(cookie, inode); |
| 723 | } |
| 724 | |
David Howells | 2d6fff6 | 2009-04-03 16:42:36 +0100 | [diff] [blame] | 725 | #endif /* _LINUX_FSCACHE_H */ |