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