util.c 8.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290
  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 (!strcmp(sdp->sd_lockstruct.ls_ops->lm_proto_name, "lock_dlm"))
  48. wait_for_completion(&sdp->sd_wdack);
  49. if (lm->lm_unmount) {
  50. fs_err(sdp, "telling LM to unmount\n");
  51. lm->lm_unmount(sdp);
  52. }
  53. fs_err(sdp, "withdrawn\n");
  54. dump_stack();
  55. }
  56. if (sdp->sd_args.ar_errors == GFS2_ERRORS_PANIC)
  57. panic("GFS2: fsid=%s: panic requested.\n", sdp->sd_fsname);
  58. return -1;
  59. }
  60. /**
  61. * gfs2_assert_withdraw_i - Cause the machine to withdraw if @assertion is false
  62. * Returns: -1 if this call withdrew the machine,
  63. * -2 if it was already withdrawn
  64. */
  65. int gfs2_assert_withdraw_i(struct gfs2_sbd *sdp, char *assertion,
  66. const char *function, char *file, unsigned int line)
  67. {
  68. int me;
  69. me = gfs2_lm_withdraw(sdp,
  70. "GFS2: fsid=%s: fatal: assertion \"%s\" failed\n"
  71. "GFS2: fsid=%s: function = %s, file = %s, line = %u\n",
  72. sdp->sd_fsname, assertion,
  73. sdp->sd_fsname, function, file, line);
  74. dump_stack();
  75. return (me) ? -1 : -2;
  76. }
  77. /**
  78. * gfs2_assert_warn_i - Print a message to the console if @assertion is false
  79. * Returns: -1 if we printed something
  80. * -2 if we didn't
  81. */
  82. int gfs2_assert_warn_i(struct gfs2_sbd *sdp, char *assertion,
  83. const char *function, char *file, unsigned int line)
  84. {
  85. if (time_before(jiffies,
  86. sdp->sd_last_warning +
  87. gfs2_tune_get(sdp, gt_complain_secs) * HZ))
  88. return -2;
  89. if (sdp->sd_args.ar_errors == GFS2_ERRORS_WITHDRAW)
  90. printk(KERN_WARNING
  91. "GFS2: fsid=%s: warning: assertion \"%s\" failed\n"
  92. "GFS2: fsid=%s: function = %s, file = %s, line = %u\n",
  93. sdp->sd_fsname, assertion,
  94. sdp->sd_fsname, 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. "GFS2: fsid=%s: fatal: filesystem consistency error\n"
  118. "GFS2: fsid=%s: function = %s, file = %s, line = %u\n",
  119. sdp->sd_fsname,
  120. sdp->sd_fsname, 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. "GFS2: fsid=%s: fatal: filesystem consistency error\n"
  135. "GFS2: fsid=%s: inode = %llu %llu\n"
  136. "GFS2: fsid=%s: function = %s, file = %s, line = %u\n",
  137. sdp->sd_fsname,
  138. sdp->sd_fsname, (unsigned long long)ip->i_no_formal_ino,
  139. (unsigned long long)ip->i_no_addr,
  140. sdp->sd_fsname, function, file, line);
  141. return rv;
  142. }
  143. /**
  144. * gfs2_consist_rgrpd_i - Flag a RG consistency error and withdraw
  145. * Returns: -1 if this call withdrew the machine,
  146. * 0 if it was already withdrawn
  147. */
  148. int gfs2_consist_rgrpd_i(struct gfs2_rgrpd *rgd, int cluster_wide,
  149. const char *function, char *file, unsigned int line)
  150. {
  151. struct gfs2_sbd *sdp = rgd->rd_sbd;
  152. int rv;
  153. rv = gfs2_lm_withdraw(sdp,
  154. "GFS2: fsid=%s: fatal: filesystem consistency error\n"
  155. "GFS2: fsid=%s: RG = %llu\n"
  156. "GFS2: fsid=%s: function = %s, file = %s, line = %u\n",
  157. sdp->sd_fsname,
  158. sdp->sd_fsname, (unsigned long long)rgd->rd_addr,
  159. sdp->sd_fsname, function, file, line);
  160. return rv;
  161. }
  162. /**
  163. * gfs2_meta_check_ii - Flag a magic number consistency error and withdraw
  164. * Returns: -1 if this call withdrew the machine,
  165. * -2 if it was already withdrawn
  166. */
  167. int gfs2_meta_check_ii(struct gfs2_sbd *sdp, struct buffer_head *bh,
  168. const char *type, const char *function, char *file,
  169. unsigned int line)
  170. {
  171. int me;
  172. me = gfs2_lm_withdraw(sdp,
  173. "GFS2: fsid=%s: fatal: invalid metadata block\n"
  174. "GFS2: fsid=%s: bh = %llu (%s)\n"
  175. "GFS2: fsid=%s: function = %s, file = %s, line = %u\n",
  176. sdp->sd_fsname,
  177. sdp->sd_fsname, (unsigned long long)bh->b_blocknr, type,
  178. sdp->sd_fsname, function, file, line);
  179. return (me) ? -1 : -2;
  180. }
  181. /**
  182. * gfs2_metatype_check_ii - Flag a metadata type consistency error and withdraw
  183. * Returns: -1 if this call withdrew the machine,
  184. * -2 if it was already withdrawn
  185. */
  186. int gfs2_metatype_check_ii(struct gfs2_sbd *sdp, struct buffer_head *bh,
  187. u16 type, u16 t, const char *function,
  188. char *file, unsigned int line)
  189. {
  190. int me;
  191. me = gfs2_lm_withdraw(sdp,
  192. "GFS2: fsid=%s: fatal: invalid metadata block\n"
  193. "GFS2: fsid=%s: bh = %llu (type: exp=%u, found=%u)\n"
  194. "GFS2: fsid=%s: function = %s, file = %s, line = %u\n",
  195. sdp->sd_fsname,
  196. sdp->sd_fsname, (unsigned long long)bh->b_blocknr, type, t,
  197. sdp->sd_fsname, function, file, line);
  198. return (me) ? -1 : -2;
  199. }
  200. /**
  201. * gfs2_io_error_i - Flag an I/O error and withdraw
  202. * Returns: -1 if this call withdrew the machine,
  203. * 0 if it was already withdrawn
  204. */
  205. int gfs2_io_error_i(struct gfs2_sbd *sdp, const char *function, char *file,
  206. unsigned int line)
  207. {
  208. int rv;
  209. rv = gfs2_lm_withdraw(sdp,
  210. "GFS2: fsid=%s: fatal: I/O error\n"
  211. "GFS2: fsid=%s: function = %s, file = %s, line = %u\n",
  212. sdp->sd_fsname,
  213. sdp->sd_fsname, function, file, line);
  214. return rv;
  215. }
  216. /**
  217. * gfs2_io_error_bh_i - Flag a buffer I/O error and withdraw
  218. * Returns: -1 if this call withdrew the machine,
  219. * 0 if it was already withdrawn
  220. */
  221. int gfs2_io_error_bh_i(struct gfs2_sbd *sdp, struct buffer_head *bh,
  222. const char *function, char *file, unsigned int line)
  223. {
  224. int rv;
  225. rv = gfs2_lm_withdraw(sdp,
  226. "GFS2: fsid=%s: fatal: I/O error\n"
  227. "GFS2: fsid=%s: block = %llu\n"
  228. "GFS2: fsid=%s: function = %s, file = %s, line = %u\n",
  229. sdp->sd_fsname,
  230. sdp->sd_fsname, (unsigned long long)bh->b_blocknr,
  231. sdp->sd_fsname, function, file, line);
  232. return rv;
  233. }
  234. void gfs2_icbit_munge(struct gfs2_sbd *sdp, unsigned char **bitmap,
  235. unsigned int bit, int new_value)
  236. {
  237. unsigned int c, o, b = bit;
  238. int old_value;
  239. c = b / (8 * PAGE_SIZE);
  240. b %= 8 * PAGE_SIZE;
  241. o = b / 8;
  242. b %= 8;
  243. old_value = (bitmap[c][o] & (1 << b));
  244. gfs2_assert_withdraw(sdp, !old_value != !new_value);
  245. if (new_value)
  246. bitmap[c][o] |= 1 << b;
  247. else
  248. bitmap[c][o] &= ~(1 << b);
  249. }