util.c 7.4 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. #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_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. 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. set_bit(SDF_SKIP_DLM_UNLOCK, &sdp->sd_flags);
  57. fs_err(sdp, "withdrawn\n");
  58. dump_stack();
  59. }
  60. if (sdp->sd_args.ar_errors == GFS2_ERRORS_PANIC)
  61. panic("GFS2: fsid=%s: panic requested\n", sdp->sd_fsname);
  62. return -1;
  63. }
  64. /**
  65. * gfs2_assert_withdraw_i - Cause the machine to withdraw if @assertion is false
  66. * Returns: -1 if this call withdrew the machine,
  67. * -2 if it was already withdrawn
  68. */
  69. int gfs2_assert_withdraw_i(struct gfs2_sbd *sdp, char *assertion,
  70. const char *function, char *file, unsigned int line)
  71. {
  72. int me;
  73. me = gfs2_lm_withdraw(sdp,
  74. "fatal: assertion \"%s\" failed\n"
  75. " function = %s, file = %s, line = %u\n",
  76. assertion, function, file, line);
  77. dump_stack();
  78. return (me) ? -1 : -2;
  79. }
  80. /**
  81. * gfs2_assert_warn_i - Print a message to the console if @assertion is false
  82. * Returns: -1 if we printed something
  83. * -2 if we didn't
  84. */
  85. int gfs2_assert_warn_i(struct gfs2_sbd *sdp, char *assertion,
  86. const char *function, char *file, unsigned int line)
  87. {
  88. if (time_before(jiffies,
  89. sdp->sd_last_warning +
  90. gfs2_tune_get(sdp, gt_complain_secs) * HZ))
  91. return -2;
  92. if (sdp->sd_args.ar_errors == GFS2_ERRORS_WITHDRAW)
  93. fs_warn(sdp, "warning: assertion \"%s\" failed at function = %s, file = %s, line = %u\n",
  94. assertion, function, file, line);
  95. if (sdp->sd_args.ar_debug)
  96. BUG();
  97. else
  98. dump_stack();
  99. if (sdp->sd_args.ar_errors == GFS2_ERRORS_PANIC)
  100. panic("GFS2: fsid=%s: warning: assertion \"%s\" failed\n"
  101. "GFS2: fsid=%s: function = %s, file = %s, line = %u\n",
  102. sdp->sd_fsname, assertion,
  103. sdp->sd_fsname, function, file, line);
  104. sdp->sd_last_warning = jiffies;
  105. return -1;
  106. }
  107. /**
  108. * gfs2_consist_i - Flag a filesystem consistency error and withdraw
  109. * Returns: -1 if this call withdrew the machine,
  110. * 0 if it was already withdrawn
  111. */
  112. int gfs2_consist_i(struct gfs2_sbd *sdp, int cluster_wide, const char *function,
  113. char *file, unsigned int line)
  114. {
  115. int rv;
  116. rv = gfs2_lm_withdraw(sdp,
  117. "fatal: filesystem consistency error - function = %s, file = %s, line = %u\n",
  118. 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. "fatal: filesystem consistency error\n"
  133. " inode = %llu %llu\n"
  134. " function = %s, file = %s, line = %u\n",
  135. (unsigned long long)ip->i_no_formal_ino,
  136. (unsigned long long)ip->i_no_addr,
  137. function, file, line);
  138. return rv;
  139. }
  140. /**
  141. * gfs2_consist_rgrpd_i - Flag a RG consistency error and withdraw
  142. * Returns: -1 if this call withdrew the machine,
  143. * 0 if it was already withdrawn
  144. */
  145. int gfs2_consist_rgrpd_i(struct gfs2_rgrpd *rgd, int cluster_wide,
  146. const char *function, char *file, unsigned int line)
  147. {
  148. struct gfs2_sbd *sdp = rgd->rd_sbd;
  149. int rv;
  150. rv = gfs2_lm_withdraw(sdp,
  151. "fatal: filesystem consistency error\n"
  152. " RG = %llu\n"
  153. " function = %s, file = %s, line = %u\n",
  154. (unsigned long long)rgd->rd_addr,
  155. function, file, line);
  156. return rv;
  157. }
  158. /**
  159. * gfs2_meta_check_ii - Flag a magic number consistency error and withdraw
  160. * Returns: -1 if this call withdrew the machine,
  161. * -2 if it was already withdrawn
  162. */
  163. int gfs2_meta_check_ii(struct gfs2_sbd *sdp, struct buffer_head *bh,
  164. const char *type, const char *function, char *file,
  165. unsigned int line)
  166. {
  167. int me;
  168. me = gfs2_lm_withdraw(sdp,
  169. "fatal: invalid metadata block\n"
  170. " bh = %llu (%s)\n"
  171. " function = %s, file = %s, line = %u\n",
  172. (unsigned long long)bh->b_blocknr, type,
  173. function, file, line);
  174. return (me) ? -1 : -2;
  175. }
  176. /**
  177. * gfs2_metatype_check_ii - Flag a metadata type consistency error and withdraw
  178. * Returns: -1 if this call withdrew the machine,
  179. * -2 if it was already withdrawn
  180. */
  181. int gfs2_metatype_check_ii(struct gfs2_sbd *sdp, struct buffer_head *bh,
  182. u16 type, u16 t, const char *function,
  183. char *file, unsigned int line)
  184. {
  185. int me;
  186. me = gfs2_lm_withdraw(sdp,
  187. "fatal: invalid metadata block\n"
  188. " bh = %llu (type: exp=%u, found=%u)\n"
  189. " function = %s, file = %s, line = %u\n",
  190. (unsigned long long)bh->b_blocknr, type, t,
  191. function, file, line);
  192. return (me) ? -1 : -2;
  193. }
  194. /**
  195. * gfs2_io_error_i - Flag an I/O error and withdraw
  196. * Returns: -1 if this call withdrew the machine,
  197. * 0 if it was already withdrawn
  198. */
  199. int gfs2_io_error_i(struct gfs2_sbd *sdp, const char *function, char *file,
  200. unsigned int line)
  201. {
  202. int rv;
  203. rv = gfs2_lm_withdraw(sdp,
  204. "fatal: I/O error\n"
  205. " function = %s, file = %s, line = %u\n",
  206. function, file, line);
  207. return rv;
  208. }
  209. /**
  210. * gfs2_io_error_bh_i - Flag a buffer I/O error and withdraw
  211. * Returns: -1 if this call withdrew the machine,
  212. * 0 if it was already withdrawn
  213. */
  214. int gfs2_io_error_bh_i(struct gfs2_sbd *sdp, struct buffer_head *bh,
  215. const char *function, char *file, unsigned int line)
  216. {
  217. int rv;
  218. rv = gfs2_lm_withdraw(sdp,
  219. "fatal: I/O error\n"
  220. " block = %llu\n"
  221. " function = %s, file = %s, line = %u\n",
  222. (unsigned long long)bh->b_blocknr,
  223. function, file, line);
  224. return rv;
  225. }