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.
8 * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
9 * or https://opensource.org/licenses/CDDL-1.0.
10 * See the License for the specific language governing permissions
11 * and limitations under the License.
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]
23 * Copyright (c) 2005, 2010, Oracle and/or its affiliates. All rights reserved.
24 * Copyright (c) 2011, 2021 by Delphix. All rights reserved.
25 * Copyright 2017 Nexenta Systems, Inc.
26 * Copyright (c) 2014 Integros [integros.com]
27 * Copyright 2016 Toomas Soome <tsoome@me.com>
28 * Copyright 2017 Joyent, Inc.
29 * Copyright (c) 2017, Intel Corporation.
30 * Copyright (c) 2019, Datto Inc. All rights reserved.
31 * Copyright (c) 2021, Klara Inc.
32 * Copyright (c) 2021, 2023 Hewlett Packard Enterprise Development LP.
35 #include <sys/zfs_context.h>
36 #include <sys/fm/fs/zfs.h>
38 #include <sys/spa_impl.h>
39 #include <sys/bpobj.h>
41 #include <sys/dmu_tx.h>
42 #include <sys/dsl_dir.h>
43 #include <sys/vdev_impl.h>
44 #include <sys/vdev_rebuild.h>
45 #include <sys/vdev_draid.h>
46 #include <sys/uberblock_impl.h>
47 #include <sys/metaslab.h>
48 #include <sys/metaslab_impl.h>
49 #include <sys/space_map.h>
50 #include <sys/space_reftree.h>
53 #include <sys/fs/zfs.h>
56 #include <sys/dsl_scan.h>
57 #include <sys/vdev_raidz.h>
59 #include <sys/vdev_initialize.h>
60 #include <sys/vdev_trim.h>
61 #include <sys/vdev_raidz.h>
63 #include <sys/zfs_ratelimit.h>
67 * One metaslab from each (normal-class) vdev is used by the ZIL. These are
68 * called "embedded slog metaslabs", are referenced by vdev_log_mg, and are
69 * part of the spa_embedded_log_class. The metaslab with the most free space
70 * in each vdev is selected for this purpose when the pool is opened (or a
71 * vdev is added). See vdev_metaslab_init().
73 * Log blocks can be allocated from the following locations. Each one is tried
74 * in order until the allocation succeeds:
75 * 1. dedicated log vdevs, aka "slog" (spa_log_class)
76 * 2. embedded slog metaslabs (spa_embedded_log_class)
77 * 3. other metaslabs in normal vdevs (spa_normal_class)
79 * zfs_embedded_slog_min_ms disables the embedded slog if there are fewer
80 * than this number of metaslabs in the vdev. This ensures that we don't set
81 * aside an unreasonable amount of space for the ZIL. If set to less than
82 * 1 << (spa_slop_shift + 1), on small pools the usable space may be reduced
83 * (by more than 1<<spa_slop_shift) due to the embedded slog metaslab.
85 static uint_t zfs_embedded_slog_min_ms
= 64;
87 /* default target for number of metaslabs per top-level vdev */
88 static uint_t zfs_vdev_default_ms_count
= 200;
90 /* minimum number of metaslabs per top-level vdev */
91 static uint_t zfs_vdev_min_ms_count
= 16;
93 /* practical upper limit of total metaslabs per top-level vdev */
94 static uint_t zfs_vdev_ms_count_limit
= 1ULL << 17;
96 /* lower limit for metaslab size (512M) */
97 static uint_t zfs_vdev_default_ms_shift
= 29;
99 /* upper limit for metaslab size (16G) */
100 static uint_t zfs_vdev_max_ms_shift
= 34;
102 int vdev_validate_skip
= B_FALSE
;
105 * Since the DTL space map of a vdev is not expected to have a lot of
106 * entries, we default its block size to 4K.
108 int zfs_vdev_dtl_sm_blksz
= (1 << 12);
111 * Rate limit slow IO (delay) events to this many per second.
113 static unsigned int zfs_slow_io_events_per_second
= 20;
116 * Rate limit checksum events after this many checksum errors per second.
118 static unsigned int zfs_checksum_events_per_second
= 20;
121 * Ignore errors during scrub/resilver. Allows to work around resilver
122 * upon import when there are pool errors.
124 static int zfs_scan_ignore_errors
= 0;
127 * vdev-wide space maps that have lots of entries written to them at
128 * the end of each transaction can benefit from a higher I/O bandwidth
129 * (e.g. vdev_obsolete_sm), thus we default their block size to 128K.
131 int zfs_vdev_standard_sm_blksz
= (1 << 17);
134 * Tunable parameter for debugging or performance analysis. Setting this
135 * will cause pool corruption on power loss if a volatile out-of-order
136 * write cache is enabled.
138 int zfs_nocacheflush
= 0;
141 * Maximum and minimum ashift values that can be automatically set based on
142 * vdev's physical ashift (disk's physical sector size). While ASHIFT_MAX
143 * is higher than the maximum value, it is intentionally limited here to not
144 * excessively impact pool space efficiency. Higher ashift values may still
145 * be forced by vdev logical ashift or by user via ashift property, but won't
146 * be set automatically as a performance optimization.
148 uint_t zfs_vdev_max_auto_ashift
= 14;
149 uint_t zfs_vdev_min_auto_ashift
= ASHIFT_MIN
;
152 vdev_dbgmsg(vdev_t
*vd
, const char *fmt
, ...)
158 (void) vsnprintf(buf
, sizeof (buf
), fmt
, adx
);
161 if (vd
->vdev_path
!= NULL
) {
162 zfs_dbgmsg("%s vdev '%s': %s", vd
->vdev_ops
->vdev_op_type
,
165 zfs_dbgmsg("%s-%llu vdev (guid %llu): %s",
166 vd
->vdev_ops
->vdev_op_type
,
167 (u_longlong_t
)vd
->vdev_id
,
168 (u_longlong_t
)vd
->vdev_guid
, buf
);
173 vdev_dbgmsg_print_tree(vdev_t
*vd
, int indent
)
177 if (vd
->vdev_ishole
|| vd
->vdev_ops
== &vdev_missing_ops
) {
178 zfs_dbgmsg("%*svdev %llu: %s", indent
, "",
179 (u_longlong_t
)vd
->vdev_id
,
180 vd
->vdev_ops
->vdev_op_type
);
184 switch (vd
->vdev_state
) {
185 case VDEV_STATE_UNKNOWN
:
186 (void) snprintf(state
, sizeof (state
), "unknown");
188 case VDEV_STATE_CLOSED
:
189 (void) snprintf(state
, sizeof (state
), "closed");
191 case VDEV_STATE_OFFLINE
:
192 (void) snprintf(state
, sizeof (state
), "offline");
194 case VDEV_STATE_REMOVED
:
195 (void) snprintf(state
, sizeof (state
), "removed");
197 case VDEV_STATE_CANT_OPEN
:
198 (void) snprintf(state
, sizeof (state
), "can't open");
200 case VDEV_STATE_FAULTED
:
201 (void) snprintf(state
, sizeof (state
), "faulted");
203 case VDEV_STATE_DEGRADED
:
204 (void) snprintf(state
, sizeof (state
), "degraded");
206 case VDEV_STATE_HEALTHY
:
207 (void) snprintf(state
, sizeof (state
), "healthy");
210 (void) snprintf(state
, sizeof (state
), "<state %u>",
211 (uint_t
)vd
->vdev_state
);
214 zfs_dbgmsg("%*svdev %u: %s%s, guid: %llu, path: %s, %s", indent
,
215 "", (int)vd
->vdev_id
, vd
->vdev_ops
->vdev_op_type
,
216 vd
->vdev_islog
? " (log)" : "",
217 (u_longlong_t
)vd
->vdev_guid
,
218 vd
->vdev_path
? vd
->vdev_path
: "N/A", state
);
220 for (uint64_t i
= 0; i
< vd
->vdev_children
; i
++)
221 vdev_dbgmsg_print_tree(vd
->vdev_child
[i
], indent
+ 2);
225 * Virtual device management.
228 static vdev_ops_t
*const vdev_ops_table
[] = {
232 &vdev_draid_spare_ops
,
245 * Given a vdev type, return the appropriate ops vector.
248 vdev_getops(const char *type
)
250 vdev_ops_t
*ops
, *const *opspp
;
252 for (opspp
= vdev_ops_table
; (ops
= *opspp
) != NULL
; opspp
++)
253 if (strcmp(ops
->vdev_op_type
, type
) == 0)
260 * Given a vdev and a metaslab class, find which metaslab group we're
261 * interested in. All vdevs may belong to two different metaslab classes.
262 * Dedicated slog devices use only the primary metaslab group, rather than a
263 * separate log group. For embedded slogs, the vdev_log_mg will be non-NULL.
266 vdev_get_mg(vdev_t
*vd
, metaslab_class_t
*mc
)
268 if (mc
== spa_embedded_log_class(vd
->vdev_spa
) &&
269 vd
->vdev_log_mg
!= NULL
)
270 return (vd
->vdev_log_mg
);
272 return (vd
->vdev_mg
);
276 vdev_default_xlate(vdev_t
*vd
, const range_seg64_t
*logical_rs
,
277 range_seg64_t
*physical_rs
, range_seg64_t
*remain_rs
)
279 (void) vd
, (void) remain_rs
;
281 physical_rs
->rs_start
= logical_rs
->rs_start
;
282 physical_rs
->rs_end
= logical_rs
->rs_end
;
286 * Derive the enumerated allocation bias from string input.
287 * String origin is either the per-vdev zap or zpool(8).
289 static vdev_alloc_bias_t
290 vdev_derive_alloc_bias(const char *bias
)
292 vdev_alloc_bias_t alloc_bias
= VDEV_BIAS_NONE
;
294 if (strcmp(bias
, VDEV_ALLOC_BIAS_LOG
) == 0)
295 alloc_bias
= VDEV_BIAS_LOG
;
296 else if (strcmp(bias
, VDEV_ALLOC_BIAS_SPECIAL
) == 0)
297 alloc_bias
= VDEV_BIAS_SPECIAL
;
298 else if (strcmp(bias
, VDEV_ALLOC_BIAS_DEDUP
) == 0)
299 alloc_bias
= VDEV_BIAS_DEDUP
;
305 * Default asize function: return the MAX of psize with the asize of
306 * all children. This is what's used by anything other than RAID-Z.
309 vdev_default_asize(vdev_t
*vd
, uint64_t psize
, uint64_t txg
)
311 uint64_t asize
= P2ROUNDUP(psize
, 1ULL << vd
->vdev_top
->vdev_ashift
);
314 for (int c
= 0; c
< vd
->vdev_children
; c
++) {
315 csize
= vdev_psize_to_asize_txg(vd
->vdev_child
[c
], psize
, txg
);
316 asize
= MAX(asize
, csize
);
323 vdev_default_min_asize(vdev_t
*vd
)
325 return (vd
->vdev_min_asize
);
329 * Get the minimum allocatable size. We define the allocatable size as
330 * the vdev's asize rounded to the nearest metaslab. This allows us to
331 * replace or attach devices which don't have the same physical size but
332 * can still satisfy the same number of allocations.
335 vdev_get_min_asize(vdev_t
*vd
)
337 vdev_t
*pvd
= vd
->vdev_parent
;
340 * If our parent is NULL (inactive spare or cache) or is the root,
341 * just return our own asize.
344 return (vd
->vdev_asize
);
347 * The top-level vdev just returns the allocatable size rounded
348 * to the nearest metaslab.
350 if (vd
== vd
->vdev_top
)
351 return (P2ALIGN(vd
->vdev_asize
, 1ULL << vd
->vdev_ms_shift
));
353 return (pvd
->vdev_ops
->vdev_op_min_asize(pvd
));
357 vdev_set_min_asize(vdev_t
*vd
)
359 vd
->vdev_min_asize
= vdev_get_min_asize(vd
);
361 for (int c
= 0; c
< vd
->vdev_children
; c
++)
362 vdev_set_min_asize(vd
->vdev_child
[c
]);
366 * Get the minimal allocation size for the top-level vdev.
369 vdev_get_min_alloc(vdev_t
*vd
)
371 uint64_t min_alloc
= 1ULL << vd
->vdev_ashift
;
373 if (vd
->vdev_ops
->vdev_op_min_alloc
!= NULL
)
374 min_alloc
= vd
->vdev_ops
->vdev_op_min_alloc(vd
);
380 * Get the parity level for a top-level vdev.
383 vdev_get_nparity(vdev_t
*vd
)
385 uint64_t nparity
= 0;
387 if (vd
->vdev_ops
->vdev_op_nparity
!= NULL
)
388 nparity
= vd
->vdev_ops
->vdev_op_nparity(vd
);
394 vdev_prop_get_int(vdev_t
*vd
, vdev_prop_t prop
, uint64_t *value
)
396 spa_t
*spa
= vd
->vdev_spa
;
397 objset_t
*mos
= spa
->spa_meta_objset
;
401 if (vd
->vdev_root_zap
!= 0) {
402 objid
= vd
->vdev_root_zap
;
403 } else if (vd
->vdev_top_zap
!= 0) {
404 objid
= vd
->vdev_top_zap
;
405 } else if (vd
->vdev_leaf_zap
!= 0) {
406 objid
= vd
->vdev_leaf_zap
;
411 err
= zap_lookup(mos
, objid
, vdev_prop_to_name(prop
),
412 sizeof (uint64_t), 1, value
);
415 *value
= vdev_prop_default_numeric(prop
);
421 * Get the number of data disks for a top-level vdev.
424 vdev_get_ndisks(vdev_t
*vd
)
428 if (vd
->vdev_ops
->vdev_op_ndisks
!= NULL
)
429 ndisks
= vd
->vdev_ops
->vdev_op_ndisks(vd
);
435 vdev_lookup_top(spa_t
*spa
, uint64_t vdev
)
437 vdev_t
*rvd
= spa
->spa_root_vdev
;
439 ASSERT(spa_config_held(spa
, SCL_ALL
, RW_READER
) != 0);
441 if (vdev
< rvd
->vdev_children
) {
442 ASSERT(rvd
->vdev_child
[vdev
] != NULL
);
443 return (rvd
->vdev_child
[vdev
]);
450 vdev_lookup_by_guid(vdev_t
*vd
, uint64_t guid
)
454 if (vd
->vdev_guid
== guid
)
457 for (int c
= 0; c
< vd
->vdev_children
; c
++)
458 if ((mvd
= vdev_lookup_by_guid(vd
->vdev_child
[c
], guid
)) !=
466 vdev_count_leaves_impl(vdev_t
*vd
)
470 if (vd
->vdev_ops
->vdev_op_leaf
)
473 for (int c
= 0; c
< vd
->vdev_children
; c
++)
474 n
+= vdev_count_leaves_impl(vd
->vdev_child
[c
]);
480 vdev_count_leaves(spa_t
*spa
)
484 spa_config_enter(spa
, SCL_VDEV
, FTAG
, RW_READER
);
485 rc
= vdev_count_leaves_impl(spa
->spa_root_vdev
);
486 spa_config_exit(spa
, SCL_VDEV
, FTAG
);
492 vdev_add_child(vdev_t
*pvd
, vdev_t
*cvd
)
494 size_t oldsize
, newsize
;
495 uint64_t id
= cvd
->vdev_id
;
498 ASSERT(spa_config_held(cvd
->vdev_spa
, SCL_ALL
, RW_WRITER
) == SCL_ALL
);
499 ASSERT(cvd
->vdev_parent
== NULL
);
501 cvd
->vdev_parent
= pvd
;
506 ASSERT(id
>= pvd
->vdev_children
|| pvd
->vdev_child
[id
] == NULL
);
508 oldsize
= pvd
->vdev_children
* sizeof (vdev_t
*);
509 pvd
->vdev_children
= MAX(pvd
->vdev_children
, id
+ 1);
510 newsize
= pvd
->vdev_children
* sizeof (vdev_t
*);
512 newchild
= kmem_alloc(newsize
, KM_SLEEP
);
513 if (pvd
->vdev_child
!= NULL
) {
514 memcpy(newchild
, pvd
->vdev_child
, oldsize
);
515 kmem_free(pvd
->vdev_child
, oldsize
);
518 pvd
->vdev_child
= newchild
;
519 pvd
->vdev_child
[id
] = cvd
;
521 cvd
->vdev_top
= (pvd
->vdev_top
? pvd
->vdev_top
: cvd
);
522 ASSERT(cvd
->vdev_top
->vdev_parent
->vdev_parent
== NULL
);
525 * Walk up all ancestors to update guid sum.
527 for (; pvd
!= NULL
; pvd
= pvd
->vdev_parent
)
528 pvd
->vdev_guid_sum
+= cvd
->vdev_guid_sum
;
530 if (cvd
->vdev_ops
->vdev_op_leaf
) {
531 list_insert_head(&cvd
->vdev_spa
->spa_leaf_list
, cvd
);
532 cvd
->vdev_spa
->spa_leaf_list_gen
++;
537 vdev_remove_child(vdev_t
*pvd
, vdev_t
*cvd
)
540 uint_t id
= cvd
->vdev_id
;
542 ASSERT(cvd
->vdev_parent
== pvd
);
547 ASSERT(id
< pvd
->vdev_children
);
548 ASSERT(pvd
->vdev_child
[id
] == cvd
);
550 pvd
->vdev_child
[id
] = NULL
;
551 cvd
->vdev_parent
= NULL
;
553 for (c
= 0; c
< pvd
->vdev_children
; c
++)
554 if (pvd
->vdev_child
[c
])
557 if (c
== pvd
->vdev_children
) {
558 kmem_free(pvd
->vdev_child
, c
* sizeof (vdev_t
*));
559 pvd
->vdev_child
= NULL
;
560 pvd
->vdev_children
= 0;
563 if (cvd
->vdev_ops
->vdev_op_leaf
) {
564 spa_t
*spa
= cvd
->vdev_spa
;
565 list_remove(&spa
->spa_leaf_list
, cvd
);
566 spa
->spa_leaf_list_gen
++;
570 * Walk up all ancestors to update guid sum.
572 for (; pvd
!= NULL
; pvd
= pvd
->vdev_parent
)
573 pvd
->vdev_guid_sum
-= cvd
->vdev_guid_sum
;
577 * Remove any holes in the child array.
580 vdev_compact_children(vdev_t
*pvd
)
582 vdev_t
**newchild
, *cvd
;
583 int oldc
= pvd
->vdev_children
;
586 ASSERT(spa_config_held(pvd
->vdev_spa
, SCL_ALL
, RW_WRITER
) == SCL_ALL
);
591 for (int c
= newc
= 0; c
< oldc
; c
++)
592 if (pvd
->vdev_child
[c
])
596 newchild
= kmem_zalloc(newc
* sizeof (vdev_t
*), KM_SLEEP
);
598 for (int c
= newc
= 0; c
< oldc
; c
++) {
599 if ((cvd
= pvd
->vdev_child
[c
]) != NULL
) {
600 newchild
[newc
] = cvd
;
601 cvd
->vdev_id
= newc
++;
608 kmem_free(pvd
->vdev_child
, oldc
* sizeof (vdev_t
*));
609 pvd
->vdev_child
= newchild
;
610 pvd
->vdev_children
= newc
;
614 * Allocate and minimally initialize a vdev_t.
617 vdev_alloc_common(spa_t
*spa
, uint_t id
, uint64_t guid
, vdev_ops_t
*ops
)
620 vdev_indirect_config_t
*vic
;
622 vd
= kmem_zalloc(sizeof (vdev_t
), KM_SLEEP
);
623 vic
= &vd
->vdev_indirect_config
;
625 if (spa
->spa_root_vdev
== NULL
) {
626 ASSERT(ops
== &vdev_root_ops
);
627 spa
->spa_root_vdev
= vd
;
628 spa
->spa_load_guid
= spa_generate_guid(NULL
);
631 if (guid
== 0 && ops
!= &vdev_hole_ops
) {
632 if (spa
->spa_root_vdev
== vd
) {
634 * The root vdev's guid will also be the pool guid,
635 * which must be unique among all pools.
637 guid
= spa_generate_guid(NULL
);
640 * Any other vdev's guid must be unique within the pool.
642 guid
= spa_generate_guid(spa
);
644 ASSERT(!spa_guid_exists(spa_guid(spa
), guid
));
649 vd
->vdev_guid
= guid
;
650 vd
->vdev_guid_sum
= guid
;
652 vd
->vdev_state
= VDEV_STATE_CLOSED
;
653 vd
->vdev_ishole
= (ops
== &vdev_hole_ops
);
654 vic
->vic_prev_indirect_vdev
= UINT64_MAX
;
656 rw_init(&vd
->vdev_indirect_rwlock
, NULL
, RW_DEFAULT
, NULL
);
657 mutex_init(&vd
->vdev_obsolete_lock
, NULL
, MUTEX_DEFAULT
, NULL
);
658 vd
->vdev_obsolete_segments
= range_tree_create(NULL
, RANGE_SEG64
, NULL
,
662 * Initialize rate limit structs for events. We rate limit ZIO delay
663 * and checksum events so that we don't overwhelm ZED with thousands
664 * of events when a disk is acting up.
666 zfs_ratelimit_init(&vd
->vdev_delay_rl
, &zfs_slow_io_events_per_second
,
668 zfs_ratelimit_init(&vd
->vdev_deadman_rl
, &zfs_slow_io_events_per_second
,
670 zfs_ratelimit_init(&vd
->vdev_checksum_rl
,
671 &zfs_checksum_events_per_second
, 1);
674 * Default Thresholds for tuning ZED
676 vd
->vdev_checksum_n
= vdev_prop_default_numeric(VDEV_PROP_CHECKSUM_N
);
677 vd
->vdev_checksum_t
= vdev_prop_default_numeric(VDEV_PROP_CHECKSUM_T
);
678 vd
->vdev_io_n
= vdev_prop_default_numeric(VDEV_PROP_IO_N
);
679 vd
->vdev_io_t
= vdev_prop_default_numeric(VDEV_PROP_IO_T
);
681 list_link_init(&vd
->vdev_config_dirty_node
);
682 list_link_init(&vd
->vdev_state_dirty_node
);
683 list_link_init(&vd
->vdev_initialize_node
);
684 list_link_init(&vd
->vdev_leaf_node
);
685 list_link_init(&vd
->vdev_trim_node
);
687 mutex_init(&vd
->vdev_dtl_lock
, NULL
, MUTEX_NOLOCKDEP
, NULL
);
688 mutex_init(&vd
->vdev_stat_lock
, NULL
, MUTEX_DEFAULT
, NULL
);
689 mutex_init(&vd
->vdev_probe_lock
, NULL
, MUTEX_DEFAULT
, NULL
);
690 mutex_init(&vd
->vdev_scan_io_queue_lock
, NULL
, MUTEX_DEFAULT
, NULL
);
692 mutex_init(&vd
->vdev_initialize_lock
, NULL
, MUTEX_DEFAULT
, NULL
);
693 mutex_init(&vd
->vdev_initialize_io_lock
, NULL
, MUTEX_DEFAULT
, NULL
);
694 cv_init(&vd
->vdev_initialize_cv
, NULL
, CV_DEFAULT
, NULL
);
695 cv_init(&vd
->vdev_initialize_io_cv
, NULL
, CV_DEFAULT
, NULL
);
697 mutex_init(&vd
->vdev_trim_lock
, NULL
, MUTEX_DEFAULT
, NULL
);
698 mutex_init(&vd
->vdev_autotrim_lock
, NULL
, MUTEX_DEFAULT
, NULL
);
699 mutex_init(&vd
->vdev_trim_io_lock
, NULL
, MUTEX_DEFAULT
, NULL
);
700 cv_init(&vd
->vdev_trim_cv
, NULL
, CV_DEFAULT
, NULL
);
701 cv_init(&vd
->vdev_autotrim_cv
, NULL
, CV_DEFAULT
, NULL
);
702 cv_init(&vd
->vdev_autotrim_kick_cv
, NULL
, CV_DEFAULT
, NULL
);
703 cv_init(&vd
->vdev_trim_io_cv
, NULL
, CV_DEFAULT
, NULL
);
705 mutex_init(&vd
->vdev_rebuild_lock
, NULL
, MUTEX_DEFAULT
, NULL
);
706 cv_init(&vd
->vdev_rebuild_cv
, NULL
, CV_DEFAULT
, NULL
);
708 for (int t
= 0; t
< DTL_TYPES
; t
++) {
709 vd
->vdev_dtl
[t
] = range_tree_create(NULL
, RANGE_SEG64
, NULL
, 0,
713 txg_list_create(&vd
->vdev_ms_list
, spa
,
714 offsetof(struct metaslab
, ms_txg_node
));
715 txg_list_create(&vd
->vdev_dtl_list
, spa
,
716 offsetof(struct vdev
, vdev_dtl_node
));
717 vd
->vdev_stat
.vs_timestamp
= gethrtime();
724 * Allocate a new vdev. The 'alloctype' is used to control whether we are
725 * creating a new vdev or loading an existing one - the behavior is slightly
726 * different for each case.
729 vdev_alloc(spa_t
*spa
, vdev_t
**vdp
, nvlist_t
*nv
, vdev_t
*parent
, uint_t id
,
734 uint64_t guid
= 0, islog
;
736 vdev_indirect_config_t
*vic
;
737 const char *tmp
= NULL
;
739 vdev_alloc_bias_t alloc_bias
= VDEV_BIAS_NONE
;
740 boolean_t top_level
= (parent
&& !parent
->vdev_parent
);
742 ASSERT(spa_config_held(spa
, SCL_ALL
, RW_WRITER
) == SCL_ALL
);
744 if (nvlist_lookup_string(nv
, ZPOOL_CONFIG_TYPE
, &type
) != 0)
745 return (SET_ERROR(EINVAL
));
747 if ((ops
= vdev_getops(type
)) == NULL
)
748 return (SET_ERROR(EINVAL
));
751 * If this is a load, get the vdev guid from the nvlist.
752 * Otherwise, vdev_alloc_common() will generate one for us.
754 if (alloctype
== VDEV_ALLOC_LOAD
) {
757 if (nvlist_lookup_uint64(nv
, ZPOOL_CONFIG_ID
, &label_id
) ||
759 return (SET_ERROR(EINVAL
));
761 if (nvlist_lookup_uint64(nv
, ZPOOL_CONFIG_GUID
, &guid
) != 0)
762 return (SET_ERROR(EINVAL
));
763 } else if (alloctype
== VDEV_ALLOC_SPARE
) {
764 if (nvlist_lookup_uint64(nv
, ZPOOL_CONFIG_GUID
, &guid
) != 0)
765 return (SET_ERROR(EINVAL
));
766 } else if (alloctype
== VDEV_ALLOC_L2CACHE
) {
767 if (nvlist_lookup_uint64(nv
, ZPOOL_CONFIG_GUID
, &guid
) != 0)
768 return (SET_ERROR(EINVAL
));
769 } else if (alloctype
== VDEV_ALLOC_ROOTPOOL
) {
770 if (nvlist_lookup_uint64(nv
, ZPOOL_CONFIG_GUID
, &guid
) != 0)
771 return (SET_ERROR(EINVAL
));
775 * The first allocated vdev must be of type 'root'.
777 if (ops
!= &vdev_root_ops
&& spa
->spa_root_vdev
== NULL
)
778 return (SET_ERROR(EINVAL
));
781 * Determine whether we're a log vdev.
784 (void) nvlist_lookup_uint64(nv
, ZPOOL_CONFIG_IS_LOG
, &islog
);
785 if (islog
&& spa_version(spa
) < SPA_VERSION_SLOGS
)
786 return (SET_ERROR(ENOTSUP
));
788 if (ops
== &vdev_hole_ops
&& spa_version(spa
) < SPA_VERSION_HOLES
)
789 return (SET_ERROR(ENOTSUP
));
791 if (top_level
&& alloctype
== VDEV_ALLOC_ADD
) {
795 * If creating a top-level vdev, check for allocation
798 if (nvlist_lookup_string(nv
, ZPOOL_CONFIG_ALLOCATION_BIAS
,
800 alloc_bias
= vdev_derive_alloc_bias(bias
);
802 /* spa_vdev_add() expects feature to be enabled */
803 if (spa
->spa_load_state
!= SPA_LOAD_CREATE
&&
804 !spa_feature_is_enabled(spa
,
805 SPA_FEATURE_ALLOCATION_CLASSES
)) {
806 return (SET_ERROR(ENOTSUP
));
810 /* spa_vdev_add() expects feature to be enabled */
811 if (ops
== &vdev_draid_ops
&&
812 spa
->spa_load_state
!= SPA_LOAD_CREATE
&&
813 !spa_feature_is_enabled(spa
, SPA_FEATURE_DRAID
)) {
814 return (SET_ERROR(ENOTSUP
));
819 * Initialize the vdev specific data. This is done before calling
820 * vdev_alloc_common() since it may fail and this simplifies the
821 * error reporting and cleanup code paths.
824 if (ops
->vdev_op_init
!= NULL
) {
825 rc
= ops
->vdev_op_init(spa
, nv
, &tsd
);
831 vd
= vdev_alloc_common(spa
, id
, guid
, ops
);
833 vd
->vdev_islog
= islog
;
835 if (top_level
&& alloc_bias
!= VDEV_BIAS_NONE
)
836 vd
->vdev_alloc_bias
= alloc_bias
;
838 if (nvlist_lookup_string(nv
, ZPOOL_CONFIG_PATH
, &tmp
) == 0)
839 vd
->vdev_path
= spa_strdup(tmp
);
842 * ZPOOL_CONFIG_AUX_STATE = "external" means we previously forced a
843 * fault on a vdev and want it to persist across imports (like with
846 rc
= nvlist_lookup_string(nv
, ZPOOL_CONFIG_AUX_STATE
, &tmp
);
847 if (rc
== 0 && tmp
!= NULL
&& strcmp(tmp
, "external") == 0) {
848 vd
->vdev_stat
.vs_aux
= VDEV_AUX_EXTERNAL
;
849 vd
->vdev_faulted
= 1;
850 vd
->vdev_label_aux
= VDEV_AUX_EXTERNAL
;
853 if (nvlist_lookup_string(nv
, ZPOOL_CONFIG_DEVID
, &tmp
) == 0)
854 vd
->vdev_devid
= spa_strdup(tmp
);
855 if (nvlist_lookup_string(nv
, ZPOOL_CONFIG_PHYS_PATH
, &tmp
) == 0)
856 vd
->vdev_physpath
= spa_strdup(tmp
);
858 if (nvlist_lookup_string(nv
, ZPOOL_CONFIG_VDEV_ENC_SYSFS_PATH
,
860 vd
->vdev_enc_sysfs_path
= spa_strdup(tmp
);
862 if (nvlist_lookup_string(nv
, ZPOOL_CONFIG_FRU
, &tmp
) == 0)
863 vd
->vdev_fru
= spa_strdup(tmp
);
866 * Set the whole_disk property. If it's not specified, leave the value
869 if (nvlist_lookup_uint64(nv
, ZPOOL_CONFIG_WHOLE_DISK
,
870 &vd
->vdev_wholedisk
) != 0)
871 vd
->vdev_wholedisk
= -1ULL;
873 vic
= &vd
->vdev_indirect_config
;
875 ASSERT0(vic
->vic_mapping_object
);
876 (void) nvlist_lookup_uint64(nv
, ZPOOL_CONFIG_INDIRECT_OBJECT
,
877 &vic
->vic_mapping_object
);
878 ASSERT0(vic
->vic_births_object
);
879 (void) nvlist_lookup_uint64(nv
, ZPOOL_CONFIG_INDIRECT_BIRTHS
,
880 &vic
->vic_births_object
);
881 ASSERT3U(vic
->vic_prev_indirect_vdev
, ==, UINT64_MAX
);
882 (void) nvlist_lookup_uint64(nv
, ZPOOL_CONFIG_PREV_INDIRECT_VDEV
,
883 &vic
->vic_prev_indirect_vdev
);
886 * Look for the 'not present' flag. This will only be set if the device
887 * was not present at the time of import.
889 (void) nvlist_lookup_uint64(nv
, ZPOOL_CONFIG_NOT_PRESENT
,
890 &vd
->vdev_not_present
);
893 * Get the alignment requirement. Ignore pool ashift for vdev
896 if (alloctype
!= VDEV_ALLOC_ATTACH
) {
897 (void) nvlist_lookup_uint64(nv
, ZPOOL_CONFIG_ASHIFT
,
900 vd
->vdev_attaching
= B_TRUE
;
904 * Retrieve the vdev creation time.
906 (void) nvlist_lookup_uint64(nv
, ZPOOL_CONFIG_CREATE_TXG
,
909 if (vd
->vdev_ops
== &vdev_root_ops
&&
910 (alloctype
== VDEV_ALLOC_LOAD
||
911 alloctype
== VDEV_ALLOC_SPLIT
||
912 alloctype
== VDEV_ALLOC_ROOTPOOL
)) {
913 (void) nvlist_lookup_uint64(nv
, ZPOOL_CONFIG_VDEV_ROOT_ZAP
,
918 * If we're a top-level vdev, try to load the allocation parameters.
921 (alloctype
== VDEV_ALLOC_LOAD
|| alloctype
== VDEV_ALLOC_SPLIT
)) {
922 (void) nvlist_lookup_uint64(nv
, ZPOOL_CONFIG_METASLAB_ARRAY
,
924 (void) nvlist_lookup_uint64(nv
, ZPOOL_CONFIG_METASLAB_SHIFT
,
926 (void) nvlist_lookup_uint64(nv
, ZPOOL_CONFIG_ASIZE
,
928 (void) nvlist_lookup_uint64(nv
, ZPOOL_CONFIG_NONALLOCATING
,
930 (void) nvlist_lookup_uint64(nv
, ZPOOL_CONFIG_REMOVING
,
932 (void) nvlist_lookup_uint64(nv
, ZPOOL_CONFIG_VDEV_TOP_ZAP
,
934 vd
->vdev_rz_expanding
= nvlist_exists(nv
,
935 ZPOOL_CONFIG_RAIDZ_EXPANDING
);
937 ASSERT0(vd
->vdev_top_zap
);
940 if (top_level
&& alloctype
!= VDEV_ALLOC_ATTACH
) {
941 ASSERT(alloctype
== VDEV_ALLOC_LOAD
||
942 alloctype
== VDEV_ALLOC_ADD
||
943 alloctype
== VDEV_ALLOC_SPLIT
||
944 alloctype
== VDEV_ALLOC_ROOTPOOL
);
945 /* Note: metaslab_group_create() is now deferred */
948 if (vd
->vdev_ops
->vdev_op_leaf
&&
949 (alloctype
== VDEV_ALLOC_LOAD
|| alloctype
== VDEV_ALLOC_SPLIT
)) {
950 (void) nvlist_lookup_uint64(nv
,
951 ZPOOL_CONFIG_VDEV_LEAF_ZAP
, &vd
->vdev_leaf_zap
);
953 ASSERT0(vd
->vdev_leaf_zap
);
957 * If we're a leaf vdev, try to load the DTL object and other state.
960 if (vd
->vdev_ops
->vdev_op_leaf
&&
961 (alloctype
== VDEV_ALLOC_LOAD
|| alloctype
== VDEV_ALLOC_L2CACHE
||
962 alloctype
== VDEV_ALLOC_ROOTPOOL
)) {
963 if (alloctype
== VDEV_ALLOC_LOAD
) {
964 (void) nvlist_lookup_uint64(nv
, ZPOOL_CONFIG_DTL
,
965 &vd
->vdev_dtl_object
);
966 (void) nvlist_lookup_uint64(nv
, ZPOOL_CONFIG_UNSPARE
,
970 if (alloctype
== VDEV_ALLOC_ROOTPOOL
) {
973 if (nvlist_lookup_uint64(nv
, ZPOOL_CONFIG_IS_SPARE
,
974 &spare
) == 0 && spare
)
978 (void) nvlist_lookup_uint64(nv
, ZPOOL_CONFIG_OFFLINE
,
981 (void) nvlist_lookup_uint64(nv
, ZPOOL_CONFIG_RESILVER_TXG
,
982 &vd
->vdev_resilver_txg
);
984 (void) nvlist_lookup_uint64(nv
, ZPOOL_CONFIG_REBUILD_TXG
,
985 &vd
->vdev_rebuild_txg
);
987 if (nvlist_exists(nv
, ZPOOL_CONFIG_RESILVER_DEFER
))
988 vdev_defer_resilver(vd
);
991 * In general, when importing a pool we want to ignore the
992 * persistent fault state, as the diagnosis made on another
993 * system may not be valid in the current context. The only
994 * exception is if we forced a vdev to a persistently faulted
995 * state with 'zpool offline -f'. The persistent fault will
996 * remain across imports until cleared.
998 * Local vdevs will remain in the faulted state.
1000 if (spa_load_state(spa
) == SPA_LOAD_OPEN
||
1001 spa_load_state(spa
) == SPA_LOAD_IMPORT
) {
1002 (void) nvlist_lookup_uint64(nv
, ZPOOL_CONFIG_FAULTED
,
1004 (void) nvlist_lookup_uint64(nv
, ZPOOL_CONFIG_DEGRADED
,
1005 &vd
->vdev_degraded
);
1006 (void) nvlist_lookup_uint64(nv
, ZPOOL_CONFIG_REMOVED
,
1009 if (vd
->vdev_faulted
|| vd
->vdev_degraded
) {
1012 vd
->vdev_label_aux
=
1013 VDEV_AUX_ERR_EXCEEDED
;
1014 if (nvlist_lookup_string(nv
,
1015 ZPOOL_CONFIG_AUX_STATE
, &aux
) == 0 &&
1016 strcmp(aux
, "external") == 0)
1017 vd
->vdev_label_aux
= VDEV_AUX_EXTERNAL
;
1019 vd
->vdev_faulted
= 0ULL;
1025 * Add ourselves to the parent's list of children.
1027 vdev_add_child(parent
, vd
);
1035 vdev_free(vdev_t
*vd
)
1037 spa_t
*spa
= vd
->vdev_spa
;
1039 ASSERT3P(vd
->vdev_initialize_thread
, ==, NULL
);
1040 ASSERT3P(vd
->vdev_trim_thread
, ==, NULL
);
1041 ASSERT3P(vd
->vdev_autotrim_thread
, ==, NULL
);
1042 ASSERT3P(vd
->vdev_rebuild_thread
, ==, NULL
);
1045 * Scan queues are normally destroyed at the end of a scan. If the
1046 * queue exists here, that implies the vdev is being removed while
1047 * the scan is still running.
1049 if (vd
->vdev_scan_io_queue
!= NULL
) {
1050 mutex_enter(&vd
->vdev_scan_io_queue_lock
);
1051 dsl_scan_io_queue_destroy(vd
->vdev_scan_io_queue
);
1052 vd
->vdev_scan_io_queue
= NULL
;
1053 mutex_exit(&vd
->vdev_scan_io_queue_lock
);
1057 * vdev_free() implies closing the vdev first. This is simpler than
1058 * trying to ensure complicated semantics for all callers.
1062 ASSERT(!list_link_active(&vd
->vdev_config_dirty_node
));
1063 ASSERT(!list_link_active(&vd
->vdev_state_dirty_node
));
1066 * Free all children.
1068 for (int c
= 0; c
< vd
->vdev_children
; c
++)
1069 vdev_free(vd
->vdev_child
[c
]);
1071 ASSERT(vd
->vdev_child
== NULL
);
1072 ASSERT(vd
->vdev_guid_sum
== vd
->vdev_guid
);
1074 if (vd
->vdev_ops
->vdev_op_fini
!= NULL
)
1075 vd
->vdev_ops
->vdev_op_fini(vd
);
1078 * Discard allocation state.
1080 if (vd
->vdev_mg
!= NULL
) {
1081 vdev_metaslab_fini(vd
);
1082 metaslab_group_destroy(vd
->vdev_mg
);
1085 if (vd
->vdev_log_mg
!= NULL
) {
1086 ASSERT0(vd
->vdev_ms_count
);
1087 metaslab_group_destroy(vd
->vdev_log_mg
);
1088 vd
->vdev_log_mg
= NULL
;
1091 ASSERT0(vd
->vdev_stat
.vs_space
);
1092 ASSERT0(vd
->vdev_stat
.vs_dspace
);
1093 ASSERT0(vd
->vdev_stat
.vs_alloc
);
1096 * Remove this vdev from its parent's child list.
1098 vdev_remove_child(vd
->vdev_parent
, vd
);
1100 ASSERT(vd
->vdev_parent
== NULL
);
1101 ASSERT(!list_link_active(&vd
->vdev_leaf_node
));
1104 * Clean up vdev structure.
1106 vdev_queue_fini(vd
);
1109 spa_strfree(vd
->vdev_path
);
1111 spa_strfree(vd
->vdev_devid
);
1112 if (vd
->vdev_physpath
)
1113 spa_strfree(vd
->vdev_physpath
);
1115 if (vd
->vdev_enc_sysfs_path
)
1116 spa_strfree(vd
->vdev_enc_sysfs_path
);
1119 spa_strfree(vd
->vdev_fru
);
1121 if (vd
->vdev_isspare
)
1122 spa_spare_remove(vd
);
1123 if (vd
->vdev_isl2cache
)
1124 spa_l2cache_remove(vd
);
1126 txg_list_destroy(&vd
->vdev_ms_list
);
1127 txg_list_destroy(&vd
->vdev_dtl_list
);
1129 mutex_enter(&vd
->vdev_dtl_lock
);
1130 space_map_close(vd
->vdev_dtl_sm
);
1131 for (int t
= 0; t
< DTL_TYPES
; t
++) {
1132 range_tree_vacate(vd
->vdev_dtl
[t
], NULL
, NULL
);
1133 range_tree_destroy(vd
->vdev_dtl
[t
]);
1135 mutex_exit(&vd
->vdev_dtl_lock
);
1137 EQUIV(vd
->vdev_indirect_births
!= NULL
,
1138 vd
->vdev_indirect_mapping
!= NULL
);
1139 if (vd
->vdev_indirect_births
!= NULL
) {
1140 vdev_indirect_mapping_close(vd
->vdev_indirect_mapping
);
1141 vdev_indirect_births_close(vd
->vdev_indirect_births
);
1144 if (vd
->vdev_obsolete_sm
!= NULL
) {
1145 ASSERT(vd
->vdev_removing
||
1146 vd
->vdev_ops
== &vdev_indirect_ops
);
1147 space_map_close(vd
->vdev_obsolete_sm
);
1148 vd
->vdev_obsolete_sm
= NULL
;
1150 range_tree_destroy(vd
->vdev_obsolete_segments
);
1151 rw_destroy(&vd
->vdev_indirect_rwlock
);
1152 mutex_destroy(&vd
->vdev_obsolete_lock
);
1154 mutex_destroy(&vd
->vdev_dtl_lock
);
1155 mutex_destroy(&vd
->vdev_stat_lock
);
1156 mutex_destroy(&vd
->vdev_probe_lock
);
1157 mutex_destroy(&vd
->vdev_scan_io_queue_lock
);
1159 mutex_destroy(&vd
->vdev_initialize_lock
);
1160 mutex_destroy(&vd
->vdev_initialize_io_lock
);
1161 cv_destroy(&vd
->vdev_initialize_io_cv
);
1162 cv_destroy(&vd
->vdev_initialize_cv
);
1164 mutex_destroy(&vd
->vdev_trim_lock
);
1165 mutex_destroy(&vd
->vdev_autotrim_lock
);
1166 mutex_destroy(&vd
->vdev_trim_io_lock
);
1167 cv_destroy(&vd
->vdev_trim_cv
);
1168 cv_destroy(&vd
->vdev_autotrim_cv
);
1169 cv_destroy(&vd
->vdev_autotrim_kick_cv
);
1170 cv_destroy(&vd
->vdev_trim_io_cv
);
1172 mutex_destroy(&vd
->vdev_rebuild_lock
);
1173 cv_destroy(&vd
->vdev_rebuild_cv
);
1175 zfs_ratelimit_fini(&vd
->vdev_delay_rl
);
1176 zfs_ratelimit_fini(&vd
->vdev_deadman_rl
);
1177 zfs_ratelimit_fini(&vd
->vdev_checksum_rl
);
1179 if (vd
== spa
->spa_root_vdev
)
1180 spa
->spa_root_vdev
= NULL
;
1182 kmem_free(vd
, sizeof (vdev_t
));
1186 * Transfer top-level vdev state from svd to tvd.
1189 vdev_top_transfer(vdev_t
*svd
, vdev_t
*tvd
)
1191 spa_t
*spa
= svd
->vdev_spa
;
1196 ASSERT(tvd
== tvd
->vdev_top
);
1198 tvd
->vdev_ms_array
= svd
->vdev_ms_array
;
1199 tvd
->vdev_ms_shift
= svd
->vdev_ms_shift
;
1200 tvd
->vdev_ms_count
= svd
->vdev_ms_count
;
1201 tvd
->vdev_top_zap
= svd
->vdev_top_zap
;
1203 svd
->vdev_ms_array
= 0;
1204 svd
->vdev_ms_shift
= 0;
1205 svd
->vdev_ms_count
= 0;
1206 svd
->vdev_top_zap
= 0;
1209 ASSERT3P(tvd
->vdev_mg
, ==, svd
->vdev_mg
);
1210 if (tvd
->vdev_log_mg
)
1211 ASSERT3P(tvd
->vdev_log_mg
, ==, svd
->vdev_log_mg
);
1212 tvd
->vdev_mg
= svd
->vdev_mg
;
1213 tvd
->vdev_log_mg
= svd
->vdev_log_mg
;
1214 tvd
->vdev_ms
= svd
->vdev_ms
;
1216 svd
->vdev_mg
= NULL
;
1217 svd
->vdev_log_mg
= NULL
;
1218 svd
->vdev_ms
= NULL
;
1220 if (tvd
->vdev_mg
!= NULL
)
1221 tvd
->vdev_mg
->mg_vd
= tvd
;
1222 if (tvd
->vdev_log_mg
!= NULL
)
1223 tvd
->vdev_log_mg
->mg_vd
= tvd
;
1225 tvd
->vdev_checkpoint_sm
= svd
->vdev_checkpoint_sm
;
1226 svd
->vdev_checkpoint_sm
= NULL
;
1228 tvd
->vdev_alloc_bias
= svd
->vdev_alloc_bias
;
1229 svd
->vdev_alloc_bias
= VDEV_BIAS_NONE
;
1231 tvd
->vdev_stat
.vs_alloc
= svd
->vdev_stat
.vs_alloc
;
1232 tvd
->vdev_stat
.vs_space
= svd
->vdev_stat
.vs_space
;
1233 tvd
->vdev_stat
.vs_dspace
= svd
->vdev_stat
.vs_dspace
;
1235 svd
->vdev_stat
.vs_alloc
= 0;
1236 svd
->vdev_stat
.vs_space
= 0;
1237 svd
->vdev_stat
.vs_dspace
= 0;
1240 * State which may be set on a top-level vdev that's in the
1241 * process of being removed.
1243 ASSERT0(tvd
->vdev_indirect_config
.vic_births_object
);
1244 ASSERT0(tvd
->vdev_indirect_config
.vic_mapping_object
);
1245 ASSERT3U(tvd
->vdev_indirect_config
.vic_prev_indirect_vdev
, ==, -1ULL);
1246 ASSERT3P(tvd
->vdev_indirect_mapping
, ==, NULL
);
1247 ASSERT3P(tvd
->vdev_indirect_births
, ==, NULL
);
1248 ASSERT3P(tvd
->vdev_obsolete_sm
, ==, NULL
);
1249 ASSERT0(tvd
->vdev_noalloc
);
1250 ASSERT0(tvd
->vdev_removing
);
1251 ASSERT0(tvd
->vdev_rebuilding
);
1252 tvd
->vdev_noalloc
= svd
->vdev_noalloc
;
1253 tvd
->vdev_removing
= svd
->vdev_removing
;
1254 tvd
->vdev_rebuilding
= svd
->vdev_rebuilding
;
1255 tvd
->vdev_rebuild_config
= svd
->vdev_rebuild_config
;
1256 tvd
->vdev_indirect_config
= svd
->vdev_indirect_config
;
1257 tvd
->vdev_indirect_mapping
= svd
->vdev_indirect_mapping
;
1258 tvd
->vdev_indirect_births
= svd
->vdev_indirect_births
;
1259 range_tree_swap(&svd
->vdev_obsolete_segments
,
1260 &tvd
->vdev_obsolete_segments
);
1261 tvd
->vdev_obsolete_sm
= svd
->vdev_obsolete_sm
;
1262 svd
->vdev_indirect_config
.vic_mapping_object
= 0;
1263 svd
->vdev_indirect_config
.vic_births_object
= 0;
1264 svd
->vdev_indirect_config
.vic_prev_indirect_vdev
= -1ULL;
1265 svd
->vdev_indirect_mapping
= NULL
;
1266 svd
->vdev_indirect_births
= NULL
;
1267 svd
->vdev_obsolete_sm
= NULL
;
1268 svd
->vdev_noalloc
= 0;
1269 svd
->vdev_removing
= 0;
1270 svd
->vdev_rebuilding
= 0;
1272 for (t
= 0; t
< TXG_SIZE
; t
++) {
1273 while ((msp
= txg_list_remove(&svd
->vdev_ms_list
, t
)) != NULL
)
1274 (void) txg_list_add(&tvd
->vdev_ms_list
, msp
, t
);
1275 while ((vd
= txg_list_remove(&svd
->vdev_dtl_list
, t
)) != NULL
)
1276 (void) txg_list_add(&tvd
->vdev_dtl_list
, vd
, t
);
1277 if (txg_list_remove_this(&spa
->spa_vdev_txg_list
, svd
, t
))
1278 (void) txg_list_add(&spa
->spa_vdev_txg_list
, tvd
, t
);
1281 if (list_link_active(&svd
->vdev_config_dirty_node
)) {
1282 vdev_config_clean(svd
);
1283 vdev_config_dirty(tvd
);
1286 if (list_link_active(&svd
->vdev_state_dirty_node
)) {
1287 vdev_state_clean(svd
);
1288 vdev_state_dirty(tvd
);
1291 tvd
->vdev_deflate_ratio
= svd
->vdev_deflate_ratio
;
1292 svd
->vdev_deflate_ratio
= 0;
1294 tvd
->vdev_islog
= svd
->vdev_islog
;
1295 svd
->vdev_islog
= 0;
1297 dsl_scan_io_queue_vdev_xfer(svd
, tvd
);
1301 vdev_top_update(vdev_t
*tvd
, vdev_t
*vd
)
1308 for (int c
= 0; c
< vd
->vdev_children
; c
++)
1309 vdev_top_update(tvd
, vd
->vdev_child
[c
]);
1313 * Add a mirror/replacing vdev above an existing vdev. There is no need to
1314 * call .vdev_op_init() since mirror/replacing vdevs do not have private state.
1317 vdev_add_parent(vdev_t
*cvd
, vdev_ops_t
*ops
)
1319 spa_t
*spa
= cvd
->vdev_spa
;
1320 vdev_t
*pvd
= cvd
->vdev_parent
;
1323 ASSERT(spa_config_held(spa
, SCL_ALL
, RW_WRITER
) == SCL_ALL
);
1325 mvd
= vdev_alloc_common(spa
, cvd
->vdev_id
, 0, ops
);
1327 mvd
->vdev_asize
= cvd
->vdev_asize
;
1328 mvd
->vdev_min_asize
= cvd
->vdev_min_asize
;
1329 mvd
->vdev_max_asize
= cvd
->vdev_max_asize
;
1330 mvd
->vdev_psize
= cvd
->vdev_psize
;
1331 mvd
->vdev_ashift
= cvd
->vdev_ashift
;
1332 mvd
->vdev_logical_ashift
= cvd
->vdev_logical_ashift
;
1333 mvd
->vdev_physical_ashift
= cvd
->vdev_physical_ashift
;
1334 mvd
->vdev_state
= cvd
->vdev_state
;
1335 mvd
->vdev_crtxg
= cvd
->vdev_crtxg
;
1337 vdev_remove_child(pvd
, cvd
);
1338 vdev_add_child(pvd
, mvd
);
1339 cvd
->vdev_id
= mvd
->vdev_children
;
1340 vdev_add_child(mvd
, cvd
);
1341 vdev_top_update(cvd
->vdev_top
, cvd
->vdev_top
);
1343 if (mvd
== mvd
->vdev_top
)
1344 vdev_top_transfer(cvd
, mvd
);
1350 * Remove a 1-way mirror/replacing vdev from the tree.
1353 vdev_remove_parent(vdev_t
*cvd
)
1355 vdev_t
*mvd
= cvd
->vdev_parent
;
1356 vdev_t
*pvd
= mvd
->vdev_parent
;
1358 ASSERT(spa_config_held(cvd
->vdev_spa
, SCL_ALL
, RW_WRITER
) == SCL_ALL
);
1360 ASSERT(mvd
->vdev_children
== 1);
1361 ASSERT(mvd
->vdev_ops
== &vdev_mirror_ops
||
1362 mvd
->vdev_ops
== &vdev_replacing_ops
||
1363 mvd
->vdev_ops
== &vdev_spare_ops
);
1364 cvd
->vdev_ashift
= mvd
->vdev_ashift
;
1365 cvd
->vdev_logical_ashift
= mvd
->vdev_logical_ashift
;
1366 cvd
->vdev_physical_ashift
= mvd
->vdev_physical_ashift
;
1367 vdev_remove_child(mvd
, cvd
);
1368 vdev_remove_child(pvd
, mvd
);
1371 * If cvd will replace mvd as a top-level vdev, preserve mvd's guid.
1372 * Otherwise, we could have detached an offline device, and when we
1373 * go to import the pool we'll think we have two top-level vdevs,
1374 * instead of a different version of the same top-level vdev.
1376 if (mvd
->vdev_top
== mvd
) {
1377 uint64_t guid_delta
= mvd
->vdev_guid
- cvd
->vdev_guid
;
1378 cvd
->vdev_orig_guid
= cvd
->vdev_guid
;
1379 cvd
->vdev_guid
+= guid_delta
;
1380 cvd
->vdev_guid_sum
+= guid_delta
;
1383 * If pool not set for autoexpand, we need to also preserve
1384 * mvd's asize to prevent automatic expansion of cvd.
1385 * Otherwise if we are adjusting the mirror by attaching and
1386 * detaching children of non-uniform sizes, the mirror could
1387 * autoexpand, unexpectedly requiring larger devices to
1388 * re-establish the mirror.
1390 if (!cvd
->vdev_spa
->spa_autoexpand
)
1391 cvd
->vdev_asize
= mvd
->vdev_asize
;
1393 cvd
->vdev_id
= mvd
->vdev_id
;
1394 vdev_add_child(pvd
, cvd
);
1395 vdev_top_update(cvd
->vdev_top
, cvd
->vdev_top
);
1397 if (cvd
== cvd
->vdev_top
)
1398 vdev_top_transfer(mvd
, cvd
);
1400 ASSERT(mvd
->vdev_children
== 0);
1405 * Choose GCD for spa_gcd_alloc.
1408 vdev_gcd(uint64_t a
, uint64_t b
)
1419 * Set spa_min_alloc and spa_gcd_alloc.
1422 vdev_spa_set_alloc(spa_t
*spa
, uint64_t min_alloc
)
1424 if (min_alloc
< spa
->spa_min_alloc
)
1425 spa
->spa_min_alloc
= min_alloc
;
1426 if (spa
->spa_gcd_alloc
== INT_MAX
) {
1427 spa
->spa_gcd_alloc
= min_alloc
;
1429 spa
->spa_gcd_alloc
= vdev_gcd(min_alloc
,
1430 spa
->spa_gcd_alloc
);
1435 vdev_metaslab_group_create(vdev_t
*vd
)
1437 spa_t
*spa
= vd
->vdev_spa
;
1440 * metaslab_group_create was delayed until allocation bias was available
1442 if (vd
->vdev_mg
== NULL
) {
1443 metaslab_class_t
*mc
;
1445 if (vd
->vdev_islog
&& vd
->vdev_alloc_bias
== VDEV_BIAS_NONE
)
1446 vd
->vdev_alloc_bias
= VDEV_BIAS_LOG
;
1448 ASSERT3U(vd
->vdev_islog
, ==,
1449 (vd
->vdev_alloc_bias
== VDEV_BIAS_LOG
));
1451 switch (vd
->vdev_alloc_bias
) {
1453 mc
= spa_log_class(spa
);
1455 case VDEV_BIAS_SPECIAL
:
1456 mc
= spa_special_class(spa
);
1458 case VDEV_BIAS_DEDUP
:
1459 mc
= spa_dedup_class(spa
);
1462 mc
= spa_normal_class(spa
);
1465 vd
->vdev_mg
= metaslab_group_create(mc
, vd
,
1466 spa
->spa_alloc_count
);
1468 if (!vd
->vdev_islog
) {
1469 vd
->vdev_log_mg
= metaslab_group_create(
1470 spa_embedded_log_class(spa
), vd
, 1);
1474 * The spa ashift min/max only apply for the normal metaslab
1475 * class. Class destination is late binding so ashift boundary
1476 * setting had to wait until now.
1478 if (vd
->vdev_top
== vd
&& vd
->vdev_ashift
!= 0 &&
1479 mc
== spa_normal_class(spa
) && vd
->vdev_aux
== NULL
) {
1480 if (vd
->vdev_ashift
> spa
->spa_max_ashift
)
1481 spa
->spa_max_ashift
= vd
->vdev_ashift
;
1482 if (vd
->vdev_ashift
< spa
->spa_min_ashift
)
1483 spa
->spa_min_ashift
= vd
->vdev_ashift
;
1485 uint64_t min_alloc
= vdev_get_min_alloc(vd
);
1486 vdev_spa_set_alloc(spa
, min_alloc
);
1492 vdev_metaslab_init(vdev_t
*vd
, uint64_t txg
)
1494 spa_t
*spa
= vd
->vdev_spa
;
1495 uint64_t oldc
= vd
->vdev_ms_count
;
1496 uint64_t newc
= vd
->vdev_asize
>> vd
->vdev_ms_shift
;
1499 boolean_t expanding
= (oldc
!= 0);
1501 ASSERT(txg
== 0 || spa_config_held(spa
, SCL_ALLOC
, RW_WRITER
));
1504 * This vdev is not being allocated from yet or is a hole.
1506 if (vd
->vdev_ms_shift
== 0)
1509 ASSERT(!vd
->vdev_ishole
);
1511 ASSERT(oldc
<= newc
);
1513 mspp
= vmem_zalloc(newc
* sizeof (*mspp
), KM_SLEEP
);
1516 memcpy(mspp
, vd
->vdev_ms
, oldc
* sizeof (*mspp
));
1517 vmem_free(vd
->vdev_ms
, oldc
* sizeof (*mspp
));
1521 vd
->vdev_ms_count
= newc
;
1523 for (uint64_t m
= oldc
; m
< newc
; m
++) {
1524 uint64_t object
= 0;
1526 * vdev_ms_array may be 0 if we are creating the "fake"
1527 * metaslabs for an indirect vdev for zdb's leak detection.
1528 * See zdb_leak_init().
1530 if (txg
== 0 && vd
->vdev_ms_array
!= 0) {
1531 error
= dmu_read(spa
->spa_meta_objset
,
1533 m
* sizeof (uint64_t), sizeof (uint64_t), &object
,
1536 vdev_dbgmsg(vd
, "unable to read the metaslab "
1537 "array [error=%d]", error
);
1542 error
= metaslab_init(vd
->vdev_mg
, m
, object
, txg
,
1545 vdev_dbgmsg(vd
, "metaslab_init failed [error=%d]",
1552 * Find the emptiest metaslab on the vdev and mark it for use for
1553 * embedded slog by moving it from the regular to the log metaslab
1556 if (vd
->vdev_mg
->mg_class
== spa_normal_class(spa
) &&
1557 vd
->vdev_ms_count
> zfs_embedded_slog_min_ms
&&
1558 avl_is_empty(&vd
->vdev_log_mg
->mg_metaslab_tree
)) {
1559 uint64_t slog_msid
= 0;
1560 uint64_t smallest
= UINT64_MAX
;
1563 * Note, we only search the new metaslabs, because the old
1564 * (pre-existing) ones may be active (e.g. have non-empty
1565 * range_tree's), and we don't move them to the new
1568 for (uint64_t m
= oldc
; m
< newc
; m
++) {
1570 space_map_allocated(vd
->vdev_ms
[m
]->ms_sm
);
1571 if (alloc
< smallest
) {
1576 metaslab_t
*slog_ms
= vd
->vdev_ms
[slog_msid
];
1578 * The metaslab was marked as dirty at the end of
1579 * metaslab_init(). Remove it from the dirty list so that we
1580 * can uninitialize and reinitialize it to the new class.
1583 (void) txg_list_remove_this(&vd
->vdev_ms_list
,
1586 uint64_t sm_obj
= space_map_object(slog_ms
->ms_sm
);
1587 metaslab_fini(slog_ms
);
1588 VERIFY0(metaslab_init(vd
->vdev_log_mg
, slog_msid
, sm_obj
, txg
,
1589 &vd
->vdev_ms
[slog_msid
]));
1593 spa_config_enter(spa
, SCL_ALLOC
, FTAG
, RW_WRITER
);
1596 * If the vdev is marked as non-allocating then don't
1597 * activate the metaslabs since we want to ensure that
1598 * no allocations are performed on this device.
1600 if (vd
->vdev_noalloc
) {
1601 /* track non-allocating vdev space */
1602 spa
->spa_nonallocating_dspace
+= spa_deflate(spa
) ?
1603 vd
->vdev_stat
.vs_dspace
: vd
->vdev_stat
.vs_space
;
1604 } else if (!expanding
) {
1605 metaslab_group_activate(vd
->vdev_mg
);
1606 if (vd
->vdev_log_mg
!= NULL
)
1607 metaslab_group_activate(vd
->vdev_log_mg
);
1611 spa_config_exit(spa
, SCL_ALLOC
, FTAG
);
1617 vdev_metaslab_fini(vdev_t
*vd
)
1619 if (vd
->vdev_checkpoint_sm
!= NULL
) {
1620 ASSERT(spa_feature_is_active(vd
->vdev_spa
,
1621 SPA_FEATURE_POOL_CHECKPOINT
));
1622 space_map_close(vd
->vdev_checkpoint_sm
);
1624 * Even though we close the space map, we need to set its
1625 * pointer to NULL. The reason is that vdev_metaslab_fini()
1626 * may be called multiple times for certain operations
1627 * (i.e. when destroying a pool) so we need to ensure that
1628 * this clause never executes twice. This logic is similar
1629 * to the one used for the vdev_ms clause below.
1631 vd
->vdev_checkpoint_sm
= NULL
;
1634 if (vd
->vdev_ms
!= NULL
) {
1635 metaslab_group_t
*mg
= vd
->vdev_mg
;
1637 metaslab_group_passivate(mg
);
1638 if (vd
->vdev_log_mg
!= NULL
) {
1639 ASSERT(!vd
->vdev_islog
);
1640 metaslab_group_passivate(vd
->vdev_log_mg
);
1643 uint64_t count
= vd
->vdev_ms_count
;
1644 for (uint64_t m
= 0; m
< count
; m
++) {
1645 metaslab_t
*msp
= vd
->vdev_ms
[m
];
1649 vmem_free(vd
->vdev_ms
, count
* sizeof (metaslab_t
*));
1651 vd
->vdev_ms_count
= 0;
1653 for (int i
= 0; i
< RANGE_TREE_HISTOGRAM_SIZE
; i
++) {
1654 ASSERT0(mg
->mg_histogram
[i
]);
1655 if (vd
->vdev_log_mg
!= NULL
)
1656 ASSERT0(vd
->vdev_log_mg
->mg_histogram
[i
]);
1659 ASSERT0(vd
->vdev_ms_count
);
1662 typedef struct vdev_probe_stats
{
1663 boolean_t vps_readable
;
1664 boolean_t vps_writeable
;
1666 } vdev_probe_stats_t
;
1669 vdev_probe_done(zio_t
*zio
)
1671 spa_t
*spa
= zio
->io_spa
;
1672 vdev_t
*vd
= zio
->io_vd
;
1673 vdev_probe_stats_t
*vps
= zio
->io_private
;
1675 ASSERT(vd
->vdev_probe_zio
!= NULL
);
1677 if (zio
->io_type
== ZIO_TYPE_READ
) {
1678 if (zio
->io_error
== 0)
1679 vps
->vps_readable
= 1;
1680 if (zio
->io_error
== 0 && spa_writeable(spa
)) {
1681 zio_nowait(zio_write_phys(vd
->vdev_probe_zio
, vd
,
1682 zio
->io_offset
, zio
->io_size
, zio
->io_abd
,
1683 ZIO_CHECKSUM_OFF
, vdev_probe_done
, vps
,
1684 ZIO_PRIORITY_SYNC_WRITE
, vps
->vps_flags
, B_TRUE
));
1686 abd_free(zio
->io_abd
);
1688 } else if (zio
->io_type
== ZIO_TYPE_WRITE
) {
1689 if (zio
->io_error
== 0)
1690 vps
->vps_writeable
= 1;
1691 abd_free(zio
->io_abd
);
1692 } else if (zio
->io_type
== ZIO_TYPE_NULL
) {
1696 vd
->vdev_cant_read
|= !vps
->vps_readable
;
1697 vd
->vdev_cant_write
|= !vps
->vps_writeable
;
1698 vdev_dbgmsg(vd
, "probe done, cant_read=%u cant_write=%u",
1699 vd
->vdev_cant_read
, vd
->vdev_cant_write
);
1701 if (vdev_readable(vd
) &&
1702 (vdev_writeable(vd
) || !spa_writeable(spa
))) {
1705 ASSERT(zio
->io_error
!= 0);
1706 vdev_dbgmsg(vd
, "failed probe");
1707 (void) zfs_ereport_post(FM_EREPORT_ZFS_PROBE_FAILURE
,
1708 spa
, vd
, NULL
, NULL
, 0);
1709 zio
->io_error
= SET_ERROR(ENXIO
);
1712 mutex_enter(&vd
->vdev_probe_lock
);
1713 ASSERT(vd
->vdev_probe_zio
== zio
);
1714 vd
->vdev_probe_zio
= NULL
;
1715 mutex_exit(&vd
->vdev_probe_lock
);
1718 while ((pio
= zio_walk_parents(zio
, &zl
)) != NULL
)
1719 if (!vdev_accessible(vd
, pio
))
1720 pio
->io_error
= SET_ERROR(ENXIO
);
1722 kmem_free(vps
, sizeof (*vps
));
1727 * Determine whether this device is accessible.
1729 * Read and write to several known locations: the pad regions of each
1730 * vdev label but the first, which we leave alone in case it contains
1734 vdev_probe(vdev_t
*vd
, zio_t
*zio
)
1736 spa_t
*spa
= vd
->vdev_spa
;
1737 vdev_probe_stats_t
*vps
= NULL
;
1740 ASSERT(vd
->vdev_ops
->vdev_op_leaf
);
1743 * Don't probe the probe.
1745 if (zio
&& (zio
->io_flags
& ZIO_FLAG_PROBE
))
1749 * To prevent 'probe storms' when a device fails, we create
1750 * just one probe i/o at a time. All zios that want to probe
1751 * this vdev will become parents of the probe io.
1753 mutex_enter(&vd
->vdev_probe_lock
);
1755 if ((pio
= vd
->vdev_probe_zio
) == NULL
) {
1756 vps
= kmem_zalloc(sizeof (*vps
), KM_SLEEP
);
1758 vps
->vps_flags
= ZIO_FLAG_CANFAIL
| ZIO_FLAG_PROBE
|
1759 ZIO_FLAG_DONT_AGGREGATE
| ZIO_FLAG_TRYHARD
;
1761 if (spa_config_held(spa
, SCL_ZIO
, RW_WRITER
)) {
1763 * vdev_cant_read and vdev_cant_write can only
1764 * transition from TRUE to FALSE when we have the
1765 * SCL_ZIO lock as writer; otherwise they can only
1766 * transition from FALSE to TRUE. This ensures that
1767 * any zio looking at these values can assume that
1768 * failures persist for the life of the I/O. That's
1769 * important because when a device has intermittent
1770 * connectivity problems, we want to ensure that
1771 * they're ascribed to the device (ENXIO) and not
1774 * Since we hold SCL_ZIO as writer here, clear both
1775 * values so the probe can reevaluate from first
1778 vps
->vps_flags
|= ZIO_FLAG_CONFIG_WRITER
;
1779 vd
->vdev_cant_read
= B_FALSE
;
1780 vd
->vdev_cant_write
= B_FALSE
;
1783 vd
->vdev_probe_zio
= pio
= zio_null(NULL
, spa
, vd
,
1784 vdev_probe_done
, vps
,
1785 vps
->vps_flags
| ZIO_FLAG_DONT_PROPAGATE
);
1788 * We can't change the vdev state in this context, so we
1789 * kick off an async task to do it on our behalf.
1792 vd
->vdev_probe_wanted
= B_TRUE
;
1793 spa_async_request(spa
, SPA_ASYNC_PROBE
);
1798 zio_add_child(zio
, pio
);
1800 mutex_exit(&vd
->vdev_probe_lock
);
1803 ASSERT(zio
!= NULL
);
1807 for (int l
= 1; l
< VDEV_LABELS
; l
++) {
1808 zio_nowait(zio_read_phys(pio
, vd
,
1809 vdev_label_offset(vd
->vdev_psize
, l
,
1810 offsetof(vdev_label_t
, vl_be
)), VDEV_PAD_SIZE
,
1811 abd_alloc_for_io(VDEV_PAD_SIZE
, B_TRUE
),
1812 ZIO_CHECKSUM_OFF
, vdev_probe_done
, vps
,
1813 ZIO_PRIORITY_SYNC_READ
, vps
->vps_flags
, B_TRUE
));
1824 vdev_load_child(void *arg
)
1828 vd
->vdev_load_error
= vdev_load(vd
);
1832 vdev_open_child(void *arg
)
1836 vd
->vdev_open_thread
= curthread
;
1837 vd
->vdev_open_error
= vdev_open(vd
);
1838 vd
->vdev_open_thread
= NULL
;
1842 vdev_uses_zvols(vdev_t
*vd
)
1845 if (zvol_is_zvol(vd
->vdev_path
))
1849 for (int c
= 0; c
< vd
->vdev_children
; c
++)
1850 if (vdev_uses_zvols(vd
->vdev_child
[c
]))
1857 * Returns B_TRUE if the passed child should be opened.
1860 vdev_default_open_children_func(vdev_t
*vd
)
1867 * Open the requested child vdevs. If any of the leaf vdevs are using
1868 * a ZFS volume then do the opens in a single thread. This avoids a
1869 * deadlock when the current thread is holding the spa_namespace_lock.
1872 vdev_open_children_impl(vdev_t
*vd
, vdev_open_children_func_t
*open_func
)
1874 int children
= vd
->vdev_children
;
1876 taskq_t
*tq
= taskq_create("vdev_open", children
, minclsyspri
,
1877 children
, children
, TASKQ_PREPOPULATE
);
1878 vd
->vdev_nonrot
= B_TRUE
;
1880 for (int c
= 0; c
< children
; c
++) {
1881 vdev_t
*cvd
= vd
->vdev_child
[c
];
1883 if (open_func(cvd
) == B_FALSE
)
1886 if (tq
== NULL
|| vdev_uses_zvols(vd
)) {
1887 cvd
->vdev_open_error
= vdev_open(cvd
);
1889 VERIFY(taskq_dispatch(tq
, vdev_open_child
,
1890 cvd
, TQ_SLEEP
) != TASKQID_INVALID
);
1893 vd
->vdev_nonrot
&= cvd
->vdev_nonrot
;
1903 * Open all child vdevs.
1906 vdev_open_children(vdev_t
*vd
)
1908 vdev_open_children_impl(vd
, vdev_default_open_children_func
);
1912 * Conditionally open a subset of child vdevs.
1915 vdev_open_children_subset(vdev_t
*vd
, vdev_open_children_func_t
*open_func
)
1917 vdev_open_children_impl(vd
, open_func
);
1921 * Compute the raidz-deflation ratio. Note, we hard-code 128k (1 << 17)
1922 * because it is the "typical" blocksize. Even though SPA_MAXBLOCKSIZE
1923 * changed, this algorithm can not change, otherwise it would inconsistently
1924 * account for existing bp's. We also hard-code txg 0 for the same reason
1925 * since expanded RAIDZ vdevs can use a different asize for different birth
1929 vdev_set_deflate_ratio(vdev_t
*vd
)
1931 if (vd
== vd
->vdev_top
&& !vd
->vdev_ishole
&& vd
->vdev_ashift
!= 0) {
1932 vd
->vdev_deflate_ratio
= (1 << 17) /
1933 (vdev_psize_to_asize_txg(vd
, 1 << 17, 0) >>
1939 * Choose the best of two ashifts, preferring one between logical ashift
1940 * (absolute minimum) and administrator defined maximum, otherwise take
1941 * the biggest of the two.
1944 vdev_best_ashift(uint64_t logical
, uint64_t a
, uint64_t b
)
1946 if (a
> logical
&& a
<= zfs_vdev_max_auto_ashift
) {
1947 if (b
<= logical
|| b
> zfs_vdev_max_auto_ashift
)
1951 } else if (b
<= logical
|| b
> zfs_vdev_max_auto_ashift
)
1957 * Maximize performance by inflating the configured ashift for top level
1958 * vdevs to be as close to the physical ashift as possible while maintaining
1959 * administrator defined limits and ensuring it doesn't go below the
1963 vdev_ashift_optimize(vdev_t
*vd
)
1965 ASSERT(vd
== vd
->vdev_top
);
1967 if (vd
->vdev_ashift
< vd
->vdev_physical_ashift
&&
1968 vd
->vdev_physical_ashift
<= zfs_vdev_max_auto_ashift
) {
1969 vd
->vdev_ashift
= MIN(
1970 MAX(zfs_vdev_max_auto_ashift
, vd
->vdev_ashift
),
1971 MAX(zfs_vdev_min_auto_ashift
,
1972 vd
->vdev_physical_ashift
));
1975 * If the logical and physical ashifts are the same, then
1976 * we ensure that the top-level vdev's ashift is not smaller
1977 * than our minimum ashift value. For the unusual case
1978 * where logical ashift > physical ashift, we can't cap
1979 * the calculated ashift based on max ashift as that
1980 * would cause failures.
1981 * We still check if we need to increase it to match
1984 vd
->vdev_ashift
= MAX(zfs_vdev_min_auto_ashift
,
1990 * Prepare a virtual device for access.
1993 vdev_open(vdev_t
*vd
)
1995 spa_t
*spa
= vd
->vdev_spa
;
1998 uint64_t max_osize
= 0;
1999 uint64_t asize
, max_asize
, psize
;
2000 uint64_t logical_ashift
= 0;
2001 uint64_t physical_ashift
= 0;
2003 ASSERT(vd
->vdev_open_thread
== curthread
||
2004 spa_config_held(spa
, SCL_STATE_ALL
, RW_WRITER
) == SCL_STATE_ALL
);
2005 ASSERT(vd
->vdev_state
== VDEV_STATE_CLOSED
||
2006 vd
->vdev_state
== VDEV_STATE_CANT_OPEN
||
2007 vd
->vdev_state
== VDEV_STATE_OFFLINE
);
2009 vd
->vdev_stat
.vs_aux
= VDEV_AUX_NONE
;
2010 vd
->vdev_cant_read
= B_FALSE
;
2011 vd
->vdev_cant_write
= B_FALSE
;
2012 vd
->vdev_min_asize
= vdev_get_min_asize(vd
);
2015 * If this vdev is not removed, check its fault status. If it's
2016 * faulted, bail out of the open.
2018 if (!vd
->vdev_removed
&& vd
->vdev_faulted
) {
2019 ASSERT(vd
->vdev_children
== 0);
2020 ASSERT(vd
->vdev_label_aux
== VDEV_AUX_ERR_EXCEEDED
||
2021 vd
->vdev_label_aux
== VDEV_AUX_EXTERNAL
);
2022 vdev_set_state(vd
, B_TRUE
, VDEV_STATE_FAULTED
,
2023 vd
->vdev_label_aux
);
2024 return (SET_ERROR(ENXIO
));
2025 } else if (vd
->vdev_offline
) {
2026 ASSERT(vd
->vdev_children
== 0);
2027 vdev_set_state(vd
, B_TRUE
, VDEV_STATE_OFFLINE
, VDEV_AUX_NONE
);
2028 return (SET_ERROR(ENXIO
));
2031 error
= vd
->vdev_ops
->vdev_op_open(vd
, &osize
, &max_osize
,
2032 &logical_ashift
, &physical_ashift
);
2034 /* Keep the device in removed state if unplugged */
2035 if (error
== ENOENT
&& vd
->vdev_removed
) {
2036 vdev_set_state(vd
, B_TRUE
, VDEV_STATE_REMOVED
,
2042 * Physical volume size should never be larger than its max size, unless
2043 * the disk has shrunk while we were reading it or the device is buggy
2044 * or damaged: either way it's not safe for use, bail out of the open.
2046 if (osize
> max_osize
) {
2047 vdev_set_state(vd
, B_TRUE
, VDEV_STATE_CANT_OPEN
,
2048 VDEV_AUX_OPEN_FAILED
);
2049 return (SET_ERROR(ENXIO
));
2053 * Reset the vdev_reopening flag so that we actually close
2054 * the vdev on error.
2056 vd
->vdev_reopening
= B_FALSE
;
2057 if (zio_injection_enabled
&& error
== 0)
2058 error
= zio_handle_device_injection(vd
, NULL
, SET_ERROR(ENXIO
));
2061 if (vd
->vdev_removed
&&
2062 vd
->vdev_stat
.vs_aux
!= VDEV_AUX_OPEN_FAILED
)
2063 vd
->vdev_removed
= B_FALSE
;
2065 if (vd
->vdev_stat
.vs_aux
== VDEV_AUX_CHILDREN_OFFLINE
) {
2066 vdev_set_state(vd
, B_TRUE
, VDEV_STATE_OFFLINE
,
2067 vd
->vdev_stat
.vs_aux
);
2069 vdev_set_state(vd
, B_TRUE
, VDEV_STATE_CANT_OPEN
,
2070 vd
->vdev_stat
.vs_aux
);
2075 vd
->vdev_removed
= B_FALSE
;
2078 * Recheck the faulted flag now that we have confirmed that
2079 * the vdev is accessible. If we're faulted, bail.
2081 if (vd
->vdev_faulted
) {
2082 ASSERT(vd
->vdev_children
== 0);
2083 ASSERT(vd
->vdev_label_aux
== VDEV_AUX_ERR_EXCEEDED
||
2084 vd
->vdev_label_aux
== VDEV_AUX_EXTERNAL
);
2085 vdev_set_state(vd
, B_TRUE
, VDEV_STATE_FAULTED
,
2086 vd
->vdev_label_aux
);
2087 return (SET_ERROR(ENXIO
));
2090 if (vd
->vdev_degraded
) {
2091 ASSERT(vd
->vdev_children
== 0);
2092 vdev_set_state(vd
, B_TRUE
, VDEV_STATE_DEGRADED
,
2093 VDEV_AUX_ERR_EXCEEDED
);
2095 vdev_set_state(vd
, B_TRUE
, VDEV_STATE_HEALTHY
, 0);
2099 * For hole or missing vdevs we just return success.
2101 if (vd
->vdev_ishole
|| vd
->vdev_ops
== &vdev_missing_ops
)
2104 for (int c
= 0; c
< vd
->vdev_children
; c
++) {
2105 if (vd
->vdev_child
[c
]->vdev_state
!= VDEV_STATE_HEALTHY
) {
2106 vdev_set_state(vd
, B_TRUE
, VDEV_STATE_DEGRADED
,
2112 osize
= P2ALIGN(osize
, (uint64_t)sizeof (vdev_label_t
));
2113 max_osize
= P2ALIGN(max_osize
, (uint64_t)sizeof (vdev_label_t
));
2115 if (vd
->vdev_children
== 0) {
2116 if (osize
< SPA_MINDEVSIZE
) {
2117 vdev_set_state(vd
, B_TRUE
, VDEV_STATE_CANT_OPEN
,
2118 VDEV_AUX_TOO_SMALL
);
2119 return (SET_ERROR(EOVERFLOW
));
2122 asize
= osize
- (VDEV_LABEL_START_SIZE
+ VDEV_LABEL_END_SIZE
);
2123 max_asize
= max_osize
- (VDEV_LABEL_START_SIZE
+
2124 VDEV_LABEL_END_SIZE
);
2126 if (vd
->vdev_parent
!= NULL
&& osize
< SPA_MINDEVSIZE
-
2127 (VDEV_LABEL_START_SIZE
+ VDEV_LABEL_END_SIZE
)) {
2128 vdev_set_state(vd
, B_TRUE
, VDEV_STATE_CANT_OPEN
,
2129 VDEV_AUX_TOO_SMALL
);
2130 return (SET_ERROR(EOVERFLOW
));
2134 max_asize
= max_osize
;
2138 * If the vdev was expanded, record this so that we can re-create the
2139 * uberblock rings in labels {2,3}, during the next sync.
2141 if ((psize
> vd
->vdev_psize
) && (vd
->vdev_psize
!= 0))
2142 vd
->vdev_copy_uberblocks
= B_TRUE
;
2144 vd
->vdev_psize
= psize
;
2147 * Make sure the allocatable size hasn't shrunk too much.
2149 if (asize
< vd
->vdev_min_asize
) {
2150 vdev_set_state(vd
, B_TRUE
, VDEV_STATE_CANT_OPEN
,
2151 VDEV_AUX_BAD_LABEL
);
2152 return (SET_ERROR(EINVAL
));
2156 * We can always set the logical/physical ashift members since
2157 * their values are only used to calculate the vdev_ashift when
2158 * the device is first added to the config. These values should
2159 * not be used for anything else since they may change whenever
2160 * the device is reopened and we don't store them in the label.
2162 vd
->vdev_physical_ashift
=
2163 MAX(physical_ashift
, vd
->vdev_physical_ashift
);
2164 vd
->vdev_logical_ashift
= MAX(logical_ashift
,
2165 vd
->vdev_logical_ashift
);
2167 if (vd
->vdev_asize
== 0) {
2169 * This is the first-ever open, so use the computed values.
2170 * For compatibility, a different ashift can be requested.
2172 vd
->vdev_asize
= asize
;
2173 vd
->vdev_max_asize
= max_asize
;
2176 * If the vdev_ashift was not overridden at creation time,
2177 * then set it the logical ashift and optimize the ashift.
2179 if (vd
->vdev_ashift
== 0) {
2180 vd
->vdev_ashift
= vd
->vdev_logical_ashift
;
2182 if (vd
->vdev_logical_ashift
> ASHIFT_MAX
) {
2183 vdev_set_state(vd
, B_TRUE
, VDEV_STATE_CANT_OPEN
,
2184 VDEV_AUX_ASHIFT_TOO_BIG
);
2185 return (SET_ERROR(EDOM
));
2188 if (vd
->vdev_top
== vd
&& vd
->vdev_attaching
== B_FALSE
)
2189 vdev_ashift_optimize(vd
);
2190 vd
->vdev_attaching
= B_FALSE
;
2192 if (vd
->vdev_ashift
!= 0 && (vd
->vdev_ashift
< ASHIFT_MIN
||
2193 vd
->vdev_ashift
> ASHIFT_MAX
)) {
2194 vdev_set_state(vd
, B_TRUE
, VDEV_STATE_CANT_OPEN
,
2195 VDEV_AUX_BAD_ASHIFT
);
2196 return (SET_ERROR(EDOM
));
2200 * Make sure the alignment required hasn't increased.
2202 if (vd
->vdev_ashift
> vd
->vdev_top
->vdev_ashift
&&
2203 vd
->vdev_ops
->vdev_op_leaf
) {
2204 (void) zfs_ereport_post(
2205 FM_EREPORT_ZFS_DEVICE_BAD_ASHIFT
,
2206 spa
, vd
, NULL
, NULL
, 0);
2207 vdev_set_state(vd
, B_TRUE
, VDEV_STATE_CANT_OPEN
,
2208 VDEV_AUX_BAD_LABEL
);
2209 return (SET_ERROR(EDOM
));
2211 vd
->vdev_max_asize
= max_asize
;
2215 * If all children are healthy we update asize if either:
2216 * The asize has increased, due to a device expansion caused by dynamic
2217 * LUN growth or vdev replacement, and automatic expansion is enabled;
2218 * making the additional space available.
2220 * The asize has decreased, due to a device shrink usually caused by a
2221 * vdev replace with a smaller device. This ensures that calculations
2222 * based of max_asize and asize e.g. esize are always valid. It's safe
2223 * to do this as we've already validated that asize is greater than
2226 if (vd
->vdev_state
== VDEV_STATE_HEALTHY
&&
2227 ((asize
> vd
->vdev_asize
&&
2228 (vd
->vdev_expanding
|| spa
->spa_autoexpand
)) ||
2229 (asize
< vd
->vdev_asize
)))
2230 vd
->vdev_asize
= asize
;
2232 vdev_set_min_asize(vd
);
2235 * Ensure we can issue some IO before declaring the
2236 * vdev open for business.
2238 if (vd
->vdev_ops
->vdev_op_leaf
&&
2239 (error
= zio_wait(vdev_probe(vd
, NULL
))) != 0) {
2240 vdev_set_state(vd
, B_TRUE
, VDEV_STATE_FAULTED
,
2241 VDEV_AUX_ERR_EXCEEDED
);
2246 * Track the minimum allocation size.
2248 if (vd
->vdev_top
== vd
&& vd
->vdev_ashift
!= 0 &&
2249 vd
->vdev_islog
== 0 && vd
->vdev_aux
== NULL
) {
2250 uint64_t min_alloc
= vdev_get_min_alloc(vd
);
2251 vdev_spa_set_alloc(spa
, min_alloc
);
2255 * If this is a leaf vdev, assess whether a resilver is needed.
2256 * But don't do this if we are doing a reopen for a scrub, since
2257 * this would just restart the scrub we are already doing.
2259 if (vd
->vdev_ops
->vdev_op_leaf
&& !spa
->spa_scrub_reopen
)
2260 dsl_scan_assess_vdev(spa
->spa_dsl_pool
, vd
);
2266 vdev_validate_child(void *arg
)
2270 vd
->vdev_validate_thread
= curthread
;
2271 vd
->vdev_validate_error
= vdev_validate(vd
);
2272 vd
->vdev_validate_thread
= NULL
;
2276 * Called once the vdevs are all opened, this routine validates the label
2277 * contents. This needs to be done before vdev_load() so that we don't
2278 * inadvertently do repair I/Os to the wrong device.
2280 * This function will only return failure if one of the vdevs indicates that it
2281 * has since been destroyed or exported. This is only possible if
2282 * /etc/zfs/zpool.cache was readonly at the time. Otherwise, the vdev state
2283 * will be updated but the function will return 0.
2286 vdev_validate(vdev_t
*vd
)
2288 spa_t
*spa
= vd
->vdev_spa
;
2291 uint64_t guid
= 0, aux_guid
= 0, top_guid
;
2295 int children
= vd
->vdev_children
;
2297 if (vdev_validate_skip
)
2301 tq
= taskq_create("vdev_validate", children
, minclsyspri
,
2302 children
, children
, TASKQ_PREPOPULATE
);
2305 for (uint64_t c
= 0; c
< children
; c
++) {
2306 vdev_t
*cvd
= vd
->vdev_child
[c
];
2308 if (tq
== NULL
|| vdev_uses_zvols(cvd
)) {
2309 vdev_validate_child(cvd
);
2311 VERIFY(taskq_dispatch(tq
, vdev_validate_child
, cvd
,
2312 TQ_SLEEP
) != TASKQID_INVALID
);
2319 for (int c
= 0; c
< children
; c
++) {
2320 int error
= vd
->vdev_child
[c
]->vdev_validate_error
;
2323 return (SET_ERROR(EBADF
));
2328 * If the device has already failed, or was marked offline, don't do
2329 * any further validation. Otherwise, label I/O will fail and we will
2330 * overwrite the previous state.
2332 if (!vd
->vdev_ops
->vdev_op_leaf
|| !vdev_readable(vd
))
2336 * If we are performing an extreme rewind, we allow for a label that
2337 * was modified at a point after the current txg.
2338 * If config lock is not held do not check for the txg. spa_sync could
2339 * be updating the vdev's label before updating spa_last_synced_txg.
2341 if (spa
->spa_extreme_rewind
|| spa_last_synced_txg(spa
) == 0 ||
2342 spa_config_held(spa
, SCL_CONFIG
, RW_WRITER
) != SCL_CONFIG
)
2345 txg
= spa_last_synced_txg(spa
);
2347 if ((label
= vdev_label_read_config(vd
, txg
)) == NULL
) {
2348 vdev_set_state(vd
, B_FALSE
, VDEV_STATE_CANT_OPEN
,
2349 VDEV_AUX_BAD_LABEL
);
2350 vdev_dbgmsg(vd
, "vdev_validate: failed reading config for "
2351 "txg %llu", (u_longlong_t
)txg
);
2356 * Determine if this vdev has been split off into another
2357 * pool. If so, then refuse to open it.
2359 if (nvlist_lookup_uint64(label
, ZPOOL_CONFIG_SPLIT_GUID
,
2360 &aux_guid
) == 0 && aux_guid
== spa_guid(spa
)) {
2361 vdev_set_state(vd
, B_FALSE
, VDEV_STATE_CANT_OPEN
,
2362 VDEV_AUX_SPLIT_POOL
);
2364 vdev_dbgmsg(vd
, "vdev_validate: vdev split into other pool");
2368 if (nvlist_lookup_uint64(label
, ZPOOL_CONFIG_POOL_GUID
, &guid
) != 0) {
2369 vdev_set_state(vd
, B_FALSE
, VDEV_STATE_CANT_OPEN
,
2370 VDEV_AUX_CORRUPT_DATA
);
2372 vdev_dbgmsg(vd
, "vdev_validate: '%s' missing from label",
2373 ZPOOL_CONFIG_POOL_GUID
);
2378 * If config is not trusted then ignore the spa guid check. This is
2379 * necessary because if the machine crashed during a re-guid the new
2380 * guid might have been written to all of the vdev labels, but not the
2381 * cached config. The check will be performed again once we have the
2382 * trusted config from the MOS.
2384 if (spa
->spa_trust_config
&& guid
!= spa_guid(spa
)) {
2385 vdev_set_state(vd
, B_FALSE
, VDEV_STATE_CANT_OPEN
,
2386 VDEV_AUX_CORRUPT_DATA
);
2388 vdev_dbgmsg(vd
, "vdev_validate: vdev label pool_guid doesn't "
2389 "match config (%llu != %llu)", (u_longlong_t
)guid
,
2390 (u_longlong_t
)spa_guid(spa
));
2394 if (nvlist_lookup_nvlist(label
, ZPOOL_CONFIG_VDEV_TREE
, &nvl
)
2395 != 0 || nvlist_lookup_uint64(nvl
, ZPOOL_CONFIG_ORIG_GUID
,
2399 if (nvlist_lookup_uint64(label
, ZPOOL_CONFIG_GUID
, &guid
) != 0) {
2400 vdev_set_state(vd
, B_FALSE
, VDEV_STATE_CANT_OPEN
,
2401 VDEV_AUX_CORRUPT_DATA
);
2403 vdev_dbgmsg(vd
, "vdev_validate: '%s' missing from label",
2408 if (nvlist_lookup_uint64(label
, ZPOOL_CONFIG_TOP_GUID
, &top_guid
)
2410 vdev_set_state(vd
, B_FALSE
, VDEV_STATE_CANT_OPEN
,
2411 VDEV_AUX_CORRUPT_DATA
);
2413 vdev_dbgmsg(vd
, "vdev_validate: '%s' missing from label",
2414 ZPOOL_CONFIG_TOP_GUID
);
2419 * If this vdev just became a top-level vdev because its sibling was
2420 * detached, it will have adopted the parent's vdev guid -- but the
2421 * label may or may not be on disk yet. Fortunately, either version
2422 * of the label will have the same top guid, so if we're a top-level
2423 * vdev, we can safely compare to that instead.
2424 * However, if the config comes from a cachefile that failed to update
2425 * after the detach, a top-level vdev will appear as a non top-level
2426 * vdev in the config. Also relax the constraints if we perform an
2429 * If we split this vdev off instead, then we also check the
2430 * original pool's guid. We don't want to consider the vdev
2431 * corrupt if it is partway through a split operation.
2433 if (vd
->vdev_guid
!= guid
&& vd
->vdev_guid
!= aux_guid
) {
2434 boolean_t mismatch
= B_FALSE
;
2435 if (spa
->spa_trust_config
&& !spa
->spa_extreme_rewind
) {
2436 if (vd
!= vd
->vdev_top
|| vd
->vdev_guid
!= top_guid
)
2439 if (vd
->vdev_guid
!= top_guid
&&
2440 vd
->vdev_top
->vdev_guid
!= guid
)
2445 vdev_set_state(vd
, B_FALSE
, VDEV_STATE_CANT_OPEN
,
2446 VDEV_AUX_CORRUPT_DATA
);
2448 vdev_dbgmsg(vd
, "vdev_validate: config guid "
2449 "doesn't match label guid");
2450 vdev_dbgmsg(vd
, "CONFIG: guid %llu, top_guid %llu",
2451 (u_longlong_t
)vd
->vdev_guid
,
2452 (u_longlong_t
)vd
->vdev_top
->vdev_guid
);
2453 vdev_dbgmsg(vd
, "LABEL: guid %llu, top_guid %llu, "
2454 "aux_guid %llu", (u_longlong_t
)guid
,
2455 (u_longlong_t
)top_guid
, (u_longlong_t
)aux_guid
);
2460 if (nvlist_lookup_uint64(label
, ZPOOL_CONFIG_POOL_STATE
,
2462 vdev_set_state(vd
, B_FALSE
, VDEV_STATE_CANT_OPEN
,
2463 VDEV_AUX_CORRUPT_DATA
);
2465 vdev_dbgmsg(vd
, "vdev_validate: '%s' missing from label",
2466 ZPOOL_CONFIG_POOL_STATE
);
2473 * If this is a verbatim import, no need to check the
2474 * state of the pool.
2476 if (!(spa
->spa_import_flags
& ZFS_IMPORT_VERBATIM
) &&
2477 spa_load_state(spa
) == SPA_LOAD_OPEN
&&
2478 state
!= POOL_STATE_ACTIVE
) {
2479 vdev_dbgmsg(vd
, "vdev_validate: invalid pool state (%llu) "
2480 "for spa %s", (u_longlong_t
)state
, spa
->spa_name
);
2481 return (SET_ERROR(EBADF
));
2485 * If we were able to open and validate a vdev that was
2486 * previously marked permanently unavailable, clear that state
2489 if (vd
->vdev_not_present
)
2490 vd
->vdev_not_present
= 0;
2496 vdev_copy_path_impl(vdev_t
*svd
, vdev_t
*dvd
)
2499 if (svd
->vdev_path
!= NULL
&& dvd
->vdev_path
!= NULL
) {
2500 if (strcmp(svd
->vdev_path
, dvd
->vdev_path
) != 0) {
2501 zfs_dbgmsg("vdev_copy_path: vdev %llu: path changed "
2502 "from '%s' to '%s'", (u_longlong_t
)dvd
->vdev_guid
,
2503 dvd
->vdev_path
, svd
->vdev_path
);
2504 spa_strfree(dvd
->vdev_path
);
2505 dvd
->vdev_path
= spa_strdup(svd
->vdev_path
);
2507 } else if (svd
->vdev_path
!= NULL
) {
2508 dvd
->vdev_path
= spa_strdup(svd
->vdev_path
);
2509 zfs_dbgmsg("vdev_copy_path: vdev %llu: path set to '%s'",
2510 (u_longlong_t
)dvd
->vdev_guid
, dvd
->vdev_path
);
2514 * Our enclosure sysfs path may have changed between imports
2516 old
= dvd
->vdev_enc_sysfs_path
;
2517 new = svd
->vdev_enc_sysfs_path
;
2518 if ((old
!= NULL
&& new == NULL
) ||
2519 (old
== NULL
&& new != NULL
) ||
2520 ((old
!= NULL
&& new != NULL
) && strcmp(new, old
) != 0)) {
2521 zfs_dbgmsg("vdev_copy_path: vdev %llu: vdev_enc_sysfs_path "
2522 "changed from '%s' to '%s'", (u_longlong_t
)dvd
->vdev_guid
,
2525 if (dvd
->vdev_enc_sysfs_path
)
2526 spa_strfree(dvd
->vdev_enc_sysfs_path
);
2528 if (svd
->vdev_enc_sysfs_path
) {
2529 dvd
->vdev_enc_sysfs_path
= spa_strdup(
2530 svd
->vdev_enc_sysfs_path
);
2532 dvd
->vdev_enc_sysfs_path
= NULL
;
2538 * Recursively copy vdev paths from one vdev to another. Source and destination
2539 * vdev trees must have same geometry otherwise return error. Intended to copy
2540 * paths from userland config into MOS config.
2543 vdev_copy_path_strict(vdev_t
*svd
, vdev_t
*dvd
)
2545 if ((svd
->vdev_ops
== &vdev_missing_ops
) ||
2546 (svd
->vdev_ishole
&& dvd
->vdev_ishole
) ||
2547 (dvd
->vdev_ops
== &vdev_indirect_ops
))
2550 if (svd
->vdev_ops
!= dvd
->vdev_ops
) {
2551 vdev_dbgmsg(svd
, "vdev_copy_path: vdev type mismatch: %s != %s",
2552 svd
->vdev_ops
->vdev_op_type
, dvd
->vdev_ops
->vdev_op_type
);
2553 return (SET_ERROR(EINVAL
));
2556 if (svd
->vdev_guid
!= dvd
->vdev_guid
) {
2557 vdev_dbgmsg(svd
, "vdev_copy_path: guids mismatch (%llu != "
2558 "%llu)", (u_longlong_t
)svd
->vdev_guid
,
2559 (u_longlong_t
)dvd
->vdev_guid
);
2560 return (SET_ERROR(EINVAL
));
2563 if (svd
->vdev_children
!= dvd
->vdev_children
) {
2564 vdev_dbgmsg(svd
, "vdev_copy_path: children count mismatch: "
2565 "%llu != %llu", (u_longlong_t
)svd
->vdev_children
,
2566 (u_longlong_t
)dvd
->vdev_children
);
2567 return (SET_ERROR(EINVAL
));
2570 for (uint64_t i
= 0; i
< svd
->vdev_children
; i
++) {
2571 int error
= vdev_copy_path_strict(svd
->vdev_child
[i
],
2572 dvd
->vdev_child
[i
]);
2577 if (svd
->vdev_ops
->vdev_op_leaf
)
2578 vdev_copy_path_impl(svd
, dvd
);
2584 vdev_copy_path_search(vdev_t
*stvd
, vdev_t
*dvd
)
2586 ASSERT(stvd
->vdev_top
== stvd
);
2587 ASSERT3U(stvd
->vdev_id
, ==, dvd
->vdev_top
->vdev_id
);
2589 for (uint64_t i
= 0; i
< dvd
->vdev_children
; i
++) {
2590 vdev_copy_path_search(stvd
, dvd
->vdev_child
[i
]);
2593 if (!dvd
->vdev_ops
->vdev_op_leaf
|| !vdev_is_concrete(dvd
))
2597 * The idea here is that while a vdev can shift positions within
2598 * a top vdev (when replacing, attaching mirror, etc.) it cannot
2599 * step outside of it.
2601 vdev_t
*vd
= vdev_lookup_by_guid(stvd
, dvd
->vdev_guid
);
2603 if (vd
== NULL
|| vd
->vdev_ops
!= dvd
->vdev_ops
)
2606 ASSERT(vd
->vdev_ops
->vdev_op_leaf
);
2608 vdev_copy_path_impl(vd
, dvd
);
2612 * Recursively copy vdev paths from one root vdev to another. Source and
2613 * destination vdev trees may differ in geometry. For each destination leaf
2614 * vdev, search a vdev with the same guid and top vdev id in the source.
2615 * Intended to copy paths from userland config into MOS config.
2618 vdev_copy_path_relaxed(vdev_t
*srvd
, vdev_t
*drvd
)
2620 uint64_t children
= MIN(srvd
->vdev_children
, drvd
->vdev_children
);
2621 ASSERT(srvd
->vdev_ops
== &vdev_root_ops
);
2622 ASSERT(drvd
->vdev_ops
== &vdev_root_ops
);
2624 for (uint64_t i
= 0; i
< children
; i
++) {
2625 vdev_copy_path_search(srvd
->vdev_child
[i
],
2626 drvd
->vdev_child
[i
]);
2631 * Close a virtual device.
2634 vdev_close(vdev_t
*vd
)
2636 vdev_t
*pvd
= vd
->vdev_parent
;
2637 spa_t
*spa __maybe_unused
= vd
->vdev_spa
;
2640 ASSERT(vd
->vdev_open_thread
== curthread
||
2641 spa_config_held(spa
, SCL_STATE_ALL
, RW_WRITER
) == SCL_STATE_ALL
);
2644 * If our parent is reopening, then we are as well, unless we are
2647 if (pvd
!= NULL
&& pvd
->vdev_reopening
)
2648 vd
->vdev_reopening
= (pvd
->vdev_reopening
&& !vd
->vdev_offline
);
2650 vd
->vdev_ops
->vdev_op_close(vd
);
2653 * We record the previous state before we close it, so that if we are
2654 * doing a reopen(), we don't generate FMA ereports if we notice that
2655 * it's still faulted.
2657 vd
->vdev_prevstate
= vd
->vdev_state
;
2659 if (vd
->vdev_offline
)
2660 vd
->vdev_state
= VDEV_STATE_OFFLINE
;
2662 vd
->vdev_state
= VDEV_STATE_CLOSED
;
2663 vd
->vdev_stat
.vs_aux
= VDEV_AUX_NONE
;
2667 vdev_hold(vdev_t
*vd
)
2669 spa_t
*spa
= vd
->vdev_spa
;
2671 ASSERT(spa_is_root(spa
));
2672 if (spa
->spa_state
== POOL_STATE_UNINITIALIZED
)
2675 for (int c
= 0; c
< vd
->vdev_children
; c
++)
2676 vdev_hold(vd
->vdev_child
[c
]);
2678 if (vd
->vdev_ops
->vdev_op_leaf
&& vd
->vdev_ops
->vdev_op_hold
!= NULL
)
2679 vd
->vdev_ops
->vdev_op_hold(vd
);
2683 vdev_rele(vdev_t
*vd
)
2685 ASSERT(spa_is_root(vd
->vdev_spa
));
2686 for (int c
= 0; c
< vd
->vdev_children
; c
++)
2687 vdev_rele(vd
->vdev_child
[c
]);
2689 if (vd
->vdev_ops
->vdev_op_leaf
&& vd
->vdev_ops
->vdev_op_rele
!= NULL
)
2690 vd
->vdev_ops
->vdev_op_rele(vd
);
2694 * Reopen all interior vdevs and any unopened leaves. We don't actually
2695 * reopen leaf vdevs which had previously been opened as they might deadlock
2696 * on the spa_config_lock. Instead we only obtain the leaf's physical size.
2697 * If the leaf has never been opened then open it, as usual.
2700 vdev_reopen(vdev_t
*vd
)
2702 spa_t
*spa
= vd
->vdev_spa
;
2704 ASSERT(spa_config_held(spa
, SCL_STATE_ALL
, RW_WRITER
) == SCL_STATE_ALL
);
2706 /* set the reopening flag unless we're taking the vdev offline */
2707 vd
->vdev_reopening
= !vd
->vdev_offline
;
2709 (void) vdev_open(vd
);
2712 * Call vdev_validate() here to make sure we have the same device.
2713 * Otherwise, a device with an invalid label could be successfully
2714 * opened in response to vdev_reopen().
2717 (void) vdev_validate_aux(vd
);
2718 if (vdev_readable(vd
) && vdev_writeable(vd
) &&
2719 vd
->vdev_aux
== &spa
->spa_l2cache
) {
2721 * In case the vdev is present we should evict all ARC
2722 * buffers and pointers to log blocks and reclaim their
2723 * space before restoring its contents to L2ARC.
2725 if (l2arc_vdev_present(vd
)) {
2726 l2arc_rebuild_vdev(vd
, B_TRUE
);
2728 l2arc_add_vdev(spa
, vd
);
2730 spa_async_request(spa
, SPA_ASYNC_L2CACHE_REBUILD
);
2731 spa_async_request(spa
, SPA_ASYNC_L2CACHE_TRIM
);
2734 (void) vdev_validate(vd
);
2738 * Recheck if resilver is still needed and cancel any
2739 * scheduled resilver if resilver is unneeded.
2741 if (!vdev_resilver_needed(spa
->spa_root_vdev
, NULL
, NULL
) &&
2742 spa
->spa_async_tasks
& SPA_ASYNC_RESILVER
) {
2743 mutex_enter(&spa
->spa_async_lock
);
2744 spa
->spa_async_tasks
&= ~SPA_ASYNC_RESILVER
;
2745 mutex_exit(&spa
->spa_async_lock
);
2749 * Reassess parent vdev's health.
2751 vdev_propagate_state(vd
);
2755 vdev_create(vdev_t
*vd
, uint64_t txg
, boolean_t isreplacing
)
2760 * Normally, partial opens (e.g. of a mirror) are allowed.
2761 * For a create, however, we want to fail the request if
2762 * there are any components we can't open.
2764 error
= vdev_open(vd
);
2766 if (error
|| vd
->vdev_state
!= VDEV_STATE_HEALTHY
) {
2768 return (error
? error
: SET_ERROR(ENXIO
));
2772 * Recursively load DTLs and initialize all labels.
2774 if ((error
= vdev_dtl_load(vd
)) != 0 ||
2775 (error
= vdev_label_init(vd
, txg
, isreplacing
?
2776 VDEV_LABEL_REPLACE
: VDEV_LABEL_CREATE
)) != 0) {
2785 vdev_metaslab_set_size(vdev_t
*vd
)
2787 uint64_t asize
= vd
->vdev_asize
;
2788 uint64_t ms_count
= asize
>> zfs_vdev_default_ms_shift
;
2792 * There are two dimensions to the metaslab sizing calculation:
2793 * the size of the metaslab and the count of metaslabs per vdev.
2795 * The default values used below are a good balance between memory
2796 * usage (larger metaslab size means more memory needed for loaded
2797 * metaslabs; more metaslabs means more memory needed for the
2798 * metaslab_t structs), metaslab load time (larger metaslabs take
2799 * longer to load), and metaslab sync time (more metaslabs means
2800 * more time spent syncing all of them).
2802 * In general, we aim for zfs_vdev_default_ms_count (200) metaslabs.
2803 * The range of the dimensions are as follows:
2805 * 2^29 <= ms_size <= 2^34
2806 * 16 <= ms_count <= 131,072
2808 * On the lower end of vdev sizes, we aim for metaslabs sizes of
2809 * at least 512MB (2^29) to minimize fragmentation effects when
2810 * testing with smaller devices. However, the count constraint
2811 * of at least 16 metaslabs will override this minimum size goal.
2813 * On the upper end of vdev sizes, we aim for a maximum metaslab
2814 * size of 16GB. However, we will cap the total count to 2^17
2815 * metaslabs to keep our memory footprint in check and let the
2816 * metaslab size grow from there if that limit is hit.
2818 * The net effect of applying above constrains is summarized below.
2820 * vdev size metaslab count
2821 * --------------|-----------------
2823 * 8GB - 100GB one per 512MB
2825 * 3TB - 2PB one per 16GB
2827 * --------------------------------
2829 * Finally, note that all of the above calculate the initial
2830 * number of metaslabs. Expanding a top-level vdev will result
2831 * in additional metaslabs being allocated making it possible
2832 * to exceed the zfs_vdev_ms_count_limit.
2835 if (ms_count
< zfs_vdev_min_ms_count
)
2836 ms_shift
= highbit64(asize
/ zfs_vdev_min_ms_count
);
2837 else if (ms_count
> zfs_vdev_default_ms_count
)
2838 ms_shift
= highbit64(asize
/ zfs_vdev_default_ms_count
);
2840 ms_shift
= zfs_vdev_default_ms_shift
;
2842 if (ms_shift
< SPA_MAXBLOCKSHIFT
) {
2843 ms_shift
= SPA_MAXBLOCKSHIFT
;
2844 } else if (ms_shift
> zfs_vdev_max_ms_shift
) {
2845 ms_shift
= zfs_vdev_max_ms_shift
;
2846 /* cap the total count to constrain memory footprint */
2847 if ((asize
>> ms_shift
) > zfs_vdev_ms_count_limit
)
2848 ms_shift
= highbit64(asize
/ zfs_vdev_ms_count_limit
);
2851 vd
->vdev_ms_shift
= ms_shift
;
2852 ASSERT3U(vd
->vdev_ms_shift
, >=, SPA_MAXBLOCKSHIFT
);
2856 vdev_dirty(vdev_t
*vd
, int flags
, void *arg
, uint64_t txg
)
2858 ASSERT(vd
== vd
->vdev_top
);
2859 /* indirect vdevs don't have metaslabs or dtls */
2860 ASSERT(vdev_is_concrete(vd
) || flags
== 0);
2861 ASSERT(ISP2(flags
));
2862 ASSERT(spa_writeable(vd
->vdev_spa
));
2864 if (flags
& VDD_METASLAB
)
2865 (void) txg_list_add(&vd
->vdev_ms_list
, arg
, txg
);
2867 if (flags
& VDD_DTL
)
2868 (void) txg_list_add(&vd
->vdev_dtl_list
, arg
, txg
);
2870 (void) txg_list_add(&vd
->vdev_spa
->spa_vdev_txg_list
, vd
, txg
);
2874 vdev_dirty_leaves(vdev_t
*vd
, int flags
, uint64_t txg
)
2876 for (int c
= 0; c
< vd
->vdev_children
; c
++)
2877 vdev_dirty_leaves(vd
->vdev_child
[c
], flags
, txg
);
2879 if (vd
->vdev_ops
->vdev_op_leaf
)
2880 vdev_dirty(vd
->vdev_top
, flags
, vd
, txg
);
2886 * A vdev's DTL (dirty time log) is the set of transaction groups for which
2887 * the vdev has less than perfect replication. There are four kinds of DTL:
2889 * DTL_MISSING: txgs for which the vdev has no valid copies of the data
2891 * DTL_PARTIAL: txgs for which data is available, but not fully replicated
2893 * DTL_SCRUB: the txgs that could not be repaired by the last scrub; upon
2894 * scrub completion, DTL_SCRUB replaces DTL_MISSING in the range of
2895 * txgs that was scrubbed.
2897 * DTL_OUTAGE: txgs which cannot currently be read, whether due to
2898 * persistent errors or just some device being offline.
2899 * Unlike the other three, the DTL_OUTAGE map is not generally
2900 * maintained; it's only computed when needed, typically to
2901 * determine whether a device can be detached.
2903 * For leaf vdevs, DTL_MISSING and DTL_PARTIAL are identical: the device
2904 * either has the data or it doesn't.
2906 * For interior vdevs such as mirror and RAID-Z the picture is more complex.
2907 * A vdev's DTL_PARTIAL is the union of its children's DTL_PARTIALs, because
2908 * if any child is less than fully replicated, then so is its parent.
2909 * A vdev's DTL_MISSING is a modified union of its children's DTL_MISSINGs,
2910 * comprising only those txgs which appear in 'maxfaults' or more children;
2911 * those are the txgs we don't have enough replication to read. For example,
2912 * double-parity RAID-Z can tolerate up to two missing devices (maxfaults == 2);
2913 * thus, its DTL_MISSING consists of the set of txgs that appear in more than
2914 * two child DTL_MISSING maps.
2916 * It should be clear from the above that to compute the DTLs and outage maps
2917 * for all vdevs, it suffices to know just the leaf vdevs' DTL_MISSING maps.
2918 * Therefore, that is all we keep on disk. When loading the pool, or after
2919 * a configuration change, we generate all other DTLs from first principles.
2922 vdev_dtl_dirty(vdev_t
*vd
, vdev_dtl_type_t t
, uint64_t txg
, uint64_t size
)
2924 range_tree_t
*rt
= vd
->vdev_dtl
[t
];
2926 ASSERT(t
< DTL_TYPES
);
2927 ASSERT(vd
!= vd
->vdev_spa
->spa_root_vdev
);
2928 ASSERT(spa_writeable(vd
->vdev_spa
));
2930 mutex_enter(&vd
->vdev_dtl_lock
);
2931 if (!range_tree_contains(rt
, txg
, size
))
2932 range_tree_add(rt
, txg
, size
);
2933 mutex_exit(&vd
->vdev_dtl_lock
);
2937 vdev_dtl_contains(vdev_t
*vd
, vdev_dtl_type_t t
, uint64_t txg
, uint64_t size
)
2939 range_tree_t
*rt
= vd
->vdev_dtl
[t
];
2940 boolean_t dirty
= B_FALSE
;
2942 ASSERT(t
< DTL_TYPES
);
2943 ASSERT(vd
!= vd
->vdev_spa
->spa_root_vdev
);
2946 * While we are loading the pool, the DTLs have not been loaded yet.
2947 * This isn't a problem but it can result in devices being tried
2948 * which are known to not have the data. In which case, the import
2949 * is relying on the checksum to ensure that we get the right data.
2950 * Note that while importing we are only reading the MOS, which is
2951 * always checksummed.
2953 mutex_enter(&vd
->vdev_dtl_lock
);
2954 if (!range_tree_is_empty(rt
))
2955 dirty
= range_tree_contains(rt
, txg
, size
);
2956 mutex_exit(&vd
->vdev_dtl_lock
);
2962 vdev_dtl_empty(vdev_t
*vd
, vdev_dtl_type_t t
)
2964 range_tree_t
*rt
= vd
->vdev_dtl
[t
];
2967 mutex_enter(&vd
->vdev_dtl_lock
);
2968 empty
= range_tree_is_empty(rt
);
2969 mutex_exit(&vd
->vdev_dtl_lock
);
2975 * Check if the txg falls within the range which must be
2976 * resilvered. DVAs outside this range can always be skipped.
2979 vdev_default_need_resilver(vdev_t
*vd
, const dva_t
*dva
, size_t psize
,
2980 uint64_t phys_birth
)
2982 (void) dva
, (void) psize
;
2984 /* Set by sequential resilver. */
2985 if (phys_birth
== TXG_UNKNOWN
)
2988 return (vdev_dtl_contains(vd
, DTL_PARTIAL
, phys_birth
, 1));
2992 * Returns B_TRUE if the vdev determines the DVA needs to be resilvered.
2995 vdev_dtl_need_resilver(vdev_t
*vd
, const dva_t
*dva
, size_t psize
,
2996 uint64_t phys_birth
)
2998 ASSERT(vd
!= vd
->vdev_spa
->spa_root_vdev
);
3000 if (vd
->vdev_ops
->vdev_op_need_resilver
== NULL
||
3001 vd
->vdev_ops
->vdev_op_leaf
)
3004 return (vd
->vdev_ops
->vdev_op_need_resilver(vd
, dva
, psize
,
3009 * Returns the lowest txg in the DTL range.
3012 vdev_dtl_min(vdev_t
*vd
)
3014 ASSERT(MUTEX_HELD(&vd
->vdev_dtl_lock
));
3015 ASSERT3U(range_tree_space(vd
->vdev_dtl
[DTL_MISSING
]), !=, 0);
3016 ASSERT0(vd
->vdev_children
);
3018 return (range_tree_min(vd
->vdev_dtl
[DTL_MISSING
]) - 1);
3022 * Returns the highest txg in the DTL.
3025 vdev_dtl_max(vdev_t
*vd
)
3027 ASSERT(MUTEX_HELD(&vd
->vdev_dtl_lock
));
3028 ASSERT3U(range_tree_space(vd
->vdev_dtl
[DTL_MISSING
]), !=, 0);
3029 ASSERT0(vd
->vdev_children
);
3031 return (range_tree_max(vd
->vdev_dtl
[DTL_MISSING
]));
3035 * Determine if a resilvering vdev should remove any DTL entries from
3036 * its range. If the vdev was resilvering for the entire duration of the
3037 * scan then it should excise that range from its DTLs. Otherwise, this
3038 * vdev is considered partially resilvered and should leave its DTL
3039 * entries intact. The comment in vdev_dtl_reassess() describes how we
3043 vdev_dtl_should_excise(vdev_t
*vd
, boolean_t rebuild_done
)
3045 ASSERT0(vd
->vdev_children
);
3047 if (vd
->vdev_state
< VDEV_STATE_DEGRADED
)
3050 if (vd
->vdev_resilver_deferred
)
3053 if (range_tree_is_empty(vd
->vdev_dtl
[DTL_MISSING
]))
3057 vdev_rebuild_t
*vr
= &vd
->vdev_top
->vdev_rebuild_config
;
3058 vdev_rebuild_phys_t
*vrp
= &vr
->vr_rebuild_phys
;
3060 /* Rebuild not initiated by attach */
3061 if (vd
->vdev_rebuild_txg
== 0)
3065 * When a rebuild completes without error then all missing data
3066 * up to the rebuild max txg has been reconstructed and the DTL
3067 * is eligible for excision.
3069 if (vrp
->vrp_rebuild_state
== VDEV_REBUILD_COMPLETE
&&
3070 vdev_dtl_max(vd
) <= vrp
->vrp_max_txg
) {
3071 ASSERT3U(vrp
->vrp_min_txg
, <=, vdev_dtl_min(vd
));
3072 ASSERT3U(vrp
->vrp_min_txg
, <, vd
->vdev_rebuild_txg
);
3073 ASSERT3U(vd
->vdev_rebuild_txg
, <=, vrp
->vrp_max_txg
);
3077 dsl_scan_t
*scn
= vd
->vdev_spa
->spa_dsl_pool
->dp_scan
;
3078 dsl_scan_phys_t
*scnp __maybe_unused
= &scn
->scn_phys
;
3080 /* Resilver not initiated by attach */
3081 if (vd
->vdev_resilver_txg
== 0)
3085 * When a resilver is initiated the scan will assign the
3086 * scn_max_txg value to the highest txg value that exists
3087 * in all DTLs. If this device's max DTL is not part of this
3088 * scan (i.e. it is not in the range (scn_min_txg, scn_max_txg]
3089 * then it is not eligible for excision.
3091 if (vdev_dtl_max(vd
) <= scn
->scn_phys
.scn_max_txg
) {
3092 ASSERT3U(scnp
->scn_min_txg
, <=, vdev_dtl_min(vd
));
3093 ASSERT3U(scnp
->scn_min_txg
, <, vd
->vdev_resilver_txg
);
3094 ASSERT3U(vd
->vdev_resilver_txg
, <=, scnp
->scn_max_txg
);
3103 * Reassess DTLs after a config change or scrub completion. If txg == 0 no
3104 * write operations will be issued to the pool.
3107 vdev_dtl_reassess(vdev_t
*vd
, uint64_t txg
, uint64_t scrub_txg
,
3108 boolean_t scrub_done
, boolean_t rebuild_done
)
3110 spa_t
*spa
= vd
->vdev_spa
;
3114 ASSERT(spa_config_held(spa
, SCL_ALL
, RW_READER
) != 0);
3116 for (int c
= 0; c
< vd
->vdev_children
; c
++)
3117 vdev_dtl_reassess(vd
->vdev_child
[c
], txg
,
3118 scrub_txg
, scrub_done
, rebuild_done
);
3120 if (vd
== spa
->spa_root_vdev
|| !vdev_is_concrete(vd
) || vd
->vdev_aux
)
3123 if (vd
->vdev_ops
->vdev_op_leaf
) {
3124 dsl_scan_t
*scn
= spa
->spa_dsl_pool
->dp_scan
;
3125 vdev_rebuild_t
*vr
= &vd
->vdev_top
->vdev_rebuild_config
;
3126 boolean_t check_excise
= B_FALSE
;
3127 boolean_t wasempty
= B_TRUE
;
3129 mutex_enter(&vd
->vdev_dtl_lock
);
3132 * If requested, pretend the scan or rebuild completed cleanly.
3134 if (zfs_scan_ignore_errors
) {
3136 scn
->scn_phys
.scn_errors
= 0;
3138 vr
->vr_rebuild_phys
.vrp_errors
= 0;
3141 if (scrub_txg
!= 0 &&
3142 !range_tree_is_empty(vd
->vdev_dtl
[DTL_MISSING
])) {
3144 zfs_dbgmsg("guid:%llu txg:%llu scrub:%llu started:%d "
3145 "dtl:%llu/%llu errors:%llu",
3146 (u_longlong_t
)vd
->vdev_guid
, (u_longlong_t
)txg
,
3147 (u_longlong_t
)scrub_txg
, spa
->spa_scrub_started
,
3148 (u_longlong_t
)vdev_dtl_min(vd
),
3149 (u_longlong_t
)vdev_dtl_max(vd
),
3150 (u_longlong_t
)(scn
? scn
->scn_phys
.scn_errors
: 0));
3154 * If we've completed a scrub/resilver or a rebuild cleanly
3155 * then determine if this vdev should remove any DTLs. We
3156 * only want to excise regions on vdevs that were available
3157 * during the entire duration of this scan.
3160 vr
!= NULL
&& vr
->vr_rebuild_phys
.vrp_errors
== 0) {
3161 check_excise
= B_TRUE
;
3163 if (spa
->spa_scrub_started
||
3164 (scn
!= NULL
&& scn
->scn_phys
.scn_errors
== 0)) {
3165 check_excise
= B_TRUE
;
3169 if (scrub_txg
&& check_excise
&&
3170 vdev_dtl_should_excise(vd
, rebuild_done
)) {
3172 * We completed a scrub, resilver or rebuild up to
3173 * scrub_txg. If we did it without rebooting, then
3174 * the scrub dtl will be valid, so excise the old
3175 * region and fold in the scrub dtl. Otherwise,
3176 * leave the dtl as-is if there was an error.
3178 * There's little trick here: to excise the beginning
3179 * of the DTL_MISSING map, we put it into a reference
3180 * tree and then add a segment with refcnt -1 that
3181 * covers the range [0, scrub_txg). This means
3182 * that each txg in that range has refcnt -1 or 0.
3183 * We then add DTL_SCRUB with a refcnt of 2, so that
3184 * entries in the range [0, scrub_txg) will have a
3185 * positive refcnt -- either 1 or 2. We then convert
3186 * the reference tree into the new DTL_MISSING map.
3188 space_reftree_create(&reftree
);
3189 space_reftree_add_map(&reftree
,
3190 vd
->vdev_dtl
[DTL_MISSING
], 1);
3191 space_reftree_add_seg(&reftree
, 0, scrub_txg
, -1);
3192 space_reftree_add_map(&reftree
,
3193 vd
->vdev_dtl
[DTL_SCRUB
], 2);
3194 space_reftree_generate_map(&reftree
,
3195 vd
->vdev_dtl
[DTL_MISSING
], 1);
3196 space_reftree_destroy(&reftree
);
3198 if (!range_tree_is_empty(vd
->vdev_dtl
[DTL_MISSING
])) {
3199 zfs_dbgmsg("update DTL_MISSING:%llu/%llu",
3200 (u_longlong_t
)vdev_dtl_min(vd
),
3201 (u_longlong_t
)vdev_dtl_max(vd
));
3202 } else if (!wasempty
) {
3203 zfs_dbgmsg("DTL_MISSING is now empty");
3206 range_tree_vacate(vd
->vdev_dtl
[DTL_PARTIAL
], NULL
, NULL
);
3207 range_tree_walk(vd
->vdev_dtl
[DTL_MISSING
],
3208 range_tree_add
, vd
->vdev_dtl
[DTL_PARTIAL
]);
3210 range_tree_vacate(vd
->vdev_dtl
[DTL_SCRUB
], NULL
, NULL
);
3211 range_tree_vacate(vd
->vdev_dtl
[DTL_OUTAGE
], NULL
, NULL
);
3212 if (!vdev_readable(vd
))
3213 range_tree_add(vd
->vdev_dtl
[DTL_OUTAGE
], 0, -1ULL);
3215 range_tree_walk(vd
->vdev_dtl
[DTL_MISSING
],
3216 range_tree_add
, vd
->vdev_dtl
[DTL_OUTAGE
]);
3219 * If the vdev was resilvering or rebuilding and no longer
3220 * has any DTLs then reset the appropriate flag and dirty
3221 * the top level so that we persist the change.
3224 range_tree_is_empty(vd
->vdev_dtl
[DTL_MISSING
]) &&
3225 range_tree_is_empty(vd
->vdev_dtl
[DTL_OUTAGE
])) {
3226 if (vd
->vdev_rebuild_txg
!= 0) {
3227 vd
->vdev_rebuild_txg
= 0;
3228 vdev_config_dirty(vd
->vdev_top
);
3229 } else if (vd
->vdev_resilver_txg
!= 0) {
3230 vd
->vdev_resilver_txg
= 0;
3231 vdev_config_dirty(vd
->vdev_top
);
3235 mutex_exit(&vd
->vdev_dtl_lock
);
3238 vdev_dirty(vd
->vdev_top
, VDD_DTL
, vd
, txg
);
3240 mutex_enter(&vd
->vdev_dtl_lock
);
3241 for (int t
= 0; t
< DTL_TYPES
; t
++) {
3242 /* account for child's outage in parent's missing map */
3243 int s
= (t
== DTL_MISSING
) ? DTL_OUTAGE
: t
;
3244 if (t
== DTL_SCRUB
) {
3245 /* leaf vdevs only */
3248 if (t
== DTL_PARTIAL
) {
3251 } else if (vdev_get_nparity(vd
) != 0) {
3253 minref
= vdev_get_nparity(vd
) + 1;
3255 /* any kind of mirror */
3256 minref
= vd
->vdev_children
;
3258 space_reftree_create(&reftree
);
3259 for (int c
= 0; c
< vd
->vdev_children
; c
++) {
3260 vdev_t
*cvd
= vd
->vdev_child
[c
];
3261 mutex_enter(&cvd
->vdev_dtl_lock
);
3262 space_reftree_add_map(&reftree
,
3263 cvd
->vdev_dtl
[s
], 1);
3264 mutex_exit(&cvd
->vdev_dtl_lock
);
3266 space_reftree_generate_map(&reftree
,
3267 vd
->vdev_dtl
[t
], minref
);
3268 space_reftree_destroy(&reftree
);
3270 mutex_exit(&vd
->vdev_dtl_lock
);
3273 if (vd
->vdev_top
->vdev_ops
== &vdev_raidz_ops
) {
3274 raidz_dtl_reassessed(vd
);
3279 * Iterate over all the vdevs except spare, and post kobj events
3282 vdev_post_kobj_evt(vdev_t
*vd
)
3284 if (vd
->vdev_ops
->vdev_op_kobj_evt_post
&&
3285 vd
->vdev_kobj_flag
== B_FALSE
) {
3286 vd
->vdev_kobj_flag
= B_TRUE
;
3287 vd
->vdev_ops
->vdev_op_kobj_evt_post(vd
);
3290 for (int c
= 0; c
< vd
->vdev_children
; c
++)
3291 vdev_post_kobj_evt(vd
->vdev_child
[c
]);
3295 * Iterate over all the vdevs except spare, and clear kobj events
3298 vdev_clear_kobj_evt(vdev_t
*vd
)
3300 vd
->vdev_kobj_flag
= B_FALSE
;
3302 for (int c
= 0; c
< vd
->vdev_children
; c
++)
3303 vdev_clear_kobj_evt(vd
->vdev_child
[c
]);
3307 vdev_dtl_load(vdev_t
*vd
)
3309 spa_t
*spa
= vd
->vdev_spa
;
3310 objset_t
*mos
= spa
->spa_meta_objset
;
3314 if (vd
->vdev_ops
->vdev_op_leaf
&& vd
->vdev_dtl_object
!= 0) {
3315 ASSERT(vdev_is_concrete(vd
));
3318 * If the dtl cannot be sync'd there is no need to open it.
3320 if (spa
->spa_mode
== SPA_MODE_READ
&& !spa
->spa_read_spacemaps
)
3323 error
= space_map_open(&vd
->vdev_dtl_sm
, mos
,
3324 vd
->vdev_dtl_object
, 0, -1ULL, 0);
3327 ASSERT(vd
->vdev_dtl_sm
!= NULL
);
3329 rt
= range_tree_create(NULL
, RANGE_SEG64
, NULL
, 0, 0);
3330 error
= space_map_load(vd
->vdev_dtl_sm
, rt
, SM_ALLOC
);
3332 mutex_enter(&vd
->vdev_dtl_lock
);
3333 range_tree_walk(rt
, range_tree_add
,
3334 vd
->vdev_dtl
[DTL_MISSING
]);
3335 mutex_exit(&vd
->vdev_dtl_lock
);
3338 range_tree_vacate(rt
, NULL
, NULL
);
3339 range_tree_destroy(rt
);
3344 for (int c
= 0; c
< vd
->vdev_children
; c
++) {
3345 error
= vdev_dtl_load(vd
->vdev_child
[c
]);
3354 vdev_zap_allocation_data(vdev_t
*vd
, dmu_tx_t
*tx
)
3356 spa_t
*spa
= vd
->vdev_spa
;
3357 objset_t
*mos
= spa
->spa_meta_objset
;
3358 vdev_alloc_bias_t alloc_bias
= vd
->vdev_alloc_bias
;
3361 ASSERT(alloc_bias
!= VDEV_BIAS_NONE
);
3364 (alloc_bias
== VDEV_BIAS_LOG
) ? VDEV_ALLOC_BIAS_LOG
:
3365 (alloc_bias
== VDEV_BIAS_SPECIAL
) ? VDEV_ALLOC_BIAS_SPECIAL
:
3366 (alloc_bias
== VDEV_BIAS_DEDUP
) ? VDEV_ALLOC_BIAS_DEDUP
: NULL
;
3368 ASSERT(string
!= NULL
);
3369 VERIFY0(zap_add(mos
, vd
->vdev_top_zap
, VDEV_TOP_ZAP_ALLOCATION_BIAS
,
3370 1, strlen(string
) + 1, string
, tx
));
3372 if (alloc_bias
== VDEV_BIAS_SPECIAL
|| alloc_bias
== VDEV_BIAS_DEDUP
) {
3373 spa_activate_allocation_classes(spa
, tx
);
3378 vdev_destroy_unlink_zap(vdev_t
*vd
, uint64_t zapobj
, dmu_tx_t
*tx
)
3380 spa_t
*spa
= vd
->vdev_spa
;
3382 VERIFY0(zap_destroy(spa
->spa_meta_objset
, zapobj
, tx
));
3383 VERIFY0(zap_remove_int(spa
->spa_meta_objset
, spa
->spa_all_vdev_zaps
,
3388 vdev_create_link_zap(vdev_t
*vd
, dmu_tx_t
*tx
)
3390 spa_t
*spa
= vd
->vdev_spa
;
3391 uint64_t zap
= zap_create(spa
->spa_meta_objset
, DMU_OTN_ZAP_METADATA
,
3392 DMU_OT_NONE
, 0, tx
);
3395 VERIFY0(zap_add_int(spa
->spa_meta_objset
, spa
->spa_all_vdev_zaps
,
3402 vdev_construct_zaps(vdev_t
*vd
, dmu_tx_t
*tx
)
3404 if (vd
->vdev_ops
!= &vdev_hole_ops
&&
3405 vd
->vdev_ops
!= &vdev_missing_ops
&&
3406 vd
->vdev_ops
!= &vdev_root_ops
&&
3407 !vd
->vdev_top
->vdev_removing
) {
3408 if (vd
->vdev_ops
->vdev_op_leaf
&& vd
->vdev_leaf_zap
== 0) {
3409 vd
->vdev_leaf_zap
= vdev_create_link_zap(vd
, tx
);
3411 if (vd
== vd
->vdev_top
&& vd
->vdev_top_zap
== 0) {
3412 vd
->vdev_top_zap
= vdev_create_link_zap(vd
, tx
);
3413 if (vd
->vdev_alloc_bias
!= VDEV_BIAS_NONE
)
3414 vdev_zap_allocation_data(vd
, tx
);
3417 if (vd
->vdev_ops
== &vdev_root_ops
&& vd
->vdev_root_zap
== 0 &&
3418 spa_feature_is_enabled(vd
->vdev_spa
, SPA_FEATURE_AVZ_V2
)) {
3419 if (!spa_feature_is_active(vd
->vdev_spa
, SPA_FEATURE_AVZ_V2
))
3420 spa_feature_incr(vd
->vdev_spa
, SPA_FEATURE_AVZ_V2
, tx
);
3421 vd
->vdev_root_zap
= vdev_create_link_zap(vd
, tx
);
3424 for (uint64_t i
= 0; i
< vd
->vdev_children
; i
++) {
3425 vdev_construct_zaps(vd
->vdev_child
[i
], tx
);
3430 vdev_dtl_sync(vdev_t
*vd
, uint64_t txg
)
3432 spa_t
*spa
= vd
->vdev_spa
;
3433 range_tree_t
*rt
= vd
->vdev_dtl
[DTL_MISSING
];
3434 objset_t
*mos
= spa
->spa_meta_objset
;
3435 range_tree_t
*rtsync
;
3437 uint64_t object
= space_map_object(vd
->vdev_dtl_sm
);
3439 ASSERT(vdev_is_concrete(vd
));
3440 ASSERT(vd
->vdev_ops
->vdev_op_leaf
);
3442 tx
= dmu_tx_create_assigned(spa
->spa_dsl_pool
, txg
);
3444 if (vd
->vdev_detached
|| vd
->vdev_top
->vdev_removing
) {
3445 mutex_enter(&vd
->vdev_dtl_lock
);
3446 space_map_free(vd
->vdev_dtl_sm
, tx
);
3447 space_map_close(vd
->vdev_dtl_sm
);
3448 vd
->vdev_dtl_sm
= NULL
;
3449 mutex_exit(&vd
->vdev_dtl_lock
);
3452 * We only destroy the leaf ZAP for detached leaves or for
3453 * removed log devices. Removed data devices handle leaf ZAP
3454 * cleanup later, once cancellation is no longer possible.
3456 if (vd
->vdev_leaf_zap
!= 0 && (vd
->vdev_detached
||
3457 vd
->vdev_top
->vdev_islog
)) {
3458 vdev_destroy_unlink_zap(vd
, vd
->vdev_leaf_zap
, tx
);
3459 vd
->vdev_leaf_zap
= 0;
3466 if (vd
->vdev_dtl_sm
== NULL
) {
3467 uint64_t new_object
;
3469 new_object
= space_map_alloc(mos
, zfs_vdev_dtl_sm_blksz
, tx
);
3470 VERIFY3U(new_object
, !=, 0);
3472 VERIFY0(space_map_open(&vd
->vdev_dtl_sm
, mos
, new_object
,
3474 ASSERT(vd
->vdev_dtl_sm
!= NULL
);
3477 rtsync
= range_tree_create(NULL
, RANGE_SEG64
, NULL
, 0, 0);
3479 mutex_enter(&vd
->vdev_dtl_lock
);
3480 range_tree_walk(rt
, range_tree_add
, rtsync
);
3481 mutex_exit(&vd
->vdev_dtl_lock
);
3483 space_map_truncate(vd
->vdev_dtl_sm
, zfs_vdev_dtl_sm_blksz
, tx
);
3484 space_map_write(vd
->vdev_dtl_sm
, rtsync
, SM_ALLOC
, SM_NO_VDEVID
, tx
);
3485 range_tree_vacate(rtsync
, NULL
, NULL
);
3487 range_tree_destroy(rtsync
);
3490 * If the object for the space map has changed then dirty
3491 * the top level so that we update the config.
3493 if (object
!= space_map_object(vd
->vdev_dtl_sm
)) {
3494 vdev_dbgmsg(vd
, "txg %llu, spa %s, DTL old object %llu, "
3495 "new object %llu", (u_longlong_t
)txg
, spa_name(spa
),
3496 (u_longlong_t
)object
,
3497 (u_longlong_t
)space_map_object(vd
->vdev_dtl_sm
));
3498 vdev_config_dirty(vd
->vdev_top
);
3505 * Determine whether the specified vdev can be offlined/detached/removed
3506 * without losing data.
3509 vdev_dtl_required(vdev_t
*vd
)
3511 spa_t
*spa
= vd
->vdev_spa
;
3512 vdev_t
*tvd
= vd
->vdev_top
;
3513 uint8_t cant_read
= vd
->vdev_cant_read
;
3516 ASSERT(spa_config_held(spa
, SCL_STATE_ALL
, RW_WRITER
) == SCL_STATE_ALL
);
3518 if (vd
== spa
->spa_root_vdev
|| vd
== tvd
)
3522 * Temporarily mark the device as unreadable, and then determine
3523 * whether this results in any DTL outages in the top-level vdev.
3524 * If not, we can safely offline/detach/remove the device.
3526 vd
->vdev_cant_read
= B_TRUE
;
3527 vdev_dtl_reassess(tvd
, 0, 0, B_FALSE
, B_FALSE
);
3528 required
= !vdev_dtl_empty(tvd
, DTL_OUTAGE
);
3529 vd
->vdev_cant_read
= cant_read
;
3530 vdev_dtl_reassess(tvd
, 0, 0, B_FALSE
, B_FALSE
);
3532 if (!required
&& zio_injection_enabled
) {
3533 required
= !!zio_handle_device_injection(vd
, NULL
,
3541 * Determine if resilver is needed, and if so the txg range.
3544 vdev_resilver_needed(vdev_t
*vd
, uint64_t *minp
, uint64_t *maxp
)
3546 boolean_t needed
= B_FALSE
;
3547 uint64_t thismin
= UINT64_MAX
;
3548 uint64_t thismax
= 0;
3550 if (vd
->vdev_children
== 0) {
3551 mutex_enter(&vd
->vdev_dtl_lock
);
3552 if (!range_tree_is_empty(vd
->vdev_dtl
[DTL_MISSING
]) &&
3553 vdev_writeable(vd
)) {
3555 thismin
= vdev_dtl_min(vd
);
3556 thismax
= vdev_dtl_max(vd
);
3559 mutex_exit(&vd
->vdev_dtl_lock
);
3561 for (int c
= 0; c
< vd
->vdev_children
; c
++) {
3562 vdev_t
*cvd
= vd
->vdev_child
[c
];
3563 uint64_t cmin
, cmax
;
3565 if (vdev_resilver_needed(cvd
, &cmin
, &cmax
)) {
3566 thismin
= MIN(thismin
, cmin
);
3567 thismax
= MAX(thismax
, cmax
);
3573 if (needed
&& minp
) {
3581 * Gets the checkpoint space map object from the vdev's ZAP. On success sm_obj
3582 * will contain either the checkpoint spacemap object or zero if none exists.
3583 * All other errors are returned to the caller.
3586 vdev_checkpoint_sm_object(vdev_t
*vd
, uint64_t *sm_obj
)
3588 ASSERT0(spa_config_held(vd
->vdev_spa
, SCL_ALL
, RW_WRITER
));
3590 if (vd
->vdev_top_zap
== 0) {
3595 int error
= zap_lookup(spa_meta_objset(vd
->vdev_spa
), vd
->vdev_top_zap
,
3596 VDEV_TOP_ZAP_POOL_CHECKPOINT_SM
, sizeof (uint64_t), 1, sm_obj
);
3597 if (error
== ENOENT
) {
3606 vdev_load(vdev_t
*vd
)
3608 int children
= vd
->vdev_children
;
3613 * It's only worthwhile to use the taskq for the root vdev, because the
3614 * slow part is metaslab_init, and that only happens for top-level
3617 if (vd
->vdev_ops
== &vdev_root_ops
&& vd
->vdev_children
> 0) {
3618 tq
= taskq_create("vdev_load", children
, minclsyspri
,
3619 children
, children
, TASKQ_PREPOPULATE
);
3623 * Recursively load all children.
3625 for (int c
= 0; c
< vd
->vdev_children
; c
++) {
3626 vdev_t
*cvd
= vd
->vdev_child
[c
];
3628 if (tq
== NULL
|| vdev_uses_zvols(cvd
)) {
3629 cvd
->vdev_load_error
= vdev_load(cvd
);
3631 VERIFY(taskq_dispatch(tq
, vdev_load_child
,
3632 cvd
, TQ_SLEEP
) != TASKQID_INVALID
);
3641 for (int c
= 0; c
< vd
->vdev_children
; c
++) {
3642 int error
= vd
->vdev_child
[c
]->vdev_load_error
;
3648 vdev_set_deflate_ratio(vd
);
3650 if (vd
->vdev_ops
== &vdev_raidz_ops
) {
3651 error
= vdev_raidz_load(vd
);
3657 * On spa_load path, grab the allocation bias from our zap
3659 if (vd
== vd
->vdev_top
&& vd
->vdev_top_zap
!= 0) {
3660 spa_t
*spa
= vd
->vdev_spa
;
3663 error
= zap_lookup(spa
->spa_meta_objset
, vd
->vdev_top_zap
,
3664 VDEV_TOP_ZAP_ALLOCATION_BIAS
, 1, sizeof (bias_str
),
3667 ASSERT(vd
->vdev_alloc_bias
== VDEV_BIAS_NONE
);
3668 vd
->vdev_alloc_bias
= vdev_derive_alloc_bias(bias_str
);
3669 } else if (error
!= ENOENT
) {
3670 vdev_set_state(vd
, B_FALSE
, VDEV_STATE_CANT_OPEN
,
3671 VDEV_AUX_CORRUPT_DATA
);
3672 vdev_dbgmsg(vd
, "vdev_load: zap_lookup(top_zap=%llu) "
3673 "failed [error=%d]",
3674 (u_longlong_t
)vd
->vdev_top_zap
, error
);
3679 if (vd
== vd
->vdev_top
&& vd
->vdev_top_zap
!= 0) {
3680 spa_t
*spa
= vd
->vdev_spa
;
3683 error
= zap_lookup(spa
->spa_meta_objset
, vd
->vdev_top_zap
,
3684 vdev_prop_to_name(VDEV_PROP_FAILFAST
), sizeof (failfast
),
3687 vd
->vdev_failfast
= failfast
& 1;
3688 } else if (error
== ENOENT
) {
3689 vd
->vdev_failfast
= vdev_prop_default_numeric(
3690 VDEV_PROP_FAILFAST
);
3693 "vdev_load: zap_lookup(top_zap=%llu) "
3694 "failed [error=%d]",
3695 (u_longlong_t
)vd
->vdev_top_zap
, error
);
3700 * Load any rebuild state from the top-level vdev zap.
3702 if (vd
== vd
->vdev_top
&& vd
->vdev_top_zap
!= 0) {
3703 error
= vdev_rebuild_load(vd
);
3704 if (error
&& error
!= ENOTSUP
) {
3705 vdev_set_state(vd
, B_FALSE
, VDEV_STATE_CANT_OPEN
,
3706 VDEV_AUX_CORRUPT_DATA
);
3707 vdev_dbgmsg(vd
, "vdev_load: vdev_rebuild_load "
3708 "failed [error=%d]", error
);
3713 if (vd
->vdev_top_zap
!= 0 || vd
->vdev_leaf_zap
!= 0) {
3716 if (vd
->vdev_top_zap
!= 0)
3717 zapobj
= vd
->vdev_top_zap
;
3719 zapobj
= vd
->vdev_leaf_zap
;
3721 error
= vdev_prop_get_int(vd
, VDEV_PROP_CHECKSUM_N
,
3722 &vd
->vdev_checksum_n
);
3723 if (error
&& error
!= ENOENT
)
3724 vdev_dbgmsg(vd
, "vdev_load: zap_lookup(zap=%llu) "
3725 "failed [error=%d]", (u_longlong_t
)zapobj
, error
);
3727 error
= vdev_prop_get_int(vd
, VDEV_PROP_CHECKSUM_T
,
3728 &vd
->vdev_checksum_t
);
3729 if (error
&& error
!= ENOENT
)
3730 vdev_dbgmsg(vd
, "vdev_load: zap_lookup(zap=%llu) "
3731 "failed [error=%d]", (u_longlong_t
)zapobj
, error
);
3733 error
= vdev_prop_get_int(vd
, VDEV_PROP_IO_N
,
3735 if (error
&& error
!= ENOENT
)
3736 vdev_dbgmsg(vd
, "vdev_load: zap_lookup(zap=%llu) "
3737 "failed [error=%d]", (u_longlong_t
)zapobj
, error
);
3739 error
= vdev_prop_get_int(vd
, VDEV_PROP_IO_T
,
3741 if (error
&& error
!= ENOENT
)
3742 vdev_dbgmsg(vd
, "vdev_load: zap_lookup(zap=%llu) "
3743 "failed [error=%d]", (u_longlong_t
)zapobj
, error
);
3747 * If this is a top-level vdev, initialize its metaslabs.
3749 if (vd
== vd
->vdev_top
&& vdev_is_concrete(vd
)) {
3750 vdev_metaslab_group_create(vd
);
3752 if (vd
->vdev_ashift
== 0 || vd
->vdev_asize
== 0) {
3753 vdev_set_state(vd
, B_FALSE
, VDEV_STATE_CANT_OPEN
,
3754 VDEV_AUX_CORRUPT_DATA
);
3755 vdev_dbgmsg(vd
, "vdev_load: invalid size. ashift=%llu, "
3756 "asize=%llu", (u_longlong_t
)vd
->vdev_ashift
,
3757 (u_longlong_t
)vd
->vdev_asize
);
3758 return (SET_ERROR(ENXIO
));
3761 error
= vdev_metaslab_init(vd
, 0);
3763 vdev_dbgmsg(vd
, "vdev_load: metaslab_init failed "
3764 "[error=%d]", error
);
3765 vdev_set_state(vd
, B_FALSE
, VDEV_STATE_CANT_OPEN
,
3766 VDEV_AUX_CORRUPT_DATA
);
3770 uint64_t checkpoint_sm_obj
;
3771 error
= vdev_checkpoint_sm_object(vd
, &checkpoint_sm_obj
);
3772 if (error
== 0 && checkpoint_sm_obj
!= 0) {
3773 objset_t
*mos
= spa_meta_objset(vd
->vdev_spa
);
3774 ASSERT(vd
->vdev_asize
!= 0);
3775 ASSERT3P(vd
->vdev_checkpoint_sm
, ==, NULL
);
3777 error
= space_map_open(&vd
->vdev_checkpoint_sm
,
3778 mos
, checkpoint_sm_obj
, 0, vd
->vdev_asize
,
3781 vdev_dbgmsg(vd
, "vdev_load: space_map_open "
3782 "failed for checkpoint spacemap (obj %llu) "
3784 (u_longlong_t
)checkpoint_sm_obj
, error
);
3787 ASSERT3P(vd
->vdev_checkpoint_sm
, !=, NULL
);
3790 * Since the checkpoint_sm contains free entries
3791 * exclusively we can use space_map_allocated() to
3792 * indicate the cumulative checkpointed space that
3795 vd
->vdev_stat
.vs_checkpoint_space
=
3796 -space_map_allocated(vd
->vdev_checkpoint_sm
);
3797 vd
->vdev_spa
->spa_checkpoint_info
.sci_dspace
+=
3798 vd
->vdev_stat
.vs_checkpoint_space
;
3799 } else if (error
!= 0) {
3800 vdev_dbgmsg(vd
, "vdev_load: failed to retrieve "
3801 "checkpoint space map object from vdev ZAP "
3802 "[error=%d]", error
);
3808 * If this is a leaf vdev, load its DTL.
3810 if (vd
->vdev_ops
->vdev_op_leaf
&& (error
= vdev_dtl_load(vd
)) != 0) {
3811 vdev_set_state(vd
, B_FALSE
, VDEV_STATE_CANT_OPEN
,
3812 VDEV_AUX_CORRUPT_DATA
);
3813 vdev_dbgmsg(vd
, "vdev_load: vdev_dtl_load failed "
3814 "[error=%d]", error
);
3818 uint64_t obsolete_sm_object
;
3819 error
= vdev_obsolete_sm_object(vd
, &obsolete_sm_object
);
3820 if (error
== 0 && obsolete_sm_object
!= 0) {
3821 objset_t
*mos
= vd
->vdev_spa
->spa_meta_objset
;
3822 ASSERT(vd
->vdev_asize
!= 0);
3823 ASSERT3P(vd
->vdev_obsolete_sm
, ==, NULL
);
3825 if ((error
= space_map_open(&vd
->vdev_obsolete_sm
, mos
,
3826 obsolete_sm_object
, 0, vd
->vdev_asize
, 0))) {
3827 vdev_set_state(vd
, B_FALSE
, VDEV_STATE_CANT_OPEN
,
3828 VDEV_AUX_CORRUPT_DATA
);
3829 vdev_dbgmsg(vd
, "vdev_load: space_map_open failed for "
3830 "obsolete spacemap (obj %llu) [error=%d]",
3831 (u_longlong_t
)obsolete_sm_object
, error
);
3834 } else if (error
!= 0) {
3835 vdev_dbgmsg(vd
, "vdev_load: failed to retrieve obsolete "
3836 "space map object from vdev ZAP [error=%d]", error
);
3844 * The special vdev case is used for hot spares and l2cache devices. Its
3845 * sole purpose it to set the vdev state for the associated vdev. To do this,
3846 * we make sure that we can open the underlying device, then try to read the
3847 * label, and make sure that the label is sane and that it hasn't been
3848 * repurposed to another pool.
3851 vdev_validate_aux(vdev_t
*vd
)
3854 uint64_t guid
, version
;
3857 if (!vdev_readable(vd
))
3860 if ((label
= vdev_label_read_config(vd
, -1ULL)) == NULL
) {
3861 vdev_set_state(vd
, B_TRUE
, VDEV_STATE_CANT_OPEN
,
3862 VDEV_AUX_CORRUPT_DATA
);
3866 if (nvlist_lookup_uint64(label
, ZPOOL_CONFIG_VERSION
, &version
) != 0 ||
3867 !SPA_VERSION_IS_SUPPORTED(version
) ||
3868 nvlist_lookup_uint64(label
, ZPOOL_CONFIG_GUID
, &guid
) != 0 ||
3869 guid
!= vd
->vdev_guid
||
3870 nvlist_lookup_uint64(label
, ZPOOL_CONFIG_POOL_STATE
, &state
) != 0) {
3871 vdev_set_state(vd
, B_TRUE
, VDEV_STATE_CANT_OPEN
,
3872 VDEV_AUX_CORRUPT_DATA
);
3878 * We don't actually check the pool state here. If it's in fact in
3879 * use by another pool, we update this fact on the fly when requested.
3886 vdev_destroy_ms_flush_data(vdev_t
*vd
, dmu_tx_t
*tx
)
3888 objset_t
*mos
= spa_meta_objset(vd
->vdev_spa
);
3890 if (vd
->vdev_top_zap
== 0)
3893 uint64_t object
= 0;
3894 int err
= zap_lookup(mos
, vd
->vdev_top_zap
,
3895 VDEV_TOP_ZAP_MS_UNFLUSHED_PHYS_TXGS
, sizeof (uint64_t), 1, &object
);
3900 VERIFY0(dmu_object_free(mos
, object
, tx
));
3901 VERIFY0(zap_remove(mos
, vd
->vdev_top_zap
,
3902 VDEV_TOP_ZAP_MS_UNFLUSHED_PHYS_TXGS
, tx
));
3906 * Free the objects used to store this vdev's spacemaps, and the array
3907 * that points to them.
3910 vdev_destroy_spacemaps(vdev_t
*vd
, dmu_tx_t
*tx
)
3912 if (vd
->vdev_ms_array
== 0)
3915 objset_t
*mos
= vd
->vdev_spa
->spa_meta_objset
;
3916 uint64_t array_count
= vd
->vdev_asize
>> vd
->vdev_ms_shift
;
3917 size_t array_bytes
= array_count
* sizeof (uint64_t);
3918 uint64_t *smobj_array
= kmem_alloc(array_bytes
, KM_SLEEP
);
3919 VERIFY0(dmu_read(mos
, vd
->vdev_ms_array
, 0,
3920 array_bytes
, smobj_array
, 0));
3922 for (uint64_t i
= 0; i
< array_count
; i
++) {
3923 uint64_t smobj
= smobj_array
[i
];
3927 space_map_free_obj(mos
, smobj
, tx
);
3930 kmem_free(smobj_array
, array_bytes
);
3931 VERIFY0(dmu_object_free(mos
, vd
->vdev_ms_array
, tx
));
3932 vdev_destroy_ms_flush_data(vd
, tx
);
3933 vd
->vdev_ms_array
= 0;
3937 vdev_remove_empty_log(vdev_t
*vd
, uint64_t txg
)
3939 spa_t
*spa
= vd
->vdev_spa
;
3941 ASSERT(vd
->vdev_islog
);
3942 ASSERT(vd
== vd
->vdev_top
);
3943 ASSERT3U(txg
, ==, spa_syncing_txg(spa
));
3945 dmu_tx_t
*tx
= dmu_tx_create_assigned(spa_get_dsl(spa
), txg
);
3947 vdev_destroy_spacemaps(vd
, tx
);
3948 if (vd
->vdev_top_zap
!= 0) {
3949 vdev_destroy_unlink_zap(vd
, vd
->vdev_top_zap
, tx
);
3950 vd
->vdev_top_zap
= 0;
3957 vdev_sync_done(vdev_t
*vd
, uint64_t txg
)
3960 boolean_t reassess
= !txg_list_empty(&vd
->vdev_ms_list
, TXG_CLEAN(txg
));
3962 ASSERT(vdev_is_concrete(vd
));
3964 while ((msp
= txg_list_remove(&vd
->vdev_ms_list
, TXG_CLEAN(txg
)))
3966 metaslab_sync_done(msp
, txg
);
3969 metaslab_sync_reassess(vd
->vdev_mg
);
3970 if (vd
->vdev_log_mg
!= NULL
)
3971 metaslab_sync_reassess(vd
->vdev_log_mg
);
3976 vdev_sync(vdev_t
*vd
, uint64_t txg
)
3978 spa_t
*spa
= vd
->vdev_spa
;
3982 ASSERT3U(txg
, ==, spa
->spa_syncing_txg
);
3983 dmu_tx_t
*tx
= dmu_tx_create_assigned(spa
->spa_dsl_pool
, txg
);
3984 if (range_tree_space(vd
->vdev_obsolete_segments
) > 0) {
3985 ASSERT(vd
->vdev_removing
||
3986 vd
->vdev_ops
== &vdev_indirect_ops
);
3988 vdev_indirect_sync_obsolete(vd
, tx
);
3991 * If the vdev is indirect, it can't have dirty
3992 * metaslabs or DTLs.
3994 if (vd
->vdev_ops
== &vdev_indirect_ops
) {
3995 ASSERT(txg_list_empty(&vd
->vdev_ms_list
, txg
));
3996 ASSERT(txg_list_empty(&vd
->vdev_dtl_list
, txg
));
4002 ASSERT(vdev_is_concrete(vd
));
4004 if (vd
->vdev_ms_array
== 0 && vd
->vdev_ms_shift
!= 0 &&
4005 !vd
->vdev_removing
) {
4006 ASSERT(vd
== vd
->vdev_top
);
4007 ASSERT0(vd
->vdev_indirect_config
.vic_mapping_object
);
4008 vd
->vdev_ms_array
= dmu_object_alloc(spa
->spa_meta_objset
,
4009 DMU_OT_OBJECT_ARRAY
, 0, DMU_OT_NONE
, 0, tx
);
4010 ASSERT(vd
->vdev_ms_array
!= 0);
4011 vdev_config_dirty(vd
);
4014 while ((msp
= txg_list_remove(&vd
->vdev_ms_list
, txg
)) != NULL
) {
4015 metaslab_sync(msp
, txg
);
4016 (void) txg_list_add(&vd
->vdev_ms_list
, msp
, TXG_CLEAN(txg
));
4019 while ((lvd
= txg_list_remove(&vd
->vdev_dtl_list
, txg
)) != NULL
)
4020 vdev_dtl_sync(lvd
, txg
);
4023 * If this is an empty log device being removed, destroy the
4024 * metadata associated with it.
4026 if (vd
->vdev_islog
&& vd
->vdev_stat
.vs_alloc
== 0 && vd
->vdev_removing
)
4027 vdev_remove_empty_log(vd
, txg
);
4029 (void) txg_list_add(&spa
->spa_vdev_txg_list
, vd
, TXG_CLEAN(txg
));
4034 * Return the amount of space that should be (or was) allocated for the given
4035 * psize (compressed block size) in the given TXG. Note that for expanded
4036 * RAIDZ vdevs, the size allocated for older BP's may be larger. See
4037 * vdev_raidz_asize().
4040 vdev_psize_to_asize_txg(vdev_t
*vd
, uint64_t psize
, uint64_t txg
)
4042 return (vd
->vdev_ops
->vdev_op_asize(vd
, psize
, txg
));
4046 vdev_psize_to_asize(vdev_t
*vd
, uint64_t psize
)
4048 return (vdev_psize_to_asize_txg(vd
, psize
, 0));
4052 * Mark the given vdev faulted. A faulted vdev behaves as if the device could
4053 * not be opened, and no I/O is attempted.
4056 vdev_fault(spa_t
*spa
, uint64_t guid
, vdev_aux_t aux
)
4060 spa_vdev_state_enter(spa
, SCL_NONE
);
4062 if ((vd
= spa_lookup_by_guid(spa
, guid
, B_TRUE
)) == NULL
)
4063 return (spa_vdev_state_exit(spa
, NULL
, SET_ERROR(ENODEV
)));
4065 if (!vd
->vdev_ops
->vdev_op_leaf
)
4066 return (spa_vdev_state_exit(spa
, NULL
, SET_ERROR(ENOTSUP
)));
4071 * If user did a 'zpool offline -f' then make the fault persist across
4074 if (aux
== VDEV_AUX_EXTERNAL_PERSIST
) {
4076 * There are two kinds of forced faults: temporary and
4077 * persistent. Temporary faults go away at pool import, while
4078 * persistent faults stay set. Both types of faults can be
4079 * cleared with a zpool clear.
4081 * We tell if a vdev is persistently faulted by looking at the
4082 * ZPOOL_CONFIG_AUX_STATE nvpair. If it's set to "external" at
4083 * import then it's a persistent fault. Otherwise, it's
4084 * temporary. We get ZPOOL_CONFIG_AUX_STATE set to "external"
4085 * by setting vd.vdev_stat.vs_aux to VDEV_AUX_EXTERNAL. This
4086 * tells vdev_config_generate() (which gets run later) to set
4087 * ZPOOL_CONFIG_AUX_STATE to "external" in the nvlist.
4089 vd
->vdev_stat
.vs_aux
= VDEV_AUX_EXTERNAL
;
4090 vd
->vdev_tmpoffline
= B_FALSE
;
4091 aux
= VDEV_AUX_EXTERNAL
;
4093 vd
->vdev_tmpoffline
= B_TRUE
;
4097 * We don't directly use the aux state here, but if we do a
4098 * vdev_reopen(), we need this value to be present to remember why we
4101 vd
->vdev_label_aux
= aux
;
4104 * Faulted state takes precedence over degraded.
4106 vd
->vdev_delayed_close
= B_FALSE
;
4107 vd
->vdev_faulted
= 1ULL;
4108 vd
->vdev_degraded
= 0ULL;
4109 vdev_set_state(vd
, B_FALSE
, VDEV_STATE_FAULTED
, aux
);
4112 * If this device has the only valid copy of the data, then
4113 * back off and simply mark the vdev as degraded instead.
4115 if (!tvd
->vdev_islog
&& vd
->vdev_aux
== NULL
&& vdev_dtl_required(vd
)) {
4116 vd
->vdev_degraded
= 1ULL;
4117 vd
->vdev_faulted
= 0ULL;
4120 * If we reopen the device and it's not dead, only then do we
4125 if (vdev_readable(vd
))
4126 vdev_set_state(vd
, B_FALSE
, VDEV_STATE_DEGRADED
, aux
);
4129 return (spa_vdev_state_exit(spa
, vd
, 0));
4133 * Mark the given vdev degraded. A degraded vdev is purely an indication to the
4134 * user that something is wrong. The vdev continues to operate as normal as far
4135 * as I/O is concerned.
4138 vdev_degrade(spa_t
*spa
, uint64_t guid
, vdev_aux_t aux
)
4142 spa_vdev_state_enter(spa
, SCL_NONE
);
4144 if ((vd
= spa_lookup_by_guid(spa
, guid
, B_TRUE
)) == NULL
)
4145 return (spa_vdev_state_exit(spa
, NULL
, SET_ERROR(ENODEV
)));
4147 if (!vd
->vdev_ops
->vdev_op_leaf
)
4148 return (spa_vdev_state_exit(spa
, NULL
, SET_ERROR(ENOTSUP
)));
4151 * If the vdev is already faulted, then don't do anything.
4153 if (vd
->vdev_faulted
|| vd
->vdev_degraded
)
4154 return (spa_vdev_state_exit(spa
, NULL
, 0));
4156 vd
->vdev_degraded
= 1ULL;
4157 if (!vdev_is_dead(vd
))
4158 vdev_set_state(vd
, B_FALSE
, VDEV_STATE_DEGRADED
,
4161 return (spa_vdev_state_exit(spa
, vd
, 0));
4165 vdev_remove_wanted(spa_t
*spa
, uint64_t guid
)
4169 spa_vdev_state_enter(spa
, SCL_NONE
);
4171 if ((vd
= spa_lookup_by_guid(spa
, guid
, B_TRUE
)) == NULL
)
4172 return (spa_vdev_state_exit(spa
, NULL
, SET_ERROR(ENODEV
)));
4175 * If the vdev is already removed, or expanding which can trigger
4176 * repartition add/remove events, then don't do anything.
4178 if (vd
->vdev_removed
|| vd
->vdev_expanding
)
4179 return (spa_vdev_state_exit(spa
, NULL
, 0));
4182 * Confirm the vdev has been removed, otherwise don't do anything.
4184 if (vd
->vdev_ops
->vdev_op_leaf
&& !zio_wait(vdev_probe(vd
, NULL
)))
4185 return (spa_vdev_state_exit(spa
, NULL
, SET_ERROR(EEXIST
)));
4187 vd
->vdev_remove_wanted
= B_TRUE
;
4188 spa_async_request(spa
, SPA_ASYNC_REMOVE
);
4190 return (spa_vdev_state_exit(spa
, vd
, 0));
4195 * Online the given vdev.
4197 * If 'ZFS_ONLINE_UNSPARE' is set, it implies two things. First, any attached
4198 * spare device should be detached when the device finishes resilvering.
4199 * Second, the online should be treated like a 'test' online case, so no FMA
4200 * events are generated if the device fails to open.
4203 vdev_online(spa_t
*spa
, uint64_t guid
, uint64_t flags
, vdev_state_t
*newstate
)
4205 vdev_t
*vd
, *tvd
, *pvd
, *rvd
= spa
->spa_root_vdev
;
4206 boolean_t wasoffline
;
4207 vdev_state_t oldstate
;
4209 spa_vdev_state_enter(spa
, SCL_NONE
);
4211 if ((vd
= spa_lookup_by_guid(spa
, guid
, B_TRUE
)) == NULL
)
4212 return (spa_vdev_state_exit(spa
, NULL
, SET_ERROR(ENODEV
)));
4214 wasoffline
= (vd
->vdev_offline
|| vd
->vdev_tmpoffline
);
4215 oldstate
= vd
->vdev_state
;
4218 vd
->vdev_offline
= B_FALSE
;
4219 vd
->vdev_tmpoffline
= B_FALSE
;
4220 vd
->vdev_checkremove
= !!(flags
& ZFS_ONLINE_CHECKREMOVE
);
4221 vd
->vdev_forcefault
= !!(flags
& ZFS_ONLINE_FORCEFAULT
);
4223 /* XXX - L2ARC 1.0 does not support expansion */
4224 if (!vd
->vdev_aux
) {
4225 for (pvd
= vd
; pvd
!= rvd
; pvd
= pvd
->vdev_parent
)
4226 pvd
->vdev_expanding
= !!((flags
& ZFS_ONLINE_EXPAND
) ||
4227 spa
->spa_autoexpand
);
4228 vd
->vdev_expansion_time
= gethrestime_sec();
4232 vd
->vdev_checkremove
= vd
->vdev_forcefault
= B_FALSE
;
4234 if (!vd
->vdev_aux
) {
4235 for (pvd
= vd
; pvd
!= rvd
; pvd
= pvd
->vdev_parent
)
4236 pvd
->vdev_expanding
= B_FALSE
;
4240 *newstate
= vd
->vdev_state
;
4241 if ((flags
& ZFS_ONLINE_UNSPARE
) &&
4242 !vdev_is_dead(vd
) && vd
->vdev_parent
&&
4243 vd
->vdev_parent
->vdev_ops
== &vdev_spare_ops
&&
4244 vd
->vdev_parent
->vdev_child
[0] == vd
)
4245 vd
->vdev_unspare
= B_TRUE
;
4247 if ((flags
& ZFS_ONLINE_EXPAND
) || spa
->spa_autoexpand
) {
4249 /* XXX - L2ARC 1.0 does not support expansion */
4251 return (spa_vdev_state_exit(spa
, vd
, ENOTSUP
));
4252 spa
->spa_ccw_fail_time
= 0;
4253 spa_async_request(spa
, SPA_ASYNC_CONFIG_UPDATE
);
4256 /* Restart initializing if necessary */
4257 mutex_enter(&vd
->vdev_initialize_lock
);
4258 if (vdev_writeable(vd
) &&
4259 vd
->vdev_initialize_thread
== NULL
&&
4260 vd
->vdev_initialize_state
== VDEV_INITIALIZE_ACTIVE
) {
4261 (void) vdev_initialize(vd
);
4263 mutex_exit(&vd
->vdev_initialize_lock
);
4266 * Restart trimming if necessary. We do not restart trimming for cache
4267 * devices here. This is triggered by l2arc_rebuild_vdev()
4268 * asynchronously for the whole device or in l2arc_evict() as it evicts
4269 * space for upcoming writes.
4271 mutex_enter(&vd
->vdev_trim_lock
);
4272 if (vdev_writeable(vd
) && !vd
->vdev_isl2cache
&&
4273 vd
->vdev_trim_thread
== NULL
&&
4274 vd
->vdev_trim_state
== VDEV_TRIM_ACTIVE
) {
4275 (void) vdev_trim(vd
, vd
->vdev_trim_rate
, vd
->vdev_trim_partial
,
4276 vd
->vdev_trim_secure
);
4278 mutex_exit(&vd
->vdev_trim_lock
);
4281 (oldstate
< VDEV_STATE_DEGRADED
&&
4282 vd
->vdev_state
>= VDEV_STATE_DEGRADED
)) {
4283 spa_event_notify(spa
, vd
, NULL
, ESC_ZFS_VDEV_ONLINE
);
4286 * Asynchronously detach spare vdev if resilver or
4287 * rebuild is not required
4289 if (vd
->vdev_unspare
&&
4290 !dsl_scan_resilvering(spa
->spa_dsl_pool
) &&
4291 !dsl_scan_resilver_scheduled(spa
->spa_dsl_pool
) &&
4292 !vdev_rebuild_active(tvd
))
4293 spa_async_request(spa
, SPA_ASYNC_DETACH_SPARE
);
4295 return (spa_vdev_state_exit(spa
, vd
, 0));
4299 vdev_offline_locked(spa_t
*spa
, uint64_t guid
, uint64_t flags
)
4303 uint64_t generation
;
4304 metaslab_group_t
*mg
;
4307 spa_vdev_state_enter(spa
, SCL_ALLOC
);
4309 if ((vd
= spa_lookup_by_guid(spa
, guid
, B_TRUE
)) == NULL
)
4310 return (spa_vdev_state_exit(spa
, NULL
, SET_ERROR(ENODEV
)));
4312 if (!vd
->vdev_ops
->vdev_op_leaf
)
4313 return (spa_vdev_state_exit(spa
, NULL
, SET_ERROR(ENOTSUP
)));
4315 if (vd
->vdev_ops
== &vdev_draid_spare_ops
)
4316 return (spa_vdev_state_exit(spa
, NULL
, ENOTSUP
));
4320 generation
= spa
->spa_config_generation
+ 1;
4323 * If the device isn't already offline, try to offline it.
4325 if (!vd
->vdev_offline
) {
4327 * If this device has the only valid copy of some data,
4328 * don't allow it to be offlined. Log devices are always
4331 if (!tvd
->vdev_islog
&& vd
->vdev_aux
== NULL
&&
4332 vdev_dtl_required(vd
))
4333 return (spa_vdev_state_exit(spa
, NULL
,
4337 * If the top-level is a slog and it has had allocations
4338 * then proceed. We check that the vdev's metaslab group
4339 * is not NULL since it's possible that we may have just
4340 * added this vdev but not yet initialized its metaslabs.
4342 if (tvd
->vdev_islog
&& mg
!= NULL
) {
4344 * Prevent any future allocations.
4346 ASSERT3P(tvd
->vdev_log_mg
, ==, NULL
);
4347 metaslab_group_passivate(mg
);
4348 (void) spa_vdev_state_exit(spa
, vd
, 0);
4350 error
= spa_reset_logs(spa
);
4353 * If the log device was successfully reset but has
4354 * checkpointed data, do not offline it.
4357 tvd
->vdev_checkpoint_sm
!= NULL
) {
4358 ASSERT3U(space_map_allocated(
4359 tvd
->vdev_checkpoint_sm
), !=, 0);
4360 error
= ZFS_ERR_CHECKPOINT_EXISTS
;
4363 spa_vdev_state_enter(spa
, SCL_ALLOC
);
4366 * Check to see if the config has changed.
4368 if (error
|| generation
!= spa
->spa_config_generation
) {
4369 metaslab_group_activate(mg
);
4371 return (spa_vdev_state_exit(spa
,
4373 (void) spa_vdev_state_exit(spa
, vd
, 0);
4376 ASSERT0(tvd
->vdev_stat
.vs_alloc
);
4380 * Offline this device and reopen its top-level vdev.
4381 * If the top-level vdev is a log device then just offline
4382 * it. Otherwise, if this action results in the top-level
4383 * vdev becoming unusable, undo it and fail the request.
4385 vd
->vdev_offline
= B_TRUE
;
4388 if (!tvd
->vdev_islog
&& vd
->vdev_aux
== NULL
&&
4389 vdev_is_dead(tvd
)) {
4390 vd
->vdev_offline
= B_FALSE
;
4392 return (spa_vdev_state_exit(spa
, NULL
,
4397 * Add the device back into the metaslab rotor so that
4398 * once we online the device it's open for business.
4400 if (tvd
->vdev_islog
&& mg
!= NULL
)
4401 metaslab_group_activate(mg
);
4404 vd
->vdev_tmpoffline
= !!(flags
& ZFS_OFFLINE_TEMPORARY
);
4406 return (spa_vdev_state_exit(spa
, vd
, 0));
4410 vdev_offline(spa_t
*spa
, uint64_t guid
, uint64_t flags
)
4414 mutex_enter(&spa
->spa_vdev_top_lock
);
4415 error
= vdev_offline_locked(spa
, guid
, flags
);
4416 mutex_exit(&spa
->spa_vdev_top_lock
);
4422 * Clear the error counts associated with this vdev. Unlike vdev_online() and
4423 * vdev_offline(), we assume the spa config is locked. We also clear all
4424 * children. If 'vd' is NULL, then the user wants to clear all vdevs.
4427 vdev_clear(spa_t
*spa
, vdev_t
*vd
)
4429 vdev_t
*rvd
= spa
->spa_root_vdev
;
4431 ASSERT(spa_config_held(spa
, SCL_STATE_ALL
, RW_WRITER
) == SCL_STATE_ALL
);
4436 vd
->vdev_stat
.vs_read_errors
= 0;
4437 vd
->vdev_stat
.vs_write_errors
= 0;
4438 vd
->vdev_stat
.vs_checksum_errors
= 0;
4439 vd
->vdev_stat
.vs_slow_ios
= 0;
4441 for (int c
= 0; c
< vd
->vdev_children
; c
++)
4442 vdev_clear(spa
, vd
->vdev_child
[c
]);
4445 * It makes no sense to "clear" an indirect or removed vdev.
4447 if (!vdev_is_concrete(vd
) || vd
->vdev_removed
)
4451 * If we're in the FAULTED state or have experienced failed I/O, then
4452 * clear the persistent state and attempt to reopen the device. We
4453 * also mark the vdev config dirty, so that the new faulted state is
4454 * written out to disk.
4456 if (vd
->vdev_faulted
|| vd
->vdev_degraded
||
4457 !vdev_readable(vd
) || !vdev_writeable(vd
)) {
4459 * When reopening in response to a clear event, it may be due to
4460 * a fmadm repair request. In this case, if the device is
4461 * still broken, we want to still post the ereport again.
4463 vd
->vdev_forcefault
= B_TRUE
;
4465 vd
->vdev_faulted
= vd
->vdev_degraded
= 0ULL;
4466 vd
->vdev_cant_read
= B_FALSE
;
4467 vd
->vdev_cant_write
= B_FALSE
;
4468 vd
->vdev_stat
.vs_aux
= 0;
4470 vdev_reopen(vd
== rvd
? rvd
: vd
->vdev_top
);
4472 vd
->vdev_forcefault
= B_FALSE
;
4474 if (vd
!= rvd
&& vdev_writeable(vd
->vdev_top
))
4475 vdev_state_dirty(vd
->vdev_top
);
4477 /* If a resilver isn't required, check if vdevs can be culled */
4478 if (vd
->vdev_aux
== NULL
&& !vdev_is_dead(vd
) &&
4479 !dsl_scan_resilvering(spa
->spa_dsl_pool
) &&
4480 !dsl_scan_resilver_scheduled(spa
->spa_dsl_pool
))
4481 spa_async_request(spa
, SPA_ASYNC_RESILVER_DONE
);
4483 spa_event_notify(spa
, vd
, NULL
, ESC_ZFS_VDEV_CLEAR
);
4487 * When clearing a FMA-diagnosed fault, we always want to
4488 * unspare the device, as we assume that the original spare was
4489 * done in response to the FMA fault.
4491 if (!vdev_is_dead(vd
) && vd
->vdev_parent
!= NULL
&&
4492 vd
->vdev_parent
->vdev_ops
== &vdev_spare_ops
&&
4493 vd
->vdev_parent
->vdev_child
[0] == vd
)
4494 vd
->vdev_unspare
= B_TRUE
;
4496 /* Clear recent error events cache (i.e. duplicate events tracking) */
4497 zfs_ereport_clear(spa
, vd
);
4501 vdev_is_dead(vdev_t
*vd
)
4504 * Holes and missing devices are always considered "dead".
4505 * This simplifies the code since we don't have to check for
4506 * these types of devices in the various code paths.
4507 * Instead we rely on the fact that we skip over dead devices
4508 * before issuing I/O to them.
4510 return (vd
->vdev_state
< VDEV_STATE_DEGRADED
||
4511 vd
->vdev_ops
== &vdev_hole_ops
||
4512 vd
->vdev_ops
== &vdev_missing_ops
);
4516 vdev_readable(vdev_t
*vd
)
4518 return (!vdev_is_dead(vd
) && !vd
->vdev_cant_read
);
4522 vdev_writeable(vdev_t
*vd
)
4524 return (!vdev_is_dead(vd
) && !vd
->vdev_cant_write
&&
4525 vdev_is_concrete(vd
));
4529 vdev_allocatable(vdev_t
*vd
)
4531 uint64_t state
= vd
->vdev_state
;
4534 * We currently allow allocations from vdevs which may be in the
4535 * process of reopening (i.e. VDEV_STATE_CLOSED). If the device
4536 * fails to reopen then we'll catch it later when we're holding
4537 * the proper locks. Note that we have to get the vdev state
4538 * in a local variable because although it changes atomically,
4539 * we're asking two separate questions about it.
4541 return (!(state
< VDEV_STATE_DEGRADED
&& state
!= VDEV_STATE_CLOSED
) &&
4542 !vd
->vdev_cant_write
&& vdev_is_concrete(vd
) &&
4543 vd
->vdev_mg
->mg_initialized
);
4547 vdev_accessible(vdev_t
*vd
, zio_t
*zio
)
4549 ASSERT(zio
->io_vd
== vd
);
4551 if (vdev_is_dead(vd
) || vd
->vdev_remove_wanted
)
4554 if (zio
->io_type
== ZIO_TYPE_READ
)
4555 return (!vd
->vdev_cant_read
);
4557 if (zio
->io_type
== ZIO_TYPE_WRITE
)
4558 return (!vd
->vdev_cant_write
);
4564 vdev_get_child_stat(vdev_t
*cvd
, vdev_stat_t
*vs
, vdev_stat_t
*cvs
)
4567 * Exclude the dRAID spare when aggregating to avoid double counting
4568 * the ops and bytes. These IOs are counted by the physical leaves.
4570 if (cvd
->vdev_ops
== &vdev_draid_spare_ops
)
4573 for (int t
= 0; t
< VS_ZIO_TYPES
; t
++) {
4574 vs
->vs_ops
[t
] += cvs
->vs_ops
[t
];
4575 vs
->vs_bytes
[t
] += cvs
->vs_bytes
[t
];
4578 cvs
->vs_scan_removing
= cvd
->vdev_removing
;
4582 * Get extended stats
4585 vdev_get_child_stat_ex(vdev_t
*cvd
, vdev_stat_ex_t
*vsx
, vdev_stat_ex_t
*cvsx
)
4590 for (t
= 0; t
< ZIO_TYPES
; t
++) {
4591 for (b
= 0; b
< ARRAY_SIZE(vsx
->vsx_disk_histo
[0]); b
++)
4592 vsx
->vsx_disk_histo
[t
][b
] += cvsx
->vsx_disk_histo
[t
][b
];
4594 for (b
= 0; b
< ARRAY_SIZE(vsx
->vsx_total_histo
[0]); b
++) {
4595 vsx
->vsx_total_histo
[t
][b
] +=
4596 cvsx
->vsx_total_histo
[t
][b
];
4600 for (t
= 0; t
< ZIO_PRIORITY_NUM_QUEUEABLE
; t
++) {
4601 for (b
= 0; b
< ARRAY_SIZE(vsx
->vsx_queue_histo
[0]); b
++) {
4602 vsx
->vsx_queue_histo
[t
][b
] +=
4603 cvsx
->vsx_queue_histo
[t
][b
];
4605 vsx
->vsx_active_queue
[t
] += cvsx
->vsx_active_queue
[t
];
4606 vsx
->vsx_pend_queue
[t
] += cvsx
->vsx_pend_queue
[t
];
4608 for (b
= 0; b
< ARRAY_SIZE(vsx
->vsx_ind_histo
[0]); b
++)
4609 vsx
->vsx_ind_histo
[t
][b
] += cvsx
->vsx_ind_histo
[t
][b
];
4611 for (b
= 0; b
< ARRAY_SIZE(vsx
->vsx_agg_histo
[0]); b
++)
4612 vsx
->vsx_agg_histo
[t
][b
] += cvsx
->vsx_agg_histo
[t
][b
];
4618 vdev_is_spacemap_addressable(vdev_t
*vd
)
4620 if (spa_feature_is_active(vd
->vdev_spa
, SPA_FEATURE_SPACEMAP_V2
))
4624 * If double-word space map entries are not enabled we assume
4625 * 47 bits of the space map entry are dedicated to the entry's
4626 * offset (see SM_OFFSET_BITS in space_map.h). We then use that
4627 * to calculate the maximum address that can be described by a
4628 * space map entry for the given device.
4630 uint64_t shift
= vd
->vdev_ashift
+ SM_OFFSET_BITS
;
4632 if (shift
>= 63) /* detect potential overflow */
4635 return (vd
->vdev_asize
< (1ULL << shift
));
4639 * Get statistics for the given vdev.
4642 vdev_get_stats_ex_impl(vdev_t
*vd
, vdev_stat_t
*vs
, vdev_stat_ex_t
*vsx
)
4646 * If we're getting stats on the root vdev, aggregate the I/O counts
4647 * over all top-level vdevs (i.e. the direct children of the root).
4649 if (!vd
->vdev_ops
->vdev_op_leaf
) {
4651 memset(vs
->vs_ops
, 0, sizeof (vs
->vs_ops
));
4652 memset(vs
->vs_bytes
, 0, sizeof (vs
->vs_bytes
));
4655 memset(vsx
, 0, sizeof (*vsx
));
4657 for (int c
= 0; c
< vd
->vdev_children
; c
++) {
4658 vdev_t
*cvd
= vd
->vdev_child
[c
];
4659 vdev_stat_t
*cvs
= &cvd
->vdev_stat
;
4660 vdev_stat_ex_t
*cvsx
= &cvd
->vdev_stat_ex
;
4662 vdev_get_stats_ex_impl(cvd
, cvs
, cvsx
);
4664 vdev_get_child_stat(cvd
, vs
, cvs
);
4666 vdev_get_child_stat_ex(cvd
, vsx
, cvsx
);
4670 * We're a leaf. Just copy our ZIO active queue stats in. The
4671 * other leaf stats are updated in vdev_stat_update().
4676 memcpy(vsx
, &vd
->vdev_stat_ex
, sizeof (vd
->vdev_stat_ex
));
4678 for (t
= 0; t
< ZIO_PRIORITY_NUM_QUEUEABLE
; t
++) {
4679 vsx
->vsx_active_queue
[t
] = vd
->vdev_queue
.vq_cactive
[t
];
4680 vsx
->vsx_pend_queue
[t
] = vdev_queue_class_length(vd
, t
);
4686 vdev_get_stats_ex(vdev_t
*vd
, vdev_stat_t
*vs
, vdev_stat_ex_t
*vsx
)
4688 vdev_t
*tvd
= vd
->vdev_top
;
4689 mutex_enter(&vd
->vdev_stat_lock
);
4691 memcpy(vs
, &vd
->vdev_stat
, sizeof (*vs
));
4692 vs
->vs_timestamp
= gethrtime() - vs
->vs_timestamp
;
4693 vs
->vs_state
= vd
->vdev_state
;
4694 vs
->vs_rsize
= vdev_get_min_asize(vd
);
4696 if (vd
->vdev_ops
->vdev_op_leaf
) {
4697 vs
->vs_pspace
= vd
->vdev_psize
;
4698 vs
->vs_rsize
+= VDEV_LABEL_START_SIZE
+
4699 VDEV_LABEL_END_SIZE
;
4701 * Report initializing progress. Since we don't
4702 * have the initializing locks held, this is only
4703 * an estimate (although a fairly accurate one).
4705 vs
->vs_initialize_bytes_done
=
4706 vd
->vdev_initialize_bytes_done
;
4707 vs
->vs_initialize_bytes_est
=
4708 vd
->vdev_initialize_bytes_est
;
4709 vs
->vs_initialize_state
= vd
->vdev_initialize_state
;
4710 vs
->vs_initialize_action_time
=
4711 vd
->vdev_initialize_action_time
;
4714 * Report manual TRIM progress. Since we don't have
4715 * the manual TRIM locks held, this is only an
4716 * estimate (although fairly accurate one).
4718 vs
->vs_trim_notsup
= !vd
->vdev_has_trim
;
4719 vs
->vs_trim_bytes_done
= vd
->vdev_trim_bytes_done
;
4720 vs
->vs_trim_bytes_est
= vd
->vdev_trim_bytes_est
;
4721 vs
->vs_trim_state
= vd
->vdev_trim_state
;
4722 vs
->vs_trim_action_time
= vd
->vdev_trim_action_time
;
4724 /* Set when there is a deferred resilver. */
4725 vs
->vs_resilver_deferred
= vd
->vdev_resilver_deferred
;
4729 * Report expandable space on top-level, non-auxiliary devices
4730 * only. The expandable space is reported in terms of metaslab
4731 * sized units since that determines how much space the pool
4734 if (vd
->vdev_aux
== NULL
&& tvd
!= NULL
) {
4735 vs
->vs_esize
= P2ALIGN(
4736 vd
->vdev_max_asize
- vd
->vdev_asize
,
4737 1ULL << tvd
->vdev_ms_shift
);
4740 vs
->vs_configured_ashift
= vd
->vdev_top
!= NULL
4741 ? vd
->vdev_top
->vdev_ashift
: vd
->vdev_ashift
;
4742 vs
->vs_logical_ashift
= vd
->vdev_logical_ashift
;
4743 if (vd
->vdev_physical_ashift
<= ASHIFT_MAX
)
4744 vs
->vs_physical_ashift
= vd
->vdev_physical_ashift
;
4746 vs
->vs_physical_ashift
= 0;
4749 * Report fragmentation and rebuild progress for top-level,
4750 * non-auxiliary, concrete devices.
4752 if (vd
->vdev_aux
== NULL
&& vd
== vd
->vdev_top
&&
4753 vdev_is_concrete(vd
)) {
4755 * The vdev fragmentation rating doesn't take into
4756 * account the embedded slog metaslab (vdev_log_mg).
4757 * Since it's only one metaslab, it would have a tiny
4758 * impact on the overall fragmentation.
4760 vs
->vs_fragmentation
= (vd
->vdev_mg
!= NULL
) ?
4761 vd
->vdev_mg
->mg_fragmentation
: 0;
4763 vs
->vs_noalloc
= MAX(vd
->vdev_noalloc
,
4764 tvd
? tvd
->vdev_noalloc
: 0);
4767 vdev_get_stats_ex_impl(vd
, vs
, vsx
);
4768 mutex_exit(&vd
->vdev_stat_lock
);
4772 vdev_get_stats(vdev_t
*vd
, vdev_stat_t
*vs
)
4774 return (vdev_get_stats_ex(vd
, vs
, NULL
));
4778 vdev_clear_stats(vdev_t
*vd
)
4780 mutex_enter(&vd
->vdev_stat_lock
);
4781 vd
->vdev_stat
.vs_space
= 0;
4782 vd
->vdev_stat
.vs_dspace
= 0;
4783 vd
->vdev_stat
.vs_alloc
= 0;
4784 mutex_exit(&vd
->vdev_stat_lock
);
4788 vdev_scan_stat_init(vdev_t
*vd
)
4790 vdev_stat_t
*vs
= &vd
->vdev_stat
;
4792 for (int c
= 0; c
< vd
->vdev_children
; c
++)
4793 vdev_scan_stat_init(vd
->vdev_child
[c
]);
4795 mutex_enter(&vd
->vdev_stat_lock
);
4796 vs
->vs_scan_processed
= 0;
4797 mutex_exit(&vd
->vdev_stat_lock
);
4801 vdev_stat_update(zio_t
*zio
, uint64_t psize
)
4803 spa_t
*spa
= zio
->io_spa
;
4804 vdev_t
*rvd
= spa
->spa_root_vdev
;
4805 vdev_t
*vd
= zio
->io_vd
? zio
->io_vd
: rvd
;
4807 uint64_t txg
= zio
->io_txg
;
4808 /* Suppress ASAN false positive */
4809 #ifdef __SANITIZE_ADDRESS__
4810 vdev_stat_t
*vs
= vd
? &vd
->vdev_stat
: NULL
;
4811 vdev_stat_ex_t
*vsx
= vd
? &vd
->vdev_stat_ex
: NULL
;
4813 vdev_stat_t
*vs
= &vd
->vdev_stat
;
4814 vdev_stat_ex_t
*vsx
= &vd
->vdev_stat_ex
;
4816 zio_type_t type
= zio
->io_type
;
4817 int flags
= zio
->io_flags
;
4820 * If this i/o is a gang leader, it didn't do any actual work.
4822 if (zio
->io_gang_tree
)
4825 if (zio
->io_error
== 0) {
4827 * If this is a root i/o, don't count it -- we've already
4828 * counted the top-level vdevs, and vdev_get_stats() will
4829 * aggregate them when asked. This reduces contention on
4830 * the root vdev_stat_lock and implicitly handles blocks
4831 * that compress away to holes, for which there is no i/o.
4832 * (Holes never create vdev children, so all the counters
4833 * remain zero, which is what we want.)
4835 * Note: this only applies to successful i/o (io_error == 0)
4836 * because unlike i/o counts, errors are not additive.
4837 * When reading a ditto block, for example, failure of
4838 * one top-level vdev does not imply a root-level error.
4843 ASSERT(vd
== zio
->io_vd
);
4845 if (flags
& ZIO_FLAG_IO_BYPASS
)
4848 mutex_enter(&vd
->vdev_stat_lock
);
4850 if (flags
& ZIO_FLAG_IO_REPAIR
) {
4852 * Repair is the result of a resilver issued by the
4853 * scan thread (spa_sync).
4855 if (flags
& ZIO_FLAG_SCAN_THREAD
) {
4856 dsl_scan_t
*scn
= spa
->spa_dsl_pool
->dp_scan
;
4857 dsl_scan_phys_t
*scn_phys
= &scn
->scn_phys
;
4858 uint64_t *processed
= &scn_phys
->scn_processed
;
4860 if (vd
->vdev_ops
->vdev_op_leaf
)
4861 atomic_add_64(processed
, psize
);
4862 vs
->vs_scan_processed
+= psize
;
4866 * Repair is the result of a rebuild issued by the
4867 * rebuild thread (vdev_rebuild_thread). To avoid
4868 * double counting repaired bytes the virtual dRAID
4869 * spare vdev is excluded from the processed bytes.
4871 if (zio
->io_priority
== ZIO_PRIORITY_REBUILD
) {
4872 vdev_t
*tvd
= vd
->vdev_top
;
4873 vdev_rebuild_t
*vr
= &tvd
->vdev_rebuild_config
;
4874 vdev_rebuild_phys_t
*vrp
= &vr
->vr_rebuild_phys
;
4875 uint64_t *rebuilt
= &vrp
->vrp_bytes_rebuilt
;
4877 if (vd
->vdev_ops
->vdev_op_leaf
&&
4878 vd
->vdev_ops
!= &vdev_draid_spare_ops
) {
4879 atomic_add_64(rebuilt
, psize
);
4881 vs
->vs_rebuild_processed
+= psize
;
4884 if (flags
& ZIO_FLAG_SELF_HEAL
)
4885 vs
->vs_self_healed
+= psize
;
4889 * The bytes/ops/histograms are recorded at the leaf level and
4890 * aggregated into the higher level vdevs in vdev_get_stats().
4892 if (vd
->vdev_ops
->vdev_op_leaf
&&
4893 (zio
->io_priority
< ZIO_PRIORITY_NUM_QUEUEABLE
)) {
4894 zio_type_t vs_type
= type
;
4895 zio_priority_t priority
= zio
->io_priority
;
4898 * TRIM ops and bytes are reported to user space as
4899 * ZIO_TYPE_IOCTL. This is done to preserve the
4900 * vdev_stat_t structure layout for user space.
4902 if (type
== ZIO_TYPE_TRIM
)
4903 vs_type
= ZIO_TYPE_IOCTL
;
4906 * Solely for the purposes of 'zpool iostat -lqrw'
4907 * reporting use the priority to categorize the IO.
4908 * Only the following are reported to user space:
4910 * ZIO_PRIORITY_SYNC_READ,
4911 * ZIO_PRIORITY_SYNC_WRITE,
4912 * ZIO_PRIORITY_ASYNC_READ,
4913 * ZIO_PRIORITY_ASYNC_WRITE,
4914 * ZIO_PRIORITY_SCRUB,
4915 * ZIO_PRIORITY_TRIM,
4916 * ZIO_PRIORITY_REBUILD.
4918 if (priority
== ZIO_PRIORITY_INITIALIZING
) {
4919 ASSERT3U(type
, ==, ZIO_TYPE_WRITE
);
4920 priority
= ZIO_PRIORITY_ASYNC_WRITE
;
4921 } else if (priority
== ZIO_PRIORITY_REMOVAL
) {
4922 priority
= ((type
== ZIO_TYPE_WRITE
) ?
4923 ZIO_PRIORITY_ASYNC_WRITE
:
4924 ZIO_PRIORITY_ASYNC_READ
);
4927 vs
->vs_ops
[vs_type
]++;
4928 vs
->vs_bytes
[vs_type
] += psize
;
4930 if (flags
& ZIO_FLAG_DELEGATED
) {
4931 vsx
->vsx_agg_histo
[priority
]
4932 [RQ_HISTO(zio
->io_size
)]++;
4934 vsx
->vsx_ind_histo
[priority
]
4935 [RQ_HISTO(zio
->io_size
)]++;
4938 if (zio
->io_delta
&& zio
->io_delay
) {
4939 vsx
->vsx_queue_histo
[priority
]
4940 [L_HISTO(zio
->io_delta
- zio
->io_delay
)]++;
4941 vsx
->vsx_disk_histo
[type
]
4942 [L_HISTO(zio
->io_delay
)]++;
4943 vsx
->vsx_total_histo
[type
]
4944 [L_HISTO(zio
->io_delta
)]++;
4948 mutex_exit(&vd
->vdev_stat_lock
);
4952 if (flags
& ZIO_FLAG_SPECULATIVE
)
4956 * If this is an I/O error that is going to be retried, then ignore the
4957 * error. Otherwise, the user may interpret B_FAILFAST I/O errors as
4958 * hard errors, when in reality they can happen for any number of
4959 * innocuous reasons (bus resets, MPxIO link failure, etc).
4961 if (zio
->io_error
== EIO
&&
4962 !(zio
->io_flags
& ZIO_FLAG_IO_RETRY
))
4966 * Intent logs writes won't propagate their error to the root
4967 * I/O so don't mark these types of failures as pool-level
4970 if (zio
->io_vd
== NULL
&& (zio
->io_flags
& ZIO_FLAG_DONT_PROPAGATE
))
4973 if (type
== ZIO_TYPE_WRITE
&& txg
!= 0 &&
4974 (!(flags
& ZIO_FLAG_IO_REPAIR
) ||
4975 (flags
& ZIO_FLAG_SCAN_THREAD
) ||
4976 spa
->spa_claiming
)) {
4978 * This is either a normal write (not a repair), or it's
4979 * a repair induced by the scrub thread, or it's a repair
4980 * made by zil_claim() during spa_load() in the first txg.
4981 * In the normal case, we commit the DTL change in the same
4982 * txg as the block was born. In the scrub-induced repair
4983 * case, we know that scrubs run in first-pass syncing context,
4984 * so we commit the DTL change in spa_syncing_txg(spa).
4985 * In the zil_claim() case, we commit in spa_first_txg(spa).
4987 * We currently do not make DTL entries for failed spontaneous
4988 * self-healing writes triggered by normal (non-scrubbing)
4989 * reads, because we have no transactional context in which to
4990 * do so -- and it's not clear that it'd be desirable anyway.
4992 if (vd
->vdev_ops
->vdev_op_leaf
) {
4993 uint64_t commit_txg
= txg
;
4994 if (flags
& ZIO_FLAG_SCAN_THREAD
) {
4995 ASSERT(flags
& ZIO_FLAG_IO_REPAIR
);
4996 ASSERT(spa_sync_pass(spa
) == 1);
4997 vdev_dtl_dirty(vd
, DTL_SCRUB
, txg
, 1);
4998 commit_txg
= spa_syncing_txg(spa
);
4999 } else if (spa
->spa_claiming
) {
5000 ASSERT(flags
& ZIO_FLAG_IO_REPAIR
);
5001 commit_txg
= spa_first_txg(spa
);
5003 ASSERT(commit_txg
>= spa_syncing_txg(spa
));
5004 if (vdev_dtl_contains(vd
, DTL_MISSING
, txg
, 1))
5006 for (pvd
= vd
; pvd
!= rvd
; pvd
= pvd
->vdev_parent
)
5007 vdev_dtl_dirty(pvd
, DTL_PARTIAL
, txg
, 1);
5008 vdev_dirty(vd
->vdev_top
, VDD_DTL
, vd
, commit_txg
);
5011 vdev_dtl_dirty(vd
, DTL_MISSING
, txg
, 1);
5016 vdev_deflated_space(vdev_t
*vd
, int64_t space
)
5018 ASSERT((space
& (SPA_MINBLOCKSIZE
-1)) == 0);
5019 ASSERT(vd
->vdev_deflate_ratio
!= 0 || vd
->vdev_isl2cache
);
5021 return ((space
>> SPA_MINBLOCKSHIFT
) * vd
->vdev_deflate_ratio
);
5025 * Update the in-core space usage stats for this vdev, its metaslab class,
5026 * and the root vdev.
5029 vdev_space_update(vdev_t
*vd
, int64_t alloc_delta
, int64_t defer_delta
,
5030 int64_t space_delta
)
5033 int64_t dspace_delta
;
5034 spa_t
*spa
= vd
->vdev_spa
;
5035 vdev_t
*rvd
= spa
->spa_root_vdev
;
5037 ASSERT(vd
== vd
->vdev_top
);
5040 * Apply the inverse of the psize-to-asize (ie. RAID-Z) space-expansion
5041 * factor. We must calculate this here and not at the root vdev
5042 * because the root vdev's psize-to-asize is simply the max of its
5043 * children's, thus not accurate enough for us.
5045 dspace_delta
= vdev_deflated_space(vd
, space_delta
);
5047 mutex_enter(&vd
->vdev_stat_lock
);
5048 /* ensure we won't underflow */
5049 if (alloc_delta
< 0) {
5050 ASSERT3U(vd
->vdev_stat
.vs_alloc
, >=, -alloc_delta
);
5053 vd
->vdev_stat
.vs_alloc
+= alloc_delta
;
5054 vd
->vdev_stat
.vs_space
+= space_delta
;
5055 vd
->vdev_stat
.vs_dspace
+= dspace_delta
;
5056 mutex_exit(&vd
->vdev_stat_lock
);
5058 /* every class but log contributes to root space stats */
5059 if (vd
->vdev_mg
!= NULL
&& !vd
->vdev_islog
) {
5060 ASSERT(!vd
->vdev_isl2cache
);
5061 mutex_enter(&rvd
->vdev_stat_lock
);
5062 rvd
->vdev_stat
.vs_alloc
+= alloc_delta
;
5063 rvd
->vdev_stat
.vs_space
+= space_delta
;
5064 rvd
->vdev_stat
.vs_dspace
+= dspace_delta
;
5065 mutex_exit(&rvd
->vdev_stat_lock
);
5067 /* Note: metaslab_class_space_update moved to metaslab_space_update */
5071 * Mark a top-level vdev's config as dirty, placing it on the dirty list
5072 * so that it will be written out next time the vdev configuration is synced.
5073 * If the root vdev is specified (vdev_top == NULL), dirty all top-level vdevs.
5076 vdev_config_dirty(vdev_t
*vd
)
5078 spa_t
*spa
= vd
->vdev_spa
;
5079 vdev_t
*rvd
= spa
->spa_root_vdev
;
5082 ASSERT(spa_writeable(spa
));
5085 * If this is an aux vdev (as with l2cache and spare devices), then we
5086 * update the vdev config manually and set the sync flag.
5088 if (vd
->vdev_aux
!= NULL
) {
5089 spa_aux_vdev_t
*sav
= vd
->vdev_aux
;
5093 for (c
= 0; c
< sav
->sav_count
; c
++) {
5094 if (sav
->sav_vdevs
[c
] == vd
)
5098 if (c
== sav
->sav_count
) {
5100 * We're being removed. There's nothing more to do.
5102 ASSERT(sav
->sav_sync
== B_TRUE
);
5106 sav
->sav_sync
= B_TRUE
;
5108 if (nvlist_lookup_nvlist_array(sav
->sav_config
,
5109 ZPOOL_CONFIG_L2CACHE
, &aux
, &naux
) != 0) {
5110 VERIFY(nvlist_lookup_nvlist_array(sav
->sav_config
,
5111 ZPOOL_CONFIG_SPARES
, &aux
, &naux
) == 0);
5117 * Setting the nvlist in the middle if the array is a little
5118 * sketchy, but it will work.
5120 nvlist_free(aux
[c
]);
5121 aux
[c
] = vdev_config_generate(spa
, vd
, B_TRUE
, 0);
5127 * The dirty list is protected by the SCL_CONFIG lock. The caller
5128 * must either hold SCL_CONFIG as writer, or must be the sync thread
5129 * (which holds SCL_CONFIG as reader). There's only one sync thread,
5130 * so this is sufficient to ensure mutual exclusion.
5132 ASSERT(spa_config_held(spa
, SCL_CONFIG
, RW_WRITER
) ||
5133 (dsl_pool_sync_context(spa_get_dsl(spa
)) &&
5134 spa_config_held(spa
, SCL_CONFIG
, RW_READER
)));
5137 for (c
= 0; c
< rvd
->vdev_children
; c
++)
5138 vdev_config_dirty(rvd
->vdev_child
[c
]);
5140 ASSERT(vd
== vd
->vdev_top
);
5142 if (!list_link_active(&vd
->vdev_config_dirty_node
) &&
5143 vdev_is_concrete(vd
)) {
5144 list_insert_head(&spa
->spa_config_dirty_list
, vd
);
5150 vdev_config_clean(vdev_t
*vd
)
5152 spa_t
*spa
= vd
->vdev_spa
;
5154 ASSERT(spa_config_held(spa
, SCL_CONFIG
, RW_WRITER
) ||
5155 (dsl_pool_sync_context(spa_get_dsl(spa
)) &&
5156 spa_config_held(spa
, SCL_CONFIG
, RW_READER
)));
5158 ASSERT(list_link_active(&vd
->vdev_config_dirty_node
));
5159 list_remove(&spa
->spa_config_dirty_list
, vd
);
5163 * Mark a top-level vdev's state as dirty, so that the next pass of
5164 * spa_sync() can convert this into vdev_config_dirty(). We distinguish
5165 * the state changes from larger config changes because they require
5166 * much less locking, and are often needed for administrative actions.
5169 vdev_state_dirty(vdev_t
*vd
)
5171 spa_t
*spa
= vd
->vdev_spa
;
5173 ASSERT(spa_writeable(spa
));
5174 ASSERT(vd
== vd
->vdev_top
);
5177 * The state list is protected by the SCL_STATE lock. The caller
5178 * must either hold SCL_STATE as writer, or must be the sync thread
5179 * (which holds SCL_STATE as reader). There's only one sync thread,
5180 * so this is sufficient to ensure mutual exclusion.
5182 ASSERT(spa_config_held(spa
, SCL_STATE
, RW_WRITER
) ||
5183 (dsl_pool_sync_context(spa_get_dsl(spa
)) &&
5184 spa_config_held(spa
, SCL_STATE
, RW_READER
)));
5186 if (!list_link_active(&vd
->vdev_state_dirty_node
) &&
5187 vdev_is_concrete(vd
))
5188 list_insert_head(&spa
->spa_state_dirty_list
, vd
);
5192 vdev_state_clean(vdev_t
*vd
)
5194 spa_t
*spa
= vd
->vdev_spa
;
5196 ASSERT(spa_config_held(spa
, SCL_STATE
, RW_WRITER
) ||
5197 (dsl_pool_sync_context(spa_get_dsl(spa
)) &&
5198 spa_config_held(spa
, SCL_STATE
, RW_READER
)));
5200 ASSERT(list_link_active(&vd
->vdev_state_dirty_node
));
5201 list_remove(&spa
->spa_state_dirty_list
, vd
);
5205 * Propagate vdev state up from children to parent.
5208 vdev_propagate_state(vdev_t
*vd
)
5210 spa_t
*spa
= vd
->vdev_spa
;
5211 vdev_t
*rvd
= spa
->spa_root_vdev
;
5212 int degraded
= 0, faulted
= 0;
5216 if (vd
->vdev_children
> 0) {
5217 for (int c
= 0; c
< vd
->vdev_children
; c
++) {
5218 child
= vd
->vdev_child
[c
];
5221 * Don't factor holes or indirect vdevs into the
5224 if (!vdev_is_concrete(child
))
5227 if (!vdev_readable(child
) ||
5228 (!vdev_writeable(child
) && spa_writeable(spa
))) {
5230 * Root special: if there is a top-level log
5231 * device, treat the root vdev as if it were
5234 if (child
->vdev_islog
&& vd
== rvd
)
5238 } else if (child
->vdev_state
<= VDEV_STATE_DEGRADED
) {
5242 if (child
->vdev_stat
.vs_aux
== VDEV_AUX_CORRUPT_DATA
)
5246 vd
->vdev_ops
->vdev_op_state_change(vd
, faulted
, degraded
);
5249 * Root special: if there is a top-level vdev that cannot be
5250 * opened due to corrupted metadata, then propagate the root
5251 * vdev's aux state as 'corrupt' rather than 'insufficient
5254 if (corrupted
&& vd
== rvd
&&
5255 rvd
->vdev_state
== VDEV_STATE_CANT_OPEN
)
5256 vdev_set_state(rvd
, B_FALSE
, VDEV_STATE_CANT_OPEN
,
5257 VDEV_AUX_CORRUPT_DATA
);
5260 if (vd
->vdev_parent
)
5261 vdev_propagate_state(vd
->vdev_parent
);
5265 * Set a vdev's state. If this is during an open, we don't update the parent
5266 * state, because we're in the process of opening children depth-first.
5267 * Otherwise, we propagate the change to the parent.
5269 * If this routine places a device in a faulted state, an appropriate ereport is
5273 vdev_set_state(vdev_t
*vd
, boolean_t isopen
, vdev_state_t state
, vdev_aux_t aux
)
5275 uint64_t save_state
;
5276 spa_t
*spa
= vd
->vdev_spa
;
5278 if (state
== vd
->vdev_state
) {
5280 * Since vdev_offline() code path is already in an offline
5281 * state we can miss a statechange event to OFFLINE. Check
5282 * the previous state to catch this condition.
5284 if (vd
->vdev_ops
->vdev_op_leaf
&&
5285 (state
== VDEV_STATE_OFFLINE
) &&
5286 (vd
->vdev_prevstate
>= VDEV_STATE_FAULTED
)) {
5287 /* post an offline state change */
5288 zfs_post_state_change(spa
, vd
, vd
->vdev_prevstate
);
5290 vd
->vdev_stat
.vs_aux
= aux
;
5294 save_state
= vd
->vdev_state
;
5296 vd
->vdev_state
= state
;
5297 vd
->vdev_stat
.vs_aux
= aux
;
5300 * If we are setting the vdev state to anything but an open state, then
5301 * always close the underlying device unless the device has requested
5302 * a delayed close (i.e. we're about to remove or fault the device).
5303 * Otherwise, we keep accessible but invalid devices open forever.
5304 * We don't call vdev_close() itself, because that implies some extra
5305 * checks (offline, etc) that we don't want here. This is limited to
5306 * leaf devices, because otherwise closing the device will affect other
5309 if (!vd
->vdev_delayed_close
&& vdev_is_dead(vd
) &&
5310 vd
->vdev_ops
->vdev_op_leaf
)
5311 vd
->vdev_ops
->vdev_op_close(vd
);
5313 if (vd
->vdev_removed
&&
5314 state
== VDEV_STATE_CANT_OPEN
&&
5315 (aux
== VDEV_AUX_OPEN_FAILED
|| vd
->vdev_checkremove
)) {
5317 * If the previous state is set to VDEV_STATE_REMOVED, then this
5318 * device was previously marked removed and someone attempted to
5319 * reopen it. If this failed due to a nonexistent device, then
5320 * keep the device in the REMOVED state. We also let this be if
5321 * it is one of our special test online cases, which is only
5322 * attempting to online the device and shouldn't generate an FMA
5325 vd
->vdev_state
= VDEV_STATE_REMOVED
;
5326 vd
->vdev_stat
.vs_aux
= VDEV_AUX_NONE
;
5327 } else if (state
== VDEV_STATE_REMOVED
) {
5328 vd
->vdev_removed
= B_TRUE
;
5329 } else if (state
== VDEV_STATE_CANT_OPEN
) {
5331 * If we fail to open a vdev during an import or recovery, we
5332 * mark it as "not available", which signifies that it was
5333 * never there to begin with. Failure to open such a device
5334 * is not considered an error.
5336 if ((spa_load_state(spa
) == SPA_LOAD_IMPORT
||
5337 spa_load_state(spa
) == SPA_LOAD_RECOVER
) &&
5338 vd
->vdev_ops
->vdev_op_leaf
)
5339 vd
->vdev_not_present
= 1;
5342 * Post the appropriate ereport. If the 'prevstate' field is
5343 * set to something other than VDEV_STATE_UNKNOWN, it indicates
5344 * that this is part of a vdev_reopen(). In this case, we don't
5345 * want to post the ereport if the device was already in the
5346 * CANT_OPEN state beforehand.
5348 * If the 'checkremove' flag is set, then this is an attempt to
5349 * online the device in response to an insertion event. If we
5350 * hit this case, then we have detected an insertion event for a
5351 * faulted or offline device that wasn't in the removed state.
5352 * In this scenario, we don't post an ereport because we are
5353 * about to replace the device, or attempt an online with
5354 * vdev_forcefault, which will generate the fault for us.
5356 if ((vd
->vdev_prevstate
!= state
|| vd
->vdev_forcefault
) &&
5357 !vd
->vdev_not_present
&& !vd
->vdev_checkremove
&&
5358 vd
!= spa
->spa_root_vdev
) {
5362 case VDEV_AUX_OPEN_FAILED
:
5363 class = FM_EREPORT_ZFS_DEVICE_OPEN_FAILED
;
5365 case VDEV_AUX_CORRUPT_DATA
:
5366 class = FM_EREPORT_ZFS_DEVICE_CORRUPT_DATA
;
5368 case VDEV_AUX_NO_REPLICAS
:
5369 class = FM_EREPORT_ZFS_DEVICE_NO_REPLICAS
;
5371 case VDEV_AUX_BAD_GUID_SUM
:
5372 class = FM_EREPORT_ZFS_DEVICE_BAD_GUID_SUM
;
5374 case VDEV_AUX_TOO_SMALL
:
5375 class = FM_EREPORT_ZFS_DEVICE_TOO_SMALL
;
5377 case VDEV_AUX_BAD_LABEL
:
5378 class = FM_EREPORT_ZFS_DEVICE_BAD_LABEL
;
5380 case VDEV_AUX_BAD_ASHIFT
:
5381 class = FM_EREPORT_ZFS_DEVICE_BAD_ASHIFT
;
5384 class = FM_EREPORT_ZFS_DEVICE_UNKNOWN
;
5387 (void) zfs_ereport_post(class, spa
, vd
, NULL
, NULL
,
5391 /* Erase any notion of persistent removed state */
5392 vd
->vdev_removed
= B_FALSE
;
5394 vd
->vdev_removed
= B_FALSE
;
5398 * Notify ZED of any significant state-change on a leaf vdev.
5401 if (vd
->vdev_ops
->vdev_op_leaf
) {
5402 /* preserve original state from a vdev_reopen() */
5403 if ((vd
->vdev_prevstate
!= VDEV_STATE_UNKNOWN
) &&
5404 (vd
->vdev_prevstate
!= vd
->vdev_state
) &&
5405 (save_state
<= VDEV_STATE_CLOSED
))
5406 save_state
= vd
->vdev_prevstate
;
5408 /* filter out state change due to initial vdev_open */
5409 if (save_state
> VDEV_STATE_CLOSED
)
5410 zfs_post_state_change(spa
, vd
, save_state
);
5413 if (!isopen
&& vd
->vdev_parent
)
5414 vdev_propagate_state(vd
->vdev_parent
);
5418 vdev_children_are_offline(vdev_t
*vd
)
5420 ASSERT(!vd
->vdev_ops
->vdev_op_leaf
);
5422 for (uint64_t i
= 0; i
< vd
->vdev_children
; i
++) {
5423 if (vd
->vdev_child
[i
]->vdev_state
!= VDEV_STATE_OFFLINE
)
5431 * Check the vdev configuration to ensure that it's capable of supporting
5432 * a root pool. We do not support partial configuration.
5435 vdev_is_bootable(vdev_t
*vd
)
5437 if (!vd
->vdev_ops
->vdev_op_leaf
) {
5438 const char *vdev_type
= vd
->vdev_ops
->vdev_op_type
;
5440 if (strcmp(vdev_type
, VDEV_TYPE_MISSING
) == 0)
5444 for (int c
= 0; c
< vd
->vdev_children
; c
++) {
5445 if (!vdev_is_bootable(vd
->vdev_child
[c
]))
5452 vdev_is_concrete(vdev_t
*vd
)
5454 vdev_ops_t
*ops
= vd
->vdev_ops
;
5455 if (ops
== &vdev_indirect_ops
|| ops
== &vdev_hole_ops
||
5456 ops
== &vdev_missing_ops
|| ops
== &vdev_root_ops
) {
5464 * Determine if a log device has valid content. If the vdev was
5465 * removed or faulted in the MOS config then we know that
5466 * the content on the log device has already been written to the pool.
5469 vdev_log_state_valid(vdev_t
*vd
)
5471 if (vd
->vdev_ops
->vdev_op_leaf
&& !vd
->vdev_faulted
&&
5475 for (int c
= 0; c
< vd
->vdev_children
; c
++)
5476 if (vdev_log_state_valid(vd
->vdev_child
[c
]))
5483 * Expand a vdev if possible.
5486 vdev_expand(vdev_t
*vd
, uint64_t txg
)
5488 ASSERT(vd
->vdev_top
== vd
);
5489 ASSERT(spa_config_held(vd
->vdev_spa
, SCL_ALL
, RW_WRITER
) == SCL_ALL
);
5490 ASSERT(vdev_is_concrete(vd
));
5492 vdev_set_deflate_ratio(vd
);
5494 if ((vd
->vdev_spa
->spa_raidz_expand
== NULL
||
5495 vd
->vdev_spa
->spa_raidz_expand
->vre_vdev_id
!= vd
->vdev_id
) &&
5496 (vd
->vdev_asize
>> vd
->vdev_ms_shift
) > vd
->vdev_ms_count
&&
5497 vdev_is_concrete(vd
)) {
5498 vdev_metaslab_group_create(vd
);
5499 VERIFY(vdev_metaslab_init(vd
, txg
) == 0);
5500 vdev_config_dirty(vd
);
5508 vdev_split(vdev_t
*vd
)
5510 vdev_t
*cvd
, *pvd
= vd
->vdev_parent
;
5512 VERIFY3U(pvd
->vdev_children
, >, 1);
5514 vdev_remove_child(pvd
, vd
);
5515 vdev_compact_children(pvd
);
5517 ASSERT3P(pvd
->vdev_child
, !=, NULL
);
5519 cvd
= pvd
->vdev_child
[0];
5520 if (pvd
->vdev_children
== 1) {
5521 vdev_remove_parent(cvd
);
5522 cvd
->vdev_splitting
= B_TRUE
;
5524 vdev_propagate_state(cvd
);
5528 vdev_deadman(vdev_t
*vd
, const char *tag
)
5530 for (int c
= 0; c
< vd
->vdev_children
; c
++) {
5531 vdev_t
*cvd
= vd
->vdev_child
[c
];
5533 vdev_deadman(cvd
, tag
);
5536 if (vd
->vdev_ops
->vdev_op_leaf
) {
5537 vdev_queue_t
*vq
= &vd
->vdev_queue
;
5539 mutex_enter(&vq
->vq_lock
);
5540 if (vq
->vq_active
> 0) {
5541 spa_t
*spa
= vd
->vdev_spa
;
5545 zfs_dbgmsg("slow vdev: %s has %u active IOs",
5546 vd
->vdev_path
, vq
->vq_active
);
5549 * Look at the head of all the pending queues,
5550 * if any I/O has been outstanding for longer than
5551 * the spa_deadman_synctime invoke the deadman logic.
5553 fio
= list_head(&vq
->vq_active_list
);
5554 delta
= gethrtime() - fio
->io_timestamp
;
5555 if (delta
> spa_deadman_synctime(spa
))
5556 zio_deadman(fio
, tag
);
5558 mutex_exit(&vq
->vq_lock
);
5563 vdev_defer_resilver(vdev_t
*vd
)
5565 ASSERT(vd
->vdev_ops
->vdev_op_leaf
);
5567 vd
->vdev_resilver_deferred
= B_TRUE
;
5568 vd
->vdev_spa
->spa_resilver_deferred
= B_TRUE
;
5572 * Clears the resilver deferred flag on all leaf devs under vd. Returns
5573 * B_TRUE if we have devices that need to be resilvered and are available to
5574 * accept resilver I/Os.
5577 vdev_clear_resilver_deferred(vdev_t
*vd
, dmu_tx_t
*tx
)
5579 boolean_t resilver_needed
= B_FALSE
;
5580 spa_t
*spa
= vd
->vdev_spa
;
5582 for (int c
= 0; c
< vd
->vdev_children
; c
++) {
5583 vdev_t
*cvd
= vd
->vdev_child
[c
];
5584 resilver_needed
|= vdev_clear_resilver_deferred(cvd
, tx
);
5587 if (vd
== spa
->spa_root_vdev
&&
5588 spa_feature_is_active(spa
, SPA_FEATURE_RESILVER_DEFER
)) {
5589 spa_feature_decr(spa
, SPA_FEATURE_RESILVER_DEFER
, tx
);
5590 vdev_config_dirty(vd
);
5591 spa
->spa_resilver_deferred
= B_FALSE
;
5592 return (resilver_needed
);
5595 if (!vdev_is_concrete(vd
) || vd
->vdev_aux
||
5596 !vd
->vdev_ops
->vdev_op_leaf
)
5597 return (resilver_needed
);
5599 vd
->vdev_resilver_deferred
= B_FALSE
;
5601 return (!vdev_is_dead(vd
) && !vd
->vdev_offline
&&
5602 vdev_resilver_needed(vd
, NULL
, NULL
));
5606 vdev_xlate_is_empty(range_seg64_t
*rs
)
5608 return (rs
->rs_start
== rs
->rs_end
);
5612 * Translate a logical range to the first contiguous physical range for the
5613 * specified vdev_t. This function is initially called with a leaf vdev and
5614 * will walk each parent vdev until it reaches a top-level vdev. Once the
5615 * top-level is reached the physical range is initialized and the recursive
5616 * function begins to unwind. As it unwinds it calls the parent's vdev
5617 * specific translation function to do the real conversion.
5620 vdev_xlate(vdev_t
*vd
, const range_seg64_t
*logical_rs
,
5621 range_seg64_t
*physical_rs
, range_seg64_t
*remain_rs
)
5624 * Walk up the vdev tree
5626 if (vd
!= vd
->vdev_top
) {
5627 vdev_xlate(vd
->vdev_parent
, logical_rs
, physical_rs
,
5631 * We've reached the top-level vdev, initialize the physical
5632 * range to the logical range and set an empty remaining
5633 * range then start to unwind.
5635 physical_rs
->rs_start
= logical_rs
->rs_start
;
5636 physical_rs
->rs_end
= logical_rs
->rs_end
;
5638 remain_rs
->rs_start
= logical_rs
->rs_start
;
5639 remain_rs
->rs_end
= logical_rs
->rs_start
;
5644 vdev_t
*pvd
= vd
->vdev_parent
;
5645 ASSERT3P(pvd
, !=, NULL
);
5646 ASSERT3P(pvd
->vdev_ops
->vdev_op_xlate
, !=, NULL
);
5649 * As this recursive function unwinds, translate the logical
5650 * range into its physical and any remaining components by calling
5651 * the vdev specific translate function.
5653 range_seg64_t intermediate
= { 0 };
5654 pvd
->vdev_ops
->vdev_op_xlate(vd
, physical_rs
, &intermediate
, remain_rs
);
5656 physical_rs
->rs_start
= intermediate
.rs_start
;
5657 physical_rs
->rs_end
= intermediate
.rs_end
;
5661 vdev_xlate_walk(vdev_t
*vd
, const range_seg64_t
*logical_rs
,
5662 vdev_xlate_func_t
*func
, void *arg
)
5664 range_seg64_t iter_rs
= *logical_rs
;
5665 range_seg64_t physical_rs
;
5666 range_seg64_t remain_rs
;
5668 while (!vdev_xlate_is_empty(&iter_rs
)) {
5670 vdev_xlate(vd
, &iter_rs
, &physical_rs
, &remain_rs
);
5673 * With raidz and dRAID, it's possible that the logical range
5674 * does not live on this leaf vdev. Only when there is a non-
5675 * zero physical size call the provided function.
5677 if (!vdev_xlate_is_empty(&physical_rs
))
5678 func(arg
, &physical_rs
);
5680 iter_rs
= remain_rs
;
5685 vdev_name(vdev_t
*vd
, char *buf
, int buflen
)
5687 if (vd
->vdev_path
== NULL
) {
5688 if (strcmp(vd
->vdev_ops
->vdev_op_type
, "root") == 0) {
5689 strlcpy(buf
, vd
->vdev_spa
->spa_name
, buflen
);
5690 } else if (!vd
->vdev_ops
->vdev_op_leaf
) {
5691 snprintf(buf
, buflen
, "%s-%llu",
5692 vd
->vdev_ops
->vdev_op_type
,
5693 (u_longlong_t
)vd
->vdev_id
);
5696 strlcpy(buf
, vd
->vdev_path
, buflen
);
5702 * Look at the vdev tree and determine whether any devices are currently being
5706 vdev_replace_in_progress(vdev_t
*vdev
)
5708 ASSERT(spa_config_held(vdev
->vdev_spa
, SCL_ALL
, RW_READER
) != 0);
5710 if (vdev
->vdev_ops
== &vdev_replacing_ops
)
5714 * A 'spare' vdev indicates that we have a replace in progress, unless
5715 * it has exactly two children, and the second, the hot spare, has
5716 * finished being resilvered.
5718 if (vdev
->vdev_ops
== &vdev_spare_ops
&& (vdev
->vdev_children
> 2 ||
5719 !vdev_dtl_empty(vdev
->vdev_child
[1], DTL_MISSING
)))
5722 for (int i
= 0; i
< vdev
->vdev_children
; i
++) {
5723 if (vdev_replace_in_progress(vdev
->vdev_child
[i
]))
5731 * Add a (source=src, propname=propval) list to an nvlist.
5734 vdev_prop_add_list(nvlist_t
*nvl
, const char *propname
, const char *strval
,
5735 uint64_t intval
, zprop_source_t src
)
5739 propval
= fnvlist_alloc();
5740 fnvlist_add_uint64(propval
, ZPROP_SOURCE
, src
);
5743 fnvlist_add_string(propval
, ZPROP_VALUE
, strval
);
5745 fnvlist_add_uint64(propval
, ZPROP_VALUE
, intval
);
5747 fnvlist_add_nvlist(nvl
, propname
, propval
);
5748 nvlist_free(propval
);
5752 vdev_props_set_sync(void *arg
, dmu_tx_t
*tx
)
5755 nvlist_t
*nvp
= arg
;
5756 spa_t
*spa
= dmu_tx_pool(tx
)->dp_spa
;
5757 objset_t
*mos
= spa
->spa_meta_objset
;
5758 nvpair_t
*elem
= NULL
;
5763 vdev_guid
= fnvlist_lookup_uint64(nvp
, ZPOOL_VDEV_PROPS_SET_VDEV
);
5764 nvprops
= fnvlist_lookup_nvlist(nvp
, ZPOOL_VDEV_PROPS_SET_PROPS
);
5765 vd
= spa_lookup_by_guid(spa
, vdev_guid
, B_TRUE
);
5767 /* this vdev could get removed while waiting for this sync task */
5772 * Set vdev property values in the vdev props mos object.
5774 if (vd
->vdev_root_zap
!= 0) {
5775 objid
= vd
->vdev_root_zap
;
5776 } else if (vd
->vdev_top_zap
!= 0) {
5777 objid
= vd
->vdev_top_zap
;
5778 } else if (vd
->vdev_leaf_zap
!= 0) {
5779 objid
= vd
->vdev_leaf_zap
;
5781 panic("unexpected vdev type");
5784 mutex_enter(&spa
->spa_props_lock
);
5786 while ((elem
= nvlist_next_nvpair(nvprops
, elem
)) != NULL
) {
5790 const char *propname
= nvpair_name(elem
);
5791 zprop_type_t proptype
;
5793 switch (prop
= vdev_name_to_prop(propname
)) {
5794 case VDEV_PROP_USERPROP
:
5795 if (vdev_prop_user(propname
)) {
5796 strval
= fnvpair_value_string(elem
);
5797 if (strlen(strval
) == 0) {
5798 /* remove the property if value == "" */
5799 (void) zap_remove(mos
, objid
, propname
,
5802 VERIFY0(zap_update(mos
, objid
, propname
,
5803 1, strlen(strval
) + 1, strval
, tx
));
5805 spa_history_log_internal(spa
, "vdev set", tx
,
5806 "vdev_guid=%llu: %s=%s",
5807 (u_longlong_t
)vdev_guid
, nvpair_name(elem
),
5812 /* normalize the property name */
5813 propname
= vdev_prop_to_name(prop
);
5814 proptype
= vdev_prop_get_type(prop
);
5816 if (nvpair_type(elem
) == DATA_TYPE_STRING
) {
5817 ASSERT(proptype
== PROP_TYPE_STRING
);
5818 strval
= fnvpair_value_string(elem
);
5819 VERIFY0(zap_update(mos
, objid
, propname
,
5820 1, strlen(strval
) + 1, strval
, tx
));
5821 spa_history_log_internal(spa
, "vdev set", tx
,
5822 "vdev_guid=%llu: %s=%s",
5823 (u_longlong_t
)vdev_guid
, nvpair_name(elem
),
5825 } else if (nvpair_type(elem
) == DATA_TYPE_UINT64
) {
5826 intval
= fnvpair_value_uint64(elem
);
5828 if (proptype
== PROP_TYPE_INDEX
) {
5830 VERIFY0(vdev_prop_index_to_string(
5831 prop
, intval
, &unused
));
5833 VERIFY0(zap_update(mos
, objid
, propname
,
5834 sizeof (uint64_t), 1, &intval
, tx
));
5835 spa_history_log_internal(spa
, "vdev set", tx
,
5836 "vdev_guid=%llu: %s=%lld",
5837 (u_longlong_t
)vdev_guid
,
5838 nvpair_name(elem
), (longlong_t
)intval
);
5840 panic("invalid vdev property type %u",
5847 mutex_exit(&spa
->spa_props_lock
);
5851 vdev_prop_set(vdev_t
*vd
, nvlist_t
*innvl
, nvlist_t
*outnvl
)
5853 spa_t
*spa
= vd
->vdev_spa
;
5854 nvpair_t
*elem
= NULL
;
5861 /* Check that vdev has a zap we can use */
5862 if (vd
->vdev_root_zap
== 0 &&
5863 vd
->vdev_top_zap
== 0 &&
5864 vd
->vdev_leaf_zap
== 0)
5865 return (SET_ERROR(EINVAL
));
5867 if (nvlist_lookup_uint64(innvl
, ZPOOL_VDEV_PROPS_SET_VDEV
,
5869 return (SET_ERROR(EINVAL
));
5871 if (nvlist_lookup_nvlist(innvl
, ZPOOL_VDEV_PROPS_SET_PROPS
,
5873 return (SET_ERROR(EINVAL
));
5875 if ((vd
= spa_lookup_by_guid(spa
, vdev_guid
, B_TRUE
)) == NULL
)
5876 return (SET_ERROR(EINVAL
));
5878 while ((elem
= nvlist_next_nvpair(nvprops
, elem
)) != NULL
) {
5879 const char *propname
= nvpair_name(elem
);
5880 vdev_prop_t prop
= vdev_name_to_prop(propname
);
5881 uint64_t intval
= 0;
5882 const char *strval
= NULL
;
5884 if (prop
== VDEV_PROP_USERPROP
&& !vdev_prop_user(propname
)) {
5889 if (vdev_prop_readonly(prop
)) {
5894 /* Special Processing */
5896 case VDEV_PROP_PATH
:
5897 if (vd
->vdev_path
== NULL
) {
5901 if (nvpair_value_string(elem
, &strval
) != 0) {
5905 /* New path must start with /dev/ */
5906 if (strncmp(strval
, "/dev/", 5)) {
5910 error
= spa_vdev_setpath(spa
, vdev_guid
, strval
);
5912 case VDEV_PROP_ALLOCATING
:
5913 if (nvpair_value_uint64(elem
, &intval
) != 0) {
5917 if (intval
!= vd
->vdev_noalloc
)
5920 error
= spa_vdev_noalloc(spa
, vdev_guid
);
5922 error
= spa_vdev_alloc(spa
, vdev_guid
);
5924 case VDEV_PROP_FAILFAST
:
5925 if (nvpair_value_uint64(elem
, &intval
) != 0) {
5929 vd
->vdev_failfast
= intval
& 1;
5931 case VDEV_PROP_CHECKSUM_N
:
5932 if (nvpair_value_uint64(elem
, &intval
) != 0) {
5936 vd
->vdev_checksum_n
= intval
;
5938 case VDEV_PROP_CHECKSUM_T
:
5939 if (nvpair_value_uint64(elem
, &intval
) != 0) {
5943 vd
->vdev_checksum_t
= intval
;
5945 case VDEV_PROP_IO_N
:
5946 if (nvpair_value_uint64(elem
, &intval
) != 0) {
5950 vd
->vdev_io_n
= intval
;
5952 case VDEV_PROP_IO_T
:
5953 if (nvpair_value_uint64(elem
, &intval
) != 0) {
5957 vd
->vdev_io_t
= intval
;
5960 /* Most processing is done in vdev_props_set_sync */
5966 vdev_prop_add_list(outnvl
, propname
, strval
, intval
, 0);
5971 return (dsl_sync_task(spa
->spa_name
, NULL
, vdev_props_set_sync
,
5972 innvl
, 6, ZFS_SPACE_CHECK_EXTRA_RESERVED
));
5976 vdev_prop_get(vdev_t
*vd
, nvlist_t
*innvl
, nvlist_t
*outnvl
)
5978 spa_t
*spa
= vd
->vdev_spa
;
5979 objset_t
*mos
= spa
->spa_meta_objset
;
5983 nvpair_t
*elem
= NULL
;
5984 nvlist_t
*nvprops
= NULL
;
5985 uint64_t intval
= 0;
5986 char *strval
= NULL
;
5987 const char *propname
= NULL
;
5991 ASSERT(mos
!= NULL
);
5993 if (nvlist_lookup_uint64(innvl
, ZPOOL_VDEV_PROPS_GET_VDEV
,
5995 return (SET_ERROR(EINVAL
));
5997 nvlist_lookup_nvlist(innvl
, ZPOOL_VDEV_PROPS_GET_PROPS
, &nvprops
);
5999 if (vd
->vdev_root_zap
!= 0) {
6000 objid
= vd
->vdev_root_zap
;
6001 } else if (vd
->vdev_top_zap
!= 0) {
6002 objid
= vd
->vdev_top_zap
;
6003 } else if (vd
->vdev_leaf_zap
!= 0) {
6004 objid
= vd
->vdev_leaf_zap
;
6006 return (SET_ERROR(EINVAL
));
6010 mutex_enter(&spa
->spa_props_lock
);
6012 if (nvprops
!= NULL
) {
6013 char namebuf
[64] = { 0 };
6015 while ((elem
= nvlist_next_nvpair(nvprops
, elem
)) != NULL
) {
6018 propname
= nvpair_name(elem
);
6019 prop
= vdev_name_to_prop(propname
);
6020 zprop_source_t src
= ZPROP_SRC_DEFAULT
;
6021 uint64_t integer_size
, num_integers
;
6024 /* Special Read-only Properties */
6025 case VDEV_PROP_NAME
:
6026 strval
= vdev_name(vd
, namebuf
,
6030 vdev_prop_add_list(outnvl
, propname
, strval
, 0,
6033 case VDEV_PROP_CAPACITY
:
6035 intval
= (vd
->vdev_stat
.vs_dspace
== 0) ? 0 :
6036 (vd
->vdev_stat
.vs_alloc
* 100 /
6037 vd
->vdev_stat
.vs_dspace
);
6038 vdev_prop_add_list(outnvl
, propname
, NULL
,
6039 intval
, ZPROP_SRC_NONE
);
6041 case VDEV_PROP_STATE
:
6042 vdev_prop_add_list(outnvl
, propname
, NULL
,
6043 vd
->vdev_state
, ZPROP_SRC_NONE
);
6045 case VDEV_PROP_GUID
:
6046 vdev_prop_add_list(outnvl
, propname
, NULL
,
6047 vd
->vdev_guid
, ZPROP_SRC_NONE
);
6049 case VDEV_PROP_ASIZE
:
6050 vdev_prop_add_list(outnvl
, propname
, NULL
,
6051 vd
->vdev_asize
, ZPROP_SRC_NONE
);
6053 case VDEV_PROP_PSIZE
:
6054 vdev_prop_add_list(outnvl
, propname
, NULL
,
6055 vd
->vdev_psize
, ZPROP_SRC_NONE
);
6057 case VDEV_PROP_ASHIFT
:
6058 vdev_prop_add_list(outnvl
, propname
, NULL
,
6059 vd
->vdev_ashift
, ZPROP_SRC_NONE
);
6061 case VDEV_PROP_SIZE
:
6062 vdev_prop_add_list(outnvl
, propname
, NULL
,
6063 vd
->vdev_stat
.vs_dspace
, ZPROP_SRC_NONE
);
6065 case VDEV_PROP_FREE
:
6066 vdev_prop_add_list(outnvl
, propname
, NULL
,
6067 vd
->vdev_stat
.vs_dspace
-
6068 vd
->vdev_stat
.vs_alloc
, ZPROP_SRC_NONE
);
6070 case VDEV_PROP_ALLOCATED
:
6071 vdev_prop_add_list(outnvl
, propname
, NULL
,
6072 vd
->vdev_stat
.vs_alloc
, ZPROP_SRC_NONE
);
6074 case VDEV_PROP_EXPANDSZ
:
6075 vdev_prop_add_list(outnvl
, propname
, NULL
,
6076 vd
->vdev_stat
.vs_esize
, ZPROP_SRC_NONE
);
6078 case VDEV_PROP_FRAGMENTATION
:
6079 vdev_prop_add_list(outnvl
, propname
, NULL
,
6080 vd
->vdev_stat
.vs_fragmentation
,
6083 case VDEV_PROP_PARITY
:
6084 vdev_prop_add_list(outnvl
, propname
, NULL
,
6085 vdev_get_nparity(vd
), ZPROP_SRC_NONE
);
6087 case VDEV_PROP_PATH
:
6088 if (vd
->vdev_path
== NULL
)
6090 vdev_prop_add_list(outnvl
, propname
,
6091 vd
->vdev_path
, 0, ZPROP_SRC_NONE
);
6093 case VDEV_PROP_DEVID
:
6094 if (vd
->vdev_devid
== NULL
)
6096 vdev_prop_add_list(outnvl
, propname
,
6097 vd
->vdev_devid
, 0, ZPROP_SRC_NONE
);
6099 case VDEV_PROP_PHYS_PATH
:
6100 if (vd
->vdev_physpath
== NULL
)
6102 vdev_prop_add_list(outnvl
, propname
,
6103 vd
->vdev_physpath
, 0, ZPROP_SRC_NONE
);
6105 case VDEV_PROP_ENC_PATH
:
6106 if (vd
->vdev_enc_sysfs_path
== NULL
)
6108 vdev_prop_add_list(outnvl
, propname
,
6109 vd
->vdev_enc_sysfs_path
, 0, ZPROP_SRC_NONE
);
6112 if (vd
->vdev_fru
== NULL
)
6114 vdev_prop_add_list(outnvl
, propname
,
6115 vd
->vdev_fru
, 0, ZPROP_SRC_NONE
);
6117 case VDEV_PROP_PARENT
:
6118 if (vd
->vdev_parent
!= NULL
) {
6119 strval
= vdev_name(vd
->vdev_parent
,
6120 namebuf
, sizeof (namebuf
));
6121 vdev_prop_add_list(outnvl
, propname
,
6122 strval
, 0, ZPROP_SRC_NONE
);
6125 case VDEV_PROP_CHILDREN
:
6126 if (vd
->vdev_children
> 0)
6127 strval
= kmem_zalloc(ZAP_MAXVALUELEN
,
6129 for (uint64_t i
= 0; i
< vd
->vdev_children
;
6133 vname
= vdev_name(vd
->vdev_child
[i
],
6134 namebuf
, sizeof (namebuf
));
6136 vname
= "(unknown)";
6137 if (strlen(strval
) > 0)
6138 strlcat(strval
, ",",
6140 strlcat(strval
, vname
, ZAP_MAXVALUELEN
);
6142 if (strval
!= NULL
) {
6143 vdev_prop_add_list(outnvl
, propname
,
6144 strval
, 0, ZPROP_SRC_NONE
);
6145 kmem_free(strval
, ZAP_MAXVALUELEN
);
6148 case VDEV_PROP_NUMCHILDREN
:
6149 vdev_prop_add_list(outnvl
, propname
, NULL
,
6150 vd
->vdev_children
, ZPROP_SRC_NONE
);
6152 case VDEV_PROP_READ_ERRORS
:
6153 vdev_prop_add_list(outnvl
, propname
, NULL
,
6154 vd
->vdev_stat
.vs_read_errors
,
6157 case VDEV_PROP_WRITE_ERRORS
:
6158 vdev_prop_add_list(outnvl
, propname
, NULL
,
6159 vd
->vdev_stat
.vs_write_errors
,
6162 case VDEV_PROP_CHECKSUM_ERRORS
:
6163 vdev_prop_add_list(outnvl
, propname
, NULL
,
6164 vd
->vdev_stat
.vs_checksum_errors
,
6167 case VDEV_PROP_INITIALIZE_ERRORS
:
6168 vdev_prop_add_list(outnvl
, propname
, NULL
,
6169 vd
->vdev_stat
.vs_initialize_errors
,
6172 case VDEV_PROP_OPS_NULL
:
6173 vdev_prop_add_list(outnvl
, propname
, NULL
,
6174 vd
->vdev_stat
.vs_ops
[ZIO_TYPE_NULL
],
6177 case VDEV_PROP_OPS_READ
:
6178 vdev_prop_add_list(outnvl
, propname
, NULL
,
6179 vd
->vdev_stat
.vs_ops
[ZIO_TYPE_READ
],
6182 case VDEV_PROP_OPS_WRITE
:
6183 vdev_prop_add_list(outnvl
, propname
, NULL
,
6184 vd
->vdev_stat
.vs_ops
[ZIO_TYPE_WRITE
],
6187 case VDEV_PROP_OPS_FREE
:
6188 vdev_prop_add_list(outnvl
, propname
, NULL
,
6189 vd
->vdev_stat
.vs_ops
[ZIO_TYPE_FREE
],
6192 case VDEV_PROP_OPS_CLAIM
:
6193 vdev_prop_add_list(outnvl
, propname
, NULL
,
6194 vd
->vdev_stat
.vs_ops
[ZIO_TYPE_CLAIM
],
6197 case VDEV_PROP_OPS_TRIM
:
6199 * TRIM ops and bytes are reported to user
6200 * space as ZIO_TYPE_IOCTL. This is done to
6201 * preserve the vdev_stat_t structure layout
6204 vdev_prop_add_list(outnvl
, propname
, NULL
,
6205 vd
->vdev_stat
.vs_ops
[ZIO_TYPE_IOCTL
],
6208 case VDEV_PROP_BYTES_NULL
:
6209 vdev_prop_add_list(outnvl
, propname
, NULL
,
6210 vd
->vdev_stat
.vs_bytes
[ZIO_TYPE_NULL
],
6213 case VDEV_PROP_BYTES_READ
:
6214 vdev_prop_add_list(outnvl
, propname
, NULL
,
6215 vd
->vdev_stat
.vs_bytes
[ZIO_TYPE_READ
],
6218 case VDEV_PROP_BYTES_WRITE
:
6219 vdev_prop_add_list(outnvl
, propname
, NULL
,
6220 vd
->vdev_stat
.vs_bytes
[ZIO_TYPE_WRITE
],
6223 case VDEV_PROP_BYTES_FREE
:
6224 vdev_prop_add_list(outnvl
, propname
, NULL
,
6225 vd
->vdev_stat
.vs_bytes
[ZIO_TYPE_FREE
],
6228 case VDEV_PROP_BYTES_CLAIM
:
6229 vdev_prop_add_list(outnvl
, propname
, NULL
,
6230 vd
->vdev_stat
.vs_bytes
[ZIO_TYPE_CLAIM
],
6233 case VDEV_PROP_BYTES_TRIM
:
6235 * TRIM ops and bytes are reported to user
6236 * space as ZIO_TYPE_IOCTL. This is done to
6237 * preserve the vdev_stat_t structure layout
6240 vdev_prop_add_list(outnvl
, propname
, NULL
,
6241 vd
->vdev_stat
.vs_bytes
[ZIO_TYPE_IOCTL
],
6244 case VDEV_PROP_REMOVING
:
6245 vdev_prop_add_list(outnvl
, propname
, NULL
,
6246 vd
->vdev_removing
, ZPROP_SRC_NONE
);
6248 case VDEV_PROP_RAIDZ_EXPANDING
:
6249 /* Only expose this for raidz */
6250 if (vd
->vdev_ops
== &vdev_raidz_ops
) {
6251 vdev_prop_add_list(outnvl
, propname
,
6252 NULL
, vd
->vdev_rz_expanding
,
6256 /* Numeric Properites */
6257 case VDEV_PROP_ALLOCATING
:
6258 /* Leaf vdevs cannot have this property */
6259 if (vd
->vdev_mg
== NULL
&&
6260 vd
->vdev_top
!= NULL
) {
6261 src
= ZPROP_SRC_NONE
;
6262 intval
= ZPROP_BOOLEAN_NA
;
6264 err
= vdev_prop_get_int(vd
, prop
,
6266 if (err
&& err
!= ENOENT
)
6270 vdev_prop_default_numeric(prop
))
6271 src
= ZPROP_SRC_DEFAULT
;
6273 src
= ZPROP_SRC_LOCAL
;
6276 vdev_prop_add_list(outnvl
, propname
, NULL
,
6279 case VDEV_PROP_FAILFAST
:
6280 src
= ZPROP_SRC_LOCAL
;
6283 err
= zap_lookup(mos
, objid
, nvpair_name(elem
),
6284 sizeof (uint64_t), 1, &intval
);
6285 if (err
== ENOENT
) {
6286 intval
= vdev_prop_default_numeric(
6292 if (intval
== vdev_prop_default_numeric(prop
))
6293 src
= ZPROP_SRC_DEFAULT
;
6295 vdev_prop_add_list(outnvl
, propname
, strval
,
6298 case VDEV_PROP_CHECKSUM_N
:
6299 case VDEV_PROP_CHECKSUM_T
:
6300 case VDEV_PROP_IO_N
:
6301 case VDEV_PROP_IO_T
:
6302 err
= vdev_prop_get_int(vd
, prop
, &intval
);
6303 if (err
&& err
!= ENOENT
)
6306 if (intval
== vdev_prop_default_numeric(prop
))
6307 src
= ZPROP_SRC_DEFAULT
;
6309 src
= ZPROP_SRC_LOCAL
;
6311 vdev_prop_add_list(outnvl
, propname
, NULL
,
6314 /* Text Properties */
6315 case VDEV_PROP_COMMENT
:
6316 /* Exists in the ZAP below */
6318 case VDEV_PROP_USERPROP
:
6319 /* User Properites */
6320 src
= ZPROP_SRC_LOCAL
;
6322 err
= zap_length(mos
, objid
, nvpair_name(elem
),
6323 &integer_size
, &num_integers
);
6327 switch (integer_size
) {
6329 /* User properties cannot be integers */
6333 /* string property */
6334 strval
= kmem_alloc(num_integers
,
6336 err
= zap_lookup(mos
, objid
,
6337 nvpair_name(elem
), 1,
6338 num_integers
, strval
);
6344 vdev_prop_add_list(outnvl
, propname
,
6346 kmem_free(strval
, num_integers
);
6359 * Get all properties from the MOS vdev property object.
6363 for (zap_cursor_init(&zc
, mos
, objid
);
6364 (err
= zap_cursor_retrieve(&zc
, &za
)) == 0;
6365 zap_cursor_advance(&zc
)) {
6368 zprop_source_t src
= ZPROP_SRC_DEFAULT
;
6369 propname
= za
.za_name
;
6371 switch (za
.za_integer_length
) {
6373 /* We do not allow integer user properties */
6374 /* This is likely an internal value */
6377 /* string property */
6378 strval
= kmem_alloc(za
.za_num_integers
,
6380 err
= zap_lookup(mos
, objid
, za
.za_name
, 1,
6381 za
.za_num_integers
, strval
);
6383 kmem_free(strval
, za
.za_num_integers
);
6386 vdev_prop_add_list(outnvl
, propname
, strval
, 0,
6388 kmem_free(strval
, za
.za_num_integers
);
6395 zap_cursor_fini(&zc
);
6398 mutex_exit(&spa
->spa_props_lock
);
6399 if (err
&& err
!= ENOENT
) {
6406 EXPORT_SYMBOL(vdev_fault
);
6407 EXPORT_SYMBOL(vdev_degrade
);
6408 EXPORT_SYMBOL(vdev_online
);
6409 EXPORT_SYMBOL(vdev_offline
);
6410 EXPORT_SYMBOL(vdev_clear
);
6412 ZFS_MODULE_PARAM(zfs_vdev
, zfs_vdev_
, default_ms_count
, UINT
, ZMOD_RW
,
6413 "Target number of metaslabs per top-level vdev");
6415 ZFS_MODULE_PARAM(zfs_vdev
, zfs_vdev_
, default_ms_shift
, UINT
, ZMOD_RW
,
6416 "Default lower limit for metaslab size");
6418 ZFS_MODULE_PARAM(zfs_vdev
, zfs_vdev_
, max_ms_shift
, UINT
, ZMOD_RW
,
6419 "Default upper limit for metaslab size");
6421 ZFS_MODULE_PARAM(zfs_vdev
, zfs_vdev_
, min_ms_count
, UINT
, ZMOD_RW
,
6422 "Minimum number of metaslabs per top-level vdev");
6424 ZFS_MODULE_PARAM(zfs_vdev
, zfs_vdev_
, ms_count_limit
, UINT
, ZMOD_RW
,
6425 "Practical upper limit of total metaslabs per top-level vdev");
6427 ZFS_MODULE_PARAM(zfs
, zfs_
, slow_io_events_per_second
, UINT
, ZMOD_RW
,
6428 "Rate limit slow IO (delay) events to this many per second");
6431 ZFS_MODULE_PARAM(zfs
, zfs_
, checksum_events_per_second
, UINT
, ZMOD_RW
,
6432 "Rate limit checksum events to this many checksum errors per second "
6433 "(do not set below ZED threshold).");
6436 ZFS_MODULE_PARAM(zfs
, zfs_
, scan_ignore_errors
, INT
, ZMOD_RW
,
6437 "Ignore errors during resilver/scrub");
6439 ZFS_MODULE_PARAM(zfs_vdev
, vdev_
, validate_skip
, INT
, ZMOD_RW
,
6440 "Bypass vdev_validate()");
6442 ZFS_MODULE_PARAM(zfs
, zfs_
, nocacheflush
, INT
, ZMOD_RW
,
6443 "Disable cache flushes");
6445 ZFS_MODULE_PARAM(zfs
, zfs_
, embedded_slog_min_ms
, UINT
, ZMOD_RW
,
6446 "Minimum number of metaslabs required to dedicate one for log blocks");
6449 ZFS_MODULE_PARAM_CALL(zfs_vdev
, zfs_vdev_
, min_auto_ashift
,
6450 param_set_min_auto_ashift
, param_get_uint
, ZMOD_RW
,
6451 "Minimum ashift used when creating new top-level vdevs");
6453 ZFS_MODULE_PARAM_CALL(zfs_vdev
, zfs_vdev_
, max_auto_ashift
,
6454 param_set_max_auto_ashift
, param_get_uint
, ZMOD_RW
,
6455 "Maximum ashift used when optimizing for logical -> physical sector "
6456 "size on new top-level vdevs");