util.c 6.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246
  1. /*
  2. * Copyright (C) Sistina Software, Inc. 1997-2003 All rights reserved.
  3. * Copyright (C) 2004-2005 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 v.2.
  8. */
  9. #include <linux/sched.h>
  10. #include <linux/slab.h>
  11. #include <linux/spinlock.h>
  12. #include <linux/completion.h>
  13. #include <linux/buffer_head.h>
  14. #include <linux/crc32.h>
  15. #include <asm/semaphore.h>
  16. #include <asm/uaccess.h>
  17. #include "gfs2.h"
  18. #include "glock.h"
  19. #include "lm.h"
  20. kmem_cache_t *gfs2_glock_cachep __read_mostly;
  21. kmem_cache_t *gfs2_inode_cachep __read_mostly;
  22. kmem_cache_t *gfs2_bufdata_cachep __read_mostly;
  23. uint32_t gfs2_disk_hash(const char *data, int len)
  24. {
  25. return crc32_le(0xFFFFFFFF, data, len) ^ 0xFFFFFFFF;
  26. }
  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. /**
  33. * gfs2_assert_withdraw_i - Cause the machine to withdraw if @assertion is false
  34. * Returns: -1 if this call withdrew the machine,
  35. * -2 if it was already withdrawn
  36. */
  37. int gfs2_assert_withdraw_i(struct gfs2_sbd *sdp, char *assertion,
  38. const char *function, char *file, unsigned int line)
  39. {
  40. int me;
  41. me = gfs2_lm_withdraw(sdp,
  42. "GFS2: fsid=%s: fatal: assertion \"%s\" failed\n"
  43. "GFS2: fsid=%s: function = %s, file = %s, line = %u\n",
  44. sdp->sd_fsname, assertion,
  45. sdp->sd_fsname, function, file, line);
  46. dump_stack();
  47. return (me) ? -1 : -2;
  48. }
  49. /**
  50. * gfs2_assert_warn_i - Print a message to the console if @assertion is false
  51. * Returns: -1 if we printed something
  52. * -2 if we didn't
  53. */
  54. int gfs2_assert_warn_i(struct gfs2_sbd *sdp, char *assertion,
  55. const char *function, char *file, unsigned int line)
  56. {
  57. if (time_before(jiffies,
  58. sdp->sd_last_warning +
  59. gfs2_tune_get(sdp, gt_complain_secs) * HZ))
  60. return -2;
  61. printk(KERN_WARNING
  62. "GFS2: fsid=%s: warning: assertion \"%s\" failed\n"
  63. "GFS2: fsid=%s: function = %s, file = %s, line = %u\n",
  64. sdp->sd_fsname, assertion,
  65. sdp->sd_fsname, function, file, line);
  66. if (sdp->sd_args.ar_debug)
  67. BUG();
  68. else
  69. dump_stack();
  70. sdp->sd_last_warning = jiffies;
  71. return -1;
  72. }
  73. /**
  74. * gfs2_consist_i - Flag a filesystem consistency error and withdraw
  75. * Returns: -1 if this call withdrew the machine,
  76. * 0 if it was already withdrawn
  77. */
  78. int gfs2_consist_i(struct gfs2_sbd *sdp, int cluster_wide, const char *function,
  79. char *file, unsigned int line)
  80. {
  81. int rv;
  82. rv = gfs2_lm_withdraw(sdp,
  83. "GFS2: fsid=%s: fatal: filesystem consistency error\n"
  84. "GFS2: fsid=%s: function = %s, file = %s, line = %u\n",
  85. sdp->sd_fsname,
  86. sdp->sd_fsname, function, file, line);
  87. return rv;
  88. }
  89. /**
  90. * gfs2_consist_inode_i - Flag an inode consistency error and withdraw
  91. * Returns: -1 if this call withdrew the machine,
  92. * 0 if it was already withdrawn
  93. */
  94. int gfs2_consist_inode_i(struct gfs2_inode *ip, int cluster_wide,
  95. const char *function, char *file, unsigned int line)
  96. {
  97. struct gfs2_sbd *sdp = ip->i_sbd;
  98. int rv;
  99. rv = gfs2_lm_withdraw(sdp,
  100. "GFS2: fsid=%s: fatal: filesystem consistency error\n"
  101. "GFS2: fsid=%s: inode = %llu %llu\n"
  102. "GFS2: fsid=%s: function = %s, file = %s, line = %u\n",
  103. sdp->sd_fsname,
  104. sdp->sd_fsname, ip->i_num.no_formal_ino, ip->i_num.no_addr,
  105. sdp->sd_fsname, function, file, line);
  106. return rv;
  107. }
  108. /**
  109. * gfs2_consist_rgrpd_i - Flag a RG 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_rgrpd_i(struct gfs2_rgrpd *rgd, int cluster_wide,
  114. const char *function, char *file, unsigned int line)
  115. {
  116. struct gfs2_sbd *sdp = rgd->rd_sbd;
  117. int rv;
  118. rv = gfs2_lm_withdraw(sdp,
  119. "GFS2: fsid=%s: fatal: filesystem consistency error\n"
  120. "GFS2: fsid=%s: RG = %llu\n"
  121. "GFS2: fsid=%s: function = %s, file = %s, line = %u\n",
  122. sdp->sd_fsname,
  123. sdp->sd_fsname, rgd->rd_ri.ri_addr,
  124. sdp->sd_fsname, function, file, line);
  125. return rv;
  126. }
  127. /**
  128. * gfs2_meta_check_ii - Flag a magic number consistency error and withdraw
  129. * Returns: -1 if this call withdrew the machine,
  130. * -2 if it was already withdrawn
  131. */
  132. int gfs2_meta_check_ii(struct gfs2_sbd *sdp, struct buffer_head *bh,
  133. const char *type, const char *function, char *file,
  134. unsigned int line)
  135. {
  136. int me;
  137. me = gfs2_lm_withdraw(sdp,
  138. "GFS2: fsid=%s: fatal: invalid metadata block\n"
  139. "GFS2: fsid=%s: bh = %llu (%s)\n"
  140. "GFS2: fsid=%s: function = %s, file = %s, line = %u\n",
  141. sdp->sd_fsname,
  142. sdp->sd_fsname, (uint64_t)bh->b_blocknr, type,
  143. sdp->sd_fsname, function, file, line);
  144. return (me) ? -1 : -2;
  145. }
  146. /**
  147. * gfs2_metatype_check_ii - Flag a metadata type consistency error and withdraw
  148. * Returns: -1 if this call withdrew the machine,
  149. * -2 if it was already withdrawn
  150. */
  151. int gfs2_metatype_check_ii(struct gfs2_sbd *sdp, struct buffer_head *bh,
  152. uint16_t type, uint16_t t, const char *function,
  153. char *file, unsigned int line)
  154. {
  155. int me;
  156. me = gfs2_lm_withdraw(sdp,
  157. "GFS2: fsid=%s: fatal: invalid metadata block\n"
  158. "GFS2: fsid=%s: bh = %llu (type: exp=%u, found=%u)\n"
  159. "GFS2: fsid=%s: function = %s, file = %s, line = %u\n",
  160. sdp->sd_fsname,
  161. sdp->sd_fsname, (uint64_t)bh->b_blocknr, type, t,
  162. sdp->sd_fsname, function, file, line);
  163. return (me) ? -1 : -2;
  164. }
  165. /**
  166. * gfs2_io_error_i - Flag an I/O error and withdraw
  167. * Returns: -1 if this call withdrew the machine,
  168. * 0 if it was already withdrawn
  169. */
  170. int gfs2_io_error_i(struct gfs2_sbd *sdp, const char *function, char *file,
  171. unsigned int line)
  172. {
  173. int rv;
  174. rv = gfs2_lm_withdraw(sdp,
  175. "GFS2: fsid=%s: fatal: I/O error\n"
  176. "GFS2: fsid=%s: function = %s, file = %s, line = %u\n",
  177. sdp->sd_fsname,
  178. sdp->sd_fsname, function, file, line);
  179. return rv;
  180. }
  181. /**
  182. * gfs2_io_error_bh_i - Flag a buffer I/O error and withdraw
  183. * Returns: -1 if this call withdrew the machine,
  184. * 0 if it was already withdrawn
  185. */
  186. int gfs2_io_error_bh_i(struct gfs2_sbd *sdp, struct buffer_head *bh,
  187. const char *function, char *file, unsigned int line)
  188. {
  189. int rv;
  190. rv = gfs2_lm_withdraw(sdp,
  191. "GFS2: fsid=%s: fatal: I/O error\n"
  192. "GFS2: fsid=%s: block = %llu\n"
  193. "GFS2: fsid=%s: function = %s, file = %s, line = %u\n",
  194. sdp->sd_fsname,
  195. sdp->sd_fsname, (uint64_t)bh->b_blocknr,
  196. sdp->sd_fsname, function, file, line);
  197. return rv;
  198. }
  199. void gfs2_icbit_munge(struct gfs2_sbd *sdp, unsigned char **bitmap,
  200. unsigned int bit, int new_value)
  201. {
  202. unsigned int c, o, b = bit;
  203. int old_value;
  204. c = b / (8 * PAGE_SIZE);
  205. b %= 8 * PAGE_SIZE;
  206. o = b / 8;
  207. b %= 8;
  208. old_value = (bitmap[c][o] & (1 << b));
  209. gfs2_assert_withdraw(sdp, !old_value != !new_value);
  210. if (new_value)
  211. bitmap[c][o] |= 1 << b;
  212. else
  213. bitmap[c][o] &= ~(1 << b);
  214. }