Blame view

fs/fscache/internal.h 12.2 KB
06b3db1b9   David Howells   FS-Cache: Add mai...
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
  /* Internal definitions for FS-Cache
   *
   * 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.
   */
  
  /*
   * Lock order, in the order in which multiple locks should be obtained:
   * - fscache_addremove_sem
   * - cookie->lock
   * - cookie->parent->lock
   * - cache->object_list_lock
   * - object->lock
   * - object->parent->lock
1bccf513a   David Howells   FS-Cache: Fix loc...
20
   * - cookie->stores_lock
06b3db1b9   David Howells   FS-Cache: Add mai...
21
22
23
24
25
26
27
28
29
30
31
   * - fscache_thread_lock
   *
   */
  
  #include <linux/fscache-cache.h>
  #include <linux/sched.h>
  
  #define FSCACHE_MIN_THREADS	4
  #define FSCACHE_MAX_THREADS	32
  
  /*
348ca1029   David Howells   FS-Cache: Fixup r...
32
   * cache.c
0e04d4cef   David Howells   FS-Cache: Add cac...
33
34
35
36
37
38
39
40
   */
  extern struct list_head fscache_cache_list;
  extern struct rw_semaphore fscache_addremove_sem;
  
  extern struct fscache_cache *fscache_select_cache_for_object(
  	struct fscache_cookie *);
  
  /*
348ca1029   David Howells   FS-Cache: Fixup r...
41
   * cookie.c
955d00917   David Howells   FS-Cache: Provide...
42
43
44
45
46
47
48
   */
  extern struct kmem_cache *fscache_cookie_jar;
  
  extern void fscache_cookie_init_once(void *);
  extern void __fscache_cookie_put(struct fscache_cookie *);
  
  /*
348ca1029   David Howells   FS-Cache: Fixup r...
49
   * fsdef.c
a6891645c   David Howells   FS-Cache: Root in...
50
51
52
53
54
   */
  extern struct fscache_cookie fscache_fsdef_index;
  extern struct fscache_cookie_def fscache_fsdef_netfs_def;
  
  /*
348ca1029   David Howells   FS-Cache: Fixup r...
55
   * histogram.c
7394daa8c   David Howells   FS-Cache: Add use...
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
   */
  #ifdef CONFIG_FSCACHE_HISTOGRAM
  extern atomic_t fscache_obj_instantiate_histogram[HZ];
  extern atomic_t fscache_objs_histogram[HZ];
  extern atomic_t fscache_ops_histogram[HZ];
  extern atomic_t fscache_retrieval_delay_histogram[HZ];
  extern atomic_t fscache_retrieval_histogram[HZ];
  
  static inline void fscache_hist(atomic_t histogram[], unsigned long start_jif)
  {
  	unsigned long jif = jiffies - start_jif;
  	if (jif >= HZ)
  		jif = HZ - 1;
  	atomic_inc(&histogram[jif]);
  }
  
  extern const struct file_operations fscache_histogram_fops;
  
  #else
  #define fscache_hist(hist, start_jif) do {} while (0)
  #endif
  
  /*
348ca1029   David Howells   FS-Cache: Fixup r...
79
   * main.c
06b3db1b9   David Howells   FS-Cache: Add mai...
80
81
82
83
84
   */
  extern unsigned fscache_defer_lookup;
  extern unsigned fscache_defer_create;
  extern unsigned fscache_debug;
  extern struct kobject *fscache_root;
8b8edefa2   Tejun Heo   fscache: convert ...
85
  extern struct workqueue_struct *fscache_object_wq;
8af7c1243   Tejun Heo   fscache: convert ...
86
  extern struct workqueue_struct *fscache_op_wq;
8b8edefa2   Tejun Heo   fscache: convert ...
87
88
89
90
91
92
  DECLARE_PER_CPU(wait_queue_head_t, fscache_object_cong_wait);
  
  static inline bool fscache_object_congested(void)
  {
  	return workqueue_congested(WORK_CPU_UNBOUND, fscache_object_wq);
  }
06b3db1b9   David Howells   FS-Cache: Add mai...
93

2868cbea7   David Howells   FS-Cache: Bit wai...
94
95
  extern int fscache_wait_bit(void *);
  extern int fscache_wait_bit_interruptible(void *);
7394daa8c   David Howells   FS-Cache: Add use...
96
  /*
348ca1029   David Howells   FS-Cache: Fixup r...
97
   * object.c
36c955902   David Howells   FS-Cache: Object ...
98
   */
4fbf4291a   David Howells   FS-Cache: Allow t...
99
  extern const char fscache_object_states_short[FSCACHE_OBJECT__NSTATES][5];
36c955902   David Howells   FS-Cache: Object ...
100
101
102
103
104
  extern void fscache_withdrawing_object(struct fscache_cache *,
  				       struct fscache_object *);
  extern void fscache_enqueue_object(struct fscache_object *);
  
  /*
4fbf4291a   David Howells   FS-Cache: Allow t...
105
106
107
108
109
110
111
112
113
114
115
   * object-list.c
   */
  #ifdef CONFIG_FSCACHE_OBJECT_LIST
  extern const struct file_operations fscache_objlist_fops;
  
  extern void fscache_objlist_add(struct fscache_object *);
  #else
  #define fscache_objlist_add(object) do {} while(0)
  #endif
  
  /*
348ca1029   David Howells   FS-Cache: Fixup r...
116
   * operation.c
36c955902   David Howells   FS-Cache: Object ...
117
   */
952efe7b7   David Howells   FS-Cache: Add and...
118
119
120
121
  extern int fscache_submit_exclusive_op(struct fscache_object *,
  				       struct fscache_operation *);
  extern int fscache_submit_op(struct fscache_object *,
  			     struct fscache_operation *);
5753c4418   David Howells   FS-Cache: Permit ...
122
  extern int fscache_cancel_op(struct fscache_operation *);
952efe7b7   David Howells   FS-Cache: Add and...
123
124
125
  extern void fscache_abort_object(struct fscache_object *);
  extern void fscache_start_operations(struct fscache_object *);
  extern void fscache_operation_gc(struct work_struct *);
36c955902   David Howells   FS-Cache: Object ...
126
127
  
  /*
348ca1029   David Howells   FS-Cache: Fixup r...
128
   * proc.c
7394daa8c   David Howells   FS-Cache: Add use...
129
130
131
132
133
134
135
136
137
138
   */
  #ifdef CONFIG_PROC_FS
  extern int __init fscache_proc_init(void);
  extern void fscache_proc_cleanup(void);
  #else
  #define fscache_proc_init()	(0)
  #define fscache_proc_cleanup()	do {} while (0)
  #endif
  
  /*
348ca1029   David Howells   FS-Cache: Fixup r...
139
   * stats.c
7394daa8c   David Howells   FS-Cache: Add use...
140
141
142
143
144
145
146
147
148
149
150
   */
  #ifdef CONFIG_FSCACHE_STATS
  extern atomic_t fscache_n_ops_processed[FSCACHE_MAX_THREADS];
  extern atomic_t fscache_n_objs_processed[FSCACHE_MAX_THREADS];
  
  extern atomic_t fscache_n_op_pend;
  extern atomic_t fscache_n_op_run;
  extern atomic_t fscache_n_op_enqueue;
  extern atomic_t fscache_n_op_deferred_release;
  extern atomic_t fscache_n_op_release;
  extern atomic_t fscache_n_op_gc;
5753c4418   David Howells   FS-Cache: Permit ...
151
  extern atomic_t fscache_n_op_cancelled;
e3d4d28b1   David Howells   FS-Cache: Handle ...
152
  extern atomic_t fscache_n_op_rejected;
7394daa8c   David Howells   FS-Cache: Add use...
153
154
155
156
157
158
159
160
161
162
163
  
  extern atomic_t fscache_n_attr_changed;
  extern atomic_t fscache_n_attr_changed_ok;
  extern atomic_t fscache_n_attr_changed_nobufs;
  extern atomic_t fscache_n_attr_changed_nomem;
  extern atomic_t fscache_n_attr_changed_calls;
  
  extern atomic_t fscache_n_allocs;
  extern atomic_t fscache_n_allocs_ok;
  extern atomic_t fscache_n_allocs_wait;
  extern atomic_t fscache_n_allocs_nobufs;
5753c4418   David Howells   FS-Cache: Permit ...
164
  extern atomic_t fscache_n_allocs_intr;
60d543ca7   David Howells   FS-Cache: Start p...
165
  extern atomic_t fscache_n_allocs_object_dead;
7394daa8c   David Howells   FS-Cache: Add use...
166
167
168
169
170
171
172
173
174
175
  extern atomic_t fscache_n_alloc_ops;
  extern atomic_t fscache_n_alloc_op_waits;
  
  extern atomic_t fscache_n_retrievals;
  extern atomic_t fscache_n_retrievals_ok;
  extern atomic_t fscache_n_retrievals_wait;
  extern atomic_t fscache_n_retrievals_nodata;
  extern atomic_t fscache_n_retrievals_nobufs;
  extern atomic_t fscache_n_retrievals_intr;
  extern atomic_t fscache_n_retrievals_nomem;
60d543ca7   David Howells   FS-Cache: Start p...
176
  extern atomic_t fscache_n_retrievals_object_dead;
7394daa8c   David Howells   FS-Cache: Add use...
177
178
179
180
181
182
183
184
185
186
  extern atomic_t fscache_n_retrieval_ops;
  extern atomic_t fscache_n_retrieval_op_waits;
  
  extern atomic_t fscache_n_stores;
  extern atomic_t fscache_n_stores_ok;
  extern atomic_t fscache_n_stores_again;
  extern atomic_t fscache_n_stores_nobufs;
  extern atomic_t fscache_n_stores_oom;
  extern atomic_t fscache_n_store_ops;
  extern atomic_t fscache_n_store_calls;
1bccf513a   David Howells   FS-Cache: Fix loc...
187
188
189
  extern atomic_t fscache_n_store_pages;
  extern atomic_t fscache_n_store_radix_deletes;
  extern atomic_t fscache_n_store_pages_over_limit;
7394daa8c   David Howells   FS-Cache: Add use...
190

201a15428   David Howells   FS-Cache: Handle ...
191
192
193
194
  extern atomic_t fscache_n_store_vmscan_not_storing;
  extern atomic_t fscache_n_store_vmscan_gone;
  extern atomic_t fscache_n_store_vmscan_busy;
  extern atomic_t fscache_n_store_vmscan_cancelled;
7394daa8c   David Howells   FS-Cache: Add use...
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
  extern atomic_t fscache_n_marks;
  extern atomic_t fscache_n_uncaches;
  
  extern atomic_t fscache_n_acquires;
  extern atomic_t fscache_n_acquires_null;
  extern atomic_t fscache_n_acquires_no_cache;
  extern atomic_t fscache_n_acquires_ok;
  extern atomic_t fscache_n_acquires_nobufs;
  extern atomic_t fscache_n_acquires_oom;
  
  extern atomic_t fscache_n_updates;
  extern atomic_t fscache_n_updates_null;
  extern atomic_t fscache_n_updates_run;
  
  extern atomic_t fscache_n_relinquishes;
  extern atomic_t fscache_n_relinquishes_null;
  extern atomic_t fscache_n_relinquishes_waitcrt;
2175bb06d   David Howells   FS-Cache: Add a r...
212
  extern atomic_t fscache_n_relinquishes_retire;
7394daa8c   David Howells   FS-Cache: Add use...
213
214
215
216
217
218
219
220
221
222
  
  extern atomic_t fscache_n_cookie_index;
  extern atomic_t fscache_n_cookie_data;
  extern atomic_t fscache_n_cookie_special;
  
  extern atomic_t fscache_n_object_alloc;
  extern atomic_t fscache_n_object_no_alloc;
  extern atomic_t fscache_n_object_lookups;
  extern atomic_t fscache_n_object_lookups_negative;
  extern atomic_t fscache_n_object_lookups_positive;
fee096deb   David Howells   CacheFiles: Catch...
223
  extern atomic_t fscache_n_object_lookups_timed_out;
7394daa8c   David Howells   FS-Cache: Add use...
224
225
226
227
228
229
230
231
  extern atomic_t fscache_n_object_created;
  extern atomic_t fscache_n_object_avail;
  extern atomic_t fscache_n_object_dead;
  
  extern atomic_t fscache_n_checkaux_none;
  extern atomic_t fscache_n_checkaux_okay;
  extern atomic_t fscache_n_checkaux_update;
  extern atomic_t fscache_n_checkaux_obsolete;
52bd75fdb   David Howells   FS-Cache: Add cou...
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
  extern atomic_t fscache_n_cop_alloc_object;
  extern atomic_t fscache_n_cop_lookup_object;
  extern atomic_t fscache_n_cop_lookup_complete;
  extern atomic_t fscache_n_cop_grab_object;
  extern atomic_t fscache_n_cop_update_object;
  extern atomic_t fscache_n_cop_drop_object;
  extern atomic_t fscache_n_cop_put_object;
  extern atomic_t fscache_n_cop_sync_cache;
  extern atomic_t fscache_n_cop_attr_changed;
  extern atomic_t fscache_n_cop_read_or_alloc_page;
  extern atomic_t fscache_n_cop_read_or_alloc_pages;
  extern atomic_t fscache_n_cop_allocate_page;
  extern atomic_t fscache_n_cop_allocate_pages;
  extern atomic_t fscache_n_cop_write_page;
  extern atomic_t fscache_n_cop_uncache_page;
  extern atomic_t fscache_n_cop_dissociate_pages;
7394daa8c   David Howells   FS-Cache: Add use...
248
249
250
251
  static inline void fscache_stat(atomic_t *stat)
  {
  	atomic_inc(stat);
  }
52bd75fdb   David Howells   FS-Cache: Add cou...
252
253
254
255
  static inline void fscache_stat_d(atomic_t *stat)
  {
  	atomic_dec(stat);
  }
60d543ca7   David Howells   FS-Cache: Start p...
256
  #define __fscache_stat(stat) (stat)
7394daa8c   David Howells   FS-Cache: Add use...
257
258
  extern const struct file_operations fscache_stats_fops;
  #else
60d543ca7   David Howells   FS-Cache: Start p...
259
  #define __fscache_stat(stat) (NULL)
7394daa8c   David Howells   FS-Cache: Add use...
260
  #define fscache_stat(stat) do {} while (0)
4fa9f4ede   David Howells   FS-Cache: Provide...
261
  #define fscache_stat_d(stat) do {} while (0)
7394daa8c   David Howells   FS-Cache: Add use...
262
  #endif
0e04d4cef   David Howells   FS-Cache: Add cac...
263
264
265
266
267
268
269
270
  /*
   * raise an event on an object
   * - if the event is not masked for that object, then the object is
   *   queued for attention by the thread pool.
   */
  static inline void fscache_raise_event(struct fscache_object *object,
  				       unsigned event)
  {
36c955902   David Howells   FS-Cache: Object ...
271
272
273
274
275
276
277
278
279
280
281
282
283
  	if (!test_and_set_bit(event, &object->events) &&
  	    test_bit(event, &object->event_mask))
  		fscache_enqueue_object(object);
  }
  
  /*
   * drop a reference to a cookie
   */
  static inline void fscache_cookie_put(struct fscache_cookie *cookie)
  {
  	BUG_ON(atomic_read(&cookie->usage) <= 0);
  	if (atomic_dec_and_test(&cookie->usage))
  		__fscache_cookie_put(cookie);
0e04d4cef   David Howells   FS-Cache: Add cac...
284
  }
b51088228   David Howells   FS-Cache: Impleme...
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
  /*
   * get an extra reference to a netfs retrieval context
   */
  static inline
  void *fscache_get_context(struct fscache_cookie *cookie, void *context)
  {
  	if (cookie->def->get_context)
  		cookie->def->get_context(cookie->netfs_data, context);
  	return context;
  }
  
  /*
   * release a reference to a netfs retrieval context
   */
  static inline
  void fscache_put_context(struct fscache_cookie *cookie, void *context)
  {
  	if (cookie->def->put_context)
  		cookie->def->put_context(cookie->netfs_data, context);
  }
06b3db1b9   David Howells   FS-Cache: Add mai...
305
306
307
308
309
310
311
  /*****************************************************************************/
  /*
   * debug tracing
   */
  #define dbgprintk(FMT, ...) \
  	printk(KERN_DEBUG "[%-6.6s] "FMT"
  ", current->comm, ##__VA_ARGS__)
06b3db1b9   David Howells   FS-Cache: Add mai...
312
313
314
  #define kenter(FMT, ...) dbgprintk("==> %s("FMT")", __func__, ##__VA_ARGS__)
  #define kleave(FMT, ...) dbgprintk("<== %s()"FMT"", __func__, ##__VA_ARGS__)
  #define kdebug(FMT, ...) dbgprintk(FMT, ##__VA_ARGS__)
12fdff3fc   David Howells   Add a dummy print...
315
  #define kjournal(FMT, ...) no_printk(FMT, ##__VA_ARGS__)
06b3db1b9   David Howells   FS-Cache: Add mai...
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
  
  #ifdef __KDEBUG
  #define _enter(FMT, ...) kenter(FMT, ##__VA_ARGS__)
  #define _leave(FMT, ...) kleave(FMT, ##__VA_ARGS__)
  #define _debug(FMT, ...) kdebug(FMT, ##__VA_ARGS__)
  
  #elif defined(CONFIG_FSCACHE_DEBUG)
  #define _enter(FMT, ...)			\
  do {						\
  	if (__do_kdebug(ENTER))			\
  		kenter(FMT, ##__VA_ARGS__);	\
  } while (0)
  
  #define _leave(FMT, ...)			\
  do {						\
  	if (__do_kdebug(LEAVE))			\
  		kleave(FMT, ##__VA_ARGS__);	\
  } while (0)
  
  #define _debug(FMT, ...)			\
  do {						\
  	if (__do_kdebug(DEBUG))			\
  		kdebug(FMT, ##__VA_ARGS__);	\
  } while (0)
  
  #else
12fdff3fc   David Howells   Add a dummy print...
342
343
344
  #define _enter(FMT, ...) no_printk("==> %s("FMT")", __func__, ##__VA_ARGS__)
  #define _leave(FMT, ...) no_printk("<== %s()"FMT"", __func__, ##__VA_ARGS__)
  #define _debug(FMT, ...) no_printk(FMT, ##__VA_ARGS__)
06b3db1b9   David Howells   FS-Cache: Add mai...
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
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
  #endif
  
  /*
   * determine whether a particular optional debugging point should be logged
   * - we need to go through three steps to persuade cpp to correctly join the
   *   shorthand in FSCACHE_DEBUG_LEVEL with its prefix
   */
  #define ____do_kdebug(LEVEL, POINT) \
  	unlikely((fscache_debug & \
  		  (FSCACHE_POINT_##POINT << (FSCACHE_DEBUG_ ## LEVEL * 3))))
  #define ___do_kdebug(LEVEL, POINT) \
  	____do_kdebug(LEVEL, POINT)
  #define __do_kdebug(POINT) \
  	___do_kdebug(FSCACHE_DEBUG_LEVEL, POINT)
  
  #define FSCACHE_DEBUG_CACHE	0
  #define FSCACHE_DEBUG_COOKIE	1
  #define FSCACHE_DEBUG_PAGE	2
  #define FSCACHE_DEBUG_OPERATION	3
  
  #define FSCACHE_POINT_ENTER	1
  #define FSCACHE_POINT_LEAVE	2
  #define FSCACHE_POINT_DEBUG	4
  
  #ifndef FSCACHE_DEBUG_LEVEL
  #define FSCACHE_DEBUG_LEVEL CACHE
  #endif
  
  /*
   * assertions
   */
  #if 1 /* defined(__KDEBUGALL) */
  
  #define ASSERT(X)							\
  do {									\
  	if (unlikely(!(X))) {						\
  		printk(KERN_ERR "
  ");					\
  		printk(KERN_ERR "FS-Cache: Assertion failed
  ");	\
  		BUG();							\
  	}								\
  } while (0)
  
  #define ASSERTCMP(X, OP, Y)						\
  do {									\
  	if (unlikely(!((X) OP (Y)))) {					\
  		printk(KERN_ERR "
  ");					\
  		printk(KERN_ERR "FS-Cache: Assertion failed
  ");	\
  		printk(KERN_ERR "%lx " #OP " %lx is false
  ",		\
  		       (unsigned long)(X), (unsigned long)(Y));		\
  		BUG();							\
  	}								\
  } while (0)
  
  #define ASSERTIF(C, X)							\
  do {									\
  	if (unlikely((C) && !(X))) {					\
  		printk(KERN_ERR "
  ");					\
  		printk(KERN_ERR "FS-Cache: Assertion failed
  ");	\
  		BUG();							\
  	}								\
  } while (0)
  
  #define ASSERTIFCMP(C, X, OP, Y)					\
  do {									\
  	if (unlikely((C) && !((X) OP (Y)))) {				\
  		printk(KERN_ERR "
  ");					\
  		printk(KERN_ERR "FS-Cache: Assertion failed
  ");	\
  		printk(KERN_ERR "%lx " #OP " %lx is false
  ",		\
  		       (unsigned long)(X), (unsigned long)(Y));		\
  		BUG();							\
  	}								\
  } while (0)
  
  #else
  
  #define ASSERT(X)			do {} while (0)
  #define ASSERTCMP(X, OP, Y)		do {} while (0)
  #define ASSERTIF(C, X)			do {} while (0)
  #define ASSERTIFCMP(C, X, OP, Y)	do {} while (0)
  
  #endif /* assert or not */