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 https://opensource.org/licenses/CDDL-1.0.
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.
23  * Copyright (c) 2016 by Delphix. All rights reserved.
24  * Copyright (c) 2023, Klara Inc.
25  */
26 
27 #ifndef _SYS_DDT_IMPL_H
28 #define	_SYS_DDT_IMPL_H
29 
30 #include <sys/ddt.h>
31 
32 #ifdef	__cplusplus
33 extern "C" {
34 #endif
35 
36 /*
37  * Ops vector to access a specific DDT object type.
38  */
39 typedef struct {
40 	char ddt_op_name[32];
41 	int (*ddt_op_create)(objset_t *os, uint64_t *object, dmu_tx_t *tx,
42 	    boolean_t prehash);
43 	int (*ddt_op_destroy)(objset_t *os, uint64_t object, dmu_tx_t *tx);
44 	int (*ddt_op_lookup)(objset_t *os, uint64_t object,
45 	    const ddt_key_t *ddk, ddt_phys_t *phys, size_t psize);
46 	int (*ddt_op_contains)(objset_t *os, uint64_t object,
47 	    const ddt_key_t *ddk);
48 	void (*ddt_op_prefetch)(objset_t *os, uint64_t object,
49 	    const ddt_key_t *ddk);
50 	int (*ddt_op_update)(objset_t *os, uint64_t object,
51 	    const ddt_key_t *ddk, const ddt_phys_t *phys, size_t psize,
52 	    dmu_tx_t *tx);
53 	int (*ddt_op_remove)(objset_t *os, uint64_t object,
54 	    const ddt_key_t *ddk, dmu_tx_t *tx);
55 	int (*ddt_op_walk)(objset_t *os, uint64_t object, uint64_t *walk,
56 	    ddt_key_t *ddk, ddt_phys_t *phys, size_t psize);
57 	int (*ddt_op_count)(objset_t *os, uint64_t object, uint64_t *count);
58 } ddt_ops_t;
59 
60 extern const ddt_ops_t ddt_zap_ops;
61 
62 extern void ddt_stat_update(ddt_t *ddt, ddt_entry_t *dde, uint64_t neg);
63 
64 /*
65  * These are only exposed so that zdb can access them. Try not to use them
66  * outside of the DDT implementation proper, and if you do, consider moving
67  * them up.
68  */
69 
70 /*
71  * Enough room to expand DMU_POOL_DDT format for all possible DDT
72  * checksum/class/type combinations.
73  */
74 #define	DDT_NAMELEN	32
75 
76 extern uint64_t ddt_phys_total_refcnt(const ddt_entry_t *dde);
77 
78 extern void ddt_key_fill(ddt_key_t *ddk, const blkptr_t *bp);
79 
80 extern void ddt_stat_add(ddt_stat_t *dst, const ddt_stat_t *src, uint64_t neg);
81 
82 extern void ddt_object_name(ddt_t *ddt, ddt_type_t type, ddt_class_t clazz,
83     char *name);
84 extern int ddt_object_walk(ddt_t *ddt, ddt_type_t type, ddt_class_t clazz,
85     uint64_t *walk, ddt_entry_t *dde);
86 extern int ddt_object_count(ddt_t *ddt, ddt_type_t type, ddt_class_t clazz,
87     uint64_t *count);
88 extern int ddt_object_info(ddt_t *ddt, ddt_type_t type, ddt_class_t clazz,
89     dmu_object_info_t *);
90 
91 #ifdef	__cplusplus
92 }
93 #endif
94 
95 #endif	/* _SYS_DDT_H */
96