blockcheck.h 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108
  1. /* -*- mode: c; c-basic-offset: 8; -*-
  2. * vim: noexpandtab sw=8 ts=8 sts=0:
  3. *
  4. * blockcheck.h
  5. *
  6. * Checksum and ECC codes for the OCFS2 userspace library.
  7. *
  8. * Copyright (C) 2004, 2008 Oracle. All rights reserved.
  9. *
  10. * This program is free software; you can redistribute it and/or
  11. * modify it under the terms of the GNU General Public
  12. * License, version 2, as published by the Free Software Foundation.
  13. *
  14. * This program is distributed in the hope that it will be useful,
  15. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  16. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  17. * General Public License for more details.
  18. */
  19. #ifndef OCFS2_BLOCKCHECK_H
  20. #define OCFS2_BLOCKCHECK_H
  21. /* Count errors and error correction from blockcheck.c */
  22. struct ocfs2_blockcheck_stats {
  23. spinlock_t b_lock;
  24. u64 b_check_count; /* Number of blocks we've checked */
  25. u64 b_failure_count; /* Number of failed checksums */
  26. u64 b_recover_count; /* Number of blocks fixed by ecc */
  27. /*
  28. * debugfs entries, used if this is passed to
  29. * ocfs2_blockcheck_stats_debugfs_install()
  30. */
  31. struct dentry *b_debug_dir; /* Parent of the debugfs files */
  32. struct dentry *b_debug_check; /* Exposes b_check_count */
  33. struct dentry *b_debug_failure; /* Exposes b_failure_count */
  34. struct dentry *b_debug_recover; /* Exposes b_recover_count */
  35. };
  36. /* High level block API */
  37. void ocfs2_compute_meta_ecc(struct super_block *sb, void *data,
  38. struct ocfs2_block_check *bc);
  39. int ocfs2_validate_meta_ecc(struct super_block *sb, void *data,
  40. struct ocfs2_block_check *bc);
  41. void ocfs2_compute_meta_ecc_bhs(struct super_block *sb,
  42. struct buffer_head **bhs, int nr,
  43. struct ocfs2_block_check *bc);
  44. int ocfs2_validate_meta_ecc_bhs(struct super_block *sb,
  45. struct buffer_head **bhs, int nr,
  46. struct ocfs2_block_check *bc);
  47. /* Lower level API */
  48. void ocfs2_block_check_compute(void *data, size_t blocksize,
  49. struct ocfs2_block_check *bc);
  50. int ocfs2_block_check_validate(void *data, size_t blocksize,
  51. struct ocfs2_block_check *bc,
  52. struct ocfs2_blockcheck_stats *stats);
  53. void ocfs2_block_check_compute_bhs(struct buffer_head **bhs, int nr,
  54. struct ocfs2_block_check *bc);
  55. int ocfs2_block_check_validate_bhs(struct buffer_head **bhs, int nr,
  56. struct ocfs2_block_check *bc,
  57. struct ocfs2_blockcheck_stats *stats);
  58. /* Debug Initialization */
  59. int ocfs2_blockcheck_stats_debugfs_install(struct ocfs2_blockcheck_stats *stats,
  60. struct dentry *parent);
  61. void ocfs2_blockcheck_stats_debugfs_remove(struct ocfs2_blockcheck_stats *stats);
  62. /*
  63. * Hamming code functions
  64. */
  65. /*
  66. * Encoding hamming code parity bits for a buffer.
  67. *
  68. * This is the low level encoder function. It can be called across
  69. * multiple hunks just like the crc32 code. 'd' is the number of bits
  70. * _in_this_hunk_. nr is the bit offset of this hunk. So, if you had
  71. * two 512B buffers, you would do it like so:
  72. *
  73. * parity = ocfs2_hamming_encode(0, buf1, 512 * 8, 0);
  74. * parity = ocfs2_hamming_encode(parity, buf2, 512 * 8, 512 * 8);
  75. *
  76. * If you just have one buffer, use ocfs2_hamming_encode_block().
  77. */
  78. u32 ocfs2_hamming_encode(u32 parity, void *data, unsigned int d,
  79. unsigned int nr);
  80. /*
  81. * Fix a buffer with a bit error. The 'fix' is the original parity
  82. * xor'd with the parity calculated now.
  83. *
  84. * Like ocfs2_hamming_encode(), this can handle hunks. nr is the bit
  85. * offset of the current hunk. If bit to be fixed is not part of the
  86. * current hunk, this does nothing.
  87. *
  88. * If you only have one buffer, use ocfs2_hamming_fix_block().
  89. */
  90. void ocfs2_hamming_fix(void *data, unsigned int d, unsigned int nr,
  91. unsigned int fix);
  92. /* Convenience wrappers for a single buffer of data */
  93. extern u32 ocfs2_hamming_encode_block(void *data, unsigned int blocksize);
  94. extern void ocfs2_hamming_fix_block(void *data, unsigned int blocksize,
  95. unsigned int fix);
  96. #endif