internal.h 8.6 KB

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