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