internal.h 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165
  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-main.c
  28. */
  29. extern unsigned fscache_defer_lookup;
  30. extern unsigned fscache_defer_create;
  31. extern unsigned fscache_debug;
  32. extern struct kobject *fscache_root;
  33. /*****************************************************************************/
  34. /*
  35. * debug tracing
  36. */
  37. #define dbgprintk(FMT, ...) \
  38. printk(KERN_DEBUG "[%-6.6s] "FMT"\n", current->comm, ##__VA_ARGS__)
  39. /* make sure we maintain the format strings, even when debugging is disabled */
  40. static inline __attribute__((format(printf, 1, 2)))
  41. void _dbprintk(const char *fmt, ...)
  42. {
  43. }
  44. #define kenter(FMT, ...) dbgprintk("==> %s("FMT")", __func__, ##__VA_ARGS__)
  45. #define kleave(FMT, ...) dbgprintk("<== %s()"FMT"", __func__, ##__VA_ARGS__)
  46. #define kdebug(FMT, ...) dbgprintk(FMT, ##__VA_ARGS__)
  47. #define kjournal(FMT, ...) _dbprintk(FMT, ##__VA_ARGS__)
  48. #ifdef __KDEBUG
  49. #define _enter(FMT, ...) kenter(FMT, ##__VA_ARGS__)
  50. #define _leave(FMT, ...) kleave(FMT, ##__VA_ARGS__)
  51. #define _debug(FMT, ...) kdebug(FMT, ##__VA_ARGS__)
  52. #elif defined(CONFIG_FSCACHE_DEBUG)
  53. #define _enter(FMT, ...) \
  54. do { \
  55. if (__do_kdebug(ENTER)) \
  56. kenter(FMT, ##__VA_ARGS__); \
  57. } while (0)
  58. #define _leave(FMT, ...) \
  59. do { \
  60. if (__do_kdebug(LEAVE)) \
  61. kleave(FMT, ##__VA_ARGS__); \
  62. } while (0)
  63. #define _debug(FMT, ...) \
  64. do { \
  65. if (__do_kdebug(DEBUG)) \
  66. kdebug(FMT, ##__VA_ARGS__); \
  67. } while (0)
  68. #else
  69. #define _enter(FMT, ...) _dbprintk("==> %s("FMT")", __func__, ##__VA_ARGS__)
  70. #define _leave(FMT, ...) _dbprintk("<== %s()"FMT"", __func__, ##__VA_ARGS__)
  71. #define _debug(FMT, ...) _dbprintk(FMT, ##__VA_ARGS__)
  72. #endif
  73. /*
  74. * determine whether a particular optional debugging point should be logged
  75. * - we need to go through three steps to persuade cpp to correctly join the
  76. * shorthand in FSCACHE_DEBUG_LEVEL with its prefix
  77. */
  78. #define ____do_kdebug(LEVEL, POINT) \
  79. unlikely((fscache_debug & \
  80. (FSCACHE_POINT_##POINT << (FSCACHE_DEBUG_ ## LEVEL * 3))))
  81. #define ___do_kdebug(LEVEL, POINT) \
  82. ____do_kdebug(LEVEL, POINT)
  83. #define __do_kdebug(POINT) \
  84. ___do_kdebug(FSCACHE_DEBUG_LEVEL, POINT)
  85. #define FSCACHE_DEBUG_CACHE 0
  86. #define FSCACHE_DEBUG_COOKIE 1
  87. #define FSCACHE_DEBUG_PAGE 2
  88. #define FSCACHE_DEBUG_OPERATION 3
  89. #define FSCACHE_POINT_ENTER 1
  90. #define FSCACHE_POINT_LEAVE 2
  91. #define FSCACHE_POINT_DEBUG 4
  92. #ifndef FSCACHE_DEBUG_LEVEL
  93. #define FSCACHE_DEBUG_LEVEL CACHE
  94. #endif
  95. /*
  96. * assertions
  97. */
  98. #if 1 /* defined(__KDEBUGALL) */
  99. #define ASSERT(X) \
  100. do { \
  101. if (unlikely(!(X))) { \
  102. printk(KERN_ERR "\n"); \
  103. printk(KERN_ERR "FS-Cache: Assertion failed\n"); \
  104. BUG(); \
  105. } \
  106. } while (0)
  107. #define ASSERTCMP(X, OP, Y) \
  108. do { \
  109. if (unlikely(!((X) OP (Y)))) { \
  110. printk(KERN_ERR "\n"); \
  111. printk(KERN_ERR "FS-Cache: Assertion failed\n"); \
  112. printk(KERN_ERR "%lx " #OP " %lx is false\n", \
  113. (unsigned long)(X), (unsigned long)(Y)); \
  114. BUG(); \
  115. } \
  116. } while (0)
  117. #define ASSERTIF(C, X) \
  118. do { \
  119. if (unlikely((C) && !(X))) { \
  120. printk(KERN_ERR "\n"); \
  121. printk(KERN_ERR "FS-Cache: Assertion failed\n"); \
  122. BUG(); \
  123. } \
  124. } while (0)
  125. #define ASSERTIFCMP(C, X, OP, Y) \
  126. do { \
  127. if (unlikely((C) && !((X) OP (Y)))) { \
  128. printk(KERN_ERR "\n"); \
  129. printk(KERN_ERR "FS-Cache: Assertion failed\n"); \
  130. printk(KERN_ERR "%lx " #OP " %lx is false\n", \
  131. (unsigned long)(X), (unsigned long)(Y)); \
  132. BUG(); \
  133. } \
  134. } while (0)
  135. #else
  136. #define ASSERT(X) do {} while (0)
  137. #define ASSERTCMP(X, OP, Y) do {} while (0)
  138. #define ASSERTIF(C, X) do {} while (0)
  139. #define ASSERTIFCMP(C, X, OP, Y) do {} while (0)
  140. #endif /* assert or not */