xref: /illumos-gate/usr/src/uts/common/fs/zfs/sys/dsl_scan.h (revision 5cabbc6b49070407fb9610cfe73d4c0e0dea3e77)
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.
23*5cabbc6bSPrashanth Sreenivasa  * Copyright (c) 2012, 2017 by Delphix. All rights reserved.
241702cce7SAlek Pinchuk  * Copyright (c) 2017 Datto Inc.
253f9d6ad7SLin Ling  */
263f9d6ad7SLin Ling 
273f9d6ad7SLin Ling #ifndef	_SYS_DSL_SCAN_H
283f9d6ad7SLin Ling #define	_SYS_DSL_SCAN_H
293f9d6ad7SLin Ling 
303f9d6ad7SLin Ling #include <sys/zfs_context.h>
313f9d6ad7SLin Ling #include <sys/zio.h>
323f9d6ad7SLin Ling #include <sys/ddt.h>
333f9d6ad7SLin Ling #include <sys/bplist.h>
343f9d6ad7SLin Ling 
353f9d6ad7SLin Ling #ifdef	__cplusplus
363f9d6ad7SLin Ling extern "C" {
373f9d6ad7SLin Ling #endif
383f9d6ad7SLin Ling 
393f9d6ad7SLin Ling struct objset;
403f9d6ad7SLin Ling struct dsl_dir;
413f9d6ad7SLin Ling struct dsl_dataset;
423f9d6ad7SLin Ling struct dsl_pool;
433f9d6ad7SLin Ling struct dmu_tx;
443f9d6ad7SLin Ling 
453f9d6ad7SLin Ling /*
463f9d6ad7SLin Ling  * All members of this structure must be uint64_t, for byteswap
473f9d6ad7SLin Ling  * purposes.
483f9d6ad7SLin Ling  */
493f9d6ad7SLin Ling typedef struct dsl_scan_phys {
503f9d6ad7SLin Ling 	uint64_t scn_func; /* pool_scan_func_t */
513f9d6ad7SLin Ling 	uint64_t scn_state; /* dsl_scan_state_t */
523f9d6ad7SLin Ling 	uint64_t scn_queue_obj;
533f9d6ad7SLin Ling 	uint64_t scn_min_txg;
543f9d6ad7SLin Ling 	uint64_t scn_max_txg;
553f9d6ad7SLin Ling 	uint64_t scn_cur_min_txg;
563f9d6ad7SLin Ling 	uint64_t scn_cur_max_txg;
573f9d6ad7SLin Ling 	uint64_t scn_start_time;
583f9d6ad7SLin Ling 	uint64_t scn_end_time;
593f9d6ad7SLin Ling 	uint64_t scn_to_examine; /* total bytes to be scanned */
603f9d6ad7SLin Ling 	uint64_t scn_examined; /* bytes scanned so far */
613f9d6ad7SLin Ling 	uint64_t scn_to_process;
623f9d6ad7SLin Ling 	uint64_t scn_processed;
633f9d6ad7SLin Ling 	uint64_t scn_errors;	/* scan I/O error count */
643f9d6ad7SLin Ling 	uint64_t scn_ddt_class_max;
653f9d6ad7SLin Ling 	ddt_bookmark_t scn_ddt_bookmark;
667802d7bfSMatthew Ahrens 	zbookmark_phys_t scn_bookmark;
673f9d6ad7SLin Ling 	uint64_t scn_flags; /* dsl_scan_flags_t */
683f9d6ad7SLin Ling } dsl_scan_phys_t;
693f9d6ad7SLin Ling 
703f9d6ad7SLin Ling #define	SCAN_PHYS_NUMINTS (sizeof (dsl_scan_phys_t) / sizeof (uint64_t))
713f9d6ad7SLin Ling 
723f9d6ad7SLin Ling typedef enum dsl_scan_flags {
733f9d6ad7SLin Ling 	DSF_VISIT_DS_AGAIN = 1<<0,
741702cce7SAlek Pinchuk 	DSF_SCRUB_PAUSED = 1<<1,
753f9d6ad7SLin Ling } dsl_scan_flags_t;
763f9d6ad7SLin Ling 
77b4952e17SGeorge Wilson /*
78b4952e17SGeorge Wilson  * Every pool will have one dsl_scan_t and this structure will contain
79b4952e17SGeorge Wilson  * in-memory information about the scan and a pointer to the on-disk
80b4952e17SGeorge Wilson  * representation (i.e. dsl_scan_phys_t). Most of the state of the scan
81b4952e17SGeorge Wilson  * is contained on-disk to allow the scan to resume in the event of a reboot
82b4952e17SGeorge Wilson  * or panic. This structure maintains information about the behavior of a
83b4952e17SGeorge Wilson  * running scan, some caching information, and how it should traverse the pool.
84b4952e17SGeorge Wilson  *
85b4952e17SGeorge Wilson  * The following members of this structure direct the behavior of the scan:
86b4952e17SGeorge Wilson  *
871702cce7SAlek Pinchuk  * scn_suspending -	a scan that cannot be completed in a single txg or
881702cce7SAlek Pinchuk  *			has exceeded its allotted time will need to suspend.
89b4952e17SGeorge Wilson  *			When this flag is set the scanner will stop traversing
90b4952e17SGeorge Wilson  *			the pool and write out the current state to disk.
91b4952e17SGeorge Wilson  *
92b4952e17SGeorge Wilson  * scn_restart_txg -	directs the scanner to either restart or start a
93b4952e17SGeorge Wilson  *			a scan at the specified txg value.
94b4952e17SGeorge Wilson  *
95b4952e17SGeorge Wilson  * scn_done_txg -	when a scan completes its traversal it will set
96b4952e17SGeorge Wilson  *			the completion txg to the next txg. This is necessary
97b4952e17SGeorge Wilson  *			to ensure that any blocks that were freed during
98b4952e17SGeorge Wilson  *			the scan but have not yet been processed (i.e deferred
99b4952e17SGeorge Wilson  *			frees) are accounted for.
100b4952e17SGeorge Wilson  *
101b4952e17SGeorge Wilson  * This structure also maintains information about deferred frees which are
102b4952e17SGeorge Wilson  * a special kind of traversal. Deferred free can exist in either a bptree or
103b4952e17SGeorge Wilson  * a bpobj structure. The scn_is_bptree flag will indicate the type of
104b4952e17SGeorge Wilson  * deferred free that is in progress. If the deferred free is part of an
105b4952e17SGeorge Wilson  * asynchronous destroy then the scn_async_destroying flag will be set.
106b4952e17SGeorge Wilson  */
1073f9d6ad7SLin Ling typedef struct dsl_scan {
1083f9d6ad7SLin Ling 	struct dsl_pool *scn_dp;
1093f9d6ad7SLin Ling 
1101702cce7SAlek Pinchuk 	boolean_t scn_suspending;
1113f9d6ad7SLin Ling 	uint64_t scn_restart_txg;
112b4952e17SGeorge Wilson 	uint64_t scn_done_txg;
1133f9d6ad7SLin Ling 	uint64_t scn_sync_start_time;
114cde58dbcSMatthew Ahrens 	zio_t *scn_zio_root;
1153f9d6ad7SLin Ling 
116ad135b5dSChristopher Siden 	/* for freeing blocks */
117ad135b5dSChristopher Siden 	boolean_t scn_is_bptree;
1184a923759SGeorge Wilson 	boolean_t scn_async_destroying;
1197fd05ac4SMatthew Ahrens 	boolean_t scn_async_stalled;
120*5cabbc6bSPrashanth Sreenivasa 	uint64_t  scn_async_block_min_time_ms;
121*5cabbc6bSPrashanth Sreenivasa 
122*5cabbc6bSPrashanth Sreenivasa 	/* for debugging / information */
1233f9d6ad7SLin Ling 	uint64_t scn_visited_this_txg;
1243f9d6ad7SLin Ling 
1253f9d6ad7SLin Ling 	dsl_scan_phys_t scn_phys;
1263f9d6ad7SLin Ling } dsl_scan_t;
1273f9d6ad7SLin Ling 
1283f9d6ad7SLin Ling int dsl_scan_init(struct dsl_pool *dp, uint64_t txg);
1293f9d6ad7SLin Ling void dsl_scan_fini(struct dsl_pool *dp);
1303f9d6ad7SLin Ling void dsl_scan_sync(struct dsl_pool *, dmu_tx_t *);
1313f9d6ad7SLin Ling int dsl_scan_cancel(struct dsl_pool *);
1323f9d6ad7SLin Ling int dsl_scan(struct dsl_pool *, pool_scan_func_t);
1331702cce7SAlek Pinchuk boolean_t dsl_scan_scrubbing(const struct dsl_pool *dp);
1341702cce7SAlek Pinchuk int dsl_scrub_set_pause_resume(const struct dsl_pool *dp, pool_scrub_cmd_t cmd);
1353f9d6ad7SLin Ling void dsl_resilver_restart(struct dsl_pool *, uint64_t txg);
1363f9d6ad7SLin Ling boolean_t dsl_scan_resilvering(struct dsl_pool *dp);
1373f9d6ad7SLin Ling boolean_t dsl_dataset_unstable(struct dsl_dataset *ds);
1383f9d6ad7SLin Ling void dsl_scan_ddt_entry(dsl_scan_t *scn, enum zio_checksum checksum,
1393f9d6ad7SLin Ling     ddt_entry_t *dde, dmu_tx_t *tx);
1403f9d6ad7SLin Ling void dsl_scan_ds_destroyed(struct dsl_dataset *ds, struct dmu_tx *tx);
1413f9d6ad7SLin Ling void dsl_scan_ds_snapshotted(struct dsl_dataset *ds, struct dmu_tx *tx);
1423f9d6ad7SLin Ling void dsl_scan_ds_clone_swapped(struct dsl_dataset *ds1, struct dsl_dataset *ds2,
1433f9d6ad7SLin Ling     struct dmu_tx *tx);
144cde58dbcSMatthew Ahrens boolean_t dsl_scan_active(dsl_scan_t *scn);
1451702cce7SAlek Pinchuk boolean_t dsl_scan_is_paused_scrub(const dsl_scan_t *scn);
1463f9d6ad7SLin Ling 
1473f9d6ad7SLin Ling #ifdef	__cplusplus
1483f9d6ad7SLin Ling }
1493f9d6ad7SLin Ling #endif
1503f9d6ad7SLin Ling 
1513f9d6ad7SLin Ling #endif /* _SYS_DSL_SCAN_H */
152