xref: /illumos-gate/usr/src/uts/common/fs/zfs/sys/zio_checksum.h (revision eb633035c80613ec93d62f90482837adaaf21a0a)
1fa9e4066Sahrens /*
2fa9e4066Sahrens  * CDDL HEADER START
3fa9e4066Sahrens  *
4fa9e4066Sahrens  * The contents of this file are subject to the terms of the
5ea8dc4b6Seschrock  * Common Development and Distribution License (the "License").
6ea8dc4b6Seschrock  * You may not use this file except in compliance with the License.
7fa9e4066Sahrens  *
8fa9e4066Sahrens  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
9fa9e4066Sahrens  * or http://www.opensolaris.org/os/licensing.
10fa9e4066Sahrens  * See the License for the specific language governing permissions
11fa9e4066Sahrens  * and limitations under the License.
12fa9e4066Sahrens  *
13fa9e4066Sahrens  * When distributing Covered Code, include this CDDL HEADER in each
14fa9e4066Sahrens  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
15fa9e4066Sahrens  * If applicable, add the following below this CDDL HEADER, with the
16fa9e4066Sahrens  * fields enclosed by brackets "[]" replaced with your own identifying
17fa9e4066Sahrens  * information: Portions Copyright [yyyy] [name of copyright owner]
18fa9e4066Sahrens  *
19fa9e4066Sahrens  * CDDL HEADER END
20fa9e4066Sahrens  */
21fa9e4066Sahrens /*
22cde58dbcSMatthew Ahrens  * Copyright (c) 2005, 2010, Oracle and/or its affiliates. All rights reserved.
23770499e1SDan Kimmel  * Copyright (c) 2014, 2016 by Delphix. All rights reserved.
2445818ee1SMatthew Ahrens  * Copyright Saso Kiselkov 2013, All rights reserved.
25fa9e4066Sahrens  */
26fa9e4066Sahrens 
27fa9e4066Sahrens #ifndef _SYS_ZIO_CHECKSUM_H
28fa9e4066Sahrens #define	_SYS_ZIO_CHECKSUM_H
29fa9e4066Sahrens 
30fa9e4066Sahrens #include <sys/zio.h>
3145818ee1SMatthew Ahrens #include <zfeature_common.h>
32fa9e4066Sahrens 
33fa9e4066Sahrens #ifdef	__cplusplus
34fa9e4066Sahrens extern "C" {
35fa9e4066Sahrens #endif
36fa9e4066Sahrens 
37770499e1SDan Kimmel struct abd;
38770499e1SDan Kimmel 
39fa9e4066Sahrens /*
40fa9e4066Sahrens  * Signature for checksum functions.
41fa9e4066Sahrens  */
42770499e1SDan Kimmel typedef void zio_checksum_t(struct abd *, uint64_t size,
4345818ee1SMatthew Ahrens     const void *ctx_template, zio_cksum_t *zcp);
4445818ee1SMatthew Ahrens typedef void *zio_checksum_tmpl_init_t(const zio_cksum_salt_t *salt);
4545818ee1SMatthew Ahrens typedef void zio_checksum_tmpl_free_t(void *ctx_template);
4645818ee1SMatthew Ahrens 
4745818ee1SMatthew Ahrens typedef enum zio_checksum_flags {
4845818ee1SMatthew Ahrens 	/* Strong enough for metadata? */
4945818ee1SMatthew Ahrens 	ZCHECKSUM_FLAG_METADATA = (1 << 1),
5045818ee1SMatthew Ahrens 	/* ZIO embedded checksum */
5145818ee1SMatthew Ahrens 	ZCHECKSUM_FLAG_EMBEDDED = (1 << 2),
5245818ee1SMatthew Ahrens 	/* Strong enough for dedup (without verification)? */
5345818ee1SMatthew Ahrens 	ZCHECKSUM_FLAG_DEDUP = (1 << 3),
5445818ee1SMatthew Ahrens 	/* Uses salt value */
5545818ee1SMatthew Ahrens 	ZCHECKSUM_FLAG_SALTED = (1 << 4),
5645818ee1SMatthew Ahrens 	/* Strong enough for nopwrite? */
57*eb633035STom Caputi 	ZCHECKSUM_FLAG_NOPWRITE = (1 << 5),
5845818ee1SMatthew Ahrens } zio_checksum_flags_t;
59fa9e4066Sahrens 
60fa9e4066Sahrens /*
61fa9e4066Sahrens  * Information about each checksum function.
62fa9e4066Sahrens  */
63fa9e4066Sahrens typedef struct zio_checksum_info {
6445818ee1SMatthew Ahrens 	/* checksum function for each byteorder */
6545818ee1SMatthew Ahrens 	zio_checksum_t			*ci_func[2];
6645818ee1SMatthew Ahrens 	zio_checksum_tmpl_init_t	*ci_tmpl_init;
6745818ee1SMatthew Ahrens 	zio_checksum_tmpl_free_t	*ci_tmpl_free;
6845818ee1SMatthew Ahrens 	zio_checksum_flags_t		ci_flags;
6945818ee1SMatthew Ahrens 	char				*ci_name;	/* descriptive name */
70fa9e4066Sahrens } zio_checksum_info_t;
71fa9e4066Sahrens 
7222fe2c88SJonathan Adams typedef struct zio_bad_cksum {
7322fe2c88SJonathan Adams 	zio_cksum_t		zbc_expected;
7422fe2c88SJonathan Adams 	zio_cksum_t		zbc_actual;
7522fe2c88SJonathan Adams 	const char		*zbc_checksum_name;
7622fe2c88SJonathan Adams 	uint8_t			zbc_byteswapped;
7722fe2c88SJonathan Adams 	uint8_t			zbc_injected;
7822fe2c88SJonathan Adams 	uint8_t			zbc_has_cksum;	/* expected/actual valid */
7922fe2c88SJonathan Adams } zio_bad_cksum_t;
8022fe2c88SJonathan Adams 
81fa9e4066Sahrens extern zio_checksum_info_t zio_checksum_table[ZIO_CHECKSUM_FUNCTIONS];
82fa9e4066Sahrens 
83fa9e4066Sahrens /*
84fa9e4066Sahrens  * Checksum routines.
85fa9e4066Sahrens  */
86770499e1SDan Kimmel extern zio_checksum_t abd_checksum_SHA256;
87770499e1SDan Kimmel extern zio_checksum_t abd_checksum_SHA512_native;
88770499e1SDan Kimmel extern zio_checksum_t abd_checksum_SHA512_byteswap;
8945818ee1SMatthew Ahrens 
9045818ee1SMatthew Ahrens /* Skein */
91770499e1SDan Kimmel extern zio_checksum_t abd_checksum_skein_native;
92770499e1SDan Kimmel extern zio_checksum_t abd_checksum_skein_byteswap;
93770499e1SDan Kimmel extern zio_checksum_tmpl_init_t abd_checksum_skein_tmpl_init;
94770499e1SDan Kimmel extern zio_checksum_tmpl_free_t abd_checksum_skein_tmpl_free;
9545818ee1SMatthew Ahrens 
9645818ee1SMatthew Ahrens /* Edon-R */
97770499e1SDan Kimmel extern zio_checksum_t abd_checksum_edonr_native;
98770499e1SDan Kimmel extern zio_checksum_t abd_checksum_edonr_byteswap;
99770499e1SDan Kimmel extern zio_checksum_tmpl_init_t abd_checksum_edonr_tmpl_init;
100770499e1SDan Kimmel extern zio_checksum_tmpl_free_t abd_checksum_edonr_tmpl_free;
101fa9e4066Sahrens 
102dcbf3bd6SGeorge Wilson extern int zio_checksum_equal(spa_t *, blkptr_t *, enum zio_checksum,
103dcbf3bd6SGeorge Wilson     void *, uint64_t, uint64_t, zio_bad_cksum_t *);
104770499e1SDan Kimmel extern void zio_checksum_compute(zio_t *, enum zio_checksum,
105770499e1SDan Kimmel     struct abd *, uint64_t);
106*eb633035STom Caputi extern int zio_checksum_error_impl(spa_t *, const blkptr_t *, enum zio_checksum,
107770499e1SDan Kimmel     struct abd *, uint64_t, uint64_t, zio_bad_cksum_t *);
10822fe2c88SJonathan Adams extern int zio_checksum_error(zio_t *zio, zio_bad_cksum_t *out);
109cde58dbcSMatthew Ahrens extern enum zio_checksum spa_dedup_checksum(spa_t *spa);
11045818ee1SMatthew Ahrens extern void zio_checksum_templates_free(spa_t *spa);
11145818ee1SMatthew Ahrens extern spa_feature_t zio_checksum_to_feature(enum zio_checksum cksum);
112fa9e4066Sahrens 
113fa9e4066Sahrens #ifdef	__cplusplus
114fa9e4066Sahrens }
115fa9e4066Sahrens #endif
116fa9e4066Sahrens 
117fa9e4066Sahrens #endif	/* _SYS_ZIO_CHECKSUM_H */
118