xref: /illumos-gate/usr/src/uts/common/fs/zfs/sys/dsl_scan.h (revision b4952e17e8858d3225793b28788278de9fe6038d)
13f9d6ad7SLin Ling /*
23f9d6ad7SLin Ling  * CDDL HEADER START
33f9d6ad7SLin Ling  *
43f9d6ad7SLin Ling  * The contents of this file are subject to the terms of the
53f9d6ad7SLin Ling  * Common Development and Distribution License (the "License").
63f9d6ad7SLin Ling  * You may not use this file except in compliance with the License.
73f9d6ad7SLin Ling  *
83f9d6ad7SLin Ling  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
93f9d6ad7SLin Ling  * or http://www.opensolaris.org/os/licensing.
103f9d6ad7SLin Ling  * See the License for the specific language governing permissions
113f9d6ad7SLin Ling  * and limitations under the License.
123f9d6ad7SLin Ling  *
133f9d6ad7SLin Ling  * When distributing Covered Code, include this CDDL HEADER in each
143f9d6ad7SLin Ling  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
153f9d6ad7SLin Ling  * If applicable, add the following below this CDDL HEADER, with the
163f9d6ad7SLin Ling  * fields enclosed by brackets "[]" replaced with your own identifying
173f9d6ad7SLin Ling  * information: Portions Copyright [yyyy] [name of copyright owner]
183f9d6ad7SLin Ling  *
193f9d6ad7SLin Ling  * CDDL HEADER END
203f9d6ad7SLin Ling  */
213f9d6ad7SLin Ling /*
223f9d6ad7SLin Ling  * Copyright (c) 2010, Oracle and/or its affiliates. All rights reserved.
234a923759SGeorge Wilson  * Copyright (c) 2013 by Delphix. All rights reserved.
243f9d6ad7SLin Ling  */
253f9d6ad7SLin Ling 
263f9d6ad7SLin Ling #ifndef	_SYS_DSL_SCAN_H
273f9d6ad7SLin Ling #define	_SYS_DSL_SCAN_H
283f9d6ad7SLin Ling 
293f9d6ad7SLin Ling #include <sys/zfs_context.h>
303f9d6ad7SLin Ling #include <sys/zio.h>
313f9d6ad7SLin Ling #include <sys/ddt.h>
323f9d6ad7SLin Ling #include <sys/bplist.h>
333f9d6ad7SLin Ling 
343f9d6ad7SLin Ling #ifdef	__cplusplus
353f9d6ad7SLin Ling extern "C" {
363f9d6ad7SLin Ling #endif
373f9d6ad7SLin Ling 
383f9d6ad7SLin Ling struct objset;
393f9d6ad7SLin Ling struct dsl_dir;
403f9d6ad7SLin Ling struct dsl_dataset;
413f9d6ad7SLin Ling struct dsl_pool;
423f9d6ad7SLin Ling struct dmu_tx;
433f9d6ad7SLin Ling 
443f9d6ad7SLin Ling /*
453f9d6ad7SLin Ling  * All members of this structure must be uint64_t, for byteswap
463f9d6ad7SLin Ling  * purposes.
473f9d6ad7SLin Ling  */
483f9d6ad7SLin Ling typedef struct dsl_scan_phys {
493f9d6ad7SLin Ling 	uint64_t scn_func; /* pool_scan_func_t */
503f9d6ad7SLin Ling 	uint64_t scn_state; /* dsl_scan_state_t */
513f9d6ad7SLin Ling 	uint64_t scn_queue_obj;
523f9d6ad7SLin Ling 	uint64_t scn_min_txg;
533f9d6ad7SLin Ling 	uint64_t scn_max_txg;
543f9d6ad7SLin Ling 	uint64_t scn_cur_min_txg;
553f9d6ad7SLin Ling 	uint64_t scn_cur_max_txg;
563f9d6ad7SLin Ling 	uint64_t scn_start_time;
573f9d6ad7SLin Ling 	uint64_t scn_end_time;
583f9d6ad7SLin Ling 	uint64_t scn_to_examine; /* total bytes to be scanned */
593f9d6ad7SLin Ling 	uint64_t scn_examined; /* bytes scanned so far */
603f9d6ad7SLin Ling 	uint64_t scn_to_process;
613f9d6ad7SLin Ling 	uint64_t scn_processed;
623f9d6ad7SLin Ling 	uint64_t scn_errors;	/* scan I/O error count */
633f9d6ad7SLin Ling 	uint64_t scn_ddt_class_max;
643f9d6ad7SLin Ling 	ddt_bookmark_t scn_ddt_bookmark;
653f9d6ad7SLin Ling 	zbookmark_t scn_bookmark;
663f9d6ad7SLin Ling 	uint64_t scn_flags; /* dsl_scan_flags_t */
673f9d6ad7SLin Ling } dsl_scan_phys_t;
683f9d6ad7SLin Ling 
693f9d6ad7SLin Ling #define	SCAN_PHYS_NUMINTS (sizeof (dsl_scan_phys_t) / sizeof (uint64_t))
703f9d6ad7SLin Ling 
713f9d6ad7SLin Ling typedef enum dsl_scan_flags {
723f9d6ad7SLin Ling 	DSF_VISIT_DS_AGAIN = 1<<0,
733f9d6ad7SLin Ling } dsl_scan_flags_t;
743f9d6ad7SLin Ling 
75*b4952e17SGeorge Wilson /*
76*b4952e17SGeorge Wilson  * Every pool will have one dsl_scan_t and this structure will contain
77*b4952e17SGeorge Wilson  * in-memory information about the scan and a pointer to the on-disk
78*b4952e17SGeorge Wilson  * representation (i.e. dsl_scan_phys_t). Most of the state of the scan
79*b4952e17SGeorge Wilson  * is contained on-disk to allow the scan to resume in the event of a reboot
80*b4952e17SGeorge Wilson  * or panic. This structure maintains information about the behavior of a
81*b4952e17SGeorge Wilson  * running scan, some caching information, and how it should traverse the pool.
82*b4952e17SGeorge Wilson  *
83*b4952e17SGeorge Wilson  * The following members of this structure direct the behavior of the scan:
84*b4952e17SGeorge Wilson  *
85*b4952e17SGeorge Wilson  * scn_pausing -	a scan that cannot be completed in a single txg or
86*b4952e17SGeorge Wilson  *			has exceeded its allotted time will need to pause.
87*b4952e17SGeorge Wilson  *			When this flag is set the scanner will stop traversing
88*b4952e17SGeorge Wilson  *			the pool and write out the current state to disk.
89*b4952e17SGeorge Wilson  *
90*b4952e17SGeorge Wilson  * scn_restart_txg -	directs the scanner to either restart or start a
91*b4952e17SGeorge Wilson  *			a scan at the specified txg value.
92*b4952e17SGeorge Wilson  *
93*b4952e17SGeorge Wilson  * scn_done_txg -	when a scan completes its traversal it will set
94*b4952e17SGeorge Wilson  *			the completion txg to the next txg. This is necessary
95*b4952e17SGeorge Wilson  *			to ensure that any blocks that were freed during
96*b4952e17SGeorge Wilson  *			the scan but have not yet been processed (i.e deferred
97*b4952e17SGeorge Wilson  *			frees) are accounted for.
98*b4952e17SGeorge Wilson  *
99*b4952e17SGeorge Wilson  * This structure also maintains information about deferred frees which are
100*b4952e17SGeorge Wilson  * a special kind of traversal. Deferred free can exist in either a bptree or
101*b4952e17SGeorge Wilson  * a bpobj structure. The scn_is_bptree flag will indicate the type of
102*b4952e17SGeorge Wilson  * deferred free that is in progress. If the deferred free is part of an
103*b4952e17SGeorge Wilson  * asynchronous destroy then the scn_async_destroying flag will be set.
104*b4952e17SGeorge Wilson  */
1053f9d6ad7SLin Ling typedef struct dsl_scan {
1063f9d6ad7SLin Ling 	struct dsl_pool *scn_dp;
1073f9d6ad7SLin Ling 
1083f9d6ad7SLin Ling 	boolean_t scn_pausing;
1093f9d6ad7SLin Ling 	uint64_t scn_restart_txg;
110*b4952e17SGeorge Wilson 	uint64_t scn_done_txg;
1113f9d6ad7SLin Ling 	uint64_t scn_sync_start_time;
112cde58dbcSMatthew Ahrens 	zio_t *scn_zio_root;
1133f9d6ad7SLin Ling 
114ad135b5dSChristopher Siden 	/* for freeing blocks */
115ad135b5dSChristopher Siden 	boolean_t scn_is_bptree;
1164a923759SGeorge Wilson 	boolean_t scn_async_destroying;
117ad135b5dSChristopher Siden 
1183f9d6ad7SLin Ling 	/* for debugging / information */
1193f9d6ad7SLin Ling 	uint64_t scn_visited_this_txg;
1203f9d6ad7SLin Ling 
1213f9d6ad7SLin Ling 	dsl_scan_phys_t scn_phys;
1223f9d6ad7SLin Ling } dsl_scan_t;
1233f9d6ad7SLin Ling 
1243f9d6ad7SLin Ling int dsl_scan_init(struct dsl_pool *dp, uint64_t txg);
1253f9d6ad7SLin Ling void dsl_scan_fini(struct dsl_pool *dp);
1263f9d6ad7SLin Ling void dsl_scan_sync(struct dsl_pool *, dmu_tx_t *);
1273f9d6ad7SLin Ling int dsl_scan_cancel(struct dsl_pool *);
1283f9d6ad7SLin Ling int dsl_scan(struct dsl_pool *, pool_scan_func_t);
1293f9d6ad7SLin Ling void dsl_resilver_restart(struct dsl_pool *, uint64_t txg);
1303f9d6ad7SLin Ling boolean_t dsl_scan_resilvering(struct dsl_pool *dp);
1313f9d6ad7SLin Ling boolean_t dsl_dataset_unstable(struct dsl_dataset *ds);
1323f9d6ad7SLin Ling void dsl_scan_ddt_entry(dsl_scan_t *scn, enum zio_checksum checksum,
1333f9d6ad7SLin Ling     ddt_entry_t *dde, dmu_tx_t *tx);
1343f9d6ad7SLin Ling void dsl_scan_ds_destroyed(struct dsl_dataset *ds, struct dmu_tx *tx);
1353f9d6ad7SLin Ling void dsl_scan_ds_snapshotted(struct dsl_dataset *ds, struct dmu_tx *tx);
1363f9d6ad7SLin Ling void dsl_scan_ds_clone_swapped(struct dsl_dataset *ds1, struct dsl_dataset *ds2,
1373f9d6ad7SLin Ling     struct dmu_tx *tx);
138cde58dbcSMatthew Ahrens boolean_t dsl_scan_active(dsl_scan_t *scn);
1393f9d6ad7SLin Ling 
1403f9d6ad7SLin Ling #ifdef	__cplusplus
1413f9d6ad7SLin Ling }
1423f9d6ad7SLin Ling #endif
1433f9d6ad7SLin Ling 
1443f9d6ad7SLin Ling #endif /* _SYS_DSL_SCAN_H */
145