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