util.c 8.0 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. mempool_t *gfs2_bh_pool __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. struct lm_lockstruct *ls = &sdp->sd_lockstruct;
  34. const struct lm_lockops *lm = ls->ls_ops;
  35. va_list args;
  36. if (sdp->sd_args.ar_errors == GFS2_ERRORS_WITHDRAW &&
  37. test_and_set_bit(SDF_SHUTDOWN, &sdp->sd_flags))
  38. return 0;
  39. va_start(args, fmt);
  40. vprintk(fmt, args);
  41. va_end(args);
  42. if (sdp->sd_args.ar_errors == GFS2_ERRORS_WITHDRAW) {
  43. fs_err(sdp, "about to withdraw this file system\n");
  44. BUG_ON(sdp->sd_args.ar_debug);
  45. kobject_uevent(&sdp->sd_kobj, KOBJ_OFFLINE);
  46. if (lm->lm_unmount) {
  47. fs_err(sdp, "telling LM to unmount\n");
  48. lm->lm_unmount(sdp);
  49. }
  50. fs_err(sdp, "withdrawn\n");
  51. dump_stack();
  52. }
  53. if (sdp->sd_args.ar_errors == GFS2_ERRORS_PANIC)
  54. panic("GFS2: fsid=%s: panic requested.\n", sdp->sd_fsname);
  55. return -1;
  56. }
  57. /**
  58. * gfs2_assert_withdraw_i - Cause the machine to withdraw if @assertion is false
  59. * Returns: -1 if this call withdrew the machine,
  60. * -2 if it was already withdrawn
  61. */
  62. int gfs2_assert_withdraw_i(struct gfs2_sbd *sdp, char *assertion,
  63. const char *function, char *file, unsigned int line)
  64. {
  65. int me;
  66. me = gfs2_lm_withdraw(sdp,
  67. "GFS2: fsid=%s: fatal: assertion \"%s\" failed\n"
  68. "GFS2: fsid=%s: function = %s, file = %s, line = %u\n",
  69. sdp->sd_fsname, assertion,
  70. sdp->sd_fsname, function, file, line);
  71. dump_stack();
  72. return (me) ? -1 : -2;
  73. }
  74. /**
  75. * gfs2_assert_warn_i - Print a message to the console if @assertion is false
  76. * Returns: -1 if we printed something
  77. * -2 if we didn't
  78. */
  79. int gfs2_assert_warn_i(struct gfs2_sbd *sdp, char *assertion,
  80. const char *function, char *file, unsigned int line)
  81. {
  82. if (time_before(jiffies,
  83. sdp->sd_last_warning +
  84. gfs2_tune_get(sdp, gt_complain_secs) * HZ))
  85. return -2;
  86. if (sdp->sd_args.ar_errors == GFS2_ERRORS_WITHDRAW)
  87. printk(KERN_WARNING
  88. "GFS2: fsid=%s: warning: assertion \"%s\" failed\n"
  89. "GFS2: fsid=%s: function = %s, file = %s, line = %u\n",
  90. sdp->sd_fsname, assertion,
  91. sdp->sd_fsname, function, file, line);
  92. if (sdp->sd_args.ar_debug)
  93. BUG();
  94. else
  95. dump_stack();
  96. if (sdp->sd_args.ar_errors == GFS2_ERRORS_PANIC)
  97. panic("GFS2: fsid=%s: warning: assertion \"%s\" failed\n"
  98. "GFS2: fsid=%s: function = %s, file = %s, line = %u\n",
  99. sdp->sd_fsname, assertion,
  100. sdp->sd_fsname, function, file, line);
  101. sdp->sd_last_warning = jiffies;
  102. return -1;
  103. }
  104. /**
  105. * gfs2_consist_i - Flag a filesystem 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_i(struct gfs2_sbd *sdp, int cluster_wide, const char *function,
  110. char *file, unsigned int line)
  111. {
  112. int rv;
  113. rv = gfs2_lm_withdraw(sdp,
  114. "GFS2: fsid=%s: fatal: filesystem consistency error\n"
  115. "GFS2: fsid=%s: function = %s, file = %s, line = %u\n",
  116. sdp->sd_fsname,
  117. sdp->sd_fsname, 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. "GFS2: fsid=%s: fatal: filesystem consistency error\n"
  132. "GFS2: fsid=%s: inode = %llu %llu\n"
  133. "GFS2: fsid=%s: function = %s, file = %s, line = %u\n",
  134. sdp->sd_fsname,
  135. sdp->sd_fsname, (unsigned long long)ip->i_no_formal_ino,
  136. (unsigned long long)ip->i_no_addr,
  137. sdp->sd_fsname, 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. "GFS2: fsid=%s: fatal: filesystem consistency error\n"
  152. "GFS2: fsid=%s: RG = %llu\n"
  153. "GFS2: fsid=%s: function = %s, file = %s, line = %u\n",
  154. sdp->sd_fsname,
  155. sdp->sd_fsname, (unsigned long long)rgd->rd_addr,
  156. sdp->sd_fsname, function, file, line);
  157. return rv;
  158. }
  159. /**
  160. * gfs2_meta_check_ii - Flag a magic number consistency error and withdraw
  161. * Returns: -1 if this call withdrew the machine,
  162. * -2 if it was already withdrawn
  163. */
  164. int gfs2_meta_check_ii(struct gfs2_sbd *sdp, struct buffer_head *bh,
  165. const char *type, const char *function, char *file,
  166. unsigned int line)
  167. {
  168. int me;
  169. me = gfs2_lm_withdraw(sdp,
  170. "GFS2: fsid=%s: fatal: invalid metadata block\n"
  171. "GFS2: fsid=%s: bh = %llu (%s)\n"
  172. "GFS2: fsid=%s: function = %s, file = %s, line = %u\n",
  173. sdp->sd_fsname,
  174. sdp->sd_fsname, (unsigned long long)bh->b_blocknr, type,
  175. sdp->sd_fsname, 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. "GFS2: fsid=%s: fatal: invalid metadata block\n"
  190. "GFS2: fsid=%s: bh = %llu (type: exp=%u, found=%u)\n"
  191. "GFS2: fsid=%s: function = %s, file = %s, line = %u\n",
  192. sdp->sd_fsname,
  193. sdp->sd_fsname, (unsigned long long)bh->b_blocknr, type, t,
  194. sdp->sd_fsname, function, file, line);
  195. return (me) ? -1 : -2;
  196. }
  197. /**
  198. * gfs2_io_error_i - Flag an 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_i(struct gfs2_sbd *sdp, const char *function, char *file,
  203. 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: function = %s, file = %s, line = %u\n",
  209. sdp->sd_fsname,
  210. sdp->sd_fsname, function, file, line);
  211. return rv;
  212. }
  213. /**
  214. * gfs2_io_error_bh_i - Flag a buffer I/O error and withdraw
  215. * Returns: -1 if this call withdrew the machine,
  216. * 0 if it was already withdrawn
  217. */
  218. int gfs2_io_error_bh_i(struct gfs2_sbd *sdp, struct buffer_head *bh,
  219. const char *function, char *file, unsigned int line)
  220. {
  221. int rv;
  222. rv = gfs2_lm_withdraw(sdp,
  223. "GFS2: fsid=%s: fatal: I/O error\n"
  224. "GFS2: fsid=%s: block = %llu\n"
  225. "GFS2: fsid=%s: function = %s, file = %s, line = %u\n",
  226. sdp->sd_fsname,
  227. sdp->sd_fsname, (unsigned long long)bh->b_blocknr,
  228. sdp->sd_fsname, function, file, line);
  229. return rv;
  230. }
  231. void gfs2_icbit_munge(struct gfs2_sbd *sdp, unsigned char **bitmap,
  232. unsigned int bit, int new_value)
  233. {
  234. unsigned int c, o, b = bit;
  235. int old_value;
  236. c = b / (8 * PAGE_SIZE);
  237. b %= 8 * PAGE_SIZE;
  238. o = b / 8;
  239. b %= 8;
  240. old_value = (bitmap[c][o] & (1 << b));
  241. gfs2_assert_withdraw(sdp, !old_value != !new_value);
  242. if (new_value)
  243. bitmap[c][o] |= 1 << b;
  244. else
  245. bitmap[c][o] &= ~(1 << b);
  246. }