util.h 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172
  1. /*
  2. * Copyright (C) Sistina Software, Inc. 1997-2003 All rights reserved.
  3. * Copyright (C) 2004-2006 Red Hat, Inc. All rights reserved.
  4. *
  5. * This copyrighted material is made available to anyone wishing to use,
  6. * modify, copy, or redistribute it subject to the terms and conditions
  7. * of the GNU General Public License version 2.
  8. */
  9. #ifndef __UTIL_DOT_H__
  10. #define __UTIL_DOT_H__
  11. #ifdef pr_fmt
  12. #undef pr_fmt
  13. #define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
  14. #endif
  15. #include <linux/mempool.h>
  16. #include "incore.h"
  17. #define fs_emerg(fs, fmt, ...) \
  18. pr_emerg("fsid=%s: " fmt, (fs)->sd_fsname, ##__VA_ARGS__)
  19. #define fs_warn(fs, fmt, ...) \
  20. pr_warn("fsid=%s: " fmt, (fs)->sd_fsname, ##__VA_ARGS__)
  21. #define fs_err(fs, fmt, ...) \
  22. pr_err("fsid=%s: " fmt, (fs)->sd_fsname, ##__VA_ARGS__)
  23. #define fs_info(fs, fmt, ...) \
  24. pr_info("fsid=%s: " fmt, (fs)->sd_fsname, ##__VA_ARGS__)
  25. void gfs2_assert_i(struct gfs2_sbd *sdp);
  26. #define gfs2_assert(sdp, assertion) \
  27. do { \
  28. if (unlikely(!(assertion))) { \
  29. gfs2_assert_i(sdp); \
  30. BUG(); \
  31. } \
  32. } while (0)
  33. int gfs2_assert_withdraw_i(struct gfs2_sbd *sdp, char *assertion,
  34. const char *function, char *file, unsigned int line);
  35. #define gfs2_assert_withdraw(sdp, assertion) \
  36. ((likely(assertion)) ? 0 : gfs2_assert_withdraw_i((sdp), #assertion, \
  37. __func__, __FILE__, __LINE__))
  38. int gfs2_assert_warn_i(struct gfs2_sbd *sdp, char *assertion,
  39. const char *function, char *file, unsigned int line);
  40. #define gfs2_assert_warn(sdp, assertion) \
  41. ((likely(assertion)) ? 0 : gfs2_assert_warn_i((sdp), #assertion, \
  42. __func__, __FILE__, __LINE__))
  43. int gfs2_consist_i(struct gfs2_sbd *sdp, int cluster_wide,
  44. const char *function, char *file, unsigned int line);
  45. #define gfs2_consist(sdp) \
  46. gfs2_consist_i((sdp), 0, __func__, __FILE__, __LINE__)
  47. int gfs2_consist_inode_i(struct gfs2_inode *ip, int cluster_wide,
  48. const char *function, char *file, unsigned int line);
  49. #define gfs2_consist_inode(ip) \
  50. gfs2_consist_inode_i((ip), 0, __func__, __FILE__, __LINE__)
  51. int gfs2_consist_rgrpd_i(struct gfs2_rgrpd *rgd, int cluster_wide,
  52. const char *function, char *file, unsigned int line);
  53. #define gfs2_consist_rgrpd(rgd) \
  54. gfs2_consist_rgrpd_i((rgd), 0, __func__, __FILE__, __LINE__)
  55. int gfs2_meta_check_ii(struct gfs2_sbd *sdp, struct buffer_head *bh,
  56. const char *type, const char *function,
  57. char *file, unsigned int line);
  58. static inline int gfs2_meta_check(struct gfs2_sbd *sdp,
  59. struct buffer_head *bh)
  60. {
  61. struct gfs2_meta_header *mh = (struct gfs2_meta_header *)bh->b_data;
  62. u32 magic = be32_to_cpu(mh->mh_magic);
  63. if (unlikely(magic != GFS2_MAGIC)) {
  64. pr_err("Magic number missing at %llu\n",
  65. (unsigned long long)bh->b_blocknr);
  66. return -EIO;
  67. }
  68. return 0;
  69. }
  70. int gfs2_metatype_check_ii(struct gfs2_sbd *sdp, struct buffer_head *bh,
  71. u16 type, u16 t,
  72. const char *function,
  73. char *file, unsigned int line);
  74. static inline int gfs2_metatype_check_i(struct gfs2_sbd *sdp,
  75. struct buffer_head *bh,
  76. u16 type,
  77. const char *function,
  78. char *file, unsigned int line)
  79. {
  80. struct gfs2_meta_header *mh = (struct gfs2_meta_header *)bh->b_data;
  81. u32 magic = be32_to_cpu(mh->mh_magic);
  82. u16 t = be32_to_cpu(mh->mh_type);
  83. if (unlikely(magic != GFS2_MAGIC))
  84. return gfs2_meta_check_ii(sdp, bh, "magic number", function,
  85. file, line);
  86. if (unlikely(t != type))
  87. return gfs2_metatype_check_ii(sdp, bh, type, t, function,
  88. file, line);
  89. return 0;
  90. }
  91. #define gfs2_metatype_check(sdp, bh, type) \
  92. gfs2_metatype_check_i((sdp), (bh), (type), __func__, __FILE__, __LINE__)
  93. static inline void gfs2_metatype_set(struct buffer_head *bh, u16 type,
  94. u16 format)
  95. {
  96. struct gfs2_meta_header *mh;
  97. mh = (struct gfs2_meta_header *)bh->b_data;
  98. mh->mh_type = cpu_to_be32(type);
  99. mh->mh_format = cpu_to_be32(format);
  100. }
  101. int gfs2_io_error_i(struct gfs2_sbd *sdp, const char *function,
  102. char *file, unsigned int line);
  103. #define gfs2_io_error(sdp) \
  104. gfs2_io_error_i((sdp), __func__, __FILE__, __LINE__);
  105. int gfs2_io_error_bh_i(struct gfs2_sbd *sdp, struct buffer_head *bh,
  106. const char *function, char *file, unsigned int line);
  107. #define gfs2_io_error_bh(sdp, bh) \
  108. gfs2_io_error_bh_i((sdp), (bh), __func__, __FILE__, __LINE__);
  109. extern struct kmem_cache *gfs2_glock_cachep;
  110. extern struct kmem_cache *gfs2_glock_aspace_cachep;
  111. extern struct kmem_cache *gfs2_inode_cachep;
  112. extern struct kmem_cache *gfs2_bufdata_cachep;
  113. extern struct kmem_cache *gfs2_rgrpd_cachep;
  114. extern struct kmem_cache *gfs2_quotad_cachep;
  115. extern struct kmem_cache *gfs2_qadata_cachep;
  116. extern mempool_t *gfs2_page_pool;
  117. static inline unsigned int gfs2_tune_get_i(struct gfs2_tune *gt,
  118. unsigned int *p)
  119. {
  120. unsigned int x;
  121. spin_lock(&gt->gt_spin);
  122. x = *p;
  123. spin_unlock(&gt->gt_spin);
  124. return x;
  125. }
  126. #define gfs2_tune_get(sdp, field) \
  127. gfs2_tune_get_i(&(sdp)->sd_tune, &(sdp)->sd_tune.field)
  128. __printf(2, 3)
  129. int gfs2_lm_withdraw(struct gfs2_sbd *sdp, const char *fmt, ...);
  130. #endif /* __UTIL_DOT_H__ */