util.c 7.4 KB

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