]>
Commit | Line | Data |
---|---|---|
428870ff 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 | |
1d3ba0bf | 9 | * or https://opensource.org/licenses/CDDL-1.0. |
428870ff BB |
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 | /* | |
22 | * Copyright (c) 2009, 2010, Oracle and/or its affiliates. All rights reserved. | |
a6255b7f | 23 | * Copyright (c) 2016 by Delphix. All rights reserved. |
428870ff BB |
24 | */ |
25 | ||
26 | #ifndef _SYS_DDT_H | |
27 | #define _SYS_DDT_H | |
28 | ||
29 | #include <sys/sysmacros.h> | |
30 | #include <sys/types.h> | |
31 | #include <sys/fs/zfs.h> | |
32 | #include <sys/zio.h> | |
33 | #include <sys/dmu.h> | |
34 | ||
35 | #ifdef __cplusplus | |
36 | extern "C" { | |
37 | #endif | |
38 | ||
a6255b7f DQ |
39 | struct abd; |
40 | ||
428870ff BB |
41 | /* |
42 | * On-disk DDT formats, in the desired search order (newest version first). | |
43 | */ | |
c8f694fe | 44 | typedef enum { |
428870ff BB |
45 | DDT_TYPE_ZAP = 0, |
46 | DDT_TYPES | |
c8f694fe RN |
47 | } ddt_type_t; |
48 | ||
49 | _Static_assert(DDT_TYPES <= UINT8_MAX, | |
50 | "ddt_type_t must fit in a uint8_t"); | |
51 | ||
52 | /* New and updated entries recieve this type, see ddt_sync_entry() */ | |
53 | #define DDT_TYPE_DEFAULT (DDT_TYPE_ZAP) | |
428870ff BB |
54 | |
55 | /* | |
56 | * DDT classes, in the desired search order (highest replication level first). | |
57 | */ | |
c8f694fe | 58 | typedef enum { |
428870ff BB |
59 | DDT_CLASS_DITTO = 0, |
60 | DDT_CLASS_DUPLICATE, | |
61 | DDT_CLASS_UNIQUE, | |
62 | DDT_CLASSES | |
c8f694fe | 63 | } ddt_class_t; |
428870ff | 64 | |
c8f694fe RN |
65 | _Static_assert(DDT_CLASSES < UINT8_MAX, |
66 | "ddt_class_t must fit in a uint8_t"); | |
428870ff | 67 | |
428870ff BB |
68 | /* |
69 | * On-disk ddt entry: key (name) and physical storage (value). | |
70 | */ | |
71 | typedef struct ddt_key { | |
72 | zio_cksum_t ddk_cksum; /* 256-bit block checksum */ | |
d3cc8b15 | 73 | /* |
b5256303 TC |
74 | * Encoded with logical & physical size, encryption, and compression, |
75 | * as follows: | |
d3cc8b15 | 76 | * +-------+-------+-------+-------+-------+-------+-------+-------+ |
b5256303 | 77 | * | 0 | 0 | 0 |X| comp| PSIZE | LSIZE | |
d3cc8b15 WA |
78 | * +-------+-------+-------+-------+-------+-------+-------+-------+ |
79 | */ | |
80 | uint64_t ddk_prop; | |
428870ff BB |
81 | } ddt_key_t; |
82 | ||
428870ff BB |
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) | |
87 | ||
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) | |
92 | ||
b5256303 TC |
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) | |
95 | ||
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) | |
428870ff | 98 | |
428870ff BB |
99 | typedef struct ddt_phys { |
100 | dva_t ddp_dva[SPA_DVAS_PER_BP]; | |
101 | uint64_t ddp_refcnt; | |
102 | uint64_t ddp_phys_birth; | |
103 | } ddt_phys_t; | |
104 | ||
050d720c MA |
105 | /* |
106 | * Note, we no longer generate new DDT_PHYS_DITTO-type blocks. However, | |
107 | * we maintain the ability to free existing dedup-ditto blocks. | |
108 | */ | |
428870ff BB |
109 | enum ddt_phys_type { |
110 | DDT_PHYS_DITTO = 0, | |
111 | DDT_PHYS_SINGLE = 1, | |
112 | DDT_PHYS_DOUBLE = 2, | |
113 | DDT_PHYS_TRIPLE = 3, | |
114 | DDT_PHYS_TYPES | |
115 | }; | |
116 | ||
117 | /* | |
118 | * In-core ddt entry | |
119 | */ | |
120 | struct ddt_entry { | |
0cb1ef60 | 121 | /* key must be first for ddt_key_compare */ |
428870ff BB |
122 | ddt_key_t dde_key; |
123 | ddt_phys_t dde_phys[DDT_PHYS_TYPES]; | |
124 | zio_t *dde_lead_zio[DDT_PHYS_TYPES]; | |
a6255b7f | 125 | struct abd *dde_repair_abd; |
c8f694fe RN |
126 | ddt_type_t dde_type; |
127 | ddt_class_t dde_class; | |
428870ff BB |
128 | uint8_t dde_loading; |
129 | uint8_t dde_loaded; | |
130 | kcondvar_t dde_cv; | |
131 | avl_node_t dde_node; | |
132 | }; | |
133 | ||
134 | /* | |
135 | * In-core ddt | |
136 | */ | |
137 | struct ddt { | |
138 | kmutex_t ddt_lock; | |
139 | avl_tree_t ddt_tree; | |
140 | avl_tree_t ddt_repair_tree; | |
141 | enum zio_checksum ddt_checksum; | |
142 | spa_t *ddt_spa; | |
143 | objset_t *ddt_os; | |
144 | uint64_t ddt_stat_object; | |
145 | uint64_t ddt_object[DDT_TYPES][DDT_CLASSES]; | |
146 | ddt_histogram_t ddt_histogram[DDT_TYPES][DDT_CLASSES]; | |
147 | ddt_histogram_t ddt_histogram_cache[DDT_TYPES][DDT_CLASSES]; | |
148 | ddt_object_t ddt_object_stats[DDT_TYPES][DDT_CLASSES]; | |
149 | avl_node_t ddt_node; | |
150 | }; | |
151 | ||
152 | /* | |
153 | * In-core and on-disk bookmark for DDT walks | |
154 | */ | |
155 | typedef struct ddt_bookmark { | |
156 | uint64_t ddb_class; | |
157 | uint64_t ddb_type; | |
158 | uint64_t ddb_checksum; | |
159 | uint64_t ddb_cursor; | |
160 | } ddt_bookmark_t; | |
161 | ||
428870ff BB |
162 | extern void ddt_bp_fill(const ddt_phys_t *ddp, blkptr_t *bp, |
163 | uint64_t txg); | |
164 | extern void ddt_bp_create(enum zio_checksum checksum, const ddt_key_t *ddk, | |
165 | const ddt_phys_t *ddp, blkptr_t *bp); | |
166 | ||
428870ff BB |
167 | extern void ddt_phys_fill(ddt_phys_t *ddp, const blkptr_t *bp); |
168 | extern void ddt_phys_clear(ddt_phys_t *ddp); | |
169 | extern void ddt_phys_addref(ddt_phys_t *ddp); | |
170 | extern void ddt_phys_decref(ddt_phys_t *ddp); | |
428870ff | 171 | extern ddt_phys_t *ddt_phys_select(const ddt_entry_t *dde, const blkptr_t *bp); |
428870ff BB |
172 | |
173 | extern void ddt_histogram_add(ddt_histogram_t *dst, const ddt_histogram_t *src); | |
174 | extern void ddt_histogram_stat(ddt_stat_t *dds, const ddt_histogram_t *ddh); | |
175 | extern boolean_t ddt_histogram_empty(const ddt_histogram_t *ddh); | |
176 | extern void ddt_get_dedup_object_stats(spa_t *spa, ddt_object_t *ddo); | |
177 | extern void ddt_get_dedup_histogram(spa_t *spa, ddt_histogram_t *ddh); | |
178 | extern void ddt_get_dedup_stats(spa_t *spa, ddt_stat_t *dds_total); | |
179 | ||
180 | extern uint64_t ddt_get_dedup_dspace(spa_t *spa); | |
181 | extern uint64_t ddt_get_pool_dedup_ratio(spa_t *spa); | |
182 | ||
428870ff BB |
183 | extern ddt_t *ddt_select(spa_t *spa, const blkptr_t *bp); |
184 | extern void ddt_enter(ddt_t *ddt); | |
185 | extern void ddt_exit(ddt_t *ddt); | |
ecf3d9b8 JL |
186 | extern void ddt_init(void); |
187 | extern void ddt_fini(void); | |
428870ff BB |
188 | extern ddt_entry_t *ddt_lookup(ddt_t *ddt, const blkptr_t *bp, boolean_t add); |
189 | extern void ddt_prefetch(spa_t *spa, const blkptr_t *bp); | |
190 | extern void ddt_remove(ddt_t *ddt, ddt_entry_t *dde); | |
191 | ||
c8f694fe | 192 | extern boolean_t ddt_class_contains(spa_t *spa, ddt_class_t max_class, |
428870ff BB |
193 | const blkptr_t *bp); |
194 | ||
195 | extern ddt_entry_t *ddt_repair_start(ddt_t *ddt, const blkptr_t *bp); | |
196 | extern void ddt_repair_done(ddt_t *ddt, ddt_entry_t *dde); | |
197 | ||
0cb1ef60 | 198 | extern int ddt_key_compare(const void *x1, const void *x2); |
428870ff BB |
199 | |
200 | extern void ddt_create(spa_t *spa); | |
201 | extern int ddt_load(spa_t *spa); | |
202 | extern void ddt_unload(spa_t *spa); | |
203 | extern void ddt_sync(spa_t *spa, uint64_t txg); | |
204 | extern int ddt_walk(spa_t *spa, ddt_bookmark_t *ddb, ddt_entry_t *dde); | |
428870ff | 205 | |
67a1b037 PJD |
206 | extern boolean_t ddt_addref(spa_t *spa, const blkptr_t *bp); |
207 | ||
428870ff BB |
208 | #ifdef __cplusplus |
209 | } | |
210 | #endif | |
211 | ||
212 | #endif /* _SYS_DDT_H */ |