xref: /freebsd/sys/contrib/openzfs/include/sys/dmu_traverse.h (revision 61145dc2b94f12f6a47344fb9aac702321880e43)
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) 2012, 2018 by Delphix. All rights reserved.
25  */
26 
27 #ifndef	_SYS_DMU_TRAVERSE_H
28 #define	_SYS_DMU_TRAVERSE_H
29 
30 #include <sys/zfs_context.h>
31 #include <sys/spa.h>
32 #include <sys/zio.h>
33 
34 #ifdef	__cplusplus
35 extern "C" {
36 #endif
37 
38 struct dnode_phys;
39 struct dsl_dataset;
40 struct zilog;
41 struct arc_buf;
42 
43 typedef int (blkptr_cb_t)(spa_t *spa, zilog_t *zilog, const blkptr_t *bp,
44     const zbookmark_phys_t *zb, const struct dnode_phys *dnp, void *arg);
45 
46 #define	TRAVERSE_PRE			(1<<0)
47 #define	TRAVERSE_POST			(1<<1)
48 #define	TRAVERSE_PREFETCH_METADATA	(1<<2)
49 #define	TRAVERSE_PREFETCH_DATA		(1<<3)
50 #define	TRAVERSE_PREFETCH (TRAVERSE_PREFETCH_METADATA | TRAVERSE_PREFETCH_DATA)
51 #define	TRAVERSE_HARD			(1<<4)
52 
53 /*
54  * Encrypted dnode blocks have encrypted bonus buffers while the rest
55  * of the dnode is left unencrypted. Callers can specify the
56  * TRAVERSE_NO_DECRYPT flag to indicate to the traversal code that
57  * they wish to receive the raw encrypted dnodes instead of attempting
58  * to read the logical data.
59  */
60 #define	TRAVERSE_NO_DECRYPT		(1<<5)
61 
62 /* Special traverse error return value to indicate skipping of children */
63 #define	TRAVERSE_VISIT_NO_CHILDREN	-1
64 
65 int traverse_dataset(struct dsl_dataset *ds,
66     uint64_t txg_start, int flags, blkptr_cb_t func, void *arg);
67 int traverse_dataset_resume(struct dsl_dataset *ds, uint64_t txg_start,
68     zbookmark_phys_t *resume, int flags, blkptr_cb_t func, void *arg);
69 int traverse_dataset_destroyed(spa_t *spa, blkptr_t *blkptr,
70     uint64_t txg_start, zbookmark_phys_t *resume, int flags,
71     blkptr_cb_t func, void *arg);
72 int traverse_pool(spa_t *spa,
73     uint64_t txg_start, int flags, blkptr_cb_t func, void *arg);
74 
75 /*
76  * Note that this calculation cannot overflow with the current maximum indirect
77  * block size (128k).  If that maximum is increased to 1M, however, this
78  * calculation can overflow, and handling would need to be added to ensure
79  * continued correctness.
80  */
81 static inline uint64_t
bp_span_in_blocks(uint8_t indblkshift,uint64_t level)82 bp_span_in_blocks(uint8_t indblkshift, uint64_t level)
83 {
84 	unsigned int shift = level * (indblkshift - SPA_BLKPTRSHIFT);
85 	ASSERT3U(shift, <, 64);
86 	return (1ULL << shift);
87 }
88 
89 #ifdef	__cplusplus
90 }
91 #endif
92 
93 #endif /* _SYS_DMU_TRAVERSE_H */
94