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