This source file includes following definitions.
- fscache_get_retrieval
- fscache_enqueue_retrieval
- fscache_retrieval_complete
- fscache_put_retrieval
- fscache_object_is_live
- fscache_object_is_dying
- fscache_object_is_available
- fscache_cache_is_broken
- fscache_object_is_active
- fscache_object_destroyed
- fscache_object_lookup_error
- fscache_set_store_limit
- fscache_end_io
- __fscache_use_cookie
- fscache_use_cookie
- __fscache_unuse_cookie
- __fscache_wake_unused_cookie
- fscache_unuse_cookie
- __printf
1
2
3
4
5
6
7
8
9
10
11
12
13
14 #ifndef _LINUX_FSCACHE_CACHE_H
15 #define _LINUX_FSCACHE_CACHE_H
16
17 #include <linux/fscache.h>
18 #include <linux/sched.h>
19 #include <linux/workqueue.h>
20
21 #define NR_MAXCACHES BITS_PER_LONG
22
23 struct fscache_cache;
24 struct fscache_cache_ops;
25 struct fscache_object;
26 struct fscache_operation;
27
28 enum fscache_obj_ref_trace {
29 fscache_obj_get_add_to_deps,
30 fscache_obj_get_queue,
31 fscache_obj_put_alloc_fail,
32 fscache_obj_put_attach_fail,
33 fscache_obj_put_drop_obj,
34 fscache_obj_put_enq_dep,
35 fscache_obj_put_queue,
36 fscache_obj_put_work,
37 fscache_obj_ref__nr_traces
38 };
39
40
41
42
43 struct fscache_cache_tag {
44 struct list_head link;
45 struct fscache_cache *cache;
46 unsigned long flags;
47 #define FSCACHE_TAG_RESERVED 0
48 atomic_t usage;
49 char name[0];
50 };
51
52
53
54
55 struct fscache_cache {
56 const struct fscache_cache_ops *ops;
57 struct fscache_cache_tag *tag;
58 struct kobject *kobj;
59 struct list_head link;
60 size_t max_index_size;
61 char identifier[36];
62
63
64 struct work_struct op_gc;
65 struct list_head object_list;
66 struct list_head op_gc_list;
67 spinlock_t object_list_lock;
68 spinlock_t op_gc_list_lock;
69 atomic_t object_count;
70 struct fscache_object *fsdef;
71 unsigned long flags;
72 #define FSCACHE_IOERROR 0
73 #define FSCACHE_CACHE_WITHDRAWN 1
74 };
75
76 extern wait_queue_head_t fscache_cache_cleared_wq;
77
78
79
80
81
82
83 typedef void (*fscache_operation_release_t)(struct fscache_operation *op);
84 typedef void (*fscache_operation_processor_t)(struct fscache_operation *op);
85 typedef void (*fscache_operation_cancel_t)(struct fscache_operation *op);
86
87 enum fscache_operation_state {
88 FSCACHE_OP_ST_BLANK,
89 FSCACHE_OP_ST_INITIALISED,
90 FSCACHE_OP_ST_PENDING,
91 FSCACHE_OP_ST_IN_PROGRESS,
92 FSCACHE_OP_ST_COMPLETE,
93 FSCACHE_OP_ST_CANCELLED,
94 FSCACHE_OP_ST_DEAD
95 };
96
97 struct fscache_operation {
98 struct work_struct work;
99 struct list_head pend_link;
100 struct fscache_object *object;
101
102 unsigned long flags;
103 #define FSCACHE_OP_TYPE 0x000f
104 #define FSCACHE_OP_ASYNC 0x0001
105 #define FSCACHE_OP_MYTHREAD 0x0002
106 #define FSCACHE_OP_WAITING 4
107 #define FSCACHE_OP_EXCLUSIVE 5
108 #define FSCACHE_OP_DEC_READ_CNT 6
109 #define FSCACHE_OP_UNUSE_COOKIE 7
110 #define FSCACHE_OP_KEEP_FLAGS 0x00f0
111
112 enum fscache_operation_state state;
113 atomic_t usage;
114 unsigned debug_id;
115
116
117
118
119 fscache_operation_processor_t processor;
120
121
122 fscache_operation_cancel_t cancel;
123
124
125 fscache_operation_release_t release;
126 };
127
128 extern atomic_t fscache_op_debug_id;
129 extern void fscache_op_work_func(struct work_struct *work);
130
131 extern void fscache_enqueue_operation(struct fscache_operation *);
132 extern void fscache_op_complete(struct fscache_operation *, bool);
133 extern void fscache_put_operation(struct fscache_operation *);
134 extern void fscache_operation_init(struct fscache_cookie *,
135 struct fscache_operation *,
136 fscache_operation_processor_t,
137 fscache_operation_cancel_t,
138 fscache_operation_release_t);
139
140
141
142
143 struct fscache_retrieval {
144 struct fscache_operation op;
145 struct fscache_cookie *cookie;
146 struct address_space *mapping;
147 fscache_rw_complete_t end_io_func;
148 void *context;
149 struct list_head to_do;
150 unsigned long start_time;
151 atomic_t n_pages;
152 };
153
154 typedef int (*fscache_page_retrieval_func_t)(struct fscache_retrieval *op,
155 struct page *page,
156 gfp_t gfp);
157
158 typedef int (*fscache_pages_retrieval_func_t)(struct fscache_retrieval *op,
159 struct list_head *pages,
160 unsigned *nr_pages,
161 gfp_t gfp);
162
163
164
165
166
167
168
169 static inline
170 struct fscache_retrieval *fscache_get_retrieval(struct fscache_retrieval *op)
171 {
172 atomic_inc(&op->op.usage);
173 return op;
174 }
175
176
177
178
179
180
181
182 static inline void fscache_enqueue_retrieval(struct fscache_retrieval *op)
183 {
184 fscache_enqueue_operation(&op->op);
185 }
186
187
188
189
190
191
192 static inline void fscache_retrieval_complete(struct fscache_retrieval *op,
193 int n_pages)
194 {
195 if (atomic_sub_return_relaxed(n_pages, &op->n_pages) <= 0)
196 fscache_op_complete(&op->op, false);
197 }
198
199
200
201
202
203
204
205 static inline void fscache_put_retrieval(struct fscache_retrieval *op)
206 {
207 fscache_put_operation(&op->op);
208 }
209
210
211
212
213
214
215
216
217 struct fscache_storage {
218 struct fscache_operation op;
219 pgoff_t store_limit;
220 };
221
222
223
224
225 struct fscache_cache_ops {
226
227 const char *name;
228
229
230 struct fscache_object *(*alloc_object)(struct fscache_cache *cache,
231 struct fscache_cookie *cookie);
232
233
234
235
236 int (*lookup_object)(struct fscache_object *object);
237
238
239 void (*lookup_complete)(struct fscache_object *object);
240
241
242 struct fscache_object *(*grab_object)(struct fscache_object *object,
243 enum fscache_obj_ref_trace why);
244
245
246 int (*pin_object)(struct fscache_object *object);
247
248
249 void (*unpin_object)(struct fscache_object *object);
250
251
252
253 int (*check_consistency)(struct fscache_operation *op);
254
255
256 void (*update_object)(struct fscache_object *object);
257
258
259 void (*invalidate_object)(struct fscache_operation *op);
260
261
262
263 void (*drop_object)(struct fscache_object *object);
264
265
266 void (*put_object)(struct fscache_object *object,
267 enum fscache_obj_ref_trace why);
268
269
270 void (*sync_cache)(struct fscache_cache *cache);
271
272
273
274 int (*attr_changed)(struct fscache_object *object);
275
276
277 int (*reserve_space)(struct fscache_object *object, loff_t i_size);
278
279
280
281 fscache_page_retrieval_func_t read_or_alloc_page;
282
283
284
285 fscache_pages_retrieval_func_t read_or_alloc_pages;
286
287
288
289 fscache_page_retrieval_func_t allocate_page;
290
291
292
293 fscache_pages_retrieval_func_t allocate_pages;
294
295
296 int (*write_page)(struct fscache_storage *op, struct page *page);
297
298
299
300
301
302 void (*uncache_page)(struct fscache_object *object,
303 struct page *page);
304
305
306 void (*dissociate_pages)(struct fscache_cache *cache);
307 };
308
309 extern struct fscache_cookie fscache_fsdef_index;
310
311
312
313
314 enum {
315 FSCACHE_OBJECT_EV_NEW_CHILD,
316 FSCACHE_OBJECT_EV_PARENT_READY,
317 FSCACHE_OBJECT_EV_UPDATE,
318 FSCACHE_OBJECT_EV_INVALIDATE,
319 FSCACHE_OBJECT_EV_CLEARED,
320 FSCACHE_OBJECT_EV_ERROR,
321 FSCACHE_OBJECT_EV_KILL,
322 NR_FSCACHE_OBJECT_EVENTS
323 };
324
325 #define FSCACHE_OBJECT_EVENTS_MASK ((1UL << NR_FSCACHE_OBJECT_EVENTS) - 1)
326
327
328
329
330 struct fscache_transition {
331 unsigned long events;
332 const struct fscache_state *transit_to;
333 };
334
335 struct fscache_state {
336 char name[24];
337 char short_name[8];
338 const struct fscache_state *(*work)(struct fscache_object *object,
339 int event);
340 const struct fscache_transition transitions[];
341 };
342
343
344
345
346 struct fscache_object {
347 const struct fscache_state *state;
348 const struct fscache_transition *oob_table;
349 int debug_id;
350 int n_children;
351 int n_ops;
352 int n_obj_ops;
353 int n_in_progress;
354 int n_exclusive;
355 atomic_t n_reads;
356 spinlock_t lock;
357
358 unsigned long lookup_jif;
359 unsigned long oob_event_mask;
360 unsigned long event_mask;
361 unsigned long events;
362
363
364 unsigned long flags;
365 #define FSCACHE_OBJECT_LOCK 0
366 #define FSCACHE_OBJECT_PENDING_WRITE 1
367 #define FSCACHE_OBJECT_WAITING 2
368 #define FSCACHE_OBJECT_IS_LIVE 3
369 #define FSCACHE_OBJECT_IS_LOOKED_UP 4
370 #define FSCACHE_OBJECT_IS_AVAILABLE 5
371 #define FSCACHE_OBJECT_RETIRED 6
372 #define FSCACHE_OBJECT_KILLED_BY_CACHE 7
373 #define FSCACHE_OBJECT_RUN_AFTER_DEAD 8
374
375 struct list_head cache_link;
376 struct hlist_node cookie_link;
377 struct fscache_cache *cache;
378 struct fscache_cookie *cookie;
379 struct fscache_object *parent;
380 struct work_struct work;
381 struct list_head dependents;
382 struct list_head dep_link;
383 struct list_head pending_ops;
384 #ifdef CONFIG_FSCACHE_OBJECT_LIST
385 struct rb_node objlist_link;
386 #endif
387 pgoff_t store_limit;
388 loff_t store_limit_l;
389 };
390
391 extern void fscache_object_init(struct fscache_object *, struct fscache_cookie *,
392 struct fscache_cache *);
393 extern void fscache_object_destroy(struct fscache_object *);
394
395 extern void fscache_object_lookup_negative(struct fscache_object *object);
396 extern void fscache_obtained_object(struct fscache_object *object);
397
398 static inline bool fscache_object_is_live(struct fscache_object *object)
399 {
400 return test_bit(FSCACHE_OBJECT_IS_LIVE, &object->flags);
401 }
402
403 static inline bool fscache_object_is_dying(struct fscache_object *object)
404 {
405 return !fscache_object_is_live(object);
406 }
407
408 static inline bool fscache_object_is_available(struct fscache_object *object)
409 {
410 return test_bit(FSCACHE_OBJECT_IS_AVAILABLE, &object->flags);
411 }
412
413 static inline bool fscache_cache_is_broken(struct fscache_object *object)
414 {
415 return test_bit(FSCACHE_IOERROR, &object->cache->flags);
416 }
417
418 static inline bool fscache_object_is_active(struct fscache_object *object)
419 {
420 return fscache_object_is_available(object) &&
421 fscache_object_is_live(object) &&
422 !fscache_cache_is_broken(object);
423 }
424
425
426
427
428
429
430
431 static inline void fscache_object_destroyed(struct fscache_cache *cache)
432 {
433 if (atomic_dec_and_test(&cache->object_count))
434 wake_up_all(&fscache_cache_cleared_wq);
435 }
436
437
438
439
440
441
442
443
444 static inline void fscache_object_lookup_error(struct fscache_object *object)
445 {
446 set_bit(FSCACHE_OBJECT_EV_ERROR, &object->events);
447 }
448
449
450
451
452
453
454
455
456
457
458
459
460 static inline
461 void fscache_set_store_limit(struct fscache_object *object, loff_t i_size)
462 {
463 object->store_limit_l = i_size;
464 object->store_limit = i_size >> PAGE_SHIFT;
465 if (i_size & ~PAGE_MASK)
466 object->store_limit++;
467 }
468
469
470
471
472
473
474
475
476
477
478 static inline void fscache_end_io(struct fscache_retrieval *op,
479 struct page *page, int error)
480 {
481 op->end_io_func(page, op->context, error);
482 }
483
484 static inline void __fscache_use_cookie(struct fscache_cookie *cookie)
485 {
486 atomic_inc(&cookie->n_active);
487 }
488
489
490
491
492
493
494
495
496 static inline bool fscache_use_cookie(struct fscache_object *object)
497 {
498 struct fscache_cookie *cookie = object->cookie;
499 return atomic_inc_not_zero(&cookie->n_active) != 0;
500 }
501
502 static inline bool __fscache_unuse_cookie(struct fscache_cookie *cookie)
503 {
504 return atomic_dec_and_test(&cookie->n_active);
505 }
506
507 static inline void __fscache_wake_unused_cookie(struct fscache_cookie *cookie)
508 {
509 wake_up_var(&cookie->n_active);
510 }
511
512
513
514
515
516
517
518
519 static inline void fscache_unuse_cookie(struct fscache_object *object)
520 {
521 struct fscache_cookie *cookie = object->cookie;
522 if (__fscache_unuse_cookie(cookie))
523 __fscache_wake_unused_cookie(cookie);
524 }
525
526
527
528
529 extern __printf(3, 4)
530 void fscache_init_cache(struct fscache_cache *cache,
531 const struct fscache_cache_ops *ops,
532 const char *idfmt, ...);
533
534 extern int fscache_add_cache(struct fscache_cache *cache,
535 struct fscache_object *fsdef,
536 const char *tagname);
537 extern void fscache_withdraw_cache(struct fscache_cache *cache);
538
539 extern void fscache_io_error(struct fscache_cache *cache);
540
541 extern void fscache_mark_page_cached(struct fscache_retrieval *op,
542 struct page *page);
543
544 extern void fscache_mark_pages_cached(struct fscache_retrieval *op,
545 struct pagevec *pagevec);
546
547 extern bool fscache_object_sleep_till_congested(signed long *timeoutp);
548
549 extern enum fscache_checkaux fscache_check_aux(struct fscache_object *object,
550 const void *data,
551 uint16_t datalen,
552 loff_t object_size);
553
554 extern void fscache_object_retrying_stale(struct fscache_object *object);
555
556 enum fscache_why_object_killed {
557 FSCACHE_OBJECT_IS_STALE,
558 FSCACHE_OBJECT_NO_SPACE,
559 FSCACHE_OBJECT_WAS_RETIRED,
560 FSCACHE_OBJECT_WAS_CULLED,
561 };
562 extern void fscache_object_mark_killed(struct fscache_object *object,
563 enum fscache_why_object_killed why);
564
565 #endif