xref: /openbmc/linux/Documentation/filesystems/caching/backend-api.rst (revision 4f2c0a4acffbec01079c28f839422e64ddeff004)
10e822145SMauro Carvalho Chehab.. SPDX-License-Identifier: GPL-2.0
20e822145SMauro Carvalho Chehab
3e0484344SDavid Howells=================
4e0484344SDavid HowellsCache Backend API
5e0484344SDavid Howells=================
60e822145SMauro Carvalho Chehab
70e822145SMauro Carvalho ChehabThe FS-Cache system provides an API by which actual caches can be supplied to
80e822145SMauro Carvalho ChehabFS-Cache for it to then serve out to network filesystems and other interested
9e0484344SDavid Howellsparties.  This API is used by::
100e822145SMauro Carvalho Chehab
11e0484344SDavid Howells	#include <linux/fscache-cache.h>.
120e822145SMauro Carvalho Chehab
130e822145SMauro Carvalho Chehab
14e0484344SDavid HowellsOverview
15e0484344SDavid Howells========
160e822145SMauro Carvalho Chehab
17e0484344SDavid HowellsInteraction with the API is handled on three levels: cache, volume and data
18e0484344SDavid Howellsstorage, and each level has its own type of cookie object:
190e822145SMauro Carvalho Chehab
20e0484344SDavid Howells	=======================	=======================
21e0484344SDavid Howells	COOKIE			C TYPE
22e0484344SDavid Howells	=======================	=======================
23e0484344SDavid Howells	Cache cookie		struct fscache_cache
24e0484344SDavid Howells	Volume cookie		struct fscache_volume
25e0484344SDavid Howells	Data storage cookie	struct fscache_cookie
26e0484344SDavid Howells	=======================	=======================
270e822145SMauro Carvalho Chehab
28e0484344SDavid HowellsCookies are used to provide some filesystem data to the cache, manage state and
29e0484344SDavid Howellspin the cache during access in addition to acting as reference points for the
30e0484344SDavid HowellsAPI functions.  Each cookie has a debugging ID that is included in trace points
31e0484344SDavid Howellsto make it easier to correlate traces.  Note, though, that debugging IDs are
32e0484344SDavid Howellssimply allocated from incrementing counters and will eventually wrap.
330e822145SMauro Carvalho Chehab
34e0484344SDavid HowellsThe cache backend and the network filesystem can both ask for cache cookies -
35e0484344SDavid Howellsand if they ask for one of the same name, they'll get the same cookie.  Volume
36e0484344SDavid Howellsand data cookies, however, are created at the behest of the filesystem only.
370e822145SMauro Carvalho Chehab
380e822145SMauro Carvalho Chehab
39e0484344SDavid HowellsCache Cookies
40e0484344SDavid Howells=============
41e0484344SDavid Howells
42e0484344SDavid HowellsCaches are represented in the API by cache cookies.  These are objects of
43e0484344SDavid Howellstype::
44e0484344SDavid Howells
45e0484344SDavid Howells	struct fscache_cache {
46e0484344SDavid Howells		void		*cache_priv;
47e0484344SDavid Howells		unsigned int	debug_id;
48e0484344SDavid Howells		char		*name;
49e0484344SDavid Howells		...
50e0484344SDavid Howells	};
51e0484344SDavid Howells
52e0484344SDavid HowellsThere are a few fields that the cache backend might be interested in.  The
53e0484344SDavid Howells``debug_id`` can be used in tracing to match lines referring to the same cache
54e0484344SDavid Howellsand ``name`` is the name the cache was registered with.  The ``cache_priv``
55e0484344SDavid Howellsmember is private data provided by the cache when it is brought online.  The
56e0484344SDavid Howellsother fields are for internal use.
57e0484344SDavid Howells
58e0484344SDavid Howells
59e0484344SDavid HowellsRegistering a Cache
60e0484344SDavid Howells===================
61e0484344SDavid Howells
62e0484344SDavid HowellsWhen a cache backend wants to bring a cache online, it should first register
63e0484344SDavid Howellsthe cache name and that will get it a cache cookie.  This is done with::
64e0484344SDavid Howells
65e0484344SDavid Howells	struct fscache_cache *fscache_acquire_cache(const char *name);
66e0484344SDavid Howells
67e0484344SDavid HowellsThis will look up and potentially create a cache cookie.  The cache cookie may
68e0484344SDavid Howellshave already been created by a network filesystem looking for it, in which case
69e0484344SDavid Howellsthat cache cookie will be used.  If the cache cookie is not in use by another
70e0484344SDavid Howellscache, it will be moved into the preparing state, otherwise it will return
71e0484344SDavid Howellsbusy.
72e0484344SDavid Howells
73e0484344SDavid HowellsIf successful, the cache backend can then start setting up the cache.  In the
74e0484344SDavid Howellsevent that the initialisation fails, the cache backend should call::
75e0484344SDavid Howells
76c54eead2SYue Hu	void fscache_relinquish_cache(struct fscache_cache *cache);
77e0484344SDavid Howells
78e0484344SDavid Howellsto reset and discard the cookie.
79e0484344SDavid Howells
80e0484344SDavid Howells
81e0484344SDavid HowellsBringing a Cache Online
82e0484344SDavid Howells=======================
83e0484344SDavid Howells
84e0484344SDavid HowellsOnce the cache is set up, it can be brought online by calling::
850e822145SMauro Carvalho Chehab
860e822145SMauro Carvalho Chehab	int fscache_add_cache(struct fscache_cache *cache,
87e0484344SDavid Howells			      const struct fscache_cache_ops *ops,
88e0484344SDavid Howells			      void *cache_priv);
890e822145SMauro Carvalho Chehab
90e0484344SDavid HowellsThis stores the cache operations table pointer and cache private data into the
91e0484344SDavid Howellscache cookie and moves the cache to the active state, thereby allowing accesses
92e0484344SDavid Howellsto take place.
930e822145SMauro Carvalho Chehab
940e822145SMauro Carvalho Chehab
95e0484344SDavid HowellsWithdrawing a Cache From Service
96e0484344SDavid Howells================================
970e822145SMauro Carvalho Chehab
98e0484344SDavid HowellsThe cache backend can withdraw a cache from service by calling this function::
990e822145SMauro Carvalho Chehab
1000e822145SMauro Carvalho Chehab	void fscache_withdraw_cache(struct fscache_cache *cache);
1010e822145SMauro Carvalho Chehab
102e0484344SDavid HowellsThis moves the cache to the withdrawn state to prevent new cache- and
103e0484344SDavid Howellsvolume-level accesses from starting and then waits for outstanding cache-level
104e0484344SDavid Howellsaccesses to complete.
105e0484344SDavid Howells
106e0484344SDavid HowellsThe cache must then go through the data storage objects it has and tell fscache
107e0484344SDavid Howellsto withdraw them, calling::
108e0484344SDavid Howells
109e0484344SDavid Howells	void fscache_withdraw_cookie(struct fscache_cookie *cookie);
110e0484344SDavid Howells
111e0484344SDavid Howellson the cookie that each object belongs to.  This schedules the specified cookie
112e0484344SDavid Howellsfor withdrawal.  This gets offloaded to a workqueue.  The cache backend can
1135d3d5b96SYue Huwait for completion by calling::
114e0484344SDavid Howells
1155d3d5b96SYue Hu	void fscache_wait_for_objects(struct fscache_cache *cache);
116e0484344SDavid Howells
117e0484344SDavid HowellsOnce all the cookies are withdrawn, a cache backend can withdraw all the
118e0484344SDavid Howellsvolumes, calling::
119e0484344SDavid Howells
120e0484344SDavid Howells	void fscache_withdraw_volume(struct fscache_volume *volume);
121e0484344SDavid Howells
122e0484344SDavid Howellsto tell fscache that a volume has been withdrawn.  This waits for all
123e0484344SDavid Howellsoutstanding accesses on the volume to complete before returning.
124e0484344SDavid Howells
125*d2bef8e1SAkhil RajWhen the cache is completely withdrawn, fscache should be notified by
126e0484344SDavid Howellscalling::
127e0484344SDavid Howells
128c54eead2SYue Hu	void fscache_relinquish_cache(struct fscache_cache *cache);
129e0484344SDavid Howells
130e0484344SDavid Howellsto clear fields in the cookie and discard the caller's ref on it.
1310e822145SMauro Carvalho Chehab
1320e822145SMauro Carvalho Chehab
133e0484344SDavid HowellsVolume Cookies
134e0484344SDavid Howells==============
1350e822145SMauro Carvalho Chehab
136e0484344SDavid HowellsWithin a cache, the data storage objects are organised into logical volumes.
137e0484344SDavid HowellsThese are represented in the API as objects of type::
1380e822145SMauro Carvalho Chehab
139e0484344SDavid Howells	struct fscache_volume {
140e0484344SDavid Howells		struct fscache_cache		*cache;
141e0484344SDavid Howells		void				*cache_priv;
142e0484344SDavid Howells		unsigned int			debug_id;
143e0484344SDavid Howells		char				*key;
144e0484344SDavid Howells		unsigned int			key_hash;
145e0484344SDavid Howells		...
146e0484344SDavid Howells		u8				coherency_len;
147e0484344SDavid Howells		u8				coherency[];
148e0484344SDavid Howells	};
1490e822145SMauro Carvalho Chehab
150e0484344SDavid HowellsThere are a number of fields here that are of interest to the caching backend:
1510e822145SMauro Carvalho Chehab
152e0484344SDavid Howells   * ``cache`` - The parent cache cookie.
1530e822145SMauro Carvalho Chehab
154e0484344SDavid Howells   * ``cache_priv`` - A place for the cache to stash private data.
155e0484344SDavid Howells
156e0484344SDavid Howells   * ``debug_id`` - A debugging ID for logging in tracepoints.
157e0484344SDavid Howells
158e0484344SDavid Howells   * ``key`` - A printable string with no '/' characters in it that represents
159e0484344SDavid Howells     the index key for the volume.  The key is NUL-terminated and padded out to
160e0484344SDavid Howells     a multiple of 4 bytes.
161e0484344SDavid Howells
162e0484344SDavid Howells   * ``key_hash`` - A hash of the index key.  This should work out the same, no
163e0484344SDavid Howells     matter the cpu arch and endianness.
164e0484344SDavid Howells
165e0484344SDavid Howells   * ``coherency`` - A piece of coherency data that should be checked when the
166e0484344SDavid Howells     volume is bound to in the cache.
167e0484344SDavid Howells
168e0484344SDavid Howells   * ``coherency_len`` - The amount of data in the coherency buffer.
1690e822145SMauro Carvalho Chehab
1700e822145SMauro Carvalho Chehab
171e0484344SDavid HowellsData Storage Cookies
172e0484344SDavid Howells====================
1730e822145SMauro Carvalho Chehab
174e0484344SDavid HowellsA volume is a logical group of data storage objects, each of which is
175e0484344SDavid Howellsrepresented to the network filesystem by a cookie.  Cookies are represented in
176e0484344SDavid Howellsthe API as objects of type::
1770e822145SMauro Carvalho Chehab
1780e822145SMauro Carvalho Chehab	struct fscache_cookie {
179e0484344SDavid Howells		struct fscache_volume		*volume;
180e0484344SDavid Howells		void				*cache_priv;
1810e822145SMauro Carvalho Chehab		unsigned long			flags;
182e0484344SDavid Howells		unsigned int			debug_id;
183e0484344SDavid Howells		unsigned int			inval_counter;
184e0484344SDavid Howells		loff_t				object_size;
185e0484344SDavid Howells		u8				advice;
186e0484344SDavid Howells		u32				key_hash;
187e0484344SDavid Howells		u8				key_len;
188e0484344SDavid Howells		u8				aux_len;
1890e822145SMauro Carvalho Chehab		...
1900e822145SMauro Carvalho Chehab	};
1910e822145SMauro Carvalho Chehab
192e0484344SDavid HowellsThe fields in the cookie that are of interest to the cache backend are:
1930e822145SMauro Carvalho Chehab
194e0484344SDavid Howells   * ``volume`` - The parent volume cookie.
195e0484344SDavid Howells
196e0484344SDavid Howells   * ``cache_priv`` - A place for the cache to stash private data.
197e0484344SDavid Howells
198e0484344SDavid Howells   * ``flags`` - A collection of bit flags, including:
199e0484344SDavid Howells
200e0484344SDavid Howells      * FSCACHE_COOKIE_NO_DATA_TO_READ - There is no data available in the
201e0484344SDavid Howells	cache to be read as the cookie has been created or invalidated.
202e0484344SDavid Howells
203e0484344SDavid Howells      * FSCACHE_COOKIE_NEEDS_UPDATE - The coherency data and/or object size has
204e0484344SDavid Howells	been changed and needs committing.
205e0484344SDavid Howells
206e0484344SDavid Howells      * FSCACHE_COOKIE_LOCAL_WRITE - The netfs's data has been modified
207e0484344SDavid Howells	locally, so the cache object may be in an incoherent state with respect
208e0484344SDavid Howells	to the server.
209e0484344SDavid Howells
210e0484344SDavid Howells      * FSCACHE_COOKIE_HAVE_DATA - The backend should set this if it
211e0484344SDavid Howells	successfully stores data into the cache.
212e0484344SDavid Howells
213e0484344SDavid Howells      * FSCACHE_COOKIE_RETIRED - The cookie was invalidated when it was
214e0484344SDavid Howells	relinquished and the cached data should be discarded.
215e0484344SDavid Howells
216e0484344SDavid Howells   * ``debug_id`` - A debugging ID for logging in tracepoints.
217e0484344SDavid Howells
218e0484344SDavid Howells   * ``inval_counter`` - The number of invalidations done on the cookie.
219e0484344SDavid Howells
220e0484344SDavid Howells   * ``advice`` - Information about how the cookie is to be used.
221e0484344SDavid Howells
222e0484344SDavid Howells   * ``key_hash`` - A hash of the index key.  This should work out the same, no
223e0484344SDavid Howells     matter the cpu arch and endianness.
224e0484344SDavid Howells
225e0484344SDavid Howells   * ``key_len`` - The length of the index key.
226e0484344SDavid Howells
227e0484344SDavid Howells   * ``aux_len`` - The length of the coherency data buffer.
228e0484344SDavid Howells
229e0484344SDavid HowellsEach cookie has an index key, which may be stored inline to the cookie or
230e0484344SDavid Howellselsewhere.  A pointer to this can be obtained by calling::
231e0484344SDavid Howells
232e0484344SDavid Howells	void *fscache_get_key(struct fscache_cookie *cookie);
233e0484344SDavid Howells
234e0484344SDavid HowellsThe index key is a binary blob, the storage for which is padded out to a
235e0484344SDavid Howellsmultiple of 4 bytes.
236e0484344SDavid Howells
237e0484344SDavid HowellsEach cookie also has a buffer for coherency data.  This may also be inline or
238e0484344SDavid Howellsdetached from the cookie and a pointer is obtained by calling::
239e0484344SDavid Howells
240e0484344SDavid Howells	void *fscache_get_aux(struct fscache_cookie *cookie);
2410e822145SMauro Carvalho Chehab
2420e822145SMauro Carvalho Chehab
2430e822145SMauro Carvalho Chehab
244e0484344SDavid HowellsCookie Accounting
245e0484344SDavid Howells=================
246e0484344SDavid Howells
247e0484344SDavid HowellsData storage cookies are counted and this is used to block cache withdrawal
248e0484344SDavid Howellscompletion until all objects have been destroyed.  The following functions are
249e0484344SDavid Howellsprovided to the cache to deal with that::
250e0484344SDavid Howells
251e0484344SDavid Howells	void fscache_count_object(struct fscache_cache *cache);
252e0484344SDavid Howells	void fscache_uncount_object(struct fscache_cache *cache);
253e0484344SDavid Howells	void fscache_wait_for_objects(struct fscache_cache *cache);
254e0484344SDavid Howells
255e0484344SDavid HowellsThe count function records the allocation of an object in a cache and the
256e0484344SDavid Howellsuncount function records its destruction.  Warning: by the time the uncount
257e0484344SDavid Howellsfunction returns, the cache may have been destroyed.
258e0484344SDavid Howells
259e0484344SDavid HowellsThe wait function can be used during the withdrawal procedure to wait for
260e0484344SDavid Howellsfscache to finish withdrawing all the objects in the cache.  When it completes,
261e0484344SDavid Howellsthere will be no remaining objects referring to the cache object or any volume
262e0484344SDavid Howellsobjects.
263e0484344SDavid Howells
264e0484344SDavid Howells
265e0484344SDavid HowellsCache Management API
266e0484344SDavid Howells====================
267e0484344SDavid Howells
268e0484344SDavid HowellsThe cache backend implements the cache management API by providing a table of
269e0484344SDavid Howellsoperations that fscache can use to manage various aspects of the cache.  These
270e0484344SDavid Howellsare held in a structure of type::
271e0484344SDavid Howells
272e0484344SDavid Howells	struct fscache_cache_ops {
273e0484344SDavid Howells		const char *name;
2740e822145SMauro Carvalho Chehab		...
2750e822145SMauro Carvalho Chehab	};
2760e822145SMauro Carvalho Chehab
277e0484344SDavid HowellsThis contains a printable name for the cache backend driver plus a number of
278e0484344SDavid Howellspointers to methods to allow fscache to request management of the cache:
2790e822145SMauro Carvalho Chehab
280e0484344SDavid Howells   * Set up a volume cookie [optional]::
2810e822145SMauro Carvalho Chehab
282e0484344SDavid Howells	void (*acquire_volume)(struct fscache_volume *volume);
2830e822145SMauro Carvalho Chehab
284e0484344SDavid Howells     This method is called when a volume cookie is being created.  The caller
285e0484344SDavid Howells     holds a cache-level access pin to prevent the cache from going away for
286e0484344SDavid Howells     the duration.  This method should set up the resources to access a volume
287e0484344SDavid Howells     in the cache and should not return until it has done so.
2880e822145SMauro Carvalho Chehab
289e0484344SDavid Howells     If successful, it can set ``cache_priv`` to its own data.
2900e822145SMauro Carvalho Chehab
2910e822145SMauro Carvalho Chehab
292e0484344SDavid Howells   * Clean up volume cookie [optional]::
2930e822145SMauro Carvalho Chehab
294e0484344SDavid Howells       void (*free_volume)(struct fscache_volume *volume);
2950e822145SMauro Carvalho Chehab
296e0484344SDavid Howells     This method is called when a volume cookie is being released if
297e0484344SDavid Howells     ``cache_priv`` is set.
2980e822145SMauro Carvalho Chehab
2990e822145SMauro Carvalho Chehab
300e0484344SDavid Howells   * Look up a cookie in the cache [mandatory]::
3010e822145SMauro Carvalho Chehab
302e0484344SDavid Howells	bool (*lookup_cookie)(struct fscache_cookie *cookie);
3030e822145SMauro Carvalho Chehab
304e0484344SDavid Howells     This method is called to look up/create the resources needed to access the
305e0484344SDavid Howells     data storage for a cookie.  It is called from a worker thread with a
306e0484344SDavid Howells     volume-level access pin in the cache to prevent it from being withdrawn.
3070e822145SMauro Carvalho Chehab
308e0484344SDavid Howells     True should be returned if successful and false otherwise.  If false is
309e0484344SDavid Howells     returned, the withdraw_cookie op (see below) will be called.
3100e822145SMauro Carvalho Chehab
311e0484344SDavid Howells     If lookup fails, but the object could still be created (e.g. it hasn't
312e0484344SDavid Howells     been cached before), then::
3130e822145SMauro Carvalho Chehab
314e0484344SDavid Howells		void fscache_cookie_lookup_negative(
315e0484344SDavid Howells			struct fscache_cookie *cookie);
3160e822145SMauro Carvalho Chehab
317e0484344SDavid Howells     can be called to let the network filesystem proceed and start downloading
318e0484344SDavid Howells     stuff whilst the cache backend gets on with the job of creating things.
3190e822145SMauro Carvalho Chehab
320e0484344SDavid Howells     If successful, ``cookie->cache_priv`` can be set.
3210e822145SMauro Carvalho Chehab
3220e822145SMauro Carvalho Chehab
323e0484344SDavid Howells   * Withdraw an object without any cookie access counts held [mandatory]::
3240e822145SMauro Carvalho Chehab
325e0484344SDavid Howells	void (*withdraw_cookie)(struct fscache_cookie *cookie);
3260e822145SMauro Carvalho Chehab
327e0484344SDavid Howells     This method is called to withdraw a cookie from service.  It will be
328e0484344SDavid Howells     called when the cookie is relinquished by the netfs, withdrawn or culled
329e0484344SDavid Howells     by the cache backend or closed after a period of non-use by fscache.
3300e822145SMauro Carvalho Chehab
331e0484344SDavid Howells     The caller doesn't hold any access pins, but it is called from a
332e0484344SDavid Howells     non-reentrant work item to manage races between the various ways
333e0484344SDavid Howells     withdrawal can occur.
3340e822145SMauro Carvalho Chehab
335e0484344SDavid Howells     The cookie will have the ``FSCACHE_COOKIE_RETIRED`` flag set on it if the
336e0484344SDavid Howells     associated data is to be removed from the cache.
3370e822145SMauro Carvalho Chehab
3380e822145SMauro Carvalho Chehab
339e0484344SDavid Howells   * Change the size of a data storage object [mandatory]::
3400e822145SMauro Carvalho Chehab
341e0484344SDavid Howells	void (*resize_cookie)(struct netfs_cache_resources *cres,
342e0484344SDavid Howells			      loff_t new_size);
3430e822145SMauro Carvalho Chehab
344e0484344SDavid Howells     This method is called to inform the cache backend of a change in size of
345e0484344SDavid Howells     the netfs file due to local truncation.  The cache backend should make all
346e0484344SDavid Howells     of the changes it needs to make before returning as this is done under the
347e0484344SDavid Howells     netfs inode mutex.
3480e822145SMauro Carvalho Chehab
349e0484344SDavid Howells     The caller holds a cookie-level access pin to prevent a race with
350e0484344SDavid Howells     withdrawal and the netfs must have the cookie marked in-use to prevent
351e0484344SDavid Howells     garbage collection or culling from removing any resources.
3520e822145SMauro Carvalho Chehab
3530e822145SMauro Carvalho Chehab
354e0484344SDavid Howells   * Invalidate a data storage object [mandatory]::
3550e822145SMauro Carvalho Chehab
356e0484344SDavid Howells	bool (*invalidate_cookie)(struct fscache_cookie *cookie);
3570e822145SMauro Carvalho Chehab
358e0484344SDavid Howells     This is called when the network filesystem detects a third-party
359e0484344SDavid Howells     modification or when an O_DIRECT write is made locally.  This requests
360e0484344SDavid Howells     that the cache backend should throw away all the data in the cache for
361e0484344SDavid Howells     this object and start afresh.  It should return true if successful and
362e0484344SDavid Howells     false otherwise.
3630e822145SMauro Carvalho Chehab
364e0484344SDavid Howells     On entry, new I O/operations are blocked.  Once the cache is in a position
365e0484344SDavid Howells     to accept I/O again, the backend should release the block by calling::
3660e822145SMauro Carvalho Chehab
367e0484344SDavid Howells	void fscache_resume_after_invalidation(struct fscache_cookie *cookie);
3680e822145SMauro Carvalho Chehab
369e0484344SDavid Howells     If the method returns false, caching will be withdrawn for this cookie.
3700e822145SMauro Carvalho Chehab
3710e822145SMauro Carvalho Chehab
372e0484344SDavid Howells   * Prepare to make local modifications to the cache [mandatory]::
3730e822145SMauro Carvalho Chehab
374e0484344SDavid Howells	void (*prepare_to_write)(struct fscache_cookie *cookie);
3750e822145SMauro Carvalho Chehab
376e0484344SDavid Howells     This method is called when the network filesystem finds that it is going
377e0484344SDavid Howells     to need to modify the contents of the cache due to local writes or
378e0484344SDavid Howells     truncations.  This gives the cache a chance to note that a cache object
379e0484344SDavid Howells     may be incoherent with respect to the server and may need writing back
380e0484344SDavid Howells     later.  This may also cause the cached data to be scrapped on later
381e0484344SDavid Howells     rebinding if not properly committed.
3820e822145SMauro Carvalho Chehab
3830e822145SMauro Carvalho Chehab
384e0484344SDavid Howells   * Begin an operation for the netfs lib [mandatory]::
3850e822145SMauro Carvalho Chehab
386e0484344SDavid Howells	bool (*begin_operation)(struct netfs_cache_resources *cres,
387e0484344SDavid Howells				enum fscache_want_state want_state);
3880e822145SMauro Carvalho Chehab
389e0484344SDavid Howells     This method is called when an I/O operation is being set up (read, write
390e0484344SDavid Howells     or resize).  The caller holds an access pin on the cookie and must have
391e0484344SDavid Howells     marked the cookie as in-use.
3920e822145SMauro Carvalho Chehab
393e0484344SDavid Howells     If it can, the backend should attach any resources it needs to keep around
394e0484344SDavid Howells     to the netfs_cache_resources object and return true.
3950e822145SMauro Carvalho Chehab
396e0484344SDavid Howells     If it can't complete the setup, it should return false.
3970e822145SMauro Carvalho Chehab
398e0484344SDavid Howells     The want_state parameter indicates the state the caller needs the cache
399e0484344SDavid Howells     object to be in and what it wants to do during the operation:
4000e822145SMauro Carvalho Chehab
401e0484344SDavid Howells	* ``FSCACHE_WANT_PARAMS`` - The caller just wants to access cache
402e0484344SDavid Howells	  object parameters; it doesn't need to do data I/O yet.
4030e822145SMauro Carvalho Chehab
404e0484344SDavid Howells	* ``FSCACHE_WANT_READ`` - The caller wants to read data.
4050e822145SMauro Carvalho Chehab
406e0484344SDavid Howells	* ``FSCACHE_WANT_WRITE`` - The caller wants to write to or resize the
407e0484344SDavid Howells          cache object.
4080e822145SMauro Carvalho Chehab
409e0484344SDavid Howells     Note that there won't necessarily be anything attached to the cookie's
410e0484344SDavid Howells     cache_priv yet if the cookie is still being created.
4110e822145SMauro Carvalho Chehab
4120e822145SMauro Carvalho Chehab
413e0484344SDavid HowellsData I/O API
414e0484344SDavid Howells============
4150e822145SMauro Carvalho Chehab
416e0484344SDavid HowellsA cache backend provides a data I/O API by through the netfs library's ``struct
417e0484344SDavid Howellsnetfs_cache_ops`` attached to a ``struct netfs_cache_resources`` by the
418e0484344SDavid Howells``begin_operation`` method described above.
4190e822145SMauro Carvalho Chehab
420e0484344SDavid HowellsSee the Documentation/filesystems/netfs_library.rst for a description.
4210e822145SMauro Carvalho Chehab
4220e822145SMauro Carvalho Chehab
423e0484344SDavid HowellsMiscellaneous Functions
424e0484344SDavid Howells=======================
4250e822145SMauro Carvalho Chehab
4260e822145SMauro Carvalho ChehabFS-Cache provides some utilities that a cache backend may make use of:
4270e822145SMauro Carvalho Chehab
4280e822145SMauro Carvalho Chehab   * Note occurrence of an I/O error in a cache::
4290e822145SMauro Carvalho Chehab
430e0484344SDavid Howells	void fscache_io_error(struct fscache_cache *cache);
4310e822145SMauro Carvalho Chehab
432e0484344SDavid Howells     This tells FS-Cache that an I/O error occurred in the cache.  This
433e0484344SDavid Howells     prevents any new I/O from being started on the cache.
4340e822145SMauro Carvalho Chehab
4350e822145SMauro Carvalho Chehab     This does not actually withdraw the cache.  That must be done separately.
4360e822145SMauro Carvalho Chehab
437e0484344SDavid Howells   * Note cessation of caching on a cookie due to failure::
4380e822145SMauro Carvalho Chehab
439e0484344SDavid Howells	void fscache_caching_failed(struct fscache_cookie *cookie);
4400e822145SMauro Carvalho Chehab
441e0484344SDavid Howells     This notes that a the caching that was being done on a cookie failed in
442e0484344SDavid Howells     some way, for instance the backing storage failed to be created or
443e0484344SDavid Howells     invalidation failed and that no further I/O operations should take place
444e0484344SDavid Howells     on it until the cache is reset.
4450e822145SMauro Carvalho Chehab
446e0484344SDavid Howells   * Count I/O requests::
4470e822145SMauro Carvalho Chehab
448e0484344SDavid Howells	void fscache_count_read(void);
449e0484344SDavid Howells	void fscache_count_write(void);
4500e822145SMauro Carvalho Chehab
451e0484344SDavid Howells     These record reads and writes from/to the cache.  The numbers are
452e0484344SDavid Howells     displayed in /proc/fs/fscache/stats.
4530e822145SMauro Carvalho Chehab
454e0484344SDavid Howells   * Count out-of-space errors::
4550e822145SMauro Carvalho Chehab
456e0484344SDavid Howells	void fscache_count_no_write_space(void);
457e0484344SDavid Howells	void fscache_count_no_create_space(void);
4580e822145SMauro Carvalho Chehab
459e0484344SDavid Howells     These record ENOSPC errors in the cache, divided into failures of data
460e0484344SDavid Howells     writes and failures of filesystem object creations (e.g. mkdir).
4610e822145SMauro Carvalho Chehab
462e0484344SDavid Howells   * Count objects culled::
4630e822145SMauro Carvalho Chehab
464e0484344SDavid Howells	void fscache_count_culled(void);
4650e822145SMauro Carvalho Chehab
466e0484344SDavid Howells     This records the culling of an object.
4670e822145SMauro Carvalho Chehab
468e0484344SDavid Howells   * Get the cookie from a set of cache resources::
4690e822145SMauro Carvalho Chehab
470e0484344SDavid Howells	struct fscache_cookie *fscache_cres_cookie(struct netfs_cache_resources *cres)
4710e822145SMauro Carvalho Chehab
472e0484344SDavid Howells     Pull a pointer to the cookie from the cache resources.  This may return a
473e0484344SDavid Howells     NULL cookie if no cookie was set.
4740e822145SMauro Carvalho Chehab
4750e822145SMauro Carvalho Chehab
476e0484344SDavid HowellsAPI Function Reference
477e0484344SDavid Howells======================
4780e822145SMauro Carvalho Chehab
479e0484344SDavid Howells.. kernel-doc:: include/linux/fscache-cache.h
480