util.h 6.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228
  1. /* SPDX-License-Identifier: GPL-2.0-only */
  2. /*
  3. * Copyright (C) Sistina Software, Inc. 1997-2003 All rights reserved.
  4. * Copyright (C) 2004-2006 Red Hat, Inc. All rights reserved.
  5. */
  6. #ifndef __UTIL_DOT_H__
  7. #define __UTIL_DOT_H__
  8. #ifdef pr_fmt
  9. #undef pr_fmt
  10. #define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
  11. #endif
  12. #include <linux/mempool.h>
  13. #include "incore.h"
  14. #define fs_emerg(fs, fmt, ...) \
  15. pr_emerg("fsid=%s: " fmt, (fs)->sd_fsname, ##__VA_ARGS__)
  16. #define fs_warn(fs, fmt, ...) \
  17. pr_warn("fsid=%s: " fmt, (fs)->sd_fsname, ##__VA_ARGS__)
  18. #define fs_err(fs, fmt, ...) \
  19. pr_err("fsid=%s: " fmt, (fs)->sd_fsname, ##__VA_ARGS__)
  20. #define fs_info(fs, fmt, ...) \
  21. pr_info("fsid=%s: " fmt, (fs)->sd_fsname, ##__VA_ARGS__)
  22. void gfs2_assert_i(struct gfs2_sbd *sdp);
  23. #define gfs2_assert(sdp, assertion) \
  24. do { \
  25. if (unlikely(!(assertion))) { \
  26. gfs2_assert_i(sdp); \
  27. BUG(); \
  28. } \
  29. } while (0)
  30. void gfs2_assert_withdraw_i(struct gfs2_sbd *sdp, char *assertion,
  31. const char *function, char *file, unsigned int line,
  32. bool delayed);
  33. #define gfs2_assert_withdraw(sdp, assertion) \
  34. ({ \
  35. bool _bool = (assertion); \
  36. if (unlikely(!_bool)) \
  37. gfs2_assert_withdraw_i((sdp), #assertion, \
  38. __func__, __FILE__, __LINE__, false); \
  39. !_bool; \
  40. })
  41. #define gfs2_assert_withdraw_delayed(sdp, assertion) \
  42. ({ \
  43. bool _bool = (assertion); \
  44. if (unlikely(!_bool)) \
  45. gfs2_assert_withdraw_i((sdp), #assertion, \
  46. __func__, __FILE__, __LINE__, true); \
  47. !_bool; \
  48. })
  49. void gfs2_assert_warn_i(struct gfs2_sbd *sdp, char *assertion,
  50. const char *function, char *file, unsigned int line);
  51. #define gfs2_assert_warn(sdp, assertion) \
  52. ({ \
  53. bool _bool = (assertion); \
  54. if (unlikely(!_bool)) \
  55. gfs2_assert_warn_i((sdp), #assertion, \
  56. __func__, __FILE__, __LINE__); \
  57. !_bool; \
  58. })
  59. void gfs2_consist_i(struct gfs2_sbd *sdp,
  60. const char *function, char *file, unsigned int line);
  61. #define gfs2_consist(sdp) \
  62. gfs2_consist_i((sdp), __func__, __FILE__, __LINE__)
  63. void gfs2_consist_inode_i(struct gfs2_inode *ip,
  64. const char *function, char *file, unsigned int line);
  65. #define gfs2_consist_inode(ip) \
  66. gfs2_consist_inode_i((ip), __func__, __FILE__, __LINE__)
  67. void gfs2_consist_rgrpd_i(struct gfs2_rgrpd *rgd,
  68. const char *function, char *file, unsigned int line);
  69. #define gfs2_consist_rgrpd(rgd) \
  70. gfs2_consist_rgrpd_i((rgd), __func__, __FILE__, __LINE__)
  71. int gfs2_meta_check_ii(struct gfs2_sbd *sdp, struct buffer_head *bh,
  72. const char *type, const char *function,
  73. char *file, unsigned int line);
  74. static inline int gfs2_meta_check(struct gfs2_sbd *sdp,
  75. struct buffer_head *bh)
  76. {
  77. struct gfs2_meta_header *mh = (struct gfs2_meta_header *)bh->b_data;
  78. u32 magic = be32_to_cpu(mh->mh_magic);
  79. if (unlikely(magic != GFS2_MAGIC)) {
  80. fs_err(sdp, "Magic number missing at %llu\n",
  81. (unsigned long long)bh->b_blocknr);
  82. return -EIO;
  83. }
  84. return 0;
  85. }
  86. int gfs2_metatype_check_ii(struct gfs2_sbd *sdp, struct buffer_head *bh,
  87. u16 type, u16 t,
  88. const char *function,
  89. char *file, unsigned int line);
  90. static inline int gfs2_metatype_check_i(struct gfs2_sbd *sdp,
  91. struct buffer_head *bh,
  92. u16 type,
  93. const char *function,
  94. char *file, unsigned int line)
  95. {
  96. struct gfs2_meta_header *mh = (struct gfs2_meta_header *)bh->b_data;
  97. u32 magic = be32_to_cpu(mh->mh_magic);
  98. u16 t = be32_to_cpu(mh->mh_type);
  99. if (unlikely(magic != GFS2_MAGIC))
  100. return gfs2_meta_check_ii(sdp, bh, "magic number", function,
  101. file, line);
  102. if (unlikely(t != type))
  103. return gfs2_metatype_check_ii(sdp, bh, type, t, function,
  104. file, line);
  105. return 0;
  106. }
  107. #define gfs2_metatype_check(sdp, bh, type) \
  108. gfs2_metatype_check_i((sdp), (bh), (type), __func__, __FILE__, __LINE__)
  109. static inline void gfs2_metatype_set(struct buffer_head *bh, u16 type,
  110. u16 format)
  111. {
  112. struct gfs2_meta_header *mh;
  113. mh = (struct gfs2_meta_header *)bh->b_data;
  114. mh->mh_type = cpu_to_be32(type);
  115. mh->mh_format = cpu_to_be32(format);
  116. }
  117. int gfs2_io_error_i(struct gfs2_sbd *sdp, const char *function,
  118. char *file, unsigned int line);
  119. extern int check_journal_clean(struct gfs2_sbd *sdp, struct gfs2_jdesc *jd,
  120. bool verbose);
  121. extern int gfs2_freeze_lock(struct gfs2_sbd *sdp,
  122. struct gfs2_holder *freeze_gh, int caller_flags);
  123. extern void gfs2_freeze_unlock(struct gfs2_holder *freeze_gh);
  124. #define gfs2_io_error(sdp) \
  125. gfs2_io_error_i((sdp), __func__, __FILE__, __LINE__);
  126. void gfs2_io_error_bh_i(struct gfs2_sbd *sdp, struct buffer_head *bh,
  127. const char *function, char *file, unsigned int line,
  128. bool withdraw);
  129. #define gfs2_io_error_bh_wd(sdp, bh) \
  130. gfs2_io_error_bh_i((sdp), (bh), __func__, __FILE__, __LINE__, true);
  131. #define gfs2_io_error_bh(sdp, bh) \
  132. gfs2_io_error_bh_i((sdp), (bh), __func__, __FILE__, __LINE__, false);
  133. extern struct kmem_cache *gfs2_glock_cachep;
  134. extern struct kmem_cache *gfs2_glock_aspace_cachep;
  135. extern struct kmem_cache *gfs2_inode_cachep;
  136. extern struct kmem_cache *gfs2_bufdata_cachep;
  137. extern struct kmem_cache *gfs2_rgrpd_cachep;
  138. extern struct kmem_cache *gfs2_quotad_cachep;
  139. extern struct kmem_cache *gfs2_qadata_cachep;
  140. extern struct kmem_cache *gfs2_trans_cachep;
  141. extern mempool_t *gfs2_page_pool;
  142. extern struct workqueue_struct *gfs2_control_wq;
  143. static inline unsigned int gfs2_tune_get_i(struct gfs2_tune *gt,
  144. unsigned int *p)
  145. {
  146. unsigned int x;
  147. spin_lock(&gt->gt_spin);
  148. x = *p;
  149. spin_unlock(&gt->gt_spin);
  150. return x;
  151. }
  152. /**
  153. * gfs2_withdraw_delayed - withdraw as soon as possible without deadlocks
  154. * @sdp: the superblock
  155. */
  156. static inline void gfs2_withdraw_delayed(struct gfs2_sbd *sdp)
  157. {
  158. set_bit(SDF_WITHDRAWING, &sdp->sd_flags);
  159. }
  160. /**
  161. * gfs2_withdrawn - test whether the file system is withdrawing or withdrawn
  162. * @sdp: the superblock
  163. */
  164. static inline bool gfs2_withdrawn(struct gfs2_sbd *sdp)
  165. {
  166. return test_bit(SDF_WITHDRAWN, &sdp->sd_flags) ||
  167. test_bit(SDF_WITHDRAWING, &sdp->sd_flags);
  168. }
  169. /**
  170. * gfs2_withdrawing - check if a withdraw is pending
  171. * @sdp: the superblock
  172. */
  173. static inline bool gfs2_withdrawing(struct gfs2_sbd *sdp)
  174. {
  175. return test_bit(SDF_WITHDRAWING, &sdp->sd_flags) &&
  176. !test_bit(SDF_WITHDRAWN, &sdp->sd_flags);
  177. }
  178. #define gfs2_tune_get(sdp, field) \
  179. gfs2_tune_get_i(&(sdp)->sd_tune, &(sdp)->sd_tune.field)
  180. __printf(2, 3)
  181. void gfs2_lm(struct gfs2_sbd *sdp, const char *fmt, ...);
  182. int gfs2_withdraw(struct gfs2_sbd *sdp);
  183. #endif /* __UTIL_DOT_H__ */