xref: /illumos-gate/usr/src/uts/common/fs/zfs/sys/dmu_traverse.h (revision 43d18f1c320355e93c47399bea0b2e022fe06364)
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, Version 1.0 only
6  * (the "License").  You may not use this file except in compliance
7  * with the License.
8  *
9  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
10  * or http://www.opensolaris.org/os/licensing.
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 2005 Sun Microsystems, Inc.  All rights reserved.
24  * Use is subject to license terms.
25  */
26 
27 #ifndef	_SYS_DMU_TRAVERSE_H
28 #define	_SYS_DMU_TRAVERSE_H
29 
30 #pragma ident	"%Z%%M%	%I%	%E% SMI"
31 
32 #include <sys/zfs_context.h>
33 #include <sys/spa.h>
34 #include <sys/zio.h>
35 #include <sys/dmu.h>
36 #include <sys/dnode.h>
37 #include <sys/arc.h>
38 
39 #ifdef	__cplusplus
40 extern "C" {
41 #endif
42 
43 #define	ADVANCE_POST	0		/* post-order traversal */
44 #define	ADVANCE_PRE	0x01		/* pre-order traversal */
45 #define	ADVANCE_PRUNE	0x02		/* prune by prev snapshot birth time */
46 #define	ADVANCE_DATA	0x04		/* read user data blocks */
47 #define	ADVANCE_HOLES	0x08		/* visit holes */
48 #define	ADVANCE_NOLOCK	0x10		/* Don't grab SPA sync lock */
49 
50 #define	ZB_NO_LEVEL	-2
51 #define	ZB_MAXLEVEL	32		/* Next power of 2 >= DN_MAX_LEVELS */
52 #define	ZB_MAXBLKID	(1ULL << 62)
53 #define	ZB_MAXOBJSET	(1ULL << 62)
54 #define	ZB_MAXOBJECT	(1ULL << 62)
55 
56 #define	ZB_MOS_CACHE	0
57 #define	ZB_MDN_CACHE	1
58 #define	ZB_DN_CACHE	2
59 #define	ZB_DEPTH	3
60 
61 typedef struct zbookmark {
62 	uint64_t	zb_objset;
63 	uint64_t	zb_object;
64 	int		zb_level;
65 	uint64_t	zb_blkid;
66 } zbookmark_t;
67 
68 typedef struct zseg {
69 	uint64_t	seg_mintxg;
70 	uint64_t	seg_maxtxg;
71 	zbookmark_t	seg_start;
72 	zbookmark_t	seg_end;
73 	list_node_t	seg_node;
74 } zseg_t;
75 
76 typedef struct traverse_blk_cache {
77 	zbookmark_t	bc_bookmark;
78 	blkptr_t	bc_blkptr;
79 	void		*bc_data;
80 	dnode_phys_t	*bc_dnode;
81 	int		bc_errno;
82 	int		bc_pad1;
83 	uint64_t	bc_pad2;
84 } traverse_blk_cache_t;
85 
86 typedef int (blkptr_cb_t)(traverse_blk_cache_t *bc, spa_t *spa, void *arg);
87 
88 struct traverse_handle {
89 	spa_t		*th_spa;
90 	blkptr_cb_t	*th_func;
91 	void		*th_arg;
92 	int		th_advance;
93 	int		th_zio_flags;
94 	list_t		th_seglist;
95 	traverse_blk_cache_t th_cache[ZB_DEPTH][ZB_MAXLEVEL];
96 	uint64_t	th_hits;
97 	uint64_t	th_arc_hits;
98 	uint64_t	th_reads;
99 	uint64_t	th_callbacks;
100 	uint64_t	th_syncs;
101 	uint64_t	th_restarts;
102 	zbookmark_t	th_noread;
103 	zbookmark_t	th_lastcb;
104 };
105 
106 int traverse_dsl_dataset(struct dsl_dataset *ds, uint64_t txg_start,
107     int advance, blkptr_cb_t func, void *arg);
108 
109 traverse_handle_t *traverse_init(spa_t *spa, blkptr_cb_t *func, void *arg,
110     int advance, int zio_flags);
111 void traverse_fini(traverse_handle_t *th);
112 
113 void traverse_add_dnode(traverse_handle_t *th,
114     uint64_t mintxg, uint64_t maxtxg, uint64_t objset, uint64_t object);
115 void traverse_add_objset(traverse_handle_t *th,
116     uint64_t mintxg, uint64_t maxtxg, uint64_t objset);
117 void traverse_add_pool(traverse_handle_t *th, uint64_t mintxg, uint64_t maxtxg);
118 
119 int traverse_more(traverse_handle_t *th);
120 
121 #ifdef	__cplusplus
122 }
123 #endif
124 
125 #endif /* _SYS_DMU_TRAVERSE_H */
126