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 (the "License").
6  * You may not use this file except in compliance with the License.
7  *
8  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
9  * or http://www.opensolaris.org/os/licensing.
10  * See the License for the specific language governing permissions
11  * and limitations under the License.
12  *
13  * When distributing Covered Code, include this CDDL HEADER in each
14  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
15  * If applicable, add the following below this CDDL HEADER, with the
16  * fields enclosed by brackets "[]" replaced with your own identifying
17  * information: Portions Copyright [yyyy] [name of copyright owner]
18  *
19  * CDDL HEADER END
20  */
21 /*
22  * Copyright (c) 2018, Intel Corporation.
23  * Copyright (c) 2020 by Lawrence Livermore National Security, LLC.
24  */
25 
26 #ifndef	_SYS_VDEV_REBUILD_H
27 #define	_SYS_VDEV_REBUILD_H
28 
29 #include <sys/spa.h>
30 
31 #ifdef	__cplusplus
32 extern "C" {
33 #endif
34 
35 /*
36  * Number of entries in the physical vdev_rebuild_phys structure.  This
37  * state is stored per top-level as VDEV_ZAP_TOP_VDEV_REBUILD_PHYS.
38  */
39 #define	REBUILD_PHYS_ENTRIES	12
40 
41 /*
42  * On-disk rebuild configuration and state.  When adding new fields they
43  * must be added to the end of the structure.
44  */
45 typedef struct vdev_rebuild_phys {
46 	uint64_t	vrp_rebuild_state;	/* vdev_rebuild_state_t */
47 	uint64_t	vrp_last_offset;	/* last rebuilt offset */
48 	uint64_t	vrp_min_txg;		/* minimum missing txg */
49 	uint64_t	vrp_max_txg;		/* maximum missing txg */
50 	uint64_t	vrp_start_time;		/* start time */
51 	uint64_t	vrp_end_time;		/* end time */
52 	uint64_t	vrp_scan_time_ms;	/* total run time in ms */
53 	uint64_t	vrp_bytes_scanned;	/* alloc bytes scanned */
54 	uint64_t	vrp_bytes_issued;	/* read bytes rebuilt */
55 	uint64_t	vrp_bytes_rebuilt;	/* rebuilt bytes */
56 	uint64_t	vrp_bytes_est;		/* total bytes to scan */
57 	uint64_t	vrp_errors;		/* errors during rebuild */
58 } vdev_rebuild_phys_t;
59 
60 /*
61  * The vdev_rebuild_t describes the current state and how a top-level vdev
62  * should be rebuilt.  The core elements are the top-vdev, the metaslab being
63  * rebuilt, range tree containing the allocated extents and the on-disk state.
64  */
65 typedef struct vdev_rebuild {
66 	vdev_t		*vr_top_vdev;		/* top-level vdev to rebuild */
67 	metaslab_t	*vr_scan_msp;		/* scanning disabled metaslab */
68 	range_tree_t	*vr_scan_tree;		/* scan ranges (in metaslab) */
69 	kmutex_t	vr_io_lock;		/* inflight IO lock */
70 	kcondvar_t	vr_io_cv;		/* inflight IO cv */
71 
72 	/* In-core state and progress */
73 	uint64_t	vr_scan_offset[TXG_SIZE];
74 	uint64_t	vr_prev_scan_time_ms;	/* any previous scan time */
75 	uint64_t	vr_bytes_inflight_max;	/* maximum bytes inflight */
76 	uint64_t	vr_bytes_inflight;	/* current bytes inflight */
77 
78 	/* Per-rebuild pass statistics for calculating bandwidth */
79 	uint64_t	vr_pass_start_time;
80 	uint64_t	vr_pass_bytes_scanned;
81 	uint64_t	vr_pass_bytes_issued;
82 
83 	/* On-disk state updated by vdev_rebuild_zap_update_sync() */
84 	vdev_rebuild_phys_t vr_rebuild_phys;
85 } vdev_rebuild_t;
86 
87 boolean_t vdev_rebuild_active(vdev_t *);
88 
89 int vdev_rebuild_load(vdev_t *);
90 void vdev_rebuild(vdev_t *);
91 void vdev_rebuild_stop_wait(vdev_t *);
92 void vdev_rebuild_stop_all(spa_t *);
93 void vdev_rebuild_restart(spa_t *);
94 void vdev_rebuild_clear_sync(void *, dmu_tx_t *);
95 int vdev_rebuild_get_stats(vdev_t *, vdev_rebuild_stat_t *);
96 
97 #ifdef	__cplusplus
98 }
99 #endif
100 
101 #endif /* _SYS_VDEV_REBUILD_H */
102