vdev.c revision 2e4c998613148111f2fc5371085331ffb39122ff
9da57d7b0ddd8d73b676ce12c040362132cdd538bt * CDDL HEADER START
9da57d7b0ddd8d73b676ce12c040362132cdd538bt * The contents of this file are subject to the terms of the
9da57d7b0ddd8d73b676ce12c040362132cdd538bt * Common Development and Distribution License (the "License").
9da57d7b0ddd8d73b676ce12c040362132cdd538bt * You may not use this file except in compliance with the License.
193974072f41a843678abf5f61979c748687e66bSherry Moore * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
9da57d7b0ddd8d73b676ce12c040362132cdd538bt * See the License for the specific language governing permissions
9da57d7b0ddd8d73b676ce12c040362132cdd538bt * and limitations under the License.
193974072f41a843678abf5f61979c748687e66bSherry Moore * When distributing Covered Code, include this CDDL HEADER in each
193974072f41a843678abf5f61979c748687e66bSherry Moore * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
9da57d7b0ddd8d73b676ce12c040362132cdd538bt * If applicable, add the following below this CDDL HEADER, with the
9da57d7b0ddd8d73b676ce12c040362132cdd538bt * fields enclosed by brackets "[]" replaced with your own identifying
9da57d7b0ddd8d73b676ce12c040362132cdd538bt * information: Portions Copyright [yyyy] [name of copyright owner]
9da57d7b0ddd8d73b676ce12c040362132cdd538bt * CDDL HEADER END
00f1c25a65b1cfd93d859ba8bd8872cd7f276c86chenlu chen - Sun Microsystems - Beijing China * Copyright (c) 2005, 2010, Oracle and/or its affiliates. All rights reserved.
00f1c25a65b1cfd93d859ba8bd8872cd7f276c86chenlu chen - Sun Microsystems - Beijing China * Copyright 2011 Nexenta Systems, Inc. All rights reserved.
00f1c25a65b1cfd93d859ba8bd8872cd7f276c86chenlu chen - Sun Microsystems - Beijing China * Copyright (c) 2011, 2014 by Delphix. All rights reserved.
ffd8e8832e01f996f32459073f4dd308fe5265baWinson Wang - Sun Microsystems - Beijing China#include <sys/uberblock_impl.h>
5b6dd21f5401160f9a62ac2e76a858c2bc105370chenlu chen - Sun Microsystems - Beijing China#include <sys/metaslab.h>
9da57d7b0ddd8d73b676ce12c040362132cdd538bt * Virtual device management.
ea65739ebec0cbd625d8c89e19592be58fa186a6chenlu chen - Sun Microsystems - Beijing China &vdev_disk_ops,
ea65739ebec0cbd625d8c89e19592be58fa186a6chenlu chen - Sun Microsystems - Beijing China &vdev_file_ops,
9da57d7b0ddd8d73b676ce12c040362132cdd538bt/* maximum scrub/resilver I/O queue per leaf vdev */
da14cebe459d3275048785f25bd869cb09b5307fEric Cheng * Given a vdev type, return the appropriate ops vector.
ea65739ebec0cbd625d8c89e19592be58fa186a6chenlu chen - Sun Microsystems - Beijing China vdev_ops_t *ops, **opspp;
62e6e1adfc8d795f477410703cc7a88dc5b82622Paul Guo for (opspp = vdev_ops_table; (ops = *opspp) != NULL; opspp++)
73cd555c10e70dac413ae4b40de8450a291750acBin Tu - Sun Microsystems - Beijing China if (strcmp(ops->vdev_op_type, type) == 0)
9da57d7b0ddd8d73b676ce12c040362132cdd538bt * Default asize function: return the MAX of psize with the asize of
9da57d7b0ddd8d73b676ce12c040362132cdd538bt * all children. This is what's used by anything other than RAID-Z.
9da57d7b0ddd8d73b676ce12c040362132cdd538bt uint64_t asize = P2ROUNDUP(psize, 1ULL << vd->vdev_top->vdev_ashift);
73cd555c10e70dac413ae4b40de8450a291750acBin Tu - Sun Microsystems - Beijing China asize = MAX(asize, csize);
9da57d7b0ddd8d73b676ce12c040362132cdd538bt * Get the minimum allocatable size. We define the allocatable size as
9da57d7b0ddd8d73b676ce12c040362132cdd538bt * the vdev's asize rounded to the nearest metaslab. This allows us to
9da57d7b0ddd8d73b676ce12c040362132cdd538bt * replace or attach devices which don't have the same physical size but
9da57d7b0ddd8d73b676ce12c040362132cdd538bt * can still satisfy the same number of allocations.
da14cebe459d3275048785f25bd869cb09b5307fEric Cheng * If our parent is NULL (inactive spare or cache) or is the root,
9da57d7b0ddd8d73b676ce12c040362132cdd538bt * just return our own asize.
9da57d7b0ddd8d73b676ce12c040362132cdd538bt * The top-level vdev just returns the allocatable size rounded
9da57d7b0ddd8d73b676ce12c040362132cdd538bt * to the nearest metaslab.
0dc2366f7b9f9f36e10909b1e95edbf2a261c2acVenugopal Iyer return (P2ALIGN(vd->vdev_asize, 1ULL << vd->vdev_ms_shift));
9da57d7b0ddd8d73b676ce12c040362132cdd538bt * The allocatable space for a raidz vdev is N * sizeof(smallest child),
9da57d7b0ddd8d73b676ce12c040362132cdd538bt * so each child must provide at least 1/Nth of its asize.
0dc2366f7b9f9f36e10909b1e95edbf2a261c2acVenugopal Iyer return (pvd->vdev_min_asize / pvd->vdev_children);
ea65739ebec0cbd625d8c89e19592be58fa186a6chenlu chen - Sun Microsystems - Beijing China vdev_set_min_asize(vd->vdev_child[c]);
ea65739ebec0cbd625d8c89e19592be58fa186a6chenlu chen - Sun Microsystems - Beijing Chinavdev_lookup_top(spa_t *spa, uint64_t vdev)
9da57d7b0ddd8d73b676ce12c040362132cdd538bt return (vd);
9da57d7b0ddd8d73b676ce12c040362132cdd538bt if ((mvd = vdev_lookup_by_guid(vd->vdev_child[c], guid)) !=
9da57d7b0ddd8d73b676ce12c040362132cdd538bt ASSERT(spa_config_held(cvd->vdev_spa, SCL_ALL, RW_WRITER) == SCL_ALL);
9da57d7b0ddd8d73b676ce12c040362132cdd538bt ASSERT(id >= pvd->vdev_children || pvd->vdev_child[id] == NULL);
9da57d7b0ddd8d73b676ce12c040362132cdd538bt * Walk up all ancestors to update guid sum.
1fedc51fe8f78efa2ee550387171e6adb2223b8dWinson Wang - Sun Microsystems - Beijing Chinavdev_remove_child(vdev_t *pvd, vdev_t *cvd)
ea65739ebec0cbd625d8c89e19592be58fa186a6chenlu chen - Sun Microsystems - Beijing China for (c = 0; c < pvd->vdev_children; c++)
ea65739ebec0cbd625d8c89e19592be58fa186a6chenlu chen - Sun Microsystems - Beijing China if (pvd->vdev_child[c])
13740cb230f19fcbf1a6468d1a6a0ba9a0a09c22Paul Guo * Walk up all ancestors to update guid sum.
13740cb230f19fcbf1a6468d1a6a0ba9a0a09c22Paul Guo * Remove any holes in the child array.
ea65739ebec0cbd625d8c89e19592be58fa186a6chenlu chen - Sun Microsystems - Beijing Chinavdev_compact_children(vdev_t *pvd)
ea65739ebec0cbd625d8c89e19592be58fa186a6chenlu chen - Sun Microsystems - Beijing China vdev_t **newchild, *cvd;
13740cb230f19fcbf1a6468d1a6a0ba9a0a09c22Paul Guo ASSERT(spa_config_held(pvd->vdev_spa, SCL_ALL, RW_WRITER) == SCL_ALL);
13740cb230f19fcbf1a6468d1a6a0ba9a0a09c22Paul Guo newchild = kmem_alloc(newc * sizeof (vdev_t *), KM_SLEEP);
73cd555c10e70dac413ae4b40de8450a291750acBin Tu - Sun Microsystems - Beijing China for (int c = newc = 0; c < oldc; c++) {
73cd555c10e70dac413ae4b40de8450a291750acBin Tu - Sun Microsystems - Beijing China if ((cvd = pvd->vdev_child[c]) != NULL) {
73cd555c10e70dac413ae4b40de8450a291750acBin Tu - Sun Microsystems - Beijing China kmem_free(pvd->vdev_child, oldc * sizeof (vdev_t *));
73cd555c10e70dac413ae4b40de8450a291750acBin Tu - Sun Microsystems - Beijing China pvd->vdev_child = newchild;
1fedc51fe8f78efa2ee550387171e6adb2223b8dWinson Wang - Sun Microsystems - Beijing China pvd->vdev_children = newc;
73cd555c10e70dac413ae4b40de8450a291750acBin Tu - Sun Microsystems - Beijing China * Allocate and minimally initialize a vdev_t.
5b6dd21f5401160f9a62ac2e76a858c2bc105370chenlu chen - Sun Microsystems - Beijing Chinavdev_alloc_common(spa_t *spa, uint_t id, uint64_t guid, vdev_ops_t *ops)
5b6dd21f5401160f9a62ac2e76a858c2bc105370chenlu chen - Sun Microsystems - Beijing China vd = kmem_zalloc(sizeof (vdev_t), KM_SLEEP);
5b6dd21f5401160f9a62ac2e76a858c2bc105370chenlu chen - Sun Microsystems - Beijing China if (spa->spa_root_vdev == NULL) {
5b6dd21f5401160f9a62ac2e76a858c2bc105370chenlu chen - Sun Microsystems - Beijing China ASSERT(ops == &vdev_root_ops);
73cd555c10e70dac413ae4b40de8450a291750acBin Tu - Sun Microsystems - Beijing China spa->spa_root_vdev = vd;
ffd8e8832e01f996f32459073f4dd308fe5265baWinson Wang - Sun Microsystems - Beijing China spa->spa_load_guid = spa_generate_guid(NULL);
73cd555c10e70dac413ae4b40de8450a291750acBin Tu - Sun Microsystems - Beijing China if (guid == 0 && ops != &vdev_hole_ops) {
73cd555c10e70dac413ae4b40de8450a291750acBin Tu - Sun Microsystems - Beijing China if (spa->spa_root_vdev == vd) {
69b5a878d62fdee1b12e78371ce6cc8abddcad15Dan McDonald * The root vdev's guid will also be the pool guid,
69b5a878d62fdee1b12e78371ce6cc8abddcad15Dan McDonald * which must be unique among all pools.
69b5a878d62fdee1b12e78371ce6cc8abddcad15Dan McDonald * Any other vdev's guid must be unique within the pool.
69b5a878d62fdee1b12e78371ce6cc8abddcad15Dan McDonald mutex_init(&vd->vdev_dtl_lock, NULL, MUTEX_DEFAULT, NULL);
69b5a878d62fdee1b12e78371ce6cc8abddcad15Dan McDonald mutex_init(&vd->vdev_stat_lock, NULL, MUTEX_DEFAULT, NULL);
69b5a878d62fdee1b12e78371ce6cc8abddcad15Dan McDonald mutex_init(&vd->vdev_probe_lock, NULL, MUTEX_DEFAULT, NULL);
69b5a878d62fdee1b12e78371ce6cc8abddcad15Dan McDonald for (int t = 0; t < DTL_TYPES; t++) {
69b5a878d62fdee1b12e78371ce6cc8abddcad15Dan McDonald vd->vdev_dtl[t] = range_tree_create(NULL, NULL,
9da57d7b0ddd8d73b676ce12c040362132cdd538bt return (vd);
9da57d7b0ddd8d73b676ce12c040362132cdd538bt * Allocate a new vdev. The 'alloctype' is used to control whether we are
9da57d7b0ddd8d73b676ce12c040362132cdd538bt * creating a new vdev or loading an existing one - the behavior is slightly
9da57d7b0ddd8d73b676ce12c040362132cdd538bt * different for each case.
9da57d7b0ddd8d73b676ce12c040362132cdd538btvdev_alloc(spa_t *spa, vdev_t **vdp, nvlist_t *nv, vdev_t *parent, uint_t id,
9da57d7b0ddd8d73b676ce12c040362132cdd538bt ASSERT(spa_config_held(spa, SCL_ALL, RW_WRITER) == SCL_ALL);
9da57d7b0ddd8d73b676ce12c040362132cdd538bt if (nvlist_lookup_string(nv, ZPOOL_CONFIG_TYPE, &type) != 0)
9da57d7b0ddd8d73b676ce12c040362132cdd538bt * If this is a load, get the vdev guid from the nvlist.
9da57d7b0ddd8d73b676ce12c040362132cdd538bt * Otherwise, vdev_alloc_common() will generate one for us.
9da57d7b0ddd8d73b676ce12c040362132cdd538bt if (nvlist_lookup_uint64(nv, ZPOOL_CONFIG_ID, &label_id) ||
9da57d7b0ddd8d73b676ce12c040362132cdd538bt if (nvlist_lookup_uint64(nv, ZPOOL_CONFIG_GUID, &guid) != 0)
9da57d7b0ddd8d73b676ce12c040362132cdd538bt if (nvlist_lookup_uint64(nv, ZPOOL_CONFIG_GUID, &guid) != 0)
9da57d7b0ddd8d73b676ce12c040362132cdd538bt if (nvlist_lookup_uint64(nv, ZPOOL_CONFIG_GUID, &guid) != 0)
9da57d7b0ddd8d73b676ce12c040362132cdd538bt if (nvlist_lookup_uint64(nv, ZPOOL_CONFIG_GUID, &guid) != 0)
9da57d7b0ddd8d73b676ce12c040362132cdd538bt * The first allocated vdev must be of type 'root'.
9da57d7b0ddd8d73b676ce12c040362132cdd538bt * Determine whether we're a log vdev.
13740cb230f19fcbf1a6468d1a6a0ba9a0a09c22Paul Guo (void) nvlist_lookup_uint64(nv, ZPOOL_CONFIG_IS_LOG, &islog);
9da57d7b0ddd8d73b676ce12c040362132cdd538bt if (ops == &vdev_hole_ops && spa_version(spa) < SPA_VERSION_HOLES)
9da57d7b0ddd8d73b676ce12c040362132cdd538bt * Set the nparity property for RAID-Z vdevs.
9da57d7b0ddd8d73b676ce12c040362132cdd538bt * Previous versions could only support 1 or 2 parity
9da57d7b0ddd8d73b676ce12c040362132cdd538bt * We require the parity to be specified for SPAs that
9da57d7b0ddd8d73b676ce12c040362132cdd538bt * support multiple parity levels.
9da57d7b0ddd8d73b676ce12c040362132cdd538bt * Otherwise, we default to 1 parity device for RAID-Z.
9da57d7b0ddd8d73b676ce12c040362132cdd538bt if (nvlist_lookup_string(nv, ZPOOL_CONFIG_PATH, &vd->vdev_path) == 0)
9da57d7b0ddd8d73b676ce12c040362132cdd538bt if (nvlist_lookup_string(nv, ZPOOL_CONFIG_DEVID, &vd->vdev_devid) == 0)
9da57d7b0ddd8d73b676ce12c040362132cdd538bt if (nvlist_lookup_string(nv, ZPOOL_CONFIG_FRU, &vd->vdev_fru) == 0)
9da57d7b0ddd8d73b676ce12c040362132cdd538bt * Set the whole_disk property. If it's not specified, leave the value
9da57d7b0ddd8d73b676ce12c040362132cdd538bt * Look for the 'not present' flag. This will only be set if the device
9da57d7b0ddd8d73b676ce12c040362132cdd538bt * was not present at the time of import.
9da57d7b0ddd8d73b676ce12c040362132cdd538bt (void) nvlist_lookup_uint64(nv, ZPOOL_CONFIG_NOT_PRESENT,
0dc2366f7b9f9f36e10909b1e95edbf2a261c2acVenugopal Iyer * Get the alignment requirement.
0dc2366f7b9f9f36e10909b1e95edbf2a261c2acVenugopal Iyer (void) nvlist_lookup_uint64(nv, ZPOOL_CONFIG_ASHIFT, &vd->vdev_ashift);
0dc2366f7b9f9f36e10909b1e95edbf2a261c2acVenugopal Iyer * Retrieve the vdev creation time.
0dc2366f7b9f9f36e10909b1e95edbf2a261c2acVenugopal Iyer (void) nvlist_lookup_uint64(nv, ZPOOL_CONFIG_CREATE_TXG,
9da57d7b0ddd8d73b676ce12c040362132cdd538bt * If we're a top-level vdev, try to load the allocation parameters.
9da57d7b0ddd8d73b676ce12c040362132cdd538bt (alloctype == VDEV_ALLOC_LOAD || alloctype == VDEV_ALLOC_SPLIT)) {
9da57d7b0ddd8d73b676ce12c040362132cdd538bt (void) nvlist_lookup_uint64(nv, ZPOOL_CONFIG_METASLAB_ARRAY,
9da57d7b0ddd8d73b676ce12c040362132cdd538bt (void) nvlist_lookup_uint64(nv, ZPOOL_CONFIG_METASLAB_SHIFT,
9da57d7b0ddd8d73b676ce12c040362132cdd538bt if (parent && !parent->vdev_parent && alloctype != VDEV_ALLOC_ATTACH) {
9da57d7b0ddd8d73b676ce12c040362132cdd538bt * If we're a leaf vdev, try to load the DTL object and other state.
9da57d7b0ddd8d73b676ce12c040362132cdd538bt (alloctype == VDEV_ALLOC_LOAD || alloctype == VDEV_ALLOC_L2CACHE ||
62e6e1adfc8d795f477410703cc7a88dc5b82622Paul Guo if (nvlist_lookup_uint64(nv, ZPOOL_CONFIG_IS_SPARE,
5b6dd21f5401160f9a62ac2e76a858c2bc105370chenlu chen - Sun Microsystems - Beijing China spa_spare_add(vd);
62e6e1adfc8d795f477410703cc7a88dc5b82622Paul Guo (void) nvlist_lookup_uint64(nv, ZPOOL_CONFIG_OFFLINE,
5b6dd21f5401160f9a62ac2e76a858c2bc105370chenlu chen - Sun Microsystems - Beijing China (void) nvlist_lookup_uint64(nv, ZPOOL_CONFIG_RESILVER_TXG,
5b6dd21f5401160f9a62ac2e76a858c2bc105370chenlu chen - Sun Microsystems - Beijing China &vd->vdev_resilver_txg);
5b6dd21f5401160f9a62ac2e76a858c2bc105370chenlu chen - Sun Microsystems - Beijing China * When importing a pool, we want to ignore the persistent fault
5b6dd21f5401160f9a62ac2e76a858c2bc105370chenlu chen - Sun Microsystems - Beijing China * state, as the diagnosis made on another system may not be
5b6dd21f5401160f9a62ac2e76a858c2bc105370chenlu chen - Sun Microsystems - Beijing China * valid in the current context. Local vdevs will
5b6dd21f5401160f9a62ac2e76a858c2bc105370chenlu chen - Sun Microsystems - Beijing China * remain in the faulted state.
5b6dd21f5401160f9a62ac2e76a858c2bc105370chenlu chen - Sun Microsystems - Beijing China if (spa_load_state(spa) == SPA_LOAD_OPEN) {
9da57d7b0ddd8d73b676ce12c040362132cdd538bt * Add ourselves to the parent's list of children.
9da57d7b0ddd8d73b676ce12c040362132cdd538bt return (0);
9da57d7b0ddd8d73b676ce12c040362132cdd538bt * vdev_free() implies closing the vdev first. This is simpler than
9da57d7b0ddd8d73b676ce12c040362132cdd538bt * trying to ensure complicated semantics for all callers.
9da57d7b0ddd8d73b676ce12c040362132cdd538bt * Free all children.
62e6e1adfc8d795f477410703cc7a88dc5b82622Paul Guo * Discard allocation state.
9da57d7b0ddd8d73b676ce12c040362132cdd538bt * Remove this vdev from its parent's child list.
9da57d7b0ddd8d73b676ce12c040362132cdd538bt * Clean up vdev structure.
9da57d7b0ddd8d73b676ce12c040362132cdd538bt for (int t = 0; t < DTL_TYPES; t++) {
9da57d7b0ddd8d73b676ce12c040362132cdd538bt * Transfer top-level vdev state from svd to tvd.
9da57d7b0ddd8d73b676ce12c040362132cdd538btstatic void
ea65739ebec0cbd625d8c89e19592be58fa186a6chenlu chen - Sun Microsystems - Beijing China svd->vdev_ms_shift = 0;
9da57d7b0ddd8d73b676ce12c040362132cdd538bt for (t = 0; t < TXG_SIZE; t++) {
9da57d7b0ddd8d73b676ce12c040362132cdd538bt while ((msp = txg_list_remove(&svd->vdev_ms_list, t)) != NULL)
9da57d7b0ddd8d73b676ce12c040362132cdd538bt while ((vd = txg_list_remove(&svd->vdev_dtl_list, t)) != NULL)
9da57d7b0ddd8d73b676ce12c040362132cdd538bt if (txg_list_remove_this(&spa->spa_vdev_txg_list, svd, t))
62e6e1adfc8d795f477410703cc7a88dc5b82622Paul Guo if (list_link_active(&svd->vdev_config_dirty_node)) {
62e6e1adfc8d795f477410703cc7a88dc5b82622Paul Guo if (list_link_active(&svd->vdev_state_dirty_node)) {
9da57d7b0ddd8d73b676ce12c040362132cdd538btstatic void
9da57d7b0ddd8d73b676ce12c040362132cdd538bt * Add a mirror/replacing vdev above an existing vdev.
5b6dd21f5401160f9a62ac2e76a858c2bc105370chenlu chen - Sun Microsystems - Beijing China ASSERT(spa_config_held(spa, SCL_ALL, RW_WRITER) == SCL_ALL);
5b6dd21f5401160f9a62ac2e76a858c2bc105370chenlu chen - Sun Microsystems - Beijing China mvd = vdev_alloc_common(spa, cvd->vdev_id, 0, ops);
5b6dd21f5401160f9a62ac2e76a858c2bc105370chenlu chen - Sun Microsystems - Beijing China mvd->vdev_asize = cvd->vdev_asize;
5b6dd21f5401160f9a62ac2e76a858c2bc105370chenlu chen - Sun Microsystems - Beijing China mvd->vdev_min_asize = cvd->vdev_min_asize;
0dc2366f7b9f9f36e10909b1e95edbf2a261c2acVenugopal Iyer vdev_top_update(cvd->vdev_top, cvd->vdev_top);
9da57d7b0ddd8d73b676ce12c040362132cdd538bt * Remove a 1-way mirror/replacing vdev from the tree.
9da57d7b0ddd8d73b676ce12c040362132cdd538bt ASSERT(spa_config_held(cvd->vdev_spa, SCL_ALL, RW_WRITER) == SCL_ALL);
9da57d7b0ddd8d73b676ce12c040362132cdd538bt * If cvd will replace mvd as a top-level vdev, preserve mvd's guid.
9da57d7b0ddd8d73b676ce12c040362132cdd538bt * Otherwise, we could have detached an offline device, and when we
9da57d7b0ddd8d73b676ce12c040362132cdd538bt * go to import the pool we'll think we have two top-level vdevs,
9da57d7b0ddd8d73b676ce12c040362132cdd538bt * instead of a different version of the same top-level vdev.
9da57d7b0ddd8d73b676ce12c040362132cdd538bt ASSERT(txg == 0 || spa_config_held(spa, SCL_ALLOC, RW_WRITER));
9da57d7b0ddd8d73b676ce12c040362132cdd538bt * This vdev is not being allocated from yet or is a hole.
9da57d7b0ddd8d73b676ce12c040362132cdd538bt return (0);
9da57d7b0ddd8d73b676ce12c040362132cdd538bt * Compute the raidz-deflation ratio. Note, we hard-code
9da57d7b0ddd8d73b676ce12c040362132cdd538bt * in 128k (1 << 17) because it is the current "typical" blocksize.
9da57d7b0ddd8d73b676ce12c040362132cdd538bt * Even if SPA_MAXBLOCKSIZE changes, this algorithm must never change,
9da57d7b0ddd8d73b676ce12c040362132cdd538bt * or we will inconsistently account for existing bp's.
9da57d7b0ddd8d73b676ce12c040362132cdd538bt if (oldc != 0) {
ea65739ebec0cbd625d8c89e19592be58fa186a6chenlu chen - Sun Microsystems - Beijing China bcopy(vd->vdev_ms, mspp, oldc * sizeof (*mspp));
9da57d7b0ddd8d73b676ce12c040362132cdd538bt if (txg == 0) {
9da57d7b0ddd8d73b676ce12c040362132cdd538bt vd->vdev_ms[m] = metaslab_init(vd->vdev_mg, m, object, txg);
9da57d7b0ddd8d73b676ce12c040362132cdd538bt * If the vdev is being removed we don't activate
9da57d7b0ddd8d73b676ce12c040362132cdd538bt * the metaslabs since we want to ensure that no new
9da57d7b0ddd8d73b676ce12c040362132cdd538bt * allocations are performed on this device.
13740cb230f19fcbf1a6468d1a6a0ba9a0a09c22Paul Guo return (0);
19843f01b1bef3453f717c23c8f89fb9313f6749Paul Guo for (m = 0; m < count; m++) {
5b6dd21f5401160f9a62ac2e76a858c2bc105370chenlu chen - Sun Microsystems - Beijing China kmem_free(vd->vdev_ms, count * sizeof (metaslab_t *));
19843f01b1bef3453f717c23c8f89fb9313f6749Paul Guotypedef struct vdev_probe_stats {
73cd555c10e70dac413ae4b40de8450a291750acBin Tu - Sun Microsystems - Beijing China boolean_t vps_readable;
73cd555c10e70dac413ae4b40de8450a291750acBin Tu - Sun Microsystems - Beijing China boolean_t vps_writeable;
5b6dd21f5401160f9a62ac2e76a858c2bc105370chenlu chen - Sun Microsystems - Beijing China int vps_flags;
5b6dd21f5401160f9a62ac2e76a858c2bc105370chenlu chen - Sun Microsystems - Beijing China} vdev_probe_stats_t;
5b6dd21f5401160f9a62ac2e76a858c2bc105370chenlu chen - Sun Microsystems - Beijing Chinavdev_probe_done(zio_t *zio)
5b6dd21f5401160f9a62ac2e76a858c2bc105370chenlu chen - Sun Microsystems - Beijing China spa_t *spa = zio->io_spa;
69b5a878d62fdee1b12e78371ce6cc8abddcad15Dan McDonald if (zio->io_error == 0 && spa_writeable(spa)) {
73cd555c10e70dac413ae4b40de8450a291750acBin Tu - Sun Microsystems - Beijing China if (!vdev_accessible(vd, pio))
9da57d7b0ddd8d73b676ce12c040362132cdd538bt * Determine whether this device is accessible.
9da57d7b0ddd8d73b676ce12c040362132cdd538bt * Read and write to several known locations: the pad regions of each
9da57d7b0ddd8d73b676ce12c040362132cdd538bt * vdev label but the first, which we leave alone in case it contains
ea65739ebec0cbd625d8c89e19592be58fa186a6chenlu chen - Sun Microsystems - Beijing China ASSERT(vd->vdev_ops->vdev_op_leaf);
9da57d7b0ddd8d73b676ce12c040362132cdd538bt * Don't probe the probe.
9da57d7b0ddd8d73b676ce12c040362132cdd538bt * To prevent 'probe storms' when a device fails, we create
9da57d7b0ddd8d73b676ce12c040362132cdd538bt * just one probe i/o at a time. All zios that want to probe
9da57d7b0ddd8d73b676ce12c040362132cdd538bt * this vdev will become parents of the probe io.
9da57d7b0ddd8d73b676ce12c040362132cdd538bt * vdev_cant_read and vdev_cant_write can only
9da57d7b0ddd8d73b676ce12c040362132cdd538bt * transition from TRUE to FALSE when we have the
9da57d7b0ddd8d73b676ce12c040362132cdd538bt * SCL_ZIO lock as writer; otherwise they can only
9da57d7b0ddd8d73b676ce12c040362132cdd538bt * transition from FALSE to TRUE. This ensures that
9da57d7b0ddd8d73b676ce12c040362132cdd538bt * any zio looking at these values can assume that
9da57d7b0ddd8d73b676ce12c040362132cdd538bt * failures persist for the life of the I/O. That's
9da57d7b0ddd8d73b676ce12c040362132cdd538bt * important because when a device has intermittent
da14cebe459d3275048785f25bd869cb09b5307fEric Cheng * connectivity problems, we want to ensure that
da14cebe459d3275048785f25bd869cb09b5307fEric Cheng * they're ascribed to the device (ENXIO) and not
da14cebe459d3275048785f25bd869cb09b5307fEric Cheng * the zio (EIO).
da14cebe459d3275048785f25bd869cb09b5307fEric Cheng * Since we hold SCL_ZIO as writer here, clear both
9da57d7b0ddd8d73b676ce12c040362132cdd538bt * values so the probe can reevaluate from first
9da57d7b0ddd8d73b676ce12c040362132cdd538bt * principles.
9da57d7b0ddd8d73b676ce12c040362132cdd538bt * We can't change the vdev state in this context, so we
9da57d7b0ddd8d73b676ce12c040362132cdd538bt * kick off an async task to do it on our behalf.
9da57d7b0ddd8d73b676ce12c040362132cdd538btstatic void
73cd555c10e70dac413ae4b40de8450a291750acBin Tu - Sun Microsystems - Beijing China vd->vdev_open_thread = curthread;
9da57d7b0ddd8d73b676ce12c040362132cdd538bt * in order to handle pools on top of zvols, do the opens
9da57d7b0ddd8d73b676ce12c040362132cdd538bt * in a single thread so that the same thread holds the
9da57d7b0ddd8d73b676ce12c040362132cdd538bt * spa_namespace_lock
9da57d7b0ddd8d73b676ce12c040362132cdd538bt for (int c = 0; c < children; c++)
9da57d7b0ddd8d73b676ce12c040362132cdd538bt for (int c = 0; c < children; c++)
9da57d7b0ddd8d73b676ce12c040362132cdd538bt VERIFY(taskq_dispatch(tq, vdev_open_child, vd->vdev_child[c],
9da57d7b0ddd8d73b676ce12c040362132cdd538bt * Prepare a virtual device for access.
9da57d7b0ddd8d73b676ce12c040362132cdd538bt spa_config_held(spa, SCL_STATE_ALL, RW_WRITER) == SCL_STATE_ALL);
9da57d7b0ddd8d73b676ce12c040362132cdd538bt * If this vdev is not removed, check its fault status. If it's
9da57d7b0ddd8d73b676ce12c040362132cdd538bt * faulted, bail out of the open.
9da57d7b0ddd8d73b676ce12c040362132cdd538bt vdev_set_state(vd, B_TRUE, VDEV_STATE_OFFLINE, VDEV_AUX_NONE);
9da57d7b0ddd8d73b676ce12c040362132cdd538bt error = vd->vdev_ops->vdev_op_open(vd, &osize, &max_osize, &ashift);
9da57d7b0ddd8d73b676ce12c040362132cdd538bt * Reset the vdev_reopening flag so that we actually close
9da57d7b0ddd8d73b676ce12c040362132cdd538bt * the vdev on error.
9da57d7b0ddd8d73b676ce12c040362132cdd538bt * Recheck the faulted flag now that we have confirmed that
9da57d7b0ddd8d73b676ce12c040362132cdd538bt * the vdev is accessible. If we're faulted, bail.
ea65739ebec0cbd625d8c89e19592be58fa186a6chenlu chen - Sun Microsystems - Beijing China VDEV_AUX_ERR_EXCEEDED);
ea65739ebec0cbd625d8c89e19592be58fa186a6chenlu chen - Sun Microsystems - Beijing China vdev_set_state(vd, B_TRUE, VDEV_STATE_HEALTHY, 0);
9da57d7b0ddd8d73b676ce12c040362132cdd538bt * For hole or missing vdevs we just return success.
9da57d7b0ddd8d73b676ce12c040362132cdd538bt if (vd->vdev_ishole || vd->vdev_ops == &vdev_missing_ops)
9da57d7b0ddd8d73b676ce12c040362132cdd538bt return (0);
9da57d7b0ddd8d73b676ce12c040362132cdd538bt if (vd->vdev_child[c]->vdev_state != VDEV_STATE_HEALTHY) {
9da57d7b0ddd8d73b676ce12c040362132cdd538bt max_osize = P2ALIGN(max_osize, (uint64_t)sizeof (vdev_label_t));
9da57d7b0ddd8d73b676ce12c040362132cdd538bt asize = osize - (VDEV_LABEL_START_SIZE + VDEV_LABEL_END_SIZE);
9da57d7b0ddd8d73b676ce12c040362132cdd538bt * Make sure the allocatable size hasn't shrunk.
9da57d7b0ddd8d73b676ce12c040362132cdd538bt * This is the first-ever open, so use the computed values.
9da57d7b0ddd8d73b676ce12c040362132cdd538bt * For testing purposes, a higher ashift can be requested.
9da57d7b0ddd8d73b676ce12c040362132cdd538bt * Detect if the alignment requirement has increased.
9da57d7b0ddd8d73b676ce12c040362132cdd538bt * We don't want to make the pool unavailable, just
69b5a878d62fdee1b12e78371ce6cc8abddcad15Dan McDonald * issue a warning instead.
9da57d7b0ddd8d73b676ce12c040362132cdd538bt "Disk, '%s', has a block alignment that is "
9da57d7b0ddd8d73b676ce12c040362132cdd538bt "larger than the pool's alignment\n",
9da57d7b0ddd8d73b676ce12c040362132cdd538bt * If all children are healthy and the asize has increased,
9da57d7b0ddd8d73b676ce12c040362132cdd538bt * then we've experienced dynamic LUN growth. If automatic
9da57d7b0ddd8d73b676ce12c040362132cdd538bt * expansion is enabled then use the additional space.
9da57d7b0ddd8d73b676ce12c040362132cdd538bt if (vd->vdev_state == VDEV_STATE_HEALTHY && asize > vd->vdev_asize &&
9da57d7b0ddd8d73b676ce12c040362132cdd538bt * Ensure we can issue some IO before declaring the
9da57d7b0ddd8d73b676ce12c040362132cdd538bt * vdev open for business.
9da57d7b0ddd8d73b676ce12c040362132cdd538bt * If a leaf vdev has a DTL, and seems healthy, then kick off a
9da57d7b0ddd8d73b676ce12c040362132cdd538bt * resilver. But don't do this if we are doing a reopen for a scrub,
9da57d7b0ddd8d73b676ce12c040362132cdd538bt * since this would just restart the scrub we are already doing.
9da57d7b0ddd8d73b676ce12c040362132cdd538bt if (vd->vdev_ops->vdev_op_leaf && !spa->spa_scrub_reopen &&
185c5677613512bc5a906decb5034a5135f67fb1Paul Guo return (0);
9da57d7b0ddd8d73b676ce12c040362132cdd538bt * Called once the vdevs are all opened, this routine validates the label
9da57d7b0ddd8d73b676ce12c040362132cdd538bt * contents. This needs to be done before vdev_load() so that we don't
9da57d7b0ddd8d73b676ce12c040362132cdd538bt * inadvertently do repair I/Os to the wrong device.
9da57d7b0ddd8d73b676ce12c040362132cdd538bt * If 'strict' is false ignore the spa guid check. This is necessary because
9da57d7b0ddd8d73b676ce12c040362132cdd538bt * if the machine crashed during a re-guid the new guid might have been written
9da57d7b0ddd8d73b676ce12c040362132cdd538bt * to all of the vdev labels, but not the cached config. The strict check
9da57d7b0ddd8d73b676ce12c040362132cdd538bt * will be performed when the pool is opened again using the mos config.
9da57d7b0ddd8d73b676ce12c040362132cdd538bt * This function will only return failure if one of the vdevs indicates that it
9da57d7b0ddd8d73b676ce12c040362132cdd538bt * has since been destroyed or exported. This is only possible if
9da57d7b0ddd8d73b676ce12c040362132cdd538bt * /etc/zfs/zpool.cache was readonly at the time. Otherwise, the vdev state
9da57d7b0ddd8d73b676ce12c040362132cdd538bt * will be updated but the function will return 0.
185c5677613512bc5a906decb5034a5135f67fb1Paul Guo * If the device has already failed, or was marked offline, don't do
185c5677613512bc5a906decb5034a5135f67fb1Paul Guo * any further validation. Otherwise, label I/O will fail and we will
185c5677613512bc5a906decb5034a5135f67fb1Paul Guo * overwrite the previous state.
185c5677613512bc5a906decb5034a5135f67fb1Paul Guo if (vd->vdev_ops->vdev_op_leaf && vdev_readable(vd)) {
19843f01b1bef3453f717c23c8f89fb9313f6749Paul Guo if ((label = vdev_label_read_config(vd, txg)) == NULL) {
5b6dd21f5401160f9a62ac2e76a858c2bc105370chenlu chen - Sun Microsystems - Beijing China vdev_set_state(vd, B_TRUE, VDEV_STATE_CANT_OPEN,
5b6dd21f5401160f9a62ac2e76a858c2bc105370chenlu chen - Sun Microsystems - Beijing China VDEV_AUX_BAD_LABEL);
19843f01b1bef3453f717c23c8f89fb9313f6749Paul Guo return (0);
9da57d7b0ddd8d73b676ce12c040362132cdd538bt * Determine if this vdev has been split off into another
9da57d7b0ddd8d73b676ce12c040362132cdd538bt * pool. If so, then refuse to open it.
9da57d7b0ddd8d73b676ce12c040362132cdd538bt return (0);
73cd555c10e70dac413ae4b40de8450a291750acBin Tu - Sun Microsystems - Beijing China VDEV_AUX_CORRUPT_DATA);
9da57d7b0ddd8d73b676ce12c040362132cdd538bt if (nvlist_lookup_nvlist(label, ZPOOL_CONFIG_VDEV_TREE, &nvl)
9da57d7b0ddd8d73b676ce12c040362132cdd538bt != 0 || nvlist_lookup_uint64(nvl, ZPOOL_CONFIG_ORIG_GUID,
9da57d7b0ddd8d73b676ce12c040362132cdd538bt * If this vdev just became a top-level vdev because its
9da57d7b0ddd8d73b676ce12c040362132cdd538bt * sibling was detached, it will have adopted the parent's
9da57d7b0ddd8d73b676ce12c040362132cdd538bt * vdev guid -- but the label may or may not be on disk yet.
9da57d7b0ddd8d73b676ce12c040362132cdd538bt * Fortunately, either version of the label will have the
9da57d7b0ddd8d73b676ce12c040362132cdd538bt * same top guid, so if we're a top-level vdev, we can
9da57d7b0ddd8d73b676ce12c040362132cdd538bt * safely compare to that instead.
9da57d7b0ddd8d73b676ce12c040362132cdd538bt * If we split this vdev off instead, then we also check the
9da57d7b0ddd8d73b676ce12c040362132cdd538bt * original pool's guid. We don't want to consider the vdev
9da57d7b0ddd8d73b676ce12c040362132cdd538bt * corrupt if it is partway through a split operation.
9da57d7b0ddd8d73b676ce12c040362132cdd538bt return (0);
9da57d7b0ddd8d73b676ce12c040362132cdd538bt return (0);
9da57d7b0ddd8d73b676ce12c040362132cdd538bt * If this is a verbatim import, no need to check the
9da57d7b0ddd8d73b676ce12c040362132cdd538bt * state of the pool.
ea65739ebec0cbd625d8c89e19592be58fa186a6chenlu chen - Sun Microsystems - Beijing China * If we were able to open and validate a vdev that was
ea65739ebec0cbd625d8c89e19592be58fa186a6chenlu chen - Sun Microsystems - Beijing China * previously marked permanently unavailable, clear that state
62e6e1adfc8d795f477410703cc7a88dc5b82622Paul Guo return (0);
ea65739ebec0cbd625d8c89e19592be58fa186a6chenlu chen - Sun Microsystems - Beijing China * Close a virtual device.
62e6e1adfc8d795f477410703cc7a88dc5b82622Paul Guo ASSERT(spa_config_held(spa, SCL_STATE_ALL, RW_WRITER) == SCL_STATE_ALL);
62e6e1adfc8d795f477410703cc7a88dc5b82622Paul Guo * If our parent is reopening, then we are as well, unless we are
62e6e1adfc8d795f477410703cc7a88dc5b82622Paul Guo * going offline.
62e6e1adfc8d795f477410703cc7a88dc5b82622Paul Guo vd->vdev_reopening = (pvd->vdev_reopening && !vd->vdev_offline);
9da57d7b0ddd8d73b676ce12c040362132cdd538bt * We record the previous state before we close it, so that if we are
9da57d7b0ddd8d73b676ce12c040362132cdd538bt * doing a reopen(), we don't generate FMA ereports if we notice that
ea65739ebec0cbd625d8c89e19592be58fa186a6chenlu chen - Sun Microsystems - Beijing China * it's still faulted.
ea65739ebec0cbd625d8c89e19592be58fa186a6chenlu chen - Sun Microsystems - Beijing China vd->vdev_prevstate = vd->vdev_state;
9da57d7b0ddd8d73b676ce12c040362132cdd538bt * Reopen all interior vdevs and any unopened leaves. We don't actually
9da57d7b0ddd8d73b676ce12c040362132cdd538bt * reopen leaf vdevs which had previously been opened as they might deadlock
9da57d7b0ddd8d73b676ce12c040362132cdd538bt * on the spa_config_lock. Instead we only obtain the leaf's physical size.
9da57d7b0ddd8d73b676ce12c040362132cdd538bt * If the leaf has never been opened then open it, as usual.
9da57d7b0ddd8d73b676ce12c040362132cdd538bt ASSERT(spa_config_held(spa, SCL_STATE_ALL, RW_WRITER) == SCL_STATE_ALL);
9da57d7b0ddd8d73b676ce12c040362132cdd538bt /* set the reopening flag unless we're taking the vdev offline */
9da57d7b0ddd8d73b676ce12c040362132cdd538bt * Call vdev_validate() here to make sure we have the same device.
9da57d7b0ddd8d73b676ce12c040362132cdd538bt * Otherwise, a device with an invalid label could be successfully
9da57d7b0ddd8d73b676ce12c040362132cdd538bt * opened in response to vdev_reopen().
9da57d7b0ddd8d73b676ce12c040362132cdd538bt * Reassess parent vdev's health.
9da57d7b0ddd8d73b676ce12c040362132cdd538btvdev_create(vdev_t *vd, uint64_t txg, boolean_t isreplacing)
9da57d7b0ddd8d73b676ce12c040362132cdd538bt * Normally, partial opens (e.g. of a mirror) are allowed.
9da57d7b0ddd8d73b676ce12c040362132cdd538bt * For a create, however, we want to fail the request if
9da57d7b0ddd8d73b676ce12c040362132cdd538bt * there are any components we can't open.
9da57d7b0ddd8d73b676ce12c040362132cdd538bt * Recursively load DTLs and initialize all labels.
9da57d7b0ddd8d73b676ce12c040362132cdd538bt return (0);
9da57d7b0ddd8d73b676ce12c040362132cdd538bt * Aim for roughly 200 metaslabs per vdev.
9da57d7b0ddd8d73b676ce12c040362132cdd538bt vd->vdev_ms_shift = MAX(vd->vdev_ms_shift, SPA_MAXBLOCKSHIFT);
9da57d7b0ddd8d73b676ce12c040362132cdd538btvdev_dirty(vdev_t *vd, int flags, void *arg, uint64_t txg)
ea65739ebec0cbd625d8c89e19592be58fa186a6chenlu chen - Sun Microsystems - Beijing China ASSERT(vd == vd->vdev_top);
9da57d7b0ddd8d73b676ce12c040362132cdd538bt (void) txg_list_add(&vd->vdev_spa->spa_vdev_txg_list, vd, txg);
9da57d7b0ddd8d73b676ce12c040362132cdd538bt * A vdev's DTL (dirty time log) is the set of transaction groups for which
ea65739ebec0cbd625d8c89e19592be58fa186a6chenlu chen - Sun Microsystems - Beijing China * the vdev has less than perfect replication. There are four kinds of DTL:
9da57d7b0ddd8d73b676ce12c040362132cdd538bt * DTL_MISSING: txgs for which the vdev has no valid copies of the data
9da57d7b0ddd8d73b676ce12c040362132cdd538bt * DTL_PARTIAL: txgs for which data is available, but not fully replicated
ea65739ebec0cbd625d8c89e19592be58fa186a6chenlu chen - Sun Microsystems - Beijing China * DTL_SCRUB: the txgs that could not be repaired by the last scrub; upon
ea65739ebec0cbd625d8c89e19592be58fa186a6chenlu chen - Sun Microsystems - Beijing China * scrub completion, DTL_SCRUB replaces DTL_MISSING in the range of
ea65739ebec0cbd625d8c89e19592be58fa186a6chenlu chen - Sun Microsystems - Beijing China * txgs that was scrubbed.
ea65739ebec0cbd625d8c89e19592be58fa186a6chenlu chen - Sun Microsystems - Beijing China * DTL_OUTAGE: txgs which cannot currently be read, whether due to
ea65739ebec0cbd625d8c89e19592be58fa186a6chenlu chen - Sun Microsystems - Beijing China * persistent errors or just some device being offline.
ea65739ebec0cbd625d8c89e19592be58fa186a6chenlu chen - Sun Microsystems - Beijing China * Unlike the other three, the DTL_OUTAGE map is not generally
ea65739ebec0cbd625d8c89e19592be58fa186a6chenlu chen - Sun Microsystems - Beijing China * maintained; it's only computed when needed, typically to
ea65739ebec0cbd625d8c89e19592be58fa186a6chenlu chen - Sun Microsystems - Beijing China * determine whether a device can be detached.
ea65739ebec0cbd625d8c89e19592be58fa186a6chenlu chen - Sun Microsystems - Beijing China * For leaf vdevs, DTL_MISSING and DTL_PARTIAL are identical: the device
ea65739ebec0cbd625d8c89e19592be58fa186a6chenlu chen - Sun Microsystems - Beijing China * either has the data or it doesn't.
ea65739ebec0cbd625d8c89e19592be58fa186a6chenlu chen - Sun Microsystems - Beijing China * For interior vdevs such as mirror and RAID-Z the picture is more complex.
ea65739ebec0cbd625d8c89e19592be58fa186a6chenlu chen - Sun Microsystems - Beijing China * A vdev's DTL_PARTIAL is the union of its children's DTL_PARTIALs, because
ea65739ebec0cbd625d8c89e19592be58fa186a6chenlu chen - Sun Microsystems - Beijing China * if any child is less than fully replicated, then so is its parent.
ea65739ebec0cbd625d8c89e19592be58fa186a6chenlu chen - Sun Microsystems - Beijing China * A vdev's DTL_MISSING is a modified union of its children's DTL_MISSINGs,
ea65739ebec0cbd625d8c89e19592be58fa186a6chenlu chen - Sun Microsystems - Beijing China * comprising only those txgs which appear in 'maxfaults' or more children;
9da57d7b0ddd8d73b676ce12c040362132cdd538bt * those are the txgs we don't have enough replication to read. For example,
9da57d7b0ddd8d73b676ce12c040362132cdd538bt * double-parity RAID-Z can tolerate up to two missing devices (maxfaults == 2);
9da57d7b0ddd8d73b676ce12c040362132cdd538bt * thus, its DTL_MISSING consists of the set of txgs that appear in more than
9da57d7b0ddd8d73b676ce12c040362132cdd538bt * two child DTL_MISSING maps.
9da57d7b0ddd8d73b676ce12c040362132cdd538bt * It should be clear from the above that to compute the DTLs and outage maps
9da57d7b0ddd8d73b676ce12c040362132cdd538bt * for all vdevs, it suffices to know just the leaf vdevs' DTL_MISSING maps.
9da57d7b0ddd8d73b676ce12c040362132cdd538bt * Therefore, that is all we keep on disk. When loading the pool, or after
9da57d7b0ddd8d73b676ce12c040362132cdd538bt * a configuration change, we generate all other DTLs from first principles.
9da57d7b0ddd8d73b676ce12c040362132cdd538btvdev_dtl_dirty(vdev_t *vd, vdev_dtl_type_t t, uint64_t txg, uint64_t size)
62e6e1adfc8d795f477410703cc7a88dc5b82622Paul Guovdev_dtl_contains(vdev_t *vd, vdev_dtl_type_t t, uint64_t txg, uint64_t size)
5b6dd21f5401160f9a62ac2e76a858c2bc105370chenlu chen - Sun Microsystems - Beijing China range_tree_t *rt = vd->vdev_dtl[t];
9da57d7b0ddd8d73b676ce12c040362132cdd538bt * Returns the lowest txg in the DTL range.
ea65739ebec0cbd625d8c89e19592be58fa186a6chenlu chen - Sun Microsystems - Beijing Chinastatic uint64_t
9da57d7b0ddd8d73b676ce12c040362132cdd538bt ASSERT3U(range_tree_space(vd->vdev_dtl[DTL_MISSING]), !=, 0);
9da57d7b0ddd8d73b676ce12c040362132cdd538bt * Returns the highest txg in the DTL.
9da57d7b0ddd8d73b676ce12c040362132cdd538bt ASSERT3U(range_tree_space(vd->vdev_dtl[DTL_MISSING]), !=, 0);
9da57d7b0ddd8d73b676ce12c040362132cdd538bt * Determine if a resilvering vdev should remove any DTL entries from
9da57d7b0ddd8d73b676ce12c040362132cdd538bt * its range. If the vdev was resilvering for the entire duration of the
9da57d7b0ddd8d73b676ce12c040362132cdd538bt * scan then it should excise that range from its DTLs. Otherwise, this
9da57d7b0ddd8d73b676ce12c040362132cdd538bt * vdev is considered partially resilvered and should leave its DTL
9da57d7b0ddd8d73b676ce12c040362132cdd538bt * entries intact. The comment in vdev_dtl_reassess() describes how we
9da57d7b0ddd8d73b676ce12c040362132cdd538bt * excise the DTLs.
ea65739ebec0cbd625d8c89e19592be58fa186a6chenlu chen - Sun Microsystems - Beijing China spa_t *spa = vd->vdev_spa;
ea65739ebec0cbd625d8c89e19592be58fa186a6chenlu chen - Sun Microsystems - Beijing China dsl_scan_t *scn = spa->spa_dsl_pool->dp_scan;
ea65739ebec0cbd625d8c89e19592be58fa186a6chenlu chen - Sun Microsystems - Beijing China ASSERT0(scn->scn_phys.scn_errors);
ea65739ebec0cbd625d8c89e19592be58fa186a6chenlu chen - Sun Microsystems - Beijing China ASSERT0(vd->vdev_children);
ea65739ebec0cbd625d8c89e19592be58fa186a6chenlu chen - Sun Microsystems - Beijing China if (vd->vdev_resilver_txg == 0 ||
ea65739ebec0cbd625d8c89e19592be58fa186a6chenlu chen - Sun Microsystems - Beijing China range_tree_space(vd->vdev_dtl[DTL_MISSING]) == 0)
ea65739ebec0cbd625d8c89e19592be58fa186a6chenlu chen - Sun Microsystems - Beijing China return (B_TRUE);
ea65739ebec0cbd625d8c89e19592be58fa186a6chenlu chen - Sun Microsystems - Beijing China * When a resilver is initiated the scan will assign the scn_max_txg
9da57d7b0ddd8d73b676ce12c040362132cdd538bt * value to the highest txg value that exists in all DTLs. If this
9da57d7b0ddd8d73b676ce12c040362132cdd538bt * device's max DTL is not part of this scan (i.e. it is not in
0dc2366f7b9f9f36e10909b1e95edbf2a261c2acVenugopal Iyer * the range (scn_min_txg, scn_max_txg] then it is not eligible
0dc2366f7b9f9f36e10909b1e95edbf2a261c2acVenugopal Iyer * for excision.
0dc2366f7b9f9f36e10909b1e95edbf2a261c2acVenugopal Iyer if (vdev_dtl_max(vd) <= scn->scn_phys.scn_max_txg) {
0dc2366f7b9f9f36e10909b1e95edbf2a261c2acVenugopal Iyer ASSERT3U(scn->scn_phys.scn_min_txg, <=, vdev_dtl_min(vd));
0dc2366f7b9f9f36e10909b1e95edbf2a261c2acVenugopal Iyer ASSERT3U(scn->scn_phys.scn_min_txg, <, vd->vdev_resilver_txg);
0dc2366f7b9f9f36e10909b1e95edbf2a261c2acVenugopal Iyer ASSERT3U(vd->vdev_resilver_txg, <=, scn->scn_phys.scn_max_txg);
0dc2366f7b9f9f36e10909b1e95edbf2a261c2acVenugopal Iyer * Reassess DTLs after a config change or scrub completion.
0dc2366f7b9f9f36e10909b1e95edbf2a261c2acVenugopal Iyervdev_dtl_reassess(vdev_t *vd, uint64_t txg, uint64_t scrub_txg, int scrub_done)
0dc2366f7b9f9f36e10909b1e95edbf2a261c2acVenugopal Iyer ASSERT(spa_config_held(spa, SCL_ALL, RW_READER) != 0);
0dc2366f7b9f9f36e10909b1e95edbf2a261c2acVenugopal Iyer if (vd == spa->spa_root_vdev || vd->vdev_ishole || vd->vdev_aux)
0dc2366f7b9f9f36e10909b1e95edbf2a261c2acVenugopal Iyer dsl_scan_t *scn = spa->spa_dsl_pool->dp_scan;
0dc2366f7b9f9f36e10909b1e95edbf2a261c2acVenugopal Iyer * If we've completed a scan cleanly then determine
0dc2366f7b9f9f36e10909b1e95edbf2a261c2acVenugopal Iyer * if this vdev should remove any DTLs. We only want to
0dc2366f7b9f9f36e10909b1e95edbf2a261c2acVenugopal Iyer * excise regions on vdevs that were available during
0dc2366f7b9f9f36e10909b1e95edbf2a261c2acVenugopal Iyer * the entire duration of this scan.
0dc2366f7b9f9f36e10909b1e95edbf2a261c2acVenugopal Iyer (scn != NULL && scn->scn_phys.scn_errors == 0)) &&
0dc2366f7b9f9f36e10909b1e95edbf2a261c2acVenugopal Iyer * We completed a scrub up to scrub_txg. If we
0dc2366f7b9f9f36e10909b1e95edbf2a261c2acVenugopal Iyer * did it without rebooting, then the scrub dtl
0dc2366f7b9f9f36e10909b1e95edbf2a261c2acVenugopal Iyer * will be valid, so excise the old region and
0dc2366f7b9f9f36e10909b1e95edbf2a261c2acVenugopal Iyer * fold in the scrub dtl. Otherwise, leave the
0dc2366f7b9f9f36e10909b1e95edbf2a261c2acVenugopal Iyer * dtl as-is if there was an error.
0dc2366f7b9f9f36e10909b1e95edbf2a261c2acVenugopal Iyer * There's little trick here: to excise the beginning
0dc2366f7b9f9f36e10909b1e95edbf2a261c2acVenugopal Iyer * of the DTL_MISSING map, we put it into a reference
0dc2366f7b9f9f36e10909b1e95edbf2a261c2acVenugopal Iyer * tree and then add a segment with refcnt -1 that
0dc2366f7b9f9f36e10909b1e95edbf2a261c2acVenugopal Iyer * covers the range [0, scrub_txg). This means
0dc2366f7b9f9f36e10909b1e95edbf2a261c2acVenugopal Iyer * that each txg in that range has refcnt -1 or 0.
0dc2366f7b9f9f36e10909b1e95edbf2a261c2acVenugopal Iyer * We then add DTL_SCRUB with a refcnt of 2, so that
0dc2366f7b9f9f36e10909b1e95edbf2a261c2acVenugopal Iyer * entries in the range [0, scrub_txg) will have a
0dc2366f7b9f9f36e10909b1e95edbf2a261c2acVenugopal Iyer * positive refcnt -- either 1 or 2. We then convert
0dc2366f7b9f9f36e10909b1e95edbf2a261c2acVenugopal Iyer * the reference tree into the new DTL_MISSING map.
0dc2366f7b9f9f36e10909b1e95edbf2a261c2acVenugopal Iyer space_reftree_add_seg(&reftree, 0, scrub_txg, -1);
0dc2366f7b9f9f36e10909b1e95edbf2a261c2acVenugopal Iyer range_tree_vacate(vd->vdev_dtl[DTL_PARTIAL], NULL, NULL);
0dc2366f7b9f9f36e10909b1e95edbf2a261c2acVenugopal Iyer range_tree_vacate(vd->vdev_dtl[DTL_SCRUB], NULL, NULL);
0dc2366f7b9f9f36e10909b1e95edbf2a261c2acVenugopal Iyer range_tree_vacate(vd->vdev_dtl[DTL_OUTAGE], NULL, NULL);
0dc2366f7b9f9f36e10909b1e95edbf2a261c2acVenugopal Iyer range_tree_add(vd->vdev_dtl[DTL_OUTAGE], 0, -1ULL);
0dc2366f7b9f9f36e10909b1e95edbf2a261c2acVenugopal Iyer * If the vdev was resilvering and no longer has any
0dc2366f7b9f9f36e10909b1e95edbf2a261c2acVenugopal Iyer * DTLs then reset its resilvering flag.
0dc2366f7b9f9f36e10909b1e95edbf2a261c2acVenugopal Iyer range_tree_space(vd->vdev_dtl[DTL_MISSING]) == 0 &&
0dc2366f7b9f9f36e10909b1e95edbf2a261c2acVenugopal Iyer range_tree_space(vd->vdev_dtl[DTL_OUTAGE]) == 0)
0dc2366f7b9f9f36e10909b1e95edbf2a261c2acVenugopal Iyer for (int t = 0; t < DTL_TYPES; t++) {
0dc2366f7b9f9f36e10909b1e95edbf2a261c2acVenugopal Iyer /* account for child's outage in parent's missing map */
0dc2366f7b9f9f36e10909b1e95edbf2a261c2acVenugopal Iyer continue; /* leaf vdevs only */
0dc2366f7b9f9f36e10909b1e95edbf2a261c2acVenugopal Iyer minref = vd->vdev_children; /* any kind of mirror */
0dc2366f7b9f9f36e10909b1e95edbf2a261c2acVenugopal Iyer for (int c = 0; c < vd->vdev_children; c++) {
0dc2366f7b9f9f36e10909b1e95edbf2a261c2acVenugopal Iyer space_reftree_add_map(&reftree, cvd->vdev_dtl[s], 1);
0dc2366f7b9f9f36e10909b1e95edbf2a261c2acVenugopal Iyer space_reftree_generate_map(&reftree, vd->vdev_dtl[t], minref);
0dc2366f7b9f9f36e10909b1e95edbf2a261c2acVenugopal Iyer if (vd->vdev_ops->vdev_op_leaf && vd->vdev_dtl_object != 0) {
0dc2366f7b9f9f36e10909b1e95edbf2a261c2acVenugopal Iyer error = space_map_open(&vd->vdev_dtl_sm, mos,
0dc2366f7b9f9f36e10909b1e95edbf2a261c2acVenugopal Iyer vd->vdev_dtl_object, 0, -1ULL, 0, &vd->vdev_dtl_lock);
0dc2366f7b9f9f36e10909b1e95edbf2a261c2acVenugopal Iyer * Now that we've opened the space_map we need to update
0dc2366f7b9f9f36e10909b1e95edbf2a261c2acVenugopal Iyer * the in-core DTL.
0dc2366f7b9f9f36e10909b1e95edbf2a261c2acVenugopal Iyer for (int c = 0; c < vd->vdev_children; c++) {
0dc2366f7b9f9f36e10909b1e95edbf2a261c2acVenugopal Iyer range_tree_t *rt = vd->vdev_dtl[DTL_MISSING];
0dc2366f7b9f9f36e10909b1e95edbf2a261c2acVenugopal Iyer uint64_t object = space_map_object(vd->vdev_dtl_sm);
0dc2366f7b9f9f36e10909b1e95edbf2a261c2acVenugopal Iyer tx = dmu_tx_create_assigned(spa->spa_dsl_pool, txg);
0dc2366f7b9f9f36e10909b1e95edbf2a261c2acVenugopal Iyer if (vd->vdev_detached || vd->vdev_top->vdev_removing) {
0dc2366f7b9f9f36e10909b1e95edbf2a261c2acVenugopal Iyer VERIFY0(space_map_open(&vd->vdev_dtl_sm, mos, new_object,
0dc2366f7b9f9f36e10909b1e95edbf2a261c2acVenugopal Iyer mutex_init(&rtlock, NULL, MUTEX_DEFAULT, NULL);
0dc2366f7b9f9f36e10909b1e95edbf2a261c2acVenugopal Iyer rtsync = range_tree_create(NULL, NULL, &rtlock);
9da57d7b0ddd8d73b676ce12c040362132cdd538bt * If the object for the space map has changed then dirty
9da57d7b0ddd8d73b676ce12c040362132cdd538bt * the top level so that we update the config.
9da57d7b0ddd8d73b676ce12c040362132cdd538bt * Determine whether the specified vdev can be offlined/detached/removed
9da57d7b0ddd8d73b676ce12c040362132cdd538bt * without losing data.
da14cebe459d3275048785f25bd869cb09b5307fEric Cheng ASSERT(spa_config_held(spa, SCL_STATE_ALL, RW_WRITER) == SCL_STATE_ALL);
da14cebe459d3275048785f25bd869cb09b5307fEric Cheng * Temporarily mark the device as unreadable, and then determine
da14cebe459d3275048785f25bd869cb09b5307fEric Cheng * whether this results in any DTL outages in the top-level vdev.
9da57d7b0ddd8d73b676ce12c040362132cdd538bt * If not, we can safely offline/detach/remove the device.
9da57d7b0ddd8d73b676ce12c040362132cdd538bt required = !!zio_handle_device_injection(vd, NULL, ECHILD);
9da57d7b0ddd8d73b676ce12c040362132cdd538bt * Determine if resilver is needed, and if so the txg range.
9da57d7b0ddd8d73b676ce12c040362132cdd538btvdev_resilver_needed(vdev_t *vd, uint64_t *minp, uint64_t *maxp)
ea65739ebec0cbd625d8c89e19592be58fa186a6chenlu chen - Sun Microsystems - Beijing China thismin = vdev_dtl_min(vd);
ea65739ebec0cbd625d8c89e19592be58fa186a6chenlu chen - Sun Microsystems - Beijing China thismax = vdev_dtl_max(vd);
ea65739ebec0cbd625d8c89e19592be58fa186a6chenlu chen - Sun Microsystems - Beijing China needed = B_TRUE;
ea65739ebec0cbd625d8c89e19592be58fa186a6chenlu chen - Sun Microsystems - Beijing China mutex_exit(&vd->vdev_dtl_lock);
ea65739ebec0cbd625d8c89e19592be58fa186a6chenlu chen - Sun Microsystems - Beijing China for (int c = 0; c < vd->vdev_children; c++) {
ea65739ebec0cbd625d8c89e19592be58fa186a6chenlu chen - Sun Microsystems - Beijing China vdev_t *cvd = vd->vdev_child[c];
ea65739ebec0cbd625d8c89e19592be58fa186a6chenlu chen - Sun Microsystems - Beijing China uint64_t cmin, cmax;
ea65739ebec0cbd625d8c89e19592be58fa186a6chenlu chen - Sun Microsystems - Beijing China if (vdev_resilver_needed(cvd, &cmin, &cmax)) {
ea65739ebec0cbd625d8c89e19592be58fa186a6chenlu chen - Sun Microsystems - Beijing China thismin = MIN(thismin, cmin);
ea65739ebec0cbd625d8c89e19592be58fa186a6chenlu chen - Sun Microsystems - Beijing China thismax = MAX(thismax, cmax);
ea65739ebec0cbd625d8c89e19592be58fa186a6chenlu chen - Sun Microsystems - Beijing China needed = B_TRUE;
ea65739ebec0cbd625d8c89e19592be58fa186a6chenlu chen - Sun Microsystems - Beijing China if (needed && minp) {
ea65739ebec0cbd625d8c89e19592be58fa186a6chenlu chen - Sun Microsystems - Beijing China *minp = thismin;
ea65739ebec0cbd625d8c89e19592be58fa186a6chenlu chen - Sun Microsystems - Beijing China *maxp = thismax;
ea65739ebec0cbd625d8c89e19592be58fa186a6chenlu chen - Sun Microsystems - Beijing China return (needed);
ea65739ebec0cbd625d8c89e19592be58fa186a6chenlu chen - Sun Microsystems - Beijing Chinavdev_load(vdev_t *vd)
ea65739ebec0cbd625d8c89e19592be58fa186a6chenlu chen - Sun Microsystems - Beijing China * Recursively load all children.
ea65739ebec0cbd625d8c89e19592be58fa186a6chenlu chen - Sun Microsystems - Beijing China for (int c = 0; c < vd->vdev_children; c++)
ea65739ebec0cbd625d8c89e19592be58fa186a6chenlu chen - Sun Microsystems - Beijing China vdev_load(vd->vdev_child[c]);
ea65739ebec0cbd625d8c89e19592be58fa186a6chenlu chen - Sun Microsystems - Beijing China * If this is a top-level vdev, initialize its metaslabs.
ea65739ebec0cbd625d8c89e19592be58fa186a6chenlu chen - Sun Microsystems - Beijing China if (vd == vd->vdev_top && !vd->vdev_ishole &&
ea65739ebec0cbd625d8c89e19592be58fa186a6chenlu chen - Sun Microsystems - Beijing China (vd->vdev_ashift == 0 || vd->vdev_asize == 0 ||
ea65739ebec0cbd625d8c89e19592be58fa186a6chenlu chen - Sun Microsystems - Beijing China vdev_metaslab_init(vd, 0) != 0))
ea65739ebec0cbd625d8c89e19592be58fa186a6chenlu chen - Sun Microsystems - Beijing China vdev_set_state(vd, B_FALSE, VDEV_STATE_CANT_OPEN,
ea65739ebec0cbd625d8c89e19592be58fa186a6chenlu chen - Sun Microsystems - Beijing China VDEV_AUX_CORRUPT_DATA);
9da57d7b0ddd8d73b676ce12c040362132cdd538bt * If this is a leaf vdev, load its DTL.
9da57d7b0ddd8d73b676ce12c040362132cdd538bt if (vd->vdev_ops->vdev_op_leaf && vdev_dtl_load(vd) != 0)
9da57d7b0ddd8d73b676ce12c040362132cdd538bt * The special vdev case is used for hot spares and l2cache devices. Its
9da57d7b0ddd8d73b676ce12c040362132cdd538bt * sole purpose it to set the vdev state for the associated vdev. To do this,
9da57d7b0ddd8d73b676ce12c040362132cdd538bt * we make sure that we can open the underlying device, then try to read the
9da57d7b0ddd8d73b676ce12c040362132cdd538bt * label, and make sure that the label is sane and that it hasn't been
9da57d7b0ddd8d73b676ce12c040362132cdd538bt * repurposed to another pool.
ea65739ebec0cbd625d8c89e19592be58fa186a6chenlu chen - Sun Microsystems - Beijing China if (!vdev_readable(vd))
9da57d7b0ddd8d73b676ce12c040362132cdd538bt return (0);
9da57d7b0ddd8d73b676ce12c040362132cdd538bt if ((label = vdev_label_read_config(vd, -1ULL)) == NULL) {
9da57d7b0ddd8d73b676ce12c040362132cdd538bt return (-1);
9da57d7b0ddd8d73b676ce12c040362132cdd538bt if (nvlist_lookup_uint64(label, ZPOOL_CONFIG_VERSION, &version) != 0 ||
9da57d7b0ddd8d73b676ce12c040362132cdd538bt nvlist_lookup_uint64(label, ZPOOL_CONFIG_GUID, &guid) != 0 ||
9da57d7b0ddd8d73b676ce12c040362132cdd538bt nvlist_lookup_uint64(label, ZPOOL_CONFIG_POOL_STATE, &state) != 0) {
ea65739ebec0cbd625d8c89e19592be58fa186a6chenlu chen - Sun Microsystems - Beijing China vdev_set_state(vd, B_TRUE, VDEV_STATE_CANT_OPEN,
ea65739ebec0cbd625d8c89e19592be58fa186a6chenlu chen - Sun Microsystems - Beijing China VDEV_AUX_CORRUPT_DATA);
9da57d7b0ddd8d73b676ce12c040362132cdd538bt return (-1);
9da57d7b0ddd8d73b676ce12c040362132cdd538bt * We don't actually check the pool state here. If it's in fact in
9da57d7b0ddd8d73b676ce12c040362132cdd538bt * use by another pool, we update this fact on the fly when requested.
ea65739ebec0cbd625d8c89e19592be58fa186a6chenlu chen - Sun Microsystems - Beijing China nvlist_free(label);
ea65739ebec0cbd625d8c89e19592be58fa186a6chenlu chen - Sun Microsystems - Beijing China spa_t *spa = vd->vdev_spa;
ffd8e8832e01f996f32459073f4dd308fe5265baWinson Wang - Sun Microsystems - Beijing China for (int m = 0; m < vd->vdev_ms_count; m++) {
0dc2366f7b9f9f36e10909b1e95edbf2a261c2acVenugopal Iyer * If the metaslab was not loaded when the vdev
9da57d7b0ddd8d73b676ce12c040362132cdd538bt * was removed then the histogram accounting may
73cd555c10e70dac413ae4b40de8450a291750acBin Tu - Sun Microsystems - Beijing China * not be accurate. Update the histogram information
69b5a878d62fdee1b12e78371ce6cc8abddcad15Dan McDonald * here so that we ensure that the metaslab group
69b5a878d62fdee1b12e78371ce6cc8abddcad15Dan McDonald * and metaslab class are up-to-date.
73cd555c10e70dac413ae4b40de8450a291750acBin Tu - Sun Microsystems - Beijing China metaslab_group_histogram_remove(mg, msp);
73cd555c10e70dac413ae4b40de8450a291750acBin Tu - Sun Microsystems - Beijing China msp->ms_sm = NULL;
73cd555c10e70dac413ae4b40de8450a291750acBin Tu - Sun Microsystems - Beijing China mutex_exit(&msp->ms_lock);
73cd555c10e70dac413ae4b40de8450a291750acBin Tu - Sun Microsystems - Beijing China metaslab_group_histogram_verify(mg);
9da57d7b0ddd8d73b676ce12c040362132cdd538bt for (int i = 0; i < RANGE_TREE_HISTOGRAM_SIZE; i++)
73cd555c10e70dac413ae4b40de8450a291750acBin Tu - Sun Microsystems - Beijing China if (vd->vdev_ms_array) {
0dc2366f7b9f9f36e10909b1e95edbf2a261c2acVenugopal Iyer (void) dmu_object_free(mos, vd->vdev_ms_array, tx);
0dc2366f7b9f9f36e10909b1e95edbf2a261c2acVenugopal Iyer boolean_t reassess = !txg_list_empty(&vd->vdev_ms_list, TXG_CLEAN(txg));
0dc2366f7b9f9f36e10909b1e95edbf2a261c2acVenugopal Iyer while (msp = txg_list_remove(&vd->vdev_ms_list, TXG_CLEAN(txg)))
0dc2366f7b9f9f36e10909b1e95edbf2a261c2acVenugopal Iyer if (vd->vdev_ms_array == 0 && vd->vdev_ms_shift != 0) {
0dc2366f7b9f9f36e10909b1e95edbf2a261c2acVenugopal Iyer tx = dmu_tx_create_assigned(spa->spa_dsl_pool, txg);
0dc2366f7b9f9f36e10909b1e95edbf2a261c2acVenugopal Iyer vd->vdev_ms_array = dmu_object_alloc(spa->spa_meta_objset,
73cd555c10e70dac413ae4b40de8450a291750acBin Tu - Sun Microsystems - Beijing China DMU_OT_OBJECT_ARRAY, 0, DMU_OT_NONE, 0, tx);
9da57d7b0ddd8d73b676ce12c040362132cdd538bt * Remove the metadata associated with this vdev once it's empty.
0dc2366f7b9f9f36e10909b1e95edbf2a261c2acVenugopal Iyer while ((msp = txg_list_remove(&vd->vdev_ms_list, txg)) != NULL) {
0dc2366f7b9f9f36e10909b1e95edbf2a261c2acVenugopal Iyer (void) txg_list_add(&vd->vdev_ms_list, msp, TXG_CLEAN(txg));
0dc2366f7b9f9f36e10909b1e95edbf2a261c2acVenugopal Iyer while ((lvd = txg_list_remove(&vd->vdev_dtl_list, txg)) != NULL)
0dc2366f7b9f9f36e10909b1e95edbf2a261c2acVenugopal Iyer (void) txg_list_add(&spa->spa_vdev_txg_list, vd, TXG_CLEAN(txg));
0dc2366f7b9f9f36e10909b1e95edbf2a261c2acVenugopal Iyervdev_psize_to_asize(vdev_t *vd, uint64_t psize)
0dc2366f7b9f9f36e10909b1e95edbf2a261c2acVenugopal Iyer return (vd->vdev_ops->vdev_op_asize(vd, psize));
0dc2366f7b9f9f36e10909b1e95edbf2a261c2acVenugopal Iyer * Mark the given vdev faulted. A faulted vdev behaves as if the device could
0dc2366f7b9f9f36e10909b1e95edbf2a261c2acVenugopal Iyer * not be opened, and no I/O is attempted.
0dc2366f7b9f9f36e10909b1e95edbf2a261c2acVenugopal Iyervdev_fault(spa_t *spa, uint64_t guid, vdev_aux_t aux)
0dc2366f7b9f9f36e10909b1e95edbf2a261c2acVenugopal Iyer if ((vd = spa_lookup_by_guid(spa, guid, B_TRUE)) == NULL)
0dc2366f7b9f9f36e10909b1e95edbf2a261c2acVenugopal Iyer return (spa_vdev_state_exit(spa, NULL, ENODEV));
0dc2366f7b9f9f36e10909b1e95edbf2a261c2acVenugopal Iyer return (spa_vdev_state_exit(spa, NULL, ENOTSUP));
0dc2366f7b9f9f36e10909b1e95edbf2a261c2acVenugopal Iyer * We don't directly use the aux state here, but if we do a
0dc2366f7b9f9f36e10909b1e95edbf2a261c2acVenugopal Iyer * vdev_reopen(), we need this value to be present to remember why we
9da57d7b0ddd8d73b676ce12c040362132cdd538bt * were faulted.
9da57d7b0ddd8d73b676ce12c040362132cdd538bt * Faulted state takes precedence over degraded.
9da57d7b0ddd8d73b676ce12c040362132cdd538bt * If this device has the only valid copy of the data, then
9da57d7b0ddd8d73b676ce12c040362132cdd538bt * back off and simply mark the vdev as degraded instead.
da14cebe459d3275048785f25bd869cb09b5307fEric Cheng if (!tvd->vdev_islog && vd->vdev_aux == NULL && vdev_dtl_required(vd)) {
0dc2366f7b9f9f36e10909b1e95edbf2a261c2acVenugopal Iyer * If we reopen the device and it's not dead, only then do we
0dc2366f7b9f9f36e10909b1e95edbf2a261c2acVenugopal Iyer * mark it degraded.
73cd555c10e70dac413ae4b40de8450a291750acBin Tu - Sun Microsystems - Beijing China return (spa_vdev_state_exit(spa, vd, 0));
9da57d7b0ddd8d73b676ce12c040362132cdd538bt * Mark the given vdev degraded. A degraded vdev is purely an indication to the
9da57d7b0ddd8d73b676ce12c040362132cdd538bt * user that something is wrong. The vdev continues to operate as normal as far
9da57d7b0ddd8d73b676ce12c040362132cdd538bt * as I/O is concerned.
1878b97151eb2746480d8b2139fa08a2e8f14df3Venugopal Iyer if ((vd = spa_lookup_by_guid(spa, guid, B_TRUE)) == NULL)
1878b97151eb2746480d8b2139fa08a2e8f14df3Venugopal Iyer return (spa_vdev_state_exit(spa, NULL, ENODEV));
1878b97151eb2746480d8b2139fa08a2e8f14df3Venugopal Iyer return (spa_vdev_state_exit(spa, NULL, ENOTSUP));
1878b97151eb2746480d8b2139fa08a2e8f14df3Venugopal Iyer * If the vdev is already faulted, then don't do anything.
1878b97151eb2746480d8b2139fa08a2e8f14df3Venugopal Iyer vdev_set_state(vd, B_FALSE, VDEV_STATE_DEGRADED,
1878b97151eb2746480d8b2139fa08a2e8f14df3Venugopal Iyer * Online the given vdev.
1878b97151eb2746480d8b2139fa08a2e8f14df3Venugopal Iyer * If 'ZFS_ONLINE_UNSPARE' is set, it implies two things. First, any attached
1878b97151eb2746480d8b2139fa08a2e8f14df3Venugopal Iyer * spare device should be detached when the device finishes resilvering.
1878b97151eb2746480d8b2139fa08a2e8f14df3Venugopal Iyer * Second, the online should be treated like a 'test' online case, so no FMA
19843f01b1bef3453f717c23c8f89fb9313f6749Paul Guo * events are generated if the device fails to open.
1878b97151eb2746480d8b2139fa08a2e8f14df3Venugopal Iyervdev_online(spa_t *spa, uint64_t guid, uint64_t flags, vdev_state_t *newstate)
9da57d7b0ddd8d73b676ce12c040362132cdd538bt if ((vd = spa_lookup_by_guid(spa, guid, B_TRUE)) == NULL)
9da57d7b0ddd8d73b676ce12c040362132cdd538bt vd->vdev_checkremove = !!(flags & ZFS_ONLINE_CHECKREMOVE);
9da57d7b0ddd8d73b676ce12c040362132cdd538bt /* XXX - L2ARC 1.0 does not support expansion */
9da57d7b0ddd8d73b676ce12c040362132cdd538bt if ((flags & ZFS_ONLINE_EXPAND) || spa->spa_autoexpand) {
9da57d7b0ddd8d73b676ce12c040362132cdd538bt /* XXX - L2ARC 1.0 does not support expansion */
9da57d7b0ddd8d73b676ce12c040362132cdd538btvdev_offline_locked(spa_t *spa, uint64_t guid, uint64_t flags)
9da57d7b0ddd8d73b676ce12c040362132cdd538bt if ((vd = spa_lookup_by_guid(spa, guid, B_TRUE)) == NULL)
69b5a878d62fdee1b12e78371ce6cc8abddcad15Dan McDonald return (spa_vdev_state_exit(spa, NULL, ENOTSUP));
69b5a878d62fdee1b12e78371ce6cc8abddcad15Dan McDonald * If the device isn't already offline, try to offline it.
9da57d7b0ddd8d73b676ce12c040362132cdd538bt * If this device has the only valid copy of some data,
9da57d7b0ddd8d73b676ce12c040362132cdd538bt * don't allow it to be offlined. Log devices are always
9da57d7b0ddd8d73b676ce12c040362132cdd538bt * expendable.
9da57d7b0ddd8d73b676ce12c040362132cdd538bt * If the top-level is a slog and it has had allocations
9da57d7b0ddd8d73b676ce12c040362132cdd538bt * then proceed. We check that the vdev's metaslab group
9da57d7b0ddd8d73b676ce12c040362132cdd538bt * is not NULL since it's possible that we may have just
9da57d7b0ddd8d73b676ce12c040362132cdd538bt * added this vdev but not yet initialized its metaslabs.
9da57d7b0ddd8d73b676ce12c040362132cdd538bt * Prevent any future allocations.
da14cebe459d3275048785f25bd869cb09b5307fEric Cheng * Check to see if the config has changed.
da14cebe459d3275048785f25bd869cb09b5307fEric Cheng * Offline this device and reopen its top-level vdev.
5b6dd21f5401160f9a62ac2e76a858c2bc105370chenlu chen - Sun Microsystems - Beijing China * If the top-level vdev is a log device then just offline
5b6dd21f5401160f9a62ac2e76a858c2bc105370chenlu chen - Sun Microsystems - Beijing China * it. Otherwise, if this action results in the top-level
73cd555c10e70dac413ae4b40de8450a291750acBin Tu - Sun Microsystems - Beijing China * vdev becoming unusable, undo it and fail the request.
5b6dd21f5401160f9a62ac2e76a858c2bc105370chenlu chen - Sun Microsystems - Beijing China vd->vdev_offline = B_TRUE;
5b6dd21f5401160f9a62ac2e76a858c2bc105370chenlu chen - Sun Microsystems - Beijing China vdev_reopen(tvd);
69b5a878d62fdee1b12e78371ce6cc8abddcad15Dan McDonald if (!tvd->vdev_islog && vd->vdev_aux == NULL &&
5b6dd21f5401160f9a62ac2e76a858c2bc105370chenlu chen - Sun Microsystems - Beijing China vdev_is_dead(tvd)) {
5b6dd21f5401160f9a62ac2e76a858c2bc105370chenlu chen - Sun Microsystems - Beijing China vd->vdev_offline = B_FALSE;
5b6dd21f5401160f9a62ac2e76a858c2bc105370chenlu chen - Sun Microsystems - Beijing China vdev_reopen(tvd);
5b6dd21f5401160f9a62ac2e76a858c2bc105370chenlu chen - Sun Microsystems - Beijing China return (spa_vdev_state_exit(spa, NULL, EBUSY));
5b6dd21f5401160f9a62ac2e76a858c2bc105370chenlu chen - Sun Microsystems - Beijing China * Add the device back into the metaslab rotor so that
da14cebe459d3275048785f25bd869cb09b5307fEric Cheng * once we online the device it's open for business.
5b6dd21f5401160f9a62ac2e76a858c2bc105370chenlu chen - Sun Microsystems - Beijing China metaslab_group_activate(mg);
73cd555c10e70dac413ae4b40de8450a291750acBin Tu - Sun Microsystems - Beijing China vd->vdev_tmpoffline = !!(flags & ZFS_OFFLINE_TEMPORARY);
5b6dd21f5401160f9a62ac2e76a858c2bc105370chenlu chen - Sun Microsystems - Beijing China return (spa_vdev_state_exit(spa, vd, 0));
5b6dd21f5401160f9a62ac2e76a858c2bc105370chenlu chen - Sun Microsystems - Beijing Chinavdev_offline(spa_t *spa, uint64_t guid, uint64_t flags)
73cd555c10e70dac413ae4b40de8450a291750acBin Tu - Sun Microsystems - Beijing China mutex_enter(&spa->spa_vdev_top_lock);
5b6dd21f5401160f9a62ac2e76a858c2bc105370chenlu chen - Sun Microsystems - Beijing China error = vdev_offline_locked(spa, guid, flags);
c971fb7ec0a19c6cd00c5614a94c97f953b6e8b1gg * Clear the error counts associated with this vdev. Unlike vdev_online() and
73cd555c10e70dac413ae4b40de8450a291750acBin Tu - Sun Microsystems - Beijing China * vdev_offline(), we assume the spa config is locked. We also clear all
73cd555c10e70dac413ae4b40de8450a291750acBin Tu - Sun Microsystems - Beijing China * children. If 'vd' is NULL, then the user wants to clear all vdevs.
73cd555c10e70dac413ae4b40de8450a291750acBin Tu - Sun Microsystems - Beijing China ASSERT(spa_config_held(spa, SCL_STATE_ALL, RW_WRITER) == SCL_STATE_ALL);
73cd555c10e70dac413ae4b40de8450a291750acBin Tu - Sun Microsystems - Beijing China vdev_clear(spa, vd->vdev_child[c]);
73cd555c10e70dac413ae4b40de8450a291750acBin Tu - Sun Microsystems - Beijing China * If we're in the FAULTED state or have experienced failed I/O, then
73cd555c10e70dac413ae4b40de8450a291750acBin Tu - Sun Microsystems - Beijing China * clear the persistent state and attempt to reopen the device. We
73cd555c10e70dac413ae4b40de8450a291750acBin Tu - Sun Microsystems - Beijing China * also mark the vdev config dirty, so that the new faulted state is
73cd555c10e70dac413ae4b40de8450a291750acBin Tu - Sun Microsystems - Beijing China * written out to disk.
73cd555c10e70dac413ae4b40de8450a291750acBin Tu - Sun Microsystems - Beijing China if (vd->vdev_faulted || vd->vdev_degraded ||
73cd555c10e70dac413ae4b40de8450a291750acBin Tu - Sun Microsystems - Beijing China !vdev_readable(vd) || !vdev_writeable(vd)) {
9da57d7b0ddd8d73b676ce12c040362132cdd538bt * When reopening in reponse to a clear event, it may be due to
9da57d7b0ddd8d73b676ce12c040362132cdd538bt * a fmadm repair request. In this case, if the device is
9da57d7b0ddd8d73b676ce12c040362132cdd538bt * still broken, we want to still post the ereport again.
9da57d7b0ddd8d73b676ce12c040362132cdd538bt * When clearing a FMA-diagnosed fault, we always want to
9da57d7b0ddd8d73b676ce12c040362132cdd538bt * unspare the device, as we assume that the original spare was
9da57d7b0ddd8d73b676ce12c040362132cdd538bt * done in response to the FMA fault.
9da57d7b0ddd8d73b676ce12c040362132cdd538bt * Holes and missing devices are always considered "dead".
9da57d7b0ddd8d73b676ce12c040362132cdd538bt * This simplifies the code since we don't have to check for
9da57d7b0ddd8d73b676ce12c040362132cdd538bt * these types of devices in the various code paths.
9da57d7b0ddd8d73b676ce12c040362132cdd538bt * Instead we rely on the fact that we skip over dead devices
9da57d7b0ddd8d73b676ce12c040362132cdd538bt * before issuing I/O to them.
9da57d7b0ddd8d73b676ce12c040362132cdd538bt return (vd->vdev_state < VDEV_STATE_DEGRADED || vd->vdev_ishole ||
0dc2366f7b9f9f36e10909b1e95edbf2a261c2acVenugopal Iyer * We currently allow allocations from vdevs which may be in the
0dc2366f7b9f9f36e10909b1e95edbf2a261c2acVenugopal Iyer * process of reopening (i.e. VDEV_STATE_CLOSED). If the device
0dc2366f7b9f9f36e10909b1e95edbf2a261c2acVenugopal Iyer * fails to reopen then we'll catch it later when we're holding
0dc2366f7b9f9f36e10909b1e95edbf2a261c2acVenugopal Iyer * the proper locks. Note that we have to get the vdev state
0dc2366f7b9f9f36e10909b1e95edbf2a261c2acVenugopal Iyer * in a local variable because although it changes atomically,
0dc2366f7b9f9f36e10909b1e95edbf2a261c2acVenugopal Iyer * we're asking two separate questions about it.
0dc2366f7b9f9f36e10909b1e95edbf2a261c2acVenugopal Iyer return (!(state < VDEV_STATE_DEGRADED && state != VDEV_STATE_CLOSED) &&
0dc2366f7b9f9f36e10909b1e95edbf2a261c2acVenugopal Iyer if (vdev_is_dead(vd) || vd->vdev_remove_wanted)
0dc2366f7b9f9f36e10909b1e95edbf2a261c2acVenugopal Iyer * Get statistics for the given vdev.
0dc2366f7b9f9f36e10909b1e95edbf2a261c2acVenugopal Iyer ASSERT(spa_config_held(spa, SCL_ALL, RW_READER) != 0);
0dc2366f7b9f9f36e10909b1e95edbf2a261c2acVenugopal Iyer vs->vs_timestamp = gethrtime() - vs->vs_timestamp;
0dc2366f7b9f9f36e10909b1e95edbf2a261c2acVenugopal Iyer vs->vs_rsize += VDEV_LABEL_START_SIZE + VDEV_LABEL_END_SIZE;
0dc2366f7b9f9f36e10909b1e95edbf2a261c2acVenugopal Iyer vs->vs_esize = vd->vdev_max_asize - vd->vdev_asize;
0dc2366f7b9f9f36e10909b1e95edbf2a261c2acVenugopal Iyer if (vd->vdev_aux == NULL && vd == vd->vdev_top)
0dc2366f7b9f9f36e10909b1e95edbf2a261c2acVenugopal Iyer vs->vs_fragmentation = vd->vdev_mg->mg_fragmentation;
0dc2366f7b9f9f36e10909b1e95edbf2a261c2acVenugopal Iyer * If we're getting stats on the root vdev, aggregate the I/O counts
0dc2366f7b9f9f36e10909b1e95edbf2a261c2acVenugopal Iyer * over all top-level vdevs (i.e. the direct children of the root).
0dc2366f7b9f9f36e10909b1e95edbf2a261c2acVenugopal Iyer for (int c = 0; c < rvd->vdev_children; c++) {
0dc2366f7b9f9f36e10909b1e95edbf2a261c2acVenugopal Iyer for (int t = 0; t < ZIO_TYPES; t++) {
0dc2366f7b9f9f36e10909b1e95edbf2a261c2acVenugopal Iyer * If this i/o is a gang leader, it didn't do any actual work.
0dc2366f7b9f9f36e10909b1e95edbf2a261c2acVenugopal Iyer * If this is a root i/o, don't count it -- we've already
0dc2366f7b9f9f36e10909b1e95edbf2a261c2acVenugopal Iyer * counted the top-level vdevs, and vdev_get_stats() will
0dc2366f7b9f9f36e10909b1e95edbf2a261c2acVenugopal Iyer * aggregate them when asked. This reduces contention on
69b5a878d62fdee1b12e78371ce6cc8abddcad15Dan McDonald * the root vdev_stat_lock and implicitly handles blocks
0dc2366f7b9f9f36e10909b1e95edbf2a261c2acVenugopal Iyer * that compress away to holes, for which there is no i/o.
0dc2366f7b9f9f36e10909b1e95edbf2a261c2acVenugopal Iyer * (Holes never create vdev children, so all the counters
0dc2366f7b9f9f36e10909b1e95edbf2a261c2acVenugopal Iyer * remain zero, which is what we want.)
0dc2366f7b9f9f36e10909b1e95edbf2a261c2acVenugopal Iyer * Note: this only applies to successful i/o (io_error == 0)
0dc2366f7b9f9f36e10909b1e95edbf2a261c2acVenugopal Iyer * because unlike i/o counts, errors are not additive.
0dc2366f7b9f9f36e10909b1e95edbf2a261c2acVenugopal Iyer * When reading a ditto block, for example, failure of
0dc2366f7b9f9f36e10909b1e95edbf2a261c2acVenugopal Iyer * one top-level vdev does not imply a root-level error.
0dc2366f7b9f9f36e10909b1e95edbf2a261c2acVenugopal Iyer uint64_t *processed = &scn_phys->scn_processed;
0dc2366f7b9f9f36e10909b1e95edbf2a261c2acVenugopal Iyer /* XXX cleanup? */
69b5a878d62fdee1b12e78371ce6cc8abddcad15Dan McDonald * If this is an I/O error that is going to be retried, then ignore the
0dc2366f7b9f9f36e10909b1e95edbf2a261c2acVenugopal Iyer * error. Otherwise, the user may interpret B_FAILFAST I/O errors as
0dc2366f7b9f9f36e10909b1e95edbf2a261c2acVenugopal Iyer * hard errors, when in reality they can happen for any number of
0dc2366f7b9f9f36e10909b1e95edbf2a261c2acVenugopal Iyer * innocuous reasons (bus resets, MPxIO link failure, etc).
0dc2366f7b9f9f36e10909b1e95edbf2a261c2acVenugopal Iyer * Intent logs writes won't propagate their error to the root
0dc2366f7b9f9f36e10909b1e95edbf2a261c2acVenugopal Iyer * I/O so don't mark these types of failures as pool-level
0dc2366f7b9f9f36e10909b1e95edbf2a261c2acVenugopal Iyer if (zio->io_vd == NULL && (zio->io_flags & ZIO_FLAG_DONT_PROPAGATE))
9da57d7b0ddd8d73b676ce12c040362132cdd538bt * This is either a normal write (not a repair), or it's
9da57d7b0ddd8d73b676ce12c040362132cdd538bt * a repair induced by the scrub thread, or it's a repair
9da57d7b0ddd8d73b676ce12c040362132cdd538bt * made by zil_claim() during spa_load() in the first txg.
9da57d7b0ddd8d73b676ce12c040362132cdd538bt * In the normal case, we commit the DTL change in the same
9da57d7b0ddd8d73b676ce12c040362132cdd538bt * txg as the block was born. In the scrub-induced repair
0dc2366f7b9f9f36e10909b1e95edbf2a261c2acVenugopal Iyer * case, we know that scrubs run in first-pass syncing context,
da14cebe459d3275048785f25bd869cb09b5307fEric Cheng * so we commit the DTL change in spa_syncing_txg(spa).
da14cebe459d3275048785f25bd869cb09b5307fEric Cheng * In the zil_claim() case, we commit in spa_first_txg(spa).
da14cebe459d3275048785f25bd869cb09b5307fEric Cheng * We currently do not make DTL entries for failed spontaneous
da14cebe459d3275048785f25bd869cb09b5307fEric Cheng * self-healing writes triggered by normal (non-scrubbing)
9da57d7b0ddd8d73b676ce12c040362132cdd538bt * reads, because we have no transactional context in which to
da14cebe459d3275048785f25bd869cb09b5307fEric Cheng * do so -- and it's not clear that it'd be desirable anyway.
da14cebe459d3275048785f25bd869cb09b5307fEric Cheng vdev_dirty(vd->vdev_top, VDD_DTL, vd, commit_txg);
da14cebe459d3275048785f25bd869cb09b5307fEric Cheng * Update the in-core space usage stats for this vdev, its metaslab class,
da14cebe459d3275048785f25bd869cb09b5307fEric Cheng * and the root vdev.
da14cebe459d3275048785f25bd869cb09b5307fEric Chengvdev_space_update(vdev_t *vd, int64_t alloc_delta, int64_t defer_delta,
9da57d7b0ddd8d73b676ce12c040362132cdd538bt * Apply the inverse of the psize-to-asize (ie. RAID-Z) space-expansion
9da57d7b0ddd8d73b676ce12c040362132cdd538bt * factor. We must calculate this here and not at the root vdev
9da57d7b0ddd8d73b676ce12c040362132cdd538bt * because the root vdev's psize-to-asize is simply the max of its
9da57d7b0ddd8d73b676ce12c040362132cdd538bt * childrens', thus not accurate enough for us.
9da57d7b0ddd8d73b676ce12c040362132cdd538bt ASSERT(vd->vdev_deflate_ratio != 0 || vd->vdev_isl2cache);
9da57d7b0ddd8d73b676ce12c040362132cdd538bt * Mark a top-level vdev's config as dirty, placing it on the dirty list
9da57d7b0ddd8d73b676ce12c040362132cdd538bt * so that it will be written out next time the vdev configuration is synced.
9da57d7b0ddd8d73b676ce12c040362132cdd538bt * If the root vdev is specified (vdev_top == NULL), dirty all top-level vdevs.
9da57d7b0ddd8d73b676ce12c040362132cdd538bt * If this is an aux vdev (as with l2cache and spare devices), then we
9da57d7b0ddd8d73b676ce12c040362132cdd538bt * update the vdev config manually and set the sync flag.
9da57d7b0ddd8d73b676ce12c040362132cdd538bt * We're being removed. There's nothing more to do.
9da57d7b0ddd8d73b676ce12c040362132cdd538bt * Setting the nvlist in the middle if the array is a little
9da57d7b0ddd8d73b676ce12c040362132cdd538bt * sketchy, but it will work.
9da57d7b0ddd8d73b676ce12c040362132cdd538bt * The dirty list is protected by the SCL_CONFIG lock. The caller
0dc2366f7b9f9f36e10909b1e95edbf2a261c2acVenugopal Iyer * must either hold SCL_CONFIG as writer, or must be the sync thread
0dc2366f7b9f9f36e10909b1e95edbf2a261c2acVenugopal Iyer * (which holds SCL_CONFIG as reader). There's only one sync thread,
0dc2366f7b9f9f36e10909b1e95edbf2a261c2acVenugopal Iyer * so this is sufficient to ensure mutual exclusion.
0dc2366f7b9f9f36e10909b1e95edbf2a261c2acVenugopal Iyer ASSERT(spa_config_held(spa, SCL_CONFIG, RW_WRITER) ||
0dc2366f7b9f9f36e10909b1e95edbf2a261c2acVenugopal Iyer spa_config_held(spa, SCL_CONFIG, RW_READER)));
0dc2366f7b9f9f36e10909b1e95edbf2a261c2acVenugopal Iyer if (!list_link_active(&vd->vdev_config_dirty_node) &&
0dc2366f7b9f9f36e10909b1e95edbf2a261c2acVenugopal Iyer list_insert_head(&spa->spa_config_dirty_list, vd);
0dc2366f7b9f9f36e10909b1e95edbf2a261c2acVenugopal Iyer ASSERT(spa_config_held(spa, SCL_CONFIG, RW_WRITER) ||
0dc2366f7b9f9f36e10909b1e95edbf2a261c2acVenugopal Iyer spa_config_held(spa, SCL_CONFIG, RW_READER)));
0dc2366f7b9f9f36e10909b1e95edbf2a261c2acVenugopal Iyer ASSERT(list_link_active(&vd->vdev_config_dirty_node));
0dc2366f7b9f9f36e10909b1e95edbf2a261c2acVenugopal Iyer list_remove(&spa->spa_config_dirty_list, vd);
0dc2366f7b9f9f36e10909b1e95edbf2a261c2acVenugopal Iyer * Mark a top-level vdev's state as dirty, so that the next pass of
0dc2366f7b9f9f36e10909b1e95edbf2a261c2acVenugopal Iyer * spa_sync() can convert this into vdev_config_dirty(). We distinguish
0dc2366f7b9f9f36e10909b1e95edbf2a261c2acVenugopal Iyer * the state changes from larger config changes because they require
0dc2366f7b9f9f36e10909b1e95edbf2a261c2acVenugopal Iyer * much less locking, and are often needed for administrative actions.
0dc2366f7b9f9f36e10909b1e95edbf2a261c2acVenugopal Iyer * The state list is protected by the SCL_STATE lock. The caller
0dc2366f7b9f9f36e10909b1e95edbf2a261c2acVenugopal Iyer * must either hold SCL_STATE as writer, or must be the sync thread
0dc2366f7b9f9f36e10909b1e95edbf2a261c2acVenugopal Iyer * (which holds SCL_STATE as reader). There's only one sync thread,
0dc2366f7b9f9f36e10909b1e95edbf2a261c2acVenugopal Iyer * so this is sufficient to ensure mutual exclusion.
0dc2366f7b9f9f36e10909b1e95edbf2a261c2acVenugopal Iyer ASSERT(spa_config_held(spa, SCL_STATE, RW_WRITER) ||
0dc2366f7b9f9f36e10909b1e95edbf2a261c2acVenugopal Iyer spa_config_held(spa, SCL_STATE, RW_READER)));
0dc2366f7b9f9f36e10909b1e95edbf2a261c2acVenugopal Iyer if (!list_link_active(&vd->vdev_state_dirty_node) && !vd->vdev_ishole)
0dc2366f7b9f9f36e10909b1e95edbf2a261c2acVenugopal Iyer list_insert_head(&spa->spa_state_dirty_list, vd);
0dc2366f7b9f9f36e10909b1e95edbf2a261c2acVenugopal Iyer ASSERT(spa_config_held(spa, SCL_STATE, RW_WRITER) ||
0dc2366f7b9f9f36e10909b1e95edbf2a261c2acVenugopal Iyer spa_config_held(spa, SCL_STATE, RW_READER)));
0dc2366f7b9f9f36e10909b1e95edbf2a261c2acVenugopal Iyer ASSERT(list_link_active(&vd->vdev_state_dirty_node));
0dc2366f7b9f9f36e10909b1e95edbf2a261c2acVenugopal Iyer * Propagate vdev state up from children to parent.
9da57d7b0ddd8d73b676ce12c040362132cdd538bt * Don't factor holes into the decision.
9da57d7b0ddd8d73b676ce12c040362132cdd538bt * Root special: if there is a top-level log
9da57d7b0ddd8d73b676ce12c040362132cdd538bt * device, treat the root vdev as if it were
9da57d7b0ddd8d73b676ce12c040362132cdd538bt * degraded.
9da57d7b0ddd8d73b676ce12c040362132cdd538bt vd->vdev_ops->vdev_op_state_change(vd, faulted, degraded);
9da57d7b0ddd8d73b676ce12c040362132cdd538bt * Root special: if there is a top-level vdev that cannot be
9da57d7b0ddd8d73b676ce12c040362132cdd538bt * opened due to corrupted metadata, then propagate the root
1fedc51fe8f78efa2ee550387171e6adb2223b8dWinson Wang - Sun Microsystems - Beijing China * vdev's aux state as 'corrupt' rather than 'insufficient
9da57d7b0ddd8d73b676ce12c040362132cdd538bt * replicas'.
73cd555c10e70dac413ae4b40de8450a291750acBin Tu - Sun Microsystems - Beijing China * Set a vdev's state. If this is during an open, we don't update the parent
73cd555c10e70dac413ae4b40de8450a291750acBin Tu - Sun Microsystems - Beijing China * state, because we're in the process of opening children depth-first.
73cd555c10e70dac413ae4b40de8450a291750acBin Tu - Sun Microsystems - Beijing China * Otherwise, we propagate the change to the parent.
9da57d7b0ddd8d73b676ce12c040362132cdd538bt * If this routine places a device in a faulted state, an appropriate ereport is
9da57d7b0ddd8d73b676ce12c040362132cdd538bt * generated.
9da57d7b0ddd8d73b676ce12c040362132cdd538btvdev_set_state(vdev_t *vd, boolean_t isopen, vdev_state_t state, vdev_aux_t aux)
da14cebe459d3275048785f25bd869cb09b5307fEric Cheng * If we are setting the vdev state to anything but an open state, then
da14cebe459d3275048785f25bd869cb09b5307fEric Cheng * always close the underlying device unless the device has requested
0dc2366f7b9f9f36e10909b1e95edbf2a261c2acVenugopal Iyer * a delayed close (i.e. we're about to remove or fault the device).
0dc2366f7b9f9f36e10909b1e95edbf2a261c2acVenugopal Iyer * Otherwise, we keep accessible but invalid devices open forever.
da14cebe459d3275048785f25bd869cb09b5307fEric Cheng * We don't call vdev_close() itself, because that implies some extra
da14cebe459d3275048785f25bd869cb09b5307fEric Cheng * checks (offline, etc) that we don't want here. This is limited to
da14cebe459d3275048785f25bd869cb09b5307fEric Cheng * leaf devices, because otherwise closing the device will affect other
da14cebe459d3275048785f25bd869cb09b5307fEric Cheng if (!vd->vdev_delayed_close && vdev_is_dead(vd) &&
0dc2366f7b9f9f36e10909b1e95edbf2a261c2acVenugopal Iyer * If we have brought this vdev back into service, we need
0dc2366f7b9f9f36e10909b1e95edbf2a261c2acVenugopal Iyer * to notify fmd so that it can gracefully repair any outstanding
0dc2366f7b9f9f36e10909b1e95edbf2a261c2acVenugopal Iyer * cases due to a missing device. We do this in all cases, even those
0dc2366f7b9f9f36e10909b1e95edbf2a261c2acVenugopal Iyer * that probably don't correlate to a repaired fault. This is sure to
0dc2366f7b9f9f36e10909b1e95edbf2a261c2acVenugopal Iyer * catch all cases, and we let the zfs-retire agent sort it out. If
0dc2366f7b9f9f36e10909b1e95edbf2a261c2acVenugopal Iyer * this is a transient state it's OK, as the retire agent will
0dc2366f7b9f9f36e10909b1e95edbf2a261c2acVenugopal Iyer * double-check the state of the vdev before repairing it.
da14cebe459d3275048785f25bd869cb09b5307fEric Cheng if (state == VDEV_STATE_HEALTHY && vd->vdev_ops->vdev_op_leaf &&
da14cebe459d3275048785f25bd869cb09b5307fEric Cheng (aux == VDEV_AUX_OPEN_FAILED || vd->vdev_checkremove)) {
9da57d7b0ddd8d73b676ce12c040362132cdd538bt * If the previous state is set to VDEV_STATE_REMOVED, then this
9da57d7b0ddd8d73b676ce12c040362132cdd538bt * device was previously marked removed and someone attempted to
9da57d7b0ddd8d73b676ce12c040362132cdd538bt * reopen it. If this failed due to a nonexistent device, then
9da57d7b0ddd8d73b676ce12c040362132cdd538bt * keep the device in the REMOVED state. We also let this be if
9da57d7b0ddd8d73b676ce12c040362132cdd538bt * it is one of our special test online cases, which is only
9da57d7b0ddd8d73b676ce12c040362132cdd538bt * attempting to online the device and shouldn't generate an FMA
ffd8e8832e01f996f32459073f4dd308fe5265baWinson Wang - Sun Microsystems - Beijing China vd->vdev_removed = B_TRUE;
ffd8e8832e01f996f32459073f4dd308fe5265baWinson Wang - Sun Microsystems - Beijing China } else if (state == VDEV_STATE_CANT_OPEN) {
c971fb7ec0a19c6cd00c5614a94c97f953b6e8b1gg * If we fail to open a vdev during an import or recovery, we
5b6dd21f5401160f9a62ac2e76a858c2bc105370chenlu chen - Sun Microsystems - Beijing China * mark it as "not available", which signifies that it was
5b6dd21f5401160f9a62ac2e76a858c2bc105370chenlu chen - Sun Microsystems - Beijing China * never there to begin with. Failure to open such a device
c971fb7ec0a19c6cd00c5614a94c97f953b6e8b1gg * is not considered an error.
73cd555c10e70dac413ae4b40de8450a291750acBin Tu - Sun Microsystems - Beijing China vd->vdev_ops->vdev_op_leaf)
73cd555c10e70dac413ae4b40de8450a291750acBin Tu - Sun Microsystems - Beijing China vd->vdev_not_present = 1;
c971fb7ec0a19c6cd00c5614a94c97f953b6e8b1gg * Post the appropriate ereport. If the 'prevstate' field is
c971fb7ec0a19c6cd00c5614a94c97f953b6e8b1gg * set to something other than VDEV_STATE_UNKNOWN, it indicates
c971fb7ec0a19c6cd00c5614a94c97f953b6e8b1gg * that this is part of a vdev_reopen(). In this case, we don't
c971fb7ec0a19c6cd00c5614a94c97f953b6e8b1gg * want to post the ereport if the device was already in the
c971fb7ec0a19c6cd00c5614a94c97f953b6e8b1gg * CANT_OPEN state beforehand.
c971fb7ec0a19c6cd00c5614a94c97f953b6e8b1gg * If the 'checkremove' flag is set, then this is an attempt to
9da57d7b0ddd8d73b676ce12c040362132cdd538bt * online the device in response to an insertion event. If we
ffd8e8832e01f996f32459073f4dd308fe5265baWinson Wang - Sun Microsystems - Beijing China * hit this case, then we have detected an insertion event for a
ffd8e8832e01f996f32459073f4dd308fe5265baWinson Wang - Sun Microsystems - Beijing China * faulted or offline device that wasn't in the removed state.
ffd8e8832e01f996f32459073f4dd308fe5265baWinson Wang - Sun Microsystems - Beijing China * In this scenario, we don't post an ereport because we are
ffd8e8832e01f996f32459073f4dd308fe5265baWinson Wang - Sun Microsystems - Beijing China * about to replace the device, or attempt an online with
ffd8e8832e01f996f32459073f4dd308fe5265baWinson Wang - Sun Microsystems - Beijing China * vdev_forcefault, which will generate the fault for us.
ffd8e8832e01f996f32459073f4dd308fe5265baWinson Wang - Sun Microsystems - Beijing China if ((vd->vdev_prevstate != state || vd->vdev_forcefault) &&
ffd8e8832e01f996f32459073f4dd308fe5265baWinson Wang - Sun Microsystems - Beijing China !vd->vdev_not_present && !vd->vdev_checkremove &&
ffd8e8832e01f996f32459073f4dd308fe5265baWinson Wang - Sun Microsystems - Beijing China vd != spa->spa_root_vdev) {
ffd8e8832e01f996f32459073f4dd308fe5265baWinson Wang - Sun Microsystems - Beijing China const char *class;
ffd8e8832e01f996f32459073f4dd308fe5265baWinson Wang - Sun Microsystems - Beijing China switch (aux) {
ffd8e8832e01f996f32459073f4dd308fe5265baWinson Wang - Sun Microsystems - Beijing China class = FM_EREPORT_ZFS_DEVICE_OPEN_FAILED;
ea65739ebec0cbd625d8c89e19592be58fa186a6chenlu chen - Sun Microsystems - Beijing China /* Erase any notion of persistent removed state */
ea65739ebec0cbd625d8c89e19592be58fa186a6chenlu chen - Sun Microsystems - Beijing China vd->vdev_removed = B_FALSE;
73cd555c10e70dac413ae4b40de8450a291750acBin Tu - Sun Microsystems - Beijing China if (!isopen && vd->vdev_parent)
43fab1a9f38ff02e665a874ea0a8eb3818e61ff3Saso Kiselkov * Check the vdev configuration to ensure that it's capable of supporting
ea65739ebec0cbd625d8c89e19592be58fa186a6chenlu chen - Sun Microsystems - Beijing China * a root pool. Currently, we do not support RAID-Z or partial configuration.
185c5677613512bc5a906decb5034a5135f67fb1Paul Guo * In addition, only a single top-level vdev is allowed and none of the leaves
ea65739ebec0cbd625d8c89e19592be58fa186a6chenlu chen - Sun Microsystems - Beijing China * can be wholedisks.
ea65739ebec0cbd625d8c89e19592be58fa186a6chenlu chen - Sun Microsystems - Beijing Chinavdev_is_bootable(vdev_t *vd)
ea65739ebec0cbd625d8c89e19592be58fa186a6chenlu chen - Sun Microsystems - Beijing China if (!vd->vdev_ops->vdev_op_leaf) {
ea65739ebec0cbd625d8c89e19592be58fa186a6chenlu chen - Sun Microsystems - Beijing China char *vdev_type = vd->vdev_ops->vdev_op_type;
ea65739ebec0cbd625d8c89e19592be58fa186a6chenlu chen - Sun Microsystems - Beijing China if (strcmp(vdev_type, VDEV_TYPE_ROOT) == 0 &&
ea65739ebec0cbd625d8c89e19592be58fa186a6chenlu chen - Sun Microsystems - Beijing China vd->vdev_children > 1) {
ea65739ebec0cbd625d8c89e19592be58fa186a6chenlu chen - Sun Microsystems - Beijing China return (B_FALSE);
ea65739ebec0cbd625d8c89e19592be58fa186a6chenlu chen - Sun Microsystems - Beijing China } else if (strcmp(vdev_type, VDEV_TYPE_RAIDZ) == 0 ||
ea65739ebec0cbd625d8c89e19592be58fa186a6chenlu chen - Sun Microsystems - Beijing China strcmp(vdev_type, VDEV_TYPE_MISSING) == 0) {
ea65739ebec0cbd625d8c89e19592be58fa186a6chenlu chen - Sun Microsystems - Beijing China return (B_FALSE);
ea65739ebec0cbd625d8c89e19592be58fa186a6chenlu chen - Sun Microsystems - Beijing China } else if (vd->vdev_wholedisk == 1) {
ea65739ebec0cbd625d8c89e19592be58fa186a6chenlu chen - Sun Microsystems - Beijing China return (B_FALSE);
ea65739ebec0cbd625d8c89e19592be58fa186a6chenlu chen - Sun Microsystems - Beijing China for (int c = 0; c < vd->vdev_children; c++) {
ea65739ebec0cbd625d8c89e19592be58fa186a6chenlu chen - Sun Microsystems - Beijing China if (!vdev_is_bootable(vd->vdev_child[c]))
ea65739ebec0cbd625d8c89e19592be58fa186a6chenlu chen - Sun Microsystems - Beijing China return (B_FALSE);
ea65739ebec0cbd625d8c89e19592be58fa186a6chenlu chen - Sun Microsystems - Beijing China return (B_TRUE);
9da57d7b0ddd8d73b676ce12c040362132cdd538bt * Load the state from the original vdev tree (ovd) which
9da57d7b0ddd8d73b676ce12c040362132cdd538bt * we've retrieved from the MOS config object. If the original
9da57d7b0ddd8d73b676ce12c040362132cdd538bt * vdev was offline or faulted then we transfer that state to the
9da57d7b0ddd8d73b676ce12c040362132cdd538bt * device in the current vdev tree (nvd).
9da57d7b0ddd8d73b676ce12c040362132cdd538bt ASSERT(spa_config_held(spa, SCL_STATE_ALL, RW_WRITER) == SCL_STATE_ALL);
9da57d7b0ddd8d73b676ce12c040362132cdd538bt vdev_load_log_state(nvd->vdev_child[c], ovd->vdev_child[c]);
9da57d7b0ddd8d73b676ce12c040362132cdd538bt * Restore the persistent vdev state
9da57d7b0ddd8d73b676ce12c040362132cdd538bt * Determine if a log device has valid content. If the vdev was
9da57d7b0ddd8d73b676ce12c040362132cdd538bt * removed or faulted in the MOS config then we know that
9da57d7b0ddd8d73b676ce12c040362132cdd538bt * the content on the log device has already been written to the pool.
3cfa0eb9019abbded0c93bce072ab4e73b989c13chenlu chen - Sun Microsystems - Beijing China for (int c = 0; c < vd->vdev_children; c++)
3cfa0eb9019abbded0c93bce072ab4e73b989c13chenlu chen - Sun Microsystems - Beijing China return (B_TRUE);
3cfa0eb9019abbded0c93bce072ab4e73b989c13chenlu chen - Sun Microsystems - Beijing China return (B_FALSE);
3cfa0eb9019abbded0c93bce072ab4e73b989c13chenlu chen - Sun Microsystems - Beijing China * Expand a vdev if possible.
3cfa0eb9019abbded0c93bce072ab4e73b989c13chenlu chen - Sun Microsystems - Beijing Chinavdev_expand(vdev_t *vd, uint64_t txg)
3cfa0eb9019abbded0c93bce072ab4e73b989c13chenlu chen - Sun Microsystems - Beijing China ASSERT(spa_config_held(vd->vdev_spa, SCL_ALL, RW_WRITER) == SCL_ALL);
3cfa0eb9019abbded0c93bce072ab4e73b989c13chenlu chen - Sun Microsystems - Beijing China if ((vd->vdev_asize >> vd->vdev_ms_shift) > vd->vdev_ms_count) {
3cfa0eb9019abbded0c93bce072ab4e73b989c13chenlu chen - Sun Microsystems - Beijing China vdev_config_dirty(vd);
9da57d7b0ddd8d73b676ce12c040362132cdd538bt * Split a vdev.
73cd555c10e70dac413ae4b40de8450a291750acBin Tu - Sun Microsystems - Beijing Chinavdev_split(vdev_t *vd)
73cd555c10e70dac413ae4b40de8450a291750acBin Tu - Sun Microsystems - Beijing China if (avl_numnodes(&vq->vq_active_tree) > 0) {
9da57d7b0ddd8d73b676ce12c040362132cdd538bt * Look at the head of all the pending queues,
9da57d7b0ddd8d73b676ce12c040362132cdd538bt * if any I/O has been outstanding for longer than
73cd555c10e70dac413ae4b40de8450a291750acBin Tu - Sun Microsystems - Beijing China * the spa_deadman_synctime we panic the system.
73cd555c10e70dac413ae4b40de8450a291750acBin Tu - Sun Microsystems - Beijing China fio = avl_first(&vq->vq_active_tree);
73cd555c10e70dac413ae4b40de8450a291750acBin Tu - Sun Microsystems - Beijing China delta = gethrtime() - fio->io_timestamp;
73cd555c10e70dac413ae4b40de8450a291750acBin Tu - Sun Microsystems - Beijing China if (delta > spa_deadman_synctime(spa)) {
73cd555c10e70dac413ae4b40de8450a291750acBin Tu - Sun Microsystems - Beijing China zfs_dbgmsg("SLOW IO: zio timestamp %lluns, "
73cd555c10e70dac413ae4b40de8450a291750acBin Tu - Sun Microsystems - Beijing China "delta %lluns, last io %lluns",