20 #include <linux/kernel.h>
21 #include <linux/types.h>
24 #include <linux/bitops.h>
26 #include <linux/module.h>
28 #include <asm/byteorder.h>
64 static unsigned int calc_code_bit(
unsigned int i,
unsigned int *p_cache)
66 unsigned int b,
p = 0;
87 for (; (1 <<
p) < (b + 1); p++)
109 unsigned int i,
b, p = 0;
128 b = calc_code_bit(nr + i, &p);
184 if (fix >= calc_code_bit(nr + d,
NULL))
192 b = calc_code_bit(nr,
NULL);
197 for (i = 0; i <
d; i++, b++)
233 #ifdef CONFIG_DEBUG_FS
235 static int blockcheck_u64_get(
void *
data,
u64 *
val)
242 static struct dentry *blockcheck_debugfs_create(
const char *
name,
277 blockcheck_debugfs_create(
"blocks_checked",
282 blockcheck_debugfs_create(
"checksums_failed",
287 blockcheck_debugfs_create(
"ecc_recoveries",
296 ocfs2_blockcheck_debug_remove(stats);
315 return ocfs2_blockcheck_debug_install(stats, parent);
320 ocfs2_blockcheck_debug_remove(stats);
330 spin_lock(&stats->
b_lock);
333 spin_unlock(&stats->
b_lock);
346 spin_lock(&stats->
b_lock);
349 spin_unlock(&stats->
b_lock);
362 spin_lock(&stats->
b_lock);
365 spin_unlock(&stats->
b_lock);
399 crc =
crc32_le(~0, data, blocksize);
429 ocfs2_blockcheck_inc_check(stats);
437 crc =
crc32_le(~0, data, blocksize);
438 if (crc == bc_crc32e)
441 ocfs2_blockcheck_inc_failure(stats);
443 "CRC32 failed: stored: 0x%x, computed 0x%x. Applying ECC.\n",
444 (
unsigned int)bc_crc32e, (
unsigned int)crc);
451 crc =
crc32_le(~0, data, blocksize);
452 if (crc == bc_crc32e) {
453 ocfs2_blockcheck_inc_recover(stats);
457 mlog(
ML_ERROR,
"Fixed CRC32 failed: stored: 0x%x, computed 0x%x\n",
458 (
unsigned int)bc_crc32e, (
unsigned int)crc);
496 for (i = 0, crc = ~0, ecc = 0; i <
nr; i++) {
497 crc =
crc32_le(crc, bhs[i]->b_data, bhs[i]->b_size);
505 bhs[i]->b_size * 8 * i);
541 ocfs2_blockcheck_inc_check(stats);
549 for (i = 0, crc = ~0; i <
nr; i++)
550 crc =
crc32_le(crc, bhs[i]->b_data, bhs[i]->b_size);
551 if (crc == bc_crc32e)
554 ocfs2_blockcheck_inc_failure(stats);
556 "CRC32 failed: stored: %u, computed %u. Applying ECC.\n",
557 (
unsigned int)bc_crc32e, (
unsigned int)crc);
560 for (i = 0, ecc = 0; i <
nr; i++) {
568 bhs[i]->b_size * 8 * i);
571 for (i = 0; i <
nr; i++) {
577 bhs[i]->b_size * 8 * i, fix);
581 for (i = 0, crc = ~0; i <
nr; i++)
582 crc =
crc32_le(crc, bhs[i]->b_data, bhs[i]->b_size);
583 if (crc == bc_crc32e) {
584 ocfs2_blockcheck_inc_recover(stats);
588 mlog(
ML_ERROR,
"Fixed CRC32 failed: stored: %u, computed %u\n",
589 (
unsigned int)bc_crc32e, (
unsigned int)crc);
619 if (ocfs2_meta_ecc(osb))
627 struct buffer_head **bhs,
int nr,
635 struct buffer_head **bhs,
int nr,
641 if (ocfs2_meta_ecc(osb))