internal.h 8.1 KB

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