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