util.c 6.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243
  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. return (me) ? -1 : -2;
  47. }
  48. /**
  49. * gfs2_assert_warn_i - Print a message to the console if @assertion is false
  50. * Returns: -1 if we printed something
  51. * -2 if we didn't
  52. */
  53. int gfs2_assert_warn_i(struct gfs2_sbd *sdp, char *assertion,
  54. const char *function, char *file, unsigned int line)
  55. {
  56. if (time_before(jiffies,
  57. sdp->sd_last_warning +
  58. gfs2_tune_get(sdp, gt_complain_secs) * HZ))
  59. return -2;
  60. printk(KERN_WARNING
  61. "GFS2: fsid=%s: warning: 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. if (sdp->sd_args.ar_debug)
  66. BUG();
  67. sdp->sd_last_warning = jiffies;
  68. return -1;
  69. }
  70. /**
  71. * gfs2_consist_i - Flag a filesystem consistency error and withdraw
  72. * Returns: -1 if this call withdrew the machine,
  73. * 0 if it was already withdrawn
  74. */
  75. int gfs2_consist_i(struct gfs2_sbd *sdp, int cluster_wide, const char *function,
  76. char *file, unsigned int line)
  77. {
  78. int rv;
  79. rv = gfs2_lm_withdraw(sdp,
  80. "GFS2: fsid=%s: fatal: filesystem consistency error\n"
  81. "GFS2: fsid=%s: function = %s, file = %s, line = %u\n",
  82. sdp->sd_fsname,
  83. sdp->sd_fsname, function, file, line);
  84. return rv;
  85. }
  86. /**
  87. * gfs2_consist_inode_i - Flag an inode consistency error and withdraw
  88. * Returns: -1 if this call withdrew the machine,
  89. * 0 if it was already withdrawn
  90. */
  91. int gfs2_consist_inode_i(struct gfs2_inode *ip, int cluster_wide,
  92. const char *function, char *file, unsigned int line)
  93. {
  94. struct gfs2_sbd *sdp = ip->i_sbd;
  95. int rv;
  96. rv = gfs2_lm_withdraw(sdp,
  97. "GFS2: fsid=%s: fatal: filesystem consistency error\n"
  98. "GFS2: fsid=%s: inode = %llu %llu\n"
  99. "GFS2: fsid=%s: function = %s, file = %s, line = %u\n",
  100. sdp->sd_fsname,
  101. sdp->sd_fsname, ip->i_num.no_formal_ino, ip->i_num.no_addr,
  102. sdp->sd_fsname, function, file, line);
  103. return rv;
  104. }
  105. /**
  106. * gfs2_consist_rgrpd_i - Flag a RG consistency error and withdraw
  107. * Returns: -1 if this call withdrew the machine,
  108. * 0 if it was already withdrawn
  109. */
  110. int gfs2_consist_rgrpd_i(struct gfs2_rgrpd *rgd, int cluster_wide,
  111. const char *function, char *file, unsigned int line)
  112. {
  113. struct gfs2_sbd *sdp = rgd->rd_sbd;
  114. int rv;
  115. rv = gfs2_lm_withdraw(sdp,
  116. "GFS2: fsid=%s: fatal: filesystem consistency error\n"
  117. "GFS2: fsid=%s: RG = %llu\n"
  118. "GFS2: fsid=%s: function = %s, file = %s, line = %u\n",
  119. sdp->sd_fsname,
  120. sdp->sd_fsname, rgd->rd_ri.ri_addr,
  121. sdp->sd_fsname, function, file, line);
  122. return rv;
  123. }
  124. /**
  125. * gfs2_meta_check_ii - Flag a magic number consistency error and withdraw
  126. * Returns: -1 if this call withdrew the machine,
  127. * -2 if it was already withdrawn
  128. */
  129. int gfs2_meta_check_ii(struct gfs2_sbd *sdp, struct buffer_head *bh,
  130. const char *type, const char *function, char *file,
  131. unsigned int line)
  132. {
  133. int me;
  134. me = gfs2_lm_withdraw(sdp,
  135. "GFS2: fsid=%s: fatal: invalid metadata block\n"
  136. "GFS2: fsid=%s: bh = %llu (%s)\n"
  137. "GFS2: fsid=%s: function = %s, file = %s, line = %u\n",
  138. sdp->sd_fsname,
  139. sdp->sd_fsname, (uint64_t)bh->b_blocknr, type,
  140. sdp->sd_fsname, function, file, line);
  141. return (me) ? -1 : -2;
  142. }
  143. /**
  144. * gfs2_metatype_check_ii - Flag a metadata type consistency error and withdraw
  145. * Returns: -1 if this call withdrew the machine,
  146. * -2 if it was already withdrawn
  147. */
  148. int gfs2_metatype_check_ii(struct gfs2_sbd *sdp, struct buffer_head *bh,
  149. uint16_t type, uint16_t t, const char *function,
  150. char *file, unsigned int line)
  151. {
  152. int me;
  153. me = gfs2_lm_withdraw(sdp,
  154. "GFS2: fsid=%s: fatal: invalid metadata block\n"
  155. "GFS2: fsid=%s: bh = %llu (type: exp=%u, found=%u)\n"
  156. "GFS2: fsid=%s: function = %s, file = %s, line = %u\n",
  157. sdp->sd_fsname,
  158. sdp->sd_fsname, (uint64_t)bh->b_blocknr, type, t,
  159. sdp->sd_fsname, function, file, line);
  160. return (me) ? -1 : -2;
  161. }
  162. /**
  163. * gfs2_io_error_i - Flag an I/O error and withdraw
  164. * Returns: -1 if this call withdrew the machine,
  165. * 0 if it was already withdrawn
  166. */
  167. int gfs2_io_error_i(struct gfs2_sbd *sdp, const char *function, char *file,
  168. unsigned int line)
  169. {
  170. int rv;
  171. rv = gfs2_lm_withdraw(sdp,
  172. "GFS2: fsid=%s: fatal: I/O error\n"
  173. "GFS2: fsid=%s: function = %s, file = %s, line = %u\n",
  174. sdp->sd_fsname,
  175. sdp->sd_fsname, function, file, line);
  176. return rv;
  177. }
  178. /**
  179. * gfs2_io_error_bh_i - Flag a buffer I/O error and withdraw
  180. * Returns: -1 if this call withdrew the machine,
  181. * 0 if it was already withdrawn
  182. */
  183. int gfs2_io_error_bh_i(struct gfs2_sbd *sdp, struct buffer_head *bh,
  184. const char *function, char *file, unsigned int line)
  185. {
  186. int rv;
  187. rv = gfs2_lm_withdraw(sdp,
  188. "GFS2: fsid=%s: fatal: I/O error\n"
  189. "GFS2: fsid=%s: block = %llu\n"
  190. "GFS2: fsid=%s: function = %s, file = %s, line = %u\n",
  191. sdp->sd_fsname,
  192. sdp->sd_fsname, (uint64_t)bh->b_blocknr,
  193. sdp->sd_fsname, function, file, line);
  194. return rv;
  195. }
  196. void gfs2_icbit_munge(struct gfs2_sbd *sdp, unsigned char **bitmap,
  197. unsigned int bit, int new_value)
  198. {
  199. unsigned int c, o, b = bit;
  200. int old_value;
  201. c = b / (8 * PAGE_SIZE);
  202. b %= 8 * PAGE_SIZE;
  203. o = b / 8;
  204. b %= 8;
  205. old_value = (bitmap[c][o] & (1 << b));
  206. gfs2_assert_withdraw(sdp, !old_value != !new_value);
  207. if (new_value)
  208. bitmap[c][o] |= 1 << b;
  209. else
  210. bitmap[c][o] &= ~(1 << b);
  211. }