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