netfs-api.txt 29 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814
  1. ===============================
  2. FS-CACHE NETWORK FILESYSTEM API
  3. ===============================
  4. There's an API by which a network filesystem can make use of the FS-Cache
  5. facilities. This is based around a number of principles:
  6. (1) Caches can store a number of different object types. There are two main
  7. object types: indices and files. The first is a special type used by
  8. FS-Cache to make finding objects faster and to make retiring of groups of
  9. objects easier.
  10. (2) Every index, file or other object is represented by a cookie. This cookie
  11. may or may not have anything associated with it, but the netfs doesn't
  12. need to care.
  13. (3) Barring the top-level index (one entry per cached netfs), the index
  14. hierarchy for each netfs is structured according the whim of the netfs.
  15. This API is declared in <linux/fscache.h>.
  16. This document contains the following sections:
  17. (1) Network filesystem definition
  18. (2) Index definition
  19. (3) Object definition
  20. (4) Network filesystem (un)registration
  21. (5) Cache tag lookup
  22. (6) Index registration
  23. (7) Data file registration
  24. (8) Miscellaneous object registration
  25. (9) Setting the data file size
  26. (10) Page alloc/read/write
  27. (11) Page uncaching
  28. (12) Index and data file update
  29. (13) Miscellaneous cookie operations
  30. (14) Cookie unregistration
  31. (15) Index and data file invalidation
  32. (16) FS-Cache specific page flags.
  33. =============================
  34. NETWORK FILESYSTEM DEFINITION
  35. =============================
  36. FS-Cache needs a description of the network filesystem. This is specified
  37. using a record of the following structure:
  38. struct fscache_netfs {
  39. uint32_t version;
  40. const char *name;
  41. struct fscache_cookie *primary_index;
  42. ...
  43. };
  44. This first two fields should be filled in before registration, and the third
  45. will be filled in by the registration function; any other fields should just be
  46. ignored and are for internal use only.
  47. The fields are:
  48. (1) The name of the netfs (used as the key in the toplevel index).
  49. (2) The version of the netfs (if the name matches but the version doesn't, the
  50. entire in-cache hierarchy for this netfs will be scrapped and begun
  51. afresh).
  52. (3) The cookie representing the primary index will be allocated according to
  53. another parameter passed into the registration function.
  54. For example, kAFS (linux/fs/afs/) uses the following definitions to describe
  55. itself:
  56. struct fscache_netfs afs_cache_netfs = {
  57. .version = 0,
  58. .name = "afs",
  59. };
  60. ================
  61. INDEX DEFINITION
  62. ================
  63. Indices are used for two purposes:
  64. (1) To aid the finding of a file based on a series of keys (such as AFS's
  65. "cell", "volume ID", "vnode ID").
  66. (2) To make it easier to discard a subset of all the files cached based around
  67. a particular key - for instance to mirror the removal of an AFS volume.
  68. However, since it's unlikely that any two netfs's are going to want to define
  69. their index hierarchies in quite the same way, FS-Cache tries to impose as few
  70. restraints as possible on how an index is structured and where it is placed in
  71. the tree. The netfs can even mix indices and data files at the same level, but
  72. it's not recommended.
  73. Each index entry consists of a key of indeterminate length plus some auxiliary
  74. data, also of indeterminate length.
  75. There are some limits on indices:
  76. (1) Any index containing non-index objects should be restricted to a single
  77. cache. Any such objects created within an index will be created in the
  78. first cache only. The cache in which an index is created can be
  79. controlled by cache tags (see below).
  80. (2) The entry data must be atomically journallable, so it is limited to about
  81. 400 bytes at present. At least 400 bytes will be available.
  82. (3) The depth of the index tree should be judged with care as the search
  83. function is recursive. Too many layers will run the kernel out of stack.
  84. =================
  85. OBJECT DEFINITION
  86. =================
  87. To define an object, a structure of the following type should be filled out:
  88. struct fscache_cookie_def
  89. {
  90. uint8_t name[16];
  91. uint8_t type;
  92. struct fscache_cache_tag *(*select_cache)(
  93. const void *parent_netfs_data,
  94. const void *cookie_netfs_data);
  95. uint16_t (*get_key)(const void *cookie_netfs_data,
  96. void *buffer,
  97. uint16_t bufmax);
  98. void (*get_attr)(const void *cookie_netfs_data,
  99. uint64_t *size);
  100. uint16_t (*get_aux)(const void *cookie_netfs_data,
  101. void *buffer,
  102. uint16_t bufmax);
  103. enum fscache_checkaux (*check_aux)(void *cookie_netfs_data,
  104. const void *data,
  105. uint16_t datalen);
  106. void (*get_context)(void *cookie_netfs_data, void *context);
  107. void (*put_context)(void *cookie_netfs_data, void *context);
  108. void (*mark_pages_cached)(void *cookie_netfs_data,
  109. struct address_space *mapping,
  110. struct pagevec *cached_pvec);
  111. void (*now_uncached)(void *cookie_netfs_data);
  112. };
  113. This has the following fields:
  114. (1) The type of the object [mandatory].
  115. This is one of the following values:
  116. (*) FSCACHE_COOKIE_TYPE_INDEX
  117. This defines an index, which is a special FS-Cache type.
  118. (*) FSCACHE_COOKIE_TYPE_DATAFILE
  119. This defines an ordinary data file.
  120. (*) Any other value between 2 and 255
  121. This defines an extraordinary object such as an XATTR.
  122. (2) The name of the object type (NUL terminated unless all 16 chars are used)
  123. [optional].
  124. (3) A function to select the cache in which to store an index [optional].
  125. This function is invoked when an index needs to be instantiated in a cache
  126. during the instantiation of a non-index object. Only the immediate index
  127. parent for the non-index object will be queried. Any indices above that
  128. in the hierarchy may be stored in multiple caches. This function does not
  129. need to be supplied for any non-index object or any index that will only
  130. have index children.
  131. If this function is not supplied or if it returns NULL then the first
  132. cache in the parent's list will be chosen, or failing that, the first
  133. cache in the master list.
  134. (4) A function to retrieve an object's key from the netfs [mandatory].
  135. This function will be called with the netfs data that was passed to the
  136. cookie acquisition function and the maximum length of key data that it may
  137. provide. It should write the required key data into the given buffer and
  138. return the quantity it wrote.
  139. (5) A function to retrieve attribute data from the netfs [optional].
  140. This function will be called with the netfs data that was passed to the
  141. cookie acquisition function. It should return the size of the file if
  142. this is a data file. The size may be used to govern how much cache must
  143. be reserved for this file in the cache.
  144. If the function is absent, a file size of 0 is assumed.
  145. (6) A function to retrieve auxiliary data from the netfs [optional].
  146. This function will be called with the netfs data that was passed to the
  147. cookie acquisition function and the maximum length of auxiliary data that
  148. it may provide. It should write the auxiliary data into the given buffer
  149. and return the quantity it wrote.
  150. If this function is absent, the auxiliary data length will be set to 0.
  151. The length of the auxiliary data buffer may be dependent on the key
  152. length. A netfs mustn't rely on being able to provide more than 400 bytes
  153. for both.
  154. (7) A function to check the auxiliary data [optional].
  155. This function will be called to check that a match found in the cache for
  156. this object is valid. For instance with AFS it could check the auxiliary
  157. data against the data version number returned by the server to determine
  158. whether the index entry in a cache is still valid.
  159. If this function is absent, it will be assumed that matching objects in a
  160. cache are always valid.
  161. If present, the function should return one of the following values:
  162. (*) FSCACHE_CHECKAUX_OKAY - the entry is okay as is
  163. (*) FSCACHE_CHECKAUX_NEEDS_UPDATE - the entry requires update
  164. (*) FSCACHE_CHECKAUX_OBSOLETE - the entry should be deleted
  165. This function can also be used to extract data from the auxiliary data in
  166. the cache and copy it into the netfs's structures.
  167. (8) A pair of functions to manage contexts for the completion callback
  168. [optional].
  169. The cache read/write functions are passed a context which is then passed
  170. to the I/O completion callback function. To ensure this context remains
  171. valid until after the I/O completion is called, two functions may be
  172. provided: one to get an extra reference on the context, and one to drop a
  173. reference to it.
  174. If the context is not used or is a type of object that won't go out of
  175. scope, then these functions are not required. These functions are not
  176. required for indices as indices may not contain data. These functions may
  177. be called in interrupt context and so may not sleep.
  178. (9) A function to mark a page as retaining cache metadata [optional].
  179. This is called by the cache to indicate that it is retaining in-memory
  180. information for this page and that the netfs should uncache the page when
  181. it has finished. This does not indicate whether there's data on the disk
  182. or not. Note that several pages at once may be presented for marking.
  183. The PG_fscache bit is set on the pages before this function would be
  184. called, so the function need not be provided if this is sufficient.
  185. This function is not required for indices as they're not permitted data.
  186. (10) A function to unmark all the pages retaining cache metadata [mandatory].
  187. This is called by FS-Cache to indicate that a backing store is being
  188. unbound from a cookie and that all the marks on the pages should be
  189. cleared to prevent confusion. Note that the cache will have torn down all
  190. its tracking information so that the pages don't need to be explicitly
  191. uncached.
  192. This function is not required for indices as they're not permitted data.
  193. ===================================
  194. NETWORK FILESYSTEM (UN)REGISTRATION
  195. ===================================
  196. The first step is to declare the network filesystem to the cache. This also
  197. involves specifying the layout of the primary index (for AFS, this would be the
  198. "cell" level).
  199. The registration function is:
  200. int fscache_register_netfs(struct fscache_netfs *netfs);
  201. It just takes a pointer to the netfs definition. It returns 0 or an error as
  202. appropriate.
  203. For kAFS, registration is done as follows:
  204. ret = fscache_register_netfs(&afs_cache_netfs);
  205. The last step is, of course, unregistration:
  206. void fscache_unregister_netfs(struct fscache_netfs *netfs);
  207. ================
  208. CACHE TAG LOOKUP
  209. ================
  210. FS-Cache permits the use of more than one cache. To permit particular index
  211. subtrees to be bound to particular caches, the second step is to look up cache
  212. representation tags. This step is optional; it can be left entirely up to
  213. FS-Cache as to which cache should be used. The problem with doing that is that
  214. FS-Cache will always pick the first cache that was registered.
  215. To get the representation for a named tag:
  216. struct fscache_cache_tag *fscache_lookup_cache_tag(const char *name);
  217. This takes a text string as the name and returns a representation of a tag. It
  218. will never return an error. It may return a dummy tag, however, if it runs out
  219. of memory; this will inhibit caching with this tag.
  220. Any representation so obtained must be released by passing it to this function:
  221. void fscache_release_cache_tag(struct fscache_cache_tag *tag);
  222. The tag will be retrieved by FS-Cache when it calls the object definition
  223. operation select_cache().
  224. ==================
  225. INDEX REGISTRATION
  226. ==================
  227. The third step is to inform FS-Cache about part of an index hierarchy that can
  228. be used to locate files. This is done by requesting a cookie for each index in
  229. the path to the file:
  230. struct fscache_cookie *
  231. fscache_acquire_cookie(struct fscache_cookie *parent,
  232. const struct fscache_object_def *def,
  233. void *netfs_data);
  234. This function creates an index entry in the index represented by parent,
  235. filling in the index entry by calling the operations pointed to by def.
  236. Note that this function never returns an error - all errors are handled
  237. internally. It may, however, return NULL to indicate no cookie. It is quite
  238. acceptable to pass this token back to this function as the parent to another
  239. acquisition (or even to the relinquish cookie, read page and write page
  240. functions - see below).
  241. Note also that no indices are actually created in a cache until a non-index
  242. object needs to be created somewhere down the hierarchy. Furthermore, an index
  243. may be created in several different caches independently at different times.
  244. This is all handled transparently, and the netfs doesn't see any of it.
  245. For example, with AFS, a cell would be added to the primary index. This index
  246. entry would have a dependent inode containing a volume location index for the
  247. volume mappings within this cell:
  248. cell->cache =
  249. fscache_acquire_cookie(afs_cache_netfs.primary_index,
  250. &afs_cell_cache_index_def,
  251. cell);
  252. Then when a volume location was accessed, it would be entered into the cell's
  253. index and an inode would be allocated that acts as a volume type and hash chain
  254. combination:
  255. vlocation->cache =
  256. fscache_acquire_cookie(cell->cache,
  257. &afs_vlocation_cache_index_def,
  258. vlocation);
  259. And then a particular flavour of volume (R/O for example) could be added to
  260. that index, creating another index for vnodes (AFS inode equivalents):
  261. volume->cache =
  262. fscache_acquire_cookie(vlocation->cache,
  263. &afs_volume_cache_index_def,
  264. volume);
  265. ======================
  266. DATA FILE REGISTRATION
  267. ======================
  268. The fourth step is to request a data file be created in the cache. This is
  269. identical to index cookie acquisition. The only difference is that the type in
  270. the object definition should be something other than index type.
  271. vnode->cache =
  272. fscache_acquire_cookie(volume->cache,
  273. &afs_vnode_cache_object_def,
  274. vnode);
  275. =================================
  276. MISCELLANEOUS OBJECT REGISTRATION
  277. =================================
  278. An optional step is to request an object of miscellaneous type be created in
  279. the cache. This is almost identical to index cookie acquisition. The only
  280. difference is that the type in the object definition should be something other
  281. than index type. Whilst the parent object could be an index, it's more likely
  282. it would be some other type of object such as a data file.
  283. xattr->cache =
  284. fscache_acquire_cookie(vnode->cache,
  285. &afs_xattr_cache_object_def,
  286. xattr);
  287. Miscellaneous objects might be used to store extended attributes or directory
  288. entries for example.
  289. ==========================
  290. SETTING THE DATA FILE SIZE
  291. ==========================
  292. The fifth step is to set the physical attributes of the file, such as its size.
  293. This doesn't automatically reserve any space in the cache, but permits the
  294. cache to adjust its metadata for data tracking appropriately:
  295. int fscache_attr_changed(struct fscache_cookie *cookie);
  296. The cache will return -ENOBUFS if there is no backing cache or if there is no
  297. space to allocate any extra metadata required in the cache. The attributes
  298. will be accessed with the get_attr() cookie definition operation.
  299. Note that attempts to read or write data pages in the cache over this size may
  300. be rebuffed with -ENOBUFS.
  301. This operation schedules an attribute adjustment to happen asynchronously at
  302. some point in the future, and as such, it may happen after the function returns
  303. to the caller. The attribute adjustment excludes read and write operations.
  304. =====================
  305. PAGE READ/ALLOC/WRITE
  306. =====================
  307. And the sixth step is to store and retrieve pages in the cache. There are
  308. three functions that are used to do this.
  309. Note:
  310. (1) A page should not be re-read or re-allocated without uncaching it first.
  311. (2) A read or allocated page must be uncached when the netfs page is released
  312. from the pagecache.
  313. (3) A page should only be written to the cache if previous read or allocated.
  314. This permits the cache to maintain its page tracking in proper order.
  315. PAGE READ
  316. ---------
  317. Firstly, the netfs should ask FS-Cache to examine the caches and read the
  318. contents cached for a particular page of a particular file if present, or else
  319. allocate space to store the contents if not:
  320. typedef
  321. void (*fscache_rw_complete_t)(struct page *page,
  322. void *context,
  323. int error);
  324. int fscache_read_or_alloc_page(struct fscache_cookie *cookie,
  325. struct page *page,
  326. fscache_rw_complete_t end_io_func,
  327. void *context,
  328. gfp_t gfp);
  329. The cookie argument must specify a cookie for an object that isn't an index,
  330. the page specified will have the data loaded into it (and is also used to
  331. specify the page number), and the gfp argument is used to control how any
  332. memory allocations made are satisfied.
  333. If the cookie indicates the inode is not cached:
  334. (1) The function will return -ENOBUFS.
  335. Else if there's a copy of the page resident in the cache:
  336. (1) The mark_pages_cached() cookie operation will be called on that page.
  337. (2) The function will submit a request to read the data from the cache's
  338. backing device directly into the page specified.
  339. (3) The function will return 0.
  340. (4) When the read is complete, end_io_func() will be invoked with:
  341. (*) The netfs data supplied when the cookie was created.
  342. (*) The page descriptor.
  343. (*) The context argument passed to the above function. This will be
  344. maintained with the get_context/put_context functions mentioned above.
  345. (*) An argument that's 0 on success or negative for an error code.
  346. If an error occurs, it should be assumed that the page contains no usable
  347. data.
  348. end_io_func() will be called in process context if the read is results in
  349. an error, but it might be called in interrupt context if the read is
  350. successful.
  351. Otherwise, if there's not a copy available in cache, but the cache may be able
  352. to store the page:
  353. (1) The mark_pages_cached() cookie operation will be called on that page.
  354. (2) A block may be reserved in the cache and attached to the object at the
  355. appropriate place.
  356. (3) The function will return -ENODATA.
  357. This function may also return -ENOMEM or -EINTR, in which case it won't have
  358. read any data from the cache.
  359. PAGE ALLOCATE
  360. -------------
  361. Alternatively, if there's not expected to be any data in the cache for a page
  362. because the file has been extended, a block can simply be allocated instead:
  363. int fscache_alloc_page(struct fscache_cookie *cookie,
  364. struct page *page,
  365. gfp_t gfp);
  366. This is similar to the fscache_read_or_alloc_page() function, except that it
  367. never reads from the cache. It will return 0 if a block has been allocated,
  368. rather than -ENODATA as the other would. One or the other must be performed
  369. before writing to the cache.
  370. The mark_pages_cached() cookie operation will be called on the page if
  371. successful.
  372. PAGE WRITE
  373. ----------
  374. Secondly, if the netfs changes the contents of the page (either due to an
  375. initial download or if a user performs a write), then the page should be
  376. written back to the cache:
  377. int fscache_write_page(struct fscache_cookie *cookie,
  378. struct page *page,
  379. gfp_t gfp);
  380. The cookie argument must specify a data file cookie, the page specified should
  381. contain the data to be written (and is also used to specify the page number),
  382. and the gfp argument is used to control how any memory allocations made are
  383. satisfied.
  384. The page must have first been read or allocated successfully and must not have
  385. been uncached before writing is performed.
  386. If the cookie indicates the inode is not cached then:
  387. (1) The function will return -ENOBUFS.
  388. Else if space can be allocated in the cache to hold this page:
  389. (1) PG_fscache_write will be set on the page.
  390. (2) The function will submit a request to write the data to cache's backing
  391. device directly from the page specified.
  392. (3) The function will return 0.
  393. (4) When the write is complete PG_fscache_write is cleared on the page and
  394. anyone waiting for that bit will be woken up.
  395. Else if there's no space available in the cache, -ENOBUFS will be returned. It
  396. is also possible for the PG_fscache_write bit to be cleared when no write took
  397. place if unforeseen circumstances arose (such as a disk error).
  398. Writing takes place asynchronously.
  399. MULTIPLE PAGE READ
  400. ------------------
  401. A facility is provided to read several pages at once, as requested by the
  402. readpages() address space operation:
  403. int fscache_read_or_alloc_pages(struct fscache_cookie *cookie,
  404. struct address_space *mapping,
  405. struct list_head *pages,
  406. int *nr_pages,
  407. fscache_rw_complete_t end_io_func,
  408. void *context,
  409. gfp_t gfp);
  410. This works in a similar way to fscache_read_or_alloc_page(), except:
  411. (1) Any page it can retrieve data for is removed from pages and nr_pages and
  412. dispatched for reading to the disk. Reads of adjacent pages on disk may
  413. be merged for greater efficiency.
  414. (2) The mark_pages_cached() cookie operation will be called on several pages
  415. at once if they're being read or allocated.
  416. (3) If there was an general error, then that error will be returned.
  417. Else if some pages couldn't be allocated or read, then -ENOBUFS will be
  418. returned.
  419. Else if some pages couldn't be read but were allocated, then -ENODATA will
  420. be returned.
  421. Otherwise, if all pages had reads dispatched, then 0 will be returned, the
  422. list will be empty and *nr_pages will be 0.
  423. (4) end_io_func will be called once for each page being read as the reads
  424. complete. It will be called in process context if error != 0, but it may
  425. be called in interrupt context if there is no error.
  426. Note that a return of -ENODATA, -ENOBUFS or any other error does not preclude
  427. some of the pages being read and some being allocated. Those pages will have
  428. been marked appropriately and will need uncaching.
  429. ==============
  430. PAGE UNCACHING
  431. ==============
  432. To uncache a page, this function should be called:
  433. void fscache_uncache_page(struct fscache_cookie *cookie,
  434. struct page *page);
  435. This function permits the cache to release any in-memory representation it
  436. might be holding for this netfs page. This function must be called once for
  437. each page on which the read or write page functions above have been called to
  438. make sure the cache's in-memory tracking information gets torn down.
  439. Note that pages can't be explicitly deleted from the a data file. The whole
  440. data file must be retired (see the relinquish cookie function below).
  441. Furthermore, note that this does not cancel the asynchronous read or write
  442. operation started by the read/alloc and write functions, so the page
  443. invalidation functions must use:
  444. bool fscache_check_page_write(struct fscache_cookie *cookie,
  445. struct page *page);
  446. to see if a page is being written to the cache, and:
  447. void fscache_wait_on_page_write(struct fscache_cookie *cookie,
  448. struct page *page);
  449. to wait for it to finish if it is.
  450. When releasepage() is being implemented, a special FS-Cache function exists to
  451. manage the heuristics of coping with vmscan trying to eject pages, which may
  452. conflict with the cache trying to write pages to the cache (which may itself
  453. need to allocate memory):
  454. bool fscache_maybe_release_page(struct fscache_cookie *cookie,
  455. struct page *page,
  456. gfp_t gfp);
  457. This takes the netfs cookie, and the page and gfp arguments as supplied to
  458. releasepage(). It will return false if the page cannot be released yet for
  459. some reason and if it returns true, the page has been uncached and can now be
  460. released.
  461. To make a page available for release, this function may wait for an outstanding
  462. storage request to complete, or it may attempt to cancel the storage request -
  463. in which case the page will not be stored in the cache this time.
  464. BULK INODE PAGE UNCACHE
  465. -----------------------
  466. A convenience routine is provided to perform an uncache on all the pages
  467. attached to an inode. This assumes that the pages on the inode correspond on a
  468. 1:1 basis with the pages in the cache.
  469. void fscache_uncache_all_inode_pages(struct fscache_cookie *cookie,
  470. struct inode *inode);
  471. This takes the netfs cookie that the pages were cached with and the inode that
  472. the pages are attached to. This function will wait for pages to finish being
  473. written to the cache and for the cache to finish with the page generally. No
  474. error is returned.
  475. ==========================
  476. INDEX AND DATA FILE UPDATE
  477. ==========================
  478. To request an update of the index data for an index or other object, the
  479. following function should be called:
  480. void fscache_update_cookie(struct fscache_cookie *cookie);
  481. This function will refer back to the netfs_data pointer stored in the cookie by
  482. the acquisition function to obtain the data to write into each revised index
  483. entry. The update method in the parent index definition will be called to
  484. transfer the data.
  485. Note that partial updates may happen automatically at other times, such as when
  486. data blocks are added to a data file object.
  487. ===============================
  488. MISCELLANEOUS COOKIE OPERATIONS
  489. ===============================
  490. There are a number of operations that can be used to control cookies:
  491. (*) Cookie pinning:
  492. int fscache_pin_cookie(struct fscache_cookie *cookie);
  493. void fscache_unpin_cookie(struct fscache_cookie *cookie);
  494. These operations permit data cookies to be pinned into the cache and to
  495. have the pinning removed. They are not permitted on index cookies.
  496. The pinning function will return 0 if successful, -ENOBUFS in the cookie
  497. isn't backed by a cache, -EOPNOTSUPP if the cache doesn't support pinning,
  498. -ENOSPC if there isn't enough space to honour the operation, -ENOMEM or
  499. -EIO if there's any other problem.
  500. (*) Data space reservation:
  501. int fscache_reserve_space(struct fscache_cookie *cookie, loff_t size);
  502. This permits a netfs to request cache space be reserved to store up to the
  503. given amount of a file. It is permitted to ask for more than the current
  504. size of the file to allow for future file expansion.
  505. If size is given as zero then the reservation will be cancelled.
  506. The function will return 0 if successful, -ENOBUFS in the cookie isn't
  507. backed by a cache, -EOPNOTSUPP if the cache doesn't support reservations,
  508. -ENOSPC if there isn't enough space to honour the operation, -ENOMEM or
  509. -EIO if there's any other problem.
  510. Note that this doesn't pin an object in a cache; it can still be culled to
  511. make space if it's not in use.
  512. =====================
  513. COOKIE UNREGISTRATION
  514. =====================
  515. To get rid of a cookie, this function should be called.
  516. void fscache_relinquish_cookie(struct fscache_cookie *cookie,
  517. int retire);
  518. If retire is non-zero, then the object will be marked for recycling, and all
  519. copies of it will be removed from all active caches in which it is present.
  520. Not only that but all child objects will also be retired.
  521. If retire is zero, then the object may be available again when next the
  522. acquisition function is called. Retirement here will overrule the pinning on a
  523. cookie.
  524. One very important note - relinquish must NOT be called for a cookie unless all
  525. the cookies for "child" indices, objects and pages have been relinquished
  526. first.
  527. ================================
  528. INDEX AND DATA FILE INVALIDATION
  529. ================================
  530. There is no direct way to invalidate an index subtree or a data file. To do
  531. this, the caller should relinquish and retire the cookie they have, and then
  532. acquire a new one.
  533. ===========================
  534. FS-CACHE SPECIFIC PAGE FLAG
  535. ===========================
  536. FS-Cache makes use of a page flag, PG_private_2, for its own purpose. This is
  537. given the alternative name PG_fscache.
  538. PG_fscache is used to indicate that the page is known by the cache, and that
  539. the cache must be informed if the page is going to go away. It's an indication
  540. to the netfs that the cache has an interest in this page, where an interest may
  541. be a pointer to it, resources allocated or reserved for it, or I/O in progress
  542. upon it.
  543. The netfs can use this information in methods such as releasepage() to
  544. determine whether it needs to uncache a page or update it.
  545. Furthermore, if this bit is set, releasepage() and invalidatepage() operations
  546. will be called on a page to get rid of it, even if PG_private is not set. This
  547. allows caching to attempted on a page before read_cache_pages() to be called
  548. after fscache_read_or_alloc_pages() as the former will try and release pages it
  549. was given under certain circumstances.
  550. This bit does not overlap with such as PG_private. This means that FS-Cache
  551. can be used with a filesystem that uses the block buffering code.
  552. There are a number of operations defined on this flag:
  553. int PageFsCache(struct page *page);
  554. void SetPageFsCache(struct page *page)
  555. void ClearPageFsCache(struct page *page)
  556. int TestSetPageFsCache(struct page *page)
  557. int TestClearPageFsCache(struct page *page)
  558. These functions are bit test, bit set, bit clear, bit test and set and bit
  559. test and clear operations on PG_fscache.