1219089Spjd/*
2219089Spjd * CDDL HEADER START
3219089Spjd *
4219089Spjd * The contents of this file are subject to the terms of the
5219089Spjd * Common Development and Distribution License (the "License").
6219089Spjd * You may not use this file except in compliance with the License.
7219089Spjd *
8219089Spjd * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
9219089Spjd * or http://www.opensolaris.org/os/licensing.
10219089Spjd * See the License for the specific language governing permissions
11219089Spjd * and limitations under the License.
12219089Spjd *
13219089Spjd * When distributing Covered Code, include this CDDL HEADER in each
14219089Spjd * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
15219089Spjd * If applicable, add the following below this CDDL HEADER, with the
16219089Spjd * fields enclosed by brackets "[]" replaced with your own identifying
17219089Spjd * information: Portions Copyright [yyyy] [name of copyright owner]
18219089Spjd *
19219089Spjd * CDDL HEADER END
20219089Spjd */
21219089Spjd/*
22219089Spjd * Copyright (c) 2010, Oracle and/or its affiliates. All rights reserved.
23268657Sdelphij * Copyright (c) 2012, 2014 by Delphix. All rights reserved.
24219089Spjd */
25219089Spjd
26219089Spjd#ifndef	_SYS_DSL_SCAN_H
27219089Spjd#define	_SYS_DSL_SCAN_H
28219089Spjd
29219089Spjd#include <sys/zfs_context.h>
30219089Spjd#include <sys/zio.h>
31219089Spjd#include <sys/ddt.h>
32219089Spjd#include <sys/bplist.h>
33219089Spjd
34219089Spjd#ifdef	__cplusplus
35219089Spjdextern "C" {
36219089Spjd#endif
37219089Spjd
38219089Spjdstruct objset;
39219089Spjdstruct dsl_dir;
40219089Spjdstruct dsl_dataset;
41219089Spjdstruct dsl_pool;
42219089Spjdstruct dmu_tx;
43219089Spjd
44219089Spjd/*
45219089Spjd * All members of this structure must be uint64_t, for byteswap
46219089Spjd * purposes.
47219089Spjd */
48219089Spjdtypedef struct dsl_scan_phys {
49219089Spjd	uint64_t scn_func; /* pool_scan_func_t */
50219089Spjd	uint64_t scn_state; /* dsl_scan_state_t */
51219089Spjd	uint64_t scn_queue_obj;
52219089Spjd	uint64_t scn_min_txg;
53219089Spjd	uint64_t scn_max_txg;
54219089Spjd	uint64_t scn_cur_min_txg;
55219089Spjd	uint64_t scn_cur_max_txg;
56219089Spjd	uint64_t scn_start_time;
57219089Spjd	uint64_t scn_end_time;
58219089Spjd	uint64_t scn_to_examine; /* total bytes to be scanned */
59219089Spjd	uint64_t scn_examined; /* bytes scanned so far */
60219089Spjd	uint64_t scn_to_process;
61219089Spjd	uint64_t scn_processed;
62219089Spjd	uint64_t scn_errors;	/* scan I/O error count */
63219089Spjd	uint64_t scn_ddt_class_max;
64219089Spjd	ddt_bookmark_t scn_ddt_bookmark;
65268657Sdelphij	zbookmark_phys_t scn_bookmark;
66219089Spjd	uint64_t scn_flags; /* dsl_scan_flags_t */
67219089Spjd} dsl_scan_phys_t;
68219089Spjd
69219089Spjd#define	SCAN_PHYS_NUMINTS (sizeof (dsl_scan_phys_t) / sizeof (uint64_t))
70219089Spjd
71219089Spjdtypedef enum dsl_scan_flags {
72219089Spjd	DSF_VISIT_DS_AGAIN = 1<<0,
73219089Spjd} dsl_scan_flags_t;
74219089Spjd
75254112Sdelphij/*
76254112Sdelphij * Every pool will have one dsl_scan_t and this structure will contain
77254112Sdelphij * in-memory information about the scan and a pointer to the on-disk
78254112Sdelphij * representation (i.e. dsl_scan_phys_t). Most of the state of the scan
79254112Sdelphij * is contained on-disk to allow the scan to resume in the event of a reboot
80254112Sdelphij * or panic. This structure maintains information about the behavior of a
81254112Sdelphij * running scan, some caching information, and how it should traverse the pool.
82254112Sdelphij *
83254112Sdelphij * The following members of this structure direct the behavior of the scan:
84254112Sdelphij *
85254112Sdelphij * scn_pausing -	a scan that cannot be completed in a single txg or
86254112Sdelphij *			has exceeded its allotted time will need to pause.
87254112Sdelphij *			When this flag is set the scanner will stop traversing
88254112Sdelphij *			the pool and write out the current state to disk.
89254112Sdelphij *
90254112Sdelphij * scn_restart_txg -	directs the scanner to either restart or start a
91254112Sdelphij *			a scan at the specified txg value.
92254112Sdelphij *
93254112Sdelphij * scn_done_txg -	when a scan completes its traversal it will set
94254112Sdelphij *			the completion txg to the next txg. This is necessary
95254112Sdelphij *			to ensure that any blocks that were freed during
96254112Sdelphij *			the scan but have not yet been processed (i.e deferred
97254112Sdelphij *			frees) are accounted for.
98254112Sdelphij *
99254112Sdelphij * This structure also maintains information about deferred frees which are
100254112Sdelphij * a special kind of traversal. Deferred free can exist in either a bptree or
101254112Sdelphij * a bpobj structure. The scn_is_bptree flag will indicate the type of
102254112Sdelphij * deferred free that is in progress. If the deferred free is part of an
103254112Sdelphij * asynchronous destroy then the scn_async_destroying flag will be set.
104254112Sdelphij */
105219089Spjdtypedef struct dsl_scan {
106219089Spjd	struct dsl_pool *scn_dp;
107219089Spjd
108219089Spjd	boolean_t scn_pausing;
109219089Spjd	uint64_t scn_restart_txg;
110254112Sdelphij	uint64_t scn_done_txg;
111219089Spjd	uint64_t scn_sync_start_time;
112219089Spjd	zio_t *scn_zio_root;
113219089Spjd
114236884Smm	/* for freeing blocks */
115236884Smm	boolean_t scn_is_bptree;
116249858Smm	boolean_t scn_async_destroying;
117268650Sdelphij	boolean_t scn_async_stalled;
118236884Smm
119219089Spjd	/* for debugging / information */
120219089Spjd	uint64_t scn_visited_this_txg;
121219089Spjd
122219089Spjd	dsl_scan_phys_t scn_phys;
123219089Spjd} dsl_scan_t;
124219089Spjd
125219089Spjdint dsl_scan_init(struct dsl_pool *dp, uint64_t txg);
126219089Spjdvoid dsl_scan_fini(struct dsl_pool *dp);
127219089Spjdvoid dsl_scan_sync(struct dsl_pool *, dmu_tx_t *);
128219089Spjdint dsl_scan_cancel(struct dsl_pool *);
129219089Spjdint dsl_scan(struct dsl_pool *, pool_scan_func_t);
130219089Spjdvoid dsl_resilver_restart(struct dsl_pool *, uint64_t txg);
131219089Spjdboolean_t dsl_scan_resilvering(struct dsl_pool *dp);
132219089Spjdboolean_t dsl_dataset_unstable(struct dsl_dataset *ds);
133219089Spjdvoid dsl_scan_ddt_entry(dsl_scan_t *scn, enum zio_checksum checksum,
134219089Spjd    ddt_entry_t *dde, dmu_tx_t *tx);
135219089Spjdvoid dsl_scan_ds_destroyed(struct dsl_dataset *ds, struct dmu_tx *tx);
136219089Spjdvoid dsl_scan_ds_snapshotted(struct dsl_dataset *ds, struct dmu_tx *tx);
137219089Spjdvoid dsl_scan_ds_clone_swapped(struct dsl_dataset *ds1, struct dsl_dataset *ds2,
138219089Spjd    struct dmu_tx *tx);
139219089Spjdboolean_t dsl_scan_active(dsl_scan_t *scn);
140219089Spjd
141219089Spjd#ifdef	__cplusplus
142219089Spjd}
143219089Spjd#endif
144219089Spjd
145219089Spjd#endif /* _SYS_DSL_SCAN_H */
146