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.
8 * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
9 * or https://opensource.org/licenses/CDDL-1.0.
10 * See the License for the specific language governing permissions
11 * and limitations under the License.
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]
22 * Copyright (c) 2009, 2010, Oracle and/or its affiliates. All rights reserved.
23 * Copyright (c) 2016 by Delphix. All rights reserved.
29 #include <sys/sysmacros.h>
30 #include <sys/types.h>
31 #include <sys/fs/zfs.h>
42 * On-disk DDT formats, in the desired search order (newest version first).
49 _Static_assert(DDT_TYPES
<= UINT8_MAX
,
50 "ddt_type_t must fit in a uint8_t");
52 /* New and updated entries recieve this type, see ddt_sync_entry() */
53 #define DDT_TYPE_DEFAULT (DDT_TYPE_ZAP)
56 * DDT classes, in the desired search order (highest replication level first).
65 _Static_assert(DDT_CLASSES
< UINT8_MAX
,
66 "ddt_class_t must fit in a uint8_t");
69 * On-disk ddt entry: key (name) and physical storage (value).
72 zio_cksum_t ddk_cksum
; /* 256-bit block checksum */
74 * Encoded with logical & physical size, encryption, and compression,
76 * +-------+-------+-------+-------+-------+-------+-------+-------+
77 * | 0 | 0 | 0 |X| comp| PSIZE | LSIZE |
78 * +-------+-------+-------+-------+-------+-------+-------+-------+
83 #define DDK_GET_LSIZE(ddk) \
84 BF64_GET_SB((ddk)->ddk_prop, 0, 16, SPA_MINBLOCKSHIFT, 1)
85 #define DDK_SET_LSIZE(ddk, x) \
86 BF64_SET_SB((ddk)->ddk_prop, 0, 16, SPA_MINBLOCKSHIFT, 1, x)
88 #define DDK_GET_PSIZE(ddk) \
89 BF64_GET_SB((ddk)->ddk_prop, 16, 16, SPA_MINBLOCKSHIFT, 1)
90 #define DDK_SET_PSIZE(ddk, x) \
91 BF64_SET_SB((ddk)->ddk_prop, 16, 16, SPA_MINBLOCKSHIFT, 1, x)
93 #define DDK_GET_COMPRESS(ddk) BF64_GET((ddk)->ddk_prop, 32, 7)
94 #define DDK_SET_COMPRESS(ddk, x) BF64_SET((ddk)->ddk_prop, 32, 7, x)
96 #define DDK_GET_CRYPT(ddk) BF64_GET((ddk)->ddk_prop, 39, 1)
97 #define DDK_SET_CRYPT(ddk, x) BF64_SET((ddk)->ddk_prop, 39, 1, x)
100 dva_t ddp_dva
[SPA_DVAS_PER_BP
];
102 uint64_t ddp_phys_birth
;
106 * Note, we no longer generate new DDT_PHYS_DITTO-type blocks. However,
107 * we maintain the ability to free existing dedup-ditto blocks.
121 /* State flags for dde_flags */
122 #define DDE_FLAG_LOADED (1 << 0) /* entry ready for use */
125 /* key must be first for ddt_key_compare */
127 ddt_phys_t dde_phys
[DDT_PHYS_TYPES
];
128 zio_t
*dde_lead_zio
[DDT_PHYS_TYPES
];
129 struct abd
*dde_repair_abd
;
131 ddt_class_t dde_class
;
143 avl_tree_t ddt_repair_tree
;
144 enum zio_checksum ddt_checksum
;
147 uint64_t ddt_stat_object
;
148 uint64_t ddt_object
[DDT_TYPES
][DDT_CLASSES
];
149 ddt_histogram_t ddt_histogram
[DDT_TYPES
][DDT_CLASSES
];
150 ddt_histogram_t ddt_histogram_cache
[DDT_TYPES
][DDT_CLASSES
];
151 ddt_object_t ddt_object_stats
[DDT_TYPES
][DDT_CLASSES
];
155 * In-core and on-disk bookmark for DDT walks
160 uint64_t ddb_checksum
;
164 extern void ddt_bp_fill(const ddt_phys_t
*ddp
, blkptr_t
*bp
,
166 extern void ddt_bp_create(enum zio_checksum checksum
, const ddt_key_t
*ddk
,
167 const ddt_phys_t
*ddp
, blkptr_t
*bp
);
169 extern void ddt_phys_fill(ddt_phys_t
*ddp
, const blkptr_t
*bp
);
170 extern void ddt_phys_clear(ddt_phys_t
*ddp
);
171 extern void ddt_phys_addref(ddt_phys_t
*ddp
);
172 extern void ddt_phys_decref(ddt_phys_t
*ddp
);
173 extern ddt_phys_t
*ddt_phys_select(const ddt_entry_t
*dde
, const blkptr_t
*bp
);
175 extern void ddt_histogram_add(ddt_histogram_t
*dst
, const ddt_histogram_t
*src
);
176 extern void ddt_histogram_stat(ddt_stat_t
*dds
, const ddt_histogram_t
*ddh
);
177 extern boolean_t
ddt_histogram_empty(const ddt_histogram_t
*ddh
);
178 extern void ddt_get_dedup_object_stats(spa_t
*spa
, ddt_object_t
*ddo
);
179 extern void ddt_get_dedup_histogram(spa_t
*spa
, ddt_histogram_t
*ddh
);
180 extern void ddt_get_dedup_stats(spa_t
*spa
, ddt_stat_t
*dds_total
);
182 extern uint64_t ddt_get_dedup_dspace(spa_t
*spa
);
183 extern uint64_t ddt_get_pool_dedup_ratio(spa_t
*spa
);
185 extern ddt_t
*ddt_select(spa_t
*spa
, const blkptr_t
*bp
);
186 extern void ddt_enter(ddt_t
*ddt
);
187 extern void ddt_exit(ddt_t
*ddt
);
188 extern void ddt_init(void);
189 extern void ddt_fini(void);
190 extern ddt_entry_t
*ddt_lookup(ddt_t
*ddt
, const blkptr_t
*bp
, boolean_t add
);
191 extern void ddt_prefetch(spa_t
*spa
, const blkptr_t
*bp
);
192 extern void ddt_remove(ddt_t
*ddt
, ddt_entry_t
*dde
);
194 extern boolean_t
ddt_class_contains(spa_t
*spa
, ddt_class_t max_class
,
197 extern ddt_entry_t
*ddt_repair_start(ddt_t
*ddt
, const blkptr_t
*bp
);
198 extern void ddt_repair_done(ddt_t
*ddt
, ddt_entry_t
*dde
);
200 extern int ddt_key_compare(const void *x1
, const void *x2
);
202 extern void ddt_create(spa_t
*spa
);
203 extern int ddt_load(spa_t
*spa
);
204 extern void ddt_unload(spa_t
*spa
);
205 extern void ddt_sync(spa_t
*spa
, uint64_t txg
);
206 extern int ddt_walk(spa_t
*spa
, ddt_bookmark_t
*ddb
, ddt_entry_t
*dde
);
208 extern boolean_t
ddt_addref(spa_t
*spa
, const blkptr_t
*bp
);
214 #endif /* _SYS_DDT_H */