Lines Matching +full:has +full:- +full:ecc
1 // SPDX-License-Identifier: GPL-2.0-only
5 * Checksum and ECC codes for the OCFS2 userspace library.
39 * power-of-two bits for parity, the data bit number and the code bit
42 * Recall that bit numbers in hamming code are 1-based. This function
43 * takes the 0-based data bit from the caller.
59 * Data bits are 0-based, but we're talking code bits, which in calc_code_bit()
60 * are 1-based. in calc_code_bit()
105 * 1-based array, but C uses 0-based. So 'i' is for C, and 'b' is in ocfs2_hamming_encode()
164 * If the bit to fix has an hweight of 1, it's a parity bit. One in ocfs2_hamming_fix()
235 debugfs_remove_recursive(stats->b_debug_dir); in ocfs2_blockcheck_debug_remove()
236 stats->b_debug_dir = NULL; in ocfs2_blockcheck_debug_remove()
246 stats->b_debug_dir = dir; in ocfs2_blockcheck_debug_install()
249 &stats->b_check_count, &blockcheck_fops); in ocfs2_blockcheck_debug_install()
252 &stats->b_failure_count, &blockcheck_fops); in ocfs2_blockcheck_debug_install()
255 &stats->b_recover_count, &blockcheck_fops); in ocfs2_blockcheck_debug_install()
269 /* Always-called wrappers for starting and stopping the debugfs files */
288 spin_lock(&stats->b_lock); in ocfs2_blockcheck_inc_check()
289 stats->b_check_count++; in ocfs2_blockcheck_inc_check()
290 new_count = stats->b_check_count; in ocfs2_blockcheck_inc_check()
291 spin_unlock(&stats->b_lock); in ocfs2_blockcheck_inc_check()
294 mlog(ML_NOTICE, "Block check count has wrapped\n"); in ocfs2_blockcheck_inc_check()
304 spin_lock(&stats->b_lock); in ocfs2_blockcheck_inc_failure()
305 stats->b_failure_count++; in ocfs2_blockcheck_inc_failure()
306 new_count = stats->b_failure_count; in ocfs2_blockcheck_inc_failure()
307 spin_unlock(&stats->b_lock); in ocfs2_blockcheck_inc_failure()
310 mlog(ML_NOTICE, "Checksum failure count has wrapped\n"); in ocfs2_blockcheck_inc_failure()
320 spin_lock(&stats->b_lock); in ocfs2_blockcheck_inc_recover()
321 stats->b_recover_count++; in ocfs2_blockcheck_inc_recover()
322 new_count = stats->b_recover_count; in ocfs2_blockcheck_inc_recover()
323 spin_unlock(&stats->b_lock); in ocfs2_blockcheck_inc_recover()
326 mlog(ML_NOTICE, "ECC recovery count has wrapped\n"); in ocfs2_blockcheck_inc_recover()
332 * These are the low-level APIs for using the ocfs2_block_check structure.
338 * ocfs2_block_check structure describing the crc32 and the ecc.
345 * The data buffer must be in on-disk endian (little endian for ocfs2).
346 * bc will be filled with little-endian values and will be ready to go to
353 u32 ecc; in ocfs2_block_check_compute() local
358 ecc = ocfs2_hamming_encode_block(data, blocksize); in ocfs2_block_check_compute()
361 * No ecc'd ocfs2 structure is larger than 4K, so ecc will be no in ocfs2_block_check_compute()
364 BUG_ON(ecc > USHRT_MAX); in ocfs2_block_check_compute()
366 bc->bc_crc32e = cpu_to_le32(crc); in ocfs2_block_check_compute()
367 bc->bc_ecc = cpu_to_le16((u16)ecc); in ocfs2_block_check_compute()
376 * Again, the data passed in should be the on-disk endian.
385 u32 crc, ecc; in ocfs2_block_check_validate() local
389 bc_crc32e = le32_to_cpu(bc->bc_crc32e); in ocfs2_block_check_validate()
390 bc_ecc = le16_to_cpu(bc->bc_ecc); in ocfs2_block_check_validate()
394 /* Fast path - if the crc32 validates, we're good to go */ in ocfs2_block_check_validate()
401 "CRC32 failed: stored: 0x%x, computed 0x%x. Applying ECC.\n", in ocfs2_block_check_validate()
404 /* Ok, try ECC fixups */ in ocfs2_block_check_validate()
405 ecc = ocfs2_hamming_encode_block(data, blocksize); in ocfs2_block_check_validate()
406 ocfs2_hamming_fix_block(data, blocksize, ecc ^ bc_ecc); in ocfs2_block_check_validate()
418 rc = -EIO; in ocfs2_block_check_validate()
421 bc->bc_crc32e = cpu_to_le32(bc_crc32e); in ocfs2_block_check_validate()
422 bc->bc_ecc = cpu_to_le16(bc_ecc); in ocfs2_block_check_validate()
430 * ocfs2_block_check structure describing the crc32 and the ecc.
437 * The data buffer must be in on-disk endian (little endian for ocfs2).
438 * bc will be filled with little-endian values and will be ready to go to
445 u32 crc, ecc; in ocfs2_block_check_compute_bhs() local
454 for (i = 0, crc = ~0, ecc = 0; i < nr; i++) { in ocfs2_block_check_compute_bhs()
455 crc = crc32_le(crc, bhs[i]->b_data, bhs[i]->b_size); in ocfs2_block_check_compute_bhs()
461 ecc = (u16)ocfs2_hamming_encode(ecc, bhs[i]->b_data, in ocfs2_block_check_compute_bhs()
462 bhs[i]->b_size * 8, in ocfs2_block_check_compute_bhs()
463 bhs[i]->b_size * 8 * i); in ocfs2_block_check_compute_bhs()
467 * No ecc'd ocfs2 structure is larger than 4K, so ecc will be no in ocfs2_block_check_compute_bhs()
470 BUG_ON(ecc > USHRT_MAX); in ocfs2_block_check_compute_bhs()
472 bc->bc_crc32e = cpu_to_le32(crc); in ocfs2_block_check_compute_bhs()
473 bc->bc_ecc = cpu_to_le16((u16)ecc); in ocfs2_block_check_compute_bhs()
483 * Again, the data passed in should be the on-disk endian.
492 u32 crc, ecc, fix; in ocfs2_block_check_validate_bhs() local
501 bc_crc32e = le32_to_cpu(bc->bc_crc32e); in ocfs2_block_check_validate_bhs()
502 bc_ecc = le16_to_cpu(bc->bc_ecc); in ocfs2_block_check_validate_bhs()
506 /* Fast path - if the crc32 validates, we're good to go */ in ocfs2_block_check_validate_bhs()
508 crc = crc32_le(crc, bhs[i]->b_data, bhs[i]->b_size); in ocfs2_block_check_validate_bhs()
514 "CRC32 failed: stored: %u, computed %u. Applying ECC.\n", in ocfs2_block_check_validate_bhs()
517 /* Ok, try ECC fixups */ in ocfs2_block_check_validate_bhs()
518 for (i = 0, ecc = 0; i < nr; i++) { in ocfs2_block_check_validate_bhs()
524 ecc = (u16)ocfs2_hamming_encode(ecc, bhs[i]->b_data, in ocfs2_block_check_validate_bhs()
525 bhs[i]->b_size * 8, in ocfs2_block_check_validate_bhs()
526 bhs[i]->b_size * 8 * i); in ocfs2_block_check_validate_bhs()
528 fix = ecc ^ bc_ecc; in ocfs2_block_check_validate_bhs()
534 ocfs2_hamming_fix(bhs[i]->b_data, bhs[i]->b_size * 8, in ocfs2_block_check_validate_bhs()
535 bhs[i]->b_size * 8 * i, fix); in ocfs2_block_check_validate_bhs()
540 crc = crc32_le(crc, bhs[i]->b_data, bhs[i]->b_size); in ocfs2_block_check_validate_bhs()
549 rc = -EIO; in ocfs2_block_check_validate_bhs()
552 bc->bc_crc32e = cpu_to_le32(bc_crc32e); in ocfs2_block_check_validate_bhs()
553 bc->bc_ecc = cpu_to_le16(bc_ecc); in ocfs2_block_check_validate_bhs()
568 ocfs2_block_check_compute(data, sb->s_blocksize, bc); in ocfs2_compute_meta_ecc()
578 rc = ocfs2_block_check_validate(data, sb->s_blocksize, bc, in ocfs2_validate_meta_ecc()
579 &osb->osb_ecc_stats); in ocfs2_validate_meta_ecc()
601 &osb->osb_ecc_stats); in ocfs2_validate_meta_ecc_bhs()