util.c 7.3 KB

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