xref: /illumos-gate/usr/src/uts/common/fs/zfs/sys/dsl_scan.h (revision a3874b8b1fe5103fc1f961609557c0587435fec0)
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.
235cabbc6bSPrashanth 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 
77*a3874b8bSToomas Soome #define	DSL_SCAN_FLAGS_MASK (DSF_VISIT_DS_AGAIN)
78*a3874b8bSToomas Soome 
79b4952e17SGeorge Wilson /*
80b4952e17SGeorge Wilson  * Every pool will have one dsl_scan_t and this structure will contain
81b4952e17SGeorge Wilson  * in-memory information about the scan and a pointer to the on-disk
82b4952e17SGeorge Wilson  * representation (i.e. dsl_scan_phys_t). Most of the state of the scan
83b4952e17SGeorge Wilson  * is contained on-disk to allow the scan to resume in the event of a reboot
84b4952e17SGeorge Wilson  * or panic. This structure maintains information about the behavior of a
85b4952e17SGeorge Wilson  * running scan, some caching information, and how it should traverse the pool.
86b4952e17SGeorge Wilson  *
87b4952e17SGeorge Wilson  * The following members of this structure direct the behavior of the scan:
88b4952e17SGeorge Wilson  *
891702cce7SAlek Pinchuk  * scn_suspending -	a scan that cannot be completed in a single txg or
901702cce7SAlek Pinchuk  *			has exceeded its allotted time will need to suspend.
91b4952e17SGeorge Wilson  *			When this flag is set the scanner will stop traversing
92b4952e17SGeorge Wilson  *			the pool and write out the current state to disk.
93b4952e17SGeorge Wilson  *
94b4952e17SGeorge Wilson  * scn_restart_txg -	directs the scanner to either restart or start a
95b4952e17SGeorge Wilson  *			a scan at the specified txg value.
96b4952e17SGeorge Wilson  *
97b4952e17SGeorge Wilson  * scn_done_txg -	when a scan completes its traversal it will set
98b4952e17SGeorge Wilson  *			the completion txg to the next txg. This is necessary
99b4952e17SGeorge Wilson  *			to ensure that any blocks that were freed during
100b4952e17SGeorge Wilson  *			the scan but have not yet been processed (i.e deferred
101b4952e17SGeorge Wilson  *			frees) are accounted for.
102b4952e17SGeorge Wilson  *
103b4952e17SGeorge Wilson  * This structure also maintains information about deferred frees which are
104b4952e17SGeorge Wilson  * a special kind of traversal. Deferred free can exist in either a bptree or
105b4952e17SGeorge Wilson  * a bpobj structure. The scn_is_bptree flag will indicate the type of
106b4952e17SGeorge Wilson  * deferred free that is in progress. If the deferred free is part of an
107b4952e17SGeorge Wilson  * asynchronous destroy then the scn_async_destroying flag will be set.
108b4952e17SGeorge Wilson  */
1093f9d6ad7SLin Ling typedef struct dsl_scan {
1103f9d6ad7SLin Ling 	struct dsl_pool *scn_dp;
1113f9d6ad7SLin Ling 	uint64_t scn_restart_txg;
112b4952e17SGeorge Wilson 	uint64_t scn_done_txg;
1133f9d6ad7SLin Ling 	uint64_t scn_sync_start_time;
114*a3874b8bSToomas Soome 	uint64_t scn_issued_before_pass;
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;
1205cabbc6bSPrashanth Sreenivasa 	uint64_t  scn_async_block_min_time_ms;
1215cabbc6bSPrashanth Sreenivasa 
122*a3874b8bSToomas Soome 	/* flags and stats for controlling scan state */
123*a3874b8bSToomas Soome 	boolean_t scn_is_sorted;	/* doing sequential scan */
124*a3874b8bSToomas Soome 	boolean_t scn_clearing;		/* scan is issuing sequential extents */
125*a3874b8bSToomas Soome 	boolean_t scn_checkpointing;	/* scan is issuing all queued extents */
126*a3874b8bSToomas Soome 	boolean_t scn_suspending;	/* scan is suspending until next txg */
127*a3874b8bSToomas Soome 	uint64_t scn_last_checkpoint;	/* time of last checkpoint */
128*a3874b8bSToomas Soome 
129*a3874b8bSToomas Soome 	/* members for thread synchronization */
130*a3874b8bSToomas Soome 	zio_t *scn_zio_root;		/* root zio for waiting on IO */
131*a3874b8bSToomas Soome 	taskq_t *scn_taskq;		/* task queue for issuing extents */
1323f9d6ad7SLin Ling 
133*a3874b8bSToomas Soome 	/* for controlling scan prefetch, protected by spa_scrub_lock */
134*a3874b8bSToomas Soome 	boolean_t scn_prefetch_stop;	/* prefetch should stop */
135*a3874b8bSToomas Soome 	zbookmark_phys_t scn_prefetch_bookmark;	/* prefetch start bookmark */
136*a3874b8bSToomas Soome 	avl_tree_t scn_prefetch_queue;	/* priority queue of prefetch IOs */
137*a3874b8bSToomas Soome 	uint64_t scn_maxinflight_bytes;	/* max bytes in flight for pool */
138*a3874b8bSToomas Soome 
139*a3874b8bSToomas Soome 	/* per txg statistics */
140*a3874b8bSToomas Soome 	uint64_t scn_visited_this_txg;	/* total bps visited this txg */
141*a3874b8bSToomas Soome 	uint64_t scn_holes_this_txg;
142*a3874b8bSToomas Soome 	uint64_t scn_lt_min_this_txg;
143*a3874b8bSToomas Soome 	uint64_t scn_gt_max_this_txg;
144*a3874b8bSToomas Soome 	uint64_t scn_ddt_contained_this_txg;
145*a3874b8bSToomas Soome 	uint64_t scn_objsets_visited_this_txg;
146*a3874b8bSToomas Soome 	uint64_t scn_avg_seg_size_this_txg;
147*a3874b8bSToomas Soome 	uint64_t scn_segs_this_txg;
148*a3874b8bSToomas Soome 	uint64_t scn_avg_zio_size_this_txg;
149*a3874b8bSToomas Soome 	uint64_t scn_zios_this_txg;
150*a3874b8bSToomas Soome 
151*a3874b8bSToomas Soome 	/* members needed for syncing scan status to disk */
152*a3874b8bSToomas Soome 	dsl_scan_phys_t scn_phys;	/* on disk representation of scan */
153*a3874b8bSToomas Soome 	dsl_scan_phys_t scn_phys_cached;
154*a3874b8bSToomas Soome 	avl_tree_t scn_queue;		/* queue of datasets to scan */
155*a3874b8bSToomas Soome 	uint64_t scn_bytes_pending;	/* outstanding data to issue */
1563f9d6ad7SLin Ling } dsl_scan_t;
1573f9d6ad7SLin Ling 
158*a3874b8bSToomas Soome typedef struct dsl_scan_io_queue dsl_scan_io_queue_t;
159*a3874b8bSToomas Soome 
160*a3874b8bSToomas Soome void scan_init(void);
161*a3874b8bSToomas Soome void scan_fini(void);
1623f9d6ad7SLin Ling int dsl_scan_init(struct dsl_pool *dp, uint64_t txg);
1633f9d6ad7SLin Ling void dsl_scan_fini(struct dsl_pool *dp);
1643f9d6ad7SLin Ling void dsl_scan_sync(struct dsl_pool *, dmu_tx_t *);
1653f9d6ad7SLin Ling int dsl_scan_cancel(struct dsl_pool *);
1663f9d6ad7SLin Ling int dsl_scan(struct dsl_pool *, pool_scan_func_t);
1671702cce7SAlek Pinchuk boolean_t dsl_scan_scrubbing(const struct dsl_pool *dp);
1681702cce7SAlek Pinchuk int dsl_scrub_set_pause_resume(const struct dsl_pool *dp, pool_scrub_cmd_t cmd);
1693f9d6ad7SLin Ling void dsl_resilver_restart(struct dsl_pool *, uint64_t txg);
1703f9d6ad7SLin Ling boolean_t dsl_scan_resilvering(struct dsl_pool *dp);
1713f9d6ad7SLin Ling boolean_t dsl_dataset_unstable(struct dsl_dataset *ds);
1723f9d6ad7SLin Ling void dsl_scan_ddt_entry(dsl_scan_t *scn, enum zio_checksum checksum,
1733f9d6ad7SLin Ling     ddt_entry_t *dde, dmu_tx_t *tx);
1743f9d6ad7SLin Ling void dsl_scan_ds_destroyed(struct dsl_dataset *ds, struct dmu_tx *tx);
1753f9d6ad7SLin Ling void dsl_scan_ds_snapshotted(struct dsl_dataset *ds, struct dmu_tx *tx);
1763f9d6ad7SLin Ling void dsl_scan_ds_clone_swapped(struct dsl_dataset *ds1, struct dsl_dataset *ds2,
1773f9d6ad7SLin Ling     struct dmu_tx *tx);
178cde58dbcSMatthew Ahrens boolean_t dsl_scan_active(dsl_scan_t *scn);
1791702cce7SAlek Pinchuk boolean_t dsl_scan_is_paused_scrub(const dsl_scan_t *scn);
180*a3874b8bSToomas Soome void dsl_scan_freed(spa_t *spa, const blkptr_t *bp);
181*a3874b8bSToomas Soome void dsl_scan_io_queue_destroy(dsl_scan_io_queue_t *queue);
182*a3874b8bSToomas Soome void dsl_scan_io_queue_vdev_xfer(vdev_t *svd, vdev_t *tvd);
1833f9d6ad7SLin Ling 
1843f9d6ad7SLin Ling #ifdef	__cplusplus
1853f9d6ad7SLin Ling }
1863f9d6ad7SLin Ling #endif
1873f9d6ad7SLin Ling 
1883f9d6ad7SLin Ling #endif /* _SYS_DSL_SCAN_H */
189