xref: /illumos-gate/usr/src/uts/common/fs/zfs/sys/vdev_impl.h (revision 45ede40b2394db7967e59f19288fae9b62efd4aa)
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) 2005, 2010, Oracle and/or its affiliates. All rights reserved.
23  * Copyright (c) 2011, 2020 by Delphix. All rights reserved.
24  * Copyright (c) 2017, Intel Corporation.
25  * Copyright 2019 Joyent, Inc.
26  * Copyright 2020 Joshua M. Clulow <josh@sysmgr.org>
27  */
28 
29 #ifndef _SYS_VDEV_IMPL_H
30 #define	_SYS_VDEV_IMPL_H
31 
32 #include <sys/avl.h>
33 #include <sys/bpobj.h>
34 #include <sys/dmu.h>
35 #include <sys/metaslab.h>
36 #include <sys/nvpair.h>
37 #include <sys/space_map.h>
38 #include <sys/vdev.h>
39 #include <sys/dkio.h>
40 #include <sys/uberblock_impl.h>
41 #include <sys/vdev_indirect_mapping.h>
42 #include <sys/vdev_indirect_births.h>
43 #include <sys/vdev_removal.h>
44 
45 #ifdef	__cplusplus
46 extern "C" {
47 #endif
48 
49 /*
50  * Virtual device descriptors.
51  *
52  * All storage pool operations go through the virtual device framework,
53  * which provides data replication and I/O scheduling.
54  */
55 
56 /*
57  * Forward declarations that lots of things need.
58  */
59 typedef struct vdev_queue vdev_queue_t;
60 typedef struct vdev_cache vdev_cache_t;
61 typedef struct vdev_cache_entry vdev_cache_entry_t;
62 struct abd;
63 
64 extern int zfs_vdev_queue_depth_pct;
65 extern int zfs_vdev_def_queue_depth;
66 extern uint32_t zfs_vdev_async_write_max_active;
67 
68 /*
69  * Virtual device operations
70  */
71 typedef int	vdev_open_func_t(vdev_t *vd, uint64_t *size, uint64_t *max_size,
72     uint64_t *ashift);
73 typedef void	vdev_close_func_t(vdev_t *vd);
74 typedef uint64_t vdev_asize_func_t(vdev_t *vd, uint64_t psize);
75 typedef void	vdev_io_start_func_t(zio_t *zio);
76 typedef void	vdev_io_done_func_t(zio_t *zio);
77 typedef void	vdev_state_change_func_t(vdev_t *vd, int, int);
78 typedef boolean_t vdev_need_resilver_func_t(vdev_t *vd, uint64_t, size_t);
79 typedef void	vdev_hold_func_t(vdev_t *vd);
80 typedef void	vdev_rele_func_t(vdev_t *vd);
81 
82 typedef void	vdev_remap_cb_t(uint64_t inner_offset, vdev_t *vd,
83     uint64_t offset, uint64_t size, void *arg);
84 typedef void	vdev_remap_func_t(vdev_t *vd, uint64_t offset, uint64_t size,
85     vdev_remap_cb_t callback, void *arg);
86 typedef int	vdev_dumpio_func_t(vdev_t *vd, caddr_t data, size_t size,
87     uint64_t offset, uint64_t origoffset, boolean_t doread, boolean_t isdump);
88 /*
89  * Given a target vdev, translates the logical range "in" to the physical
90  * range "res"
91  */
92 typedef void vdev_xlation_func_t(vdev_t *cvd, const range_seg64_t *in,
93     range_seg64_t *res);
94 
95 typedef struct vdev_ops {
96 	vdev_open_func_t		*vdev_op_open;
97 	vdev_close_func_t		*vdev_op_close;
98 	vdev_asize_func_t		*vdev_op_asize;
99 	vdev_io_start_func_t		*vdev_op_io_start;
100 	vdev_io_done_func_t		*vdev_op_io_done;
101 	vdev_state_change_func_t	*vdev_op_state_change;
102 	vdev_need_resilver_func_t	*vdev_op_need_resilver;
103 	vdev_hold_func_t		*vdev_op_hold;
104 	vdev_rele_func_t		*vdev_op_rele;
105 	vdev_remap_func_t		*vdev_op_remap;
106 	/*
107 	 * For translating ranges from non-leaf vdevs (e.g. raidz) to leaves.
108 	 * Used when initializing vdevs. Isn't used by leaf ops.
109 	 */
110 	vdev_xlation_func_t		*vdev_op_xlate;
111 	vdev_dumpio_func_t		*vdev_op_dumpio;
112 	char				vdev_op_type[16];
113 	boolean_t			vdev_op_leaf;
114 } vdev_ops_t;
115 
116 /*
117  * Virtual device properties
118  */
119 struct vdev_cache_entry {
120 	struct abd	*ve_abd;
121 	uint64_t	ve_offset;
122 	uint64_t	ve_lastused;
123 	avl_node_t	ve_offset_node;
124 	avl_node_t	ve_lastused_node;
125 	uint32_t	ve_hits;
126 	uint16_t	ve_missed_update;
127 	zio_t		*ve_fill_io;
128 };
129 
130 struct vdev_cache {
131 	avl_tree_t	vc_offset_tree;
132 	avl_tree_t	vc_lastused_tree;
133 	kmutex_t	vc_lock;
134 };
135 
136 typedef struct vdev_queue_class {
137 	uint32_t	vqc_active;
138 
139 	/*
140 	 * Sorted by offset or timestamp, depending on if the queue is
141 	 * LBA-ordered vs FIFO.
142 	 */
143 	avl_tree_t	vqc_queued_tree;
144 } vdev_queue_class_t;
145 
146 struct vdev_queue {
147 	vdev_t		*vq_vdev;
148 	vdev_queue_class_t vq_class[ZIO_PRIORITY_NUM_QUEUEABLE];
149 	avl_tree_t	vq_active_tree;
150 	avl_tree_t	vq_read_offset_tree;
151 	avl_tree_t	vq_write_offset_tree;
152 	avl_tree_t	vq_trim_offset_tree;
153 	uint64_t	vq_last_offset;
154 	hrtime_t	vq_io_complete_ts; /* time last i/o completed */
155 	kmutex_t	vq_lock;
156 };
157 
158 typedef enum vdev_alloc_bias {
159 	VDEV_BIAS_NONE,
160 	VDEV_BIAS_LOG,		/* dedicated to ZIL data (SLOG) */
161 	VDEV_BIAS_SPECIAL,	/* dedicated to ddt, metadata, and small blks */
162 	VDEV_BIAS_DEDUP		/* dedicated to dedup metadata */
163 } vdev_alloc_bias_t;
164 
165 
166 /*
167  * On-disk indirect vdev state.
168  *
169  * An indirect vdev is described exclusively in the MOS config of a pool.
170  * The config for an indirect vdev includes several fields, which are
171  * accessed in memory by a vdev_indirect_config_t.
172  */
173 typedef struct vdev_indirect_config {
174 	/*
175 	 * Object (in MOS) which contains the indirect mapping. This object
176 	 * contains an array of vdev_indirect_mapping_entry_phys_t ordered by
177 	 * vimep_src. The bonus buffer for this object is a
178 	 * vdev_indirect_mapping_phys_t. This object is allocated when a vdev
179 	 * removal is initiated.
180 	 *
181 	 * Note that this object can be empty if none of the data on the vdev
182 	 * has been copied yet.
183 	 */
184 	uint64_t	vic_mapping_object;
185 
186 	/*
187 	 * Object (in MOS) which contains the birth times for the mapping
188 	 * entries. This object contains an array of
189 	 * vdev_indirect_birth_entry_phys_t sorted by vibe_offset. The bonus
190 	 * buffer for this object is a vdev_indirect_birth_phys_t. This object
191 	 * is allocated when a vdev removal is initiated.
192 	 *
193 	 * Note that this object can be empty if none of the vdev has yet been
194 	 * copied.
195 	 */
196 	uint64_t	vic_births_object;
197 
198 	/*
199 	 * This is the vdev ID which was removed previous to this vdev, or
200 	 * UINT64_MAX if there are no previously removed vdevs.
201 	 */
202 	uint64_t	vic_prev_indirect_vdev;
203 } vdev_indirect_config_t;
204 
205 /*
206  * Virtual device descriptor
207  */
208 struct vdev {
209 	/*
210 	 * Common to all vdev types.
211 	 */
212 	uint64_t	vdev_id;	/* child number in vdev parent	*/
213 	uint64_t	vdev_guid;	/* unique ID for this vdev	*/
214 	uint64_t	vdev_guid_sum;	/* self guid + all child guids	*/
215 	uint64_t	vdev_orig_guid;	/* orig. guid prior to remove	*/
216 	uint64_t	vdev_asize;	/* allocatable device capacity	*/
217 	uint64_t	vdev_min_asize;	/* min acceptable asize		*/
218 	uint64_t	vdev_max_asize;	/* max acceptable asize		*/
219 	uint64_t	vdev_ashift;	/* block alignment shift	*/
220 	uint64_t	vdev_state;	/* see VDEV_STATE_* #defines	*/
221 	uint64_t	vdev_prevstate;	/* used when reopening a vdev	*/
222 	vdev_ops_t	*vdev_ops;	/* vdev operations		*/
223 	spa_t		*vdev_spa;	/* spa for this vdev		*/
224 	void		*vdev_tsd;	/* type-specific data		*/
225 	vnode_t		*vdev_name_vp;	/* vnode for pathname		*/
226 	vnode_t		*vdev_devid_vp;	/* vnode for devid		*/
227 	vdev_t		*vdev_top;	/* top-level vdev		*/
228 	vdev_t		*vdev_parent;	/* parent vdev			*/
229 	vdev_t		**vdev_child;	/* array of children		*/
230 	uint64_t	vdev_children;	/* number of children		*/
231 	vdev_stat_t	vdev_stat;	/* virtual device statistics	*/
232 	vdev_stat_ex_t	vdev_stat_ex;	/* extended statistics		*/
233 	boolean_t	vdev_expanding;	/* expand the vdev?		*/
234 	boolean_t	vdev_reopening;	/* reopen in progress?		*/
235 	boolean_t	vdev_nonrot;	/* true if solid state		*/
236 	int		vdev_open_error; /* error on last open		*/
237 	kthread_t	*vdev_open_thread; /* thread opening children	*/
238 	uint64_t	vdev_crtxg;	/* txg when top-level was added */
239 
240 	/*
241 	 * Top-level vdev state.
242 	 */
243 	uint64_t	vdev_ms_array;	/* metaslab array object	*/
244 	uint64_t	vdev_ms_shift;	/* metaslab size shift		*/
245 	uint64_t	vdev_ms_count;	/* number of metaslabs		*/
246 	metaslab_group_t *vdev_mg;	/* metaslab group		*/
247 	metaslab_t	**vdev_ms;	/* metaslab array		*/
248 	txg_list_t	vdev_ms_list;	/* per-txg dirty metaslab lists	*/
249 	txg_list_t	vdev_dtl_list;	/* per-txg dirty DTL lists	*/
250 	txg_node_t	vdev_txg_node;	/* per-txg dirty vdev linkage	*/
251 	boolean_t	vdev_remove_wanted; /* async remove wanted?	*/
252 	boolean_t	vdev_probe_wanted; /* async probe wanted?	*/
253 	list_node_t	vdev_config_dirty_node; /* config dirty list	*/
254 	list_node_t	vdev_state_dirty_node; /* state dirty list	*/
255 	uint64_t	vdev_deflate_ratio; /* deflation ratio (x512)	*/
256 	uint64_t	vdev_islog;	/* is an intent log device	*/
257 	uint64_t	vdev_removing;	/* device is being removed?	*/
258 	boolean_t	vdev_ishole;	/* is a hole in the namespace	*/
259 	uint64_t	vdev_top_zap;
260 	vdev_alloc_bias_t vdev_alloc_bias; /* metaslab allocation bias	*/
261 
262 	/* pool checkpoint related */
263 	space_map_t	*vdev_checkpoint_sm;	/* contains reserved blocks */
264 
265 	/* Initialize related */
266 	boolean_t	vdev_initialize_exit_wanted;
267 	vdev_initializing_state_t	vdev_initialize_state;
268 	list_node_t	vdev_initialize_node;
269 	kthread_t	*vdev_initialize_thread;
270 	/* Protects vdev_initialize_thread and vdev_initialize_state. */
271 	kmutex_t	vdev_initialize_lock;
272 	kcondvar_t	vdev_initialize_cv;
273 	uint64_t	vdev_initialize_offset[TXG_SIZE];
274 	uint64_t	vdev_initialize_last_offset;
275 	range_tree_t	*vdev_initialize_tree;	/* valid while initializing */
276 	uint64_t	vdev_initialize_bytes_est;
277 	uint64_t	vdev_initialize_bytes_done;
278 	time_t		vdev_initialize_action_time;	/* start and end time */
279 
280 	/* TRIM related */
281 	boolean_t	vdev_trim_exit_wanted;
282 	boolean_t	vdev_autotrim_exit_wanted;
283 	vdev_trim_state_t	vdev_trim_state;
284 	list_node_t	vdev_trim_node;
285 	kmutex_t	vdev_autotrim_lock;
286 	kcondvar_t	vdev_autotrim_cv;
287 	kthread_t	*vdev_autotrim_thread;
288 	/* Protects vdev_trim_thread and vdev_trim_state. */
289 	kmutex_t	vdev_trim_lock;
290 	kcondvar_t	vdev_trim_cv;
291 	kthread_t	*vdev_trim_thread;
292 	uint64_t	vdev_trim_offset[TXG_SIZE];
293 	uint64_t	vdev_trim_last_offset;
294 	uint64_t	vdev_trim_bytes_est;
295 	uint64_t	vdev_trim_bytes_done;
296 	uint64_t	vdev_trim_rate;		/* requested rate (bytes/sec) */
297 	uint64_t	vdev_trim_partial;	/* requested partial TRIM */
298 	uint64_t	vdev_trim_secure;	/* requested secure TRIM */
299 	time_t		vdev_trim_action_time;	/* start and end time */
300 
301 	/* The following is not in ZoL, but used for auto-trim test progress */
302 	uint64_t	vdev_autotrim_bytes_done;
303 
304 	/* for limiting outstanding I/Os (initialize and TRIM) */
305 	kmutex_t	vdev_initialize_io_lock;
306 	kcondvar_t	vdev_initialize_io_cv;
307 	uint64_t	vdev_initialize_inflight;
308 	kmutex_t	vdev_trim_io_lock;
309 	kcondvar_t	vdev_trim_io_cv;
310 	uint64_t	vdev_trim_inflight[2];
311 
312 	/*
313 	 * Values stored in the config for an indirect or removing vdev.
314 	 */
315 	vdev_indirect_config_t	vdev_indirect_config;
316 
317 	/*
318 	 * The vdev_indirect_rwlock protects the vdev_indirect_mapping
319 	 * pointer from changing on indirect vdevs (when it is condensed).
320 	 * Note that removing (not yet indirect) vdevs have different
321 	 * access patterns (the mapping is not accessed from open context,
322 	 * e.g. from zio_read) and locking strategy (e.g. svr_lock).
323 	 */
324 	krwlock_t vdev_indirect_rwlock;
325 	vdev_indirect_mapping_t *vdev_indirect_mapping;
326 	vdev_indirect_births_t *vdev_indirect_births;
327 
328 	/*
329 	 * In memory data structures used to manage the obsolete sm, for
330 	 * indirect or removing vdevs.
331 	 *
332 	 * The vdev_obsolete_segments is the in-core record of the segments
333 	 * that are no longer referenced anywhere in the pool (due to
334 	 * being freed or remapped and not referenced by any snapshots).
335 	 * During a sync, segments are added to vdev_obsolete_segments
336 	 * via vdev_indirect_mark_obsolete(); at the end of each sync
337 	 * pass, this is appended to vdev_obsolete_sm via
338 	 * vdev_indirect_sync_obsolete().  The vdev_obsolete_lock
339 	 * protects against concurrent modifications of vdev_obsolete_segments
340 	 * from multiple zio threads.
341 	 */
342 	kmutex_t	vdev_obsolete_lock;
343 	range_tree_t	*vdev_obsolete_segments;
344 	space_map_t	*vdev_obsolete_sm;
345 
346 	/*
347 	 * Protects the vdev_scan_io_queue field itself as well as the
348 	 * structure's contents (when present).
349 	 */
350 	kmutex_t	vdev_scan_io_queue_lock;
351 	struct dsl_scan_io_queue	*vdev_scan_io_queue;
352 
353 	/*
354 	 * Leaf vdev state.
355 	 */
356 	range_tree_t	*vdev_dtl[DTL_TYPES]; /* dirty time logs	*/
357 	space_map_t	*vdev_dtl_sm;	/* dirty time log space map	*/
358 	txg_node_t	vdev_dtl_node;	/* per-txg dirty DTL linkage	*/
359 	uint64_t	vdev_dtl_object; /* DTL object			*/
360 	uint64_t	vdev_psize;	/* physical device capacity	*/
361 	uint64_t	vdev_wholedisk;	/* true if this is a whole disk */
362 	uint64_t	vdev_offline;	/* persistent offline state	*/
363 	uint64_t	vdev_faulted;	/* persistent faulted state	*/
364 	uint64_t	vdev_degraded;	/* persistent degraded state	*/
365 	uint64_t	vdev_removed;	/* persistent removed state	*/
366 	uint64_t	vdev_resilver_txg; /* persistent resilvering state */
367 	uint64_t	vdev_nparity;	/* number of parity devices for raidz */
368 	char		*vdev_path;	/* vdev path (if any)		*/
369 	char		*vdev_devid;	/* vdev devid (if any)		*/
370 	char		*vdev_physpath;	/* vdev device path (if any)	*/
371 	char		*vdev_fru;	/* physical FRU location	*/
372 	uint64_t	vdev_not_present; /* not present during import	*/
373 	uint64_t	vdev_unspare;	/* unspare when resilvering done */
374 	boolean_t	vdev_nowritecache; /* true if flushwritecache failed */
375 	boolean_t	vdev_has_trim;	/* TRIM is supported		*/
376 	boolean_t	vdev_has_securetrim; /* secure TRIM is supported */
377 	boolean_t	vdev_checkremove; /* temporary online test	*/
378 	boolean_t	vdev_forcefault; /* force online fault		*/
379 	boolean_t	vdev_splitting;	/* split or repair in progress  */
380 	boolean_t	vdev_delayed_close; /* delayed device close?	*/
381 	boolean_t	vdev_tmpoffline; /* device taken offline temporarily? */
382 	boolean_t	vdev_detached;	/* device detached?		*/
383 	boolean_t	vdev_cant_read;	/* vdev is failing all reads	*/
384 	boolean_t	vdev_cant_write; /* vdev is failing all writes	*/
385 	boolean_t	vdev_isspare;	/* was a hot spare		*/
386 	boolean_t	vdev_isl2cache;	/* was a l2cache device		*/
387 	boolean_t	vdev_resilver_deferred;  /* resilver deferred */
388 	vdev_queue_t	vdev_queue;	/* I/O deadline schedule queue	*/
389 	vdev_cache_t	vdev_cache;	/* physical block cache		*/
390 	spa_aux_vdev_t	*vdev_aux;	/* for l2cache and spares vdevs	*/
391 	zio_t		*vdev_probe_zio; /* root of current probe	*/
392 	vdev_aux_t	vdev_label_aux;	/* on-disk aux state		*/
393 	uint64_t	vdev_leaf_zap;
394 	hrtime_t	vdev_mmp_pending; /* 0 if write finished	*/
395 	uint64_t	vdev_mmp_kstat_id;	/* to find kstat entry */
396 	list_node_t	vdev_leaf_node;		/* leaf vdev list */
397 
398 	/*
399 	 * For DTrace to work in userland (libzpool) context, these fields must
400 	 * remain at the end of the structure.  DTrace will use the kernel's
401 	 * CTF definition for 'struct vdev', and since the size of a kmutex_t is
402 	 * larger in userland, the offsets for the rest of the fields would be
403 	 * incorrect.
404 	 */
405 	kmutex_t	vdev_dtl_lock;	/* vdev_dtl_{map,resilver}	*/
406 	kmutex_t	vdev_stat_lock;	/* vdev_stat			*/
407 	kmutex_t	vdev_probe_lock; /* protects vdev_probe_zio	*/
408 };
409 
410 #define	VDEV_RAIDZ_MAXPARITY	3
411 
412 #define	VDEV_PAD_SIZE		(8 << 10)
413 /* 2 padding areas (vl_pad1 and vl_be) to skip */
414 #define	VDEV_SKIP_SIZE		VDEV_PAD_SIZE * 2
415 #define	VDEV_PHYS_SIZE		(112 << 10)
416 #define	VDEV_UBERBLOCK_RING	(128 << 10)
417 
418 /*
419  * MMP blocks occupy the last MMP_BLOCKS_PER_LABEL slots in the uberblock
420  * ring when MMP is enabled.
421  */
422 #define	MMP_BLOCKS_PER_LABEL	1
423 
424 /* The largest uberblock we support is 8k. */
425 #define	MAX_UBERBLOCK_SHIFT (13)
426 #define	VDEV_UBERBLOCK_SHIFT(vd)	\
427 	MIN(MAX((vd)->vdev_top->vdev_ashift, UBERBLOCK_SHIFT), \
428 	    MAX_UBERBLOCK_SHIFT)
429 #define	VDEV_UBERBLOCK_COUNT(vd)	\
430 	(VDEV_UBERBLOCK_RING >> VDEV_UBERBLOCK_SHIFT(vd))
431 #define	VDEV_UBERBLOCK_OFFSET(vd, n)	\
432 	offsetof(vdev_label_t, vl_uberblock[(n) << VDEV_UBERBLOCK_SHIFT(vd)])
433 #define	VDEV_UBERBLOCK_SIZE(vd)		(1ULL << VDEV_UBERBLOCK_SHIFT(vd))
434 
435 typedef struct vdev_phys {
436 	char		vp_nvlist[VDEV_PHYS_SIZE - sizeof (zio_eck_t)];
437 	zio_eck_t	vp_zbt;
438 } vdev_phys_t;
439 
440 typedef enum vbe_vers {
441 	/*
442 	 * The bootenv file is stored as ascii text in the envblock.
443 	 * It is used by the GRUB bootloader used on Linux to store the
444 	 * contents of the grubenv file. The file is stored as raw ASCII,
445 	 * and is protected by an embedded checksum. By default, GRUB will
446 	 * check if the boot filesystem supports storing the environment data
447 	 * in a special location, and if so, will invoke filesystem specific
448 	 * logic to retrieve it. This can be overriden by a variable, should
449 	 * the user so desire.
450 	 */
451 	VB_RAW = 0,
452 
453 	/*
454 	 * The bootenv file is converted to an nvlist and then packed into the
455 	 * envblock.
456 	 */
457 	VB_NVLIST = 1
458 } vbe_vers_t;
459 
460 typedef struct vdev_boot_envblock {
461 	uint64_t	vbe_version;
462 	char		vbe_bootenv[VDEV_PAD_SIZE - sizeof (uint64_t) -
463 			sizeof (zio_eck_t)];
464 	zio_eck_t	vbe_zbt;
465 } vdev_boot_envblock_t;
466 
467 CTASSERT(sizeof (vdev_boot_envblock_t) == VDEV_PAD_SIZE);
468 
469 typedef struct vdev_label {
470 	char		vl_pad1[VDEV_PAD_SIZE];			/*  8K */
471 	vdev_boot_envblock_t	vl_be;				/*  8K */
472 	vdev_phys_t	vl_vdev_phys;				/* 112K	*/
473 	char		vl_uberblock[VDEV_UBERBLOCK_RING];	/* 128K	*/
474 } vdev_label_t;							/* 256K total */
475 
476 /*
477  * vdev_dirty() flags
478  */
479 #define	VDD_METASLAB	0x01
480 #define	VDD_DTL		0x02
481 
482 /* Offset of embedded boot loader region on each label */
483 #define	VDEV_BOOT_OFFSET	(2 * sizeof (vdev_label_t))
484 /*
485  * Size of embedded boot loader region on each label.
486  * The total size of the first two labels plus the boot area is 4MB.
487  */
488 #define	VDEV_BOOT_SIZE		(7ULL << 19)			/* 3.5M */
489 
490 /*
491  * Size of label regions at the start and end of each leaf device.
492  */
493 #define	VDEV_LABEL_START_SIZE	(2 * sizeof (vdev_label_t) + VDEV_BOOT_SIZE)
494 #define	VDEV_LABEL_END_SIZE	(2 * sizeof (vdev_label_t))
495 #define	VDEV_LABELS		4
496 #define	VDEV_BEST_LABEL		VDEV_LABELS
497 
498 #define	VDEV_ALLOC_LOAD		0
499 #define	VDEV_ALLOC_ADD		1
500 #define	VDEV_ALLOC_SPARE	2
501 #define	VDEV_ALLOC_L2CACHE	3
502 #define	VDEV_ALLOC_ROOTPOOL	4
503 #define	VDEV_ALLOC_SPLIT	5
504 #define	VDEV_ALLOC_ATTACH	6
505 
506 /*
507  * Allocate or free a vdev
508  */
509 extern vdev_t *vdev_alloc_common(spa_t *spa, uint_t id, uint64_t guid,
510     vdev_ops_t *ops);
511 extern int vdev_alloc(spa_t *spa, vdev_t **vdp, nvlist_t *config,
512     vdev_t *parent, uint_t id, int alloctype);
513 extern void vdev_free(vdev_t *vd);
514 
515 /*
516  * Add or remove children and parents
517  */
518 extern void vdev_add_child(vdev_t *pvd, vdev_t *cvd);
519 extern void vdev_remove_child(vdev_t *pvd, vdev_t *cvd);
520 extern void vdev_compact_children(vdev_t *pvd);
521 extern vdev_t *vdev_add_parent(vdev_t *cvd, vdev_ops_t *ops);
522 extern void vdev_remove_parent(vdev_t *cvd);
523 
524 /*
525  * vdev sync load and sync
526  */
527 extern boolean_t vdev_log_state_valid(vdev_t *vd);
528 extern int vdev_load(vdev_t *vd);
529 extern int vdev_dtl_load(vdev_t *vd);
530 extern void vdev_sync(vdev_t *vd, uint64_t txg);
531 extern void vdev_sync_done(vdev_t *vd, uint64_t txg);
532 extern void vdev_dirty(vdev_t *vd, int flags, void *arg, uint64_t txg);
533 extern void vdev_dirty_leaves(vdev_t *vd, int flags, uint64_t txg);
534 
535 /*
536  * Available vdev types.
537  */
538 extern vdev_ops_t vdev_root_ops;
539 extern vdev_ops_t vdev_mirror_ops;
540 extern vdev_ops_t vdev_replacing_ops;
541 extern vdev_ops_t vdev_raidz_ops;
542 extern vdev_ops_t vdev_disk_ops;
543 extern vdev_ops_t vdev_file_ops;
544 extern vdev_ops_t vdev_missing_ops;
545 extern vdev_ops_t vdev_hole_ops;
546 extern vdev_ops_t vdev_spare_ops;
547 extern vdev_ops_t vdev_indirect_ops;
548 
549 /*
550  * Common size functions
551  */
552 extern void vdev_default_xlate(vdev_t *vd, const range_seg64_t *in,
553     range_seg64_t *out);
554 extern uint64_t vdev_default_asize(vdev_t *vd, uint64_t psize);
555 extern uint64_t vdev_get_min_asize(vdev_t *vd);
556 extern void vdev_set_min_asize(vdev_t *vd);
557 
558 /*
559  * Global variables
560  */
561 extern int zfs_vdev_standard_sm_blksz;
562 /* zdb uses this tunable, so it must be declared here to make lint happy. */
563 extern int zfs_vdev_cache_size;
564 
565 /*
566  * Functions from vdev_indirect.c
567  */
568 extern void vdev_indirect_sync_obsolete(vdev_t *vd, dmu_tx_t *tx);
569 extern boolean_t vdev_indirect_should_condense(vdev_t *vd);
570 extern void spa_condense_indirect_start_sync(vdev_t *vd, dmu_tx_t *tx);
571 extern int vdev_obsolete_sm_object(vdev_t *vd);
572 extern boolean_t vdev_obsolete_counts_are_precise(vdev_t *vd);
573 
574 /*
575  * Other miscellaneous functions
576  */
577 int vdev_checkpoint_sm_object(vdev_t *vd);
578 
579 /*
580  * The vdev_buf_t is used to translate between zio_t and buf_t, and back again.
581  */
582 typedef struct vdev_buf {
583 	buf_t	vb_buf;		/* buffer that describes the io */
584 	zio_t	*vb_io;		/* pointer back to the original zio_t */
585 } vdev_buf_t;
586 
587 /*
588  * Support routines used during boot from a ZFS pool
589  */
590 extern int vdev_disk_read_rootlabel(const char *, const char *, nvlist_t **);
591 extern void vdev_disk_preroot_init(void);
592 extern void vdev_disk_preroot_fini(void);
593 extern const char *vdev_disk_preroot_lookup(uint64_t, uint64_t);
594 
595 #ifdef	__cplusplus
596 }
597 #endif
598 
599 #endif	/* _SYS_VDEV_IMPL_H */
600