util.c 8.1 KB

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