util.c 7.3 KB

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