internal.h 8.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329
  1. /* Internal definitions for FS-Cache
  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. /*
  12. * Lock order, in the order in which multiple locks should be obtained:
  13. * - fscache_addremove_sem
  14. * - cookie->lock
  15. * - cookie->parent->lock
  16. * - cache->object_list_lock
  17. * - object->lock
  18. * - object->parent->lock
  19. * - fscache_thread_lock
  20. *
  21. */
  22. #include <linux/fscache-cache.h>
  23. #include <linux/sched.h>
  24. #define FSCACHE_MIN_THREADS 4
  25. #define FSCACHE_MAX_THREADS 32
  26. /*
  27. * fsc-cache.c
  28. */
  29. extern struct list_head fscache_cache_list;
  30. extern struct rw_semaphore fscache_addremove_sem;
  31. extern struct fscache_cache *fscache_select_cache_for_object(
  32. struct fscache_cookie *);
  33. /*
  34. * fsc-cookie.c
  35. */
  36. extern struct kmem_cache *fscache_cookie_jar;
  37. extern void fscache_cookie_init_once(void *);
  38. extern void __fscache_cookie_put(struct fscache_cookie *);
  39. /*
  40. * fsc-fsdef.c
  41. */
  42. extern struct fscache_cookie fscache_fsdef_index;
  43. extern struct fscache_cookie_def fscache_fsdef_netfs_def;
  44. /*
  45. * fsc-histogram.c
  46. */
  47. #ifdef CONFIG_FSCACHE_HISTOGRAM
  48. extern atomic_t fscache_obj_instantiate_histogram[HZ];
  49. extern atomic_t fscache_objs_histogram[HZ];
  50. extern atomic_t fscache_ops_histogram[HZ];
  51. extern atomic_t fscache_retrieval_delay_histogram[HZ];
  52. extern atomic_t fscache_retrieval_histogram[HZ];
  53. static inline void fscache_hist(atomic_t histogram[], unsigned long start_jif)
  54. {
  55. unsigned long jif = jiffies - start_jif;
  56. if (jif >= HZ)
  57. jif = HZ - 1;
  58. atomic_inc(&histogram[jif]);
  59. }
  60. extern const struct file_operations fscache_histogram_fops;
  61. #else
  62. #define fscache_hist(hist, start_jif) do {} while (0)
  63. #endif
  64. /*
  65. * fsc-main.c
  66. */
  67. extern unsigned fscache_defer_lookup;
  68. extern unsigned fscache_defer_create;
  69. extern unsigned fscache_debug;
  70. extern struct kobject *fscache_root;
  71. extern int fscache_wait_bit(void *);
  72. extern int fscache_wait_bit_interruptible(void *);
  73. /*
  74. * fsc-proc.c
  75. */
  76. #ifdef CONFIG_PROC_FS
  77. extern int __init fscache_proc_init(void);
  78. extern void fscache_proc_cleanup(void);
  79. #else
  80. #define fscache_proc_init() (0)
  81. #define fscache_proc_cleanup() do {} while (0)
  82. #endif
  83. /*
  84. * fsc-stats.c
  85. */
  86. #ifdef CONFIG_FSCACHE_STATS
  87. extern atomic_t fscache_n_ops_processed[FSCACHE_MAX_THREADS];
  88. extern atomic_t fscache_n_objs_processed[FSCACHE_MAX_THREADS];
  89. extern atomic_t fscache_n_op_pend;
  90. extern atomic_t fscache_n_op_run;
  91. extern atomic_t fscache_n_op_enqueue;
  92. extern atomic_t fscache_n_op_deferred_release;
  93. extern atomic_t fscache_n_op_release;
  94. extern atomic_t fscache_n_op_gc;
  95. extern atomic_t fscache_n_attr_changed;
  96. extern atomic_t fscache_n_attr_changed_ok;
  97. extern atomic_t fscache_n_attr_changed_nobufs;
  98. extern atomic_t fscache_n_attr_changed_nomem;
  99. extern atomic_t fscache_n_attr_changed_calls;
  100. extern atomic_t fscache_n_allocs;
  101. extern atomic_t fscache_n_allocs_ok;
  102. extern atomic_t fscache_n_allocs_wait;
  103. extern atomic_t fscache_n_allocs_nobufs;
  104. extern atomic_t fscache_n_alloc_ops;
  105. extern atomic_t fscache_n_alloc_op_waits;
  106. extern atomic_t fscache_n_retrievals;
  107. extern atomic_t fscache_n_retrievals_ok;
  108. extern atomic_t fscache_n_retrievals_wait;
  109. extern atomic_t fscache_n_retrievals_nodata;
  110. extern atomic_t fscache_n_retrievals_nobufs;
  111. extern atomic_t fscache_n_retrievals_intr;
  112. extern atomic_t fscache_n_retrievals_nomem;
  113. extern atomic_t fscache_n_retrieval_ops;
  114. extern atomic_t fscache_n_retrieval_op_waits;
  115. extern atomic_t fscache_n_stores;
  116. extern atomic_t fscache_n_stores_ok;
  117. extern atomic_t fscache_n_stores_again;
  118. extern atomic_t fscache_n_stores_nobufs;
  119. extern atomic_t fscache_n_stores_oom;
  120. extern atomic_t fscache_n_store_ops;
  121. extern atomic_t fscache_n_store_calls;
  122. extern atomic_t fscache_n_marks;
  123. extern atomic_t fscache_n_uncaches;
  124. extern atomic_t fscache_n_acquires;
  125. extern atomic_t fscache_n_acquires_null;
  126. extern atomic_t fscache_n_acquires_no_cache;
  127. extern atomic_t fscache_n_acquires_ok;
  128. extern atomic_t fscache_n_acquires_nobufs;
  129. extern atomic_t fscache_n_acquires_oom;
  130. extern atomic_t fscache_n_updates;
  131. extern atomic_t fscache_n_updates_null;
  132. extern atomic_t fscache_n_updates_run;
  133. extern atomic_t fscache_n_relinquishes;
  134. extern atomic_t fscache_n_relinquishes_null;
  135. extern atomic_t fscache_n_relinquishes_waitcrt;
  136. extern atomic_t fscache_n_cookie_index;
  137. extern atomic_t fscache_n_cookie_data;
  138. extern atomic_t fscache_n_cookie_special;
  139. extern atomic_t fscache_n_object_alloc;
  140. extern atomic_t fscache_n_object_no_alloc;
  141. extern atomic_t fscache_n_object_lookups;
  142. extern atomic_t fscache_n_object_lookups_negative;
  143. extern atomic_t fscache_n_object_lookups_positive;
  144. extern atomic_t fscache_n_object_created;
  145. extern atomic_t fscache_n_object_avail;
  146. extern atomic_t fscache_n_object_dead;
  147. extern atomic_t fscache_n_checkaux_none;
  148. extern atomic_t fscache_n_checkaux_okay;
  149. extern atomic_t fscache_n_checkaux_update;
  150. extern atomic_t fscache_n_checkaux_obsolete;
  151. static inline void fscache_stat(atomic_t *stat)
  152. {
  153. atomic_inc(stat);
  154. }
  155. extern const struct file_operations fscache_stats_fops;
  156. #else
  157. #define fscache_stat(stat) do {} while (0)
  158. #endif
  159. /*
  160. * raise an event on an object
  161. * - if the event is not masked for that object, then the object is
  162. * queued for attention by the thread pool.
  163. */
  164. static inline void fscache_raise_event(struct fscache_object *object,
  165. unsigned event)
  166. {
  167. BUG(); // TODO
  168. }
  169. /*****************************************************************************/
  170. /*
  171. * debug tracing
  172. */
  173. #define dbgprintk(FMT, ...) \
  174. printk(KERN_DEBUG "[%-6.6s] "FMT"\n", current->comm, ##__VA_ARGS__)
  175. /* make sure we maintain the format strings, even when debugging is disabled */
  176. static inline __attribute__((format(printf, 1, 2)))
  177. void _dbprintk(const char *fmt, ...)
  178. {
  179. }
  180. #define kenter(FMT, ...) dbgprintk("==> %s("FMT")", __func__, ##__VA_ARGS__)
  181. #define kleave(FMT, ...) dbgprintk("<== %s()"FMT"", __func__, ##__VA_ARGS__)
  182. #define kdebug(FMT, ...) dbgprintk(FMT, ##__VA_ARGS__)
  183. #define kjournal(FMT, ...) _dbprintk(FMT, ##__VA_ARGS__)
  184. #ifdef __KDEBUG
  185. #define _enter(FMT, ...) kenter(FMT, ##__VA_ARGS__)
  186. #define _leave(FMT, ...) kleave(FMT, ##__VA_ARGS__)
  187. #define _debug(FMT, ...) kdebug(FMT, ##__VA_ARGS__)
  188. #elif defined(CONFIG_FSCACHE_DEBUG)
  189. #define _enter(FMT, ...) \
  190. do { \
  191. if (__do_kdebug(ENTER)) \
  192. kenter(FMT, ##__VA_ARGS__); \
  193. } while (0)
  194. #define _leave(FMT, ...) \
  195. do { \
  196. if (__do_kdebug(LEAVE)) \
  197. kleave(FMT, ##__VA_ARGS__); \
  198. } while (0)
  199. #define _debug(FMT, ...) \
  200. do { \
  201. if (__do_kdebug(DEBUG)) \
  202. kdebug(FMT, ##__VA_ARGS__); \
  203. } while (0)
  204. #else
  205. #define _enter(FMT, ...) _dbprintk("==> %s("FMT")", __func__, ##__VA_ARGS__)
  206. #define _leave(FMT, ...) _dbprintk("<== %s()"FMT"", __func__, ##__VA_ARGS__)
  207. #define _debug(FMT, ...) _dbprintk(FMT, ##__VA_ARGS__)
  208. #endif
  209. /*
  210. * determine whether a particular optional debugging point should be logged
  211. * - we need to go through three steps to persuade cpp to correctly join the
  212. * shorthand in FSCACHE_DEBUG_LEVEL with its prefix
  213. */
  214. #define ____do_kdebug(LEVEL, POINT) \
  215. unlikely((fscache_debug & \
  216. (FSCACHE_POINT_##POINT << (FSCACHE_DEBUG_ ## LEVEL * 3))))
  217. #define ___do_kdebug(LEVEL, POINT) \
  218. ____do_kdebug(LEVEL, POINT)
  219. #define __do_kdebug(POINT) \
  220. ___do_kdebug(FSCACHE_DEBUG_LEVEL, POINT)
  221. #define FSCACHE_DEBUG_CACHE 0
  222. #define FSCACHE_DEBUG_COOKIE 1
  223. #define FSCACHE_DEBUG_PAGE 2
  224. #define FSCACHE_DEBUG_OPERATION 3
  225. #define FSCACHE_POINT_ENTER 1
  226. #define FSCACHE_POINT_LEAVE 2
  227. #define FSCACHE_POINT_DEBUG 4
  228. #ifndef FSCACHE_DEBUG_LEVEL
  229. #define FSCACHE_DEBUG_LEVEL CACHE
  230. #endif
  231. /*
  232. * assertions
  233. */
  234. #if 1 /* defined(__KDEBUGALL) */
  235. #define ASSERT(X) \
  236. do { \
  237. if (unlikely(!(X))) { \
  238. printk(KERN_ERR "\n"); \
  239. printk(KERN_ERR "FS-Cache: Assertion failed\n"); \
  240. BUG(); \
  241. } \
  242. } while (0)
  243. #define ASSERTCMP(X, OP, Y) \
  244. do { \
  245. if (unlikely(!((X) OP (Y)))) { \
  246. printk(KERN_ERR "\n"); \
  247. printk(KERN_ERR "FS-Cache: Assertion failed\n"); \
  248. printk(KERN_ERR "%lx " #OP " %lx is false\n", \
  249. (unsigned long)(X), (unsigned long)(Y)); \
  250. BUG(); \
  251. } \
  252. } while (0)
  253. #define ASSERTIF(C, X) \
  254. do { \
  255. if (unlikely((C) && !(X))) { \
  256. printk(KERN_ERR "\n"); \
  257. printk(KERN_ERR "FS-Cache: Assertion failed\n"); \
  258. BUG(); \
  259. } \
  260. } while (0)
  261. #define ASSERTIFCMP(C, X, OP, Y) \
  262. do { \
  263. if (unlikely((C) && !((X) OP (Y)))) { \
  264. printk(KERN_ERR "\n"); \
  265. printk(KERN_ERR "FS-Cache: Assertion failed\n"); \
  266. printk(KERN_ERR "%lx " #OP " %lx is false\n", \
  267. (unsigned long)(X), (unsigned long)(Y)); \
  268. BUG(); \
  269. } \
  270. } while (0)
  271. #else
  272. #define ASSERT(X) do {} while (0)
  273. #define ASSERTCMP(X, OP, Y) do {} while (0)
  274. #define ASSERTIF(C, X) do {} while (0)
  275. #define ASSERTIFCMP(C, X, OP, Y) do {} while (0)
  276. #endif /* assert or not */