util.c 6.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244
  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. #include <linux/slab.h>
  10. #include <linux/spinlock.h>
  11. #include <linux/completion.h>
  12. #include <linux/buffer_head.h>
  13. #include <linux/crc32.h>
  14. #include <linux/gfs2_ondisk.h>
  15. #include <linux/lm_interface.h>
  16. #include <asm/uaccess.h>
  17. #include "gfs2.h"
  18. #include "incore.h"
  19. #include "glock.h"
  20. #include "lm.h"
  21. #include "util.h"
  22. struct kmem_cache *gfs2_glock_cachep __read_mostly;
  23. struct kmem_cache *gfs2_inode_cachep __read_mostly;
  24. struct kmem_cache *gfs2_bufdata_cachep __read_mostly;
  25. void gfs2_assert_i(struct gfs2_sbd *sdp)
  26. {
  27. printk(KERN_EMERG "GFS2: fsid=%s: fatal assertion failed\n",
  28. sdp->sd_fsname);
  29. }
  30. /**
  31. * gfs2_assert_withdraw_i - Cause the machine to withdraw if @assertion is false
  32. * Returns: -1 if this call withdrew the machine,
  33. * -2 if it was already withdrawn
  34. */
  35. int gfs2_assert_withdraw_i(struct gfs2_sbd *sdp, char *assertion,
  36. const char *function, char *file, unsigned int line)
  37. {
  38. int me;
  39. me = gfs2_lm_withdraw(sdp,
  40. "GFS2: fsid=%s: fatal: assertion \"%s\" failed\n"
  41. "GFS2: fsid=%s: function = %s, file = %s, line = %u\n",
  42. sdp->sd_fsname, assertion,
  43. sdp->sd_fsname, function, file, line);
  44. dump_stack();
  45. return (me) ? -1 : -2;
  46. }
  47. /**
  48. * gfs2_assert_warn_i - Print a message to the console if @assertion is false
  49. * Returns: -1 if we printed something
  50. * -2 if we didn't
  51. */
  52. int gfs2_assert_warn_i(struct gfs2_sbd *sdp, char *assertion,
  53. const char *function, char *file, unsigned int line)
  54. {
  55. if (time_before(jiffies,
  56. sdp->sd_last_warning +
  57. gfs2_tune_get(sdp, gt_complain_secs) * HZ))
  58. return -2;
  59. printk(KERN_WARNING
  60. "GFS2: fsid=%s: warning: assertion \"%s\" failed\n"
  61. "GFS2: fsid=%s: function = %s, file = %s, line = %u\n",
  62. sdp->sd_fsname, assertion,
  63. sdp->sd_fsname, function, file, line);
  64. if (sdp->sd_args.ar_debug)
  65. BUG();
  66. else
  67. dump_stack();
  68. sdp->sd_last_warning = jiffies;
  69. return -1;
  70. }
  71. /**
  72. * gfs2_consist_i - Flag a filesystem consistency error and withdraw
  73. * Returns: -1 if this call withdrew the machine,
  74. * 0 if it was already withdrawn
  75. */
  76. int gfs2_consist_i(struct gfs2_sbd *sdp, int cluster_wide, const char *function,
  77. char *file, unsigned int line)
  78. {
  79. int rv;
  80. rv = gfs2_lm_withdraw(sdp,
  81. "GFS2: fsid=%s: fatal: filesystem consistency error\n"
  82. "GFS2: fsid=%s: function = %s, file = %s, line = %u\n",
  83. sdp->sd_fsname,
  84. sdp->sd_fsname, function, file, line);
  85. return rv;
  86. }
  87. /**
  88. * gfs2_consist_inode_i - Flag an inode consistency error and withdraw
  89. * Returns: -1 if this call withdrew the machine,
  90. * 0 if it was already withdrawn
  91. */
  92. int gfs2_consist_inode_i(struct gfs2_inode *ip, int cluster_wide,
  93. const char *function, char *file, unsigned int line)
  94. {
  95. struct gfs2_sbd *sdp = GFS2_SB(&ip->i_inode);
  96. int rv;
  97. rv = gfs2_lm_withdraw(sdp,
  98. "GFS2: fsid=%s: fatal: filesystem consistency error\n"
  99. "GFS2: fsid=%s: inode = %llu %llu\n"
  100. "GFS2: fsid=%s: function = %s, file = %s, line = %u\n",
  101. sdp->sd_fsname,
  102. sdp->sd_fsname, (unsigned long long)ip->i_no_formal_ino,
  103. (unsigned long long)ip->i_no_addr,
  104. sdp->sd_fsname, function, file, line);
  105. return rv;
  106. }
  107. /**
  108. * gfs2_consist_rgrpd_i - Flag a RG consistency error and withdraw
  109. * Returns: -1 if this call withdrew the machine,
  110. * 0 if it was already withdrawn
  111. */
  112. int gfs2_consist_rgrpd_i(struct gfs2_rgrpd *rgd, int cluster_wide,
  113. const char *function, char *file, unsigned int line)
  114. {
  115. struct gfs2_sbd *sdp = rgd->rd_sbd;
  116. int rv;
  117. rv = gfs2_lm_withdraw(sdp,
  118. "GFS2: fsid=%s: fatal: filesystem consistency error\n"
  119. "GFS2: fsid=%s: RG = %llu\n"
  120. "GFS2: fsid=%s: function = %s, file = %s, line = %u\n",
  121. sdp->sd_fsname,
  122. sdp->sd_fsname, (unsigned long long)rgd->rd_addr,
  123. sdp->sd_fsname, function, file, line);
  124. return rv;
  125. }
  126. /**
  127. * gfs2_meta_check_ii - Flag a magic number consistency error and withdraw
  128. * Returns: -1 if this call withdrew the machine,
  129. * -2 if it was already withdrawn
  130. */
  131. int gfs2_meta_check_ii(struct gfs2_sbd *sdp, struct buffer_head *bh,
  132. const char *type, const char *function, char *file,
  133. unsigned int line)
  134. {
  135. int me;
  136. me = gfs2_lm_withdraw(sdp,
  137. "GFS2: fsid=%s: fatal: invalid metadata block\n"
  138. "GFS2: fsid=%s: bh = %llu (%s)\n"
  139. "GFS2: fsid=%s: function = %s, file = %s, line = %u\n",
  140. sdp->sd_fsname,
  141. sdp->sd_fsname, (unsigned long long)bh->b_blocknr, type,
  142. sdp->sd_fsname, function, file, line);
  143. return (me) ? -1 : -2;
  144. }
  145. /**
  146. * gfs2_metatype_check_ii - Flag a metadata type consistency error and withdraw
  147. * Returns: -1 if this call withdrew the machine,
  148. * -2 if it was already withdrawn
  149. */
  150. int gfs2_metatype_check_ii(struct gfs2_sbd *sdp, struct buffer_head *bh,
  151. u16 type, u16 t, const char *function,
  152. char *file, unsigned int line)
  153. {
  154. int me;
  155. me = gfs2_lm_withdraw(sdp,
  156. "GFS2: fsid=%s: fatal: invalid metadata block\n"
  157. "GFS2: fsid=%s: bh = %llu (type: exp=%u, found=%u)\n"
  158. "GFS2: fsid=%s: function = %s, file = %s, line = %u\n",
  159. sdp->sd_fsname,
  160. sdp->sd_fsname, (unsigned long long)bh->b_blocknr, type, t,
  161. sdp->sd_fsname, function, file, line);
  162. return (me) ? -1 : -2;
  163. }
  164. /**
  165. * gfs2_io_error_i - Flag an I/O error and withdraw
  166. * Returns: -1 if this call withdrew the machine,
  167. * 0 if it was already withdrawn
  168. */
  169. int gfs2_io_error_i(struct gfs2_sbd *sdp, const char *function, char *file,
  170. unsigned int line)
  171. {
  172. int rv;
  173. rv = gfs2_lm_withdraw(sdp,
  174. "GFS2: fsid=%s: fatal: I/O error\n"
  175. "GFS2: fsid=%s: function = %s, file = %s, line = %u\n",
  176. sdp->sd_fsname,
  177. sdp->sd_fsname, function, file, line);
  178. return rv;
  179. }
  180. /**
  181. * gfs2_io_error_bh_i - Flag a buffer I/O error and withdraw
  182. * Returns: -1 if this call withdrew the machine,
  183. * 0 if it was already withdrawn
  184. */
  185. int gfs2_io_error_bh_i(struct gfs2_sbd *sdp, struct buffer_head *bh,
  186. const char *function, char *file, unsigned int line)
  187. {
  188. int rv;
  189. rv = gfs2_lm_withdraw(sdp,
  190. "GFS2: fsid=%s: fatal: I/O error\n"
  191. "GFS2: fsid=%s: block = %llu\n"
  192. "GFS2: fsid=%s: function = %s, file = %s, line = %u\n",
  193. sdp->sd_fsname,
  194. sdp->sd_fsname, (unsigned long long)bh->b_blocknr,
  195. sdp->sd_fsname, function, file, line);
  196. return rv;
  197. }
  198. void gfs2_icbit_munge(struct gfs2_sbd *sdp, unsigned char **bitmap,
  199. unsigned int bit, int new_value)
  200. {
  201. unsigned int c, o, b = bit;
  202. int old_value;
  203. c = b / (8 * PAGE_SIZE);
  204. b %= 8 * PAGE_SIZE;
  205. o = b / 8;
  206. b %= 8;
  207. old_value = (bitmap[c][o] & (1 << b));
  208. gfs2_assert_withdraw(sdp, !old_value != !new_value);
  209. if (new_value)
  210. bitmap[c][o] |= 1 << b;
  211. else
  212. bitmap[c][o] &= ~(1 << b);
  213. }