util.c 6.8 KB

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