fscache.h 24 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747
  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. #ifndef _LINUX_FSCACHE_H
  18. #define _LINUX_FSCACHE_H
  19. #include <linux/fs.h>
  20. #include <linux/list.h>
  21. #include <linux/pagemap.h>
  22. #include <linux/pagevec.h>
  23. #if defined(CONFIG_FSCACHE) || defined(CONFIG_FSCACHE_MODULE)
  24. #define fscache_available() (1)
  25. #define fscache_cookie_valid(cookie) (cookie)
  26. #else
  27. #define fscache_available() (0)
  28. #define fscache_cookie_valid(cookie) (0)
  29. #endif
  30. /*
  31. * overload PG_private_2 to give us PG_fscache - this is used to indicate that
  32. * a page is currently backed by a local disk cache
  33. */
  34. #define PageFsCache(page) PagePrivate2((page))
  35. #define SetPageFsCache(page) SetPagePrivate2((page))
  36. #define ClearPageFsCache(page) ClearPagePrivate2((page))
  37. #define TestSetPageFsCache(page) TestSetPagePrivate2((page))
  38. #define TestClearPageFsCache(page) TestClearPagePrivate2((page))
  39. /* pattern used to fill dead space in an index entry */
  40. #define FSCACHE_INDEX_DEADFILL_PATTERN 0x79
  41. struct pagevec;
  42. struct fscache_cache_tag;
  43. struct fscache_cookie;
  44. struct fscache_netfs;
  45. typedef void (*fscache_rw_complete_t)(struct page *page,
  46. void *context,
  47. int error);
  48. /* result of index entry consultation */
  49. enum fscache_checkaux {
  50. FSCACHE_CHECKAUX_OKAY, /* entry okay as is */
  51. FSCACHE_CHECKAUX_NEEDS_UPDATE, /* entry requires update */
  52. FSCACHE_CHECKAUX_OBSOLETE, /* entry requires deletion */
  53. };
  54. /*
  55. * fscache cookie definition
  56. */
  57. struct fscache_cookie_def {
  58. /* name of cookie type */
  59. char name[16];
  60. /* cookie type */
  61. uint8_t type;
  62. #define FSCACHE_COOKIE_TYPE_INDEX 0
  63. #define FSCACHE_COOKIE_TYPE_DATAFILE 1
  64. /* select the cache into which to insert an entry in this index
  65. * - optional
  66. * - should return a cache identifier or NULL to cause the cache to be
  67. * inherited from the parent if possible or the first cache picked
  68. * for a non-index file if not
  69. */
  70. struct fscache_cache_tag *(*select_cache)(
  71. const void *parent_netfs_data,
  72. const void *cookie_netfs_data);
  73. /* get an index key
  74. * - should store the key data in the buffer
  75. * - should return the amount of data stored
  76. * - not permitted to return an error
  77. * - the netfs data from the cookie being used as the source is
  78. * presented
  79. */
  80. uint16_t (*get_key)(const void *cookie_netfs_data,
  81. void *buffer,
  82. uint16_t bufmax);
  83. /* get certain file attributes from the netfs data
  84. * - this function can be absent for an index
  85. * - not permitted to return an error
  86. * - the netfs data from the cookie being used as the source is
  87. * presented
  88. */
  89. void (*get_attr)(const void *cookie_netfs_data, uint64_t *size);
  90. /* get the auxiliary data from netfs data
  91. * - this function can be absent if the index carries no state data
  92. * - should store the auxiliary data in the buffer
  93. * - should return the amount of amount stored
  94. * - not permitted to return an error
  95. * - the netfs data from the cookie being used as the source is
  96. * presented
  97. */
  98. uint16_t (*get_aux)(const void *cookie_netfs_data,
  99. void *buffer,
  100. uint16_t bufmax);
  101. /* consult the netfs about the state of an object
  102. * - this function can be absent if the index carries no state data
  103. * - the netfs data from the cookie being used as the target is
  104. * presented, as is the auxiliary data
  105. */
  106. enum fscache_checkaux (*check_aux)(void *cookie_netfs_data,
  107. const void *data,
  108. uint16_t datalen);
  109. /* get an extra reference on a read context
  110. * - this function can be absent if the completion function doesn't
  111. * require a context
  112. */
  113. void (*get_context)(void *cookie_netfs_data, void *context);
  114. /* release an extra reference on a read context
  115. * - this function can be absent if the completion function doesn't
  116. * require a context
  117. */
  118. void (*put_context)(void *cookie_netfs_data, void *context);
  119. /* indicate page that now have cache metadata retained
  120. * - this function should mark the specified page as now being cached
  121. * - the page will have been marked with PG_fscache before this is
  122. * called, so this is optional
  123. */
  124. void (*mark_page_cached)(void *cookie_netfs_data,
  125. struct address_space *mapping,
  126. struct page *page);
  127. /* indicate the cookie is no longer cached
  128. * - this function is called when the backing store currently caching
  129. * a cookie is removed
  130. * - the netfs should use this to clean up any markers indicating
  131. * cached pages
  132. * - this is mandatory for any object that may have data
  133. */
  134. void (*now_uncached)(void *cookie_netfs_data);
  135. };
  136. /*
  137. * fscache cached network filesystem type
  138. * - name, version and ops must be filled in before registration
  139. * - all other fields will be set during registration
  140. */
  141. struct fscache_netfs {
  142. uint32_t version; /* indexing version */
  143. const char *name; /* filesystem name */
  144. struct fscache_cookie *primary_index;
  145. struct list_head link; /* internal link */
  146. };
  147. /*
  148. * slow-path functions for when there is actually caching available, and the
  149. * netfs does actually have a valid token
  150. * - these are not to be called directly
  151. * - these are undefined symbols when FS-Cache is not configured and the
  152. * optimiser takes care of not using them
  153. */
  154. extern int __fscache_register_netfs(struct fscache_netfs *);
  155. extern void __fscache_unregister_netfs(struct fscache_netfs *);
  156. extern struct fscache_cache_tag *__fscache_lookup_cache_tag(const char *);
  157. extern void __fscache_release_cache_tag(struct fscache_cache_tag *);
  158. extern struct fscache_cookie *__fscache_acquire_cookie(
  159. struct fscache_cookie *,
  160. const struct fscache_cookie_def *,
  161. void *);
  162. extern void __fscache_relinquish_cookie(struct fscache_cookie *, int);
  163. extern int __fscache_check_consistency(struct fscache_cookie *);
  164. extern void __fscache_update_cookie(struct fscache_cookie *);
  165. extern int __fscache_attr_changed(struct fscache_cookie *);
  166. extern void __fscache_invalidate(struct fscache_cookie *);
  167. extern void __fscache_wait_on_invalidate(struct fscache_cookie *);
  168. extern int __fscache_read_or_alloc_page(struct fscache_cookie *,
  169. struct page *,
  170. fscache_rw_complete_t,
  171. void *,
  172. gfp_t);
  173. extern int __fscache_read_or_alloc_pages(struct fscache_cookie *,
  174. struct address_space *,
  175. struct list_head *,
  176. unsigned *,
  177. fscache_rw_complete_t,
  178. void *,
  179. gfp_t);
  180. extern int __fscache_alloc_page(struct fscache_cookie *, struct page *, gfp_t);
  181. extern int __fscache_write_page(struct fscache_cookie *, struct page *, gfp_t);
  182. extern void __fscache_uncache_page(struct fscache_cookie *, struct page *);
  183. extern bool __fscache_check_page_write(struct fscache_cookie *, struct page *);
  184. extern void __fscache_wait_on_page_write(struct fscache_cookie *, struct page *);
  185. extern bool __fscache_maybe_release_page(struct fscache_cookie *, struct page *,
  186. gfp_t);
  187. extern void __fscache_uncache_all_inode_pages(struct fscache_cookie *,
  188. struct inode *);
  189. extern void __fscache_readpages_cancel(struct fscache_cookie *cookie,
  190. struct list_head *pages);
  191. /**
  192. * fscache_register_netfs - Register a filesystem as desiring caching services
  193. * @netfs: The description of the filesystem
  194. *
  195. * Register a filesystem as desiring caching services if they're available.
  196. *
  197. * See Documentation/filesystems/caching/netfs-api.txt for a complete
  198. * description.
  199. */
  200. static inline
  201. int fscache_register_netfs(struct fscache_netfs *netfs)
  202. {
  203. if (fscache_available())
  204. return __fscache_register_netfs(netfs);
  205. else
  206. return 0;
  207. }
  208. /**
  209. * fscache_unregister_netfs - Indicate that a filesystem no longer desires
  210. * caching services
  211. * @netfs: The description of the filesystem
  212. *
  213. * Indicate that a filesystem no longer desires caching services for the
  214. * moment.
  215. *
  216. * See Documentation/filesystems/caching/netfs-api.txt for a complete
  217. * description.
  218. */
  219. static inline
  220. void fscache_unregister_netfs(struct fscache_netfs *netfs)
  221. {
  222. if (fscache_available())
  223. __fscache_unregister_netfs(netfs);
  224. }
  225. /**
  226. * fscache_lookup_cache_tag - Look up a cache tag
  227. * @name: The name of the tag to search for
  228. *
  229. * Acquire a specific cache referral tag that can be used to select a specific
  230. * cache in which to cache an index.
  231. *
  232. * See Documentation/filesystems/caching/netfs-api.txt for a complete
  233. * description.
  234. */
  235. static inline
  236. struct fscache_cache_tag *fscache_lookup_cache_tag(const char *name)
  237. {
  238. if (fscache_available())
  239. return __fscache_lookup_cache_tag(name);
  240. else
  241. return NULL;
  242. }
  243. /**
  244. * fscache_release_cache_tag - Release a cache tag
  245. * @tag: The tag to release
  246. *
  247. * Release a reference to a cache referral tag previously looked up.
  248. *
  249. * See Documentation/filesystems/caching/netfs-api.txt for a complete
  250. * description.
  251. */
  252. static inline
  253. void fscache_release_cache_tag(struct fscache_cache_tag *tag)
  254. {
  255. if (fscache_available())
  256. __fscache_release_cache_tag(tag);
  257. }
  258. /**
  259. * fscache_acquire_cookie - Acquire a cookie to represent a cache object
  260. * @parent: The cookie that's to be the parent of this one
  261. * @def: A description of the cache object, including callback operations
  262. * @netfs_data: An arbitrary piece of data to be kept in the cookie to
  263. * represent the cache object to the netfs
  264. *
  265. * This function is used to inform FS-Cache about part of an index hierarchy
  266. * that can be used to locate files. This is done by requesting a cookie for
  267. * each index in the path to the file.
  268. *
  269. * See Documentation/filesystems/caching/netfs-api.txt for a complete
  270. * description.
  271. */
  272. static inline
  273. struct fscache_cookie *fscache_acquire_cookie(
  274. struct fscache_cookie *parent,
  275. const struct fscache_cookie_def *def,
  276. void *netfs_data)
  277. {
  278. if (fscache_cookie_valid(parent))
  279. return __fscache_acquire_cookie(parent, def, netfs_data);
  280. else
  281. return NULL;
  282. }
  283. /**
  284. * fscache_relinquish_cookie - Return the cookie to the cache, maybe discarding
  285. * it
  286. * @cookie: The cookie being returned
  287. * @retire: True if the cache object the cookie represents is to be discarded
  288. *
  289. * This function returns a cookie to the cache, forcibly discarding the
  290. * associated cache object if retire is set to true.
  291. *
  292. * See Documentation/filesystems/caching/netfs-api.txt for a complete
  293. * description.
  294. */
  295. static inline
  296. void fscache_relinquish_cookie(struct fscache_cookie *cookie, int retire)
  297. {
  298. if (fscache_cookie_valid(cookie))
  299. __fscache_relinquish_cookie(cookie, retire);
  300. }
  301. /**
  302. * fscache_check_consistency - Request that if the cache is updated
  303. * @cookie: The cookie representing the cache object
  304. *
  305. * Request an consistency check from fscache, which passes the request
  306. * to the backing cache.
  307. *
  308. * Returns 0 if consistent and -ESTALE if inconsistent. May also
  309. * return -ENOMEM and -ERESTARTSYS.
  310. */
  311. static inline
  312. int fscache_check_consistency(struct fscache_cookie *cookie)
  313. {
  314. if (fscache_cookie_valid(cookie))
  315. return __fscache_check_consistency(cookie);
  316. else
  317. return 0;
  318. }
  319. /**
  320. * fscache_update_cookie - Request that a cache object be updated
  321. * @cookie: The cookie representing the cache object
  322. *
  323. * Request an update of the index data for the cache object associated with the
  324. * cookie.
  325. *
  326. * See Documentation/filesystems/caching/netfs-api.txt for a complete
  327. * description.
  328. */
  329. static inline
  330. void fscache_update_cookie(struct fscache_cookie *cookie)
  331. {
  332. if (fscache_cookie_valid(cookie))
  333. __fscache_update_cookie(cookie);
  334. }
  335. /**
  336. * fscache_pin_cookie - Pin a data-storage cache object in its cache
  337. * @cookie: The cookie representing the cache object
  338. *
  339. * Permit data-storage cache objects to be pinned in the cache.
  340. *
  341. * See Documentation/filesystems/caching/netfs-api.txt for a complete
  342. * description.
  343. */
  344. static inline
  345. int fscache_pin_cookie(struct fscache_cookie *cookie)
  346. {
  347. return -ENOBUFS;
  348. }
  349. /**
  350. * fscache_pin_cookie - Unpin a data-storage cache object in its cache
  351. * @cookie: The cookie representing the cache object
  352. *
  353. * Permit data-storage cache objects to be unpinned from the cache.
  354. *
  355. * See Documentation/filesystems/caching/netfs-api.txt for a complete
  356. * description.
  357. */
  358. static inline
  359. void fscache_unpin_cookie(struct fscache_cookie *cookie)
  360. {
  361. }
  362. /**
  363. * fscache_attr_changed - Notify cache that an object's attributes changed
  364. * @cookie: The cookie representing the cache object
  365. *
  366. * Send a notification to the cache indicating that an object's attributes have
  367. * changed. This includes the data size. These attributes will be obtained
  368. * through the get_attr() cookie definition op.
  369. *
  370. * See Documentation/filesystems/caching/netfs-api.txt for a complete
  371. * description.
  372. */
  373. static inline
  374. int fscache_attr_changed(struct fscache_cookie *cookie)
  375. {
  376. if (fscache_cookie_valid(cookie))
  377. return __fscache_attr_changed(cookie);
  378. else
  379. return -ENOBUFS;
  380. }
  381. /**
  382. * fscache_invalidate - Notify cache that an object needs invalidation
  383. * @cookie: The cookie representing the cache object
  384. *
  385. * Notify the cache that an object is needs to be invalidated and that it
  386. * should abort any retrievals or stores it is doing on the cache. The object
  387. * is then marked non-caching until such time as the invalidation is complete.
  388. *
  389. * This can be called with spinlocks held.
  390. *
  391. * See Documentation/filesystems/caching/netfs-api.txt for a complete
  392. * description.
  393. */
  394. static inline
  395. void fscache_invalidate(struct fscache_cookie *cookie)
  396. {
  397. if (fscache_cookie_valid(cookie))
  398. __fscache_invalidate(cookie);
  399. }
  400. /**
  401. * fscache_wait_on_invalidate - Wait for invalidation to complete
  402. * @cookie: The cookie representing the cache object
  403. *
  404. * Wait for the invalidation of an object to complete.
  405. *
  406. * See Documentation/filesystems/caching/netfs-api.txt for a complete
  407. * description.
  408. */
  409. static inline
  410. void fscache_wait_on_invalidate(struct fscache_cookie *cookie)
  411. {
  412. if (fscache_cookie_valid(cookie))
  413. __fscache_wait_on_invalidate(cookie);
  414. }
  415. /**
  416. * fscache_reserve_space - Reserve data space for a cached object
  417. * @cookie: The cookie representing the cache object
  418. * @i_size: The amount of space to be reserved
  419. *
  420. * Reserve an amount of space in the cache for the cache object attached to a
  421. * cookie so that a write to that object within the space can always be
  422. * honoured.
  423. *
  424. * See Documentation/filesystems/caching/netfs-api.txt for a complete
  425. * description.
  426. */
  427. static inline
  428. int fscache_reserve_space(struct fscache_cookie *cookie, loff_t size)
  429. {
  430. return -ENOBUFS;
  431. }
  432. /**
  433. * fscache_read_or_alloc_page - Read a page from the cache or allocate a block
  434. * in which to store it
  435. * @cookie: The cookie representing the cache object
  436. * @page: The netfs page to fill if possible
  437. * @end_io_func: The callback to invoke when and if the page is filled
  438. * @context: An arbitrary piece of data to pass on to end_io_func()
  439. * @gfp: The conditions under which memory allocation should be made
  440. *
  441. * Read a page from the cache, or if that's not possible make a potential
  442. * one-block reservation in the cache into which the page may be stored once
  443. * fetched from the server.
  444. *
  445. * If the page is not backed by the cache object, or if it there's some reason
  446. * it can't be, -ENOBUFS will be returned and nothing more will be done for
  447. * that page.
  448. *
  449. * Else, if that page is backed by the cache, a read will be initiated directly
  450. * to the netfs's page and 0 will be returned by this function. The
  451. * end_io_func() callback will be invoked when the operation terminates on a
  452. * completion or failure. Note that the callback may be invoked before the
  453. * return.
  454. *
  455. * Else, if the page is unbacked, -ENODATA is returned and a block may have
  456. * been allocated in the cache.
  457. *
  458. * See Documentation/filesystems/caching/netfs-api.txt for a complete
  459. * description.
  460. */
  461. static inline
  462. int fscache_read_or_alloc_page(struct fscache_cookie *cookie,
  463. struct page *page,
  464. fscache_rw_complete_t end_io_func,
  465. void *context,
  466. gfp_t gfp)
  467. {
  468. if (fscache_cookie_valid(cookie))
  469. return __fscache_read_or_alloc_page(cookie, page, end_io_func,
  470. context, gfp);
  471. else
  472. return -ENOBUFS;
  473. }
  474. /**
  475. * fscache_read_or_alloc_pages - Read pages from the cache and/or allocate
  476. * blocks in which to store them
  477. * @cookie: The cookie representing the cache object
  478. * @mapping: The netfs inode mapping to which the pages will be attached
  479. * @pages: A list of potential netfs pages to be filled
  480. * @nr_pages: Number of pages to be read and/or allocated
  481. * @end_io_func: The callback to invoke when and if each page is filled
  482. * @context: An arbitrary piece of data to pass on to end_io_func()
  483. * @gfp: The conditions under which memory allocation should be made
  484. *
  485. * Read a set of pages from the cache, or if that's not possible, attempt to
  486. * make a potential one-block reservation for each page in the cache into which
  487. * that page may be stored once fetched from the server.
  488. *
  489. * If some pages are not backed by the cache object, or if it there's some
  490. * reason they can't be, -ENOBUFS will be returned and nothing more will be
  491. * done for that pages.
  492. *
  493. * Else, if some of the pages are backed by the cache, a read will be initiated
  494. * directly to the netfs's page and 0 will be returned by this function. The
  495. * end_io_func() callback will be invoked when the operation terminates on a
  496. * completion or failure. Note that the callback may be invoked before the
  497. * return.
  498. *
  499. * Else, if a page is unbacked, -ENODATA is returned and a block may have
  500. * been allocated in the cache.
  501. *
  502. * Because the function may want to return all of -ENOBUFS, -ENODATA and 0 in
  503. * regard to different pages, the return values are prioritised in that order.
  504. * Any pages submitted for reading are removed from the pages list.
  505. *
  506. * See Documentation/filesystems/caching/netfs-api.txt for a complete
  507. * description.
  508. */
  509. static inline
  510. int fscache_read_or_alloc_pages(struct fscache_cookie *cookie,
  511. struct address_space *mapping,
  512. struct list_head *pages,
  513. unsigned *nr_pages,
  514. fscache_rw_complete_t end_io_func,
  515. void *context,
  516. gfp_t gfp)
  517. {
  518. if (fscache_cookie_valid(cookie))
  519. return __fscache_read_or_alloc_pages(cookie, mapping, pages,
  520. nr_pages, end_io_func,
  521. context, gfp);
  522. else
  523. return -ENOBUFS;
  524. }
  525. /**
  526. * fscache_alloc_page - Allocate a block in which to store a page
  527. * @cookie: The cookie representing the cache object
  528. * @page: The netfs page to allocate a page for
  529. * @gfp: The conditions under which memory allocation should be made
  530. *
  531. * Request Allocation a block in the cache in which to store a netfs page
  532. * without retrieving any contents from the cache.
  533. *
  534. * If the page is not backed by a file then -ENOBUFS will be returned and
  535. * nothing more will be done, and no reservation will be made.
  536. *
  537. * Else, a block will be allocated if one wasn't already, and 0 will be
  538. * returned
  539. *
  540. * See Documentation/filesystems/caching/netfs-api.txt for a complete
  541. * description.
  542. */
  543. static inline
  544. int fscache_alloc_page(struct fscache_cookie *cookie,
  545. struct page *page,
  546. gfp_t gfp)
  547. {
  548. if (fscache_cookie_valid(cookie))
  549. return __fscache_alloc_page(cookie, page, gfp);
  550. else
  551. return -ENOBUFS;
  552. }
  553. /**
  554. * fscache_readpages_cancel - Cancel read/alloc on pages
  555. * @cookie: The cookie representing the inode's cache object.
  556. * @pages: The netfs pages that we canceled write on in readpages()
  557. *
  558. * Uncache/unreserve the pages reserved earlier in readpages() via
  559. * fscache_readpages_or_alloc() and similar. In most successful caches in
  560. * readpages() this doesn't do anything. In cases when the underlying netfs's
  561. * readahead failed we need to clean up the pagelist (unmark and uncache).
  562. *
  563. * This function may sleep as it may have to clean up disk state.
  564. */
  565. static inline
  566. void fscache_readpages_cancel(struct fscache_cookie *cookie,
  567. struct list_head *pages)
  568. {
  569. if (fscache_cookie_valid(cookie))
  570. __fscache_readpages_cancel(cookie, pages);
  571. }
  572. /**
  573. * fscache_write_page - Request storage of a page in the cache
  574. * @cookie: The cookie representing the cache object
  575. * @page: The netfs page to store
  576. * @gfp: The conditions under which memory allocation should be made
  577. *
  578. * Request the contents of the netfs page be written into the cache. This
  579. * request may be ignored if no cache block is currently allocated, in which
  580. * case it will return -ENOBUFS.
  581. *
  582. * If a cache block was already allocated, a write will be initiated and 0 will
  583. * be returned. The PG_fscache_write page bit is set immediately and will then
  584. * be cleared at the completion of the write to indicate the success or failure
  585. * of the operation. Note that the completion may happen before the return.
  586. *
  587. * See Documentation/filesystems/caching/netfs-api.txt for a complete
  588. * description.
  589. */
  590. static inline
  591. int fscache_write_page(struct fscache_cookie *cookie,
  592. struct page *page,
  593. gfp_t gfp)
  594. {
  595. if (fscache_cookie_valid(cookie))
  596. return __fscache_write_page(cookie, page, gfp);
  597. else
  598. return -ENOBUFS;
  599. }
  600. /**
  601. * fscache_uncache_page - Indicate that caching is no longer required on a page
  602. * @cookie: The cookie representing the cache object
  603. * @page: The netfs page that was being cached.
  604. *
  605. * Tell the cache that we no longer want a page to be cached and that it should
  606. * remove any knowledge of the netfs page it may have.
  607. *
  608. * Note that this cannot cancel any outstanding I/O operations between this
  609. * page and the cache.
  610. *
  611. * See Documentation/filesystems/caching/netfs-api.txt for a complete
  612. * description.
  613. */
  614. static inline
  615. void fscache_uncache_page(struct fscache_cookie *cookie,
  616. struct page *page)
  617. {
  618. if (fscache_cookie_valid(cookie))
  619. __fscache_uncache_page(cookie, page);
  620. }
  621. /**
  622. * fscache_check_page_write - Ask if a page is being writing to the cache
  623. * @cookie: The cookie representing the cache object
  624. * @page: The netfs page that is being cached.
  625. *
  626. * Ask the cache if a page is being written to the cache.
  627. *
  628. * See Documentation/filesystems/caching/netfs-api.txt for a complete
  629. * description.
  630. */
  631. static inline
  632. bool fscache_check_page_write(struct fscache_cookie *cookie,
  633. struct page *page)
  634. {
  635. if (fscache_cookie_valid(cookie))
  636. return __fscache_check_page_write(cookie, page);
  637. return false;
  638. }
  639. /**
  640. * fscache_wait_on_page_write - Wait for a page to complete writing to the cache
  641. * @cookie: The cookie representing the cache object
  642. * @page: The netfs page that is being cached.
  643. *
  644. * Ask the cache to wake us up when a page is no longer being written to the
  645. * cache.
  646. *
  647. * See Documentation/filesystems/caching/netfs-api.txt for a complete
  648. * description.
  649. */
  650. static inline
  651. void fscache_wait_on_page_write(struct fscache_cookie *cookie,
  652. struct page *page)
  653. {
  654. if (fscache_cookie_valid(cookie))
  655. __fscache_wait_on_page_write(cookie, page);
  656. }
  657. /**
  658. * fscache_maybe_release_page - Consider releasing a page, cancelling a store
  659. * @cookie: The cookie representing the cache object
  660. * @page: The netfs page that is being cached.
  661. * @gfp: The gfp flags passed to releasepage()
  662. *
  663. * Consider releasing a page for the vmscan algorithm, on behalf of the netfs's
  664. * releasepage() call. A storage request on the page may cancelled if it is
  665. * not currently being processed.
  666. *
  667. * The function returns true if the page no longer has a storage request on it,
  668. * and false if a storage request is left in place. If true is returned, the
  669. * page will have been passed to fscache_uncache_page(). If false is returned
  670. * the page cannot be freed yet.
  671. */
  672. static inline
  673. bool fscache_maybe_release_page(struct fscache_cookie *cookie,
  674. struct page *page,
  675. gfp_t gfp)
  676. {
  677. if (fscache_cookie_valid(cookie) && PageFsCache(page))
  678. return __fscache_maybe_release_page(cookie, page, gfp);
  679. return false;
  680. }
  681. /**
  682. * fscache_uncache_all_inode_pages - Uncache all an inode's pages
  683. * @cookie: The cookie representing the inode's cache object.
  684. * @inode: The inode to uncache pages from.
  685. *
  686. * Uncache all the pages in an inode that are marked PG_fscache, assuming them
  687. * to be associated with the given cookie.
  688. *
  689. * This function may sleep. It will wait for pages that are being written out
  690. * and will wait whilst the PG_fscache mark is removed by the cache.
  691. */
  692. static inline
  693. void fscache_uncache_all_inode_pages(struct fscache_cookie *cookie,
  694. struct inode *inode)
  695. {
  696. if (fscache_cookie_valid(cookie))
  697. __fscache_uncache_all_inode_pages(cookie, inode);
  698. }
  699. #endif /* _LINUX_FSCACHE_H */