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 /*
63 * Always use logical birth time for birth time comparisons. This is useful
64 * for operations that care about user data changes rather than physical
65 * block rewrites (e.g., incremental replication).
66 */
67 #define TRAVERSE_LOGICAL (1<<6)
68
69 /* Special traverse error return value to indicate skipping of children */
70 #define TRAVERSE_VISIT_NO_CHILDREN -1
71
72 int traverse_dataset(struct dsl_dataset *ds,
73 uint64_t txg_start, int flags, blkptr_cb_t func, void *arg);
74 int traverse_dataset_resume(struct dsl_dataset *ds, uint64_t txg_start,
75 zbookmark_phys_t *resume, int flags, blkptr_cb_t func, void *arg);
76 int traverse_dataset_destroyed(spa_t *spa, blkptr_t *blkptr,
77 uint64_t txg_start, zbookmark_phys_t *resume, int flags,
78 blkptr_cb_t func, void *arg);
79 int traverse_pool(spa_t *spa,
80 uint64_t txg_start, int flags, blkptr_cb_t func, void *arg);
81
82 /*
83 * Note that this calculation cannot overflow with the current maximum indirect
84 * block size (128k). If that maximum is increased to 1M, however, this
85 * calculation can overflow, and handling would need to be added to ensure
86 * continued correctness.
87 */
88 static inline uint64_t
bp_span_in_blocks(uint8_t indblkshift,uint64_t level)89 bp_span_in_blocks(uint8_t indblkshift, uint64_t level)
90 {
91 unsigned int shift = level * (indblkshift - SPA_BLKPTRSHIFT);
92 ASSERT3U(shift, <, 64);
93 return (1ULL << shift);
94 }
95
96 #ifdef __cplusplus
97 }
98 #endif
99
100 #endif /* _SYS_DMU_TRAVERSE_H */
101