Blame view

include/linux/fscache-cache.h 18.4 KB
0dfc41d1e   David Howells   FS-Cache: Add the...
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
  /* General filesystem caching backing cache interface
   *
   * Copyright (C) 2004-2007 Red Hat, Inc. All Rights Reserved.
   * Written by David Howells (dhowells@redhat.com)
   *
   * This program is free software; you can redistribute it and/or
   * modify it under the terms of the GNU General Public License
   * as published by the Free Software Foundation; either version
   * 2 of the License, or (at your option) any later version.
   *
   * NOTE!!! See:
   *
   *	Documentation/filesystems/caching/backend-api.txt
   *
   * for a description of the cache backend interface declared here.
   */
  
  #ifndef _LINUX_FSCACHE_CACHE_H
  #define _LINUX_FSCACHE_CACHE_H
  
  #include <linux/fscache.h>
  #include <linux/sched.h>
8b8edefa2   Tejun Heo   fscache: convert ...
23
  #include <linux/workqueue.h>
0dfc41d1e   David Howells   FS-Cache: Add the...
24
25
26
27
28
29
30
  
  #define NR_MAXCACHES BITS_PER_LONG
  
  struct fscache_cache;
  struct fscache_cache_ops;
  struct fscache_object;
  struct fscache_operation;
0dfc41d1e   David Howells   FS-Cache: Add the...
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
  /*
   * cache tag definition
   */
  struct fscache_cache_tag {
  	struct list_head	link;
  	struct fscache_cache	*cache;		/* cache referred to by this tag */
  	unsigned long		flags;
  #define FSCACHE_TAG_RESERVED	0		/* T if tag is reserved for a cache */
  	atomic_t		usage;
  	char			name[0];	/* tag name */
  };
  
  /*
   * cache definition
   */
  struct fscache_cache {
  	const struct fscache_cache_ops *ops;
  	struct fscache_cache_tag *tag;		/* tag representing this cache */
  	struct kobject		*kobj;		/* system representation of this cache */
  	struct list_head	link;		/* link in list of caches */
  	size_t			max_index_size;	/* maximum size of index data */
  	char			identifier[36];	/* cache label */
  
  	/* node management */
  	struct work_struct	op_gc;		/* operation garbage collector */
  	struct list_head	object_list;	/* list of data/index objects */
  	struct list_head	op_gc_list;	/* list of ops to be deleted */
  	spinlock_t		object_list_lock;
  	spinlock_t		op_gc_list_lock;
  	atomic_t		object_count;	/* no. of live objects in this cache */
  	struct fscache_object	*fsdef;		/* object for the fsdef index */
  	unsigned long		flags;
  #define FSCACHE_IOERROR		0	/* cache stopped on I/O error */
  #define FSCACHE_CACHE_WITHDRAWN	1	/* cache has been withdrawn */
  };
  
  extern wait_queue_head_t fscache_cache_cleared_wq;
  
  /*
   * operation to be applied to a cache object
   * - retrieval initiation operations are done in the context of the process
   *   that issued them, and not in an async thread pool
   */
  typedef void (*fscache_operation_release_t)(struct fscache_operation *op);
  typedef void (*fscache_operation_processor_t)(struct fscache_operation *op);
d3b97ca4a   David Howells   FS-Cache: The ope...
76
  typedef void (*fscache_operation_cancel_t)(struct fscache_operation *op);
0dfc41d1e   David Howells   FS-Cache: Add the...
77

9f10523f8   David Howells   FS-Cache: Fix ope...
78
79
80
81
82
83
84
85
86
  enum fscache_operation_state {
  	FSCACHE_OP_ST_BLANK,		/* Op is not yet submitted */
  	FSCACHE_OP_ST_INITIALISED,	/* Op is initialised */
  	FSCACHE_OP_ST_PENDING,		/* Op is blocked from running */
  	FSCACHE_OP_ST_IN_PROGRESS,	/* Op is in progress */
  	FSCACHE_OP_ST_COMPLETE,		/* Op is complete */
  	FSCACHE_OP_ST_CANCELLED,	/* Op has been cancelled */
  	FSCACHE_OP_ST_DEAD		/* Op is now dead */
  };
0dfc41d1e   David Howells   FS-Cache: Add the...
87
  struct fscache_operation {
8af7c1243   Tejun Heo   fscache: convert ...
88
  	struct work_struct	work;		/* record for async ops */
0dfc41d1e   David Howells   FS-Cache: Add the...
89
90
91
92
93
  	struct list_head	pend_link;	/* link in object->pending_ops */
  	struct fscache_object	*object;	/* object to be operated upon */
  
  	unsigned long		flags;
  #define FSCACHE_OP_TYPE		0x000f	/* operation type */
8af7c1243   Tejun Heo   fscache: convert ...
94
95
  #define FSCACHE_OP_ASYNC	0x0001	/* - async op, processor may sleep for disk */
  #define FSCACHE_OP_MYTHREAD	0x0002	/* - processing is done be issuing thread, not pool */
0dfc41d1e   David Howells   FS-Cache: Add the...
96
97
  #define FSCACHE_OP_WAITING	4	/* cleared when op is woken */
  #define FSCACHE_OP_EXCLUSIVE	5	/* exclusive op, other ops must wait */
9f10523f8   David Howells   FS-Cache: Fix ope...
98
  #define FSCACHE_OP_DEC_READ_CNT	6	/* decrement object->n_reads on destruction */
1362729b1   David Howells   FS-Cache: Simplif...
99
100
  #define FSCACHE_OP_UNUSE_COOKIE	7	/* call fscache_unuse_cookie() on completion */
  #define FSCACHE_OP_KEEP_FLAGS	0x00f0	/* flags to keep when repurposing an op */
0dfc41d1e   David Howells   FS-Cache: Add the...
101

9f10523f8   David Howells   FS-Cache: Fix ope...
102
  	enum fscache_operation_state state;
0dfc41d1e   David Howells   FS-Cache: Add the...
103
104
105
106
107
108
109
  	atomic_t		usage;
  	unsigned		debug_id;	/* debugging ID */
  
  	/* operation processor callback
  	 * - can be NULL if FSCACHE_OP_WAITING is going to be used to perform
  	 *   the op in a non-pool thread */
  	fscache_operation_processor_t processor;
d3b97ca4a   David Howells   FS-Cache: The ope...
110
111
  	/* Operation cancellation cleanup (optional) */
  	fscache_operation_cancel_t cancel;
0dfc41d1e   David Howells   FS-Cache: Add the...
112
113
114
115
116
  	/* operation releaser */
  	fscache_operation_release_t release;
  };
  
  extern atomic_t fscache_op_debug_id;
8af7c1243   Tejun Heo   fscache: convert ...
117
  extern void fscache_op_work_func(struct work_struct *work);
0dfc41d1e   David Howells   FS-Cache: Add the...
118
119
  
  extern void fscache_enqueue_operation(struct fscache_operation *);
1f372dff1   David Howells   FS-Cache: Mark ca...
120
  extern void fscache_op_complete(struct fscache_operation *, bool);
0dfc41d1e   David Howells   FS-Cache: Add the...
121
  extern void fscache_put_operation(struct fscache_operation *);
1339ec98e   David Howells   FS-Cache: Out of ...
122
123
  extern void fscache_operation_init(struct fscache_operation *,
  				   fscache_operation_processor_t,
d3b97ca4a   David Howells   FS-Cache: The ope...
124
  				   fscache_operation_cancel_t,
1339ec98e   David Howells   FS-Cache: Out of ...
125
  				   fscache_operation_release_t);
0dfc41d1e   David Howells   FS-Cache: Add the...
126

0dfc41d1e   David Howells   FS-Cache: Add the...
127
128
129
130
131
  /*
   * data read operation
   */
  struct fscache_retrieval {
  	struct fscache_operation op;
4a47132ff   David Howells   FS-Cache: Retain ...
132
  	struct fscache_cookie	*cookie;	/* The netfs cookie */
0dfc41d1e   David Howells   FS-Cache: Add the...
133
134
135
136
137
  	struct address_space	*mapping;	/* netfs pages */
  	fscache_rw_complete_t	end_io_func;	/* function to call on I/O completion */
  	void			*context;	/* netfs read context (pinned) */
  	struct list_head	to_do;		/* list of things to be done by the backend */
  	unsigned long		start_time;	/* time at which retrieval started */
1bb4b7f98   David Howells   FS-Cache: The ret...
138
  	atomic_t		n_pages;	/* number of pages to be retrieved */
0dfc41d1e   David Howells   FS-Cache: Add the...
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
  };
  
  typedef int (*fscache_page_retrieval_func_t)(struct fscache_retrieval *op,
  					     struct page *page,
  					     gfp_t gfp);
  
  typedef int (*fscache_pages_retrieval_func_t)(struct fscache_retrieval *op,
  					      struct list_head *pages,
  					      unsigned *nr_pages,
  					      gfp_t gfp);
  
  /**
   * fscache_get_retrieval - Get an extra reference on a retrieval operation
   * @op: The retrieval operation to get a reference on
   *
   * Get an extra reference on a retrieval operation.
   */
  static inline
  struct fscache_retrieval *fscache_get_retrieval(struct fscache_retrieval *op)
  {
  	atomic_inc(&op->op.usage);
  	return op;
  }
  
  /**
   * fscache_enqueue_retrieval - Enqueue a retrieval operation for processing
   * @op: The retrieval operation affected
   *
   * Enqueue a retrieval operation for processing by the FS-Cache thread pool.
   */
  static inline void fscache_enqueue_retrieval(struct fscache_retrieval *op)
  {
  	fscache_enqueue_operation(&op->op);
  }
  
  /**
9f10523f8   David Howells   FS-Cache: Fix ope...
175
176
177
178
179
180
181
   * fscache_retrieval_complete - Record (partial) completion of a retrieval
   * @op: The retrieval operation affected
   * @n_pages: The number of pages to account for
   */
  static inline void fscache_retrieval_complete(struct fscache_retrieval *op,
  					      int n_pages)
  {
1bb4b7f98   David Howells   FS-Cache: The ret...
182
183
  	atomic_sub(n_pages, &op->n_pages);
  	if (atomic_read(&op->n_pages) <= 0)
1f372dff1   David Howells   FS-Cache: Mark ca...
184
  		fscache_op_complete(&op->op, true);
9f10523f8   David Howells   FS-Cache: Fix ope...
185
186
187
  }
  
  /**
0dfc41d1e   David Howells   FS-Cache: Add the...
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
   * fscache_put_retrieval - Drop a reference to a retrieval operation
   * @op: The retrieval operation affected
   *
   * Drop a reference to a retrieval operation.
   */
  static inline void fscache_put_retrieval(struct fscache_retrieval *op)
  {
  	fscache_put_operation(&op->op);
  }
  
  /*
   * cached page storage work item
   * - used to do three things:
   *   - batch writes to the cache
   *   - do cache writes asynchronously
   *   - defer writes until cache object lookup completion
   */
  struct fscache_storage {
  	struct fscache_operation op;
  	pgoff_t			store_limit;	/* don't write more than this */
  };
  
  /*
   * cache operations
   */
  struct fscache_cache_ops {
  	/* name of cache provider */
  	const char *name;
  
  	/* allocate an object record for a cookie */
  	struct fscache_object *(*alloc_object)(struct fscache_cache *cache,
  					       struct fscache_cookie *cookie);
fee096deb   David Howells   CacheFiles: Catch...
220
221
222
223
  	/* look up the object for a cookie
  	 * - return -ETIMEDOUT to be requeued
  	 */
  	int (*lookup_object)(struct fscache_object *object);
0dfc41d1e   David Howells   FS-Cache: Add the...
224
225
226
227
228
229
230
231
232
233
234
235
  
  	/* finished looking up */
  	void (*lookup_complete)(struct fscache_object *object);
  
  	/* increment the usage count on this object (may fail if unmounting) */
  	struct fscache_object *(*grab_object)(struct fscache_object *object);
  
  	/* pin an object in the cache */
  	int (*pin_object)(struct fscache_object *object);
  
  	/* unpin an object in the cache */
  	void (*unpin_object)(struct fscache_object *object);
da9803bc8   David Howells   FS-Cache: Add int...
236
237
  	/* check the consistency between the backing cache and the FS-Cache
  	 * cookie */
480ce08a7   Yan, Zheng   FS-Cache: make ch...
238
  	int (*check_consistency)(struct fscache_operation *op);
da9803bc8   David Howells   FS-Cache: Add int...
239

25985edce   Lucas De Marchi   Fix common misspe...
240
  	/* store the updated auxiliary data on an object */
0dfc41d1e   David Howells   FS-Cache: Add the...
241
  	void (*update_object)(struct fscache_object *object);
ef778e7ae   David Howells   FS-Cache: Provide...
242
243
  	/* Invalidate an object */
  	void (*invalidate_object)(struct fscache_operation *op);
0dfc41d1e   David Howells   FS-Cache: Add the...
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
  	/* discard the resources pinned by an object and effect retirement if
  	 * necessary */
  	void (*drop_object)(struct fscache_object *object);
  
  	/* dispose of a reference to an object */
  	void (*put_object)(struct fscache_object *object);
  
  	/* sync a cache */
  	void (*sync_cache)(struct fscache_cache *cache);
  
  	/* notification that the attributes of a non-index object (such as
  	 * i_size) have changed */
  	int (*attr_changed)(struct fscache_object *object);
  
  	/* reserve space for an object's data and associated metadata */
  	int (*reserve_space)(struct fscache_object *object, loff_t i_size);
  
  	/* request a backing block for a page be read or allocated in the
  	 * cache */
  	fscache_page_retrieval_func_t read_or_alloc_page;
  
  	/* request backing blocks for a list of pages be read or allocated in
  	 * the cache */
  	fscache_pages_retrieval_func_t read_or_alloc_pages;
  
  	/* request a backing block for a page be allocated in the cache so that
  	 * it can be written directly */
  	fscache_page_retrieval_func_t allocate_page;
  
  	/* request backing blocks for pages be allocated in the cache so that
  	 * they can be written directly */
  	fscache_pages_retrieval_func_t allocate_pages;
  
  	/* write a page to its backing block in the cache */
  	int (*write_page)(struct fscache_storage *op, struct page *page);
  
  	/* detach backing block from a page (optional)
  	 * - must release the cookie lock before returning
  	 * - may sleep
  	 */
  	void (*uncache_page)(struct fscache_object *object,
  			     struct page *page);
  
  	/* dissociate a cache from all the pages it was backing */
  	void (*dissociate_pages)(struct fscache_cache *cache);
  };
0dfc41d1e   David Howells   FS-Cache: Add the...
290
291
292
  extern struct fscache_cookie fscache_fsdef_index;
  
  /*
36a02de5d   David Howells   FS-Cache: Convert...
293
294
295
   * Event list for fscache_object::{event_mask,events}
   */
  enum {
caaef6900   David Howells   FS-Cache: Fix obj...
296
297
  	FSCACHE_OBJECT_EV_NEW_CHILD,	/* T if object has a new child */
  	FSCACHE_OBJECT_EV_PARENT_READY,	/* T if object's parent is ready */
36a02de5d   David Howells   FS-Cache: Convert...
298
299
300
301
  	FSCACHE_OBJECT_EV_UPDATE,	/* T if object should be updated */
  	FSCACHE_OBJECT_EV_INVALIDATE,	/* T if cache requested object invalidation */
  	FSCACHE_OBJECT_EV_CLEARED,	/* T if accessors all gone */
  	FSCACHE_OBJECT_EV_ERROR,	/* T if fatal error occurred during processing */
caaef6900   David Howells   FS-Cache: Fix obj...
302
  	FSCACHE_OBJECT_EV_KILL,		/* T if netfs relinquished or cache withdrew object */
36a02de5d   David Howells   FS-Cache: Convert...
303
304
305
306
307
308
  	NR_FSCACHE_OBJECT_EVENTS
  };
  
  #define FSCACHE_OBJECT_EVENTS_MASK ((1UL << NR_FSCACHE_OBJECT_EVENTS) - 1)
  
  /*
caaef6900   David Howells   FS-Cache: Fix obj...
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
   * States for object state machine.
   */
  struct fscache_transition {
  	unsigned long events;
  	const struct fscache_state *transit_to;
  };
  
  struct fscache_state {
  	char name[24];
  	char short_name[8];
  	const struct fscache_state *(*work)(struct fscache_object *object,
  					    int event);
  	const struct fscache_transition transitions[];
  };
  
  /*
0dfc41d1e   David Howells   FS-Cache: Add the...
325
326
327
   * on-disk cache file or index handle
   */
  struct fscache_object {
caaef6900   David Howells   FS-Cache: Fix obj...
328
329
  	const struct fscache_state *state;	/* Object state machine state */
  	const struct fscache_transition *oob_table; /* OOB state transition table */
0dfc41d1e   David Howells   FS-Cache: Add the...
330
331
  	int			debug_id;	/* debugging ID */
  	int			n_children;	/* number of child objects */
9f10523f8   David Howells   FS-Cache: Fix ope...
332
  	int			n_ops;		/* number of extant ops on object */
0dfc41d1e   David Howells   FS-Cache: Add the...
333
334
  	int			n_obj_ops;	/* number of object ops outstanding on object */
  	int			n_in_progress;	/* number of ops in progress */
9f10523f8   David Howells   FS-Cache: Fix ope...
335
  	int			n_exclusive;	/* number of exclusive ops queued or in progress */
4fbf4291a   David Howells   FS-Cache: Allow t...
336
  	atomic_t		n_reads;	/* number of read ops in progress */
0dfc41d1e   David Howells   FS-Cache: Add the...
337
338
339
  	spinlock_t		lock;		/* state and operations lock */
  
  	unsigned long		lookup_jif;	/* time at which lookup started */
caaef6900   David Howells   FS-Cache: Fix obj...
340
  	unsigned long		oob_event_mask;	/* OOB events this object is interested in */
0dfc41d1e   David Howells   FS-Cache: Add the...
341
342
343
  	unsigned long		event_mask;	/* events this object is interested in */
  	unsigned long		events;		/* events to be processed by this object
  						 * (order is important - using fls) */
0dfc41d1e   David Howells   FS-Cache: Add the...
344
345
346
347
348
  
  	unsigned long		flags;
  #define FSCACHE_OBJECT_LOCK		0	/* T if object is busy being processed */
  #define FSCACHE_OBJECT_PENDING_WRITE	1	/* T if object has pending write */
  #define FSCACHE_OBJECT_WAITING		2	/* T if object is waiting on its parent */
1362729b1   David Howells   FS-Cache: Simplif...
349
350
351
  #define FSCACHE_OBJECT_IS_LIVE		3	/* T if object is not withdrawn or relinquished */
  #define FSCACHE_OBJECT_IS_LOOKED_UP	4	/* T if object has been looked up */
  #define FSCACHE_OBJECT_IS_AVAILABLE	5	/* T if object has become active */
94d30ae90   David Howells   FS-Cache: Provide...
352
  #define FSCACHE_OBJECT_RETIRED		6	/* T if object was retired on relinquishment */
182d919b8   David Howells   FS-Cache: Count c...
353
  #define FSCACHE_OBJECT_KILLED_BY_CACHE	7	/* T if object was killed by the cache */
e26bfebdf   David Howells   fscache: Fix dead...
354
  #define FSCACHE_OBJECT_RUN_AFTER_DEAD	8	/* T if object has been dispatched after death */
0dfc41d1e   David Howells   FS-Cache: Add the...
355
356
357
358
359
360
  
  	struct list_head	cache_link;	/* link in cache->object_list */
  	struct hlist_node	cookie_link;	/* link in cookie->backing_objects */
  	struct fscache_cache	*cache;		/* cache that supplied this object */
  	struct fscache_cookie	*cookie;	/* netfs's file/index object */
  	struct fscache_object	*parent;	/* parent object */
8b8edefa2   Tejun Heo   fscache: convert ...
361
  	struct work_struct	work;		/* attention scheduling record */
0dfc41d1e   David Howells   FS-Cache: Add the...
362
363
364
  	struct list_head	dependents;	/* FIFO of dependent objects */
  	struct list_head	dep_link;	/* link in parent's dependents list */
  	struct list_head	pending_ops;	/* unstarted operations on this object */
4fbf4291a   David Howells   FS-Cache: Allow t...
365
366
367
  #ifdef CONFIG_FSCACHE_OBJECT_LIST
  	struct rb_node		objlist_link;	/* link in global object list */
  #endif
0dfc41d1e   David Howells   FS-Cache: Add the...
368
  	pgoff_t			store_limit;	/* current storage limit */
a17754fb8   David Howells   CacheFiles: Don't...
369
  	loff_t			store_limit_l;	/* current storage limit */
0dfc41d1e   David Howells   FS-Cache: Add the...
370
  };
610be24ee   David Howells   FS-Cache: Uninlin...
371
372
  extern void fscache_object_init(struct fscache_object *, struct fscache_cookie *,
  				struct fscache_cache *);
1362729b1   David Howells   FS-Cache: Simplif...
373
  extern void fscache_object_destroy(struct fscache_object *);
0dfc41d1e   David Howells   FS-Cache: Add the...
374
375
376
  
  extern void fscache_object_lookup_negative(struct fscache_object *object);
  extern void fscache_obtained_object(struct fscache_object *object);
493f7bc11   David Howells   FS-Cache: Wrap ch...
377
378
  static inline bool fscache_object_is_live(struct fscache_object *object)
  {
caaef6900   David Howells   FS-Cache: Fix obj...
379
  	return test_bit(FSCACHE_OBJECT_IS_LIVE, &object->flags);
493f7bc11   David Howells   FS-Cache: Wrap ch...
380
381
382
383
384
385
386
387
388
  }
  
  static inline bool fscache_object_is_dying(struct fscache_object *object)
  {
  	return !fscache_object_is_live(object);
  }
  
  static inline bool fscache_object_is_available(struct fscache_object *object)
  {
caaef6900   David Howells   FS-Cache: Fix obj...
389
  	return test_bit(FSCACHE_OBJECT_IS_AVAILABLE, &object->flags);
493f7bc11   David Howells   FS-Cache: Wrap ch...
390
  }
30ceec628   David Howells   FS-Cache: When su...
391
392
393
394
  static inline bool fscache_cache_is_broken(struct fscache_object *object)
  {
  	return test_bit(FSCACHE_IOERROR, &object->cache->flags);
  }
493f7bc11   David Howells   FS-Cache: Wrap ch...
395
396
397
398
  static inline bool fscache_object_is_active(struct fscache_object *object)
  {
  	return fscache_object_is_available(object) &&
  		fscache_object_is_live(object) &&
30ceec628   David Howells   FS-Cache: When su...
399
  		!fscache_cache_is_broken(object);
493f7bc11   David Howells   FS-Cache: Wrap ch...
400
  }
0dfc41d1e   David Howells   FS-Cache: Add the...
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
  /**
   * fscache_object_destroyed - Note destruction of an object in a cache
   * @cache: The cache from which the object came
   *
   * Note the destruction and deallocation of an object record in a cache.
   */
  static inline void fscache_object_destroyed(struct fscache_cache *cache)
  {
  	if (atomic_dec_and_test(&cache->object_count))
  		wake_up_all(&fscache_cache_cleared_wq);
  }
  
  /**
   * fscache_object_lookup_error - Note an object encountered an error
   * @object: The object on which the error was encountered
   *
   * Note that an object encountered a fatal error (usually an I/O error) and
   * that it should be withdrawn as soon as possible.
   */
  static inline void fscache_object_lookup_error(struct fscache_object *object)
  {
  	set_bit(FSCACHE_OBJECT_EV_ERROR, &object->events);
  }
  
  /**
   * fscache_set_store_limit - Set the maximum size to be stored in an object
   * @object: The object to set the maximum on
   * @i_size: The limit to set in bytes
   *
   * Set the maximum size an object is permitted to reach, implying the highest
   * byte that may be written.  Intended to be called by the attr_changed() op.
   *
   * See Documentation/filesystems/caching/backend-api.txt for a complete
   * description.
   */
  static inline
  void fscache_set_store_limit(struct fscache_object *object, loff_t i_size)
  {
a17754fb8   David Howells   CacheFiles: Don't...
439
  	object->store_limit_l = i_size;
0dfc41d1e   David Howells   FS-Cache: Add the...
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
  	object->store_limit = i_size >> PAGE_SHIFT;
  	if (i_size & ~PAGE_MASK)
  		object->store_limit++;
  }
  
  /**
   * fscache_end_io - End a retrieval operation on a page
   * @op: The FS-Cache operation covering the retrieval
   * @page: The page that was to be fetched
   * @error: The error code (0 if successful)
   *
   * Note the end of an operation to retrieve a page, as covered by a particular
   * operation record.
   */
  static inline void fscache_end_io(struct fscache_retrieval *op,
  				  struct page *page, int error)
  {
  	op->end_io_func(page, op->context, error);
  }
8fb883f3e   David Howells   FS-Cache: Add use...
459
460
461
462
  static inline void __fscache_use_cookie(struct fscache_cookie *cookie)
  {
  	atomic_inc(&cookie->n_active);
  }
1362729b1   David Howells   FS-Cache: Simplif...
463
464
465
466
467
468
469
470
471
472
473
474
  /**
   * fscache_use_cookie - Request usage of cookie attached to an object
   * @object: Object description
   * 
   * Request usage of the cookie attached to an object.  NULL is returned if the
   * relinquishment had reduced the cookie usage count to 0.
   */
  static inline bool fscache_use_cookie(struct fscache_object *object)
  {
  	struct fscache_cookie *cookie = object->cookie;
  	return atomic_inc_not_zero(&cookie->n_active) != 0;
  }
8fb883f3e   David Howells   FS-Cache: Add use...
475
476
477
478
479
480
481
482
483
  static inline bool __fscache_unuse_cookie(struct fscache_cookie *cookie)
  {
  	return atomic_dec_and_test(&cookie->n_active);
  }
  
  static inline void __fscache_wake_unused_cookie(struct fscache_cookie *cookie)
  {
  	wake_up_atomic_t(&cookie->n_active);
  }
1362729b1   David Howells   FS-Cache: Simplif...
484
485
486
487
488
489
490
491
492
493
  /**
   * fscache_unuse_cookie - Cease usage of cookie attached to an object
   * @object: Object description
   * 
   * Cease usage of the cookie attached to an object.  When the users count
   * reaches zero then the cookie relinquishment will be permitted to proceed.
   */
  static inline void fscache_unuse_cookie(struct fscache_object *object)
  {
  	struct fscache_cookie *cookie = object->cookie;
8fb883f3e   David Howells   FS-Cache: Add use...
494
495
  	if (__fscache_unuse_cookie(cookie))
  		__fscache_wake_unused_cookie(cookie);
1362729b1   David Howells   FS-Cache: Simplif...
496
  }
0dfc41d1e   David Howells   FS-Cache: Add the...
497
498
499
  /*
   * out-of-line cache backend functions
   */
b9075fa96   Joe Perches   treewide: use __p...
500
501
502
503
  extern __printf(3, 4)
  void fscache_init_cache(struct fscache_cache *cache,
  			const struct fscache_cache_ops *ops,
  			const char *idfmt, ...);
0dfc41d1e   David Howells   FS-Cache: Add the...
504
505
506
507
508
509
510
  
  extern int fscache_add_cache(struct fscache_cache *cache,
  			     struct fscache_object *fsdef,
  			     const char *tagname);
  extern void fscache_withdraw_cache(struct fscache_cache *cache);
  
  extern void fscache_io_error(struct fscache_cache *cache);
c4d6d8dbf   David Howells   CacheFiles: Fix t...
511
512
  extern void fscache_mark_page_cached(struct fscache_retrieval *op,
  				     struct page *page);
0dfc41d1e   David Howells   FS-Cache: Add the...
513
514
  extern void fscache_mark_pages_cached(struct fscache_retrieval *op,
  				      struct pagevec *pagevec);
8b8edefa2   Tejun Heo   fscache: convert ...
515
  extern bool fscache_object_sleep_till_congested(signed long *timeoutp);
0dfc41d1e   David Howells   FS-Cache: Add the...
516
517
518
  extern enum fscache_checkaux fscache_check_aux(struct fscache_object *object,
  					       const void *data,
  					       uint16_t datalen);
182d919b8   David Howells   FS-Cache: Count c...
519
520
521
522
523
524
525
526
527
528
  extern void fscache_object_retrying_stale(struct fscache_object *object);
  
  enum fscache_why_object_killed {
  	FSCACHE_OBJECT_IS_STALE,
  	FSCACHE_OBJECT_NO_SPACE,
  	FSCACHE_OBJECT_WAS_RETIRED,
  	FSCACHE_OBJECT_WAS_CULLED,
  };
  extern void fscache_object_mark_killed(struct fscache_object *object,
  				       enum fscache_why_object_killed why);
0dfc41d1e   David Howells   FS-Cache: Add the...
529
  #endif /* _LINUX_FSCACHE_CACHE_H */