internal.h 8.8 KB

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