xref: /illumos-gate/usr/src/uts/common/fs/zfs/sys/vdev_impl.h (revision 5cabbc6b49070407fb9610cfe73d4c0e0dea3e77)
1fa9e4066Sahrens /*
2fa9e4066Sahrens  * CDDL HEADER START
3fa9e4066Sahrens  *
4fa9e4066Sahrens  * The contents of this file are subject to the terms of the
5441d80aaSlling  * Common Development and Distribution License (the "License").
6441d80aaSlling  * You may not use this file except in compliance with the License.
7fa9e4066Sahrens  *
8fa9e4066Sahrens  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
9fa9e4066Sahrens  * or http://www.opensolaris.org/os/licensing.
10fa9e4066Sahrens  * See the License for the specific language governing permissions
11fa9e4066Sahrens  * and limitations under the License.
12fa9e4066Sahrens  *
13fa9e4066Sahrens  * When distributing Covered Code, include this CDDL HEADER in each
14fa9e4066Sahrens  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
15fa9e4066Sahrens  * If applicable, add the following below this CDDL HEADER, with the
16fa9e4066Sahrens  * fields enclosed by brackets "[]" replaced with your own identifying
17fa9e4066Sahrens  * information: Portions Copyright [yyyy] [name of copyright owner]
18fa9e4066Sahrens  *
19fa9e4066Sahrens  * CDDL HEADER END
20fa9e4066Sahrens  */
21fa9e4066Sahrens /*
2298d1cbfeSGeorge Wilson  * Copyright (c) 2005, 2010, Oracle and/or its affiliates. All rights reserved.
2381cd5c55SMatthew Ahrens  * Copyright (c) 2011, 2015 by Delphix. All rights reserved.
24fa9e4066Sahrens  */
25fa9e4066Sahrens 
26fa9e4066Sahrens #ifndef _SYS_VDEV_IMPL_H
27fa9e4066Sahrens #define	_SYS_VDEV_IMPL_H
28fa9e4066Sahrens 
29fa9e4066Sahrens #include <sys/avl.h>
30*5cabbc6bSPrashanth Sreenivasa #include <sys/bpobj.h>
31fa9e4066Sahrens #include <sys/dmu.h>
32fa9e4066Sahrens #include <sys/metaslab.h>
33fa9e4066Sahrens #include <sys/nvpair.h>
34fa9e4066Sahrens #include <sys/space_map.h>
35fa9e4066Sahrens #include <sys/vdev.h>
36fa9e4066Sahrens #include <sys/dkio.h>
37fa9e4066Sahrens #include <sys/uberblock_impl.h>
38*5cabbc6bSPrashanth Sreenivasa #include <sys/vdev_indirect_mapping.h>
39*5cabbc6bSPrashanth Sreenivasa #include <sys/vdev_indirect_births.h>
40*5cabbc6bSPrashanth Sreenivasa #include <sys/vdev_removal.h>
41fa9e4066Sahrens 
42fa9e4066Sahrens #ifdef	__cplusplus
43fa9e4066Sahrens extern "C" {
44fa9e4066Sahrens #endif
45fa9e4066Sahrens 
46fa9e4066Sahrens /*
47fa9e4066Sahrens  * Virtual device descriptors.
48fa9e4066Sahrens  *
49fa9e4066Sahrens  * All storage pool operations go through the virtual device framework,
50fa9e4066Sahrens  * which provides data replication and I/O scheduling.
51fa9e4066Sahrens  */
52fa9e4066Sahrens 
53fa9e4066Sahrens /*
54fa9e4066Sahrens  * Forward declarations that lots of things need.
55fa9e4066Sahrens  */
56fa9e4066Sahrens typedef struct vdev_queue vdev_queue_t;
57fa9e4066Sahrens typedef struct vdev_cache vdev_cache_t;
58fa9e4066Sahrens typedef struct vdev_cache_entry vdev_cache_entry_t;
59770499e1SDan Kimmel struct abd;
60fa9e4066Sahrens 
610f7643c7SGeorge Wilson extern int zfs_vdev_queue_depth_pct;
620f7643c7SGeorge Wilson extern uint32_t zfs_vdev_async_write_max_active;
630f7643c7SGeorge Wilson 
64fa9e4066Sahrens /*
65fa9e4066Sahrens  * Virtual device operations
66fa9e4066Sahrens  */
674263d13fSGeorge Wilson typedef int	vdev_open_func_t(vdev_t *vd, uint64_t *size, uint64_t *max_size,
684263d13fSGeorge Wilson     uint64_t *ashift);
69fa9e4066Sahrens typedef void	vdev_close_func_t(vdev_t *vd);
70fa9e4066Sahrens typedef uint64_t vdev_asize_func_t(vdev_t *vd, uint64_t psize);
71738f37bcSGeorge Wilson typedef void	vdev_io_start_func_t(zio_t *zio);
72e14bb325SJeff Bonwick typedef void	vdev_io_done_func_t(zio_t *zio);
73fa9e4066Sahrens typedef void	vdev_state_change_func_t(vdev_t *vd, int, int);
74dcba9f3fSGeorge Wilson typedef void	vdev_hold_func_t(vdev_t *vd);
75dcba9f3fSGeorge Wilson typedef void	vdev_rele_func_t(vdev_t *vd);
76fa9e4066Sahrens 
77*5cabbc6bSPrashanth Sreenivasa typedef void	vdev_remap_cb_t(uint64_t inner_offset, vdev_t *vd,
78*5cabbc6bSPrashanth Sreenivasa     uint64_t offset, uint64_t size, void *arg);
79*5cabbc6bSPrashanth Sreenivasa typedef void	vdev_remap_func_t(vdev_t *vd, uint64_t offset, uint64_t size,
80*5cabbc6bSPrashanth Sreenivasa     vdev_remap_cb_t callback, void *arg);
81*5cabbc6bSPrashanth Sreenivasa 
82fa9e4066Sahrens typedef struct vdev_ops {
83fa9e4066Sahrens 	vdev_open_func_t		*vdev_op_open;
84fa9e4066Sahrens 	vdev_close_func_t		*vdev_op_close;
85fa9e4066Sahrens 	vdev_asize_func_t		*vdev_op_asize;
86fa9e4066Sahrens 	vdev_io_start_func_t		*vdev_op_io_start;
87fa9e4066Sahrens 	vdev_io_done_func_t		*vdev_op_io_done;
88fa9e4066Sahrens 	vdev_state_change_func_t	*vdev_op_state_change;
89dcba9f3fSGeorge Wilson 	vdev_hold_func_t		*vdev_op_hold;
90dcba9f3fSGeorge Wilson 	vdev_rele_func_t		*vdev_op_rele;
91*5cabbc6bSPrashanth Sreenivasa 	vdev_remap_func_t		*vdev_op_remap;
92fa9e4066Sahrens 	char				vdev_op_type[16];
93fa9e4066Sahrens 	boolean_t			vdev_op_leaf;
94fa9e4066Sahrens } vdev_ops_t;
95fa9e4066Sahrens 
96fa9e4066Sahrens /*
97fa9e4066Sahrens  * Virtual device properties
98fa9e4066Sahrens  */
99fa9e4066Sahrens struct vdev_cache_entry {
100770499e1SDan Kimmel 	struct abd	*ve_abd;
101fa9e4066Sahrens 	uint64_t	ve_offset;
102fa9e4066Sahrens 	uint64_t	ve_lastused;
103fa9e4066Sahrens 	avl_node_t	ve_offset_node;
104fa9e4066Sahrens 	avl_node_t	ve_lastused_node;
105fa9e4066Sahrens 	uint32_t	ve_hits;
106fa9e4066Sahrens 	uint16_t	ve_missed_update;
107fa9e4066Sahrens 	zio_t		*ve_fill_io;
108fa9e4066Sahrens };
109fa9e4066Sahrens 
110fa9e4066Sahrens struct vdev_cache {
111fa9e4066Sahrens 	avl_tree_t	vc_offset_tree;
112fa9e4066Sahrens 	avl_tree_t	vc_lastused_tree;
113fa9e4066Sahrens 	kmutex_t	vc_lock;
114fa9e4066Sahrens };
115fa9e4066Sahrens 
11669962b56SMatthew Ahrens typedef struct vdev_queue_class {
11769962b56SMatthew Ahrens 	uint32_t	vqc_active;
11869962b56SMatthew Ahrens 
11969962b56SMatthew Ahrens 	/*
12069962b56SMatthew Ahrens 	 * Sorted by offset or timestamp, depending on if the queue is
12169962b56SMatthew Ahrens 	 * LBA-ordered vs FIFO.
12269962b56SMatthew Ahrens 	 */
12369962b56SMatthew Ahrens 	avl_tree_t	vqc_queued_tree;
12469962b56SMatthew Ahrens } vdev_queue_class_t;
12569962b56SMatthew Ahrens 
126fa9e4066Sahrens struct vdev_queue {
12769962b56SMatthew Ahrens 	vdev_t		*vq_vdev;
12869962b56SMatthew Ahrens 	vdev_queue_class_t vq_class[ZIO_PRIORITY_NUM_QUEUEABLE];
12969962b56SMatthew Ahrens 	avl_tree_t	vq_active_tree;
130fe319232SJustin T. Gibbs 	avl_tree_t	vq_read_offset_tree;
131fe319232SJustin T. Gibbs 	avl_tree_t	vq_write_offset_tree;
13269962b56SMatthew Ahrens 	uint64_t	vq_last_offset;
13369962b56SMatthew Ahrens 	hrtime_t	vq_io_complete_ts; /* time last i/o completed */
134fa9e4066Sahrens 	kmutex_t	vq_lock;
135fa9e4066Sahrens };
136fa9e4066Sahrens 
137fa9e4066Sahrens /*
138*5cabbc6bSPrashanth Sreenivasa  * On-disk indirect vdev state.
139*5cabbc6bSPrashanth Sreenivasa  *
140*5cabbc6bSPrashanth Sreenivasa  * An indirect vdev is described exclusively in the MOS config of a pool.
141*5cabbc6bSPrashanth Sreenivasa  * The config for an indirect vdev includes several fields, which are
142*5cabbc6bSPrashanth Sreenivasa  * accessed in memory by a vdev_indirect_config_t.
143*5cabbc6bSPrashanth Sreenivasa  */
144*5cabbc6bSPrashanth Sreenivasa typedef struct vdev_indirect_config {
145*5cabbc6bSPrashanth Sreenivasa 	/*
146*5cabbc6bSPrashanth Sreenivasa 	 * Object (in MOS) which contains the indirect mapping. This object
147*5cabbc6bSPrashanth Sreenivasa 	 * contains an array of vdev_indirect_mapping_entry_phys_t ordered by
148*5cabbc6bSPrashanth Sreenivasa 	 * vimep_src. The bonus buffer for this object is a
149*5cabbc6bSPrashanth Sreenivasa 	 * vdev_indirect_mapping_phys_t. This object is allocated when a vdev
150*5cabbc6bSPrashanth Sreenivasa 	 * removal is initiated.
151*5cabbc6bSPrashanth Sreenivasa 	 *
152*5cabbc6bSPrashanth Sreenivasa 	 * Note that this object can be empty if none of the data on the vdev
153*5cabbc6bSPrashanth Sreenivasa 	 * has been copied yet.
154*5cabbc6bSPrashanth Sreenivasa 	 */
155*5cabbc6bSPrashanth Sreenivasa 	uint64_t	vic_mapping_object;
156*5cabbc6bSPrashanth Sreenivasa 
157*5cabbc6bSPrashanth Sreenivasa 	/*
158*5cabbc6bSPrashanth Sreenivasa 	 * Object (in MOS) which contains the birth times for the mapping
159*5cabbc6bSPrashanth Sreenivasa 	 * entries. This object contains an array of
160*5cabbc6bSPrashanth Sreenivasa 	 * vdev_indirect_birth_entry_phys_t sorted by vibe_offset. The bonus
161*5cabbc6bSPrashanth Sreenivasa 	 * buffer for this object is a vdev_indirect_birth_phys_t. This object
162*5cabbc6bSPrashanth Sreenivasa 	 * is allocated when a vdev removal is initiated.
163*5cabbc6bSPrashanth Sreenivasa 	 *
164*5cabbc6bSPrashanth Sreenivasa 	 * Note that this object can be empty if none of the vdev has yet been
165*5cabbc6bSPrashanth Sreenivasa 	 * copied.
166*5cabbc6bSPrashanth Sreenivasa 	 */
167*5cabbc6bSPrashanth Sreenivasa 	uint64_t	vic_births_object;
168*5cabbc6bSPrashanth Sreenivasa 
169*5cabbc6bSPrashanth Sreenivasa 	/*
170*5cabbc6bSPrashanth Sreenivasa 	 * This is the vdev ID which was removed previous to this vdev, or
171*5cabbc6bSPrashanth Sreenivasa 	 * UINT64_MAX if there are no previously removed vdevs.
172*5cabbc6bSPrashanth Sreenivasa 	 */
173*5cabbc6bSPrashanth Sreenivasa 	uint64_t	vic_prev_indirect_vdev;
174*5cabbc6bSPrashanth Sreenivasa } vdev_indirect_config_t;
175*5cabbc6bSPrashanth Sreenivasa 
176*5cabbc6bSPrashanth Sreenivasa /*
177fa9e4066Sahrens  * Virtual device descriptor
178fa9e4066Sahrens  */
179fa9e4066Sahrens struct vdev {
180fa9e4066Sahrens 	/*
181fa9e4066Sahrens 	 * Common to all vdev types.
182fa9e4066Sahrens 	 */
183fa9e4066Sahrens 	uint64_t	vdev_id;	/* child number in vdev parent	*/
184fa9e4066Sahrens 	uint64_t	vdev_guid;	/* unique ID for this vdev	*/
185fa9e4066Sahrens 	uint64_t	vdev_guid_sum;	/* self guid + all child guids	*/
1861195e687SMark J Musante 	uint64_t	vdev_orig_guid;	/* orig. guid prior to remove	*/
187fa9e4066Sahrens 	uint64_t	vdev_asize;	/* allocatable device capacity	*/
188573ca77eSGeorge Wilson 	uint64_t	vdev_min_asize;	/* min acceptable asize		*/
1894263d13fSGeorge Wilson 	uint64_t	vdev_max_asize;	/* max acceptable asize		*/
190fa9e4066Sahrens 	uint64_t	vdev_ashift;	/* block alignment shift	*/
191fa9e4066Sahrens 	uint64_t	vdev_state;	/* see VDEV_STATE_* #defines	*/
192560e6e96Seschrock 	uint64_t	vdev_prevstate;	/* used when reopening a vdev	*/
193fa9e4066Sahrens 	vdev_ops_t	*vdev_ops;	/* vdev operations		*/
194fa9e4066Sahrens 	spa_t		*vdev_spa;	/* spa for this vdev		*/
195fa9e4066Sahrens 	void		*vdev_tsd;	/* type-specific data		*/
196dcba9f3fSGeorge Wilson 	vnode_t		*vdev_name_vp;	/* vnode for pathname		*/
197dcba9f3fSGeorge Wilson 	vnode_t		*vdev_devid_vp;	/* vnode for devid		*/
198fa9e4066Sahrens 	vdev_t		*vdev_top;	/* top-level vdev		*/
199fa9e4066Sahrens 	vdev_t		*vdev_parent;	/* parent vdev			*/
200fa9e4066Sahrens 	vdev_t		**vdev_child;	/* array of children		*/
201fa9e4066Sahrens 	uint64_t	vdev_children;	/* number of children		*/
202fa9e4066Sahrens 	vdev_stat_t	vdev_stat;	/* virtual device statistics	*/
203573ca77eSGeorge Wilson 	boolean_t	vdev_expanding;	/* expand the vdev?		*/
204095bcd66SGeorge Wilson 	boolean_t	vdev_reopening;	/* reopen in progress?		*/
205f64c0e34SEric Taylor 	int		vdev_open_error; /* error on last open		*/
206f64c0e34SEric Taylor 	kthread_t	*vdev_open_thread; /* thread opening children	*/
20788ecc943SGeorge Wilson 	uint64_t	vdev_crtxg;	/* txg when top-level was added */
208fa9e4066Sahrens 
209fa9e4066Sahrens 	/*
210fa9e4066Sahrens 	 * Top-level vdev state.
211fa9e4066Sahrens 	 */
212fa9e4066Sahrens 	uint64_t	vdev_ms_array;	/* metaslab array object	*/
213fa9e4066Sahrens 	uint64_t	vdev_ms_shift;	/* metaslab size shift		*/
214fa9e4066Sahrens 	uint64_t	vdev_ms_count;	/* number of metaslabs		*/
215fa9e4066Sahrens 	metaslab_group_t *vdev_mg;	/* metaslab group		*/
216fa9e4066Sahrens 	metaslab_t	**vdev_ms;	/* metaslab array		*/
217fa9e4066Sahrens 	txg_list_t	vdev_ms_list;	/* per-txg dirty metaslab lists	*/
218fa9e4066Sahrens 	txg_list_t	vdev_dtl_list;	/* per-txg dirty DTL lists	*/
219fa9e4066Sahrens 	txg_node_t	vdev_txg_node;	/* per-txg dirty vdev linkage	*/
2203d7072f8Seschrock 	boolean_t	vdev_remove_wanted; /* async remove wanted?	*/
221e14bb325SJeff Bonwick 	boolean_t	vdev_probe_wanted; /* async probe wanted?	*/
222e14bb325SJeff Bonwick 	list_node_t	vdev_config_dirty_node; /* config dirty list	*/
223e14bb325SJeff Bonwick 	list_node_t	vdev_state_dirty_node; /* state dirty list	*/
22499653d4eSeschrock 	uint64_t	vdev_deflate_ratio; /* deflation ratio (x512)	*/
2258654d025Sperrin 	uint64_t	vdev_islog;	/* is an intent log device	*/
2260713e232SGeorge Wilson 	uint64_t	vdev_removing;	/* device is being removed?	*/
2270713e232SGeorge Wilson 	boolean_t	vdev_ishole;	/* is a hole in the namespace	*/
2280f7643c7SGeorge Wilson 	kmutex_t	vdev_queue_lock; /* protects vdev_queue_depth	*/
229215198a6SJoe Stein 	uint64_t	vdev_top_zap;
230fa9e4066Sahrens 
231fa9e4066Sahrens 	/*
232*5cabbc6bSPrashanth Sreenivasa 	 * Values stored in the config for an indirect or removing vdev.
233*5cabbc6bSPrashanth Sreenivasa 	 */
234*5cabbc6bSPrashanth Sreenivasa 	vdev_indirect_config_t	vdev_indirect_config;
235*5cabbc6bSPrashanth Sreenivasa 
236*5cabbc6bSPrashanth Sreenivasa 	/*
237*5cabbc6bSPrashanth Sreenivasa 	 * The vdev_indirect_rwlock protects the vdev_indirect_mapping
238*5cabbc6bSPrashanth Sreenivasa 	 * pointer from changing on indirect vdevs (when it is condensed).
239*5cabbc6bSPrashanth Sreenivasa 	 * Note that removing (not yet indirect) vdevs have different
240*5cabbc6bSPrashanth Sreenivasa 	 * access patterns (the mapping is not accessed from open context,
241*5cabbc6bSPrashanth Sreenivasa 	 * e.g. from zio_read) and locking strategy (e.g. svr_lock).
242*5cabbc6bSPrashanth Sreenivasa 	 */
243*5cabbc6bSPrashanth Sreenivasa 	krwlock_t vdev_indirect_rwlock;
244*5cabbc6bSPrashanth Sreenivasa 	vdev_indirect_mapping_t *vdev_indirect_mapping;
245*5cabbc6bSPrashanth Sreenivasa 	vdev_indirect_births_t *vdev_indirect_births;
246*5cabbc6bSPrashanth Sreenivasa 
247*5cabbc6bSPrashanth Sreenivasa 	/*
248*5cabbc6bSPrashanth Sreenivasa 	 * In memory data structures used to manage the obsolete sm, for
249*5cabbc6bSPrashanth Sreenivasa 	 * indirect or removing vdevs.
250*5cabbc6bSPrashanth Sreenivasa 	 *
251*5cabbc6bSPrashanth Sreenivasa 	 * The vdev_obsolete_segments is the in-core record of the segments
252*5cabbc6bSPrashanth Sreenivasa 	 * that are no longer referenced anywhere in the pool (due to
253*5cabbc6bSPrashanth Sreenivasa 	 * being freed or remapped and not referenced by any snapshots).
254*5cabbc6bSPrashanth Sreenivasa 	 * During a sync, segments are added to vdev_obsolete_segments
255*5cabbc6bSPrashanth Sreenivasa 	 * via vdev_indirect_mark_obsolete(); at the end of each sync
256*5cabbc6bSPrashanth Sreenivasa 	 * pass, this is appended to vdev_obsolete_sm via
257*5cabbc6bSPrashanth Sreenivasa 	 * vdev_indirect_sync_obsolete().  The vdev_obsolete_lock
258*5cabbc6bSPrashanth Sreenivasa 	 * protects against concurrent modifications of vdev_obsolete_segments
259*5cabbc6bSPrashanth Sreenivasa 	 * from multiple zio threads.
260*5cabbc6bSPrashanth Sreenivasa 	 */
261*5cabbc6bSPrashanth Sreenivasa 	kmutex_t	vdev_obsolete_lock;
262*5cabbc6bSPrashanth Sreenivasa 	range_tree_t	*vdev_obsolete_segments;
263*5cabbc6bSPrashanth Sreenivasa 	space_map_t	*vdev_obsolete_sm;
264*5cabbc6bSPrashanth Sreenivasa 
265*5cabbc6bSPrashanth Sreenivasa 	/*
2660f7643c7SGeorge Wilson 	 * The queue depth parameters determine how many async writes are
2670f7643c7SGeorge Wilson 	 * still pending (i.e. allocated by net yet issued to disk) per
2680f7643c7SGeorge Wilson 	 * top-level (vdev_async_write_queue_depth) and the maximum allowed
2690f7643c7SGeorge Wilson 	 * (vdev_max_async_write_queue_depth). These values only apply to
2700f7643c7SGeorge Wilson 	 * top-level vdevs.
2710f7643c7SGeorge Wilson 	 */
2720f7643c7SGeorge Wilson 	uint64_t	vdev_async_write_queue_depth;
2730f7643c7SGeorge Wilson 	uint64_t	vdev_max_async_write_queue_depth;
2740f7643c7SGeorge Wilson 
2750f7643c7SGeorge Wilson 	/*
276fa9e4066Sahrens 	 * Leaf vdev state.
277fa9e4066Sahrens 	 */
2780713e232SGeorge Wilson 	range_tree_t	*vdev_dtl[DTL_TYPES]; /* dirty time logs	*/
2790713e232SGeorge Wilson 	space_map_t	*vdev_dtl_sm;	/* dirty time log space map	*/
280fa9e4066Sahrens 	txg_node_t	vdev_dtl_node;	/* per-txg dirty DTL linkage	*/
2810713e232SGeorge Wilson 	uint64_t	vdev_dtl_object; /* DTL object			*/
2820713e232SGeorge Wilson 	uint64_t	vdev_psize;	/* physical device capacity	*/
283afefbcddSeschrock 	uint64_t	vdev_wholedisk;	/* true if this is a whole disk */
2843d7072f8Seschrock 	uint64_t	vdev_offline;	/* persistent offline state	*/
2853d7072f8Seschrock 	uint64_t	vdev_faulted;	/* persistent faulted state	*/
2863d7072f8Seschrock 	uint64_t	vdev_degraded;	/* persistent degraded state	*/
2873d7072f8Seschrock 	uint64_t	vdev_removed;	/* persistent removed state	*/
288b4952e17SGeorge Wilson 	uint64_t	vdev_resilver_txg; /* persistent resilvering state */
28999653d4eSeschrock 	uint64_t	vdev_nparity;	/* number of parity devices for raidz */
290fa9e4066Sahrens 	char		*vdev_path;	/* vdev path (if any)		*/
291fa9e4066Sahrens 	char		*vdev_devid;	/* vdev devid (if any)		*/
2923d7072f8Seschrock 	char		*vdev_physpath;	/* vdev device path (if any)	*/
2936809eb4eSEric Schrock 	char		*vdev_fru;	/* physical FRU location	*/
294e14bb325SJeff Bonwick 	uint64_t	vdev_not_present; /* not present during import	*/
295e14bb325SJeff Bonwick 	uint64_t	vdev_unspare;	/* unspare when resilvering done */
296e14bb325SJeff Bonwick 	boolean_t	vdev_nowritecache; /* true if flushwritecache failed */
297e14bb325SJeff Bonwick 	boolean_t	vdev_checkremove; /* temporary online test	*/
298e14bb325SJeff Bonwick 	boolean_t	vdev_forcefault; /* force online fault		*/
2991195e687SMark J Musante 	boolean_t	vdev_splitting;	/* split or repair in progress  */
30098d1cbfeSGeorge Wilson 	boolean_t	vdev_delayed_close; /* delayed device close?	*/
3010713e232SGeorge Wilson 	boolean_t	vdev_tmpoffline; /* device taken offline temporarily? */
3020713e232SGeorge Wilson 	boolean_t	vdev_detached;	/* device detached?		*/
3030713e232SGeorge Wilson 	boolean_t	vdev_cant_read;	/* vdev is failing all reads	*/
3040713e232SGeorge Wilson 	boolean_t	vdev_cant_write; /* vdev is failing all writes	*/
3050713e232SGeorge Wilson 	boolean_t	vdev_isspare;	/* was a hot spare		*/
3060713e232SGeorge Wilson 	boolean_t	vdev_isl2cache;	/* was a l2cache device		*/
307fa9e4066Sahrens 	vdev_queue_t	vdev_queue;	/* I/O deadline schedule queue	*/
308fa9e4066Sahrens 	vdev_cache_t	vdev_cache;	/* physical block cache		*/
30981cd5c55SMatthew Ahrens 	spa_aux_vdev_t	*vdev_aux;	/* for l2cache and spares vdevs	*/
310e14bb325SJeff Bonwick 	zio_t		*vdev_probe_zio; /* root of current probe	*/
311069f55e2SEric Schrock 	vdev_aux_t	vdev_label_aux;	/* on-disk aux state		*/
312215198a6SJoe Stein 	uint64_t	vdev_leaf_zap;
313fa9e4066Sahrens 
314fa9e4066Sahrens 	/*
315fa9e4066Sahrens 	 * For DTrace to work in userland (libzpool) context, these fields must
316fa9e4066Sahrens 	 * remain at the end of the structure.  DTrace will use the kernel's
317fa9e4066Sahrens 	 * CTF definition for 'struct vdev', and since the size of a kmutex_t is
318ad135b5dSChristopher Siden 	 * larger in userland, the offsets for the rest of the fields would be
319fa9e4066Sahrens 	 * incorrect.
320fa9e4066Sahrens 	 */
321fa9e4066Sahrens 	kmutex_t	vdev_dtl_lock;	/* vdev_dtl_{map,resilver}	*/
322fa9e4066Sahrens 	kmutex_t	vdev_stat_lock;	/* vdev_stat			*/
323e14bb325SJeff Bonwick 	kmutex_t	vdev_probe_lock; /* protects vdev_probe_zio	*/
324fa9e4066Sahrens };
325fa9e4066Sahrens 
326b24ab676SJeff Bonwick #define	VDEV_RAIDZ_MAXPARITY	3
327b24ab676SJeff Bonwick 
328f83ffe1aSLin Ling #define	VDEV_PAD_SIZE		(8 << 10)
329f83ffe1aSLin Ling /* 2 padding areas (vl_pad1 and vl_pad2) to skip */
330f83ffe1aSLin Ling #define	VDEV_SKIP_SIZE		VDEV_PAD_SIZE * 2
331fa9e4066Sahrens #define	VDEV_PHYS_SIZE		(112 << 10)
332ecc2d604Sbonwick #define	VDEV_UBERBLOCK_RING	(128 << 10)
333ecc2d604Sbonwick 
3342a104a52SAlex Reece /* The largest uberblock we support is 8k. */
3352a104a52SAlex Reece #define	MAX_UBERBLOCK_SHIFT (13)
336ecc2d604Sbonwick #define	VDEV_UBERBLOCK_SHIFT(vd)	\
3372a104a52SAlex Reece 	MIN(MAX((vd)->vdev_top->vdev_ashift, UBERBLOCK_SHIFT), \
3382a104a52SAlex Reece 	    MAX_UBERBLOCK_SHIFT)
339ecc2d604Sbonwick #define	VDEV_UBERBLOCK_COUNT(vd)	\
340ecc2d604Sbonwick 	(VDEV_UBERBLOCK_RING >> VDEV_UBERBLOCK_SHIFT(vd))
341ecc2d604Sbonwick #define	VDEV_UBERBLOCK_OFFSET(vd, n)	\
342ecc2d604Sbonwick 	offsetof(vdev_label_t, vl_uberblock[(n) << VDEV_UBERBLOCK_SHIFT(vd)])
343ecc2d604Sbonwick #define	VDEV_UBERBLOCK_SIZE(vd)		(1ULL << VDEV_UBERBLOCK_SHIFT(vd))
344fa9e4066Sahrens 
345fa9e4066Sahrens typedef struct vdev_phys {
3466e1f5caaSNeil Perrin 	char		vp_nvlist[VDEV_PHYS_SIZE - sizeof (zio_eck_t)];
3476e1f5caaSNeil Perrin 	zio_eck_t	vp_zbt;
348fa9e4066Sahrens } vdev_phys_t;
349fa9e4066Sahrens 
350fa9e4066Sahrens typedef struct vdev_label {
351f83ffe1aSLin Ling 	char		vl_pad1[VDEV_PAD_SIZE];			/*  8K */
352f83ffe1aSLin Ling 	char		vl_pad2[VDEV_PAD_SIZE];			/*  8K */
3533dd27b57Stabriz 	vdev_phys_t	vl_vdev_phys;				/* 112K	*/
354ecc2d604Sbonwick 	char		vl_uberblock[VDEV_UBERBLOCK_RING];	/* 128K	*/
355fa9e4066Sahrens } vdev_label_t;							/* 256K total */
356fa9e4066Sahrens 
357fa9e4066Sahrens /*
358ecc2d604Sbonwick  * vdev_dirty() flags
359ecc2d604Sbonwick  */
360ecc2d604Sbonwick #define	VDD_METASLAB	0x01
361ecc2d604Sbonwick #define	VDD_DTL		0x02
362ecc2d604Sbonwick 
363f7170741SWill Andrews /* Offset of embedded boot loader region on each label */
364f7170741SWill Andrews #define	VDEV_BOOT_OFFSET	(2 * sizeof (vdev_label_t))
365ecc2d604Sbonwick /*
366f7170741SWill Andrews  * Size of embedded boot loader region on each label.
367fa9e4066Sahrens  * The total size of the first two labels plus the boot area is 4MB.
368fa9e4066Sahrens  */
369fa9e4066Sahrens #define	VDEV_BOOT_SIZE		(7ULL << 19)			/* 3.5M */
370fa9e4066Sahrens 
371fa9e4066Sahrens /*
372fa9e4066Sahrens  * Size of label regions at the start and end of each leaf device.
373fa9e4066Sahrens  */
374fa9e4066Sahrens #define	VDEV_LABEL_START_SIZE	(2 * sizeof (vdev_label_t) + VDEV_BOOT_SIZE)
375fa9e4066Sahrens #define	VDEV_LABEL_END_SIZE	(2 * sizeof (vdev_label_t))
376fa9e4066Sahrens #define	VDEV_LABELS		4
377ad135b5dSChristopher Siden #define	VDEV_BEST_LABEL		VDEV_LABELS
378fa9e4066Sahrens 
379fa9e4066Sahrens #define	VDEV_ALLOC_LOAD		0
380fa9e4066Sahrens #define	VDEV_ALLOC_ADD		1
38199653d4eSeschrock #define	VDEV_ALLOC_SPARE	2
382fa94a07fSbrendan #define	VDEV_ALLOC_L2CACHE	3
38321ecdf64SLin Ling #define	VDEV_ALLOC_ROOTPOOL	4
3841195e687SMark J Musante #define	VDEV_ALLOC_SPLIT	5
385cd0837ccSGeorge Wilson #define	VDEV_ALLOC_ATTACH	6
386fa9e4066Sahrens 
387fa9e4066Sahrens /*
388fa9e4066Sahrens  * Allocate or free a vdev
389fa9e4066Sahrens  */
39088ecc943SGeorge Wilson extern vdev_t *vdev_alloc_common(spa_t *spa, uint_t id, uint64_t guid,
39188ecc943SGeorge Wilson     vdev_ops_t *ops);
39299653d4eSeschrock extern int vdev_alloc(spa_t *spa, vdev_t **vdp, nvlist_t *config,
39399653d4eSeschrock     vdev_t *parent, uint_t id, int alloctype);
394fa9e4066Sahrens extern void vdev_free(vdev_t *vd);
395fa9e4066Sahrens 
396fa9e4066Sahrens /*
397fa9e4066Sahrens  * Add or remove children and parents
398fa9e4066Sahrens  */
399fa9e4066Sahrens extern void vdev_add_child(vdev_t *pvd, vdev_t *cvd);
400fa9e4066Sahrens extern void vdev_remove_child(vdev_t *pvd, vdev_t *cvd);
401fa9e4066Sahrens extern void vdev_compact_children(vdev_t *pvd);
402fa9e4066Sahrens extern vdev_t *vdev_add_parent(vdev_t *cvd, vdev_ops_t *ops);
403fa9e4066Sahrens extern void vdev_remove_parent(vdev_t *cvd);
404fa9e4066Sahrens 
405fa9e4066Sahrens /*
406fa9e4066Sahrens  * vdev sync load and sync
407fa9e4066Sahrens  */
40888ecc943SGeorge Wilson extern void vdev_load_log_state(vdev_t *nvd, vdev_t *ovd);
4094b964adaSGeorge Wilson extern boolean_t vdev_log_state_valid(vdev_t *vd);
410*5cabbc6bSPrashanth Sreenivasa extern int vdev_load(vdev_t *vd);
4110713e232SGeorge Wilson extern int vdev_dtl_load(vdev_t *vd);
412fa9e4066Sahrens extern void vdev_sync(vdev_t *vd, uint64_t txg);
413fa9e4066Sahrens extern void vdev_sync_done(vdev_t *vd, uint64_t txg);
414ecc2d604Sbonwick extern void vdev_dirty(vdev_t *vd, int flags, void *arg, uint64_t txg);
4150713e232SGeorge Wilson extern void vdev_dirty_leaves(vdev_t *vd, int flags, uint64_t txg);
416fa9e4066Sahrens 
417fa9e4066Sahrens /*
418fa9e4066Sahrens  * Available vdev types.
419fa9e4066Sahrens  */
420fa9e4066Sahrens extern vdev_ops_t vdev_root_ops;
421fa9e4066Sahrens extern vdev_ops_t vdev_mirror_ops;
422fa9e4066Sahrens extern vdev_ops_t vdev_replacing_ops;
423fa9e4066Sahrens extern vdev_ops_t vdev_raidz_ops;
424fa9e4066Sahrens extern vdev_ops_t vdev_disk_ops;
425fa9e4066Sahrens extern vdev_ops_t vdev_file_ops;
426fa9e4066Sahrens extern vdev_ops_t vdev_missing_ops;
42788ecc943SGeorge Wilson extern vdev_ops_t vdev_hole_ops;
42899653d4eSeschrock extern vdev_ops_t vdev_spare_ops;
429*5cabbc6bSPrashanth Sreenivasa extern vdev_ops_t vdev_indirect_ops;
430fa9e4066Sahrens 
431fa9e4066Sahrens /*
4322a79c5feSlling  * Common size functions
433fa9e4066Sahrens  */
434fa9e4066Sahrens extern uint64_t vdev_default_asize(vdev_t *vd, uint64_t psize);
435573ca77eSGeorge Wilson extern uint64_t vdev_get_min_asize(vdev_t *vd);
436573ca77eSGeorge Wilson extern void vdev_set_min_asize(vdev_t *vd);
437fa9e4066Sahrens 
438e81c57b1Sahrens /*
439f7170741SWill Andrews  * Global variables
440e81c57b1Sahrens  */
441f7170741SWill Andrews /* zdb uses this tunable, so it must be declared here to make lint happy. */
442e81c57b1Sahrens extern int zfs_vdev_cache_size;
443e81c57b1Sahrens 
44431d7e8faSGeorge Wilson /*
445*5cabbc6bSPrashanth Sreenivasa  * Functions from vdev_indirect.c
446*5cabbc6bSPrashanth Sreenivasa  */
447*5cabbc6bSPrashanth Sreenivasa extern void vdev_indirect_sync_obsolete(vdev_t *vd, dmu_tx_t *tx);
448*5cabbc6bSPrashanth Sreenivasa extern boolean_t vdev_indirect_should_condense(vdev_t *vd);
449*5cabbc6bSPrashanth Sreenivasa extern void spa_condense_indirect_start_sync(vdev_t *vd, dmu_tx_t *tx);
450*5cabbc6bSPrashanth Sreenivasa extern int vdev_obsolete_sm_object(vdev_t *vd);
451*5cabbc6bSPrashanth Sreenivasa extern boolean_t vdev_obsolete_counts_are_precise(vdev_t *vd);
452*5cabbc6bSPrashanth Sreenivasa 
453*5cabbc6bSPrashanth Sreenivasa /*
45431d7e8faSGeorge Wilson  * The vdev_buf_t is used to translate between zio_t and buf_t, and back again.
45531d7e8faSGeorge Wilson  */
45631d7e8faSGeorge Wilson typedef struct vdev_buf {
45731d7e8faSGeorge Wilson 	buf_t	vb_buf;		/* buffer that describes the io */
45831d7e8faSGeorge Wilson 	zio_t	*vb_io;		/* pointer back to the original zio_t */
45931d7e8faSGeorge Wilson } vdev_buf_t;
46031d7e8faSGeorge Wilson 
461fa9e4066Sahrens #ifdef	__cplusplus
462fa9e4066Sahrens }
463fa9e4066Sahrens #endif
464fa9e4066Sahrens 
465fa9e4066Sahrens #endif	/* _SYS_VDEV_IMPL_H */
466