]> git.proxmox.com Git - mirror_zfs.git/blame - include/sys/zio_checksum.h
ztest: scrub ddt repair
[mirror_zfs.git] / include / sys / zio_checksum.h
CommitLineData
34dc7c2f
BB
1/*
2 * CDDL HEADER START
3 *
4 * The contents of this file are subject to the terms of the
5 * Common Development and Distribution License (the "License").
6 * You may not use this file except in compliance with the License.
7 *
8 * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
9 * or http://www.opensolaris.org/os/licensing.
10 * See the License for the specific language governing permissions
11 * and limitations under the License.
12 *
13 * When distributing Covered Code, include this CDDL HEADER in each
14 * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
15 * If applicable, add the following below this CDDL HEADER, with the
16 * fields enclosed by brackets "[]" replaced with your own identifying
17 * information: Portions Copyright [yyyy] [name of copyright owner]
18 *
19 * CDDL HEADER END
20 */
21/*
428870ff 22 * Copyright (c) 2005, 2010, Oracle and/or its affiliates. All rights reserved.
a6255b7f 23 * Copyright (c) 2014, 2016 by Delphix. All rights reserved.
3c67d83a 24 * Copyright Saso Kiselkov 2013, All rights reserved.
34dc7c2f
BB
25 */
26
27#ifndef _SYS_ZIO_CHECKSUM_H
28#define _SYS_ZIO_CHECKSUM_H
29
34dc7c2f 30#include <sys/zio.h>
3c67d83a 31#include <zfeature_common.h>
2fe36b0b 32#include <zfs_fletcher.h>
34dc7c2f
BB
33
34#ifdef __cplusplus
35extern "C" {
36#endif
37
a6255b7f
DQ
38struct abd;
39
34dc7c2f
BB
40/*
41 * Signature for checksum functions.
42 */
a6255b7f 43typedef void zio_checksum_t(struct abd *abd, uint64_t size,
3c67d83a
TH
44 const void *ctx_template, zio_cksum_t *zcp);
45typedef void *zio_checksum_tmpl_init_t(const zio_cksum_salt_t *salt);
46typedef void zio_checksum_tmpl_free_t(void *ctx_template);
47
48typedef enum zio_checksum_flags {
49 /* Strong enough for metadata? */
50 ZCHECKSUM_FLAG_METADATA = (1 << 1),
51 /* ZIO embedded checksum */
52 ZCHECKSUM_FLAG_EMBEDDED = (1 << 2),
53 /* Strong enough for dedup (without verification)? */
54 ZCHECKSUM_FLAG_DEDUP = (1 << 3),
55 /* Uses salt value */
56 ZCHECKSUM_FLAG_SALTED = (1 << 4),
57 /* Strong enough for nopwrite? */
58 ZCHECKSUM_FLAG_NOPWRITE = (1 << 5)
59} zio_checksum_flags_t;
34dc7c2f 60
2fe36b0b
DQ
61typedef enum {
62 ZIO_CHECKSUM_NATIVE,
63 ZIO_CHECKSUM_BYTESWAP
64} zio_byteorder_t;
65
66typedef struct zio_abd_checksum_data {
67 zio_byteorder_t acd_byteorder;
68 fletcher_4_ctx_t *acd_ctx;
69 zio_cksum_t *acd_zcp;
70 void *acd_private;
71} zio_abd_checksum_data_t;
72
73typedef void zio_abd_checksum_init_t(zio_abd_checksum_data_t *);
74typedef void zio_abd_checksum_fini_t(zio_abd_checksum_data_t *);
75typedef int zio_abd_checksum_iter_t(void *, size_t, void *);
76
77typedef const struct zio_abd_checksum_func {
78 zio_abd_checksum_init_t *acf_init;
79 zio_abd_checksum_fini_t *acf_fini;
80 zio_abd_checksum_iter_t *acf_iter;
81} zio_abd_checksum_func_t;
82
34dc7c2f
BB
83/*
84 * Information about each checksum function.
85 */
b01615d5 86typedef const struct zio_checksum_info {
3c67d83a
TH
87 /* checksum function for each byteorder */
88 zio_checksum_t *ci_func[2];
89 zio_checksum_tmpl_init_t *ci_tmpl_init;
90 zio_checksum_tmpl_free_t *ci_tmpl_free;
91 zio_checksum_flags_t ci_flags;
92 char *ci_name; /* descriptive name */
34dc7c2f
BB
93} zio_checksum_info_t;
94
428870ff
BB
95typedef struct zio_bad_cksum {
96 zio_cksum_t zbc_expected;
97 zio_cksum_t zbc_actual;
98 const char *zbc_checksum_name;
99 uint8_t zbc_byteswapped;
100 uint8_t zbc_injected;
101 uint8_t zbc_has_cksum; /* expected/actual valid */
102} zio_bad_cksum_t;
103
34dc7c2f
BB
104extern zio_checksum_info_t zio_checksum_table[ZIO_CHECKSUM_FUNCTIONS];
105
106/*
107 * Checksum routines.
108 */
a6255b7f
DQ
109extern zio_checksum_t abd_checksum_SHA256;
110extern zio_checksum_t abd_checksum_SHA512_native;
111extern zio_checksum_t abd_checksum_SHA512_byteswap;
3c67d83a
TH
112
113/* Skein */
a6255b7f
DQ
114extern zio_checksum_t abd_checksum_skein_native;
115extern zio_checksum_t abd_checksum_skein_byteswap;
116extern zio_checksum_tmpl_init_t abd_checksum_skein_tmpl_init;
117extern zio_checksum_tmpl_free_t abd_checksum_skein_tmpl_free;
3c67d83a
TH
118
119/* Edon-R */
a6255b7f
DQ
120extern zio_checksum_t abd_checksum_edonr_native;
121extern zio_checksum_t abd_checksum_edonr_byteswap;
122extern zio_checksum_tmpl_init_t abd_checksum_edonr_tmpl_init;
123extern zio_checksum_tmpl_free_t abd_checksum_edonr_tmpl_free;
34dc7c2f 124
2fe36b0b
DQ
125extern zio_abd_checksum_func_t fletcher_4_abd_ops;
126extern zio_checksum_t abd_fletcher_4_native;
127extern zio_checksum_t abd_fletcher_4_byteswap;
128
d3c2ae1c
GW
129extern int zio_checksum_equal(spa_t *, blkptr_t *, enum zio_checksum,
130 void *, uint64_t, uint64_t, zio_bad_cksum_t *);
a6255b7f
DQ
131extern void zio_checksum_compute(zio_t *, enum zio_checksum,
132 struct abd *, uint64_t);
84c07ada 133extern int zio_checksum_error_impl(spa_t *, const blkptr_t *, enum zio_checksum,
a6255b7f 134 struct abd *, uint64_t, uint64_t, zio_bad_cksum_t *);
428870ff
BB
135extern int zio_checksum_error(zio_t *zio, zio_bad_cksum_t *out);
136extern enum zio_checksum spa_dedup_checksum(spa_t *spa);
3c67d83a
TH
137extern void zio_checksum_templates_free(spa_t *spa);
138extern spa_feature_t zio_checksum_to_feature(enum zio_checksum cksum);
34dc7c2f
BB
139
140#ifdef __cplusplus
141}
142#endif
143
144#endif /* _SYS_ZIO_CHECKSUM_H */