util.h 4.8 KB

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