util.c 7.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266
  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 "util.h"
  21. struct kmem_cache *gfs2_glock_cachep __read_mostly;
  22. struct kmem_cache *gfs2_inode_cachep __read_mostly;
  23. struct kmem_cache *gfs2_bufdata_cachep __read_mostly;
  24. struct kmem_cache *gfs2_rgrpd_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. int gfs2_lm_withdraw(struct gfs2_sbd *sdp, char *fmt, ...)
  31. {
  32. va_list args;
  33. if (test_and_set_bit(SDF_SHUTDOWN, &sdp->sd_flags))
  34. return 0;
  35. va_start(args, fmt);
  36. vprintk(fmt, args);
  37. va_end(args);
  38. fs_err(sdp, "about to withdraw this file system\n");
  39. BUG_ON(sdp->sd_args.ar_debug);
  40. fs_err(sdp, "telling LM to withdraw\n");
  41. gfs2_withdraw_lockproto(&sdp->sd_lockstruct);
  42. fs_err(sdp, "withdrawn\n");
  43. dump_stack();
  44. return -1;
  45. }
  46. /**
  47. * gfs2_assert_withdraw_i - Cause the machine to withdraw if @assertion is false
  48. * Returns: -1 if this call withdrew the machine,
  49. * -2 if it was already withdrawn
  50. */
  51. int gfs2_assert_withdraw_i(struct gfs2_sbd *sdp, char *assertion,
  52. const char *function, char *file, unsigned int line)
  53. {
  54. int me;
  55. me = gfs2_lm_withdraw(sdp,
  56. "GFS2: fsid=%s: fatal: assertion \"%s\" failed\n"
  57. "GFS2: fsid=%s: function = %s, file = %s, line = %u\n",
  58. sdp->sd_fsname, assertion,
  59. sdp->sd_fsname, function, file, line);
  60. dump_stack();
  61. return (me) ? -1 : -2;
  62. }
  63. /**
  64. * gfs2_assert_warn_i - Print a message to the console if @assertion is false
  65. * Returns: -1 if we printed something
  66. * -2 if we didn't
  67. */
  68. int gfs2_assert_warn_i(struct gfs2_sbd *sdp, char *assertion,
  69. const char *function, char *file, unsigned int line)
  70. {
  71. if (time_before(jiffies,
  72. sdp->sd_last_warning +
  73. gfs2_tune_get(sdp, gt_complain_secs) * HZ))
  74. return -2;
  75. printk(KERN_WARNING
  76. "GFS2: fsid=%s: warning: assertion \"%s\" failed\n"
  77. "GFS2: fsid=%s: function = %s, file = %s, line = %u\n",
  78. sdp->sd_fsname, assertion,
  79. sdp->sd_fsname, function, file, line);
  80. if (sdp->sd_args.ar_debug)
  81. BUG();
  82. else
  83. dump_stack();
  84. sdp->sd_last_warning = jiffies;
  85. return -1;
  86. }
  87. /**
  88. * gfs2_consist_i - Flag a filesystem 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_i(struct gfs2_sbd *sdp, int cluster_wide, const char *function,
  93. char *file, unsigned int line)
  94. {
  95. int rv;
  96. rv = gfs2_lm_withdraw(sdp,
  97. "GFS2: fsid=%s: fatal: filesystem consistency error\n"
  98. "GFS2: fsid=%s: function = %s, file = %s, line = %u\n",
  99. sdp->sd_fsname,
  100. sdp->sd_fsname, function, file, line);
  101. return rv;
  102. }
  103. /**
  104. * gfs2_consist_inode_i - Flag an inode consistency error and withdraw
  105. * Returns: -1 if this call withdrew the machine,
  106. * 0 if it was already withdrawn
  107. */
  108. int gfs2_consist_inode_i(struct gfs2_inode *ip, int cluster_wide,
  109. const char *function, char *file, unsigned int line)
  110. {
  111. struct gfs2_sbd *sdp = GFS2_SB(&ip->i_inode);
  112. int rv;
  113. rv = gfs2_lm_withdraw(sdp,
  114. "GFS2: fsid=%s: fatal: filesystem consistency error\n"
  115. "GFS2: fsid=%s: inode = %llu %llu\n"
  116. "GFS2: fsid=%s: function = %s, file = %s, line = %u\n",
  117. sdp->sd_fsname,
  118. sdp->sd_fsname, (unsigned long long)ip->i_no_formal_ino,
  119. (unsigned long long)ip->i_no_addr,
  120. sdp->sd_fsname, function, file, line);
  121. return rv;
  122. }
  123. /**
  124. * gfs2_consist_rgrpd_i - Flag a RG consistency error and withdraw
  125. * Returns: -1 if this call withdrew the machine,
  126. * 0 if it was already withdrawn
  127. */
  128. int gfs2_consist_rgrpd_i(struct gfs2_rgrpd *rgd, int cluster_wide,
  129. const char *function, char *file, unsigned int line)
  130. {
  131. struct gfs2_sbd *sdp = rgd->rd_sbd;
  132. int rv;
  133. rv = gfs2_lm_withdraw(sdp,
  134. "GFS2: fsid=%s: fatal: filesystem consistency error\n"
  135. "GFS2: fsid=%s: RG = %llu\n"
  136. "GFS2: fsid=%s: function = %s, file = %s, line = %u\n",
  137. sdp->sd_fsname,
  138. sdp->sd_fsname, (unsigned long long)rgd->rd_addr,
  139. sdp->sd_fsname, function, file, line);
  140. return rv;
  141. }
  142. /**
  143. * gfs2_meta_check_ii - Flag a magic number consistency error and withdraw
  144. * Returns: -1 if this call withdrew the machine,
  145. * -2 if it was already withdrawn
  146. */
  147. int gfs2_meta_check_ii(struct gfs2_sbd *sdp, struct buffer_head *bh,
  148. const char *type, const char *function, char *file,
  149. unsigned int line)
  150. {
  151. int me;
  152. me = gfs2_lm_withdraw(sdp,
  153. "GFS2: fsid=%s: fatal: invalid metadata block\n"
  154. "GFS2: fsid=%s: bh = %llu (%s)\n"
  155. "GFS2: fsid=%s: function = %s, file = %s, line = %u\n",
  156. sdp->sd_fsname,
  157. sdp->sd_fsname, (unsigned long long)bh->b_blocknr, type,
  158. sdp->sd_fsname, function, file, line);
  159. return (me) ? -1 : -2;
  160. }
  161. /**
  162. * gfs2_metatype_check_ii - Flag a metadata type consistency error and withdraw
  163. * Returns: -1 if this call withdrew the machine,
  164. * -2 if it was already withdrawn
  165. */
  166. int gfs2_metatype_check_ii(struct gfs2_sbd *sdp, struct buffer_head *bh,
  167. u16 type, u16 t, const char *function,
  168. char *file, unsigned int line)
  169. {
  170. int me;
  171. me = gfs2_lm_withdraw(sdp,
  172. "GFS2: fsid=%s: fatal: invalid metadata block\n"
  173. "GFS2: fsid=%s: bh = %llu (type: exp=%u, found=%u)\n"
  174. "GFS2: fsid=%s: function = %s, file = %s, line = %u\n",
  175. sdp->sd_fsname,
  176. sdp->sd_fsname, (unsigned long long)bh->b_blocknr, type, t,
  177. sdp->sd_fsname, function, file, line);
  178. return (me) ? -1 : -2;
  179. }
  180. /**
  181. * gfs2_io_error_i - Flag an 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_i(struct gfs2_sbd *sdp, const char *function, char *file,
  186. 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: function = %s, file = %s, line = %u\n",
  192. sdp->sd_fsname,
  193. sdp->sd_fsname, function, file, line);
  194. return rv;
  195. }
  196. /**
  197. * gfs2_io_error_bh_i - Flag a buffer I/O error and withdraw
  198. * Returns: -1 if this call withdrew the machine,
  199. * 0 if it was already withdrawn
  200. */
  201. int gfs2_io_error_bh_i(struct gfs2_sbd *sdp, struct buffer_head *bh,
  202. const char *function, char *file, unsigned int line)
  203. {
  204. int rv;
  205. rv = gfs2_lm_withdraw(sdp,
  206. "GFS2: fsid=%s: fatal: I/O error\n"
  207. "GFS2: fsid=%s: block = %llu\n"
  208. "GFS2: fsid=%s: function = %s, file = %s, line = %u\n",
  209. sdp->sd_fsname,
  210. sdp->sd_fsname, (unsigned long long)bh->b_blocknr,
  211. sdp->sd_fsname, function, file, line);
  212. return rv;
  213. }
  214. void gfs2_icbit_munge(struct gfs2_sbd *sdp, unsigned char **bitmap,
  215. unsigned int bit, int new_value)
  216. {
  217. unsigned int c, o, b = bit;
  218. int old_value;
  219. c = b / (8 * PAGE_SIZE);
  220. b %= 8 * PAGE_SIZE;
  221. o = b / 8;
  222. b %= 8;
  223. old_value = (bitmap[c][o] & (1 << b));
  224. gfs2_assert_withdraw(sdp, !old_value != !new_value);
  225. if (new_value)
  226. bitmap[c][o] |= 1 << b;
  227. else
  228. bitmap[c][o] &= ~(1 << b);
  229. }