util.c 7.4 KB

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