aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--Documentation/filesystems/caching/fscache.txt330
-rw-r--r--Documentation/filesystems/caching/netfs-api.txt778
-rw-r--r--include/linux/fscache.h548
3 files changed, 1656 insertions, 0 deletions
diff --git a/Documentation/filesystems/caching/fscache.txt b/Documentation/filesystems/caching/fscache.txt
new file mode 100644
index 000000000000..a759d916273e
--- /dev/null
+++ b/Documentation/filesystems/caching/fscache.txt
@@ -0,0 +1,330 @@
1 ==========================
2 General Filesystem Caching
3 ==========================
4
5========
6OVERVIEW
7========
8
9This facility is a general purpose cache for network filesystems, though it
10could be used for caching other things such as ISO9660 filesystems too.
11
12FS-Cache mediates between cache backends (such as CacheFS) and network
13filesystems:
14
15 +---------+
16 | | +--------------+
17 | NFS |--+ | |
18 | | | +-->| CacheFS |
19 +---------+ | +----------+ | | /dev/hda5 |
20 | | | | +--------------+
21 +---------+ +-->| | |
22 | | | |--+
23 | AFS |----->| FS-Cache |
24 | | | |--+
25 +---------+ +-->| | |
26 | | | | +--------------+
27 +---------+ | +----------+ | | |
28 | | | +-->| CacheFiles |
29 | ISOFS |--+ | /var/cache |
30 | | +--------------+
31 +---------+
32
33Or to look at it another way, FS-Cache is a module that provides a caching
34facility to a network filesystem such that the cache is transparent to the
35user:
36
37 +---------+
38 | |
39 | Server |
40 | |
41 +---------+
42 | NETWORK
43 ~~~~~|~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
44 |
45 | +----------+
46 V | |
47 +---------+ | |
48 | | | |
49 | NFS |----->| FS-Cache |
50 | | | |--+
51 +---------+ | | | +--------------+ +--------------+
52 | | | | | | | |
53 V +----------+ +-->| CacheFiles |-->| Ext3 |
54 +---------+ | /var/cache | | /dev/sda6 |
55 | | +--------------+ +--------------+
56 | VFS | ^ ^
57 | | | |
58 +---------+ +--------------+ |
59 | KERNEL SPACE | |
60 ~~~~~|~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~|~~~~~~|~~~~
61 | USER SPACE | |
62 V | |
63 +---------+ +--------------+
64 | | | |
65 | Process | | cachefilesd |
66 | | | |
67 +---------+ +--------------+
68
69
70FS-Cache does not follow the idea of completely loading every netfs file
71opened in its entirety into a cache before permitting it to be accessed and
72then serving the pages out of that cache rather than the netfs inode because:
73
74 (1) It must be practical to operate without a cache.
75
76 (2) The size of any accessible file must not be limited to the size of the
77 cache.
78
79 (3) The combined size of all opened files (this includes mapped libraries)
80 must not be limited to the size of the cache.
81
82 (4) The user should not be forced to download an entire file just to do a
83 one-off access of a small portion of it (such as might be done with the
84 "file" program).
85
86It instead serves the cache out in PAGE_SIZE chunks as and when requested by
87the netfs('s) using it.
88
89
90FS-Cache provides the following facilities:
91
92 (1) More than one cache can be used at once. Caches can be selected
93 explicitly by use of tags.
94
95 (2) Caches can be added / removed at any time.
96
97 (3) The netfs is provided with an interface that allows either party to
98 withdraw caching facilities from a file (required for (2)).
99
100 (4) The interface to the netfs returns as few errors as possible, preferring
101 rather to let the netfs remain oblivious.
102
103 (5) Cookies are used to represent indices, files and other objects to the
104 netfs. The simplest cookie is just a NULL pointer - indicating nothing
105 cached there.
106
107 (6) The netfs is allowed to propose - dynamically - any index hierarchy it
108 desires, though it must be aware that the index search function is
109 recursive, stack space is limited, and indices can only be children of
110 indices.
111
112 (7) Data I/O is done direct to and from the netfs's pages. The netfs
113 indicates that page A is at index B of the data-file represented by cookie
114 C, and that it should be read or written. The cache backend may or may
115 not start I/O on that page, but if it does, a netfs callback will be
116 invoked to indicate completion. The I/O may be either synchronous or
117 asynchronous.
118
119 (8) Cookies can be "retired" upon release. At this point FS-Cache will mark
120 them as obsolete and the index hierarchy rooted at that point will get
121 recycled.
122
123 (9) The netfs provides a "match" function for index searches. In addition to
124 saying whether a match was made or not, this can also specify that an
125 entry should be updated or deleted.
126
127(10) As much as possible is done asynchronously.
128
129
130FS-Cache maintains a virtual indexing tree in which all indices, files, objects
131and pages are kept. Bits of this tree may actually reside in one or more
132caches.
133
134 FSDEF
135 |
136 +------------------------------------+
137 | |
138 NFS AFS
139 | |
140 +--------------------------+ +-----------+
141 | | | |
142 homedir mirror afs.org redhat.com
143 | | |
144 +------------+ +---------------+ +----------+
145 | | | | | |
146 00001 00002 00007 00125 vol00001 vol00002
147 | | | | |
148 +---+---+ +-----+ +---+ +------+------+ +-----+----+
149 | | | | | | | | | | | | |
150PG0 PG1 PG2 PG0 XATTR PG0 PG1 DIRENT DIRENT DIRENT R/W R/O Bak
151 | |
152 PG0 +-------+
153 | |
154 00001 00003
155 |
156 +---+---+
157 | | |
158 PG0 PG1 PG2
159
160In the example above, you can see two netfs's being backed: NFS and AFS. These
161have different index hierarchies:
162
163 (*) The NFS primary index contains per-server indices. Each server index is
164 indexed by NFS file handles to get data file objects. Each data file
165 objects can have an array of pages, but may also have further child
166 objects, such as extended attributes and directory entries. Extended
167 attribute objects themselves have page-array contents.
168
169 (*) The AFS primary index contains per-cell indices. Each cell index contains
170 per-logical-volume indices. Each of volume index contains up to three
171 indices for the read-write, read-only and backup mirrors of those volumes.
172 Each of these contains vnode data file objects, each of which contains an
173 array of pages.
174
175The very top index is the FS-Cache master index in which individual netfs's
176have entries.
177
178Any index object may reside in more than one cache, provided it only has index
179children. Any index with non-index object children will be assumed to only
180reside in one cache.
181
182
183The netfs API to FS-Cache can be found in:
184
185 Documentation/filesystems/caching/netfs-api.txt
186
187The cache backend API to FS-Cache can be found in:
188
189 Documentation/filesystems/caching/backend-api.txt
190
191
192=======================
193STATISTICAL INFORMATION
194=======================
195
196If FS-Cache is compiled with the following options enabled:
197
198 CONFIG_FSCACHE_PROC=y (implied by the following two)
199 CONFIG_FSCACHE_STATS=y
200 CONFIG_FSCACHE_HISTOGRAM=y
201
202then it will gather certain statistics and display them through a number of
203proc files.
204
205 (*) /proc/fs/fscache/stats
206
207 This shows counts of a number of events that can happen in FS-Cache:
208
209 CLASS EVENT MEANING
210 ======= ======= =======================================================
211 Cookies idx=N Number of index cookies allocated
212 dat=N Number of data storage cookies allocated
213 spc=N Number of special cookies allocated
214 Objects alc=N Number of objects allocated
215 nal=N Number of object allocation failures
216 avl=N Number of objects that reached the available state
217 ded=N Number of objects that reached the dead state
218 ChkAux non=N Number of objects that didn't have a coherency check
219 ok=N Number of objects that passed a coherency check
220 upd=N Number of objects that needed a coherency data update
221 obs=N Number of objects that were declared obsolete
222 Pages mrk=N Number of pages marked as being cached
223 unc=N Number of uncache page requests seen
224 Acquire n=N Number of acquire cookie requests seen
225 nul=N Number of acq reqs given a NULL parent
226 noc=N Number of acq reqs rejected due to no cache available
227 ok=N Number of acq reqs succeeded
228 nbf=N Number of acq reqs rejected due to error
229 oom=N Number of acq reqs failed on ENOMEM
230 Lookups n=N Number of lookup calls made on cache backends
231 neg=N Number of negative lookups made
232 pos=N Number of positive lookups made
233 crt=N Number of objects created by lookup
234 Updates n=N Number of update cookie requests seen
235 nul=N Number of upd reqs given a NULL parent
236 run=N Number of upd reqs granted CPU time
237 Relinqs n=N Number of relinquish cookie requests seen
238 nul=N Number of rlq reqs given a NULL parent
239 wcr=N Number of rlq reqs waited on completion of creation
240 AttrChg n=N Number of attribute changed requests seen
241 ok=N Number of attr changed requests queued
242 nbf=N Number of attr changed rejected -ENOBUFS
243 oom=N Number of attr changed failed -ENOMEM
244 run=N Number of attr changed ops given CPU time
245 Allocs n=N Number of allocation requests seen
246 ok=N Number of successful alloc reqs
247 wt=N Number of alloc reqs that waited on lookup completion
248 nbf=N Number of alloc reqs rejected -ENOBUFS
249 ops=N Number of alloc reqs submitted
250 owt=N Number of alloc reqs waited for CPU time
251 Retrvls n=N Number of retrieval (read) requests seen
252 ok=N Number of successful retr reqs
253 wt=N Number of retr reqs that waited on lookup completion
254 nod=N Number of retr reqs returned -ENODATA
255 nbf=N Number of retr reqs rejected -ENOBUFS
256 int=N Number of retr reqs aborted -ERESTARTSYS
257 oom=N Number of retr reqs failed -ENOMEM
258 ops=N Number of retr reqs submitted
259 owt=N Number of retr reqs waited for CPU time
260 Stores n=N Number of storage (write) requests seen
261 ok=N Number of successful store reqs
262 agn=N Number of store reqs on a page already pending storage
263 nbf=N Number of store reqs rejected -ENOBUFS
264 oom=N Number of store reqs failed -ENOMEM
265 ops=N Number of store reqs submitted
266 run=N Number of store reqs granted CPU time
267 Ops pend=N Number of times async ops added to pending queues
268 run=N Number of times async ops given CPU time
269 enq=N Number of times async ops queued for processing
270 dfr=N Number of async ops queued for deferred release
271 rel=N Number of async ops released
272 gc=N Number of deferred-release async ops garbage collected
273
274
275 (*) /proc/fs/fscache/histogram
276
277 cat /proc/fs/fscache/histogram
278 +HZ +TIME OBJ INST OP RUNS OBJ RUNS RETRV DLY RETRIEVLS
279 ===== ===== ========= ========= ========= ========= =========
280
281 This shows the breakdown of the number of times each amount of time
282 between 0 jiffies and HZ-1 jiffies a variety of tasks took to run. The
283 columns are as follows:
284
285 COLUMN TIME MEASUREMENT
286 ======= =======================================================
287 OBJ INST Length of time to instantiate an object
288 OP RUNS Length of time a call to process an operation took
289 OBJ RUNS Length of time a call to process an object event took
290 RETRV DLY Time between an requesting a read and lookup completing
291 RETRIEVLS Time between beginning and end of a retrieval
292
293 Each row shows the number of events that took a particular range of times.
294 Each step is 1 jiffy in size. The +HZ column indicates the particular
295 jiffy range covered, and the +TIME field the equivalent number of seconds.
296
297
298=========
299DEBUGGING
300=========
301
302The FS-Cache facility can have runtime debugging enabled by adjusting the value
303in:
304
305 /sys/module/fscache/parameters/debug
306
307This is a bitmask of debugging streams to enable:
308
309 BIT VALUE STREAM POINT
310 ======= ======= =============================== =======================
311 0 1 Cache management Function entry trace
312 1 2 Function exit trace
313 2 4 General
314 3 8 Cookie management Function entry trace
315 4 16 Function exit trace
316 5 32 General
317 6 64 Page handling Function entry trace
318 7 128 Function exit trace
319 8 256 General
320 9 512 Operation management Function entry trace
321 10 1024 Function exit trace
322 11 2048 General
323
324The appropriate set of values should be OR'd together and the result written to
325the control file. For example:
326
327 echo $((1|8|64)) >/sys/module/fscache/parameters/debug
328
329will turn on all function entry debugging.
330
diff --git a/Documentation/filesystems/caching/netfs-api.txt b/Documentation/filesystems/caching/netfs-api.txt
new file mode 100644
index 000000000000..4db125b3a5c6
--- /dev/null
+++ b/Documentation/filesystems/caching/netfs-api.txt
@@ -0,0 +1,778 @@
1 ===============================
2 FS-CACHE NETWORK FILESYSTEM API
3 ===============================
4
5There's an API by which a network filesystem can make use of the FS-Cache
6facilities. This is based around a number of principles:
7
8 (1) Caches can store a number of different object types. There are two main
9 object types: indices and files. The first is a special type used by
10 FS-Cache to make finding objects faster and to make retiring of groups of
11 objects easier.
12
13 (2) Every index, file or other object is represented by a cookie. This cookie
14 may or may not have anything associated with it, but the netfs doesn't
15 need to care.
16
17 (3) Barring the top-level index (one entry per cached netfs), the index
18 hierarchy for each netfs is structured according the whim of the netfs.
19
20This API is declared in <linux/fscache.h>.
21
22This document contains the following sections:
23
24 (1) Network filesystem definition
25 (2) Index definition
26 (3) Object definition
27 (4) Network filesystem (un)registration
28 (5) Cache tag lookup
29 (6) Index registration
30 (7) Data file registration
31 (8) Miscellaneous object registration
32 (9) Setting the data file size
33 (10) Page alloc/read/write
34 (11) Page uncaching
35 (12) Index and data file update
36 (13) Miscellaneous cookie operations
37 (14) Cookie unregistration
38 (15) Index and data file invalidation
39 (16) FS-Cache specific page flags.
40
41
42=============================
43NETWORK FILESYSTEM DEFINITION
44=============================
45
46FS-Cache needs a description of the network filesystem. This is specified
47using a record of the following structure:
48
49 struct fscache_netfs {
50 uint32_t version;
51 const char *name;
52 struct fscache_cookie *primary_index;
53 ...
54 };
55
56This first two fields should be filled in before registration, and the third
57will be filled in by the registration function; any other fields should just be
58ignored and are for internal use only.
59
60The fields are:
61
62 (1) The name of the netfs (used as the key in the toplevel index).
63
64 (2) The version of the netfs (if the name matches but the version doesn't, the
65 entire in-cache hierarchy for this netfs will be scrapped and begun
66 afresh).
67
68 (3) The cookie representing the primary index will be allocated according to
69 another parameter passed into the registration function.
70
71For example, kAFS (linux/fs/afs/) uses the following definitions to describe
72itself:
73
74 struct fscache_netfs afs_cache_netfs = {
75 .version = 0,
76 .name = "afs",
77 };
78
79
80================
81INDEX DEFINITION
82================
83
84Indices are used for two purposes:
85
86 (1) To aid the finding of a file based on a series of keys (such as AFS's
87 "cell", "volume ID", "vnode ID").
88
89 (2) To make it easier to discard a subset of all the files cached based around
90 a particular key - for instance to mirror the removal of an AFS volume.
91
92However, since it's unlikely that any two netfs's are going to want to define
93their index hierarchies in quite the same way, FS-Cache tries to impose as few
94restraints as possible on how an index is structured and where it is placed in
95the tree. The netfs can even mix indices and data files at the same level, but
96it's not recommended.
97
98Each index entry consists of a key of indeterminate length plus some auxilliary
99data, also of indeterminate length.
100
101There are some limits on indices:
102
103 (1) Any index containing non-index objects should be restricted to a single
104 cache. Any such objects created within an index will be created in the
105 first cache only. The cache in which an index is created can be
106 controlled by cache tags (see below).
107
108 (2) The entry data must be atomically journallable, so it is limited to about
109 400 bytes at present. At least 400 bytes will be available.
110
111 (3) The depth of the index tree should be judged with care as the search
112 function is recursive. Too many layers will run the kernel out of stack.
113
114
115=================
116OBJECT DEFINITION
117=================
118
119To define an object, a structure of the following type should be filled out:
120
121 struct fscache_cookie_def
122 {
123 uint8_t name[16];
124 uint8_t type;
125
126 struct fscache_cache_tag *(*select_cache)(
127 const void *parent_netfs_data,
128 const void *cookie_netfs_data);
129
130 uint16_t (*get_key)(const void *cookie_netfs_data,
131 void *buffer,
132 uint16_t bufmax);
133
134 void (*get_attr)(const void *cookie_netfs_data,
135 uint64_t *size);
136
137 uint16_t (*get_aux)(const void *cookie_netfs_data,
138 void *buffer,
139 uint16_t bufmax);
140
141 enum fscache_checkaux (*check_aux)(void *cookie_netfs_data,
142 const void *data,
143 uint16_t datalen);
144
145 void (*get_context)(void *cookie_netfs_data, void *context);
146
147 void (*put_context)(void *cookie_netfs_data, void *context);
148
149 void (*mark_pages_cached)(void *cookie_netfs_data,
150 struct address_space *mapping,
151 struct pagevec *cached_pvec);
152
153 void (*now_uncached)(void *cookie_netfs_data);
154 };
155
156This has the following fields:
157
158 (1) The type of the object [mandatory].
159
160 This is one of the following values:
161
162 (*) FSCACHE_COOKIE_TYPE_INDEX
163
164 This defines an index, which is a special FS-Cache type.
165
166 (*) FSCACHE_COOKIE_TYPE_DATAFILE
167
168 This defines an ordinary data file.
169
170 (*) Any other value between 2 and 255
171
172 This defines an extraordinary object such as an XATTR.
173
174 (2) The name of the object type (NUL terminated unless all 16 chars are used)
175 [optional].
176
177 (3) A function to select the cache in which to store an index [optional].
178
179 This function is invoked when an index needs to be instantiated in a cache
180 during the instantiation of a non-index object. Only the immediate index
181 parent for the non-index object will be queried. Any indices above that
182 in the hierarchy may be stored in multiple caches. This function does not
183 need to be supplied for any non-index object or any index that will only
184 have index children.
185
186 If this function is not supplied or if it returns NULL then the first
187 cache in the parent's list will be chosed, or failing that, the first
188 cache in the master list.
189
190 (4) A function to retrieve an object's key from the netfs [mandatory].
191
192 This function will be called with the netfs data that was passed to the
193 cookie acquisition function and the maximum length of key data that it may
194 provide. It should write the required key data into the given buffer and
195 return the quantity it wrote.
196
197 (5) A function to retrieve attribute data from the netfs [optional].
198
199 This function will be called with the netfs data that was passed to the
200 cookie acquisition function. It should return the size of the file if
201 this is a data file. The size may be used to govern how much cache must
202 be reserved for this file in the cache.
203
204 If the function is absent, a file size of 0 is assumed.
205
206 (6) A function to retrieve auxilliary data from the netfs [optional].
207
208 This function will be called with the netfs data that was passed to the
209 cookie acquisition function and the maximum length of auxilliary data that
210 it may provide. It should write the auxilliary data into the given buffer
211 and return the quantity it wrote.
212
213 If this function is absent, the auxilliary data length will be set to 0.
214
215 The length of the auxilliary data buffer may be dependent on the key
216 length. A netfs mustn't rely on being able to provide more than 400 bytes
217 for both.
218
219 (7) A function to check the auxilliary data [optional].
220
221 This function will be called to check that a match found in the cache for
222 this object is valid. For instance with AFS it could check the auxilliary
223 data against the data version number returned by the server to determine
224 whether the index entry in a cache is still valid.
225
226 If this function is absent, it will be assumed that matching objects in a
227 cache are always valid.
228
229 If present, the function should return one of the following values:
230
231 (*) FSCACHE_CHECKAUX_OKAY - the entry is okay as is
232 (*) FSCACHE_CHECKAUX_NEEDS_UPDATE - the entry requires update
233 (*) FSCACHE_CHECKAUX_OBSOLETE - the entry should be deleted
234
235 This function can also be used to extract data from the auxilliary data in
236 the cache and copy it into the netfs's structures.
237
238 (8) A pair of functions to manage contexts for the completion callback
239 [optional].
240
241 The cache read/write functions are passed a context which is then passed
242 to the I/O completion callback function. To ensure this context remains
243 valid until after the I/O completion is called, two functions may be
244 provided: one to get an extra reference on the context, and one to drop a
245 reference to it.
246
247 If the context is not used or is a type of object that won't go out of
248 scope, then these functions are not required. These functions are not
249 required for indices as indices may not contain data. These functions may
250 be called in interrupt context and so may not sleep.
251
252 (9) A function to mark a page as retaining cache metadata [optional].
253
254 This is called by the cache to indicate that it is retaining in-memory
255 information for this page and that the netfs should uncache the page when
256 it has finished. This does not indicate whether there's data on the disk
257 or not. Note that several pages at once may be presented for marking.
258
259 The PG_fscache bit is set on the pages before this function would be
260 called, so the function need not be provided if this is sufficient.
261
262 This function is not required for indices as they're not permitted data.
263
264(10) A function to unmark all the pages retaining cache metadata [mandatory].
265
266 This is called by FS-Cache to indicate that a backing store is being
267 unbound from a cookie and that all the marks on the pages should be
268 cleared to prevent confusion. Note that the cache will have torn down all
269 its tracking information so that the pages don't need to be explicitly
270 uncached.
271
272 This function is not required for indices as they're not permitted data.
273
274
275===================================
276NETWORK FILESYSTEM (UN)REGISTRATION
277===================================
278
279The first step is to declare the network filesystem to the cache. This also
280involves specifying the layout of the primary index (for AFS, this would be the
281"cell" level).
282
283The registration function is:
284
285 int fscache_register_netfs(struct fscache_netfs *netfs);
286
287It just takes a pointer to the netfs definition. It returns 0 or an error as
288appropriate.
289
290For kAFS, registration is done as follows:
291
292 ret = fscache_register_netfs(&afs_cache_netfs);
293
294The last step is, of course, unregistration:
295
296 void fscache_unregister_netfs(struct fscache_netfs *netfs);
297
298
299================
300CACHE TAG LOOKUP
301================
302
303FS-Cache permits the use of more than one cache. To permit particular index
304subtrees to be bound to particular caches, the second step is to look up cache
305representation tags. This step is optional; it can be left entirely up to
306FS-Cache as to which cache should be used. The problem with doing that is that
307FS-Cache will always pick the first cache that was registered.
308
309To get the representation for a named tag:
310
311 struct fscache_cache_tag *fscache_lookup_cache_tag(const char *name);
312
313This takes a text string as the name and returns a representation of a tag. It
314will never return an error. It may return a dummy tag, however, if it runs out
315of memory; this will inhibit caching with this tag.
316
317Any representation so obtained must be released by passing it to this function:
318
319 void fscache_release_cache_tag(struct fscache_cache_tag *tag);
320
321The tag will be retrieved by FS-Cache when it calls the object definition
322operation select_cache().
323
324
325==================
326INDEX REGISTRATION
327==================
328
329The third step is to inform FS-Cache about part of an index hierarchy that can
330be used to locate files. This is done by requesting a cookie for each index in
331the path to the file:
332
333 struct fscache_cookie *
334 fscache_acquire_cookie(struct fscache_cookie *parent,
335 const struct fscache_object_def *def,
336 void *netfs_data);
337
338This function creates an index entry in the index represented by parent,
339filling in the index entry by calling the operations pointed to by def.
340
341Note that this function never returns an error - all errors are handled
342internally. It may, however, return NULL to indicate no cookie. It is quite
343acceptable to pass this token back to this function as the parent to another
344acquisition (or even to the relinquish cookie, read page and write page
345functions - see below).
346
347Note also that no indices are actually created in a cache until a non-index
348object needs to be created somewhere down the hierarchy. Furthermore, an index
349may be created in several different caches independently at different times.
350This is all handled transparently, and the netfs doesn't see any of it.
351
352For example, with AFS, a cell would be added to the primary index. This index
353entry would have a dependent inode containing a volume location index for the
354volume mappings within this cell:
355
356 cell->cache =
357 fscache_acquire_cookie(afs_cache_netfs.primary_index,
358 &afs_cell_cache_index_def,
359 cell);
360
361Then when a volume location was accessed, it would be entered into the cell's
362index and an inode would be allocated that acts as a volume type and hash chain
363combination:
364
365 vlocation->cache =
366 fscache_acquire_cookie(cell->cache,
367 &afs_vlocation_cache_index_def,
368 vlocation);
369
370And then a particular flavour of volume (R/O for example) could be added to
371that index, creating another index for vnodes (AFS inode equivalents):
372
373 volume->cache =
374 fscache_acquire_cookie(vlocation->cache,
375 &afs_volume_cache_index_def,
376 volume);
377
378
379======================
380DATA FILE REGISTRATION
381======================
382
383The fourth step is to request a data file be created in the cache. This is
384identical to index cookie acquisition. The only difference is that the type in
385the object definition should be something other than index type.
386
387 vnode->cache =
388 fscache_acquire_cookie(volume->cache,
389 &afs_vnode_cache_object_def,
390 vnode);
391
392
393=================================
394MISCELLANEOUS OBJECT REGISTRATION
395=================================
396
397An optional step is to request an object of miscellaneous type be created in
398the cache. This is almost identical to index cookie acquisition. The only
399difference is that the type in the object definition should be something other
400than index type. Whilst the parent object could be an index, it's more likely
401it would be some other type of object such as a data file.
402
403 xattr->cache =
404 fscache_acquire_cookie(vnode->cache,
405 &afs_xattr_cache_object_def,
406 xattr);
407
408Miscellaneous objects might be used to store extended attributes or directory
409entries for example.
410
411
412==========================
413SETTING THE DATA FILE SIZE
414==========================
415
416The fifth step is to set the physical attributes of the file, such as its size.
417This doesn't automatically reserve any space in the cache, but permits the
418cache to adjust its metadata for data tracking appropriately:
419
420 int fscache_attr_changed(struct fscache_cookie *cookie);
421
422The cache will return -ENOBUFS if there is no backing cache or if there is no
423space to allocate any extra metadata required in the cache. The attributes
424will be accessed with the get_attr() cookie definition operation.
425
426Note that attempts to read or write data pages in the cache over this size may
427be rebuffed with -ENOBUFS.
428
429This operation schedules an attribute adjustment to happen asynchronously at
430some point in the future, and as such, it may happen after the function returns
431to the caller. The attribute adjustment excludes read and write operations.
432
433
434=====================
435PAGE READ/ALLOC/WRITE
436=====================
437
438And the sixth step is to store and retrieve pages in the cache. There are
439three functions that are used to do this.
440
441Note:
442
443 (1) A page should not be re-read or re-allocated without uncaching it first.
444
445 (2) A read or allocated page must be uncached when the netfs page is released
446 from the pagecache.
447
448 (3) A page should only be written to the cache if previous read or allocated.
449
450This permits the cache to maintain its page tracking in proper order.
451
452
453PAGE READ
454---------
455
456Firstly, the netfs should ask FS-Cache to examine the caches and read the
457contents cached for a particular page of a particular file if present, or else
458allocate space to store the contents if not:
459
460 typedef
461 void (*fscache_rw_complete_t)(struct page *page,
462 void *context,
463 int error);
464
465 int fscache_read_or_alloc_page(struct fscache_cookie *cookie,
466 struct page *page,
467 fscache_rw_complete_t end_io_func,
468 void *context,
469 gfp_t gfp);
470
471The cookie argument must specify a cookie for an object that isn't an index,
472the page specified will have the data loaded into it (and is also used to
473specify the page number), and the gfp argument is used to control how any
474memory allocations made are satisfied.
475
476If the cookie indicates the inode is not cached:
477
478 (1) The function will return -ENOBUFS.
479
480Else if there's a copy of the page resident in the cache:
481
482 (1) The mark_pages_cached() cookie operation will be called on that page.
483
484 (2) The function will submit a request to read the data from the cache's
485 backing device directly into the page specified.
486
487 (3) The function will return 0.
488
489 (4) When the read is complete, end_io_func() will be invoked with:
490
491 (*) The netfs data supplied when the cookie was created.
492
493 (*) The page descriptor.
494
495 (*) The context argument passed to the above function. This will be
496 maintained with the get_context/put_context functions mentioned above.
497
498 (*) An argument that's 0 on success or negative for an error code.
499
500 If an error occurs, it should be assumed that the page contains no usable
501 data.
502
503 end_io_func() will be called in process context if the read is results in
504 an error, but it might be called in interrupt context if the read is
505 successful.
506
507Otherwise, if there's not a copy available in cache, but the cache may be able
508to store the page:
509
510 (1) The mark_pages_cached() cookie operation will be called on that page.
511
512 (2) A block may be reserved in the cache and attached to the object at the
513 appropriate place.
514
515 (3) The function will return -ENODATA.
516
517This function may also return -ENOMEM or -EINTR, in which case it won't have
518read any data from the cache.
519
520
521PAGE ALLOCATE
522-------------
523
524Alternatively, if there's not expected to be any data in the cache for a page
525because the file has been extended, a block can simply be allocated instead:
526
527 int fscache_alloc_page(struct fscache_cookie *cookie,
528 struct page *page,
529 gfp_t gfp);
530
531This is similar to the fscache_read_or_alloc_page() function, except that it
532never reads from the cache. It will return 0 if a block has been allocated,
533rather than -ENODATA as the other would. One or the other must be performed
534before writing to the cache.
535
536The mark_pages_cached() cookie operation will be called on the page if
537successful.
538
539
540PAGE WRITE
541----------
542
543Secondly, if the netfs changes the contents of the page (either due to an
544initial download or if a user performs a write), then the page should be
545written back to the cache:
546
547 int fscache_write_page(struct fscache_cookie *cookie,
548 struct page *page,
549 gfp_t gfp);
550
551The cookie argument must specify a data file cookie, the page specified should
552contain the data to be written (and is also used to specify the page number),
553and the gfp argument is used to control how any memory allocations made are
554satisfied.
555
556The page must have first been read or allocated successfully and must not have
557been uncached before writing is performed.
558
559If the cookie indicates the inode is not cached then:
560
561 (1) The function will return -ENOBUFS.
562
563Else if space can be allocated in the cache to hold this page:
564
565 (1) PG_fscache_write will be set on the page.
566
567 (2) The function will submit a request to write the data to cache's backing
568 device directly from the page specified.
569
570 (3) The function will return 0.
571
572 (4) When the write is complete PG_fscache_write is cleared on the page and
573 anyone waiting for that bit will be woken up.
574
575Else if there's no space available in the cache, -ENOBUFS will be returned. It
576is also possible for the PG_fscache_write bit to be cleared when no write took
577place if unforeseen circumstances arose (such as a disk error).
578
579Writing takes place asynchronously.
580
581
582MULTIPLE PAGE READ
583------------------
584
585A facility is provided to read several pages at once, as requested by the
586readpages() address space operation:
587
588 int fscache_read_or_alloc_pages(struct fscache_cookie *cookie,
589 struct address_space *mapping,
590 struct list_head *pages,
591 int *nr_pages,
592 fscache_rw_complete_t end_io_func,
593 void *context,
594 gfp_t gfp);
595
596This works in a similar way to fscache_read_or_alloc_page(), except:
597
598 (1) Any page it can retrieve data for is removed from pages and nr_pages and
599 dispatched for reading to the disk. Reads of adjacent pages on disk may
600 be merged for greater efficiency.
601
602 (2) The mark_pages_cached() cookie operation will be called on several pages
603 at once if they're being read or allocated.
604
605 (3) If there was an general error, then that error will be returned.
606
607 Else if some pages couldn't be allocated or read, then -ENOBUFS will be
608 returned.
609
610 Else if some pages couldn't be read but were allocated, then -ENODATA will
611 be returned.
612
613 Otherwise, if all pages had reads dispatched, then 0 will be returned, the
614 list will be empty and *nr_pages will be 0.
615
616 (4) end_io_func will be called once for each page being read as the reads
617 complete. It will be called in process context if error != 0, but it may
618 be called in interrupt context if there is no error.
619
620Note that a return of -ENODATA, -ENOBUFS or any other error does not preclude
621some of the pages being read and some being allocated. Those pages will have
622been marked appropriately and will need uncaching.
623
624
625==============
626PAGE UNCACHING
627==============
628
629To uncache a page, this function should be called:
630
631 void fscache_uncache_page(struct fscache_cookie *cookie,
632 struct page *page);
633
634This function permits the cache to release any in-memory representation it
635might be holding for this netfs page. This function must be called once for
636each page on which the read or write page functions above have been called to
637make sure the cache's in-memory tracking information gets torn down.
638
639Note that pages can't be explicitly deleted from the a data file. The whole
640data file must be retired (see the relinquish cookie function below).
641
642Furthermore, note that this does not cancel the asynchronous read or write
643operation started by the read/alloc and write functions, so the page
644invalidation and release functions must use:
645
646 bool fscache_check_page_write(struct fscache_cookie *cookie,
647 struct page *page);
648
649to see if a page is being written to the cache, and:
650
651 void fscache_wait_on_page_write(struct fscache_cookie *cookie,
652 struct page *page);
653
654to wait for it to finish if it is.
655
656
657==========================
658INDEX AND DATA FILE UPDATE
659==========================
660
661To request an update of the index data for an index or other object, the
662following function should be called:
663
664 void fscache_update_cookie(struct fscache_cookie *cookie);
665
666This function will refer back to the netfs_data pointer stored in the cookie by
667the acquisition function to obtain the data to write into each revised index
668entry. The update method in the parent index definition will be called to
669transfer the data.
670
671Note that partial updates may happen automatically at other times, such as when
672data blocks are added to a data file object.
673
674
675===============================
676MISCELLANEOUS COOKIE OPERATIONS
677===============================
678
679There are a number of operations that can be used to control cookies:
680
681 (*) Cookie pinning:
682
683 int fscache_pin_cookie(struct fscache_cookie *cookie);
684 void fscache_unpin_cookie(struct fscache_cookie *cookie);
685
686 These operations permit data cookies to be pinned into the cache and to
687 have the pinning removed. They are not permitted on index cookies.
688
689 The pinning function will return 0 if successful, -ENOBUFS in the cookie
690 isn't backed by a cache, -EOPNOTSUPP if the cache doesn't support pinning,
691 -ENOSPC if there isn't enough space to honour the operation, -ENOMEM or
692 -EIO if there's any other problem.
693
694 (*) Data space reservation:
695
696 int fscache_reserve_space(struct fscache_cookie *cookie, loff_t size);
697
698 This permits a netfs to request cache space be reserved to store up to the
699 given amount of a file. It is permitted to ask for more than the current
700 size of the file to allow for future file expansion.
701
702 If size is given as zero then the reservation will be cancelled.
703
704 The function will return 0 if successful, -ENOBUFS in the cookie isn't
705 backed by a cache, -EOPNOTSUPP if the cache doesn't support reservations,
706 -ENOSPC if there isn't enough space to honour the operation, -ENOMEM or
707 -EIO if there's any other problem.
708
709 Note that this doesn't pin an object in a cache; it can still be culled to
710 make space if it's not in use.
711
712
713=====================
714COOKIE UNREGISTRATION
715=====================
716
717To get rid of a cookie, this function should be called.
718
719 void fscache_relinquish_cookie(struct fscache_cookie *cookie,
720 int retire);
721
722If retire is non-zero, then the object will be marked for recycling, and all
723copies of it will be removed from all active caches in which it is present.
724Not only that but all child objects will also be retired.
725
726If retire is zero, then the object may be available again when next the
727acquisition function is called. Retirement here will overrule the pinning on a
728cookie.
729
730One very important note - relinquish must NOT be called for a cookie unless all
731the cookies for "child" indices, objects and pages have been relinquished
732first.
733
734
735================================
736INDEX AND DATA FILE INVALIDATION
737================================
738
739There is no direct way to invalidate an index subtree or a data file. To do
740this, the caller should relinquish and retire the cookie they have, and then
741acquire a new one.
742
743
744===========================
745FS-CACHE SPECIFIC PAGE FLAG
746===========================
747
748FS-Cache makes use of a page flag, PG_private_2, for its own purpose. This is
749given the alternative name PG_fscache.
750
751PG_fscache is used to indicate that the page is known by the cache, and that
752the cache must be informed if the page is going to go away. It's an indication
753to the netfs that the cache has an interest in this page, where an interest may
754be a pointer to it, resources allocated or reserved for it, or I/O in progress
755upon it.
756
757The netfs can use this information in methods such as releasepage() to
758determine whether it needs to uncache a page or update it.
759
760Furthermore, if this bit is set, releasepage() and invalidatepage() operations
761will be called on a page to get rid of it, even if PG_private is not set. This
762allows caching to attempted on a page before read_cache_pages() to be called
763after fscache_read_or_alloc_pages() as the former will try and release pages it
764was given under certain circumstances.
765
766This bit does not overlap with such as PG_private. This means that FS-Cache
767can be used with a filesystem that uses the block buffering code.
768
769There are a number of operations defined on this flag:
770
771 int PageFsCache(struct page *page);
772 void SetPageFsCache(struct page *page)
773 void ClearPageFsCache(struct page *page)
774 int TestSetPageFsCache(struct page *page)
775 int TestClearPageFsCache(struct page *page)
776
777These functions are bit test, bit set, bit clear, bit test and set and bit
778test and clear operations on PG_fscache.
diff --git a/include/linux/fscache.h b/include/linux/fscache.h
new file mode 100644
index 000000000000..feb3b0e0af4d
--- /dev/null
+++ b/include/linux/fscache.h
@@ -0,0 +1,548 @@
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
48struct pagevec;
49struct fscache_cache_tag;
50struct fscache_cookie;
51struct fscache_netfs;
52
53typedef void (*fscache_rw_complete_t)(struct page *page,
54 void *context,
55 int error);
56
57/* result of index entry consultation */
58enum 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 */
67struct fscache_cookie_def {
68 /* name of cookie type */
69 char name[16];
70
71 /* cookie type */
72 uint8_t type;
73#define FSCACHE_COOKIE_TYPE_INDEX 0
74#define FSCACHE_COOKIE_TYPE_DATAFILE 1
75
76 /* select the cache into which to insert an entry in this index
77 * - optional
78 * - should return a cache identifier or NULL to cause the cache to be
79 * inherited from the parent if possible or the first cache picked
80 * for a non-index file if not
81 */
82 struct fscache_cache_tag *(*select_cache)(
83 const void *parent_netfs_data,
84 const void *cookie_netfs_data);
85
86 /* get an index key
87 * - should store the key data in the buffer
88 * - should return the amount of amount stored
89 * - not permitted to return an error
90 * - the netfs data from the cookie being used as the source is
91 * presented
92 */
93 uint16_t (*get_key)(const void *cookie_netfs_data,
94 void *buffer,
95 uint16_t bufmax);
96
97 /* get certain file attributes from the netfs data
98 * - this function can be absent for an index
99 * - not permitted to return an error
100 * - the netfs data from the cookie being used as the source is
101 * presented
102 */
103 void (*get_attr)(const void *cookie_netfs_data, uint64_t *size);
104
105 /* get the auxilliary data from netfs data
106 * - this function can be absent if the index carries no state data
107 * - should store the auxilliary data in the buffer
108 * - should return the amount of amount stored
109 * - not permitted to return an error
110 * - the netfs data from the cookie being used as the source is
111 * presented
112 */
113 uint16_t (*get_aux)(const void *cookie_netfs_data,
114 void *buffer,
115 uint16_t bufmax);
116
117 /* consult the netfs about the state of an object
118 * - this function can be absent if the index carries no state data
119 * - the netfs data from the cookie being used as the target is
120 * presented, as is the auxilliary data
121 */
122 enum fscache_checkaux (*check_aux)(void *cookie_netfs_data,
123 const void *data,
124 uint16_t datalen);
125
126 /* get an extra reference on a read context
127 * - this function can be absent if the completion function doesn't
128 * require a context
129 */
130 void (*get_context)(void *cookie_netfs_data, void *context);
131
132 /* release an extra reference on a read context
133 * - this function can be absent if the completion function doesn't
134 * require a context
135 */
136 void (*put_context)(void *cookie_netfs_data, void *context);
137
138 /* indicate pages that now have cache metadata retained
139 * - this function should mark the specified pages as now being cached
140 * - the pages will have been marked with PG_fscache before this is
141 * called, so this is optional
142 */
143 void (*mark_pages_cached)(void *cookie_netfs_data,
144 struct address_space *mapping,
145 struct pagevec *cached_pvec);
146
147 /* indicate the cookie is no longer cached
148 * - this function is called when the backing store currently caching
149 * a cookie is removed
150 * - the netfs should use this to clean up any markers indicating
151 * cached pages
152 * - this is mandatory for any object that may have data
153 */
154 void (*now_uncached)(void *cookie_netfs_data);
155};
156
157/*
158 * fscache cached network filesystem type
159 * - name, version and ops must be filled in before registration
160 * - all other fields will be set during registration
161 */
162struct 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 */
176
177/**
178 * fscache_register_netfs - Register a filesystem as desiring caching services
179 * @netfs: The description of the filesystem
180 *
181 * Register a filesystem as desiring caching services if they're available.
182 *
183 * See Documentation/filesystems/caching/netfs-api.txt for a complete
184 * description.
185 */
186static inline
187int fscache_register_netfs(struct fscache_netfs *netfs)
188{
189 return 0;
190}
191
192/**
193 * fscache_unregister_netfs - Indicate that a filesystem no longer desires
194 * caching services
195 * @netfs: The description of the filesystem
196 *
197 * Indicate that a filesystem no longer desires caching services for the
198 * moment.
199 *
200 * See Documentation/filesystems/caching/netfs-api.txt for a complete
201 * description.
202 */
203static inline
204void fscache_unregister_netfs(struct fscache_netfs *netfs)
205{
206}
207
208/**
209 * fscache_lookup_cache_tag - Look up a cache tag
210 * @name: The name of the tag to search for
211 *
212 * Acquire a specific cache referral tag that can be used to select a specific
213 * cache in which to cache an index.
214 *
215 * See Documentation/filesystems/caching/netfs-api.txt for a complete
216 * description.
217 */
218static inline
219struct fscache_cache_tag *fscache_lookup_cache_tag(const char *name)
220{
221 return NULL;
222}
223
224/**
225 * fscache_release_cache_tag - Release a cache tag
226 * @tag: The tag to release
227 *
228 * Release a reference to a cache referral tag previously looked up.
229 *
230 * See Documentation/filesystems/caching/netfs-api.txt for a complete
231 * description.
232 */
233static inline
234void fscache_release_cache_tag(struct fscache_cache_tag *tag)
235{
236}
237
238/**
239 * fscache_acquire_cookie - Acquire a cookie to represent a cache object
240 * @parent: The cookie that's to be the parent of this one
241 * @def: A description of the cache object, including callback operations
242 * @netfs_data: An arbitrary piece of data to be kept in the cookie to
243 * represent the cache object to the netfs
244 *
245 * This function is used to inform FS-Cache about part of an index hierarchy
246 * that can be used to locate files. This is done by requesting a cookie for
247 * each index in the path to the file.
248 *
249 * See Documentation/filesystems/caching/netfs-api.txt for a complete
250 * description.
251 */
252static inline
253struct fscache_cookie *fscache_acquire_cookie(
254 struct fscache_cookie *parent,
255 const struct fscache_cookie_def *def,
256 void *netfs_data)
257{
258 return NULL;
259}
260
261/**
262 * fscache_relinquish_cookie - Return the cookie to the cache, maybe discarding
263 * it
264 * @cookie: The cookie being returned
265 * @retire: True if the cache object the cookie represents is to be discarded
266 *
267 * This function returns a cookie to the cache, forcibly discarding the
268 * associated cache object if retire is set to true.
269 *
270 * See Documentation/filesystems/caching/netfs-api.txt for a complete
271 * description.
272 */
273static inline
274void fscache_relinquish_cookie(struct fscache_cookie *cookie, int retire)
275{
276}
277
278/**
279 * fscache_update_cookie - Request that a cache object be updated
280 * @cookie: The cookie representing the cache object
281 *
282 * Request an update of the index data for the cache object associated with the
283 * cookie.
284 *
285 * See Documentation/filesystems/caching/netfs-api.txt for a complete
286 * description.
287 */
288static inline
289void fscache_update_cookie(struct fscache_cookie *cookie)
290{
291}
292
293/**
294 * fscache_pin_cookie - Pin a data-storage cache object in its cache
295 * @cookie: The cookie representing the cache object
296 *
297 * Permit data-storage cache objects to be pinned in the cache.
298 *
299 * See Documentation/filesystems/caching/netfs-api.txt for a complete
300 * description.
301 */
302static inline
303int fscache_pin_cookie(struct fscache_cookie *cookie)
304{
305 return -ENOBUFS;
306}
307
308/**
309 * fscache_pin_cookie - Unpin a data-storage cache object in its cache
310 * @cookie: The cookie representing the cache object
311 *
312 * Permit data-storage cache objects to be unpinned from the cache.
313 *
314 * See Documentation/filesystems/caching/netfs-api.txt for a complete
315 * description.
316 */
317static inline
318void fscache_unpin_cookie(struct fscache_cookie *cookie)
319{
320}
321
322/**
323 * fscache_attr_changed - Notify cache that an object's attributes changed
324 * @cookie: The cookie representing the cache object
325 *
326 * Send a notification to the cache indicating that an object's attributes have
327 * changed. This includes the data size. These attributes will be obtained
328 * through the get_attr() cookie definition op.
329 *
330 * See Documentation/filesystems/caching/netfs-api.txt for a complete
331 * description.
332 */
333static inline
334int fscache_attr_changed(struct fscache_cookie *cookie)
335{
336 return -ENOBUFS;
337}
338
339/**
340 * fscache_reserve_space - Reserve data space for a cached object
341 * @cookie: The cookie representing the cache object
342 * @i_size: The amount of space to be reserved
343 *
344 * Reserve an amount of space in the cache for the cache object attached to a
345 * cookie so that a write to that object within the space can always be
346 * honoured.
347 *
348 * See Documentation/filesystems/caching/netfs-api.txt for a complete
349 * description.
350 */
351static inline
352int fscache_reserve_space(struct fscache_cookie *cookie, loff_t size)
353{
354 return -ENOBUFS;
355}
356
357/**
358 * fscache_read_or_alloc_page - Read a page from the cache or allocate a block
359 * in which to store it
360 * @cookie: The cookie representing the cache object
361 * @page: The netfs page to fill if possible
362 * @end_io_func: The callback to invoke when and if the page is filled
363 * @context: An arbitrary piece of data to pass on to end_io_func()
364 * @gfp: The conditions under which memory allocation should be made
365 *
366 * Read a page from the cache, or if that's not possible make a potential
367 * one-block reservation in the cache into which the page may be stored once
368 * fetched from the server.
369 *
370 * If the page is not backed by the cache object, or if it there's some reason
371 * it can't be, -ENOBUFS will be returned and nothing more will be done for
372 * that page.
373 *
374 * Else, if that page is backed by the cache, a read will be initiated directly
375 * to the netfs's page and 0 will be returned by this function. The
376 * end_io_func() callback will be invoked when the operation terminates on a
377 * completion or failure. Note that the callback may be invoked before the
378 * return.
379 *
380 * Else, if the page is unbacked, -ENODATA is returned and a block may have
381 * been allocated in the cache.
382 *
383 * See Documentation/filesystems/caching/netfs-api.txt for a complete
384 * description.
385 */
386static inline
387int fscache_read_or_alloc_page(struct fscache_cookie *cookie,
388 struct page *page,
389 fscache_rw_complete_t end_io_func,
390 void *context,
391 gfp_t gfp)
392{
393 return -ENOBUFS;
394}
395
396/**
397 * fscache_read_or_alloc_pages - Read pages from the cache and/or allocate
398 * blocks in which to store them
399 * @cookie: The cookie representing the cache object
400 * @mapping: The netfs inode mapping to which the pages will be attached
401 * @pages: A list of potential netfs pages to be filled
402 * @end_io_func: The callback to invoke when and if each page is filled
403 * @context: An arbitrary piece of data to pass on to end_io_func()
404 * @gfp: The conditions under which memory allocation should be made
405 *
406 * Read a set of pages from the cache, or if that's not possible, attempt to
407 * make a potential one-block reservation for each page in the cache into which
408 * that page may be stored once fetched from the server.
409 *
410 * If some pages are not backed by the cache object, or if it there's some
411 * reason they can't be, -ENOBUFS will be returned and nothing more will be
412 * done for that pages.
413 *
414 * Else, if some of the pages are backed by the cache, a read will be initiated
415 * directly to the netfs's page and 0 will be returned by this function. The
416 * end_io_func() callback will be invoked when the operation terminates on a
417 * completion or failure. Note that the callback may be invoked before the
418 * return.
419 *
420 * Else, if a page is unbacked, -ENODATA is returned and a block may have
421 * been allocated in the cache.
422 *
423 * Because the function may want to return all of -ENOBUFS, -ENODATA and 0 in
424 * regard to different pages, the return values are prioritised in that order.
425 * Any pages submitted for reading are removed from the pages list.
426 *
427 * See Documentation/filesystems/caching/netfs-api.txt for a complete
428 * description.
429 */
430static inline
431int fscache_read_or_alloc_pages(struct fscache_cookie *cookie,
432 struct address_space *mapping,
433 struct list_head *pages,
434 unsigned *nr_pages,
435 fscache_rw_complete_t end_io_func,
436 void *context,
437 gfp_t gfp)
438{
439 return -ENOBUFS;
440}
441
442/**
443 * fscache_alloc_page - Allocate a block in which to store a page
444 * @cookie: The cookie representing the cache object
445 * @page: The netfs page to allocate a page for
446 * @gfp: The conditions under which memory allocation should be made
447 *
448 * Request Allocation a block in the cache in which to store a netfs page
449 * without retrieving any contents from the cache.
450 *
451 * If the page is not backed by a file then -ENOBUFS will be returned and
452 * nothing more will be done, and no reservation will be made.
453 *
454 * Else, a block will be allocated if one wasn't already, and 0 will be
455 * returned
456 *
457 * See Documentation/filesystems/caching/netfs-api.txt for a complete
458 * description.
459 */
460static inline
461int fscache_alloc_page(struct fscache_cookie *cookie,
462 struct page *page,
463 gfp_t gfp)
464{
465 return -ENOBUFS;
466}
467
468/**
469 * fscache_write_page - Request storage of a page in the cache
470 * @cookie: The cookie representing the cache object
471 * @page: The netfs page to store
472 * @gfp: The conditions under which memory allocation should be made
473 *
474 * Request the contents of the netfs page be written into the cache. This
475 * request may be ignored if no cache block is currently allocated, in which
476 * case it will return -ENOBUFS.
477 *
478 * If a cache block was already allocated, a write will be initiated and 0 will
479 * be returned. The PG_fscache_write page bit is set immediately and will then
480 * be cleared at the completion of the write to indicate the success or failure
481 * of the operation. Note that the completion may happen before the return.
482 *
483 * See Documentation/filesystems/caching/netfs-api.txt for a complete
484 * description.
485 */
486static inline
487int fscache_write_page(struct fscache_cookie *cookie,
488 struct page *page,
489 gfp_t gfp)
490{
491 return -ENOBUFS;
492}
493
494/**
495 * fscache_uncache_page - Indicate that caching is no longer required on a page
496 * @cookie: The cookie representing the cache object
497 * @page: The netfs page that was being cached.
498 *
499 * Tell the cache that we no longer want a page to be cached and that it should
500 * remove any knowledge of the netfs page it may have.
501 *
502 * Note that this cannot cancel any outstanding I/O operations between this
503 * page and the cache.
504 *
505 * See Documentation/filesystems/caching/netfs-api.txt for a complete
506 * description.
507 */
508static inline
509void fscache_uncache_page(struct fscache_cookie *cookie,
510 struct page *page)
511{
512}
513
514/**
515 * fscache_check_page_write - Ask if a page is being writing to the cache
516 * @cookie: The cookie representing the cache object
517 * @page: The netfs page that is being cached.
518 *
519 * Ask the cache if a page is being written to the cache.
520 *
521 * See Documentation/filesystems/caching/netfs-api.txt for a complete
522 * description.
523 */
524static inline
525bool fscache_check_page_write(struct fscache_cookie *cookie,
526 struct page *page)
527{
528 return false;
529}
530
531/**
532 * fscache_wait_on_page_write - Wait for a page to complete writing to the cache
533 * @cookie: The cookie representing the cache object
534 * @page: The netfs page that is being cached.
535 *
536 * Ask the cache to wake us up when a page is no longer being written to the
537 * cache.
538 *
539 * See Documentation/filesystems/caching/netfs-api.txt for a complete
540 * description.
541 */
542static inline
543void fscache_wait_on_page_write(struct fscache_cookie *cookie,
544 struct page *page)
545{
546}
547
548#endif /* _LINUX_FSCACHE_H */