util.h 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176
  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. #include <linux/mempool.h>
  12. #include "incore.h"
  13. #define fs_printk(level, fs, fmt, arg...) \
  14. printk(level "GFS2: fsid=%s: " fmt , (fs)->sd_fsname , ## arg)
  15. #define fs_info(fs, fmt, arg...) \
  16. fs_printk(KERN_INFO , fs , fmt , ## arg)
  17. #define fs_warn(fs, fmt, arg...) \
  18. fs_printk(KERN_WARNING , fs , fmt , ## arg)
  19. #define fs_err(fs, fmt, arg...) \
  20. fs_printk(KERN_ERR, fs , fmt , ## arg)
  21. void gfs2_assert_i(struct gfs2_sbd *sdp);
  22. #define gfs2_assert(sdp, assertion) \
  23. do { \
  24. if (unlikely(!(assertion))) { \
  25. gfs2_assert_i(sdp); \
  26. BUG(); \
  27. } \
  28. } while (0)
  29. int gfs2_assert_withdraw_i(struct gfs2_sbd *sdp, char *assertion,
  30. const char *function, char *file, unsigned int line);
  31. #define gfs2_assert_withdraw(sdp, assertion) \
  32. ((likely(assertion)) ? 0 : gfs2_assert_withdraw_i((sdp), #assertion, \
  33. __func__, __FILE__, __LINE__))
  34. int gfs2_assert_warn_i(struct gfs2_sbd *sdp, char *assertion,
  35. const char *function, char *file, unsigned int line);
  36. #define gfs2_assert_warn(sdp, assertion) \
  37. ((likely(assertion)) ? 0 : gfs2_assert_warn_i((sdp), #assertion, \
  38. __func__, __FILE__, __LINE__))
  39. int gfs2_consist_i(struct gfs2_sbd *sdp, int cluster_wide,
  40. const char *function, char *file, unsigned int line);
  41. #define gfs2_consist(sdp) \
  42. gfs2_consist_i((sdp), 0, __func__, __FILE__, __LINE__)
  43. int gfs2_consist_inode_i(struct gfs2_inode *ip, int cluster_wide,
  44. const char *function, char *file, unsigned int line);
  45. #define gfs2_consist_inode(ip) \
  46. gfs2_consist_inode_i((ip), 0, __func__, __FILE__, __LINE__)
  47. int gfs2_consist_rgrpd_i(struct gfs2_rgrpd *rgd, int cluster_wide,
  48. const char *function, char *file, unsigned int line);
  49. #define gfs2_consist_rgrpd(rgd) \
  50. gfs2_consist_rgrpd_i((rgd), 0, __func__, __FILE__, __LINE__)
  51. int gfs2_meta_check_ii(struct gfs2_sbd *sdp, struct buffer_head *bh,
  52. const char *type, const char *function,
  53. char *file, unsigned int line);
  54. static inline int gfs2_meta_check_i(struct gfs2_sbd *sdp,
  55. struct buffer_head *bh,
  56. const char *function,
  57. char *file, unsigned int line)
  58. {
  59. struct gfs2_meta_header *mh = (struct gfs2_meta_header *)bh->b_data;
  60. u32 magic = be32_to_cpu(mh->mh_magic);
  61. if (unlikely(magic != GFS2_MAGIC))
  62. return gfs2_meta_check_ii(sdp, bh, "magic number", function,
  63. file, line);
  64. return 0;
  65. }
  66. #define gfs2_meta_check(sdp, bh) \
  67. gfs2_meta_check_i((sdp), (bh), __func__, __FILE__, __LINE__)
  68. int gfs2_metatype_check_ii(struct gfs2_sbd *sdp, struct buffer_head *bh,
  69. u16 type, u16 t,
  70. const char *function,
  71. char *file, unsigned int line);
  72. static inline int gfs2_metatype_check_i(struct gfs2_sbd *sdp,
  73. struct buffer_head *bh,
  74. u16 type,
  75. const char *function,
  76. char *file, unsigned int line)
  77. {
  78. struct gfs2_meta_header *mh = (struct gfs2_meta_header *)bh->b_data;
  79. u32 magic = be32_to_cpu(mh->mh_magic);
  80. u16 t = be32_to_cpu(mh->mh_type);
  81. if (unlikely(magic != GFS2_MAGIC))
  82. return gfs2_meta_check_ii(sdp, bh, "magic number", function,
  83. file, line);
  84. if (unlikely(t != type))
  85. return gfs2_metatype_check_ii(sdp, bh, type, t, function,
  86. file, line);
  87. return 0;
  88. }
  89. #define gfs2_metatype_check(sdp, bh, type) \
  90. gfs2_metatype_check_i((sdp), (bh), (type), __func__, __FILE__, __LINE__)
  91. static inline void gfs2_metatype_set(struct buffer_head *bh, u16 type,
  92. u16 format)
  93. {
  94. struct gfs2_meta_header *mh;
  95. mh = (struct gfs2_meta_header *)bh->b_data;
  96. mh->mh_type = cpu_to_be32(type);
  97. mh->mh_format = cpu_to_be32(format);
  98. }
  99. int gfs2_io_error_i(struct gfs2_sbd *sdp, const char *function,
  100. char *file, unsigned int line);
  101. #define gfs2_io_error(sdp) \
  102. gfs2_io_error_i((sdp), __func__, __FILE__, __LINE__);
  103. int gfs2_io_error_bh_i(struct gfs2_sbd *sdp, struct buffer_head *bh,
  104. const char *function, char *file, unsigned int line);
  105. #define gfs2_io_error_bh(sdp, bh) \
  106. gfs2_io_error_bh_i((sdp), (bh), __func__, __FILE__, __LINE__);
  107. extern struct kmem_cache *gfs2_glock_cachep;
  108. extern struct kmem_cache *gfs2_glock_aspace_cachep;
  109. extern struct kmem_cache *gfs2_inode_cachep;
  110. extern struct kmem_cache *gfs2_bufdata_cachep;
  111. extern struct kmem_cache *gfs2_rgrpd_cachep;
  112. extern struct kmem_cache *gfs2_quotad_cachep;
  113. extern mempool_t *gfs2_bh_pool;
  114. static inline unsigned int gfs2_tune_get_i(struct gfs2_tune *gt,
  115. unsigned int *p)
  116. {
  117. unsigned int x;
  118. spin_lock(&gt->gt_spin);
  119. x = *p;
  120. spin_unlock(&gt->gt_spin);
  121. return x;
  122. }
  123. #define gfs2_tune_get(sdp, field) \
  124. gfs2_tune_get_i(&(sdp)->sd_tune, &(sdp)->sd_tune.field)
  125. void gfs2_icbit_munge(struct gfs2_sbd *sdp, unsigned char **bitmap,
  126. unsigned int bit, int new_value);
  127. int gfs2_lm_withdraw(struct gfs2_sbd *sdp, char *fmt, ...);
  128. #endif /* __UTIL_DOT_H__ */