vdev.c revision 2e4c998613148111f2fc5371085331ffb39122ff
9da57d7b0ddd8d73b676ce12c040362132cdd538bt/*
9da57d7b0ddd8d73b676ce12c040362132cdd538bt * CDDL HEADER START
9da57d7b0ddd8d73b676ce12c040362132cdd538bt *
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.
9da57d7b0ddd8d73b676ce12c040362132cdd538bt *
193974072f41a843678abf5f61979c748687e66bSherry Moore * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
193974072f41a843678abf5f61979c748687e66bSherry Moore * or http://www.opensolaris.org/os/licensing.
9da57d7b0ddd8d73b676ce12c040362132cdd538bt * See the License for the specific language governing permissions
9da57d7b0ddd8d73b676ce12c040362132cdd538bt * and limitations under the License.
9da57d7b0ddd8d73b676ce12c040362132cdd538bt *
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 *
9da57d7b0ddd8d73b676ce12c040362132cdd538bt * CDDL HEADER END
9da57d7b0ddd8d73b676ce12c040362132cdd538bt */
9da57d7b0ddd8d73b676ce12c040362132cdd538bt
9da57d7b0ddd8d73b676ce12c040362132cdd538bt/*
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.
00f1c25a65b1cfd93d859ba8bd8872cd7f276c86chenlu chen - Sun Microsystems - Beijing China */
00f1c25a65b1cfd93d859ba8bd8872cd7f276c86chenlu chen - Sun Microsystems - Beijing China
69b5a878d62fdee1b12e78371ce6cc8abddcad15Dan McDonald#include <sys/zfs_context.h>
69b5a878d62fdee1b12e78371ce6cc8abddcad15Dan McDonald#include <sys/fm/fs/zfs.h>
43fab1a9f38ff02e665a874ea0a8eb3818e61ff3Saso Kiselkov#include <sys/spa.h>
9da57d7b0ddd8d73b676ce12c040362132cdd538bt#include <sys/spa_impl.h>
9da57d7b0ddd8d73b676ce12c040362132cdd538bt#include <sys/dmu.h>
9da57d7b0ddd8d73b676ce12c040362132cdd538bt#include <sys/dmu_tx.h>
9da57d7b0ddd8d73b676ce12c040362132cdd538bt#include <sys/vdev_impl.h>
ffd8e8832e01f996f32459073f4dd308fe5265baWinson Wang - Sun Microsystems - Beijing China#include <sys/uberblock_impl.h>
5b6dd21f5401160f9a62ac2e76a858c2bc105370chenlu chen - Sun Microsystems - Beijing China#include <sys/metaslab.h>
9da57d7b0ddd8d73b676ce12c040362132cdd538bt#include <sys/metaslab_impl.h>
9da57d7b0ddd8d73b676ce12c040362132cdd538bt#include <sys/space_map.h>
9da57d7b0ddd8d73b676ce12c040362132cdd538bt#include <sys/space_reftree.h>
9da57d7b0ddd8d73b676ce12c040362132cdd538bt#include <sys/zio.h>
9da57d7b0ddd8d73b676ce12c040362132cdd538bt#include <sys/zap.h>
9da57d7b0ddd8d73b676ce12c040362132cdd538bt#include <sys/fs/zfs.h>
9da57d7b0ddd8d73b676ce12c040362132cdd538bt#include <sys/arc.h>
9da57d7b0ddd8d73b676ce12c040362132cdd538bt#include <sys/zil.h>
9da57d7b0ddd8d73b676ce12c040362132cdd538bt#include <sys/dsl_scan.h>
9da57d7b0ddd8d73b676ce12c040362132cdd538bt
9da57d7b0ddd8d73b676ce12c040362132cdd538bt/*
9da57d7b0ddd8d73b676ce12c040362132cdd538bt * Virtual device management.
9da57d7b0ddd8d73b676ce12c040362132cdd538bt */
9da57d7b0ddd8d73b676ce12c040362132cdd538bt
9da57d7b0ddd8d73b676ce12c040362132cdd538btstatic vdev_ops_t *vdev_ops_table[] = {
9da57d7b0ddd8d73b676ce12c040362132cdd538bt &vdev_root_ops,
9da57d7b0ddd8d73b676ce12c040362132cdd538bt &vdev_raidz_ops,
9da57d7b0ddd8d73b676ce12c040362132cdd538bt &vdev_mirror_ops,
9da57d7b0ddd8d73b676ce12c040362132cdd538bt &vdev_replacing_ops,
9da57d7b0ddd8d73b676ce12c040362132cdd538bt &vdev_spare_ops,
ea65739ebec0cbd625d8c89e19592be58fa186a6chenlu chen - Sun Microsystems - Beijing China &vdev_disk_ops,
ea65739ebec0cbd625d8c89e19592be58fa186a6chenlu chen - Sun Microsystems - Beijing China &vdev_file_ops,
9da57d7b0ddd8d73b676ce12c040362132cdd538bt &vdev_missing_ops,
9da57d7b0ddd8d73b676ce12c040362132cdd538bt &vdev_hole_ops,
9da57d7b0ddd8d73b676ce12c040362132cdd538bt NULL
9da57d7b0ddd8d73b676ce12c040362132cdd538bt};
9da57d7b0ddd8d73b676ce12c040362132cdd538bt
9da57d7b0ddd8d73b676ce12c040362132cdd538bt/* maximum scrub/resilver I/O queue per leaf vdev */
0dc2366f7b9f9f36e10909b1e95edbf2a261c2acVenugopal Iyerint zfs_scrub_limit = 10;
0dc2366f7b9f9f36e10909b1e95edbf2a261c2acVenugopal Iyer
9da57d7b0ddd8d73b676ce12c040362132cdd538bt/*
da14cebe459d3275048785f25bd869cb09b5307fEric Cheng * Given a vdev type, return the appropriate ops vector.
9da57d7b0ddd8d73b676ce12c040362132cdd538bt */
9da57d7b0ddd8d73b676ce12c040362132cdd538btstatic vdev_ops_t *
0dc2366f7b9f9f36e10909b1e95edbf2a261c2acVenugopal Iyervdev_getops(const char *type)
9da57d7b0ddd8d73b676ce12c040362132cdd538bt{
ea65739ebec0cbd625d8c89e19592be58fa186a6chenlu chen - Sun Microsystems - Beijing China vdev_ops_t *ops, **opspp;
9da57d7b0ddd8d73b676ce12c040362132cdd538bt
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)
5b6dd21f5401160f9a62ac2e76a858c2bc105370chenlu chen - Sun Microsystems - Beijing China break;
62e6e1adfc8d795f477410703cc7a88dc5b82622Paul Guo
9da57d7b0ddd8d73b676ce12c040362132cdd538bt return (ops);
9da57d7b0ddd8d73b676ce12c040362132cdd538bt}
9da57d7b0ddd8d73b676ce12c040362132cdd538bt
9da57d7b0ddd8d73b676ce12c040362132cdd538bt/*
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 */
9da57d7b0ddd8d73b676ce12c040362132cdd538btuint64_t
9da57d7b0ddd8d73b676ce12c040362132cdd538btvdev_default_asize(vdev_t *vd, uint64_t psize)
9da57d7b0ddd8d73b676ce12c040362132cdd538bt{
9da57d7b0ddd8d73b676ce12c040362132cdd538bt uint64_t asize = P2ROUNDUP(psize, 1ULL << vd->vdev_top->vdev_ashift);
9da57d7b0ddd8d73b676ce12c040362132cdd538bt uint64_t csize;
9da57d7b0ddd8d73b676ce12c040362132cdd538bt
9da57d7b0ddd8d73b676ce12c040362132cdd538bt for (int c = 0; c < vd->vdev_children; c++) {
9da57d7b0ddd8d73b676ce12c040362132cdd538bt csize = vdev_psize_to_asize(vd->vdev_child[c], psize);
73cd555c10e70dac413ae4b40de8450a291750acBin Tu - Sun Microsystems - Beijing China asize = MAX(asize, csize);
73cd555c10e70dac413ae4b40de8450a291750acBin Tu - Sun Microsystems - Beijing China }
73cd555c10e70dac413ae4b40de8450a291750acBin Tu - Sun Microsystems - Beijing China
0dc2366f7b9f9f36e10909b1e95edbf2a261c2acVenugopal Iyer return (asize);
73cd555c10e70dac413ae4b40de8450a291750acBin Tu - Sun Microsystems - Beijing China}
9da57d7b0ddd8d73b676ce12c040362132cdd538bt
9da57d7b0ddd8d73b676ce12c040362132cdd538bt/*
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.
9da57d7b0ddd8d73b676ce12c040362132cdd538bt */
73cd555c10e70dac413ae4b40de8450a291750acBin Tu - Sun Microsystems - Beijing Chinauint64_t
9da57d7b0ddd8d73b676ce12c040362132cdd538btvdev_get_min_asize(vdev_t *vd)
9da57d7b0ddd8d73b676ce12c040362132cdd538bt{
13740cb230f19fcbf1a6468d1a6a0ba9a0a09c22Paul Guo vdev_t *pvd = vd->vdev_parent;
9da57d7b0ddd8d73b676ce12c040362132cdd538bt
da14cebe459d3275048785f25bd869cb09b5307fEric Cheng /*
da14cebe459d3275048785f25bd869cb09b5307fEric Cheng * If our parent is NULL (inactive spare or cache) or is the root,
9da57d7b0ddd8d73b676ce12c040362132cdd538bt * just return our own asize.
9da57d7b0ddd8d73b676ce12c040362132cdd538bt */
9da57d7b0ddd8d73b676ce12c040362132cdd538bt if (pvd == NULL)
9da57d7b0ddd8d73b676ce12c040362132cdd538bt return (vd->vdev_asize);
9da57d7b0ddd8d73b676ce12c040362132cdd538bt
9da57d7b0ddd8d73b676ce12c040362132cdd538bt /*
9da57d7b0ddd8d73b676ce12c040362132cdd538bt * The top-level vdev just returns the allocatable size rounded
9da57d7b0ddd8d73b676ce12c040362132cdd538bt * to the nearest metaslab.
0dc2366f7b9f9f36e10909b1e95edbf2a261c2acVenugopal Iyer */
0dc2366f7b9f9f36e10909b1e95edbf2a261c2acVenugopal Iyer if (vd == vd->vdev_top)
0dc2366f7b9f9f36e10909b1e95edbf2a261c2acVenugopal Iyer return (P2ALIGN(vd->vdev_asize, 1ULL << vd->vdev_ms_shift));
9da57d7b0ddd8d73b676ce12c040362132cdd538bt
9da57d7b0ddd8d73b676ce12c040362132cdd538bt /*
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.
9da57d7b0ddd8d73b676ce12c040362132cdd538bt */
9da57d7b0ddd8d73b676ce12c040362132cdd538bt if (pvd->vdev_ops == &vdev_raidz_ops)
0dc2366f7b9f9f36e10909b1e95edbf2a261c2acVenugopal Iyer return (pvd->vdev_min_asize / pvd->vdev_children);
0dc2366f7b9f9f36e10909b1e95edbf2a261c2acVenugopal Iyer
0dc2366f7b9f9f36e10909b1e95edbf2a261c2acVenugopal Iyer return (pvd->vdev_min_asize);
0dc2366f7b9f9f36e10909b1e95edbf2a261c2acVenugopal Iyer}
0dc2366f7b9f9f36e10909b1e95edbf2a261c2acVenugopal Iyer
0dc2366f7b9f9f36e10909b1e95edbf2a261c2acVenugopal Iyervoid
0dc2366f7b9f9f36e10909b1e95edbf2a261c2acVenugopal Iyervdev_set_min_asize(vdev_t *vd)
0dc2366f7b9f9f36e10909b1e95edbf2a261c2acVenugopal Iyer{
0dc2366f7b9f9f36e10909b1e95edbf2a261c2acVenugopal Iyer vd->vdev_min_asize = vdev_get_min_asize(vd);
0dc2366f7b9f9f36e10909b1e95edbf2a261c2acVenugopal Iyer
0dc2366f7b9f9f36e10909b1e95edbf2a261c2acVenugopal Iyer for (int c = 0; c < vd->vdev_children; c++)
ea65739ebec0cbd625d8c89e19592be58fa186a6chenlu chen - Sun Microsystems - Beijing China vdev_set_min_asize(vd->vdev_child[c]);
ea65739ebec0cbd625d8c89e19592be58fa186a6chenlu chen - Sun Microsystems - Beijing China}
ea65739ebec0cbd625d8c89e19592be58fa186a6chenlu chen - Sun Microsystems - Beijing China
ea65739ebec0cbd625d8c89e19592be58fa186a6chenlu chen - Sun Microsystems - Beijing Chinavdev_t *
ea65739ebec0cbd625d8c89e19592be58fa186a6chenlu chen - Sun Microsystems - Beijing Chinavdev_lookup_top(spa_t *spa, uint64_t vdev)
9da57d7b0ddd8d73b676ce12c040362132cdd538bt{
9da57d7b0ddd8d73b676ce12c040362132cdd538bt vdev_t *rvd = spa->spa_root_vdev;
9da57d7b0ddd8d73b676ce12c040362132cdd538bt
9da57d7b0ddd8d73b676ce12c040362132cdd538bt ASSERT(spa_config_held(spa, SCL_ALL, RW_READER) != 0);
9da57d7b0ddd8d73b676ce12c040362132cdd538bt
9da57d7b0ddd8d73b676ce12c040362132cdd538bt if (vdev < rvd->vdev_children) {
9da57d7b0ddd8d73b676ce12c040362132cdd538bt ASSERT(rvd->vdev_child[vdev] != NULL);
9da57d7b0ddd8d73b676ce12c040362132cdd538bt return (rvd->vdev_child[vdev]);
9da57d7b0ddd8d73b676ce12c040362132cdd538bt }
9da57d7b0ddd8d73b676ce12c040362132cdd538bt
9da57d7b0ddd8d73b676ce12c040362132cdd538bt return (NULL);
9da57d7b0ddd8d73b676ce12c040362132cdd538bt}
9da57d7b0ddd8d73b676ce12c040362132cdd538bt
9da57d7b0ddd8d73b676ce12c040362132cdd538btvdev_t *
9da57d7b0ddd8d73b676ce12c040362132cdd538btvdev_lookup_by_guid(vdev_t *vd, uint64_t guid)
9da57d7b0ddd8d73b676ce12c040362132cdd538bt{
9da57d7b0ddd8d73b676ce12c040362132cdd538bt vdev_t *mvd;
9da57d7b0ddd8d73b676ce12c040362132cdd538bt
9da57d7b0ddd8d73b676ce12c040362132cdd538bt if (vd->vdev_guid == guid)
9da57d7b0ddd8d73b676ce12c040362132cdd538bt return (vd);
9da57d7b0ddd8d73b676ce12c040362132cdd538bt
9da57d7b0ddd8d73b676ce12c040362132cdd538bt for (int c = 0; c < vd->vdev_children; c++)
9da57d7b0ddd8d73b676ce12c040362132cdd538bt if ((mvd = vdev_lookup_by_guid(vd->vdev_child[c], guid)) !=
9da57d7b0ddd8d73b676ce12c040362132cdd538bt NULL)
9da57d7b0ddd8d73b676ce12c040362132cdd538bt return (mvd);
9da57d7b0ddd8d73b676ce12c040362132cdd538bt
9da57d7b0ddd8d73b676ce12c040362132cdd538bt return (NULL);
9da57d7b0ddd8d73b676ce12c040362132cdd538bt}
9da57d7b0ddd8d73b676ce12c040362132cdd538bt
9da57d7b0ddd8d73b676ce12c040362132cdd538btvoid
9da57d7b0ddd8d73b676ce12c040362132cdd538btvdev_add_child(vdev_t *pvd, vdev_t *cvd)
9da57d7b0ddd8d73b676ce12c040362132cdd538bt{
193974072f41a843678abf5f61979c748687e66bSherry Moore size_t oldsize, newsize;
193974072f41a843678abf5f61979c748687e66bSherry Moore uint64_t id = cvd->vdev_id;
9da57d7b0ddd8d73b676ce12c040362132cdd538bt vdev_t **newchild;
9da57d7b0ddd8d73b676ce12c040362132cdd538bt
9da57d7b0ddd8d73b676ce12c040362132cdd538bt ASSERT(spa_config_held(cvd->vdev_spa, SCL_ALL, RW_WRITER) == SCL_ALL);
9da57d7b0ddd8d73b676ce12c040362132cdd538bt ASSERT(cvd->vdev_parent == NULL);
ffd8e8832e01f996f32459073f4dd308fe5265baWinson Wang - Sun Microsystems - Beijing China
9da57d7b0ddd8d73b676ce12c040362132cdd538bt cvd->vdev_parent = pvd;
9da57d7b0ddd8d73b676ce12c040362132cdd538bt
9da57d7b0ddd8d73b676ce12c040362132cdd538bt if (pvd == NULL)
9da57d7b0ddd8d73b676ce12c040362132cdd538bt return;
9da57d7b0ddd8d73b676ce12c040362132cdd538bt
9da57d7b0ddd8d73b676ce12c040362132cdd538bt ASSERT(id >= pvd->vdev_children || pvd->vdev_child[id] == NULL);
9da57d7b0ddd8d73b676ce12c040362132cdd538bt
9da57d7b0ddd8d73b676ce12c040362132cdd538bt oldsize = pvd->vdev_children * sizeof (vdev_t *);
9da57d7b0ddd8d73b676ce12c040362132cdd538bt pvd->vdev_children = MAX(pvd->vdev_children, id + 1);
9da57d7b0ddd8d73b676ce12c040362132cdd538bt newsize = pvd->vdev_children * sizeof (vdev_t *);
9da57d7b0ddd8d73b676ce12c040362132cdd538bt
837c1ac4e72b7d86278cca88b1075af557f7d161Stephen Hanson newchild = kmem_zalloc(newsize, KM_SLEEP);
9da57d7b0ddd8d73b676ce12c040362132cdd538bt if (pvd->vdev_child != NULL) {
9da57d7b0ddd8d73b676ce12c040362132cdd538bt bcopy(pvd->vdev_child, newchild, oldsize);
9da57d7b0ddd8d73b676ce12c040362132cdd538bt kmem_free(pvd->vdev_child, oldsize);
9da57d7b0ddd8d73b676ce12c040362132cdd538bt }
9da57d7b0ddd8d73b676ce12c040362132cdd538bt
9da57d7b0ddd8d73b676ce12c040362132cdd538bt pvd->vdev_child = newchild;
9da57d7b0ddd8d73b676ce12c040362132cdd538bt pvd->vdev_child[id] = cvd;
9da57d7b0ddd8d73b676ce12c040362132cdd538bt
9da57d7b0ddd8d73b676ce12c040362132cdd538bt cvd->vdev_top = (pvd->vdev_top ? pvd->vdev_top: cvd);
9da57d7b0ddd8d73b676ce12c040362132cdd538bt ASSERT(cvd->vdev_top->vdev_parent->vdev_parent == NULL);
9da57d7b0ddd8d73b676ce12c040362132cdd538bt
9da57d7b0ddd8d73b676ce12c040362132cdd538bt /*
9da57d7b0ddd8d73b676ce12c040362132cdd538bt * Walk up all ancestors to update guid sum.
9da57d7b0ddd8d73b676ce12c040362132cdd538bt */
9da57d7b0ddd8d73b676ce12c040362132cdd538bt for (; pvd != NULL; pvd = pvd->vdev_parent)
9da57d7b0ddd8d73b676ce12c040362132cdd538bt pvd->vdev_guid_sum += cvd->vdev_guid_sum;
1fedc51fe8f78efa2ee550387171e6adb2223b8dWinson Wang - Sun Microsystems - Beijing China}
1fedc51fe8f78efa2ee550387171e6adb2223b8dWinson Wang - Sun Microsystems - Beijing China
1fedc51fe8f78efa2ee550387171e6adb2223b8dWinson Wang - Sun Microsystems - Beijing Chinavoid
1fedc51fe8f78efa2ee550387171e6adb2223b8dWinson Wang - Sun Microsystems - Beijing Chinavdev_remove_child(vdev_t *pvd, vdev_t *cvd)
ea65739ebec0cbd625d8c89e19592be58fa186a6chenlu chen - Sun Microsystems - Beijing China{
0dc2366f7b9f9f36e10909b1e95edbf2a261c2acVenugopal Iyer int c;
9da57d7b0ddd8d73b676ce12c040362132cdd538bt uint_t id = cvd->vdev_id;
9da57d7b0ddd8d73b676ce12c040362132cdd538bt
9da57d7b0ddd8d73b676ce12c040362132cdd538bt ASSERT(cvd->vdev_parent == pvd);
9da57d7b0ddd8d73b676ce12c040362132cdd538bt
9da57d7b0ddd8d73b676ce12c040362132cdd538bt if (pvd == NULL)
9da57d7b0ddd8d73b676ce12c040362132cdd538bt return;
9da57d7b0ddd8d73b676ce12c040362132cdd538bt
9da57d7b0ddd8d73b676ce12c040362132cdd538bt ASSERT(id < pvd->vdev_children);
da14cebe459d3275048785f25bd869cb09b5307fEric Cheng ASSERT(pvd->vdev_child[id] == cvd);
9da57d7b0ddd8d73b676ce12c040362132cdd538bt
0dc2366f7b9f9f36e10909b1e95edbf2a261c2acVenugopal Iyer pvd->vdev_child[id] = NULL;
9da57d7b0ddd8d73b676ce12c040362132cdd538bt cvd->vdev_parent = NULL;
ea65739ebec0cbd625d8c89e19592be58fa186a6chenlu chen - Sun Microsystems - Beijing China
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])
ea65739ebec0cbd625d8c89e19592be58fa186a6chenlu chen - Sun Microsystems - Beijing China break;
0dc2366f7b9f9f36e10909b1e95edbf2a261c2acVenugopal Iyer
0dc2366f7b9f9f36e10909b1e95edbf2a261c2acVenugopal Iyer if (c == pvd->vdev_children) {
9da57d7b0ddd8d73b676ce12c040362132cdd538bt kmem_free(pvd->vdev_child, c * sizeof (vdev_t *));
9da57d7b0ddd8d73b676ce12c040362132cdd538bt pvd->vdev_child = NULL;
13740cb230f19fcbf1a6468d1a6a0ba9a0a09c22Paul Guo pvd->vdev_children = 0;
13740cb230f19fcbf1a6468d1a6a0ba9a0a09c22Paul Guo }
13740cb230f19fcbf1a6468d1a6a0ba9a0a09c22Paul Guo
13740cb230f19fcbf1a6468d1a6a0ba9a0a09c22Paul Guo /*
13740cb230f19fcbf1a6468d1a6a0ba9a0a09c22Paul Guo * Walk up all ancestors to update guid sum.
13740cb230f19fcbf1a6468d1a6a0ba9a0a09c22Paul Guo */
0dc2366f7b9f9f36e10909b1e95edbf2a261c2acVenugopal Iyer for (; pvd != NULL; pvd = pvd->vdev_parent)
0dc2366f7b9f9f36e10909b1e95edbf2a261c2acVenugopal Iyer pvd->vdev_guid_sum -= cvd->vdev_guid_sum;
0dc2366f7b9f9f36e10909b1e95edbf2a261c2acVenugopal Iyer}
0dc2366f7b9f9f36e10909b1e95edbf2a261c2acVenugopal Iyer
13740cb230f19fcbf1a6468d1a6a0ba9a0a09c22Paul Guo/*
13740cb230f19fcbf1a6468d1a6a0ba9a0a09c22Paul Guo * Remove any holes in the child array.
13740cb230f19fcbf1a6468d1a6a0ba9a0a09c22Paul Guo */
1fedc51fe8f78efa2ee550387171e6adb2223b8dWinson Wang - Sun Microsystems - Beijing Chinavoid
ea65739ebec0cbd625d8c89e19592be58fa186a6chenlu chen - Sun Microsystems - Beijing Chinavdev_compact_children(vdev_t *pvd)
ea65739ebec0cbd625d8c89e19592be58fa186a6chenlu chen - Sun Microsystems - Beijing China{
ea65739ebec0cbd625d8c89e19592be58fa186a6chenlu chen - Sun Microsystems - Beijing China vdev_t **newchild, *cvd;
13740cb230f19fcbf1a6468d1a6a0ba9a0a09c22Paul Guo int oldc = pvd->vdev_children;
13740cb230f19fcbf1a6468d1a6a0ba9a0a09c22Paul Guo int newc;
13740cb230f19fcbf1a6468d1a6a0ba9a0a09c22Paul Guo
13740cb230f19fcbf1a6468d1a6a0ba9a0a09c22Paul Guo ASSERT(spa_config_held(pvd->vdev_spa, SCL_ALL, RW_WRITER) == SCL_ALL);
5b6dd21f5401160f9a62ac2e76a858c2bc105370chenlu chen - Sun Microsystems - Beijing China
13740cb230f19fcbf1a6468d1a6a0ba9a0a09c22Paul Guo for (int c = newc = 0; c < oldc; c++)
13740cb230f19fcbf1a6468d1a6a0ba9a0a09c22Paul Guo if (pvd->vdev_child[c])
13740cb230f19fcbf1a6468d1a6a0ba9a0a09c22Paul Guo newc++;
13740cb230f19fcbf1a6468d1a6a0ba9a0a09c22Paul Guo
13740cb230f19fcbf1a6468d1a6a0ba9a0a09c22Paul Guo newchild = kmem_alloc(newc * sizeof (vdev_t *), KM_SLEEP);
73cd555c10e70dac413ae4b40de8450a291750acBin Tu - Sun Microsystems - Beijing China
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) {
0dc2366f7b9f9f36e10909b1e95edbf2a261c2acVenugopal Iyer newchild[newc] = cvd;
0dc2366f7b9f9f36e10909b1e95edbf2a261c2acVenugopal Iyer cvd->vdev_id = newc++;
0dc2366f7b9f9f36e10909b1e95edbf2a261c2acVenugopal Iyer }
0dc2366f7b9f9f36e10909b1e95edbf2a261c2acVenugopal Iyer }
73cd555c10e70dac413ae4b40de8450a291750acBin Tu - Sun Microsystems - Beijing China
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;
ea65739ebec0cbd625d8c89e19592be58fa186a6chenlu chen - Sun Microsystems - Beijing China}
ea65739ebec0cbd625d8c89e19592be58fa186a6chenlu chen - Sun Microsystems - Beijing China
ea65739ebec0cbd625d8c89e19592be58fa186a6chenlu chen - Sun Microsystems - Beijing China/*
73cd555c10e70dac413ae4b40de8450a291750acBin Tu - Sun Microsystems - Beijing China * Allocate and minimally initialize a vdev_t.
73cd555c10e70dac413ae4b40de8450a291750acBin Tu - Sun Microsystems - Beijing China */
73cd555c10e70dac413ae4b40de8450a291750acBin Tu - Sun Microsystems - Beijing Chinavdev_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{
5b6dd21f5401160f9a62ac2e76a858c2bc105370chenlu chen - Sun Microsystems - Beijing China vdev_t *vd;
5b6dd21f5401160f9a62ac2e76a858c2bc105370chenlu chen - Sun Microsystems - Beijing China
5b6dd21f5401160f9a62ac2e76a858c2bc105370chenlu chen - Sun Microsystems - Beijing China vd = kmem_zalloc(sizeof (vdev_t), KM_SLEEP);
5b6dd21f5401160f9a62ac2e76a858c2bc105370chenlu chen - Sun Microsystems - Beijing China
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);
5b6dd21f5401160f9a62ac2e76a858c2bc105370chenlu chen - Sun Microsystems - Beijing China }
5b6dd21f5401160f9a62ac2e76a858c2bc105370chenlu chen - Sun Microsystems - Beijing China
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 /*
69b5a878d62fdee1b12e78371ce6cc8abddcad15Dan McDonald * The root vdev's guid will also be the pool guid,
69b5a878d62fdee1b12e78371ce6cc8abddcad15Dan McDonald * which must be unique among all pools.
69b5a878d62fdee1b12e78371ce6cc8abddcad15Dan McDonald */
69b5a878d62fdee1b12e78371ce6cc8abddcad15Dan McDonald guid = spa_generate_guid(NULL);
69b5a878d62fdee1b12e78371ce6cc8abddcad15Dan McDonald } else {
69b5a878d62fdee1b12e78371ce6cc8abddcad15Dan McDonald /*
69b5a878d62fdee1b12e78371ce6cc8abddcad15Dan McDonald * Any other vdev's guid must be unique within the pool.
69b5a878d62fdee1b12e78371ce6cc8abddcad15Dan McDonald */
69b5a878d62fdee1b12e78371ce6cc8abddcad15Dan McDonald guid = spa_generate_guid(spa);
69b5a878d62fdee1b12e78371ce6cc8abddcad15Dan McDonald }
69b5a878d62fdee1b12e78371ce6cc8abddcad15Dan McDonald ASSERT(!spa_guid_exists(spa_guid(spa), guid));
69b5a878d62fdee1b12e78371ce6cc8abddcad15Dan McDonald }
69b5a878d62fdee1b12e78371ce6cc8abddcad15Dan McDonald
69b5a878d62fdee1b12e78371ce6cc8abddcad15Dan McDonald vd->vdev_spa = spa;
69b5a878d62fdee1b12e78371ce6cc8abddcad15Dan McDonald vd->vdev_id = id;
69b5a878d62fdee1b12e78371ce6cc8abddcad15Dan McDonald vd->vdev_guid = guid;
69b5a878d62fdee1b12e78371ce6cc8abddcad15Dan McDonald vd->vdev_guid_sum = guid;
69b5a878d62fdee1b12e78371ce6cc8abddcad15Dan McDonald vd->vdev_ops = ops;
69b5a878d62fdee1b12e78371ce6cc8abddcad15Dan McDonald vd->vdev_state = VDEV_STATE_CLOSED;
69b5a878d62fdee1b12e78371ce6cc8abddcad15Dan McDonald vd->vdev_ishole = (ops == &vdev_hole_ops);
69b5a878d62fdee1b12e78371ce6cc8abddcad15Dan McDonald
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,
69b5a878d62fdee1b12e78371ce6cc8abddcad15Dan McDonald &vd->vdev_dtl_lock);
69b5a878d62fdee1b12e78371ce6cc8abddcad15Dan McDonald }
69b5a878d62fdee1b12e78371ce6cc8abddcad15Dan McDonald txg_list_create(&vd->vdev_ms_list,
9da57d7b0ddd8d73b676ce12c040362132cdd538bt offsetof(struct metaslab, ms_txg_node));
9da57d7b0ddd8d73b676ce12c040362132cdd538bt txg_list_create(&vd->vdev_dtl_list,
9da57d7b0ddd8d73b676ce12c040362132cdd538bt offsetof(struct vdev, vdev_dtl_node));
9da57d7b0ddd8d73b676ce12c040362132cdd538bt vd->vdev_stat.vs_timestamp = gethrtime();
9da57d7b0ddd8d73b676ce12c040362132cdd538bt vdev_queue_init(vd);
9da57d7b0ddd8d73b676ce12c040362132cdd538bt vdev_cache_init(vd);
9da57d7b0ddd8d73b676ce12c040362132cdd538bt
9da57d7b0ddd8d73b676ce12c040362132cdd538bt return (vd);
9da57d7b0ddd8d73b676ce12c040362132cdd538bt}
9da57d7b0ddd8d73b676ce12c040362132cdd538bt
9da57d7b0ddd8d73b676ce12c040362132cdd538bt/*
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.
9da57d7b0ddd8d73b676ce12c040362132cdd538bt */
9da57d7b0ddd8d73b676ce12c040362132cdd538btint
9da57d7b0ddd8d73b676ce12c040362132cdd538btvdev_alloc(spa_t *spa, vdev_t **vdp, nvlist_t *nv, vdev_t *parent, uint_t id,
9da57d7b0ddd8d73b676ce12c040362132cdd538bt int alloctype)
9da57d7b0ddd8d73b676ce12c040362132cdd538bt{
9da57d7b0ddd8d73b676ce12c040362132cdd538bt vdev_ops_t *ops;
9da57d7b0ddd8d73b676ce12c040362132cdd538bt char *type;
9da57d7b0ddd8d73b676ce12c040362132cdd538bt uint64_t guid = 0, islog, nparity;
9da57d7b0ddd8d73b676ce12c040362132cdd538bt vdev_t *vd;
9da57d7b0ddd8d73b676ce12c040362132cdd538bt
9da57d7b0ddd8d73b676ce12c040362132cdd538bt ASSERT(spa_config_held(spa, SCL_ALL, RW_WRITER) == SCL_ALL);
9da57d7b0ddd8d73b676ce12c040362132cdd538bt
9da57d7b0ddd8d73b676ce12c040362132cdd538bt if (nvlist_lookup_string(nv, ZPOOL_CONFIG_TYPE, &type) != 0)
9da57d7b0ddd8d73b676ce12c040362132cdd538bt return (SET_ERROR(EINVAL));
9da57d7b0ddd8d73b676ce12c040362132cdd538bt
9da57d7b0ddd8d73b676ce12c040362132cdd538bt if ((ops = vdev_getops(type)) == NULL)
9da57d7b0ddd8d73b676ce12c040362132cdd538bt return (SET_ERROR(EINVAL));
9da57d7b0ddd8d73b676ce12c040362132cdd538bt
9da57d7b0ddd8d73b676ce12c040362132cdd538bt /*
9da57d7b0ddd8d73b676ce12c040362132cdd538bt * If this is a load, get the vdev guid from the nvlist.
9da57d7b0ddd8d73b676ce12c040362132cdd538bt * Otherwise, vdev_alloc_common() will generate one for us.
9da57d7b0ddd8d73b676ce12c040362132cdd538bt */
9da57d7b0ddd8d73b676ce12c040362132cdd538bt if (alloctype == VDEV_ALLOC_LOAD) {
9da57d7b0ddd8d73b676ce12c040362132cdd538bt uint64_t label_id;
9da57d7b0ddd8d73b676ce12c040362132cdd538bt
9da57d7b0ddd8d73b676ce12c040362132cdd538bt if (nvlist_lookup_uint64(nv, ZPOOL_CONFIG_ID, &label_id) ||
9da57d7b0ddd8d73b676ce12c040362132cdd538bt label_id != id)
9da57d7b0ddd8d73b676ce12c040362132cdd538bt return (SET_ERROR(EINVAL));
9da57d7b0ddd8d73b676ce12c040362132cdd538bt
9da57d7b0ddd8d73b676ce12c040362132cdd538bt if (nvlist_lookup_uint64(nv, ZPOOL_CONFIG_GUID, &guid) != 0)
9da57d7b0ddd8d73b676ce12c040362132cdd538bt return (SET_ERROR(EINVAL));
9da57d7b0ddd8d73b676ce12c040362132cdd538bt } else if (alloctype == VDEV_ALLOC_SPARE) {
9da57d7b0ddd8d73b676ce12c040362132cdd538bt if (nvlist_lookup_uint64(nv, ZPOOL_CONFIG_GUID, &guid) != 0)
9da57d7b0ddd8d73b676ce12c040362132cdd538bt return (SET_ERROR(EINVAL));
9da57d7b0ddd8d73b676ce12c040362132cdd538bt } else if (alloctype == VDEV_ALLOC_L2CACHE) {
9da57d7b0ddd8d73b676ce12c040362132cdd538bt if (nvlist_lookup_uint64(nv, ZPOOL_CONFIG_GUID, &guid) != 0)
9da57d7b0ddd8d73b676ce12c040362132cdd538bt return (SET_ERROR(EINVAL));
9da57d7b0ddd8d73b676ce12c040362132cdd538bt } else if (alloctype == VDEV_ALLOC_ROOTPOOL) {
9da57d7b0ddd8d73b676ce12c040362132cdd538bt if (nvlist_lookup_uint64(nv, ZPOOL_CONFIG_GUID, &guid) != 0)
9da57d7b0ddd8d73b676ce12c040362132cdd538bt return (SET_ERROR(EINVAL));
9da57d7b0ddd8d73b676ce12c040362132cdd538bt }
9da57d7b0ddd8d73b676ce12c040362132cdd538bt
9da57d7b0ddd8d73b676ce12c040362132cdd538bt /*
9da57d7b0ddd8d73b676ce12c040362132cdd538bt * The first allocated vdev must be of type 'root'.
9da57d7b0ddd8d73b676ce12c040362132cdd538bt */
9da57d7b0ddd8d73b676ce12c040362132cdd538bt if (ops != &vdev_root_ops && spa->spa_root_vdev == NULL)
9da57d7b0ddd8d73b676ce12c040362132cdd538bt return (SET_ERROR(EINVAL));
9da57d7b0ddd8d73b676ce12c040362132cdd538bt
9da57d7b0ddd8d73b676ce12c040362132cdd538bt /*
9da57d7b0ddd8d73b676ce12c040362132cdd538bt * Determine whether we're a log vdev.
9da57d7b0ddd8d73b676ce12c040362132cdd538bt */
9da57d7b0ddd8d73b676ce12c040362132cdd538bt islog = 0;
13740cb230f19fcbf1a6468d1a6a0ba9a0a09c22Paul Guo (void) nvlist_lookup_uint64(nv, ZPOOL_CONFIG_IS_LOG, &islog);
9da57d7b0ddd8d73b676ce12c040362132cdd538bt if (islog && spa_version(spa) < SPA_VERSION_SLOGS)
9da57d7b0ddd8d73b676ce12c040362132cdd538bt return (SET_ERROR(ENOTSUP));
9da57d7b0ddd8d73b676ce12c040362132cdd538bt
9da57d7b0ddd8d73b676ce12c040362132cdd538bt if (ops == &vdev_hole_ops && spa_version(spa) < SPA_VERSION_HOLES)
9da57d7b0ddd8d73b676ce12c040362132cdd538bt return (SET_ERROR(ENOTSUP));
9da57d7b0ddd8d73b676ce12c040362132cdd538bt
9da57d7b0ddd8d73b676ce12c040362132cdd538bt /*
9da57d7b0ddd8d73b676ce12c040362132cdd538bt * Set the nparity property for RAID-Z vdevs.
9da57d7b0ddd8d73b676ce12c040362132cdd538bt */
9da57d7b0ddd8d73b676ce12c040362132cdd538bt nparity = -1ULL;
9da57d7b0ddd8d73b676ce12c040362132cdd538bt if (ops == &vdev_raidz_ops) {
9da57d7b0ddd8d73b676ce12c040362132cdd538bt if (nvlist_lookup_uint64(nv, ZPOOL_CONFIG_NPARITY,
9da57d7b0ddd8d73b676ce12c040362132cdd538bt &nparity) == 0) {
9da57d7b0ddd8d73b676ce12c040362132cdd538bt if (nparity == 0 || nparity > VDEV_RAIDZ_MAXPARITY)
9da57d7b0ddd8d73b676ce12c040362132cdd538bt return (SET_ERROR(EINVAL));
9da57d7b0ddd8d73b676ce12c040362132cdd538bt /*
9da57d7b0ddd8d73b676ce12c040362132cdd538bt * Previous versions could only support 1 or 2 parity
9da57d7b0ddd8d73b676ce12c040362132cdd538bt * device.
9da57d7b0ddd8d73b676ce12c040362132cdd538bt */
9da57d7b0ddd8d73b676ce12c040362132cdd538bt if (nparity > 1 &&
9da57d7b0ddd8d73b676ce12c040362132cdd538bt spa_version(spa) < SPA_VERSION_RAIDZ2)
9da57d7b0ddd8d73b676ce12c040362132cdd538bt return (SET_ERROR(ENOTSUP));
9da57d7b0ddd8d73b676ce12c040362132cdd538bt if (nparity > 2 &&
9da57d7b0ddd8d73b676ce12c040362132cdd538bt spa_version(spa) < SPA_VERSION_RAIDZ3)
9da57d7b0ddd8d73b676ce12c040362132cdd538bt return (SET_ERROR(ENOTSUP));
9da57d7b0ddd8d73b676ce12c040362132cdd538bt } else {
9da57d7b0ddd8d73b676ce12c040362132cdd538bt /*
9da57d7b0ddd8d73b676ce12c040362132cdd538bt * We require the parity to be specified for SPAs that
9da57d7b0ddd8d73b676ce12c040362132cdd538bt * support multiple parity levels.
9da57d7b0ddd8d73b676ce12c040362132cdd538bt */
9da57d7b0ddd8d73b676ce12c040362132cdd538bt if (spa_version(spa) >= SPA_VERSION_RAIDZ2)
9da57d7b0ddd8d73b676ce12c040362132cdd538bt return (SET_ERROR(EINVAL));
9da57d7b0ddd8d73b676ce12c040362132cdd538bt /*
9da57d7b0ddd8d73b676ce12c040362132cdd538bt * Otherwise, we default to 1 parity device for RAID-Z.
9da57d7b0ddd8d73b676ce12c040362132cdd538bt */
c971fb7ec0a19c6cd00c5614a94c97f953b6e8b1gg nparity = 1;
9da57d7b0ddd8d73b676ce12c040362132cdd538bt }
9da57d7b0ddd8d73b676ce12c040362132cdd538bt } else {
9da57d7b0ddd8d73b676ce12c040362132cdd538bt nparity = 0;
9da57d7b0ddd8d73b676ce12c040362132cdd538bt }
9da57d7b0ddd8d73b676ce12c040362132cdd538bt ASSERT(nparity != -1ULL);
9da57d7b0ddd8d73b676ce12c040362132cdd538bt
9da57d7b0ddd8d73b676ce12c040362132cdd538bt vd = vdev_alloc_common(spa, id, guid, ops);
9da57d7b0ddd8d73b676ce12c040362132cdd538bt
9da57d7b0ddd8d73b676ce12c040362132cdd538bt vd->vdev_islog = islog;
9da57d7b0ddd8d73b676ce12c040362132cdd538bt vd->vdev_nparity = nparity;
9da57d7b0ddd8d73b676ce12c040362132cdd538bt
9da57d7b0ddd8d73b676ce12c040362132cdd538bt if (nvlist_lookup_string(nv, ZPOOL_CONFIG_PATH, &vd->vdev_path) == 0)
9da57d7b0ddd8d73b676ce12c040362132cdd538bt vd->vdev_path = spa_strdup(vd->vdev_path);
9da57d7b0ddd8d73b676ce12c040362132cdd538bt if (nvlist_lookup_string(nv, ZPOOL_CONFIG_DEVID, &vd->vdev_devid) == 0)
9da57d7b0ddd8d73b676ce12c040362132cdd538bt vd->vdev_devid = spa_strdup(vd->vdev_devid);
9da57d7b0ddd8d73b676ce12c040362132cdd538bt if (nvlist_lookup_string(nv, ZPOOL_CONFIG_PHYS_PATH,
9da57d7b0ddd8d73b676ce12c040362132cdd538bt &vd->vdev_physpath) == 0)
9da57d7b0ddd8d73b676ce12c040362132cdd538bt vd->vdev_physpath = spa_strdup(vd->vdev_physpath);
9da57d7b0ddd8d73b676ce12c040362132cdd538bt if (nvlist_lookup_string(nv, ZPOOL_CONFIG_FRU, &vd->vdev_fru) == 0)
9da57d7b0ddd8d73b676ce12c040362132cdd538bt vd->vdev_fru = spa_strdup(vd->vdev_fru);
9da57d7b0ddd8d73b676ce12c040362132cdd538bt
9da57d7b0ddd8d73b676ce12c040362132cdd538bt /*
9da57d7b0ddd8d73b676ce12c040362132cdd538bt * Set the whole_disk property. If it's not specified, leave the value
9da57d7b0ddd8d73b676ce12c040362132cdd538bt * as -1.
9da57d7b0ddd8d73b676ce12c040362132cdd538bt */
9da57d7b0ddd8d73b676ce12c040362132cdd538bt if (nvlist_lookup_uint64(nv, ZPOOL_CONFIG_WHOLE_DISK,
9da57d7b0ddd8d73b676ce12c040362132cdd538bt &vd->vdev_wholedisk) != 0)
9da57d7b0ddd8d73b676ce12c040362132cdd538bt vd->vdev_wholedisk = -1ULL;
9da57d7b0ddd8d73b676ce12c040362132cdd538bt
9da57d7b0ddd8d73b676ce12c040362132cdd538bt /*
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 */
9da57d7b0ddd8d73b676ce12c040362132cdd538bt (void) nvlist_lookup_uint64(nv, ZPOOL_CONFIG_NOT_PRESENT,
9da57d7b0ddd8d73b676ce12c040362132cdd538bt &vd->vdev_not_present);
9da57d7b0ddd8d73b676ce12c040362132cdd538bt
9da57d7b0ddd8d73b676ce12c040362132cdd538bt /*
0dc2366f7b9f9f36e10909b1e95edbf2a261c2acVenugopal Iyer * Get the alignment requirement.
0dc2366f7b9f9f36e10909b1e95edbf2a261c2acVenugopal Iyer */
0dc2366f7b9f9f36e10909b1e95edbf2a261c2acVenugopal Iyer (void) nvlist_lookup_uint64(nv, ZPOOL_CONFIG_ASHIFT, &vd->vdev_ashift);
0dc2366f7b9f9f36e10909b1e95edbf2a261c2acVenugopal Iyer
0dc2366f7b9f9f36e10909b1e95edbf2a261c2acVenugopal Iyer /*
0dc2366f7b9f9f36e10909b1e95edbf2a261c2acVenugopal Iyer * Retrieve the vdev creation time.
0dc2366f7b9f9f36e10909b1e95edbf2a261c2acVenugopal Iyer */
0dc2366f7b9f9f36e10909b1e95edbf2a261c2acVenugopal Iyer (void) nvlist_lookup_uint64(nv, ZPOOL_CONFIG_CREATE_TXG,
9da57d7b0ddd8d73b676ce12c040362132cdd538bt &vd->vdev_crtxg);
9da57d7b0ddd8d73b676ce12c040362132cdd538bt
9da57d7b0ddd8d73b676ce12c040362132cdd538bt /*
9da57d7b0ddd8d73b676ce12c040362132cdd538bt * If we're a top-level vdev, try to load the allocation parameters.
9da57d7b0ddd8d73b676ce12c040362132cdd538bt */
9da57d7b0ddd8d73b676ce12c040362132cdd538bt if (parent && !parent->vdev_parent &&
9da57d7b0ddd8d73b676ce12c040362132cdd538bt (alloctype == VDEV_ALLOC_LOAD || alloctype == VDEV_ALLOC_SPLIT)) {
9da57d7b0ddd8d73b676ce12c040362132cdd538bt (void) nvlist_lookup_uint64(nv, ZPOOL_CONFIG_METASLAB_ARRAY,
9da57d7b0ddd8d73b676ce12c040362132cdd538bt &vd->vdev_ms_array);
9da57d7b0ddd8d73b676ce12c040362132cdd538bt (void) nvlist_lookup_uint64(nv, ZPOOL_CONFIG_METASLAB_SHIFT,
9da57d7b0ddd8d73b676ce12c040362132cdd538bt &vd->vdev_ms_shift);
9da57d7b0ddd8d73b676ce12c040362132cdd538bt (void) nvlist_lookup_uint64(nv, ZPOOL_CONFIG_ASIZE,
9da57d7b0ddd8d73b676ce12c040362132cdd538bt &vd->vdev_asize);
9da57d7b0ddd8d73b676ce12c040362132cdd538bt (void) nvlist_lookup_uint64(nv, ZPOOL_CONFIG_REMOVING,
9da57d7b0ddd8d73b676ce12c040362132cdd538bt &vd->vdev_removing);
9da57d7b0ddd8d73b676ce12c040362132cdd538bt }
9da57d7b0ddd8d73b676ce12c040362132cdd538bt
9da57d7b0ddd8d73b676ce12c040362132cdd538bt if (parent && !parent->vdev_parent && alloctype != VDEV_ALLOC_ATTACH) {
9da57d7b0ddd8d73b676ce12c040362132cdd538bt ASSERT(alloctype == VDEV_ALLOC_LOAD ||
9da57d7b0ddd8d73b676ce12c040362132cdd538bt alloctype == VDEV_ALLOC_ADD ||
9da57d7b0ddd8d73b676ce12c040362132cdd538bt alloctype == VDEV_ALLOC_SPLIT ||
9da57d7b0ddd8d73b676ce12c040362132cdd538bt alloctype == VDEV_ALLOC_ROOTPOOL);
9da57d7b0ddd8d73b676ce12c040362132cdd538bt vd->vdev_mg = metaslab_group_create(islog ?
9da57d7b0ddd8d73b676ce12c040362132cdd538bt spa_log_class(spa) : spa_normal_class(spa), vd);
73cd555c10e70dac413ae4b40de8450a291750acBin Tu - Sun Microsystems - Beijing China }
73cd555c10e70dac413ae4b40de8450a291750acBin Tu - Sun Microsystems - Beijing China
9da57d7b0ddd8d73b676ce12c040362132cdd538bt /*
9da57d7b0ddd8d73b676ce12c040362132cdd538bt * If we're a leaf vdev, try to load the DTL object and other state.
9da57d7b0ddd8d73b676ce12c040362132cdd538bt */
9da57d7b0ddd8d73b676ce12c040362132cdd538bt if (vd->vdev_ops->vdev_op_leaf &&
9da57d7b0ddd8d73b676ce12c040362132cdd538bt (alloctype == VDEV_ALLOC_LOAD || alloctype == VDEV_ALLOC_L2CACHE ||
9da57d7b0ddd8d73b676ce12c040362132cdd538bt alloctype == VDEV_ALLOC_ROOTPOOL)) {
9da57d7b0ddd8d73b676ce12c040362132cdd538bt if (alloctype == VDEV_ALLOC_LOAD) {
9da57d7b0ddd8d73b676ce12c040362132cdd538bt (void) nvlist_lookup_uint64(nv, ZPOOL_CONFIG_DTL,
9da57d7b0ddd8d73b676ce12c040362132cdd538bt &vd->vdev_dtl_object);
9da57d7b0ddd8d73b676ce12c040362132cdd538bt (void) nvlist_lookup_uint64(nv, ZPOOL_CONFIG_UNSPARE,
9da57d7b0ddd8d73b676ce12c040362132cdd538bt &vd->vdev_unspare);
9da57d7b0ddd8d73b676ce12c040362132cdd538bt }
13740cb230f19fcbf1a6468d1a6a0ba9a0a09c22Paul Guo
62e6e1adfc8d795f477410703cc7a88dc5b82622Paul Guo if (alloctype == VDEV_ALLOC_ROOTPOOL) {
13740cb230f19fcbf1a6468d1a6a0ba9a0a09c22Paul Guo uint64_t spare = 0;
5b6dd21f5401160f9a62ac2e76a858c2bc105370chenlu chen - Sun Microsystems - Beijing China
62e6e1adfc8d795f477410703cc7a88dc5b82622Paul Guo if (nvlist_lookup_uint64(nv, ZPOOL_CONFIG_IS_SPARE,
13740cb230f19fcbf1a6468d1a6a0ba9a0a09c22Paul Guo &spare) == 0 && spare)
5b6dd21f5401160f9a62ac2e76a858c2bc105370chenlu chen - Sun Microsystems - Beijing China spa_spare_add(vd);
13740cb230f19fcbf1a6468d1a6a0ba9a0a09c22Paul Guo }
13740cb230f19fcbf1a6468d1a6a0ba9a0a09c22Paul Guo
62e6e1adfc8d795f477410703cc7a88dc5b82622Paul Guo (void) nvlist_lookup_uint64(nv, ZPOOL_CONFIG_OFFLINE,
13740cb230f19fcbf1a6468d1a6a0ba9a0a09c22Paul Guo &vd->vdev_offline);
5b6dd21f5401160f9a62ac2e76a858c2bc105370chenlu chen - Sun Microsystems - Beijing China
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
5b6dd21f5401160f9a62ac2e76a858c2bc105370chenlu chen - Sun Microsystems - Beijing China /*
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 */
5b6dd21f5401160f9a62ac2e76a858c2bc105370chenlu chen - Sun Microsystems - Beijing China if (spa_load_state(spa) == SPA_LOAD_OPEN) {
9da57d7b0ddd8d73b676ce12c040362132cdd538bt (void) nvlist_lookup_uint64(nv, ZPOOL_CONFIG_FAULTED,
9da57d7b0ddd8d73b676ce12c040362132cdd538bt &vd->vdev_faulted);
9da57d7b0ddd8d73b676ce12c040362132cdd538bt (void) nvlist_lookup_uint64(nv, ZPOOL_CONFIG_DEGRADED,
9da57d7b0ddd8d73b676ce12c040362132cdd538bt &vd->vdev_degraded);
9da57d7b0ddd8d73b676ce12c040362132cdd538bt (void) nvlist_lookup_uint64(nv, ZPOOL_CONFIG_REMOVED,
9da57d7b0ddd8d73b676ce12c040362132cdd538bt &vd->vdev_removed);
9da57d7b0ddd8d73b676ce12c040362132cdd538bt
9da57d7b0ddd8d73b676ce12c040362132cdd538bt if (vd->vdev_faulted || vd->vdev_degraded) {
9da57d7b0ddd8d73b676ce12c040362132cdd538bt char *aux;
9da57d7b0ddd8d73b676ce12c040362132cdd538bt
9da57d7b0ddd8d73b676ce12c040362132cdd538bt vd->vdev_label_aux =
9da57d7b0ddd8d73b676ce12c040362132cdd538bt VDEV_AUX_ERR_EXCEEDED;
9da57d7b0ddd8d73b676ce12c040362132cdd538bt if (nvlist_lookup_string(nv,
9da57d7b0ddd8d73b676ce12c040362132cdd538bt ZPOOL_CONFIG_AUX_STATE, &aux) == 0 &&
9da57d7b0ddd8d73b676ce12c040362132cdd538bt strcmp(aux, "external") == 0)
9da57d7b0ddd8d73b676ce12c040362132cdd538bt vd->vdev_label_aux = VDEV_AUX_EXTERNAL;
9da57d7b0ddd8d73b676ce12c040362132cdd538bt }
9da57d7b0ddd8d73b676ce12c040362132cdd538bt }
9da57d7b0ddd8d73b676ce12c040362132cdd538bt }
9da57d7b0ddd8d73b676ce12c040362132cdd538bt
9da57d7b0ddd8d73b676ce12c040362132cdd538bt /*
9da57d7b0ddd8d73b676ce12c040362132cdd538bt * Add ourselves to the parent's list of children.
9da57d7b0ddd8d73b676ce12c040362132cdd538bt */
9da57d7b0ddd8d73b676ce12c040362132cdd538bt vdev_add_child(parent, vd);
62e6e1adfc8d795f477410703cc7a88dc5b82622Paul Guo
62e6e1adfc8d795f477410703cc7a88dc5b82622Paul Guo *vdp = vd;
62e6e1adfc8d795f477410703cc7a88dc5b82622Paul Guo
9da57d7b0ddd8d73b676ce12c040362132cdd538bt return (0);
9da57d7b0ddd8d73b676ce12c040362132cdd538bt}
9da57d7b0ddd8d73b676ce12c040362132cdd538bt
9da57d7b0ddd8d73b676ce12c040362132cdd538btvoid
9da57d7b0ddd8d73b676ce12c040362132cdd538btvdev_free(vdev_t *vd)
9da57d7b0ddd8d73b676ce12c040362132cdd538bt{
9da57d7b0ddd8d73b676ce12c040362132cdd538bt spa_t *spa = vd->vdev_spa;
9da57d7b0ddd8d73b676ce12c040362132cdd538bt
9da57d7b0ddd8d73b676ce12c040362132cdd538bt /*
9da57d7b0ddd8d73b676ce12c040362132cdd538bt * vdev_free() implies closing the vdev first. This is simpler than
9da57d7b0ddd8d73b676ce12c040362132cdd538bt * trying to ensure complicated semantics for all callers.
9da57d7b0ddd8d73b676ce12c040362132cdd538bt */
9da57d7b0ddd8d73b676ce12c040362132cdd538bt vdev_close(vd);
9da57d7b0ddd8d73b676ce12c040362132cdd538bt
9da57d7b0ddd8d73b676ce12c040362132cdd538bt ASSERT(!list_link_active(&vd->vdev_config_dirty_node));
9da57d7b0ddd8d73b676ce12c040362132cdd538bt ASSERT(!list_link_active(&vd->vdev_state_dirty_node));
9da57d7b0ddd8d73b676ce12c040362132cdd538bt
9da57d7b0ddd8d73b676ce12c040362132cdd538bt /*
9da57d7b0ddd8d73b676ce12c040362132cdd538bt * Free all children.
9da57d7b0ddd8d73b676ce12c040362132cdd538bt */
9da57d7b0ddd8d73b676ce12c040362132cdd538bt for (int c = 0; c < vd->vdev_children; c++)
9da57d7b0ddd8d73b676ce12c040362132cdd538bt vdev_free(vd->vdev_child[c]);
9da57d7b0ddd8d73b676ce12c040362132cdd538bt
13740cb230f19fcbf1a6468d1a6a0ba9a0a09c22Paul Guo ASSERT(vd->vdev_child == NULL);
9da57d7b0ddd8d73b676ce12c040362132cdd538bt ASSERT(vd->vdev_guid_sum == vd->vdev_guid);
9da57d7b0ddd8d73b676ce12c040362132cdd538bt
62e6e1adfc8d795f477410703cc7a88dc5b82622Paul Guo /*
62e6e1adfc8d795f477410703cc7a88dc5b82622Paul Guo * Discard allocation state.
62e6e1adfc8d795f477410703cc7a88dc5b82622Paul Guo */
62e6e1adfc8d795f477410703cc7a88dc5b82622Paul Guo if (vd->vdev_mg != NULL) {
62e6e1adfc8d795f477410703cc7a88dc5b82622Paul Guo vdev_metaslab_fini(vd);
62e6e1adfc8d795f477410703cc7a88dc5b82622Paul Guo metaslab_group_destroy(vd->vdev_mg);
62e6e1adfc8d795f477410703cc7a88dc5b82622Paul Guo }
62e6e1adfc8d795f477410703cc7a88dc5b82622Paul Guo
9da57d7b0ddd8d73b676ce12c040362132cdd538bt ASSERT0(vd->vdev_stat.vs_space);
9da57d7b0ddd8d73b676ce12c040362132cdd538bt ASSERT0(vd->vdev_stat.vs_dspace);
9da57d7b0ddd8d73b676ce12c040362132cdd538bt ASSERT0(vd->vdev_stat.vs_alloc);
9da57d7b0ddd8d73b676ce12c040362132cdd538bt
9da57d7b0ddd8d73b676ce12c040362132cdd538bt /*
9da57d7b0ddd8d73b676ce12c040362132cdd538bt * Remove this vdev from its parent's child list.
9da57d7b0ddd8d73b676ce12c040362132cdd538bt */
9da57d7b0ddd8d73b676ce12c040362132cdd538bt vdev_remove_child(vd->vdev_parent, vd);
9da57d7b0ddd8d73b676ce12c040362132cdd538bt
9da57d7b0ddd8d73b676ce12c040362132cdd538bt ASSERT(vd->vdev_parent == NULL);
ffd8e8832e01f996f32459073f4dd308fe5265baWinson Wang - Sun Microsystems - Beijing China
62e6e1adfc8d795f477410703cc7a88dc5b82622Paul Guo /*
9da57d7b0ddd8d73b676ce12c040362132cdd538bt * Clean up vdev structure.
9da57d7b0ddd8d73b676ce12c040362132cdd538bt */
9da57d7b0ddd8d73b676ce12c040362132cdd538bt vdev_queue_fini(vd);
9da57d7b0ddd8d73b676ce12c040362132cdd538bt vdev_cache_fini(vd);
9da57d7b0ddd8d73b676ce12c040362132cdd538bt
9da57d7b0ddd8d73b676ce12c040362132cdd538bt if (vd->vdev_path)
9da57d7b0ddd8d73b676ce12c040362132cdd538bt spa_strfree(vd->vdev_path);
9da57d7b0ddd8d73b676ce12c040362132cdd538bt if (vd->vdev_devid)
9da57d7b0ddd8d73b676ce12c040362132cdd538bt spa_strfree(vd->vdev_devid);
9da57d7b0ddd8d73b676ce12c040362132cdd538bt if (vd->vdev_physpath)
9da57d7b0ddd8d73b676ce12c040362132cdd538bt spa_strfree(vd->vdev_physpath);
9da57d7b0ddd8d73b676ce12c040362132cdd538bt if (vd->vdev_fru)
9da57d7b0ddd8d73b676ce12c040362132cdd538bt spa_strfree(vd->vdev_fru);
9da57d7b0ddd8d73b676ce12c040362132cdd538bt
9da57d7b0ddd8d73b676ce12c040362132cdd538bt if (vd->vdev_isspare)
9da57d7b0ddd8d73b676ce12c040362132cdd538bt spa_spare_remove(vd);
9da57d7b0ddd8d73b676ce12c040362132cdd538bt if (vd->vdev_isl2cache)
9da57d7b0ddd8d73b676ce12c040362132cdd538bt spa_l2cache_remove(vd);
9da57d7b0ddd8d73b676ce12c040362132cdd538bt
9da57d7b0ddd8d73b676ce12c040362132cdd538bt txg_list_destroy(&vd->vdev_ms_list);
9da57d7b0ddd8d73b676ce12c040362132cdd538bt txg_list_destroy(&vd->vdev_dtl_list);
9da57d7b0ddd8d73b676ce12c040362132cdd538bt
9da57d7b0ddd8d73b676ce12c040362132cdd538bt mutex_enter(&vd->vdev_dtl_lock);
9da57d7b0ddd8d73b676ce12c040362132cdd538bt space_map_close(vd->vdev_dtl_sm);
9da57d7b0ddd8d73b676ce12c040362132cdd538bt for (int t = 0; t < DTL_TYPES; t++) {
9da57d7b0ddd8d73b676ce12c040362132cdd538bt range_tree_vacate(vd->vdev_dtl[t], NULL, NULL);
9da57d7b0ddd8d73b676ce12c040362132cdd538bt range_tree_destroy(vd->vdev_dtl[t]);
9da57d7b0ddd8d73b676ce12c040362132cdd538bt }
9da57d7b0ddd8d73b676ce12c040362132cdd538bt mutex_exit(&vd->vdev_dtl_lock);
9da57d7b0ddd8d73b676ce12c040362132cdd538bt
9da57d7b0ddd8d73b676ce12c040362132cdd538bt mutex_destroy(&vd->vdev_dtl_lock);
9da57d7b0ddd8d73b676ce12c040362132cdd538bt mutex_destroy(&vd->vdev_stat_lock);
9da57d7b0ddd8d73b676ce12c040362132cdd538bt mutex_destroy(&vd->vdev_probe_lock);
9da57d7b0ddd8d73b676ce12c040362132cdd538bt
9da57d7b0ddd8d73b676ce12c040362132cdd538bt if (vd == spa->spa_root_vdev)
9da57d7b0ddd8d73b676ce12c040362132cdd538bt spa->spa_root_vdev = NULL;
9da57d7b0ddd8d73b676ce12c040362132cdd538bt
9da57d7b0ddd8d73b676ce12c040362132cdd538bt kmem_free(vd, sizeof (vdev_t));
9da57d7b0ddd8d73b676ce12c040362132cdd538bt}
9da57d7b0ddd8d73b676ce12c040362132cdd538bt
9da57d7b0ddd8d73b676ce12c040362132cdd538bt/*
9da57d7b0ddd8d73b676ce12c040362132cdd538bt * Transfer top-level vdev state from svd to tvd.
9da57d7b0ddd8d73b676ce12c040362132cdd538bt */
9da57d7b0ddd8d73b676ce12c040362132cdd538btstatic void
9da57d7b0ddd8d73b676ce12c040362132cdd538btvdev_top_transfer(vdev_t *svd, vdev_t *tvd)
9da57d7b0ddd8d73b676ce12c040362132cdd538bt{
9da57d7b0ddd8d73b676ce12c040362132cdd538bt spa_t *spa = svd->vdev_spa;
9da57d7b0ddd8d73b676ce12c040362132cdd538bt metaslab_t *msp;
9da57d7b0ddd8d73b676ce12c040362132cdd538bt vdev_t *vd;
9da57d7b0ddd8d73b676ce12c040362132cdd538bt int t;
9da57d7b0ddd8d73b676ce12c040362132cdd538bt
9da57d7b0ddd8d73b676ce12c040362132cdd538bt ASSERT(tvd == tvd->vdev_top);
9da57d7b0ddd8d73b676ce12c040362132cdd538bt
9da57d7b0ddd8d73b676ce12c040362132cdd538bt tvd->vdev_ms_array = svd->vdev_ms_array;
9da57d7b0ddd8d73b676ce12c040362132cdd538bt tvd->vdev_ms_shift = svd->vdev_ms_shift;
9da57d7b0ddd8d73b676ce12c040362132cdd538bt tvd->vdev_ms_count = svd->vdev_ms_count;
62e6e1adfc8d795f477410703cc7a88dc5b82622Paul Guo
62e6e1adfc8d795f477410703cc7a88dc5b82622Paul Guo svd->vdev_ms_array = 0;
ea65739ebec0cbd625d8c89e19592be58fa186a6chenlu chen - Sun Microsystems - Beijing China svd->vdev_ms_shift = 0;
9da57d7b0ddd8d73b676ce12c040362132cdd538bt svd->vdev_ms_count = 0;
9da57d7b0ddd8d73b676ce12c040362132cdd538bt
9da57d7b0ddd8d73b676ce12c040362132cdd538bt if (tvd->vdev_mg)
62e6e1adfc8d795f477410703cc7a88dc5b82622Paul Guo ASSERT3P(tvd->vdev_mg, ==, svd->vdev_mg);
9da57d7b0ddd8d73b676ce12c040362132cdd538bt tvd->vdev_mg = svd->vdev_mg;
9da57d7b0ddd8d73b676ce12c040362132cdd538bt tvd->vdev_ms = svd->vdev_ms;
9da57d7b0ddd8d73b676ce12c040362132cdd538bt
9da57d7b0ddd8d73b676ce12c040362132cdd538bt svd->vdev_mg = NULL;
9da57d7b0ddd8d73b676ce12c040362132cdd538bt svd->vdev_ms = NULL;
9da57d7b0ddd8d73b676ce12c040362132cdd538bt
9da57d7b0ddd8d73b676ce12c040362132cdd538bt if (tvd->vdev_mg != NULL)
9da57d7b0ddd8d73b676ce12c040362132cdd538bt tvd->vdev_mg->mg_vd = tvd;
9da57d7b0ddd8d73b676ce12c040362132cdd538bt
9da57d7b0ddd8d73b676ce12c040362132cdd538bt tvd->vdev_stat.vs_alloc = svd->vdev_stat.vs_alloc;
9da57d7b0ddd8d73b676ce12c040362132cdd538bt tvd->vdev_stat.vs_space = svd->vdev_stat.vs_space;
9da57d7b0ddd8d73b676ce12c040362132cdd538bt tvd->vdev_stat.vs_dspace = svd->vdev_stat.vs_dspace;
9da57d7b0ddd8d73b676ce12c040362132cdd538bt
9da57d7b0ddd8d73b676ce12c040362132cdd538bt svd->vdev_stat.vs_alloc = 0;
9da57d7b0ddd8d73b676ce12c040362132cdd538bt svd->vdev_stat.vs_space = 0;
9da57d7b0ddd8d73b676ce12c040362132cdd538bt svd->vdev_stat.vs_dspace = 0;
9da57d7b0ddd8d73b676ce12c040362132cdd538bt
9da57d7b0ddd8d73b676ce12c040362132cdd538bt for (t = 0; t < TXG_SIZE; t++) {
9da57d7b0ddd8d73b676ce12c040362132cdd538bt while ((msp = txg_list_remove(&svd->vdev_ms_list, t)) != NULL)
9da57d7b0ddd8d73b676ce12c040362132cdd538bt (void) txg_list_add(&tvd->vdev_ms_list, msp, t);
9da57d7b0ddd8d73b676ce12c040362132cdd538bt while ((vd = txg_list_remove(&svd->vdev_dtl_list, t)) != NULL)
9da57d7b0ddd8d73b676ce12c040362132cdd538bt (void) txg_list_add(&tvd->vdev_dtl_list, vd, t);
9da57d7b0ddd8d73b676ce12c040362132cdd538bt if (txg_list_remove_this(&spa->spa_vdev_txg_list, svd, t))
9da57d7b0ddd8d73b676ce12c040362132cdd538bt (void) txg_list_add(&spa->spa_vdev_txg_list, tvd, t);
9da57d7b0ddd8d73b676ce12c040362132cdd538bt }
9da57d7b0ddd8d73b676ce12c040362132cdd538bt
62e6e1adfc8d795f477410703cc7a88dc5b82622Paul Guo if (list_link_active(&svd->vdev_config_dirty_node)) {
62e6e1adfc8d795f477410703cc7a88dc5b82622Paul Guo vdev_config_clean(svd);
62e6e1adfc8d795f477410703cc7a88dc5b82622Paul Guo vdev_config_dirty(tvd);
62e6e1adfc8d795f477410703cc7a88dc5b82622Paul Guo }
62e6e1adfc8d795f477410703cc7a88dc5b82622Paul Guo
62e6e1adfc8d795f477410703cc7a88dc5b82622Paul Guo if (list_link_active(&svd->vdev_state_dirty_node)) {
62e6e1adfc8d795f477410703cc7a88dc5b82622Paul Guo vdev_state_clean(svd);
62e6e1adfc8d795f477410703cc7a88dc5b82622Paul Guo vdev_state_dirty(tvd);
62e6e1adfc8d795f477410703cc7a88dc5b82622Paul Guo }
62e6e1adfc8d795f477410703cc7a88dc5b82622Paul Guo
9da57d7b0ddd8d73b676ce12c040362132cdd538bt tvd->vdev_deflate_ratio = svd->vdev_deflate_ratio;
9da57d7b0ddd8d73b676ce12c040362132cdd538bt svd->vdev_deflate_ratio = 0;
9da57d7b0ddd8d73b676ce12c040362132cdd538bt
9da57d7b0ddd8d73b676ce12c040362132cdd538bt tvd->vdev_islog = svd->vdev_islog;
9da57d7b0ddd8d73b676ce12c040362132cdd538bt svd->vdev_islog = 0;
9da57d7b0ddd8d73b676ce12c040362132cdd538bt}
9da57d7b0ddd8d73b676ce12c040362132cdd538bt
9da57d7b0ddd8d73b676ce12c040362132cdd538btstatic void
9da57d7b0ddd8d73b676ce12c040362132cdd538btvdev_top_update(vdev_t *tvd, vdev_t *vd)
9da57d7b0ddd8d73b676ce12c040362132cdd538bt{
9da57d7b0ddd8d73b676ce12c040362132cdd538bt if (vd == NULL)
9da57d7b0ddd8d73b676ce12c040362132cdd538bt return;
9da57d7b0ddd8d73b676ce12c040362132cdd538bt
9da57d7b0ddd8d73b676ce12c040362132cdd538bt vd->vdev_top = tvd;
9da57d7b0ddd8d73b676ce12c040362132cdd538bt
9da57d7b0ddd8d73b676ce12c040362132cdd538bt for (int c = 0; c < vd->vdev_children; c++)
9da57d7b0ddd8d73b676ce12c040362132cdd538bt vdev_top_update(tvd, vd->vdev_child[c]);
9da57d7b0ddd8d73b676ce12c040362132cdd538bt}
9da57d7b0ddd8d73b676ce12c040362132cdd538bt
9da57d7b0ddd8d73b676ce12c040362132cdd538bt/*
9da57d7b0ddd8d73b676ce12c040362132cdd538bt * Add a mirror/replacing vdev above an existing vdev.
13740cb230f19fcbf1a6468d1a6a0ba9a0a09c22Paul Guo */
62e6e1adfc8d795f477410703cc7a88dc5b82622Paul Guovdev_t *
13740cb230f19fcbf1a6468d1a6a0ba9a0a09c22Paul Guovdev_add_parent(vdev_t *cvd, vdev_ops_t *ops)
62e6e1adfc8d795f477410703cc7a88dc5b82622Paul Guo{
62e6e1adfc8d795f477410703cc7a88dc5b82622Paul Guo spa_t *spa = cvd->vdev_spa;
13740cb230f19fcbf1a6468d1a6a0ba9a0a09c22Paul Guo vdev_t *pvd = cvd->vdev_parent;
13740cb230f19fcbf1a6468d1a6a0ba9a0a09c22Paul Guo vdev_t *mvd;
5b6dd21f5401160f9a62ac2e76a858c2bc105370chenlu chen - Sun Microsystems - Beijing China
5b6dd21f5401160f9a62ac2e76a858c2bc105370chenlu chen - Sun Microsystems - Beijing China ASSERT(spa_config_held(spa, SCL_ALL, RW_WRITER) == SCL_ALL);
5b6dd21f5401160f9a62ac2e76a858c2bc105370chenlu chen - Sun Microsystems - Beijing China
5b6dd21f5401160f9a62ac2e76a858c2bc105370chenlu chen - Sun Microsystems - Beijing China mvd = vdev_alloc_common(spa, cvd->vdev_id, 0, ops);
5b6dd21f5401160f9a62ac2e76a858c2bc105370chenlu chen - Sun Microsystems - Beijing China
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;
9da57d7b0ddd8d73b676ce12c040362132cdd538bt mvd->vdev_max_asize = cvd->vdev_max_asize;
9da57d7b0ddd8d73b676ce12c040362132cdd538bt mvd->vdev_ashift = cvd->vdev_ashift;
9da57d7b0ddd8d73b676ce12c040362132cdd538bt mvd->vdev_state = cvd->vdev_state;
9da57d7b0ddd8d73b676ce12c040362132cdd538bt mvd->vdev_crtxg = cvd->vdev_crtxg;
9da57d7b0ddd8d73b676ce12c040362132cdd538bt
9da57d7b0ddd8d73b676ce12c040362132cdd538bt vdev_remove_child(pvd, cvd);
9da57d7b0ddd8d73b676ce12c040362132cdd538bt vdev_add_child(pvd, mvd);
0dc2366f7b9f9f36e10909b1e95edbf2a261c2acVenugopal Iyer cvd->vdev_id = mvd->vdev_children;
0dc2366f7b9f9f36e10909b1e95edbf2a261c2acVenugopal Iyer vdev_add_child(mvd, cvd);
0dc2366f7b9f9f36e10909b1e95edbf2a261c2acVenugopal Iyer vdev_top_update(cvd->vdev_top, cvd->vdev_top);
0dc2366f7b9f9f36e10909b1e95edbf2a261c2acVenugopal Iyer
0dc2366f7b9f9f36e10909b1e95edbf2a261c2acVenugopal Iyer if (mvd == mvd->vdev_top)
9da57d7b0ddd8d73b676ce12c040362132cdd538bt vdev_top_transfer(cvd, mvd);
9da57d7b0ddd8d73b676ce12c040362132cdd538bt
9da57d7b0ddd8d73b676ce12c040362132cdd538bt return (mvd);
9da57d7b0ddd8d73b676ce12c040362132cdd538bt}
9da57d7b0ddd8d73b676ce12c040362132cdd538bt
9da57d7b0ddd8d73b676ce12c040362132cdd538bt/*
9da57d7b0ddd8d73b676ce12c040362132cdd538bt * Remove a 1-way mirror/replacing vdev from the tree.
9da57d7b0ddd8d73b676ce12c040362132cdd538bt */
9da57d7b0ddd8d73b676ce12c040362132cdd538btvoid
9da57d7b0ddd8d73b676ce12c040362132cdd538btvdev_remove_parent(vdev_t *cvd)
9da57d7b0ddd8d73b676ce12c040362132cdd538bt{
9da57d7b0ddd8d73b676ce12c040362132cdd538bt vdev_t *mvd = cvd->vdev_parent;
9da57d7b0ddd8d73b676ce12c040362132cdd538bt vdev_t *pvd = mvd->vdev_parent;
9da57d7b0ddd8d73b676ce12c040362132cdd538bt
9da57d7b0ddd8d73b676ce12c040362132cdd538bt ASSERT(spa_config_held(cvd->vdev_spa, SCL_ALL, RW_WRITER) == SCL_ALL);
9da57d7b0ddd8d73b676ce12c040362132cdd538bt
9da57d7b0ddd8d73b676ce12c040362132cdd538bt ASSERT(mvd->vdev_children == 1);
9da57d7b0ddd8d73b676ce12c040362132cdd538bt ASSERT(mvd->vdev_ops == &vdev_mirror_ops ||
9da57d7b0ddd8d73b676ce12c040362132cdd538bt mvd->vdev_ops == &vdev_replacing_ops ||
9da57d7b0ddd8d73b676ce12c040362132cdd538bt mvd->vdev_ops == &vdev_spare_ops);
9da57d7b0ddd8d73b676ce12c040362132cdd538bt cvd->vdev_ashift = mvd->vdev_ashift;
9da57d7b0ddd8d73b676ce12c040362132cdd538bt
9da57d7b0ddd8d73b676ce12c040362132cdd538bt vdev_remove_child(mvd, cvd);
9da57d7b0ddd8d73b676ce12c040362132cdd538bt vdev_remove_child(pvd, mvd);
9da57d7b0ddd8d73b676ce12c040362132cdd538bt
9da57d7b0ddd8d73b676ce12c040362132cdd538bt /*
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 */
9da57d7b0ddd8d73b676ce12c040362132cdd538bt if (mvd->vdev_top == mvd) {
9da57d7b0ddd8d73b676ce12c040362132cdd538bt uint64_t guid_delta = mvd->vdev_guid - cvd->vdev_guid;
9da57d7b0ddd8d73b676ce12c040362132cdd538bt cvd->vdev_orig_guid = cvd->vdev_guid;
9da57d7b0ddd8d73b676ce12c040362132cdd538bt cvd->vdev_guid += guid_delta;
9da57d7b0ddd8d73b676ce12c040362132cdd538bt cvd->vdev_guid_sum += guid_delta;
9da57d7b0ddd8d73b676ce12c040362132cdd538bt }
9da57d7b0ddd8d73b676ce12c040362132cdd538bt cvd->vdev_id = mvd->vdev_id;
9da57d7b0ddd8d73b676ce12c040362132cdd538bt vdev_add_child(pvd, cvd);
9da57d7b0ddd8d73b676ce12c040362132cdd538bt vdev_top_update(cvd->vdev_top, cvd->vdev_top);
9da57d7b0ddd8d73b676ce12c040362132cdd538bt
9da57d7b0ddd8d73b676ce12c040362132cdd538bt if (cvd == cvd->vdev_top)
9da57d7b0ddd8d73b676ce12c040362132cdd538bt vdev_top_transfer(mvd, cvd);
9da57d7b0ddd8d73b676ce12c040362132cdd538bt
9da57d7b0ddd8d73b676ce12c040362132cdd538bt ASSERT(mvd->vdev_children == 0);
9da57d7b0ddd8d73b676ce12c040362132cdd538bt vdev_free(mvd);
9da57d7b0ddd8d73b676ce12c040362132cdd538bt}
9da57d7b0ddd8d73b676ce12c040362132cdd538bt
9da57d7b0ddd8d73b676ce12c040362132cdd538btint
9da57d7b0ddd8d73b676ce12c040362132cdd538btvdev_metaslab_init(vdev_t *vd, uint64_t txg)
9da57d7b0ddd8d73b676ce12c040362132cdd538bt{
9da57d7b0ddd8d73b676ce12c040362132cdd538bt spa_t *spa = vd->vdev_spa;
9da57d7b0ddd8d73b676ce12c040362132cdd538bt objset_t *mos = spa->spa_meta_objset;
9da57d7b0ddd8d73b676ce12c040362132cdd538bt uint64_t m;
9da57d7b0ddd8d73b676ce12c040362132cdd538bt uint64_t oldc = vd->vdev_ms_count;
9da57d7b0ddd8d73b676ce12c040362132cdd538bt uint64_t newc = vd->vdev_asize >> vd->vdev_ms_shift;
9da57d7b0ddd8d73b676ce12c040362132cdd538bt metaslab_t **mspp;
9da57d7b0ddd8d73b676ce12c040362132cdd538bt int error;
9da57d7b0ddd8d73b676ce12c040362132cdd538bt
9da57d7b0ddd8d73b676ce12c040362132cdd538bt ASSERT(txg == 0 || spa_config_held(spa, SCL_ALLOC, RW_WRITER));
9da57d7b0ddd8d73b676ce12c040362132cdd538bt
9da57d7b0ddd8d73b676ce12c040362132cdd538bt /*
9da57d7b0ddd8d73b676ce12c040362132cdd538bt * This vdev is not being allocated from yet or is a hole.
9da57d7b0ddd8d73b676ce12c040362132cdd538bt */
9da57d7b0ddd8d73b676ce12c040362132cdd538bt if (vd->vdev_ms_shift == 0)
9da57d7b0ddd8d73b676ce12c040362132cdd538bt return (0);
9da57d7b0ddd8d73b676ce12c040362132cdd538bt
9da57d7b0ddd8d73b676ce12c040362132cdd538bt ASSERT(!vd->vdev_ishole);
9da57d7b0ddd8d73b676ce12c040362132cdd538bt
9da57d7b0ddd8d73b676ce12c040362132cdd538bt /*
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 */
9da57d7b0ddd8d73b676ce12c040362132cdd538bt vd->vdev_deflate_ratio = (1 << 17) /
9da57d7b0ddd8d73b676ce12c040362132cdd538bt (vdev_psize_to_asize(vd, 1 << 17) >> SPA_MINBLOCKSHIFT);
9da57d7b0ddd8d73b676ce12c040362132cdd538bt
9da57d7b0ddd8d73b676ce12c040362132cdd538bt ASSERT(oldc <= newc);
9da57d7b0ddd8d73b676ce12c040362132cdd538bt
9da57d7b0ddd8d73b676ce12c040362132cdd538bt mspp = kmem_zalloc(newc * sizeof (*mspp), KM_SLEEP);
9da57d7b0ddd8d73b676ce12c040362132cdd538bt
9da57d7b0ddd8d73b676ce12c040362132cdd538bt if (oldc != 0) {
ea65739ebec0cbd625d8c89e19592be58fa186a6chenlu chen - Sun Microsystems - Beijing China bcopy(vd->vdev_ms, mspp, oldc * sizeof (*mspp));
da14cebe459d3275048785f25bd869cb09b5307fEric Cheng kmem_free(vd->vdev_ms, oldc * sizeof (*mspp));
9da57d7b0ddd8d73b676ce12c040362132cdd538bt }
9da57d7b0ddd8d73b676ce12c040362132cdd538bt
9da57d7b0ddd8d73b676ce12c040362132cdd538bt vd->vdev_ms = mspp;
9da57d7b0ddd8d73b676ce12c040362132cdd538bt vd->vdev_ms_count = newc;
9da57d7b0ddd8d73b676ce12c040362132cdd538bt
9da57d7b0ddd8d73b676ce12c040362132cdd538bt for (m = oldc; m < newc; m++) {
9da57d7b0ddd8d73b676ce12c040362132cdd538bt uint64_t object = 0;
9da57d7b0ddd8d73b676ce12c040362132cdd538bt
9da57d7b0ddd8d73b676ce12c040362132cdd538bt if (txg == 0) {
9da57d7b0ddd8d73b676ce12c040362132cdd538bt error = dmu_read(mos, vd->vdev_ms_array,
9da57d7b0ddd8d73b676ce12c040362132cdd538bt m * sizeof (uint64_t), sizeof (uint64_t), &object,
9da57d7b0ddd8d73b676ce12c040362132cdd538bt DMU_READ_PREFETCH);
9da57d7b0ddd8d73b676ce12c040362132cdd538bt if (error)
9da57d7b0ddd8d73b676ce12c040362132cdd538bt return (error);
9da57d7b0ddd8d73b676ce12c040362132cdd538bt }
9da57d7b0ddd8d73b676ce12c040362132cdd538bt vd->vdev_ms[m] = metaslab_init(vd->vdev_mg, m, object, txg);
9da57d7b0ddd8d73b676ce12c040362132cdd538bt }
9da57d7b0ddd8d73b676ce12c040362132cdd538bt
9da57d7b0ddd8d73b676ce12c040362132cdd538bt if (txg == 0)
9da57d7b0ddd8d73b676ce12c040362132cdd538bt spa_config_enter(spa, SCL_ALLOC, FTAG, RW_WRITER);
9da57d7b0ddd8d73b676ce12c040362132cdd538bt
9da57d7b0ddd8d73b676ce12c040362132cdd538bt /*
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.
9da57d7b0ddd8d73b676ce12c040362132cdd538bt */
9da57d7b0ddd8d73b676ce12c040362132cdd538bt if (oldc == 0 && !vd->vdev_removing)
9da57d7b0ddd8d73b676ce12c040362132cdd538bt metaslab_group_activate(vd->vdev_mg);
9da57d7b0ddd8d73b676ce12c040362132cdd538bt
9da57d7b0ddd8d73b676ce12c040362132cdd538bt if (txg == 0)
9da57d7b0ddd8d73b676ce12c040362132cdd538bt spa_config_exit(spa, SCL_ALLOC, FTAG);
13740cb230f19fcbf1a6468d1a6a0ba9a0a09c22Paul Guo
13740cb230f19fcbf1a6468d1a6a0ba9a0a09c22Paul Guo return (0);
13740cb230f19fcbf1a6468d1a6a0ba9a0a09c22Paul Guo}
13740cb230f19fcbf1a6468d1a6a0ba9a0a09c22Paul Guo
13740cb230f19fcbf1a6468d1a6a0ba9a0a09c22Paul Guovoid
13740cb230f19fcbf1a6468d1a6a0ba9a0a09c22Paul Guovdev_metaslab_fini(vdev_t *vd)
13740cb230f19fcbf1a6468d1a6a0ba9a0a09c22Paul Guo{
13740cb230f19fcbf1a6468d1a6a0ba9a0a09c22Paul Guo uint64_t m;
13740cb230f19fcbf1a6468d1a6a0ba9a0a09c22Paul Guo uint64_t count = vd->vdev_ms_count;
13740cb230f19fcbf1a6468d1a6a0ba9a0a09c22Paul Guo
13740cb230f19fcbf1a6468d1a6a0ba9a0a09c22Paul Guo if (vd->vdev_ms != NULL) {
13740cb230f19fcbf1a6468d1a6a0ba9a0a09c22Paul Guo metaslab_group_passivate(vd->vdev_mg);
19843f01b1bef3453f717c23c8f89fb9313f6749Paul Guo for (m = 0; m < count; m++) {
13740cb230f19fcbf1a6468d1a6a0ba9a0a09c22Paul Guo metaslab_t *msp = vd->vdev_ms[m];
13740cb230f19fcbf1a6468d1a6a0ba9a0a09c22Paul Guo
13740cb230f19fcbf1a6468d1a6a0ba9a0a09c22Paul Guo if (msp != NULL)
13740cb230f19fcbf1a6468d1a6a0ba9a0a09c22Paul Guo metaslab_fini(msp);
13740cb230f19fcbf1a6468d1a6a0ba9a0a09c22Paul Guo }
5b6dd21f5401160f9a62ac2e76a858c2bc105370chenlu chen - Sun Microsystems - Beijing China kmem_free(vd->vdev_ms, count * sizeof (metaslab_t *));
13740cb230f19fcbf1a6468d1a6a0ba9a0a09c22Paul Guo vd->vdev_ms = NULL;
73cd555c10e70dac413ae4b40de8450a291750acBin Tu - Sun Microsystems - Beijing China }
5b6dd21f5401160f9a62ac2e76a858c2bc105370chenlu chen - Sun Microsystems - Beijing China}
73cd555c10e70dac413ae4b40de8450a291750acBin Tu - Sun Microsystems - Beijing China
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 China
5b6dd21f5401160f9a62ac2e76a858c2bc105370chenlu chen - Sun Microsystems - Beijing Chinastatic void
5b6dd21f5401160f9a62ac2e76a858c2bc105370chenlu chen - Sun Microsystems - Beijing Chinavdev_probe_done(zio_t *zio)
13740cb230f19fcbf1a6468d1a6a0ba9a0a09c22Paul Guo{
5b6dd21f5401160f9a62ac2e76a858c2bc105370chenlu chen - Sun Microsystems - Beijing China spa_t *spa = zio->io_spa;
69b5a878d62fdee1b12e78371ce6cc8abddcad15Dan McDonald vdev_t *vd = zio->io_vd;
69b5a878d62fdee1b12e78371ce6cc8abddcad15Dan McDonald vdev_probe_stats_t *vps = zio->io_private;
69b5a878d62fdee1b12e78371ce6cc8abddcad15Dan McDonald
69b5a878d62fdee1b12e78371ce6cc8abddcad15Dan McDonald ASSERT(vd->vdev_probe_zio != NULL);
69b5a878d62fdee1b12e78371ce6cc8abddcad15Dan McDonald
69b5a878d62fdee1b12e78371ce6cc8abddcad15Dan McDonald if (zio->io_type == ZIO_TYPE_READ) {
69b5a878d62fdee1b12e78371ce6cc8abddcad15Dan McDonald if (zio->io_error == 0)
69b5a878d62fdee1b12e78371ce6cc8abddcad15Dan McDonald vps->vps_readable = 1;
69b5a878d62fdee1b12e78371ce6cc8abddcad15Dan McDonald if (zio->io_error == 0 && spa_writeable(spa)) {
13740cb230f19fcbf1a6468d1a6a0ba9a0a09c22Paul Guo zio_nowait(zio_write_phys(vd->vdev_probe_zio, vd,
19843f01b1bef3453f717c23c8f89fb9313f6749Paul Guo zio->io_offset, zio->io_size, zio->io_data,
13740cb230f19fcbf1a6468d1a6a0ba9a0a09c22Paul Guo ZIO_CHECKSUM_OFF, vdev_probe_done, vps,
13740cb230f19fcbf1a6468d1a6a0ba9a0a09c22Paul Guo ZIO_PRIORITY_SYNC_WRITE, vps->vps_flags, B_TRUE));
13740cb230f19fcbf1a6468d1a6a0ba9a0a09c22Paul Guo } else {
13740cb230f19fcbf1a6468d1a6a0ba9a0a09c22Paul Guo zio_buf_free(zio->io_data, zio->io_size);
13740cb230f19fcbf1a6468d1a6a0ba9a0a09c22Paul Guo }
9da57d7b0ddd8d73b676ce12c040362132cdd538bt } else if (zio->io_type == ZIO_TYPE_WRITE) {
9da57d7b0ddd8d73b676ce12c040362132cdd538bt if (zio->io_error == 0)
9da57d7b0ddd8d73b676ce12c040362132cdd538bt vps->vps_writeable = 1;
9da57d7b0ddd8d73b676ce12c040362132cdd538bt zio_buf_free(zio->io_data, zio->io_size);
9da57d7b0ddd8d73b676ce12c040362132cdd538bt } else if (zio->io_type == ZIO_TYPE_NULL) {
9da57d7b0ddd8d73b676ce12c040362132cdd538bt zio_t *pio;
9da57d7b0ddd8d73b676ce12c040362132cdd538bt
9da57d7b0ddd8d73b676ce12c040362132cdd538bt vd->vdev_cant_read |= !vps->vps_readable;
9da57d7b0ddd8d73b676ce12c040362132cdd538bt vd->vdev_cant_write |= !vps->vps_writeable;
9da57d7b0ddd8d73b676ce12c040362132cdd538bt
9da57d7b0ddd8d73b676ce12c040362132cdd538bt if (vdev_readable(vd) &&
9da57d7b0ddd8d73b676ce12c040362132cdd538bt (vdev_writeable(vd) || !spa_writeable(spa))) {
9da57d7b0ddd8d73b676ce12c040362132cdd538bt zio->io_error = 0;
9da57d7b0ddd8d73b676ce12c040362132cdd538bt } else {
9da57d7b0ddd8d73b676ce12c040362132cdd538bt ASSERT(zio->io_error != 0);
9da57d7b0ddd8d73b676ce12c040362132cdd538bt zfs_ereport_post(FM_EREPORT_ZFS_PROBE_FAILURE,
9da57d7b0ddd8d73b676ce12c040362132cdd538bt spa, vd, NULL, 0, 0);
9da57d7b0ddd8d73b676ce12c040362132cdd538bt zio->io_error = SET_ERROR(ENXIO);
73cd555c10e70dac413ae4b40de8450a291750acBin Tu - Sun Microsystems - Beijing China }
73cd555c10e70dac413ae4b40de8450a291750acBin Tu - Sun Microsystems - Beijing China
9da57d7b0ddd8d73b676ce12c040362132cdd538bt mutex_enter(&vd->vdev_probe_lock);
9da57d7b0ddd8d73b676ce12c040362132cdd538bt ASSERT(vd->vdev_probe_zio == zio);
9da57d7b0ddd8d73b676ce12c040362132cdd538bt vd->vdev_probe_zio = NULL;
9da57d7b0ddd8d73b676ce12c040362132cdd538bt mutex_exit(&vd->vdev_probe_lock);
9da57d7b0ddd8d73b676ce12c040362132cdd538bt
9da57d7b0ddd8d73b676ce12c040362132cdd538bt while ((pio = zio_walk_parents(zio)) != NULL)
73cd555c10e70dac413ae4b40de8450a291750acBin Tu - Sun Microsystems - Beijing China if (!vdev_accessible(vd, pio))
9da57d7b0ddd8d73b676ce12c040362132cdd538bt pio->io_error = SET_ERROR(ENXIO);
9da57d7b0ddd8d73b676ce12c040362132cdd538bt
9da57d7b0ddd8d73b676ce12c040362132cdd538bt kmem_free(vps, sizeof (*vps));
9da57d7b0ddd8d73b676ce12c040362132cdd538bt }
9da57d7b0ddd8d73b676ce12c040362132cdd538bt}
9da57d7b0ddd8d73b676ce12c040362132cdd538bt
9da57d7b0ddd8d73b676ce12c040362132cdd538bt/*
9da57d7b0ddd8d73b676ce12c040362132cdd538bt * Determine whether this device is accessible.
9da57d7b0ddd8d73b676ce12c040362132cdd538bt *
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
9da57d7b0ddd8d73b676ce12c040362132cdd538bt * a VTOC.
9da57d7b0ddd8d73b676ce12c040362132cdd538bt */
9da57d7b0ddd8d73b676ce12c040362132cdd538btzio_t *
9da57d7b0ddd8d73b676ce12c040362132cdd538btvdev_probe(vdev_t *vd, zio_t *zio)
9da57d7b0ddd8d73b676ce12c040362132cdd538bt{
9da57d7b0ddd8d73b676ce12c040362132cdd538bt spa_t *spa = vd->vdev_spa;
9da57d7b0ddd8d73b676ce12c040362132cdd538bt vdev_probe_stats_t *vps = NULL;
9da57d7b0ddd8d73b676ce12c040362132cdd538bt zio_t *pio;
9da57d7b0ddd8d73b676ce12c040362132cdd538bt
ea65739ebec0cbd625d8c89e19592be58fa186a6chenlu chen - Sun Microsystems - Beijing China ASSERT(vd->vdev_ops->vdev_op_leaf);
ea65739ebec0cbd625d8c89e19592be58fa186a6chenlu chen - Sun Microsystems - Beijing China
9da57d7b0ddd8d73b676ce12c040362132cdd538bt /*
9da57d7b0ddd8d73b676ce12c040362132cdd538bt * Don't probe the probe.
9da57d7b0ddd8d73b676ce12c040362132cdd538bt */
9da57d7b0ddd8d73b676ce12c040362132cdd538bt if (zio && (zio->io_flags & ZIO_FLAG_PROBE))
9da57d7b0ddd8d73b676ce12c040362132cdd538bt return (NULL);
9da57d7b0ddd8d73b676ce12c040362132cdd538bt
9da57d7b0ddd8d73b676ce12c040362132cdd538bt /*
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 */
9da57d7b0ddd8d73b676ce12c040362132cdd538bt mutex_enter(&vd->vdev_probe_lock);
9da57d7b0ddd8d73b676ce12c040362132cdd538bt
da14cebe459d3275048785f25bd869cb09b5307fEric Cheng if ((pio = vd->vdev_probe_zio) == NULL) {
9da57d7b0ddd8d73b676ce12c040362132cdd538bt vps = kmem_zalloc(sizeof (*vps), KM_SLEEP);
0dc2366f7b9f9f36e10909b1e95edbf2a261c2acVenugopal Iyer
9da57d7b0ddd8d73b676ce12c040362132cdd538bt vps->vps_flags = ZIO_FLAG_CANFAIL | ZIO_FLAG_PROBE |
9da57d7b0ddd8d73b676ce12c040362132cdd538bt ZIO_FLAG_DONT_CACHE | ZIO_FLAG_DONT_AGGREGATE |
9da57d7b0ddd8d73b676ce12c040362132cdd538bt ZIO_FLAG_TRYHARD;
0dc2366f7b9f9f36e10909b1e95edbf2a261c2acVenugopal Iyer
9da57d7b0ddd8d73b676ce12c040362132cdd538bt if (spa_config_held(spa, SCL_ZIO, RW_WRITER)) {
9da57d7b0ddd8d73b676ce12c040362132cdd538bt /*
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 *
da14cebe459d3275048785f25bd869cb09b5307fEric Cheng * Since we hold SCL_ZIO as writer here, clear both
9da57d7b0ddd8d73b676ce12c040362132cdd538bt * values so the probe can reevaluate from first
9da57d7b0ddd8d73b676ce12c040362132cdd538bt * principles.
9da57d7b0ddd8d73b676ce12c040362132cdd538bt */
9da57d7b0ddd8d73b676ce12c040362132cdd538bt vps->vps_flags |= ZIO_FLAG_CONFIG_WRITER;
9da57d7b0ddd8d73b676ce12c040362132cdd538bt vd->vdev_cant_read = B_FALSE;
9da57d7b0ddd8d73b676ce12c040362132cdd538bt vd->vdev_cant_write = B_FALSE;
9da57d7b0ddd8d73b676ce12c040362132cdd538bt }
9da57d7b0ddd8d73b676ce12c040362132cdd538bt
9da57d7b0ddd8d73b676ce12c040362132cdd538bt vd->vdev_probe_zio = pio = zio_null(NULL, spa, vd,
9da57d7b0ddd8d73b676ce12c040362132cdd538bt vdev_probe_done, vps,
9da57d7b0ddd8d73b676ce12c040362132cdd538bt vps->vps_flags | ZIO_FLAG_DONT_PROPAGATE);
9da57d7b0ddd8d73b676ce12c040362132cdd538bt
9da57d7b0ddd8d73b676ce12c040362132cdd538bt /*
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.
9da57d7b0ddd8d73b676ce12c040362132cdd538bt */
9da57d7b0ddd8d73b676ce12c040362132cdd538bt if (zio != NULL) {
9da57d7b0ddd8d73b676ce12c040362132cdd538bt vd->vdev_probe_wanted = B_TRUE;
9da57d7b0ddd8d73b676ce12c040362132cdd538bt spa_async_request(spa, SPA_ASYNC_PROBE);
0dc2366f7b9f9f36e10909b1e95edbf2a261c2acVenugopal Iyer }
9da57d7b0ddd8d73b676ce12c040362132cdd538bt }
0dc2366f7b9f9f36e10909b1e95edbf2a261c2acVenugopal Iyer
9da57d7b0ddd8d73b676ce12c040362132cdd538bt if (zio != NULL)
9da57d7b0ddd8d73b676ce12c040362132cdd538bt zio_add_child(zio, pio);
9da57d7b0ddd8d73b676ce12c040362132cdd538bt
9da57d7b0ddd8d73b676ce12c040362132cdd538bt mutex_exit(&vd->vdev_probe_lock);
0dc2366f7b9f9f36e10909b1e95edbf2a261c2acVenugopal Iyer
0dc2366f7b9f9f36e10909b1e95edbf2a261c2acVenugopal Iyer if (vps == NULL) {
0dc2366f7b9f9f36e10909b1e95edbf2a261c2acVenugopal Iyer ASSERT(zio != NULL);
0dc2366f7b9f9f36e10909b1e95edbf2a261c2acVenugopal Iyer return (NULL);
0dc2366f7b9f9f36e10909b1e95edbf2a261c2acVenugopal Iyer }
0dc2366f7b9f9f36e10909b1e95edbf2a261c2acVenugopal Iyer
0dc2366f7b9f9f36e10909b1e95edbf2a261c2acVenugopal Iyer for (int l = 1; l < VDEV_LABELS; l++) {
0dc2366f7b9f9f36e10909b1e95edbf2a261c2acVenugopal Iyer zio_nowait(zio_read_phys(pio, vd,
9da57d7b0ddd8d73b676ce12c040362132cdd538bt vdev_label_offset(vd->vdev_psize, l,
9da57d7b0ddd8d73b676ce12c040362132cdd538bt offsetof(vdev_label_t, vl_pad2)),
9da57d7b0ddd8d73b676ce12c040362132cdd538bt VDEV_PAD_SIZE, zio_buf_alloc(VDEV_PAD_SIZE),
9da57d7b0ddd8d73b676ce12c040362132cdd538bt ZIO_CHECKSUM_OFF, vdev_probe_done, vps,
9da57d7b0ddd8d73b676ce12c040362132cdd538bt ZIO_PRIORITY_SYNC_READ, vps->vps_flags, B_TRUE));
9da57d7b0ddd8d73b676ce12c040362132cdd538bt }
9da57d7b0ddd8d73b676ce12c040362132cdd538bt
9da57d7b0ddd8d73b676ce12c040362132cdd538bt if (zio == NULL)
9da57d7b0ddd8d73b676ce12c040362132cdd538bt return (pio);
9da57d7b0ddd8d73b676ce12c040362132cdd538bt
9da57d7b0ddd8d73b676ce12c040362132cdd538bt zio_nowait(pio);
9da57d7b0ddd8d73b676ce12c040362132cdd538bt return (NULL);
9da57d7b0ddd8d73b676ce12c040362132cdd538bt}
9da57d7b0ddd8d73b676ce12c040362132cdd538bt
9da57d7b0ddd8d73b676ce12c040362132cdd538btstatic void
9da57d7b0ddd8d73b676ce12c040362132cdd538btvdev_open_child(void *arg)
9da57d7b0ddd8d73b676ce12c040362132cdd538bt{
9da57d7b0ddd8d73b676ce12c040362132cdd538bt vdev_t *vd = arg;
9da57d7b0ddd8d73b676ce12c040362132cdd538bt
73cd555c10e70dac413ae4b40de8450a291750acBin Tu - Sun Microsystems - Beijing China vd->vdev_open_thread = curthread;
9da57d7b0ddd8d73b676ce12c040362132cdd538bt vd->vdev_open_error = vdev_open(vd);
9da57d7b0ddd8d73b676ce12c040362132cdd538bt vd->vdev_open_thread = NULL;
9da57d7b0ddd8d73b676ce12c040362132cdd538bt}
9da57d7b0ddd8d73b676ce12c040362132cdd538bt
9da57d7b0ddd8d73b676ce12c040362132cdd538btboolean_t
9da57d7b0ddd8d73b676ce12c040362132cdd538btvdev_uses_zvols(vdev_t *vd)
73cd555c10e70dac413ae4b40de8450a291750acBin Tu - Sun Microsystems - Beijing China{
9da57d7b0ddd8d73b676ce12c040362132cdd538bt if (vd->vdev_path && strncmp(vd->vdev_path, ZVOL_DIR,
9da57d7b0ddd8d73b676ce12c040362132cdd538bt strlen(ZVOL_DIR)) == 0)
9da57d7b0ddd8d73b676ce12c040362132cdd538bt return (B_TRUE);
9da57d7b0ddd8d73b676ce12c040362132cdd538bt for (int c = 0; c < vd->vdev_children; c++)
9da57d7b0ddd8d73b676ce12c040362132cdd538bt if (vdev_uses_zvols(vd->vdev_child[c]))
9da57d7b0ddd8d73b676ce12c040362132cdd538bt return (B_TRUE);
9da57d7b0ddd8d73b676ce12c040362132cdd538bt return (B_FALSE);
9da57d7b0ddd8d73b676ce12c040362132cdd538bt}
9da57d7b0ddd8d73b676ce12c040362132cdd538bt
9da57d7b0ddd8d73b676ce12c040362132cdd538btvoid
9da57d7b0ddd8d73b676ce12c040362132cdd538btvdev_open_children(vdev_t *vd)
9da57d7b0ddd8d73b676ce12c040362132cdd538bt{
9da57d7b0ddd8d73b676ce12c040362132cdd538bt taskq_t *tq;
9da57d7b0ddd8d73b676ce12c040362132cdd538bt int children = vd->vdev_children;
9da57d7b0ddd8d73b676ce12c040362132cdd538bt
9da57d7b0ddd8d73b676ce12c040362132cdd538bt /*
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 */
9da57d7b0ddd8d73b676ce12c040362132cdd538bt if (vdev_uses_zvols(vd)) {
9da57d7b0ddd8d73b676ce12c040362132cdd538bt for (int c = 0; c < children; c++)
9da57d7b0ddd8d73b676ce12c040362132cdd538bt vd->vdev_child[c]->vdev_open_error =
9da57d7b0ddd8d73b676ce12c040362132cdd538bt vdev_open(vd->vdev_child[c]);
9da57d7b0ddd8d73b676ce12c040362132cdd538bt return;
9da57d7b0ddd8d73b676ce12c040362132cdd538bt }
9da57d7b0ddd8d73b676ce12c040362132cdd538bt tq = taskq_create("vdev_open", children, minclsyspri,
9da57d7b0ddd8d73b676ce12c040362132cdd538bt children, children, TASKQ_PREPOPULATE);
9da57d7b0ddd8d73b676ce12c040362132cdd538bt
9da57d7b0ddd8d73b676ce12c040362132cdd538bt for (int c = 0; c < children; c++)
9da57d7b0ddd8d73b676ce12c040362132cdd538bt VERIFY(taskq_dispatch(tq, vdev_open_child, vd->vdev_child[c],
9da57d7b0ddd8d73b676ce12c040362132cdd538bt TQ_SLEEP) != NULL);
9da57d7b0ddd8d73b676ce12c040362132cdd538bt
9da57d7b0ddd8d73b676ce12c040362132cdd538bt taskq_destroy(tq);
9da57d7b0ddd8d73b676ce12c040362132cdd538bt}
9da57d7b0ddd8d73b676ce12c040362132cdd538bt
9da57d7b0ddd8d73b676ce12c040362132cdd538bt/*
9da57d7b0ddd8d73b676ce12c040362132cdd538bt * Prepare a virtual device for access.
9da57d7b0ddd8d73b676ce12c040362132cdd538bt */
9da57d7b0ddd8d73b676ce12c040362132cdd538btint
9da57d7b0ddd8d73b676ce12c040362132cdd538btvdev_open(vdev_t *vd)
9da57d7b0ddd8d73b676ce12c040362132cdd538bt{
9da57d7b0ddd8d73b676ce12c040362132cdd538bt spa_t *spa = vd->vdev_spa;
9da57d7b0ddd8d73b676ce12c040362132cdd538bt int error;
9da57d7b0ddd8d73b676ce12c040362132cdd538bt uint64_t osize = 0;
9da57d7b0ddd8d73b676ce12c040362132cdd538bt uint64_t max_osize = 0;
9da57d7b0ddd8d73b676ce12c040362132cdd538bt uint64_t asize, max_asize, psize;
9da57d7b0ddd8d73b676ce12c040362132cdd538bt uint64_t ashift = 0;
9da57d7b0ddd8d73b676ce12c040362132cdd538bt
9da57d7b0ddd8d73b676ce12c040362132cdd538bt ASSERT(vd->vdev_open_thread == curthread ||
9da57d7b0ddd8d73b676ce12c040362132cdd538bt spa_config_held(spa, SCL_STATE_ALL, RW_WRITER) == SCL_STATE_ALL);
9da57d7b0ddd8d73b676ce12c040362132cdd538bt ASSERT(vd->vdev_state == VDEV_STATE_CLOSED ||
9da57d7b0ddd8d73b676ce12c040362132cdd538bt vd->vdev_state == VDEV_STATE_CANT_OPEN ||
9da57d7b0ddd8d73b676ce12c040362132cdd538bt vd->vdev_state == VDEV_STATE_OFFLINE);
9da57d7b0ddd8d73b676ce12c040362132cdd538bt
9da57d7b0ddd8d73b676ce12c040362132cdd538bt vd->vdev_stat.vs_aux = VDEV_AUX_NONE;
9da57d7b0ddd8d73b676ce12c040362132cdd538bt vd->vdev_cant_read = B_FALSE;
9da57d7b0ddd8d73b676ce12c040362132cdd538bt vd->vdev_cant_write = B_FALSE;
9da57d7b0ddd8d73b676ce12c040362132cdd538bt vd->vdev_min_asize = vdev_get_min_asize(vd);
9da57d7b0ddd8d73b676ce12c040362132cdd538bt
9da57d7b0ddd8d73b676ce12c040362132cdd538bt /*
9da57d7b0ddd8d73b676ce12c040362132cdd538bt * If this vdev is not removed, check its fault status. If it's
9da57d7b0ddd8d73b676ce12c040362132cdd538bt * faulted, bail out of the open.
9da57d7b0ddd8d73b676ce12c040362132cdd538bt */
9da57d7b0ddd8d73b676ce12c040362132cdd538bt if (!vd->vdev_removed && vd->vdev_faulted) {
9da57d7b0ddd8d73b676ce12c040362132cdd538bt ASSERT(vd->vdev_children == 0);
9da57d7b0ddd8d73b676ce12c040362132cdd538bt ASSERT(vd->vdev_label_aux == VDEV_AUX_ERR_EXCEEDED ||
9da57d7b0ddd8d73b676ce12c040362132cdd538bt vd->vdev_label_aux == VDEV_AUX_EXTERNAL);
9da57d7b0ddd8d73b676ce12c040362132cdd538bt vdev_set_state(vd, B_TRUE, VDEV_STATE_FAULTED,
62e6e1adfc8d795f477410703cc7a88dc5b82622Paul Guo vd->vdev_label_aux);
9da57d7b0ddd8d73b676ce12c040362132cdd538bt return (SET_ERROR(ENXIO));
9da57d7b0ddd8d73b676ce12c040362132cdd538bt } else if (vd->vdev_offline) {
9da57d7b0ddd8d73b676ce12c040362132cdd538bt ASSERT(vd->vdev_children == 0);
9da57d7b0ddd8d73b676ce12c040362132cdd538bt vdev_set_state(vd, B_TRUE, VDEV_STATE_OFFLINE, VDEV_AUX_NONE);
9da57d7b0ddd8d73b676ce12c040362132cdd538bt return (SET_ERROR(ENXIO));
9da57d7b0ddd8d73b676ce12c040362132cdd538bt }
9da57d7b0ddd8d73b676ce12c040362132cdd538bt
9da57d7b0ddd8d73b676ce12c040362132cdd538bt error = vd->vdev_ops->vdev_op_open(vd, &osize, &max_osize, &ashift);
ea65739ebec0cbd625d8c89e19592be58fa186a6chenlu chen - Sun Microsystems - Beijing China
9da57d7b0ddd8d73b676ce12c040362132cdd538bt /*
9da57d7b0ddd8d73b676ce12c040362132cdd538bt * Reset the vdev_reopening flag so that we actually close
9da57d7b0ddd8d73b676ce12c040362132cdd538bt * the vdev on error.
9da57d7b0ddd8d73b676ce12c040362132cdd538bt */
9da57d7b0ddd8d73b676ce12c040362132cdd538bt vd->vdev_reopening = B_FALSE;
9da57d7b0ddd8d73b676ce12c040362132cdd538bt if (zio_injection_enabled && error == 0)
9da57d7b0ddd8d73b676ce12c040362132cdd538bt error = zio_handle_device_injection(vd, NULL, ENXIO);
9da57d7b0ddd8d73b676ce12c040362132cdd538bt
9da57d7b0ddd8d73b676ce12c040362132cdd538bt if (error) {
9da57d7b0ddd8d73b676ce12c040362132cdd538bt if (vd->vdev_removed &&
62e6e1adfc8d795f477410703cc7a88dc5b82622Paul Guo vd->vdev_stat.vs_aux != VDEV_AUX_OPEN_FAILED)
62e6e1adfc8d795f477410703cc7a88dc5b82622Paul Guo vd->vdev_removed = B_FALSE;
62e6e1adfc8d795f477410703cc7a88dc5b82622Paul Guo
62e6e1adfc8d795f477410703cc7a88dc5b82622Paul Guo vdev_set_state(vd, B_TRUE, VDEV_STATE_CANT_OPEN,
62e6e1adfc8d795f477410703cc7a88dc5b82622Paul Guo vd->vdev_stat.vs_aux);
62e6e1adfc8d795f477410703cc7a88dc5b82622Paul Guo return (error);
62e6e1adfc8d795f477410703cc7a88dc5b82622Paul Guo }
62e6e1adfc8d795f477410703cc7a88dc5b82622Paul Guo
9da57d7b0ddd8d73b676ce12c040362132cdd538bt vd->vdev_removed = B_FALSE;
9da57d7b0ddd8d73b676ce12c040362132cdd538bt
9da57d7b0ddd8d73b676ce12c040362132cdd538bt /*
9da57d7b0ddd8d73b676ce12c040362132cdd538bt * Recheck the faulted flag now that we have confirmed that
9da57d7b0ddd8d73b676ce12c040362132cdd538bt * the vdev is accessible. If we're faulted, bail.
9da57d7b0ddd8d73b676ce12c040362132cdd538bt */
9da57d7b0ddd8d73b676ce12c040362132cdd538bt if (vd->vdev_faulted) {
9da57d7b0ddd8d73b676ce12c040362132cdd538bt ASSERT(vd->vdev_children == 0);
9da57d7b0ddd8d73b676ce12c040362132cdd538bt ASSERT(vd->vdev_label_aux == VDEV_AUX_ERR_EXCEEDED ||
9da57d7b0ddd8d73b676ce12c040362132cdd538bt vd->vdev_label_aux == VDEV_AUX_EXTERNAL);
9da57d7b0ddd8d73b676ce12c040362132cdd538bt vdev_set_state(vd, B_TRUE, VDEV_STATE_FAULTED,
9da57d7b0ddd8d73b676ce12c040362132cdd538bt vd->vdev_label_aux);
9da57d7b0ddd8d73b676ce12c040362132cdd538bt return (SET_ERROR(ENXIO));
9da57d7b0ddd8d73b676ce12c040362132cdd538bt }
9da57d7b0ddd8d73b676ce12c040362132cdd538bt
9da57d7b0ddd8d73b676ce12c040362132cdd538bt if (vd->vdev_degraded) {
9da57d7b0ddd8d73b676ce12c040362132cdd538bt ASSERT(vd->vdev_children == 0);
62e6e1adfc8d795f477410703cc7a88dc5b82622Paul Guo vdev_set_state(vd, B_TRUE, VDEV_STATE_DEGRADED,
ea65739ebec0cbd625d8c89e19592be58fa186a6chenlu chen - Sun Microsystems - Beijing China VDEV_AUX_ERR_EXCEEDED);
ea65739ebec0cbd625d8c89e19592be58fa186a6chenlu chen - Sun Microsystems - Beijing China } else {
ea65739ebec0cbd625d8c89e19592be58fa186a6chenlu chen - Sun Microsystems - Beijing China vdev_set_state(vd, B_TRUE, VDEV_STATE_HEALTHY, 0);
ea65739ebec0cbd625d8c89e19592be58fa186a6chenlu chen - Sun Microsystems - Beijing China }
ea65739ebec0cbd625d8c89e19592be58fa186a6chenlu chen - Sun Microsystems - Beijing China
9da57d7b0ddd8d73b676ce12c040362132cdd538bt /*
9da57d7b0ddd8d73b676ce12c040362132cdd538bt * For hole or missing vdevs we just return success.
9da57d7b0ddd8d73b676ce12c040362132cdd538bt */
9da57d7b0ddd8d73b676ce12c040362132cdd538bt if (vd->vdev_ishole || vd->vdev_ops == &vdev_missing_ops)
9da57d7b0ddd8d73b676ce12c040362132cdd538bt return (0);
9da57d7b0ddd8d73b676ce12c040362132cdd538bt
9da57d7b0ddd8d73b676ce12c040362132cdd538bt for (int c = 0; c < vd->vdev_children; c++) {
9da57d7b0ddd8d73b676ce12c040362132cdd538bt if (vd->vdev_child[c]->vdev_state != VDEV_STATE_HEALTHY) {
9da57d7b0ddd8d73b676ce12c040362132cdd538bt vdev_set_state(vd, B_TRUE, VDEV_STATE_DEGRADED,
9da57d7b0ddd8d73b676ce12c040362132cdd538bt VDEV_AUX_NONE);
9da57d7b0ddd8d73b676ce12c040362132cdd538bt break;
9da57d7b0ddd8d73b676ce12c040362132cdd538bt }
9da57d7b0ddd8d73b676ce12c040362132cdd538bt }
9da57d7b0ddd8d73b676ce12c040362132cdd538bt
9da57d7b0ddd8d73b676ce12c040362132cdd538bt osize = P2ALIGN(osize, (uint64_t)sizeof (vdev_label_t));
9da57d7b0ddd8d73b676ce12c040362132cdd538bt max_osize = P2ALIGN(max_osize, (uint64_t)sizeof (vdev_label_t));
9da57d7b0ddd8d73b676ce12c040362132cdd538bt
9da57d7b0ddd8d73b676ce12c040362132cdd538bt if (vd->vdev_children == 0) {
9da57d7b0ddd8d73b676ce12c040362132cdd538bt if (osize < SPA_MINDEVSIZE) {
9da57d7b0ddd8d73b676ce12c040362132cdd538bt vdev_set_state(vd, B_TRUE, VDEV_STATE_CANT_OPEN,
9da57d7b0ddd8d73b676ce12c040362132cdd538bt VDEV_AUX_TOO_SMALL);
9da57d7b0ddd8d73b676ce12c040362132cdd538bt return (SET_ERROR(EOVERFLOW));
9da57d7b0ddd8d73b676ce12c040362132cdd538bt }
9da57d7b0ddd8d73b676ce12c040362132cdd538bt psize = osize;
9da57d7b0ddd8d73b676ce12c040362132cdd538bt asize = osize - (VDEV_LABEL_START_SIZE + VDEV_LABEL_END_SIZE);
9da57d7b0ddd8d73b676ce12c040362132cdd538bt max_asize = max_osize - (VDEV_LABEL_START_SIZE +
9da57d7b0ddd8d73b676ce12c040362132cdd538bt VDEV_LABEL_END_SIZE);
9da57d7b0ddd8d73b676ce12c040362132cdd538bt } else {
9da57d7b0ddd8d73b676ce12c040362132cdd538bt if (vd->vdev_parent != NULL && osize < SPA_MINDEVSIZE -
9da57d7b0ddd8d73b676ce12c040362132cdd538bt (VDEV_LABEL_START_SIZE + VDEV_LABEL_END_SIZE)) {
9da57d7b0ddd8d73b676ce12c040362132cdd538bt vdev_set_state(vd, B_TRUE, VDEV_STATE_CANT_OPEN,
9da57d7b0ddd8d73b676ce12c040362132cdd538bt VDEV_AUX_TOO_SMALL);
9da57d7b0ddd8d73b676ce12c040362132cdd538bt return (SET_ERROR(EOVERFLOW));
9da57d7b0ddd8d73b676ce12c040362132cdd538bt }
9da57d7b0ddd8d73b676ce12c040362132cdd538bt psize = 0;
9da57d7b0ddd8d73b676ce12c040362132cdd538bt asize = osize;
9da57d7b0ddd8d73b676ce12c040362132cdd538bt max_asize = max_osize;
9da57d7b0ddd8d73b676ce12c040362132cdd538bt }
9da57d7b0ddd8d73b676ce12c040362132cdd538bt
9da57d7b0ddd8d73b676ce12c040362132cdd538bt vd->vdev_psize = psize;
9da57d7b0ddd8d73b676ce12c040362132cdd538bt
9da57d7b0ddd8d73b676ce12c040362132cdd538bt /*
9da57d7b0ddd8d73b676ce12c040362132cdd538bt * Make sure the allocatable size hasn't shrunk.
9da57d7b0ddd8d73b676ce12c040362132cdd538bt */
9da57d7b0ddd8d73b676ce12c040362132cdd538bt if (asize < vd->vdev_min_asize) {
9da57d7b0ddd8d73b676ce12c040362132cdd538bt vdev_set_state(vd, B_TRUE, VDEV_STATE_CANT_OPEN,
9da57d7b0ddd8d73b676ce12c040362132cdd538bt VDEV_AUX_BAD_LABEL);
9da57d7b0ddd8d73b676ce12c040362132cdd538bt return (SET_ERROR(EINVAL));
9da57d7b0ddd8d73b676ce12c040362132cdd538bt }
9da57d7b0ddd8d73b676ce12c040362132cdd538bt
9da57d7b0ddd8d73b676ce12c040362132cdd538bt if (vd->vdev_asize == 0) {
9da57d7b0ddd8d73b676ce12c040362132cdd538bt /*
9da57d7b0ddd8d73b676ce12c040362132cdd538bt * This is the first-ever open, so use the computed values.
9da57d7b0ddd8d73b676ce12c040362132cdd538bt * For testing purposes, a higher ashift can be requested.
9da57d7b0ddd8d73b676ce12c040362132cdd538bt */
9da57d7b0ddd8d73b676ce12c040362132cdd538bt vd->vdev_asize = asize;
9da57d7b0ddd8d73b676ce12c040362132cdd538bt vd->vdev_max_asize = max_asize;
9da57d7b0ddd8d73b676ce12c040362132cdd538bt vd->vdev_ashift = MAX(ashift, vd->vdev_ashift);
9da57d7b0ddd8d73b676ce12c040362132cdd538bt } else {
9da57d7b0ddd8d73b676ce12c040362132cdd538bt /*
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.
69b5a878d62fdee1b12e78371ce6cc8abddcad15Dan McDonald */
9da57d7b0ddd8d73b676ce12c040362132cdd538bt if (ashift > vd->vdev_top->vdev_ashift &&
9da57d7b0ddd8d73b676ce12c040362132cdd538bt vd->vdev_ops->vdev_op_leaf) {
9da57d7b0ddd8d73b676ce12c040362132cdd538bt cmn_err(CE_WARN,
9da57d7b0ddd8d73b676ce12c040362132cdd538bt "Disk, '%s', has a block alignment that is "
9da57d7b0ddd8d73b676ce12c040362132cdd538bt "larger than the pool's alignment\n",
9da57d7b0ddd8d73b676ce12c040362132cdd538bt vd->vdev_path);
9da57d7b0ddd8d73b676ce12c040362132cdd538bt }
9da57d7b0ddd8d73b676ce12c040362132cdd538bt vd->vdev_max_asize = max_asize;
9da57d7b0ddd8d73b676ce12c040362132cdd538bt }
9da57d7b0ddd8d73b676ce12c040362132cdd538bt
9da57d7b0ddd8d73b676ce12c040362132cdd538bt /*
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 */
9da57d7b0ddd8d73b676ce12c040362132cdd538bt if (vd->vdev_state == VDEV_STATE_HEALTHY && asize > vd->vdev_asize &&
9da57d7b0ddd8d73b676ce12c040362132cdd538bt (vd->vdev_expanding || spa->spa_autoexpand))
9da57d7b0ddd8d73b676ce12c040362132cdd538bt vd->vdev_asize = asize;
9da57d7b0ddd8d73b676ce12c040362132cdd538bt
9da57d7b0ddd8d73b676ce12c040362132cdd538bt vdev_set_min_asize(vd);
9da57d7b0ddd8d73b676ce12c040362132cdd538bt
9da57d7b0ddd8d73b676ce12c040362132cdd538bt /*
9da57d7b0ddd8d73b676ce12c040362132cdd538bt * Ensure we can issue some IO before declaring the
9da57d7b0ddd8d73b676ce12c040362132cdd538bt * vdev open for business.
9da57d7b0ddd8d73b676ce12c040362132cdd538bt */
9da57d7b0ddd8d73b676ce12c040362132cdd538bt if (vd->vdev_ops->vdev_op_leaf &&
9da57d7b0ddd8d73b676ce12c040362132cdd538bt (error = zio_wait(vdev_probe(vd, NULL))) != 0) {
9da57d7b0ddd8d73b676ce12c040362132cdd538bt vdev_set_state(vd, B_TRUE, VDEV_STATE_FAULTED,
9da57d7b0ddd8d73b676ce12c040362132cdd538bt VDEV_AUX_ERR_EXCEEDED);
9da57d7b0ddd8d73b676ce12c040362132cdd538bt return (error);
9da57d7b0ddd8d73b676ce12c040362132cdd538bt }
9da57d7b0ddd8d73b676ce12c040362132cdd538bt
9da57d7b0ddd8d73b676ce12c040362132cdd538bt /*
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 */
9da57d7b0ddd8d73b676ce12c040362132cdd538bt if (vd->vdev_ops->vdev_op_leaf && !spa->spa_scrub_reopen &&
9da57d7b0ddd8d73b676ce12c040362132cdd538bt vdev_resilver_needed(vd, NULL, NULL))
9da57d7b0ddd8d73b676ce12c040362132cdd538bt spa_async_request(spa, SPA_ASYNC_RESILVER);
9da57d7b0ddd8d73b676ce12c040362132cdd538bt
185c5677613512bc5a906decb5034a5135f67fb1Paul Guo return (0);
9da57d7b0ddd8d73b676ce12c040362132cdd538bt}
9da57d7b0ddd8d73b676ce12c040362132cdd538bt
9da57d7b0ddd8d73b676ce12c040362132cdd538bt/*
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 *
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 *
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.
9da57d7b0ddd8d73b676ce12c040362132cdd538bt */
9da57d7b0ddd8d73b676ce12c040362132cdd538btint
9da57d7b0ddd8d73b676ce12c040362132cdd538btvdev_validate(vdev_t *vd, boolean_t strict)
9da57d7b0ddd8d73b676ce12c040362132cdd538bt{
9da57d7b0ddd8d73b676ce12c040362132cdd538bt spa_t *spa = vd->vdev_spa;
9da57d7b0ddd8d73b676ce12c040362132cdd538bt nvlist_t *label;
9da57d7b0ddd8d73b676ce12c040362132cdd538bt uint64_t guid = 0, top_guid;
9da57d7b0ddd8d73b676ce12c040362132cdd538bt uint64_t state;
185c5677613512bc5a906decb5034a5135f67fb1Paul Guo
185c5677613512bc5a906decb5034a5135f67fb1Paul Guo for (int c = 0; c < vd->vdev_children; c++)
185c5677613512bc5a906decb5034a5135f67fb1Paul Guo if (vdev_validate(vd->vdev_child[c], strict) != 0)
185c5677613512bc5a906decb5034a5135f67fb1Paul Guo return (SET_ERROR(EBADF));
185c5677613512bc5a906decb5034a5135f67fb1Paul Guo
185c5677613512bc5a906decb5034a5135f67fb1Paul Guo /*
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 */
185c5677613512bc5a906decb5034a5135f67fb1Paul Guo if (vd->vdev_ops->vdev_op_leaf && vdev_readable(vd)) {
9da57d7b0ddd8d73b676ce12c040362132cdd538bt uint64_t aux_guid = 0;
9da57d7b0ddd8d73b676ce12c040362132cdd538bt nvlist_t *nvl;
19843f01b1bef3453f717c23c8f89fb9313f6749Paul Guo uint64_t txg = spa_last_synced_txg(spa) != 0 ?
19843f01b1bef3453f717c23c8f89fb9313f6749Paul Guo spa_last_synced_txg(spa) : -1ULL;
19843f01b1bef3453f717c23c8f89fb9313f6749Paul Guo
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 }
9da57d7b0ddd8d73b676ce12c040362132cdd538bt
9da57d7b0ddd8d73b676ce12c040362132cdd538bt /*
9da57d7b0ddd8d73b676ce12c040362132cdd538bt * Determine if this vdev has been split off into another
9da57d7b0ddd8d73b676ce12c040362132cdd538bt * pool. If so, then refuse to open it.
9da57d7b0ddd8d73b676ce12c040362132cdd538bt */
9da57d7b0ddd8d73b676ce12c040362132cdd538bt if (nvlist_lookup_uint64(label, ZPOOL_CONFIG_SPLIT_GUID,
9da57d7b0ddd8d73b676ce12c040362132cdd538bt &aux_guid) == 0 && aux_guid == spa_guid(spa)) {
9da57d7b0ddd8d73b676ce12c040362132cdd538bt vdev_set_state(vd, B_FALSE, VDEV_STATE_CANT_OPEN,
9da57d7b0ddd8d73b676ce12c040362132cdd538bt VDEV_AUX_SPLIT_POOL);
9da57d7b0ddd8d73b676ce12c040362132cdd538bt nvlist_free(label);
9da57d7b0ddd8d73b676ce12c040362132cdd538bt return (0);
9da57d7b0ddd8d73b676ce12c040362132cdd538bt }
9da57d7b0ddd8d73b676ce12c040362132cdd538bt
9da57d7b0ddd8d73b676ce12c040362132cdd538bt if (strict && (nvlist_lookup_uint64(label,
9da57d7b0ddd8d73b676ce12c040362132cdd538bt ZPOOL_CONFIG_POOL_GUID, &guid) != 0 ||
9da57d7b0ddd8d73b676ce12c040362132cdd538bt guid != spa_guid(spa))) {
9da57d7b0ddd8d73b676ce12c040362132cdd538bt vdev_set_state(vd, B_FALSE, VDEV_STATE_CANT_OPEN,
73cd555c10e70dac413ae4b40de8450a291750acBin Tu - Sun Microsystems - Beijing China VDEV_AUX_CORRUPT_DATA);
9da57d7b0ddd8d73b676ce12c040362132cdd538bt nvlist_free(label);
73cd555c10e70dac413ae4b40de8450a291750acBin Tu - Sun Microsystems - Beijing China return (0);
9da57d7b0ddd8d73b676ce12c040362132cdd538bt }
9da57d7b0ddd8d73b676ce12c040362132cdd538bt
9da57d7b0ddd8d73b676ce12c040362132cdd538bt if (nvlist_lookup_nvlist(label, ZPOOL_CONFIG_VDEV_TREE, &nvl)
9da57d7b0ddd8d73b676ce12c040362132cdd538bt != 0 || nvlist_lookup_uint64(nvl, ZPOOL_CONFIG_ORIG_GUID,
9da57d7b0ddd8d73b676ce12c040362132cdd538bt &aux_guid) != 0)
9da57d7b0ddd8d73b676ce12c040362132cdd538bt aux_guid = 0;
9da57d7b0ddd8d73b676ce12c040362132cdd538bt
9da57d7b0ddd8d73b676ce12c040362132cdd538bt /*
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 *
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 */
9da57d7b0ddd8d73b676ce12c040362132cdd538bt if (nvlist_lookup_uint64(label, ZPOOL_CONFIG_GUID,
9da57d7b0ddd8d73b676ce12c040362132cdd538bt &guid) != 0 ||
9da57d7b0ddd8d73b676ce12c040362132cdd538bt nvlist_lookup_uint64(label, ZPOOL_CONFIG_TOP_GUID,
9da57d7b0ddd8d73b676ce12c040362132cdd538bt &top_guid) != 0 ||
9da57d7b0ddd8d73b676ce12c040362132cdd538bt ((vd->vdev_guid != guid && vd->vdev_guid != aux_guid) &&
9da57d7b0ddd8d73b676ce12c040362132cdd538bt (vd->vdev_guid != top_guid || vd != vd->vdev_top))) {
9da57d7b0ddd8d73b676ce12c040362132cdd538bt vdev_set_state(vd, B_FALSE, VDEV_STATE_CANT_OPEN,
9da57d7b0ddd8d73b676ce12c040362132cdd538bt VDEV_AUX_CORRUPT_DATA);
9da57d7b0ddd8d73b676ce12c040362132cdd538bt nvlist_free(label);
9da57d7b0ddd8d73b676ce12c040362132cdd538bt return (0);
9da57d7b0ddd8d73b676ce12c040362132cdd538bt }
9da57d7b0ddd8d73b676ce12c040362132cdd538bt
9da57d7b0ddd8d73b676ce12c040362132cdd538bt if (nvlist_lookup_uint64(label, ZPOOL_CONFIG_POOL_STATE,
9da57d7b0ddd8d73b676ce12c040362132cdd538bt &state) != 0) {
9da57d7b0ddd8d73b676ce12c040362132cdd538bt vdev_set_state(vd, B_FALSE, VDEV_STATE_CANT_OPEN,
9da57d7b0ddd8d73b676ce12c040362132cdd538bt VDEV_AUX_CORRUPT_DATA);
9da57d7b0ddd8d73b676ce12c040362132cdd538bt nvlist_free(label);
9da57d7b0ddd8d73b676ce12c040362132cdd538bt return (0);
9da57d7b0ddd8d73b676ce12c040362132cdd538bt }
9da57d7b0ddd8d73b676ce12c040362132cdd538bt
9da57d7b0ddd8d73b676ce12c040362132cdd538bt nvlist_free(label);
9da57d7b0ddd8d73b676ce12c040362132cdd538bt
9da57d7b0ddd8d73b676ce12c040362132cdd538bt /*
9da57d7b0ddd8d73b676ce12c040362132cdd538bt * If this is a verbatim import, no need to check the
9da57d7b0ddd8d73b676ce12c040362132cdd538bt * state of the pool.
9da57d7b0ddd8d73b676ce12c040362132cdd538bt */
9da57d7b0ddd8d73b676ce12c040362132cdd538bt if (!(spa->spa_import_flags & ZFS_IMPORT_VERBATIM) &&
9da57d7b0ddd8d73b676ce12c040362132cdd538bt spa_load_state(spa) == SPA_LOAD_OPEN &&
9da57d7b0ddd8d73b676ce12c040362132cdd538bt state != POOL_STATE_ACTIVE)
9da57d7b0ddd8d73b676ce12c040362132cdd538bt return (SET_ERROR(EBADF));
62e6e1adfc8d795f477410703cc7a88dc5b82622Paul Guo
62e6e1adfc8d795f477410703cc7a88dc5b82622Paul Guo /*
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
ea65739ebec0cbd625d8c89e19592be58fa186a6chenlu chen - Sun Microsystems - Beijing China * now.
ea65739ebec0cbd625d8c89e19592be58fa186a6chenlu chen - Sun Microsystems - Beijing China */
9da57d7b0ddd8d73b676ce12c040362132cdd538bt if (vd->vdev_not_present)
9da57d7b0ddd8d73b676ce12c040362132cdd538bt vd->vdev_not_present = 0;
9da57d7b0ddd8d73b676ce12c040362132cdd538bt }
9da57d7b0ddd8d73b676ce12c040362132cdd538bt
62e6e1adfc8d795f477410703cc7a88dc5b82622Paul Guo return (0);
9da57d7b0ddd8d73b676ce12c040362132cdd538bt}
ea65739ebec0cbd625d8c89e19592be58fa186a6chenlu chen - Sun Microsystems - Beijing China
9da57d7b0ddd8d73b676ce12c040362132cdd538bt/*
ea65739ebec0cbd625d8c89e19592be58fa186a6chenlu chen - Sun Microsystems - Beijing China * Close a virtual device.
ea65739ebec0cbd625d8c89e19592be58fa186a6chenlu chen - Sun Microsystems - Beijing China */
ea65739ebec0cbd625d8c89e19592be58fa186a6chenlu chen - Sun Microsystems - Beijing Chinavoid
9da57d7b0ddd8d73b676ce12c040362132cdd538btvdev_close(vdev_t *vd)
9da57d7b0ddd8d73b676ce12c040362132cdd538bt{
62e6e1adfc8d795f477410703cc7a88dc5b82622Paul Guo spa_t *spa = vd->vdev_spa;
62e6e1adfc8d795f477410703cc7a88dc5b82622Paul Guo vdev_t *pvd = vd->vdev_parent;
62e6e1adfc8d795f477410703cc7a88dc5b82622Paul Guo
62e6e1adfc8d795f477410703cc7a88dc5b82622Paul Guo ASSERT(spa_config_held(spa, SCL_STATE_ALL, RW_WRITER) == SCL_STATE_ALL);
62e6e1adfc8d795f477410703cc7a88dc5b82622Paul Guo
62e6e1adfc8d795f477410703cc7a88dc5b82622Paul Guo /*
62e6e1adfc8d795f477410703cc7a88dc5b82622Paul Guo * If our parent is reopening, then we are as well, unless we are
62e6e1adfc8d795f477410703cc7a88dc5b82622Paul Guo * going offline.
62e6e1adfc8d795f477410703cc7a88dc5b82622Paul Guo */
62e6e1adfc8d795f477410703cc7a88dc5b82622Paul Guo if (pvd != NULL && pvd->vdev_reopening)
62e6e1adfc8d795f477410703cc7a88dc5b82622Paul Guo vd->vdev_reopening = (pvd->vdev_reopening && !vd->vdev_offline);
62e6e1adfc8d795f477410703cc7a88dc5b82622Paul Guo
62e6e1adfc8d795f477410703cc7a88dc5b82622Paul Guo vd->vdev_ops->vdev_op_close(vd);
62e6e1adfc8d795f477410703cc7a88dc5b82622Paul Guo
62e6e1adfc8d795f477410703cc7a88dc5b82622Paul Guo vdev_cache_purge(vd);
62e6e1adfc8d795f477410703cc7a88dc5b82622Paul Guo
ea65739ebec0cbd625d8c89e19592be58fa186a6chenlu chen - Sun Microsystems - Beijing China /*
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.
9da57d7b0ddd8d73b676ce12c040362132cdd538bt */
ea65739ebec0cbd625d8c89e19592be58fa186a6chenlu chen - Sun Microsystems - Beijing China vd->vdev_prevstate = vd->vdev_state;
9da57d7b0ddd8d73b676ce12c040362132cdd538bt
9da57d7b0ddd8d73b676ce12c040362132cdd538bt if (vd->vdev_offline)
9da57d7b0ddd8d73b676ce12c040362132cdd538bt vd->vdev_state = VDEV_STATE_OFFLINE;
9da57d7b0ddd8d73b676ce12c040362132cdd538bt else
9da57d7b0ddd8d73b676ce12c040362132cdd538bt vd->vdev_state = VDEV_STATE_CLOSED;
9da57d7b0ddd8d73b676ce12c040362132cdd538bt vd->vdev_stat.vs_aux = VDEV_AUX_NONE;
9da57d7b0ddd8d73b676ce12c040362132cdd538bt}
9da57d7b0ddd8d73b676ce12c040362132cdd538bt
9da57d7b0ddd8d73b676ce12c040362132cdd538btvoid
9da57d7b0ddd8d73b676ce12c040362132cdd538btvdev_hold(vdev_t *vd)
9da57d7b0ddd8d73b676ce12c040362132cdd538bt{
9da57d7b0ddd8d73b676ce12c040362132cdd538bt spa_t *spa = vd->vdev_spa;
9da57d7b0ddd8d73b676ce12c040362132cdd538bt
9da57d7b0ddd8d73b676ce12c040362132cdd538bt ASSERT(spa_is_root(spa));
9da57d7b0ddd8d73b676ce12c040362132cdd538bt if (spa->spa_state == POOL_STATE_UNINITIALIZED)
9da57d7b0ddd8d73b676ce12c040362132cdd538bt return;
9da57d7b0ddd8d73b676ce12c040362132cdd538bt
9da57d7b0ddd8d73b676ce12c040362132cdd538bt for (int c = 0; c < vd->vdev_children; c++)
9da57d7b0ddd8d73b676ce12c040362132cdd538bt vdev_hold(vd->vdev_child[c]);
9da57d7b0ddd8d73b676ce12c040362132cdd538bt
9da57d7b0ddd8d73b676ce12c040362132cdd538bt if (vd->vdev_ops->vdev_op_leaf)
9da57d7b0ddd8d73b676ce12c040362132cdd538bt vd->vdev_ops->vdev_op_hold(vd);
9da57d7b0ddd8d73b676ce12c040362132cdd538bt}
9da57d7b0ddd8d73b676ce12c040362132cdd538bt
9da57d7b0ddd8d73b676ce12c040362132cdd538btvoid
9da57d7b0ddd8d73b676ce12c040362132cdd538btvdev_rele(vdev_t *vd)
9da57d7b0ddd8d73b676ce12c040362132cdd538bt{
9da57d7b0ddd8d73b676ce12c040362132cdd538bt spa_t *spa = vd->vdev_spa;
9da57d7b0ddd8d73b676ce12c040362132cdd538bt
9da57d7b0ddd8d73b676ce12c040362132cdd538bt ASSERT(spa_is_root(spa));
9da57d7b0ddd8d73b676ce12c040362132cdd538bt for (int c = 0; c < vd->vdev_children; c++)
9da57d7b0ddd8d73b676ce12c040362132cdd538bt vdev_rele(vd->vdev_child[c]);
9da57d7b0ddd8d73b676ce12c040362132cdd538bt
9da57d7b0ddd8d73b676ce12c040362132cdd538bt if (vd->vdev_ops->vdev_op_leaf)
9da57d7b0ddd8d73b676ce12c040362132cdd538bt vd->vdev_ops->vdev_op_rele(vd);
9da57d7b0ddd8d73b676ce12c040362132cdd538bt}
9da57d7b0ddd8d73b676ce12c040362132cdd538bt
9da57d7b0ddd8d73b676ce12c040362132cdd538bt/*
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 */
9da57d7b0ddd8d73b676ce12c040362132cdd538btvoid
9da57d7b0ddd8d73b676ce12c040362132cdd538btvdev_reopen(vdev_t *vd)
9da57d7b0ddd8d73b676ce12c040362132cdd538bt{
9da57d7b0ddd8d73b676ce12c040362132cdd538bt spa_t *spa = vd->vdev_spa;
9da57d7b0ddd8d73b676ce12c040362132cdd538bt
9da57d7b0ddd8d73b676ce12c040362132cdd538bt ASSERT(spa_config_held(spa, SCL_STATE_ALL, RW_WRITER) == SCL_STATE_ALL);
9da57d7b0ddd8d73b676ce12c040362132cdd538bt
9da57d7b0ddd8d73b676ce12c040362132cdd538bt /* set the reopening flag unless we're taking the vdev offline */
9da57d7b0ddd8d73b676ce12c040362132cdd538bt vd->vdev_reopening = !vd->vdev_offline;
9da57d7b0ddd8d73b676ce12c040362132cdd538bt vdev_close(vd);
9da57d7b0ddd8d73b676ce12c040362132cdd538bt (void) vdev_open(vd);
9da57d7b0ddd8d73b676ce12c040362132cdd538bt
9da57d7b0ddd8d73b676ce12c040362132cdd538bt /*
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 */
9da57d7b0ddd8d73b676ce12c040362132cdd538bt if (vd->vdev_aux) {
9da57d7b0ddd8d73b676ce12c040362132cdd538bt (void) vdev_validate_aux(vd);
9da57d7b0ddd8d73b676ce12c040362132cdd538bt if (vdev_readable(vd) && vdev_writeable(vd) &&
9da57d7b0ddd8d73b676ce12c040362132cdd538bt vd->vdev_aux == &spa->spa_l2cache &&
9da57d7b0ddd8d73b676ce12c040362132cdd538bt !l2arc_vdev_present(vd))
9da57d7b0ddd8d73b676ce12c040362132cdd538bt l2arc_add_vdev(spa, vd);
9da57d7b0ddd8d73b676ce12c040362132cdd538bt } else {
9da57d7b0ddd8d73b676ce12c040362132cdd538bt (void) vdev_validate(vd, B_TRUE);
9da57d7b0ddd8d73b676ce12c040362132cdd538bt }
9da57d7b0ddd8d73b676ce12c040362132cdd538bt
9da57d7b0ddd8d73b676ce12c040362132cdd538bt /*
9da57d7b0ddd8d73b676ce12c040362132cdd538bt * Reassess parent vdev's health.
9da57d7b0ddd8d73b676ce12c040362132cdd538bt */
9da57d7b0ddd8d73b676ce12c040362132cdd538bt vdev_propagate_state(vd);
9da57d7b0ddd8d73b676ce12c040362132cdd538bt}
9da57d7b0ddd8d73b676ce12c040362132cdd538bt
9da57d7b0ddd8d73b676ce12c040362132cdd538btint
9da57d7b0ddd8d73b676ce12c040362132cdd538btvdev_create(vdev_t *vd, uint64_t txg, boolean_t isreplacing)
9da57d7b0ddd8d73b676ce12c040362132cdd538bt{
9da57d7b0ddd8d73b676ce12c040362132cdd538bt int error;
9da57d7b0ddd8d73b676ce12c040362132cdd538bt
9da57d7b0ddd8d73b676ce12c040362132cdd538bt /*
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 */
9da57d7b0ddd8d73b676ce12c040362132cdd538bt error = vdev_open(vd);
9da57d7b0ddd8d73b676ce12c040362132cdd538bt
9da57d7b0ddd8d73b676ce12c040362132cdd538bt if (error || vd->vdev_state != VDEV_STATE_HEALTHY) {
9da57d7b0ddd8d73b676ce12c040362132cdd538bt vdev_close(vd);
9da57d7b0ddd8d73b676ce12c040362132cdd538bt return (error ? error : ENXIO);
9da57d7b0ddd8d73b676ce12c040362132cdd538bt }
9da57d7b0ddd8d73b676ce12c040362132cdd538bt
9da57d7b0ddd8d73b676ce12c040362132cdd538bt /*
9da57d7b0ddd8d73b676ce12c040362132cdd538bt * Recursively load DTLs and initialize all labels.
9da57d7b0ddd8d73b676ce12c040362132cdd538bt */
9da57d7b0ddd8d73b676ce12c040362132cdd538bt if ((error = vdev_dtl_load(vd)) != 0 ||
9da57d7b0ddd8d73b676ce12c040362132cdd538bt (error = vdev_label_init(vd, txg, isreplacing ?
9da57d7b0ddd8d73b676ce12c040362132cdd538bt VDEV_LABEL_REPLACE : VDEV_LABEL_CREATE)) != 0) {
9da57d7b0ddd8d73b676ce12c040362132cdd538bt vdev_close(vd);
9da57d7b0ddd8d73b676ce12c040362132cdd538bt return (error);
9da57d7b0ddd8d73b676ce12c040362132cdd538bt }
9da57d7b0ddd8d73b676ce12c040362132cdd538bt
9da57d7b0ddd8d73b676ce12c040362132cdd538bt return (0);
9da57d7b0ddd8d73b676ce12c040362132cdd538bt}
9da57d7b0ddd8d73b676ce12c040362132cdd538bt
9da57d7b0ddd8d73b676ce12c040362132cdd538btvoid
9da57d7b0ddd8d73b676ce12c040362132cdd538btvdev_metaslab_set_size(vdev_t *vd)
9da57d7b0ddd8d73b676ce12c040362132cdd538bt{
9da57d7b0ddd8d73b676ce12c040362132cdd538bt /*
9da57d7b0ddd8d73b676ce12c040362132cdd538bt * Aim for roughly 200 metaslabs per vdev.
9da57d7b0ddd8d73b676ce12c040362132cdd538bt */
9da57d7b0ddd8d73b676ce12c040362132cdd538bt vd->vdev_ms_shift = highbit64(vd->vdev_asize / 200);
9da57d7b0ddd8d73b676ce12c040362132cdd538bt vd->vdev_ms_shift = MAX(vd->vdev_ms_shift, SPA_MAXBLOCKSHIFT);
9da57d7b0ddd8d73b676ce12c040362132cdd538bt}
9da57d7b0ddd8d73b676ce12c040362132cdd538bt
9da57d7b0ddd8d73b676ce12c040362132cdd538btvoid
9da57d7b0ddd8d73b676ce12c040362132cdd538btvdev_dirty(vdev_t *vd, int flags, void *arg, uint64_t txg)
ea65739ebec0cbd625d8c89e19592be58fa186a6chenlu chen - Sun Microsystems - Beijing China{
ea65739ebec0cbd625d8c89e19592be58fa186a6chenlu chen - Sun Microsystems - Beijing China ASSERT(vd == vd->vdev_top);
9da57d7b0ddd8d73b676ce12c040362132cdd538bt ASSERT(!vd->vdev_ishole);
9da57d7b0ddd8d73b676ce12c040362132cdd538bt ASSERT(ISP2(flags));
9da57d7b0ddd8d73b676ce12c040362132cdd538bt ASSERT(spa_writeable(vd->vdev_spa));
9da57d7b0ddd8d73b676ce12c040362132cdd538bt
9da57d7b0ddd8d73b676ce12c040362132cdd538bt if (flags & VDD_METASLAB)
9da57d7b0ddd8d73b676ce12c040362132cdd538bt (void) txg_list_add(&vd->vdev_ms_list, arg, txg);
9da57d7b0ddd8d73b676ce12c040362132cdd538bt
9da57d7b0ddd8d73b676ce12c040362132cdd538bt if (flags & VDD_DTL)
9da57d7b0ddd8d73b676ce12c040362132cdd538bt (void) txg_list_add(&vd->vdev_dtl_list, arg, txg);
9da57d7b0ddd8d73b676ce12c040362132cdd538bt
9da57d7b0ddd8d73b676ce12c040362132cdd538bt (void) txg_list_add(&vd->vdev_spa->spa_vdev_txg_list, vd, txg);
9da57d7b0ddd8d73b676ce12c040362132cdd538bt}
ea65739ebec0cbd625d8c89e19592be58fa186a6chenlu chen - Sun Microsystems - Beijing China
9da57d7b0ddd8d73b676ce12c040362132cdd538btvoid
9da57d7b0ddd8d73b676ce12c040362132cdd538btvdev_dirty_leaves(vdev_t *vd, int flags, uint64_t txg)
9da57d7b0ddd8d73b676ce12c040362132cdd538bt{
9da57d7b0ddd8d73b676ce12c040362132cdd538bt for (int c = 0; c < vd->vdev_children; c++)
9da57d7b0ddd8d73b676ce12c040362132cdd538bt vdev_dirty_leaves(vd->vdev_child[c], flags, txg);
9da57d7b0ddd8d73b676ce12c040362132cdd538bt
9da57d7b0ddd8d73b676ce12c040362132cdd538bt if (vd->vdev_ops->vdev_op_leaf)
9da57d7b0ddd8d73b676ce12c040362132cdd538bt vdev_dirty(vd->vdev_top, flags, vd, txg);
9da57d7b0ddd8d73b676ce12c040362132cdd538bt}
9da57d7b0ddd8d73b676ce12c040362132cdd538bt
9da57d7b0ddd8d73b676ce12c040362132cdd538bt/*
9da57d7b0ddd8d73b676ce12c040362132cdd538bt * DTLs.
9da57d7b0ddd8d73b676ce12c040362132cdd538bt *
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 *
9da57d7b0ddd8d73b676ce12c040362132cdd538bt * DTL_MISSING: txgs for which the vdev has no valid copies of the data
9da57d7b0ddd8d73b676ce12c040362132cdd538bt *
9da57d7b0ddd8d73b676ce12c040362132cdd538bt * DTL_PARTIAL: txgs for which data is available, but not fully replicated
9da57d7b0ddd8d73b676ce12c040362132cdd538bt *
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 *
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 *
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 *
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 *
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.
9da57d7b0ddd8d73b676ce12c040362132cdd538bt */
9da57d7b0ddd8d73b676ce12c040362132cdd538btvoid
9da57d7b0ddd8d73b676ce12c040362132cdd538btvdev_dtl_dirty(vdev_t *vd, vdev_dtl_type_t t, uint64_t txg, uint64_t size)
9da57d7b0ddd8d73b676ce12c040362132cdd538bt{
9da57d7b0ddd8d73b676ce12c040362132cdd538bt range_tree_t *rt = vd->vdev_dtl[t];
9da57d7b0ddd8d73b676ce12c040362132cdd538bt
9da57d7b0ddd8d73b676ce12c040362132cdd538bt ASSERT(t < DTL_TYPES);
9da57d7b0ddd8d73b676ce12c040362132cdd538bt ASSERT(vd != vd->vdev_spa->spa_root_vdev);
9da57d7b0ddd8d73b676ce12c040362132cdd538bt ASSERT(spa_writeable(vd->vdev_spa));
9da57d7b0ddd8d73b676ce12c040362132cdd538bt
9da57d7b0ddd8d73b676ce12c040362132cdd538bt mutex_enter(rt->rt_lock);
9da57d7b0ddd8d73b676ce12c040362132cdd538bt if (!range_tree_contains(rt, txg, size))
9da57d7b0ddd8d73b676ce12c040362132cdd538bt range_tree_add(rt, txg, size);
62e6e1adfc8d795f477410703cc7a88dc5b82622Paul Guo mutex_exit(rt->rt_lock);
62e6e1adfc8d795f477410703cc7a88dc5b82622Paul Guo}
5b6dd21f5401160f9a62ac2e76a858c2bc105370chenlu chen - Sun Microsystems - Beijing China
5b6dd21f5401160f9a62ac2e76a858c2bc105370chenlu chen - Sun Microsystems - Beijing Chinaboolean_t
62e6e1adfc8d795f477410703cc7a88dc5b82622Paul Guovdev_dtl_contains(vdev_t *vd, vdev_dtl_type_t t, uint64_t txg, uint64_t size)
5b6dd21f5401160f9a62ac2e76a858c2bc105370chenlu chen - Sun Microsystems - Beijing China{
5b6dd21f5401160f9a62ac2e76a858c2bc105370chenlu chen - Sun Microsystems - Beijing China range_tree_t *rt = vd->vdev_dtl[t];
62e6e1adfc8d795f477410703cc7a88dc5b82622Paul Guo boolean_t dirty = B_FALSE;
9da57d7b0ddd8d73b676ce12c040362132cdd538bt
9da57d7b0ddd8d73b676ce12c040362132cdd538bt ASSERT(t < DTL_TYPES);
9da57d7b0ddd8d73b676ce12c040362132cdd538bt ASSERT(vd != vd->vdev_spa->spa_root_vdev);
9da57d7b0ddd8d73b676ce12c040362132cdd538bt
9da57d7b0ddd8d73b676ce12c040362132cdd538bt mutex_enter(rt->rt_lock);
9da57d7b0ddd8d73b676ce12c040362132cdd538bt if (range_tree_space(rt) != 0)
9da57d7b0ddd8d73b676ce12c040362132cdd538bt dirty = range_tree_contains(rt, txg, size);
9da57d7b0ddd8d73b676ce12c040362132cdd538bt mutex_exit(rt->rt_lock);
9da57d7b0ddd8d73b676ce12c040362132cdd538bt
9da57d7b0ddd8d73b676ce12c040362132cdd538bt return (dirty);
9da57d7b0ddd8d73b676ce12c040362132cdd538bt}
9da57d7b0ddd8d73b676ce12c040362132cdd538bt
9da57d7b0ddd8d73b676ce12c040362132cdd538btboolean_t
9da57d7b0ddd8d73b676ce12c040362132cdd538btvdev_dtl_empty(vdev_t *vd, vdev_dtl_type_t t)
9da57d7b0ddd8d73b676ce12c040362132cdd538bt{
9da57d7b0ddd8d73b676ce12c040362132cdd538bt range_tree_t *rt = vd->vdev_dtl[t];
9da57d7b0ddd8d73b676ce12c040362132cdd538bt boolean_t empty;
9da57d7b0ddd8d73b676ce12c040362132cdd538bt
9da57d7b0ddd8d73b676ce12c040362132cdd538bt mutex_enter(rt->rt_lock);
9da57d7b0ddd8d73b676ce12c040362132cdd538bt empty = (range_tree_space(rt) == 0);
9da57d7b0ddd8d73b676ce12c040362132cdd538bt mutex_exit(rt->rt_lock);
9da57d7b0ddd8d73b676ce12c040362132cdd538bt
9da57d7b0ddd8d73b676ce12c040362132cdd538bt return (empty);
9da57d7b0ddd8d73b676ce12c040362132cdd538bt}
9da57d7b0ddd8d73b676ce12c040362132cdd538bt
9da57d7b0ddd8d73b676ce12c040362132cdd538bt/*
9da57d7b0ddd8d73b676ce12c040362132cdd538bt * Returns the lowest txg in the DTL range.
9da57d7b0ddd8d73b676ce12c040362132cdd538bt */
ea65739ebec0cbd625d8c89e19592be58fa186a6chenlu chen - Sun Microsystems - Beijing Chinastatic uint64_t
9da57d7b0ddd8d73b676ce12c040362132cdd538btvdev_dtl_min(vdev_t *vd)
9da57d7b0ddd8d73b676ce12c040362132cdd538bt{
9da57d7b0ddd8d73b676ce12c040362132cdd538bt range_seg_t *rs;
9da57d7b0ddd8d73b676ce12c040362132cdd538bt
9da57d7b0ddd8d73b676ce12c040362132cdd538bt ASSERT(MUTEX_HELD(&vd->vdev_dtl_lock));
9da57d7b0ddd8d73b676ce12c040362132cdd538bt ASSERT3U(range_tree_space(vd->vdev_dtl[DTL_MISSING]), !=, 0);
9da57d7b0ddd8d73b676ce12c040362132cdd538bt ASSERT0(vd->vdev_children);
9da57d7b0ddd8d73b676ce12c040362132cdd538bt
9da57d7b0ddd8d73b676ce12c040362132cdd538bt rs = avl_first(&vd->vdev_dtl[DTL_MISSING]->rt_root);
9da57d7b0ddd8d73b676ce12c040362132cdd538bt return (rs->rs_start - 1);
9da57d7b0ddd8d73b676ce12c040362132cdd538bt}
9da57d7b0ddd8d73b676ce12c040362132cdd538bt
9da57d7b0ddd8d73b676ce12c040362132cdd538bt/*
9da57d7b0ddd8d73b676ce12c040362132cdd538bt * Returns the highest txg in the DTL.
9da57d7b0ddd8d73b676ce12c040362132cdd538bt */
9da57d7b0ddd8d73b676ce12c040362132cdd538btstatic uint64_t
9da57d7b0ddd8d73b676ce12c040362132cdd538btvdev_dtl_max(vdev_t *vd)
9da57d7b0ddd8d73b676ce12c040362132cdd538bt{
9da57d7b0ddd8d73b676ce12c040362132cdd538bt range_seg_t *rs;
9da57d7b0ddd8d73b676ce12c040362132cdd538bt
9da57d7b0ddd8d73b676ce12c040362132cdd538bt ASSERT(MUTEX_HELD(&vd->vdev_dtl_lock));
9da57d7b0ddd8d73b676ce12c040362132cdd538bt ASSERT3U(range_tree_space(vd->vdev_dtl[DTL_MISSING]), !=, 0);
9da57d7b0ddd8d73b676ce12c040362132cdd538bt ASSERT0(vd->vdev_children);
9da57d7b0ddd8d73b676ce12c040362132cdd538bt
9da57d7b0ddd8d73b676ce12c040362132cdd538bt rs = avl_last(&vd->vdev_dtl[DTL_MISSING]->rt_root);
9da57d7b0ddd8d73b676ce12c040362132cdd538bt return (rs->rs_end);
9da57d7b0ddd8d73b676ce12c040362132cdd538bt}
9da57d7b0ddd8d73b676ce12c040362132cdd538bt
9da57d7b0ddd8d73b676ce12c040362132cdd538bt/*
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.
9da57d7b0ddd8d73b676ce12c040362132cdd538bt */
9da57d7b0ddd8d73b676ce12c040362132cdd538btstatic boolean_t
9da57d7b0ddd8d73b676ce12c040362132cdd538btvdev_dtl_should_excise(vdev_t *vd)
ea65739ebec0cbd625d8c89e19592be58fa186a6chenlu chen - Sun Microsystems - Beijing China{
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
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
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
ea65739ebec0cbd625d8c89e19592be58fa186a6chenlu chen - Sun Microsystems - Beijing China /*
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 */
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 return (B_TRUE);
0dc2366f7b9f9f36e10909b1e95edbf2a261c2acVenugopal Iyer }
0dc2366f7b9f9f36e10909b1e95edbf2a261c2acVenugopal Iyer return (B_FALSE);
0dc2366f7b9f9f36e10909b1e95edbf2a261c2acVenugopal Iyer}
0dc2366f7b9f9f36e10909b1e95edbf2a261c2acVenugopal Iyer
0dc2366f7b9f9f36e10909b1e95edbf2a261c2acVenugopal Iyer/*
0dc2366f7b9f9f36e10909b1e95edbf2a261c2acVenugopal Iyer * Reassess DTLs after a config change or scrub completion.
0dc2366f7b9f9f36e10909b1e95edbf2a261c2acVenugopal Iyer */
0dc2366f7b9f9f36e10909b1e95edbf2a261c2acVenugopal Iyervoid
0dc2366f7b9f9f36e10909b1e95edbf2a261c2acVenugopal Iyervdev_dtl_reassess(vdev_t *vd, uint64_t txg, uint64_t scrub_txg, int scrub_done)
0dc2366f7b9f9f36e10909b1e95edbf2a261c2acVenugopal Iyer{
0dc2366f7b9f9f36e10909b1e95edbf2a261c2acVenugopal Iyer spa_t *spa = vd->vdev_spa;
0dc2366f7b9f9f36e10909b1e95edbf2a261c2acVenugopal Iyer avl_tree_t reftree;
0dc2366f7b9f9f36e10909b1e95edbf2a261c2acVenugopal Iyer int minref;
0dc2366f7b9f9f36e10909b1e95edbf2a261c2acVenugopal Iyer
0dc2366f7b9f9f36e10909b1e95edbf2a261c2acVenugopal Iyer ASSERT(spa_config_held(spa, SCL_ALL, RW_READER) != 0);
0dc2366f7b9f9f36e10909b1e95edbf2a261c2acVenugopal Iyer
0dc2366f7b9f9f36e10909b1e95edbf2a261c2acVenugopal Iyer for (int c = 0; c < vd->vdev_children; c++)
0dc2366f7b9f9f36e10909b1e95edbf2a261c2acVenugopal Iyer vdev_dtl_reassess(vd->vdev_child[c], txg,
0dc2366f7b9f9f36e10909b1e95edbf2a261c2acVenugopal Iyer scrub_txg, scrub_done);
0dc2366f7b9f9f36e10909b1e95edbf2a261c2acVenugopal Iyer
0dc2366f7b9f9f36e10909b1e95edbf2a261c2acVenugopal Iyer if (vd == spa->spa_root_vdev || vd->vdev_ishole || vd->vdev_aux)
0dc2366f7b9f9f36e10909b1e95edbf2a261c2acVenugopal Iyer return;
0dc2366f7b9f9f36e10909b1e95edbf2a261c2acVenugopal Iyer
0dc2366f7b9f9f36e10909b1e95edbf2a261c2acVenugopal Iyer if (vd->vdev_ops->vdev_op_leaf) {
0dc2366f7b9f9f36e10909b1e95edbf2a261c2acVenugopal Iyer dsl_scan_t *scn = spa->spa_dsl_pool->dp_scan;
0dc2366f7b9f9f36e10909b1e95edbf2a261c2acVenugopal Iyer
0dc2366f7b9f9f36e10909b1e95edbf2a261c2acVenugopal Iyer mutex_enter(&vd->vdev_dtl_lock);
0dc2366f7b9f9f36e10909b1e95edbf2a261c2acVenugopal Iyer
0dc2366f7b9f9f36e10909b1e95edbf2a261c2acVenugopal Iyer /*
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 */
0dc2366f7b9f9f36e10909b1e95edbf2a261c2acVenugopal Iyer if (scrub_txg != 0 &&
0dc2366f7b9f9f36e10909b1e95edbf2a261c2acVenugopal Iyer (spa->spa_scrub_started ||
0dc2366f7b9f9f36e10909b1e95edbf2a261c2acVenugopal Iyer (scn != NULL && scn->scn_phys.scn_errors == 0)) &&
0dc2366f7b9f9f36e10909b1e95edbf2a261c2acVenugopal Iyer vdev_dtl_should_excise(vd)) {
0dc2366f7b9f9f36e10909b1e95edbf2a261c2acVenugopal Iyer /*
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 *
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 */
0dc2366f7b9f9f36e10909b1e95edbf2a261c2acVenugopal Iyer space_reftree_create(&reftree);
0dc2366f7b9f9f36e10909b1e95edbf2a261c2acVenugopal Iyer space_reftree_add_map(&reftree,
0dc2366f7b9f9f36e10909b1e95edbf2a261c2acVenugopal Iyer vd->vdev_dtl[DTL_MISSING], 1);
0dc2366f7b9f9f36e10909b1e95edbf2a261c2acVenugopal Iyer space_reftree_add_seg(&reftree, 0, scrub_txg, -1);
0dc2366f7b9f9f36e10909b1e95edbf2a261c2acVenugopal Iyer space_reftree_add_map(&reftree,
0dc2366f7b9f9f36e10909b1e95edbf2a261c2acVenugopal Iyer vd->vdev_dtl[DTL_SCRUB], 2);
0dc2366f7b9f9f36e10909b1e95edbf2a261c2acVenugopal Iyer space_reftree_generate_map(&reftree,
0dc2366f7b9f9f36e10909b1e95edbf2a261c2acVenugopal Iyer vd->vdev_dtl[DTL_MISSING], 1);
0dc2366f7b9f9f36e10909b1e95edbf2a261c2acVenugopal Iyer space_reftree_destroy(&reftree);
0dc2366f7b9f9f36e10909b1e95edbf2a261c2acVenugopal Iyer }
0dc2366f7b9f9f36e10909b1e95edbf2a261c2acVenugopal Iyer range_tree_vacate(vd->vdev_dtl[DTL_PARTIAL], NULL, NULL);
0dc2366f7b9f9f36e10909b1e95edbf2a261c2acVenugopal Iyer range_tree_walk(vd->vdev_dtl[DTL_MISSING],
0dc2366f7b9f9f36e10909b1e95edbf2a261c2acVenugopal Iyer range_tree_add, vd->vdev_dtl[DTL_PARTIAL]);
0dc2366f7b9f9f36e10909b1e95edbf2a261c2acVenugopal Iyer if (scrub_done)
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 if (!vdev_readable(vd))
0dc2366f7b9f9f36e10909b1e95edbf2a261c2acVenugopal Iyer range_tree_add(vd->vdev_dtl[DTL_OUTAGE], 0, -1ULL);
0dc2366f7b9f9f36e10909b1e95edbf2a261c2acVenugopal Iyer else
0dc2366f7b9f9f36e10909b1e95edbf2a261c2acVenugopal Iyer range_tree_walk(vd->vdev_dtl[DTL_MISSING],
0dc2366f7b9f9f36e10909b1e95edbf2a261c2acVenugopal Iyer range_tree_add, vd->vdev_dtl[DTL_OUTAGE]);
0dc2366f7b9f9f36e10909b1e95edbf2a261c2acVenugopal Iyer
0dc2366f7b9f9f36e10909b1e95edbf2a261c2acVenugopal Iyer /*
0dc2366f7b9f9f36e10909b1e95edbf2a261c2acVenugopal Iyer * If the vdev was resilvering and no longer has any
0dc2366f7b9f9f36e10909b1e95edbf2a261c2acVenugopal Iyer * DTLs then reset its resilvering flag.
0dc2366f7b9f9f36e10909b1e95edbf2a261c2acVenugopal Iyer */
0dc2366f7b9f9f36e10909b1e95edbf2a261c2acVenugopal Iyer if (vd->vdev_resilver_txg != 0 &&
0dc2366f7b9f9f36e10909b1e95edbf2a261c2acVenugopal Iyer range_tree_space(vd->vdev_dtl[DTL_MISSING]) == 0 &&
0dc2366f7b9f9f36e10909b1e95edbf2a261c2acVenugopal Iyer range_tree_space(vd->vdev_dtl[DTL_OUTAGE]) == 0)
0dc2366f7b9f9f36e10909b1e95edbf2a261c2acVenugopal Iyer vd->vdev_resilver_txg = 0;
0dc2366f7b9f9f36e10909b1e95edbf2a261c2acVenugopal Iyer
0dc2366f7b9f9f36e10909b1e95edbf2a261c2acVenugopal Iyer mutex_exit(&vd->vdev_dtl_lock);
0dc2366f7b9f9f36e10909b1e95edbf2a261c2acVenugopal Iyer
0dc2366f7b9f9f36e10909b1e95edbf2a261c2acVenugopal Iyer if (txg != 0)
0dc2366f7b9f9f36e10909b1e95edbf2a261c2acVenugopal Iyer vdev_dirty(vd->vdev_top, VDD_DTL, vd, txg);
0dc2366f7b9f9f36e10909b1e95edbf2a261c2acVenugopal Iyer return;
0dc2366f7b9f9f36e10909b1e95edbf2a261c2acVenugopal Iyer }
0dc2366f7b9f9f36e10909b1e95edbf2a261c2acVenugopal Iyer
0dc2366f7b9f9f36e10909b1e95edbf2a261c2acVenugopal Iyer mutex_enter(&vd->vdev_dtl_lock);
0dc2366f7b9f9f36e10909b1e95edbf2a261c2acVenugopal Iyer for (int t = 0; t < DTL_TYPES; t++) {
0dc2366f7b9f9f36e10909b1e95edbf2a261c2acVenugopal Iyer /* account for child's outage in parent's missing map */
0dc2366f7b9f9f36e10909b1e95edbf2a261c2acVenugopal Iyer int s = (t == DTL_MISSING) ? DTL_OUTAGE: t;
0dc2366f7b9f9f36e10909b1e95edbf2a261c2acVenugopal Iyer if (t == DTL_SCRUB)
0dc2366f7b9f9f36e10909b1e95edbf2a261c2acVenugopal Iyer continue; /* leaf vdevs only */
0dc2366f7b9f9f36e10909b1e95edbf2a261c2acVenugopal Iyer if (t == DTL_PARTIAL)
0dc2366f7b9f9f36e10909b1e95edbf2a261c2acVenugopal Iyer minref = 1; /* i.e. non-zero */
0dc2366f7b9f9f36e10909b1e95edbf2a261c2acVenugopal Iyer else if (vd->vdev_nparity != 0)
0dc2366f7b9f9f36e10909b1e95edbf2a261c2acVenugopal Iyer minref = vd->vdev_nparity + 1; /* RAID-Z */
0dc2366f7b9f9f36e10909b1e95edbf2a261c2acVenugopal Iyer else
0dc2366f7b9f9f36e10909b1e95edbf2a261c2acVenugopal Iyer minref = vd->vdev_children; /* any kind of mirror */
0dc2366f7b9f9f36e10909b1e95edbf2a261c2acVenugopal Iyer space_reftree_create(&reftree);
0dc2366f7b9f9f36e10909b1e95edbf2a261c2acVenugopal Iyer for (int c = 0; c < vd->vdev_children; c++) {
0dc2366f7b9f9f36e10909b1e95edbf2a261c2acVenugopal Iyer vdev_t *cvd = vd->vdev_child[c];
0dc2366f7b9f9f36e10909b1e95edbf2a261c2acVenugopal Iyer mutex_enter(&cvd->vdev_dtl_lock);
0dc2366f7b9f9f36e10909b1e95edbf2a261c2acVenugopal Iyer space_reftree_add_map(&reftree, cvd->vdev_dtl[s], 1);
0dc2366f7b9f9f36e10909b1e95edbf2a261c2acVenugopal Iyer mutex_exit(&cvd->vdev_dtl_lock);
0dc2366f7b9f9f36e10909b1e95edbf2a261c2acVenugopal Iyer }
0dc2366f7b9f9f36e10909b1e95edbf2a261c2acVenugopal Iyer space_reftree_generate_map(&reftree, vd->vdev_dtl[t], minref);
0dc2366f7b9f9f36e10909b1e95edbf2a261c2acVenugopal Iyer space_reftree_destroy(&reftree);
0dc2366f7b9f9f36e10909b1e95edbf2a261c2acVenugopal Iyer }
0dc2366f7b9f9f36e10909b1e95edbf2a261c2acVenugopal Iyer mutex_exit(&vd->vdev_dtl_lock);
0dc2366f7b9f9f36e10909b1e95edbf2a261c2acVenugopal Iyer}
0dc2366f7b9f9f36e10909b1e95edbf2a261c2acVenugopal Iyer
0dc2366f7b9f9f36e10909b1e95edbf2a261c2acVenugopal Iyerint
0dc2366f7b9f9f36e10909b1e95edbf2a261c2acVenugopal Iyervdev_dtl_load(vdev_t *vd)
0dc2366f7b9f9f36e10909b1e95edbf2a261c2acVenugopal Iyer{
0dc2366f7b9f9f36e10909b1e95edbf2a261c2acVenugopal Iyer spa_t *spa = vd->vdev_spa;
0dc2366f7b9f9f36e10909b1e95edbf2a261c2acVenugopal Iyer objset_t *mos = spa->spa_meta_objset;
0dc2366f7b9f9f36e10909b1e95edbf2a261c2acVenugopal Iyer int error = 0;
0dc2366f7b9f9f36e10909b1e95edbf2a261c2acVenugopal Iyer
0dc2366f7b9f9f36e10909b1e95edbf2a261c2acVenugopal Iyer if (vd->vdev_ops->vdev_op_leaf && vd->vdev_dtl_object != 0) {
0dc2366f7b9f9f36e10909b1e95edbf2a261c2acVenugopal Iyer ASSERT(!vd->vdev_ishole);
0dc2366f7b9f9f36e10909b1e95edbf2a261c2acVenugopal Iyer
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 if (error)
0dc2366f7b9f9f36e10909b1e95edbf2a261c2acVenugopal Iyer return (error);
0dc2366f7b9f9f36e10909b1e95edbf2a261c2acVenugopal Iyer ASSERT(vd->vdev_dtl_sm != NULL);
0dc2366f7b9f9f36e10909b1e95edbf2a261c2acVenugopal Iyer
0dc2366f7b9f9f36e10909b1e95edbf2a261c2acVenugopal Iyer mutex_enter(&vd->vdev_dtl_lock);
0dc2366f7b9f9f36e10909b1e95edbf2a261c2acVenugopal Iyer
0dc2366f7b9f9f36e10909b1e95edbf2a261c2acVenugopal Iyer /*
0dc2366f7b9f9f36e10909b1e95edbf2a261c2acVenugopal Iyer * Now that we've opened the space_map we need to update
0dc2366f7b9f9f36e10909b1e95edbf2a261c2acVenugopal Iyer * the in-core DTL.
0dc2366f7b9f9f36e10909b1e95edbf2a261c2acVenugopal Iyer */
0dc2366f7b9f9f36e10909b1e95edbf2a261c2acVenugopal Iyer space_map_update(vd->vdev_dtl_sm);
0dc2366f7b9f9f36e10909b1e95edbf2a261c2acVenugopal Iyer
0dc2366f7b9f9f36e10909b1e95edbf2a261c2acVenugopal Iyer error = space_map_load(vd->vdev_dtl_sm,
0dc2366f7b9f9f36e10909b1e95edbf2a261c2acVenugopal Iyer vd->vdev_dtl[DTL_MISSING], SM_ALLOC);
0dc2366f7b9f9f36e10909b1e95edbf2a261c2acVenugopal Iyer mutex_exit(&vd->vdev_dtl_lock);
0dc2366f7b9f9f36e10909b1e95edbf2a261c2acVenugopal Iyer
0dc2366f7b9f9f36e10909b1e95edbf2a261c2acVenugopal Iyer return (error);
0dc2366f7b9f9f36e10909b1e95edbf2a261c2acVenugopal Iyer }
0dc2366f7b9f9f36e10909b1e95edbf2a261c2acVenugopal Iyer
0dc2366f7b9f9f36e10909b1e95edbf2a261c2acVenugopal Iyer for (int c = 0; c < vd->vdev_children; c++) {
0dc2366f7b9f9f36e10909b1e95edbf2a261c2acVenugopal Iyer error = vdev_dtl_load(vd->vdev_child[c]);
0dc2366f7b9f9f36e10909b1e95edbf2a261c2acVenugopal Iyer if (error != 0)
0dc2366f7b9f9f36e10909b1e95edbf2a261c2acVenugopal Iyer break;
0dc2366f7b9f9f36e10909b1e95edbf2a261c2acVenugopal Iyer }
0dc2366f7b9f9f36e10909b1e95edbf2a261c2acVenugopal Iyer
0dc2366f7b9f9f36e10909b1e95edbf2a261c2acVenugopal Iyer return (error);
0dc2366f7b9f9f36e10909b1e95edbf2a261c2acVenugopal Iyer}
0dc2366f7b9f9f36e10909b1e95edbf2a261c2acVenugopal Iyer
0dc2366f7b9f9f36e10909b1e95edbf2a261c2acVenugopal Iyervoid
0dc2366f7b9f9f36e10909b1e95edbf2a261c2acVenugopal Iyervdev_dtl_sync(vdev_t *vd, uint64_t txg)
0dc2366f7b9f9f36e10909b1e95edbf2a261c2acVenugopal Iyer{
0dc2366f7b9f9f36e10909b1e95edbf2a261c2acVenugopal Iyer spa_t *spa = vd->vdev_spa;
0dc2366f7b9f9f36e10909b1e95edbf2a261c2acVenugopal Iyer range_tree_t *rt = vd->vdev_dtl[DTL_MISSING];
0dc2366f7b9f9f36e10909b1e95edbf2a261c2acVenugopal Iyer objset_t *mos = spa->spa_meta_objset;
0dc2366f7b9f9f36e10909b1e95edbf2a261c2acVenugopal Iyer range_tree_t *rtsync;
0dc2366f7b9f9f36e10909b1e95edbf2a261c2acVenugopal Iyer kmutex_t rtlock;
0dc2366f7b9f9f36e10909b1e95edbf2a261c2acVenugopal Iyer dmu_tx_t *tx;
0dc2366f7b9f9f36e10909b1e95edbf2a261c2acVenugopal Iyer uint64_t object = space_map_object(vd->vdev_dtl_sm);
0dc2366f7b9f9f36e10909b1e95edbf2a261c2acVenugopal Iyer
0dc2366f7b9f9f36e10909b1e95edbf2a261c2acVenugopal Iyer ASSERT(!vd->vdev_ishole);
0dc2366f7b9f9f36e10909b1e95edbf2a261c2acVenugopal Iyer ASSERT(vd->vdev_ops->vdev_op_leaf);
0dc2366f7b9f9f36e10909b1e95edbf2a261c2acVenugopal Iyer
0dc2366f7b9f9f36e10909b1e95edbf2a261c2acVenugopal Iyer tx = dmu_tx_create_assigned(spa->spa_dsl_pool, txg);
0dc2366f7b9f9f36e10909b1e95edbf2a261c2acVenugopal Iyer
0dc2366f7b9f9f36e10909b1e95edbf2a261c2acVenugopal Iyer if (vd->vdev_detached || vd->vdev_top->vdev_removing) {
0dc2366f7b9f9f36e10909b1e95edbf2a261c2acVenugopal Iyer mutex_enter(&vd->vdev_dtl_lock);
0dc2366f7b9f9f36e10909b1e95edbf2a261c2acVenugopal Iyer space_map_free(vd->vdev_dtl_sm, tx);
0dc2366f7b9f9f36e10909b1e95edbf2a261c2acVenugopal Iyer space_map_close(vd->vdev_dtl_sm);
0dc2366f7b9f9f36e10909b1e95edbf2a261c2acVenugopal Iyer vd->vdev_dtl_sm = NULL;
0dc2366f7b9f9f36e10909b1e95edbf2a261c2acVenugopal Iyer mutex_exit(&vd->vdev_dtl_lock);
0dc2366f7b9f9f36e10909b1e95edbf2a261c2acVenugopal Iyer dmu_tx_commit(tx);
0dc2366f7b9f9f36e10909b1e95edbf2a261c2acVenugopal Iyer return;
0dc2366f7b9f9f36e10909b1e95edbf2a261c2acVenugopal Iyer }
0dc2366f7b9f9f36e10909b1e95edbf2a261c2acVenugopal Iyer
0dc2366f7b9f9f36e10909b1e95edbf2a261c2acVenugopal Iyer if (vd->vdev_dtl_sm == NULL) {
0dc2366f7b9f9f36e10909b1e95edbf2a261c2acVenugopal Iyer uint64_t new_object;
0dc2366f7b9f9f36e10909b1e95edbf2a261c2acVenugopal Iyer
0dc2366f7b9f9f36e10909b1e95edbf2a261c2acVenugopal Iyer new_object = space_map_alloc(mos, tx);
0dc2366f7b9f9f36e10909b1e95edbf2a261c2acVenugopal Iyer VERIFY3U(new_object, !=, 0);
0dc2366f7b9f9f36e10909b1e95edbf2a261c2acVenugopal Iyer
0dc2366f7b9f9f36e10909b1e95edbf2a261c2acVenugopal Iyer VERIFY0(space_map_open(&vd->vdev_dtl_sm, mos, new_object,
0dc2366f7b9f9f36e10909b1e95edbf2a261c2acVenugopal Iyer 0, -1ULL, 0, &vd->vdev_dtl_lock));
0dc2366f7b9f9f36e10909b1e95edbf2a261c2acVenugopal Iyer ASSERT(vd->vdev_dtl_sm != NULL);
0dc2366f7b9f9f36e10909b1e95edbf2a261c2acVenugopal Iyer }
0dc2366f7b9f9f36e10909b1e95edbf2a261c2acVenugopal Iyer
0dc2366f7b9f9f36e10909b1e95edbf2a261c2acVenugopal Iyer mutex_init(&rtlock, NULL, MUTEX_DEFAULT, NULL);
0dc2366f7b9f9f36e10909b1e95edbf2a261c2acVenugopal Iyer
0dc2366f7b9f9f36e10909b1e95edbf2a261c2acVenugopal Iyer rtsync = range_tree_create(NULL, NULL, &rtlock);
0dc2366f7b9f9f36e10909b1e95edbf2a261c2acVenugopal Iyer
0dc2366f7b9f9f36e10909b1e95edbf2a261c2acVenugopal Iyer mutex_enter(&rtlock);
0dc2366f7b9f9f36e10909b1e95edbf2a261c2acVenugopal Iyer
0dc2366f7b9f9f36e10909b1e95edbf2a261c2acVenugopal Iyer mutex_enter(&vd->vdev_dtl_lock);
0dc2366f7b9f9f36e10909b1e95edbf2a261c2acVenugopal Iyer range_tree_walk(rt, range_tree_add, rtsync);
0dc2366f7b9f9f36e10909b1e95edbf2a261c2acVenugopal Iyer mutex_exit(&vd->vdev_dtl_lock);
9da57d7b0ddd8d73b676ce12c040362132cdd538bt
9da57d7b0ddd8d73b676ce12c040362132cdd538bt space_map_truncate(vd->vdev_dtl_sm, tx);
9da57d7b0ddd8d73b676ce12c040362132cdd538bt space_map_write(vd->vdev_dtl_sm, rtsync, SM_ALLOC, tx);
9da57d7b0ddd8d73b676ce12c040362132cdd538bt range_tree_vacate(rtsync, NULL, NULL);
9da57d7b0ddd8d73b676ce12c040362132cdd538bt
9da57d7b0ddd8d73b676ce12c040362132cdd538bt range_tree_destroy(rtsync);
9da57d7b0ddd8d73b676ce12c040362132cdd538bt
9da57d7b0ddd8d73b676ce12c040362132cdd538bt mutex_exit(&rtlock);
9da57d7b0ddd8d73b676ce12c040362132cdd538bt mutex_destroy(&rtlock);
9da57d7b0ddd8d73b676ce12c040362132cdd538bt
9da57d7b0ddd8d73b676ce12c040362132cdd538bt /*
9da57d7b0ddd8d73b676ce12c040362132cdd538bt * If the object for the space map has changed then dirty
9da57d7b0ddd8d73b676ce12c040362132cdd538bt * the top level so that we update the config.
9da57d7b0ddd8d73b676ce12c040362132cdd538bt */
9da57d7b0ddd8d73b676ce12c040362132cdd538bt if (object != space_map_object(vd->vdev_dtl_sm)) {
9da57d7b0ddd8d73b676ce12c040362132cdd538bt zfs_dbgmsg("txg %llu, spa %s, DTL old object %llu, "
9da57d7b0ddd8d73b676ce12c040362132cdd538bt "new object %llu", txg, spa_name(spa), object,
9da57d7b0ddd8d73b676ce12c040362132cdd538bt space_map_object(vd->vdev_dtl_sm));
9da57d7b0ddd8d73b676ce12c040362132cdd538bt vdev_config_dirty(vd->vdev_top);
9da57d7b0ddd8d73b676ce12c040362132cdd538bt }
9da57d7b0ddd8d73b676ce12c040362132cdd538bt
9da57d7b0ddd8d73b676ce12c040362132cdd538bt dmu_tx_commit(tx);
9da57d7b0ddd8d73b676ce12c040362132cdd538bt
9da57d7b0ddd8d73b676ce12c040362132cdd538bt mutex_enter(&vd->vdev_dtl_lock);
9da57d7b0ddd8d73b676ce12c040362132cdd538bt space_map_update(vd->vdev_dtl_sm);
9da57d7b0ddd8d73b676ce12c040362132cdd538bt mutex_exit(&vd->vdev_dtl_lock);
9da57d7b0ddd8d73b676ce12c040362132cdd538bt}
9da57d7b0ddd8d73b676ce12c040362132cdd538bt
9da57d7b0ddd8d73b676ce12c040362132cdd538bt/*
9da57d7b0ddd8d73b676ce12c040362132cdd538bt * Determine whether the specified vdev can be offlined/detached/removed
9da57d7b0ddd8d73b676ce12c040362132cdd538bt * without losing data.
da14cebe459d3275048785f25bd869cb09b5307fEric Cheng */
da14cebe459d3275048785f25bd869cb09b5307fEric Chengboolean_t
da14cebe459d3275048785f25bd869cb09b5307fEric Chengvdev_dtl_required(vdev_t *vd)
da14cebe459d3275048785f25bd869cb09b5307fEric Cheng{
da14cebe459d3275048785f25bd869cb09b5307fEric Cheng spa_t *spa = vd->vdev_spa;
da14cebe459d3275048785f25bd869cb09b5307fEric Cheng vdev_t *tvd = vd->vdev_top;
da14cebe459d3275048785f25bd869cb09b5307fEric Cheng uint8_t cant_read = vd->vdev_cant_read;
da14cebe459d3275048785f25bd869cb09b5307fEric Cheng boolean_t required;
da14cebe459d3275048785f25bd869cb09b5307fEric Cheng
da14cebe459d3275048785f25bd869cb09b5307fEric Cheng ASSERT(spa_config_held(spa, SCL_STATE_ALL, RW_WRITER) == SCL_STATE_ALL);
da14cebe459d3275048785f25bd869cb09b5307fEric Cheng
da14cebe459d3275048785f25bd869cb09b5307fEric Cheng if (vd == spa->spa_root_vdev || vd == tvd)
da14cebe459d3275048785f25bd869cb09b5307fEric Cheng return (B_TRUE);
da14cebe459d3275048785f25bd869cb09b5307fEric Cheng
da14cebe459d3275048785f25bd869cb09b5307fEric Cheng /*
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 */
9da57d7b0ddd8d73b676ce12c040362132cdd538bt vd->vdev_cant_read = B_TRUE;
9da57d7b0ddd8d73b676ce12c040362132cdd538bt vdev_dtl_reassess(tvd, 0, 0, B_FALSE);
9da57d7b0ddd8d73b676ce12c040362132cdd538bt required = !vdev_dtl_empty(tvd, DTL_OUTAGE);
9da57d7b0ddd8d73b676ce12c040362132cdd538bt vd->vdev_cant_read = cant_read;
9da57d7b0ddd8d73b676ce12c040362132cdd538bt vdev_dtl_reassess(tvd, 0, 0, B_FALSE);
9da57d7b0ddd8d73b676ce12c040362132cdd538bt
9da57d7b0ddd8d73b676ce12c040362132cdd538bt if (!required && zio_injection_enabled)
9da57d7b0ddd8d73b676ce12c040362132cdd538bt required = !!zio_handle_device_injection(vd, NULL, ECHILD);
9da57d7b0ddd8d73b676ce12c040362132cdd538bt
9da57d7b0ddd8d73b676ce12c040362132cdd538bt return (required);
9da57d7b0ddd8d73b676ce12c040362132cdd538bt}
9da57d7b0ddd8d73b676ce12c040362132cdd538bt
9da57d7b0ddd8d73b676ce12c040362132cdd538bt/*
9da57d7b0ddd8d73b676ce12c040362132cdd538bt * Determine if resilver is needed, and if so the txg range.
9da57d7b0ddd8d73b676ce12c040362132cdd538bt */
9da57d7b0ddd8d73b676ce12c040362132cdd538btboolean_t
9da57d7b0ddd8d73b676ce12c040362132cdd538btvdev_resilver_needed(vdev_t *vd, uint64_t *minp, uint64_t *maxp)
9da57d7b0ddd8d73b676ce12c040362132cdd538bt{
da14cebe459d3275048785f25bd869cb09b5307fEric Cheng boolean_t needed = B_FALSE;
da14cebe459d3275048785f25bd869cb09b5307fEric Cheng uint64_t thismin = UINT64_MAX;
da14cebe459d3275048785f25bd869cb09b5307fEric Cheng uint64_t thismax = 0;
da14cebe459d3275048785f25bd869cb09b5307fEric Cheng
da14cebe459d3275048785f25bd869cb09b5307fEric Cheng if (vd->vdev_children == 0) {
da14cebe459d3275048785f25bd869cb09b5307fEric Cheng mutex_enter(&vd->vdev_dtl_lock);
9da57d7b0ddd8d73b676ce12c040362132cdd538bt if (range_tree_space(vd->vdev_dtl[DTL_MISSING]) != 0 &&
9da57d7b0ddd8d73b676ce12c040362132cdd538bt vdev_writeable(vd)) {
ea65739ebec0cbd625d8c89e19592be58fa186a6chenlu chen - Sun Microsystems - Beijing China
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 }
ea65739ebec0cbd625d8c89e19592be58fa186a6chenlu chen - Sun Microsystems - Beijing China mutex_exit(&vd->vdev_dtl_lock);
ea65739ebec0cbd625d8c89e19592be58fa186a6chenlu chen - Sun Microsystems - Beijing China } else {
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
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 }
ea65739ebec0cbd625d8c89e19592be58fa186a6chenlu chen - Sun Microsystems - Beijing China }
ea65739ebec0cbd625d8c89e19592be58fa186a6chenlu chen - Sun Microsystems - Beijing China }
ea65739ebec0cbd625d8c89e19592be58fa186a6chenlu chen - Sun Microsystems - Beijing China
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 }
ea65739ebec0cbd625d8c89e19592be58fa186a6chenlu chen - Sun Microsystems - Beijing China return (needed);
ea65739ebec0cbd625d8c89e19592be58fa186a6chenlu chen - Sun Microsystems - Beijing China}
ea65739ebec0cbd625d8c89e19592be58fa186a6chenlu chen - Sun Microsystems - Beijing China
ea65739ebec0cbd625d8c89e19592be58fa186a6chenlu chen - Sun Microsystems - Beijing Chinavoid
ea65739ebec0cbd625d8c89e19592be58fa186a6chenlu chen - Sun Microsystems - Beijing Chinavdev_load(vdev_t *vd)
ea65739ebec0cbd625d8c89e19592be58fa186a6chenlu chen - Sun Microsystems - Beijing China{
ea65739ebec0cbd625d8c89e19592be58fa186a6chenlu chen - Sun Microsystems - Beijing China /*
ea65739ebec0cbd625d8c89e19592be58fa186a6chenlu chen - Sun Microsystems - Beijing China * Recursively load all children.
ea65739ebec0cbd625d8c89e19592be58fa186a6chenlu chen - Sun Microsystems - Beijing China */
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
ea65739ebec0cbd625d8c89e19592be58fa186a6chenlu chen - Sun Microsystems - Beijing China /*
ea65739ebec0cbd625d8c89e19592be58fa186a6chenlu chen - Sun Microsystems - Beijing China * If this is a top-level vdev, initialize its metaslabs.
ea65739ebec0cbd625d8c89e19592be58fa186a6chenlu chen - Sun Microsystems - Beijing China */
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);
ea65739ebec0cbd625d8c89e19592be58fa186a6chenlu chen - Sun Microsystems - Beijing China
9da57d7b0ddd8d73b676ce12c040362132cdd538bt /*
9da57d7b0ddd8d73b676ce12c040362132cdd538bt * If this is a leaf vdev, load its DTL.
9da57d7b0ddd8d73b676ce12c040362132cdd538bt */
9da57d7b0ddd8d73b676ce12c040362132cdd538bt if (vd->vdev_ops->vdev_op_leaf && vdev_dtl_load(vd) != 0)
9da57d7b0ddd8d73b676ce12c040362132cdd538bt vdev_set_state(vd, B_FALSE, VDEV_STATE_CANT_OPEN,
9da57d7b0ddd8d73b676ce12c040362132cdd538bt VDEV_AUX_CORRUPT_DATA);
9da57d7b0ddd8d73b676ce12c040362132cdd538bt}
9da57d7b0ddd8d73b676ce12c040362132cdd538bt
9da57d7b0ddd8d73b676ce12c040362132cdd538bt/*
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.
9da57d7b0ddd8d73b676ce12c040362132cdd538bt */
9da57d7b0ddd8d73b676ce12c040362132cdd538btint
9da57d7b0ddd8d73b676ce12c040362132cdd538btvdev_validate_aux(vdev_t *vd)
9da57d7b0ddd8d73b676ce12c040362132cdd538bt{
9da57d7b0ddd8d73b676ce12c040362132cdd538bt nvlist_t *label;
9da57d7b0ddd8d73b676ce12c040362132cdd538bt uint64_t guid, version;
9da57d7b0ddd8d73b676ce12c040362132cdd538bt uint64_t state;
9da57d7b0ddd8d73b676ce12c040362132cdd538bt
ea65739ebec0cbd625d8c89e19592be58fa186a6chenlu chen - Sun Microsystems - Beijing China if (!vdev_readable(vd))
9da57d7b0ddd8d73b676ce12c040362132cdd538bt return (0);
9da57d7b0ddd8d73b676ce12c040362132cdd538bt
9da57d7b0ddd8d73b676ce12c040362132cdd538bt if ((label = vdev_label_read_config(vd, -1ULL)) == NULL) {
9da57d7b0ddd8d73b676ce12c040362132cdd538bt vdev_set_state(vd, B_TRUE, VDEV_STATE_CANT_OPEN,
9da57d7b0ddd8d73b676ce12c040362132cdd538bt VDEV_AUX_CORRUPT_DATA);
9da57d7b0ddd8d73b676ce12c040362132cdd538bt return (-1);
9da57d7b0ddd8d73b676ce12c040362132cdd538bt }
9da57d7b0ddd8d73b676ce12c040362132cdd538bt
9da57d7b0ddd8d73b676ce12c040362132cdd538bt if (nvlist_lookup_uint64(label, ZPOOL_CONFIG_VERSION, &version) != 0 ||
9da57d7b0ddd8d73b676ce12c040362132cdd538bt !SPA_VERSION_IS_SUPPORTED(version) ||
9da57d7b0ddd8d73b676ce12c040362132cdd538bt nvlist_lookup_uint64(label, ZPOOL_CONFIG_GUID, &guid) != 0 ||
9da57d7b0ddd8d73b676ce12c040362132cdd538bt guid != vd->vdev_guid ||
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 nvlist_free(label);
9da57d7b0ddd8d73b676ce12c040362132cdd538bt return (-1);
9da57d7b0ddd8d73b676ce12c040362132cdd538bt }
9da57d7b0ddd8d73b676ce12c040362132cdd538bt
9da57d7b0ddd8d73b676ce12c040362132cdd538bt /*
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.
9da57d7b0ddd8d73b676ce12c040362132cdd538bt */
ea65739ebec0cbd625d8c89e19592be58fa186a6chenlu chen - Sun Microsystems - Beijing China nvlist_free(label);
0dc2366f7b9f9f36e10909b1e95edbf2a261c2acVenugopal Iyer return (0);
9da57d7b0ddd8d73b676ce12c040362132cdd538bt}
9da57d7b0ddd8d73b676ce12c040362132cdd538bt
9da57d7b0ddd8d73b676ce12c040362132cdd538btvoid
9da57d7b0ddd8d73b676ce12c040362132cdd538btvdev_remove(vdev_t *vd, uint64_t txg)
ea65739ebec0cbd625d8c89e19592be58fa186a6chenlu chen - Sun Microsystems - Beijing China{
ea65739ebec0cbd625d8c89e19592be58fa186a6chenlu chen - Sun Microsystems - Beijing China spa_t *spa = vd->vdev_spa;
0dc2366f7b9f9f36e10909b1e95edbf2a261c2acVenugopal Iyer objset_t *mos = spa->spa_meta_objset;
0dc2366f7b9f9f36e10909b1e95edbf2a261c2acVenugopal Iyer dmu_tx_t *tx;
9da57d7b0ddd8d73b676ce12c040362132cdd538bt
9da57d7b0ddd8d73b676ce12c040362132cdd538bt tx = dmu_tx_create_assigned(spa_get_dsl(spa), txg);
9da57d7b0ddd8d73b676ce12c040362132cdd538bt
9da57d7b0ddd8d73b676ce12c040362132cdd538bt if (vd->vdev_ms != NULL) {
0dc2366f7b9f9f36e10909b1e95edbf2a261c2acVenugopal Iyer metaslab_group_t *mg = vd->vdev_mg;
0dc2366f7b9f9f36e10909b1e95edbf2a261c2acVenugopal Iyer
0dc2366f7b9f9f36e10909b1e95edbf2a261c2acVenugopal Iyer metaslab_group_histogram_verify(mg);
9da57d7b0ddd8d73b676ce12c040362132cdd538bt metaslab_class_histogram_verify(mg->mg_class);
ea65739ebec0cbd625d8c89e19592be58fa186a6chenlu chen - Sun Microsystems - Beijing China
ffd8e8832e01f996f32459073f4dd308fe5265baWinson Wang - Sun Microsystems - Beijing China for (int m = 0; m < vd->vdev_ms_count; m++) {
9da57d7b0ddd8d73b676ce12c040362132cdd538bt metaslab_t *msp = vd->vdev_ms[m];
9da57d7b0ddd8d73b676ce12c040362132cdd538bt
9da57d7b0ddd8d73b676ce12c040362132cdd538bt if (msp == NULL || msp->ms_sm == NULL)
9da57d7b0ddd8d73b676ce12c040362132cdd538bt continue;
9da57d7b0ddd8d73b676ce12c040362132cdd538bt
9da57d7b0ddd8d73b676ce12c040362132cdd538bt mutex_enter(&msp->ms_lock);
9da57d7b0ddd8d73b676ce12c040362132cdd538bt /*
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 */
73cd555c10e70dac413ae4b40de8450a291750acBin Tu - Sun Microsystems - Beijing China metaslab_group_histogram_remove(mg, msp);
0dc2366f7b9f9f36e10909b1e95edbf2a261c2acVenugopal Iyer
9da57d7b0ddd8d73b676ce12c040362132cdd538bt VERIFY0(space_map_allocated(msp->ms_sm));
69b5a878d62fdee1b12e78371ce6cc8abddcad15Dan McDonald space_map_free(msp->ms_sm, tx);
69b5a878d62fdee1b12e78371ce6cc8abddcad15Dan McDonald space_map_close(msp->ms_sm);
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 }
73cd555c10e70dac413ae4b40de8450a291750acBin Tu - Sun Microsystems - Beijing China
73cd555c10e70dac413ae4b40de8450a291750acBin Tu - Sun Microsystems - Beijing China metaslab_group_histogram_verify(mg);
9da57d7b0ddd8d73b676ce12c040362132cdd538bt metaslab_class_histogram_verify(mg->mg_class);
9da57d7b0ddd8d73b676ce12c040362132cdd538bt for (int i = 0; i < RANGE_TREE_HISTOGRAM_SIZE; i++)
9da57d7b0ddd8d73b676ce12c040362132cdd538bt ASSERT0(mg->mg_histogram[i]);
9da57d7b0ddd8d73b676ce12c040362132cdd538bt
9da57d7b0ddd8d73b676ce12c040362132cdd538bt }
9da57d7b0ddd8d73b676ce12c040362132cdd538bt
73cd555c10e70dac413ae4b40de8450a291750acBin Tu - Sun Microsystems - Beijing China if (vd->vdev_ms_array) {
0dc2366f7b9f9f36e10909b1e95edbf2a261c2acVenugopal Iyer (void) dmu_object_free(mos, vd->vdev_ms_array, tx);
9da57d7b0ddd8d73b676ce12c040362132cdd538bt vd->vdev_ms_array = 0;
9da57d7b0ddd8d73b676ce12c040362132cdd538bt }
9da57d7b0ddd8d73b676ce12c040362132cdd538bt dmu_tx_commit(tx);
9da57d7b0ddd8d73b676ce12c040362132cdd538bt}
9da57d7b0ddd8d73b676ce12c040362132cdd538bt
9da57d7b0ddd8d73b676ce12c040362132cdd538btvoid
9da57d7b0ddd8d73b676ce12c040362132cdd538btvdev_sync_done(vdev_t *vd, uint64_t txg)
9da57d7b0ddd8d73b676ce12c040362132cdd538bt{
da14cebe459d3275048785f25bd869cb09b5307fEric Cheng metaslab_t *msp;
0dc2366f7b9f9f36e10909b1e95edbf2a261c2acVenugopal Iyer boolean_t reassess = !txg_list_empty(&vd->vdev_ms_list, TXG_CLEAN(txg));
0dc2366f7b9f9f36e10909b1e95edbf2a261c2acVenugopal Iyer
9da57d7b0ddd8d73b676ce12c040362132cdd538bt ASSERT(!vd->vdev_ishole);
73cd555c10e70dac413ae4b40de8450a291750acBin Tu - Sun Microsystems - Beijing China
0dc2366f7b9f9f36e10909b1e95edbf2a261c2acVenugopal Iyer while (msp = txg_list_remove(&vd->vdev_ms_list, TXG_CLEAN(txg)))
0dc2366f7b9f9f36e10909b1e95edbf2a261c2acVenugopal Iyer metaslab_sync_done(msp, txg);
0dc2366f7b9f9f36e10909b1e95edbf2a261c2acVenugopal Iyer
0dc2366f7b9f9f36e10909b1e95edbf2a261c2acVenugopal Iyer if (reassess)
0dc2366f7b9f9f36e10909b1e95edbf2a261c2acVenugopal Iyer metaslab_sync_reassess(vd->vdev_mg);
0dc2366f7b9f9f36e10909b1e95edbf2a261c2acVenugopal Iyer}
0dc2366f7b9f9f36e10909b1e95edbf2a261c2acVenugopal Iyer
0dc2366f7b9f9f36e10909b1e95edbf2a261c2acVenugopal Iyervoid
0dc2366f7b9f9f36e10909b1e95edbf2a261c2acVenugopal Iyervdev_sync(vdev_t *vd, uint64_t txg)
0dc2366f7b9f9f36e10909b1e95edbf2a261c2acVenugopal Iyer{
0dc2366f7b9f9f36e10909b1e95edbf2a261c2acVenugopal Iyer spa_t *spa = vd->vdev_spa;
0dc2366f7b9f9f36e10909b1e95edbf2a261c2acVenugopal Iyer vdev_t *lvd;
0dc2366f7b9f9f36e10909b1e95edbf2a261c2acVenugopal Iyer metaslab_t *msp;
0dc2366f7b9f9f36e10909b1e95edbf2a261c2acVenugopal Iyer dmu_tx_t *tx;
0dc2366f7b9f9f36e10909b1e95edbf2a261c2acVenugopal Iyer
0dc2366f7b9f9f36e10909b1e95edbf2a261c2acVenugopal Iyer ASSERT(!vd->vdev_ishole);
0dc2366f7b9f9f36e10909b1e95edbf2a261c2acVenugopal Iyer
0dc2366f7b9f9f36e10909b1e95edbf2a261c2acVenugopal Iyer if (vd->vdev_ms_array == 0 && vd->vdev_ms_shift != 0) {
0dc2366f7b9f9f36e10909b1e95edbf2a261c2acVenugopal Iyer ASSERT(vd == vd->vdev_top);
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 ASSERT(vd->vdev_ms_array != 0);
9da57d7b0ddd8d73b676ce12c040362132cdd538bt vdev_config_dirty(vd);
9da57d7b0ddd8d73b676ce12c040362132cdd538bt dmu_tx_commit(tx);
9da57d7b0ddd8d73b676ce12c040362132cdd538bt }
9da57d7b0ddd8d73b676ce12c040362132cdd538bt
9da57d7b0ddd8d73b676ce12c040362132cdd538bt /*
9da57d7b0ddd8d73b676ce12c040362132cdd538bt * Remove the metadata associated with this vdev once it's empty.
9da57d7b0ddd8d73b676ce12c040362132cdd538bt */
9da57d7b0ddd8d73b676ce12c040362132cdd538bt if (vd->vdev_stat.vs_alloc == 0 && vd->vdev_removing)
9da57d7b0ddd8d73b676ce12c040362132cdd538bt vdev_remove(vd, txg);
0dc2366f7b9f9f36e10909b1e95edbf2a261c2acVenugopal Iyer
0dc2366f7b9f9f36e10909b1e95edbf2a261c2acVenugopal Iyer while ((msp = txg_list_remove(&vd->vdev_ms_list, txg)) != NULL) {
0dc2366f7b9f9f36e10909b1e95edbf2a261c2acVenugopal Iyer metaslab_sync(msp, txg);
0dc2366f7b9f9f36e10909b1e95edbf2a261c2acVenugopal Iyer (void) txg_list_add(&vd->vdev_ms_list, msp, TXG_CLEAN(txg));
0dc2366f7b9f9f36e10909b1e95edbf2a261c2acVenugopal Iyer }
0dc2366f7b9f9f36e10909b1e95edbf2a261c2acVenugopal Iyer
0dc2366f7b9f9f36e10909b1e95edbf2a261c2acVenugopal Iyer while ((lvd = txg_list_remove(&vd->vdev_dtl_list, txg)) != NULL)
0dc2366f7b9f9f36e10909b1e95edbf2a261c2acVenugopal Iyer vdev_dtl_sync(lvd, txg);
0dc2366f7b9f9f36e10909b1e95edbf2a261c2acVenugopal Iyer
0dc2366f7b9f9f36e10909b1e95edbf2a261c2acVenugopal Iyer (void) txg_list_add(&spa->spa_vdev_txg_list, vd, TXG_CLEAN(txg));
0dc2366f7b9f9f36e10909b1e95edbf2a261c2acVenugopal Iyer}
0dc2366f7b9f9f36e10909b1e95edbf2a261c2acVenugopal Iyer
0dc2366f7b9f9f36e10909b1e95edbf2a261c2acVenugopal Iyeruint64_t
0dc2366f7b9f9f36e10909b1e95edbf2a261c2acVenugopal Iyervdev_psize_to_asize(vdev_t *vd, uint64_t psize)
0dc2366f7b9f9f36e10909b1e95edbf2a261c2acVenugopal Iyer{
0dc2366f7b9f9f36e10909b1e95edbf2a261c2acVenugopal Iyer return (vd->vdev_ops->vdev_op_asize(vd, psize));
0dc2366f7b9f9f36e10909b1e95edbf2a261c2acVenugopal Iyer}
0dc2366f7b9f9f36e10909b1e95edbf2a261c2acVenugopal Iyer
0dc2366f7b9f9f36e10909b1e95edbf2a261c2acVenugopal Iyer/*
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 Iyer */
0dc2366f7b9f9f36e10909b1e95edbf2a261c2acVenugopal Iyerint
0dc2366f7b9f9f36e10909b1e95edbf2a261c2acVenugopal Iyervdev_fault(spa_t *spa, uint64_t guid, vdev_aux_t aux)
0dc2366f7b9f9f36e10909b1e95edbf2a261c2acVenugopal Iyer{
0dc2366f7b9f9f36e10909b1e95edbf2a261c2acVenugopal Iyer vdev_t *vd, *tvd;
0dc2366f7b9f9f36e10909b1e95edbf2a261c2acVenugopal Iyer
0dc2366f7b9f9f36e10909b1e95edbf2a261c2acVenugopal Iyer spa_vdev_state_enter(spa, SCL_NONE);
0dc2366f7b9f9f36e10909b1e95edbf2a261c2acVenugopal Iyer
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
0dc2366f7b9f9f36e10909b1e95edbf2a261c2acVenugopal Iyer if (!vd->vdev_ops->vdev_op_leaf)
0dc2366f7b9f9f36e10909b1e95edbf2a261c2acVenugopal Iyer return (spa_vdev_state_exit(spa, NULL, ENOTSUP));
0dc2366f7b9f9f36e10909b1e95edbf2a261c2acVenugopal Iyer
0dc2366f7b9f9f36e10909b1e95edbf2a261c2acVenugopal Iyer tvd = vd->vdev_top;
0dc2366f7b9f9f36e10909b1e95edbf2a261c2acVenugopal Iyer
0dc2366f7b9f9f36e10909b1e95edbf2a261c2acVenugopal Iyer /*
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 */
9da57d7b0ddd8d73b676ce12c040362132cdd538bt vd->vdev_label_aux = aux;
9da57d7b0ddd8d73b676ce12c040362132cdd538bt
9da57d7b0ddd8d73b676ce12c040362132cdd538bt /*
9da57d7b0ddd8d73b676ce12c040362132cdd538bt * Faulted state takes precedence over degraded.
9da57d7b0ddd8d73b676ce12c040362132cdd538bt */
9da57d7b0ddd8d73b676ce12c040362132cdd538bt vd->vdev_delayed_close = B_FALSE;
9da57d7b0ddd8d73b676ce12c040362132cdd538bt vd->vdev_faulted = 1ULL;
9da57d7b0ddd8d73b676ce12c040362132cdd538bt vd->vdev_degraded = 0ULL;
9da57d7b0ddd8d73b676ce12c040362132cdd538bt vdev_set_state(vd, B_FALSE, VDEV_STATE_FAULTED, aux);
9da57d7b0ddd8d73b676ce12c040362132cdd538bt
9da57d7b0ddd8d73b676ce12c040362132cdd538bt /*
9da57d7b0ddd8d73b676ce12c040362132cdd538bt * If this device has the only valid copy of the data, then
9da57d7b0ddd8d73b676ce12c040362132cdd538bt * back off and simply mark the vdev as degraded instead.
9da57d7b0ddd8d73b676ce12c040362132cdd538bt */
da14cebe459d3275048785f25bd869cb09b5307fEric Cheng if (!tvd->vdev_islog && vd->vdev_aux == NULL && vdev_dtl_required(vd)) {
da14cebe459d3275048785f25bd869cb09b5307fEric Cheng vd->vdev_degraded = 1ULL;
da14cebe459d3275048785f25bd869cb09b5307fEric Cheng vd->vdev_faulted = 0ULL;
da14cebe459d3275048785f25bd869cb09b5307fEric Cheng
da14cebe459d3275048785f25bd869cb09b5307fEric Cheng /*
0dc2366f7b9f9f36e10909b1e95edbf2a261c2acVenugopal Iyer * If we reopen the device and it's not dead, only then do we
0dc2366f7b9f9f36e10909b1e95edbf2a261c2acVenugopal Iyer * mark it degraded.
0dc2366f7b9f9f36e10909b1e95edbf2a261c2acVenugopal Iyer */
0dc2366f7b9f9f36e10909b1e95edbf2a261c2acVenugopal Iyer vdev_reopen(tvd);
da14cebe459d3275048785f25bd869cb09b5307fEric Cheng
da14cebe459d3275048785f25bd869cb09b5307fEric Cheng if (vdev_readable(vd))
9da57d7b0ddd8d73b676ce12c040362132cdd538bt vdev_set_state(vd, B_FALSE, VDEV_STATE_DEGRADED, aux);
73cd555c10e70dac413ae4b40de8450a291750acBin Tu - Sun Microsystems - Beijing China }
73cd555c10e70dac413ae4b40de8450a291750acBin Tu - Sun Microsystems - Beijing China
73cd555c10e70dac413ae4b40de8450a291750acBin Tu - Sun Microsystems - Beijing China return (spa_vdev_state_exit(spa, vd, 0));
73cd555c10e70dac413ae4b40de8450a291750acBin Tu - Sun Microsystems - Beijing China}
9da57d7b0ddd8d73b676ce12c040362132cdd538bt
9da57d7b0ddd8d73b676ce12c040362132cdd538bt/*
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.
9da57d7b0ddd8d73b676ce12c040362132cdd538bt */
9da57d7b0ddd8d73b676ce12c040362132cdd538btint
9da57d7b0ddd8d73b676ce12c040362132cdd538btvdev_degrade(spa_t *spa, uint64_t guid, vdev_aux_t aux)
9da57d7b0ddd8d73b676ce12c040362132cdd538bt{
9da57d7b0ddd8d73b676ce12c040362132cdd538bt vdev_t *vd;
9da57d7b0ddd8d73b676ce12c040362132cdd538bt
9da57d7b0ddd8d73b676ce12c040362132cdd538bt spa_vdev_state_enter(spa, SCL_NONE);
9da57d7b0ddd8d73b676ce12c040362132cdd538bt
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
1878b97151eb2746480d8b2139fa08a2e8f14df3Venugopal Iyer if (!vd->vdev_ops->vdev_op_leaf)
1878b97151eb2746480d8b2139fa08a2e8f14df3Venugopal Iyer return (spa_vdev_state_exit(spa, NULL, ENOTSUP));
1878b97151eb2746480d8b2139fa08a2e8f14df3Venugopal Iyer
1878b97151eb2746480d8b2139fa08a2e8f14df3Venugopal Iyer /*
1878b97151eb2746480d8b2139fa08a2e8f14df3Venugopal Iyer * If the vdev is already faulted, then don't do anything.
1878b97151eb2746480d8b2139fa08a2e8f14df3Venugopal Iyer */
1878b97151eb2746480d8b2139fa08a2e8f14df3Venugopal Iyer if (vd->vdev_faulted || vd->vdev_degraded)
1878b97151eb2746480d8b2139fa08a2e8f14df3Venugopal Iyer return (spa_vdev_state_exit(spa, NULL, 0));
1878b97151eb2746480d8b2139fa08a2e8f14df3Venugopal Iyer
1878b97151eb2746480d8b2139fa08a2e8f14df3Venugopal Iyer vd->vdev_degraded = 1ULL;
1878b97151eb2746480d8b2139fa08a2e8f14df3Venugopal Iyer if (!vdev_is_dead(vd))
1878b97151eb2746480d8b2139fa08a2e8f14df3Venugopal Iyer vdev_set_state(vd, B_FALSE, VDEV_STATE_DEGRADED,
1878b97151eb2746480d8b2139fa08a2e8f14df3Venugopal Iyer aux);
1878b97151eb2746480d8b2139fa08a2e8f14df3Venugopal Iyer
1878b97151eb2746480d8b2139fa08a2e8f14df3Venugopal Iyer return (spa_vdev_state_exit(spa, vd, 0));
1878b97151eb2746480d8b2139fa08a2e8f14df3Venugopal Iyer}
1878b97151eb2746480d8b2139fa08a2e8f14df3Venugopal Iyer
1878b97151eb2746480d8b2139fa08a2e8f14df3Venugopal Iyer/*
1878b97151eb2746480d8b2139fa08a2e8f14df3Venugopal Iyer * Online the given vdev.
1878b97151eb2746480d8b2139fa08a2e8f14df3Venugopal Iyer *
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 Iyer */
1878b97151eb2746480d8b2139fa08a2e8f14df3Venugopal Iyerint
1878b97151eb2746480d8b2139fa08a2e8f14df3Venugopal Iyervdev_online(spa_t *spa, uint64_t guid, uint64_t flags, vdev_state_t *newstate)
1878b97151eb2746480d8b2139fa08a2e8f14df3Venugopal Iyer{
9da57d7b0ddd8d73b676ce12c040362132cdd538bt vdev_t *vd, *tvd, *pvd, *rvd = spa->spa_root_vdev;
9da57d7b0ddd8d73b676ce12c040362132cdd538bt
9da57d7b0ddd8d73b676ce12c040362132cdd538bt spa_vdev_state_enter(spa, SCL_NONE);
9da57d7b0ddd8d73b676ce12c040362132cdd538bt
9da57d7b0ddd8d73b676ce12c040362132cdd538bt if ((vd = spa_lookup_by_guid(spa, guid, B_TRUE)) == NULL)
9da57d7b0ddd8d73b676ce12c040362132cdd538bt return (spa_vdev_state_exit(spa, NULL, ENODEV));
9da57d7b0ddd8d73b676ce12c040362132cdd538bt
9da57d7b0ddd8d73b676ce12c040362132cdd538bt if (!vd->vdev_ops->vdev_op_leaf)
9da57d7b0ddd8d73b676ce12c040362132cdd538bt return (spa_vdev_state_exit(spa, NULL, ENOTSUP));
9da57d7b0ddd8d73b676ce12c040362132cdd538bt
9da57d7b0ddd8d73b676ce12c040362132cdd538bt tvd = vd->vdev_top;
9da57d7b0ddd8d73b676ce12c040362132cdd538bt vd->vdev_offline = B_FALSE;
9da57d7b0ddd8d73b676ce12c040362132cdd538bt vd->vdev_tmpoffline = B_FALSE;
9da57d7b0ddd8d73b676ce12c040362132cdd538bt vd->vdev_checkremove = !!(flags & ZFS_ONLINE_CHECKREMOVE);
9da57d7b0ddd8d73b676ce12c040362132cdd538bt vd->vdev_forcefault = !!(flags & ZFS_ONLINE_FORCEFAULT);
9da57d7b0ddd8d73b676ce12c040362132cdd538bt
9da57d7b0ddd8d73b676ce12c040362132cdd538bt /* XXX - L2ARC 1.0 does not support expansion */
9da57d7b0ddd8d73b676ce12c040362132cdd538bt if (!vd->vdev_aux) {
9da57d7b0ddd8d73b676ce12c040362132cdd538bt for (pvd = vd; pvd != rvd; pvd = pvd->vdev_parent)
9da57d7b0ddd8d73b676ce12c040362132cdd538bt pvd->vdev_expanding = !!(flags & ZFS_ONLINE_EXPAND);
9da57d7b0ddd8d73b676ce12c040362132cdd538bt }
9da57d7b0ddd8d73b676ce12c040362132cdd538bt
9da57d7b0ddd8d73b676ce12c040362132cdd538bt vdev_reopen(tvd);
9da57d7b0ddd8d73b676ce12c040362132cdd538bt vd->vdev_checkremove = vd->vdev_forcefault = B_FALSE;
9da57d7b0ddd8d73b676ce12c040362132cdd538bt
9da57d7b0ddd8d73b676ce12c040362132cdd538bt if (!vd->vdev_aux) {
9da57d7b0ddd8d73b676ce12c040362132cdd538bt for (pvd = vd; pvd != rvd; pvd = pvd->vdev_parent)
9da57d7b0ddd8d73b676ce12c040362132cdd538bt pvd->vdev_expanding = B_FALSE;
9da57d7b0ddd8d73b676ce12c040362132cdd538bt }
9da57d7b0ddd8d73b676ce12c040362132cdd538bt
9da57d7b0ddd8d73b676ce12c040362132cdd538bt if (newstate)
9da57d7b0ddd8d73b676ce12c040362132cdd538bt *newstate = vd->vdev_state;
9da57d7b0ddd8d73b676ce12c040362132cdd538bt if ((flags & ZFS_ONLINE_UNSPARE) &&
9da57d7b0ddd8d73b676ce12c040362132cdd538bt !vdev_is_dead(vd) && vd->vdev_parent &&
9da57d7b0ddd8d73b676ce12c040362132cdd538bt vd->vdev_parent->vdev_ops == &vdev_spare_ops &&
9da57d7b0ddd8d73b676ce12c040362132cdd538bt vd->vdev_parent->vdev_child[0] == vd)
9da57d7b0ddd8d73b676ce12c040362132cdd538bt vd->vdev_unspare = B_TRUE;
9da57d7b0ddd8d73b676ce12c040362132cdd538bt
9da57d7b0ddd8d73b676ce12c040362132cdd538bt if ((flags & ZFS_ONLINE_EXPAND) || spa->spa_autoexpand) {
9da57d7b0ddd8d73b676ce12c040362132cdd538bt
9da57d7b0ddd8d73b676ce12c040362132cdd538bt /* XXX - L2ARC 1.0 does not support expansion */
9da57d7b0ddd8d73b676ce12c040362132cdd538bt if (vd->vdev_aux)
9da57d7b0ddd8d73b676ce12c040362132cdd538bt return (spa_vdev_state_exit(spa, vd, ENOTSUP));
9da57d7b0ddd8d73b676ce12c040362132cdd538bt spa_async_request(spa, SPA_ASYNC_CONFIG_UPDATE);
9da57d7b0ddd8d73b676ce12c040362132cdd538bt }
9da57d7b0ddd8d73b676ce12c040362132cdd538bt return (spa_vdev_state_exit(spa, vd, 0));
9da57d7b0ddd8d73b676ce12c040362132cdd538bt}
9da57d7b0ddd8d73b676ce12c040362132cdd538bt
9da57d7b0ddd8d73b676ce12c040362132cdd538btstatic int
9da57d7b0ddd8d73b676ce12c040362132cdd538btvdev_offline_locked(spa_t *spa, uint64_t guid, uint64_t flags)
9da57d7b0ddd8d73b676ce12c040362132cdd538bt{
9da57d7b0ddd8d73b676ce12c040362132cdd538bt vdev_t *vd, *tvd;
9da57d7b0ddd8d73b676ce12c040362132cdd538bt int error = 0;
9da57d7b0ddd8d73b676ce12c040362132cdd538bt uint64_t generation;
9da57d7b0ddd8d73b676ce12c040362132cdd538bt metaslab_group_t *mg;
9da57d7b0ddd8d73b676ce12c040362132cdd538bt
9da57d7b0ddd8d73b676ce12c040362132cdd538bttop:
9da57d7b0ddd8d73b676ce12c040362132cdd538bt spa_vdev_state_enter(spa, SCL_ALLOC);
9da57d7b0ddd8d73b676ce12c040362132cdd538bt
9da57d7b0ddd8d73b676ce12c040362132cdd538bt if ((vd = spa_lookup_by_guid(spa, guid, B_TRUE)) == NULL)
9da57d7b0ddd8d73b676ce12c040362132cdd538bt return (spa_vdev_state_exit(spa, NULL, ENODEV));
9da57d7b0ddd8d73b676ce12c040362132cdd538bt
69b5a878d62fdee1b12e78371ce6cc8abddcad15Dan McDonald if (!vd->vdev_ops->vdev_op_leaf)
69b5a878d62fdee1b12e78371ce6cc8abddcad15Dan McDonald return (spa_vdev_state_exit(spa, NULL, ENOTSUP));
69b5a878d62fdee1b12e78371ce6cc8abddcad15Dan McDonald
69b5a878d62fdee1b12e78371ce6cc8abddcad15Dan McDonald tvd = vd->vdev_top;
69b5a878d62fdee1b12e78371ce6cc8abddcad15Dan McDonald mg = tvd->vdev_mg;
69b5a878d62fdee1b12e78371ce6cc8abddcad15Dan McDonald generation = spa->spa_config_generation + 1;
69b5a878d62fdee1b12e78371ce6cc8abddcad15Dan McDonald
69b5a878d62fdee1b12e78371ce6cc8abddcad15Dan McDonald /*
69b5a878d62fdee1b12e78371ce6cc8abddcad15Dan McDonald * If the device isn't already offline, try to offline it.
69b5a878d62fdee1b12e78371ce6cc8abddcad15Dan McDonald */
69b5a878d62fdee1b12e78371ce6cc8abddcad15Dan McDonald if (!vd->vdev_offline) {
69b5a878d62fdee1b12e78371ce6cc8abddcad15Dan McDonald /*
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 */
9da57d7b0ddd8d73b676ce12c040362132cdd538bt if (!tvd->vdev_islog && vd->vdev_aux == NULL &&
9da57d7b0ddd8d73b676ce12c040362132cdd538bt vdev_dtl_required(vd))
9da57d7b0ddd8d73b676ce12c040362132cdd538bt return (spa_vdev_state_exit(spa, NULL, EBUSY));
9da57d7b0ddd8d73b676ce12c040362132cdd538bt
ea65739ebec0cbd625d8c89e19592be58fa186a6chenlu chen - Sun Microsystems - Beijing China /*
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 */
9da57d7b0ddd8d73b676ce12c040362132cdd538bt if (tvd->vdev_islog && mg != NULL) {
f27d3025d908422c3f6e682964b4f1e2b4834e4agg /*
9da57d7b0ddd8d73b676ce12c040362132cdd538bt * Prevent any future allocations.
f27d3025d908422c3f6e682964b4f1e2b4834e4agg */
9da57d7b0ddd8d73b676ce12c040362132cdd538bt metaslab_group_passivate(mg);
9da57d7b0ddd8d73b676ce12c040362132cdd538bt (void) spa_vdev_state_exit(spa, vd, 0);
9da57d7b0ddd8d73b676ce12c040362132cdd538bt
9da57d7b0ddd8d73b676ce12c040362132cdd538bt error = spa_offline_log(spa);
9da57d7b0ddd8d73b676ce12c040362132cdd538bt
c971fb7ec0a19c6cd00c5614a94c97f953b6e8b1gg spa_vdev_state_enter(spa, SCL_ALLOC);
9da57d7b0ddd8d73b676ce12c040362132cdd538bt
c971fb7ec0a19c6cd00c5614a94c97f953b6e8b1gg /*
da14cebe459d3275048785f25bd869cb09b5307fEric Cheng * Check to see if the config has changed.
9da57d7b0ddd8d73b676ce12c040362132cdd538bt */
9da57d7b0ddd8d73b676ce12c040362132cdd538bt if (error || generation != spa->spa_config_generation) {
9da57d7b0ddd8d73b676ce12c040362132cdd538bt metaslab_group_activate(mg);
9da57d7b0ddd8d73b676ce12c040362132cdd538bt if (error)
9da57d7b0ddd8d73b676ce12c040362132cdd538bt return (spa_vdev_state_exit(spa,
9da57d7b0ddd8d73b676ce12c040362132cdd538bt vd, error));
c971fb7ec0a19c6cd00c5614a94c97f953b6e8b1gg (void) spa_vdev_state_exit(spa, vd, 0);
da14cebe459d3275048785f25bd869cb09b5307fEric Cheng goto top;
da14cebe459d3275048785f25bd869cb09b5307fEric Cheng }
da14cebe459d3275048785f25bd869cb09b5307fEric Cheng ASSERT0(tvd->vdev_stat.vs_alloc);
da14cebe459d3275048785f25bd869cb09b5307fEric Cheng }
da14cebe459d3275048785f25bd869cb09b5307fEric Cheng
da14cebe459d3275048785f25bd869cb09b5307fEric Cheng /*
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.
73cd555c10e70dac413ae4b40de8450a291750acBin Tu - Sun Microsystems - Beijing China */
5b6dd21f5401160f9a62ac2e76a858c2bc105370chenlu chen - Sun Microsystems - Beijing China vd->vdev_offline = B_TRUE;
5b6dd21f5401160f9a62ac2e76a858c2bc105370chenlu chen - Sun Microsystems - Beijing China vdev_reopen(tvd);
5b6dd21f5401160f9a62ac2e76a858c2bc105370chenlu chen - Sun Microsystems - Beijing China
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 }
5b6dd21f5401160f9a62ac2e76a858c2bc105370chenlu chen - Sun Microsystems - Beijing China
73cd555c10e70dac413ae4b40de8450a291750acBin Tu - Sun Microsystems - Beijing China /*
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.
da14cebe459d3275048785f25bd869cb09b5307fEric Cheng */
da14cebe459d3275048785f25bd869cb09b5307fEric Cheng if (tvd->vdev_islog && mg != NULL)
5b6dd21f5401160f9a62ac2e76a858c2bc105370chenlu chen - Sun Microsystems - Beijing China metaslab_group_activate(mg);
5b6dd21f5401160f9a62ac2e76a858c2bc105370chenlu chen - Sun Microsystems - Beijing China }
5b6dd21f5401160f9a62ac2e76a858c2bc105370chenlu chen - Sun Microsystems - Beijing China
73cd555c10e70dac413ae4b40de8450a291750acBin Tu - Sun Microsystems - Beijing China vd->vdev_tmpoffline = !!(flags & ZFS_OFFLINE_TEMPORARY);
5b6dd21f5401160f9a62ac2e76a858c2bc105370chenlu chen - Sun Microsystems - Beijing China
5b6dd21f5401160f9a62ac2e76a858c2bc105370chenlu chen - Sun Microsystems - Beijing China return (spa_vdev_state_exit(spa, vd, 0));
5b6dd21f5401160f9a62ac2e76a858c2bc105370chenlu chen - Sun Microsystems - Beijing China}
69b5a878d62fdee1b12e78371ce6cc8abddcad15Dan McDonald
5b6dd21f5401160f9a62ac2e76a858c2bc105370chenlu chen - Sun Microsystems - Beijing Chinaint
5b6dd21f5401160f9a62ac2e76a858c2bc105370chenlu chen - Sun Microsystems - Beijing Chinavdev_offline(spa_t *spa, uint64_t guid, uint64_t flags)
5b6dd21f5401160f9a62ac2e76a858c2bc105370chenlu chen - Sun Microsystems - Beijing China{
5b6dd21f5401160f9a62ac2e76a858c2bc105370chenlu chen - Sun Microsystems - Beijing China int error;
5b6dd21f5401160f9a62ac2e76a858c2bc105370chenlu chen - Sun Microsystems - Beijing China
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);
da14cebe459d3275048785f25bd869cb09b5307fEric Cheng mutex_exit(&spa->spa_vdev_top_lock);
c971fb7ec0a19c6cd00c5614a94c97f953b6e8b1gg
c971fb7ec0a19c6cd00c5614a94c97f953b6e8b1gg return (error);
c971fb7ec0a19c6cd00c5614a94c97f953b6e8b1gg}
c971fb7ec0a19c6cd00c5614a94c97f953b6e8b1gg
c971fb7ec0a19c6cd00c5614a94c97f953b6e8b1gg/*
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.
69b5a878d62fdee1b12e78371ce6cc8abddcad15Dan McDonald */
73cd555c10e70dac413ae4b40de8450a291750acBin Tu - Sun Microsystems - Beijing Chinavoid
69b5a878d62fdee1b12e78371ce6cc8abddcad15Dan McDonaldvdev_clear(spa_t *spa, vdev_t *vd)
69b5a878d62fdee1b12e78371ce6cc8abddcad15Dan McDonald{
69b5a878d62fdee1b12e78371ce6cc8abddcad15Dan McDonald vdev_t *rvd = spa->spa_root_vdev;
73cd555c10e70dac413ae4b40de8450a291750acBin Tu - Sun Microsystems - Beijing China
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
69b5a878d62fdee1b12e78371ce6cc8abddcad15Dan McDonald if (vd == NULL)
69b5a878d62fdee1b12e78371ce6cc8abddcad15Dan McDonald vd = rvd;
69b5a878d62fdee1b12e78371ce6cc8abddcad15Dan McDonald
69b5a878d62fdee1b12e78371ce6cc8abddcad15Dan McDonald vd->vdev_stat.vs_read_errors = 0;
69b5a878d62fdee1b12e78371ce6cc8abddcad15Dan McDonald vd->vdev_stat.vs_write_errors = 0;
69b5a878d62fdee1b12e78371ce6cc8abddcad15Dan McDonald vd->vdev_stat.vs_checksum_errors = 0;
69b5a878d62fdee1b12e78371ce6cc8abddcad15Dan McDonald
69b5a878d62fdee1b12e78371ce6cc8abddcad15Dan McDonald for (int c = 0; c < vd->vdev_children; c++)
73cd555c10e70dac413ae4b40de8450a291750acBin Tu - Sun Microsystems - Beijing China vdev_clear(spa, vd->vdev_child[c]);
73cd555c10e70dac413ae4b40de8450a291750acBin Tu - Sun Microsystems - Beijing China
73cd555c10e70dac413ae4b40de8450a291750acBin Tu - Sun Microsystems - Beijing China /*
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 */
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)) {
73cd555c10e70dac413ae4b40de8450a291750acBin Tu - Sun Microsystems - Beijing China
73cd555c10e70dac413ae4b40de8450a291750acBin Tu - Sun Microsystems - Beijing China /*
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 */
9da57d7b0ddd8d73b676ce12c040362132cdd538bt vd->vdev_forcefault = B_TRUE;
9da57d7b0ddd8d73b676ce12c040362132cdd538bt
9da57d7b0ddd8d73b676ce12c040362132cdd538bt vd->vdev_faulted = vd->vdev_degraded = 0ULL;
9da57d7b0ddd8d73b676ce12c040362132cdd538bt vd->vdev_cant_read = B_FALSE;
9da57d7b0ddd8d73b676ce12c040362132cdd538bt vd->vdev_cant_write = B_FALSE;
c971fb7ec0a19c6cd00c5614a94c97f953b6e8b1gg
9da57d7b0ddd8d73b676ce12c040362132cdd538bt vdev_reopen(vd == rvd ? rvd : vd->vdev_top);
9da57d7b0ddd8d73b676ce12c040362132cdd538bt
0dc2366f7b9f9f36e10909b1e95edbf2a261c2acVenugopal Iyer vd->vdev_forcefault = B_FALSE;
9da57d7b0ddd8d73b676ce12c040362132cdd538bt
9da57d7b0ddd8d73b676ce12c040362132cdd538bt if (vd != rvd && vdev_writeable(vd->vdev_top))
9da57d7b0ddd8d73b676ce12c040362132cdd538bt vdev_state_dirty(vd->vdev_top);
9da57d7b0ddd8d73b676ce12c040362132cdd538bt
9da57d7b0ddd8d73b676ce12c040362132cdd538bt if (vd->vdev_aux == NULL && !vdev_is_dead(vd))
0dc2366f7b9f9f36e10909b1e95edbf2a261c2acVenugopal Iyer spa_async_request(spa, SPA_ASYNC_RESILVER);
0dc2366f7b9f9f36e10909b1e95edbf2a261c2acVenugopal Iyer
9da57d7b0ddd8d73b676ce12c040362132cdd538bt spa_event_notify(spa, vd, ESC_ZFS_VDEV_CLEAR);
0dc2366f7b9f9f36e10909b1e95edbf2a261c2acVenugopal Iyer }
0dc2366f7b9f9f36e10909b1e95edbf2a261c2acVenugopal Iyer
c971fb7ec0a19c6cd00c5614a94c97f953b6e8b1gg /*
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 */
9da57d7b0ddd8d73b676ce12c040362132cdd538bt if (!vdev_is_dead(vd) && vd->vdev_parent != NULL &&
9da57d7b0ddd8d73b676ce12c040362132cdd538bt vd->vdev_parent->vdev_ops == &vdev_spare_ops &&
9da57d7b0ddd8d73b676ce12c040362132cdd538bt vd->vdev_parent->vdev_child[0] == vd)
9da57d7b0ddd8d73b676ce12c040362132cdd538bt vd->vdev_unspare = B_TRUE;
9da57d7b0ddd8d73b676ce12c040362132cdd538bt}
9da57d7b0ddd8d73b676ce12c040362132cdd538bt
9da57d7b0ddd8d73b676ce12c040362132cdd538btboolean_t
9da57d7b0ddd8d73b676ce12c040362132cdd538btvdev_is_dead(vdev_t *vd)
9da57d7b0ddd8d73b676ce12c040362132cdd538bt{
c971fb7ec0a19c6cd00c5614a94c97f953b6e8b1gg /*
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 */
9da57d7b0ddd8d73b676ce12c040362132cdd538bt return (vd->vdev_state < VDEV_STATE_DEGRADED || vd->vdev_ishole ||
9da57d7b0ddd8d73b676ce12c040362132cdd538bt vd->vdev_ops == &vdev_missing_ops);
9da57d7b0ddd8d73b676ce12c040362132cdd538bt}
9da57d7b0ddd8d73b676ce12c040362132cdd538bt
9da57d7b0ddd8d73b676ce12c040362132cdd538btboolean_t
9da57d7b0ddd8d73b676ce12c040362132cdd538btvdev_readable(vdev_t *vd)
9da57d7b0ddd8d73b676ce12c040362132cdd538bt{
9da57d7b0ddd8d73b676ce12c040362132cdd538bt return (!vdev_is_dead(vd) && !vd->vdev_cant_read);
9da57d7b0ddd8d73b676ce12c040362132cdd538bt}
9da57d7b0ddd8d73b676ce12c040362132cdd538bt
9da57d7b0ddd8d73b676ce12c040362132cdd538btboolean_t
9da57d7b0ddd8d73b676ce12c040362132cdd538btvdev_writeable(vdev_t *vd)
9da57d7b0ddd8d73b676ce12c040362132cdd538bt{
9da57d7b0ddd8d73b676ce12c040362132cdd538bt return (!vdev_is_dead(vd) && !vd->vdev_cant_write);
9da57d7b0ddd8d73b676ce12c040362132cdd538bt}
9da57d7b0ddd8d73b676ce12c040362132cdd538bt
9da57d7b0ddd8d73b676ce12c040362132cdd538btboolean_t
9da57d7b0ddd8d73b676ce12c040362132cdd538btvdev_allocatable(vdev_t *vd)
0dc2366f7b9f9f36e10909b1e95edbf2a261c2acVenugopal Iyer{
0dc2366f7b9f9f36e10909b1e95edbf2a261c2acVenugopal Iyer uint64_t state = vd->vdev_state;
0dc2366f7b9f9f36e10909b1e95edbf2a261c2acVenugopal Iyer
0dc2366f7b9f9f36e10909b1e95edbf2a261c2acVenugopal Iyer /*
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 */
0dc2366f7b9f9f36e10909b1e95edbf2a261c2acVenugopal Iyer return (!(state < VDEV_STATE_DEGRADED && state != VDEV_STATE_CLOSED) &&
0dc2366f7b9f9f36e10909b1e95edbf2a261c2acVenugopal Iyer !vd->vdev_cant_write && !vd->vdev_ishole);
0dc2366f7b9f9f36e10909b1e95edbf2a261c2acVenugopal Iyer}
0dc2366f7b9f9f36e10909b1e95edbf2a261c2acVenugopal Iyer
0dc2366f7b9f9f36e10909b1e95edbf2a261c2acVenugopal Iyerboolean_t
0dc2366f7b9f9f36e10909b1e95edbf2a261c2acVenugopal Iyervdev_accessible(vdev_t *vd, zio_t *zio)
0dc2366f7b9f9f36e10909b1e95edbf2a261c2acVenugopal Iyer{
0dc2366f7b9f9f36e10909b1e95edbf2a261c2acVenugopal Iyer ASSERT(zio->io_vd == vd);
0dc2366f7b9f9f36e10909b1e95edbf2a261c2acVenugopal Iyer
0dc2366f7b9f9f36e10909b1e95edbf2a261c2acVenugopal Iyer if (vdev_is_dead(vd) || vd->vdev_remove_wanted)
0dc2366f7b9f9f36e10909b1e95edbf2a261c2acVenugopal Iyer return (B_FALSE);
0dc2366f7b9f9f36e10909b1e95edbf2a261c2acVenugopal Iyer
0dc2366f7b9f9f36e10909b1e95edbf2a261c2acVenugopal Iyer if (zio->io_type == ZIO_TYPE_READ)
0dc2366f7b9f9f36e10909b1e95edbf2a261c2acVenugopal Iyer return (!vd->vdev_cant_read);
69b5a878d62fdee1b12e78371ce6cc8abddcad15Dan McDonald
0dc2366f7b9f9f36e10909b1e95edbf2a261c2acVenugopal Iyer if (zio->io_type == ZIO_TYPE_WRITE)
0dc2366f7b9f9f36e10909b1e95edbf2a261c2acVenugopal Iyer return (!vd->vdev_cant_write);
0dc2366f7b9f9f36e10909b1e95edbf2a261c2acVenugopal Iyer
0dc2366f7b9f9f36e10909b1e95edbf2a261c2acVenugopal Iyer return (B_TRUE);
0dc2366f7b9f9f36e10909b1e95edbf2a261c2acVenugopal Iyer}
0dc2366f7b9f9f36e10909b1e95edbf2a261c2acVenugopal Iyer
0dc2366f7b9f9f36e10909b1e95edbf2a261c2acVenugopal Iyer/*
0dc2366f7b9f9f36e10909b1e95edbf2a261c2acVenugopal Iyer * Get statistics for the given vdev.
0dc2366f7b9f9f36e10909b1e95edbf2a261c2acVenugopal Iyer */
0dc2366f7b9f9f36e10909b1e95edbf2a261c2acVenugopal Iyervoid
0dc2366f7b9f9f36e10909b1e95edbf2a261c2acVenugopal Iyervdev_get_stats(vdev_t *vd, vdev_stat_t *vs)
0dc2366f7b9f9f36e10909b1e95edbf2a261c2acVenugopal Iyer{
0dc2366f7b9f9f36e10909b1e95edbf2a261c2acVenugopal Iyer spa_t *spa = vd->vdev_spa;
0dc2366f7b9f9f36e10909b1e95edbf2a261c2acVenugopal Iyer vdev_t *rvd = spa->spa_root_vdev;
0dc2366f7b9f9f36e10909b1e95edbf2a261c2acVenugopal Iyer
0dc2366f7b9f9f36e10909b1e95edbf2a261c2acVenugopal Iyer ASSERT(spa_config_held(spa, SCL_ALL, RW_READER) != 0);
0dc2366f7b9f9f36e10909b1e95edbf2a261c2acVenugopal Iyer
0dc2366f7b9f9f36e10909b1e95edbf2a261c2acVenugopal Iyer mutex_enter(&vd->vdev_stat_lock);
0dc2366f7b9f9f36e10909b1e95edbf2a261c2acVenugopal Iyer bcopy(&vd->vdev_stat, vs, sizeof (*vs));
0dc2366f7b9f9f36e10909b1e95edbf2a261c2acVenugopal Iyer vs->vs_timestamp = gethrtime() - vs->vs_timestamp;
0dc2366f7b9f9f36e10909b1e95edbf2a261c2acVenugopal Iyer vs->vs_state = vd->vdev_state;
0dc2366f7b9f9f36e10909b1e95edbf2a261c2acVenugopal Iyer vs->vs_rsize = vdev_get_min_asize(vd);
0dc2366f7b9f9f36e10909b1e95edbf2a261c2acVenugopal Iyer if (vd->vdev_ops->vdev_op_leaf)
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
0dc2366f7b9f9f36e10909b1e95edbf2a261c2acVenugopal Iyer /*
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 */
0dc2366f7b9f9f36e10909b1e95edbf2a261c2acVenugopal Iyer if (vd == rvd) {
0dc2366f7b9f9f36e10909b1e95edbf2a261c2acVenugopal Iyer for (int c = 0; c < rvd->vdev_children; c++) {
0dc2366f7b9f9f36e10909b1e95edbf2a261c2acVenugopal Iyer vdev_t *cvd = rvd->vdev_child[c];
0dc2366f7b9f9f36e10909b1e95edbf2a261c2acVenugopal Iyer vdev_stat_t *cvs = &cvd->vdev_stat;
0dc2366f7b9f9f36e10909b1e95edbf2a261c2acVenugopal Iyer
0dc2366f7b9f9f36e10909b1e95edbf2a261c2acVenugopal Iyer for (int t = 0; t < ZIO_TYPES; t++) {
0dc2366f7b9f9f36e10909b1e95edbf2a261c2acVenugopal Iyer vs->vs_ops[t] += cvs->vs_ops[t];
0dc2366f7b9f9f36e10909b1e95edbf2a261c2acVenugopal Iyer vs->vs_bytes[t] += cvs->vs_bytes[t];
0dc2366f7b9f9f36e10909b1e95edbf2a261c2acVenugopal Iyer }
0dc2366f7b9f9f36e10909b1e95edbf2a261c2acVenugopal Iyer cvs->vs_scan_removing = cvd->vdev_removing;
0dc2366f7b9f9f36e10909b1e95edbf2a261c2acVenugopal Iyer }
0dc2366f7b9f9f36e10909b1e95edbf2a261c2acVenugopal Iyer }
0dc2366f7b9f9f36e10909b1e95edbf2a261c2acVenugopal Iyer mutex_exit(&vd->vdev_stat_lock);
0dc2366f7b9f9f36e10909b1e95edbf2a261c2acVenugopal Iyer}
0dc2366f7b9f9f36e10909b1e95edbf2a261c2acVenugopal Iyer
0dc2366f7b9f9f36e10909b1e95edbf2a261c2acVenugopal Iyervoid
0dc2366f7b9f9f36e10909b1e95edbf2a261c2acVenugopal Iyervdev_clear_stats(vdev_t *vd)
0dc2366f7b9f9f36e10909b1e95edbf2a261c2acVenugopal Iyer{
0dc2366f7b9f9f36e10909b1e95edbf2a261c2acVenugopal Iyer mutex_enter(&vd->vdev_stat_lock);
0dc2366f7b9f9f36e10909b1e95edbf2a261c2acVenugopal Iyer vd->vdev_stat.vs_space = 0;
0dc2366f7b9f9f36e10909b1e95edbf2a261c2acVenugopal Iyer vd->vdev_stat.vs_dspace = 0;
0dc2366f7b9f9f36e10909b1e95edbf2a261c2acVenugopal Iyer vd->vdev_stat.vs_alloc = 0;
0dc2366f7b9f9f36e10909b1e95edbf2a261c2acVenugopal Iyer mutex_exit(&vd->vdev_stat_lock);
0dc2366f7b9f9f36e10909b1e95edbf2a261c2acVenugopal Iyer}
0dc2366f7b9f9f36e10909b1e95edbf2a261c2acVenugopal Iyer
0dc2366f7b9f9f36e10909b1e95edbf2a261c2acVenugopal Iyervoid
0dc2366f7b9f9f36e10909b1e95edbf2a261c2acVenugopal Iyervdev_scan_stat_init(vdev_t *vd)
0dc2366f7b9f9f36e10909b1e95edbf2a261c2acVenugopal Iyer{
0dc2366f7b9f9f36e10909b1e95edbf2a261c2acVenugopal Iyer vdev_stat_t *vs = &vd->vdev_stat;
0dc2366f7b9f9f36e10909b1e95edbf2a261c2acVenugopal Iyer
0dc2366f7b9f9f36e10909b1e95edbf2a261c2acVenugopal Iyer for (int c = 0; c < vd->vdev_children; c++)
0dc2366f7b9f9f36e10909b1e95edbf2a261c2acVenugopal Iyer vdev_scan_stat_init(vd->vdev_child[c]);
0dc2366f7b9f9f36e10909b1e95edbf2a261c2acVenugopal Iyer
0dc2366f7b9f9f36e10909b1e95edbf2a261c2acVenugopal Iyer mutex_enter(&vd->vdev_stat_lock);
0dc2366f7b9f9f36e10909b1e95edbf2a261c2acVenugopal Iyer vs->vs_scan_processed = 0;
0dc2366f7b9f9f36e10909b1e95edbf2a261c2acVenugopal Iyer mutex_exit(&vd->vdev_stat_lock);
0dc2366f7b9f9f36e10909b1e95edbf2a261c2acVenugopal Iyer}
0dc2366f7b9f9f36e10909b1e95edbf2a261c2acVenugopal Iyer
0dc2366f7b9f9f36e10909b1e95edbf2a261c2acVenugopal Iyervoid
0dc2366f7b9f9f36e10909b1e95edbf2a261c2acVenugopal Iyervdev_stat_update(zio_t *zio, uint64_t psize)
0dc2366f7b9f9f36e10909b1e95edbf2a261c2acVenugopal Iyer{
0dc2366f7b9f9f36e10909b1e95edbf2a261c2acVenugopal Iyer spa_t *spa = zio->io_spa;
0dc2366f7b9f9f36e10909b1e95edbf2a261c2acVenugopal Iyer vdev_t *rvd = spa->spa_root_vdev;
0dc2366f7b9f9f36e10909b1e95edbf2a261c2acVenugopal Iyer vdev_t *vd = zio->io_vd ? zio->io_vd : rvd;
0dc2366f7b9f9f36e10909b1e95edbf2a261c2acVenugopal Iyer vdev_t *pvd;
0dc2366f7b9f9f36e10909b1e95edbf2a261c2acVenugopal Iyer uint64_t txg = zio->io_txg;
0dc2366f7b9f9f36e10909b1e95edbf2a261c2acVenugopal Iyer vdev_stat_t *vs = &vd->vdev_stat;
0dc2366f7b9f9f36e10909b1e95edbf2a261c2acVenugopal Iyer zio_type_t type = zio->io_type;
0dc2366f7b9f9f36e10909b1e95edbf2a261c2acVenugopal Iyer int flags = zio->io_flags;
0dc2366f7b9f9f36e10909b1e95edbf2a261c2acVenugopal Iyer
0dc2366f7b9f9f36e10909b1e95edbf2a261c2acVenugopal Iyer /*
0dc2366f7b9f9f36e10909b1e95edbf2a261c2acVenugopal Iyer * If this i/o is a gang leader, it didn't do any actual work.
0dc2366f7b9f9f36e10909b1e95edbf2a261c2acVenugopal Iyer */
0dc2366f7b9f9f36e10909b1e95edbf2a261c2acVenugopal Iyer if (zio->io_gang_tree)
0dc2366f7b9f9f36e10909b1e95edbf2a261c2acVenugopal Iyer return;
0dc2366f7b9f9f36e10909b1e95edbf2a261c2acVenugopal Iyer
0dc2366f7b9f9f36e10909b1e95edbf2a261c2acVenugopal Iyer if (zio->io_error == 0) {
0dc2366f7b9f9f36e10909b1e95edbf2a261c2acVenugopal Iyer /*
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 *
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 */
0dc2366f7b9f9f36e10909b1e95edbf2a261c2acVenugopal Iyer if (vd == rvd)
0dc2366f7b9f9f36e10909b1e95edbf2a261c2acVenugopal Iyer return;
0dc2366f7b9f9f36e10909b1e95edbf2a261c2acVenugopal Iyer
0dc2366f7b9f9f36e10909b1e95edbf2a261c2acVenugopal Iyer ASSERT(vd == zio->io_vd);
0dc2366f7b9f9f36e10909b1e95edbf2a261c2acVenugopal Iyer
0dc2366f7b9f9f36e10909b1e95edbf2a261c2acVenugopal Iyer if (flags & ZIO_FLAG_IO_BYPASS)
0dc2366f7b9f9f36e10909b1e95edbf2a261c2acVenugopal Iyer return;
0dc2366f7b9f9f36e10909b1e95edbf2a261c2acVenugopal Iyer
0dc2366f7b9f9f36e10909b1e95edbf2a261c2acVenugopal Iyer mutex_enter(&vd->vdev_stat_lock);
0dc2366f7b9f9f36e10909b1e95edbf2a261c2acVenugopal Iyer
0dc2366f7b9f9f36e10909b1e95edbf2a261c2acVenugopal Iyer if (flags & ZIO_FLAG_IO_REPAIR) {
0dc2366f7b9f9f36e10909b1e95edbf2a261c2acVenugopal Iyer if (flags & ZIO_FLAG_SCAN_THREAD) {
0dc2366f7b9f9f36e10909b1e95edbf2a261c2acVenugopal Iyer dsl_scan_phys_t *scn_phys =
0dc2366f7b9f9f36e10909b1e95edbf2a261c2acVenugopal Iyer &spa->spa_dsl_pool->dp_scan->scn_phys;
0dc2366f7b9f9f36e10909b1e95edbf2a261c2acVenugopal Iyer uint64_t *processed = &scn_phys->scn_processed;
0dc2366f7b9f9f36e10909b1e95edbf2a261c2acVenugopal Iyer
0dc2366f7b9f9f36e10909b1e95edbf2a261c2acVenugopal Iyer /* XXX cleanup? */
0dc2366f7b9f9f36e10909b1e95edbf2a261c2acVenugopal Iyer if (vd->vdev_ops->vdev_op_leaf)
0dc2366f7b9f9f36e10909b1e95edbf2a261c2acVenugopal Iyer atomic_add_64(processed, psize);
0dc2366f7b9f9f36e10909b1e95edbf2a261c2acVenugopal Iyer vs->vs_scan_processed += psize;
0dc2366f7b9f9f36e10909b1e95edbf2a261c2acVenugopal Iyer }
0dc2366f7b9f9f36e10909b1e95edbf2a261c2acVenugopal Iyer
0dc2366f7b9f9f36e10909b1e95edbf2a261c2acVenugopal Iyer if (flags & ZIO_FLAG_SELF_HEAL)
0dc2366f7b9f9f36e10909b1e95edbf2a261c2acVenugopal Iyer vs->vs_self_healed += psize;
0dc2366f7b9f9f36e10909b1e95edbf2a261c2acVenugopal Iyer }
0dc2366f7b9f9f36e10909b1e95edbf2a261c2acVenugopal Iyer
0dc2366f7b9f9f36e10909b1e95edbf2a261c2acVenugopal Iyer vs->vs_ops[type]++;
0dc2366f7b9f9f36e10909b1e95edbf2a261c2acVenugopal Iyer vs->vs_bytes[type] += psize;
0dc2366f7b9f9f36e10909b1e95edbf2a261c2acVenugopal Iyer
0dc2366f7b9f9f36e10909b1e95edbf2a261c2acVenugopal Iyer mutex_exit(&vd->vdev_stat_lock);
0dc2366f7b9f9f36e10909b1e95edbf2a261c2acVenugopal Iyer return;
0dc2366f7b9f9f36e10909b1e95edbf2a261c2acVenugopal Iyer }
0dc2366f7b9f9f36e10909b1e95edbf2a261c2acVenugopal Iyer
0dc2366f7b9f9f36e10909b1e95edbf2a261c2acVenugopal Iyer if (flags & ZIO_FLAG_SPECULATIVE)
0dc2366f7b9f9f36e10909b1e95edbf2a261c2acVenugopal Iyer return;
0dc2366f7b9f9f36e10909b1e95edbf2a261c2acVenugopal Iyer
69b5a878d62fdee1b12e78371ce6cc8abddcad15Dan McDonald /*
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 */
0dc2366f7b9f9f36e10909b1e95edbf2a261c2acVenugopal Iyer if (zio->io_error == EIO &&
0dc2366f7b9f9f36e10909b1e95edbf2a261c2acVenugopal Iyer !(zio->io_flags & ZIO_FLAG_IO_RETRY))
0dc2366f7b9f9f36e10909b1e95edbf2a261c2acVenugopal Iyer return;
0dc2366f7b9f9f36e10909b1e95edbf2a261c2acVenugopal Iyer
0dc2366f7b9f9f36e10909b1e95edbf2a261c2acVenugopal Iyer /*
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 * errors.
0dc2366f7b9f9f36e10909b1e95edbf2a261c2acVenugopal Iyer */
0dc2366f7b9f9f36e10909b1e95edbf2a261c2acVenugopal Iyer if (zio->io_vd == NULL && (zio->io_flags & ZIO_FLAG_DONT_PROPAGATE))
9da57d7b0ddd8d73b676ce12c040362132cdd538bt return;
9da57d7b0ddd8d73b676ce12c040362132cdd538bt
9da57d7b0ddd8d73b676ce12c040362132cdd538bt mutex_enter(&vd->vdev_stat_lock);
9da57d7b0ddd8d73b676ce12c040362132cdd538bt if (type == ZIO_TYPE_READ && !vdev_is_dead(vd)) {
9da57d7b0ddd8d73b676ce12c040362132cdd538bt if (zio->io_error == ECKSUM)
9da57d7b0ddd8d73b676ce12c040362132cdd538bt vs->vs_checksum_errors++;
9da57d7b0ddd8d73b676ce12c040362132cdd538bt else
da14cebe459d3275048785f25bd869cb09b5307fEric Cheng vs->vs_read_errors++;
9da57d7b0ddd8d73b676ce12c040362132cdd538bt }
9da57d7b0ddd8d73b676ce12c040362132cdd538bt if (type == ZIO_TYPE_WRITE && !vdev_is_dead(vd))
9da57d7b0ddd8d73b676ce12c040362132cdd538bt vs->vs_write_errors++;
9da57d7b0ddd8d73b676ce12c040362132cdd538bt mutex_exit(&vd->vdev_stat_lock);
da14cebe459d3275048785f25bd869cb09b5307fEric Cheng
da14cebe459d3275048785f25bd869cb09b5307fEric Cheng if (type == ZIO_TYPE_WRITE && txg != 0 &&
9da57d7b0ddd8d73b676ce12c040362132cdd538bt (!(flags & ZIO_FLAG_IO_REPAIR) ||
9da57d7b0ddd8d73b676ce12c040362132cdd538bt (flags & ZIO_FLAG_SCAN_THREAD) ||
9da57d7b0ddd8d73b676ce12c040362132cdd538bt spa->spa_claiming)) {
9da57d7b0ddd8d73b676ce12c040362132cdd538bt /*
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 *
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.
9da57d7b0ddd8d73b676ce12c040362132cdd538bt */
9da57d7b0ddd8d73b676ce12c040362132cdd538bt if (vd->vdev_ops->vdev_op_leaf) {
9da57d7b0ddd8d73b676ce12c040362132cdd538bt uint64_t commit_txg = txg;
da14cebe459d3275048785f25bd869cb09b5307fEric Cheng if (flags & ZIO_FLAG_SCAN_THREAD) {
da14cebe459d3275048785f25bd869cb09b5307fEric Cheng ASSERT(flags & ZIO_FLAG_IO_REPAIR);
da14cebe459d3275048785f25bd869cb09b5307fEric Cheng ASSERT(spa_sync_pass(spa) == 1);
da14cebe459d3275048785f25bd869cb09b5307fEric Cheng vdev_dtl_dirty(vd, DTL_SCRUB, txg, 1);
0dc2366f7b9f9f36e10909b1e95edbf2a261c2acVenugopal Iyer commit_txg = spa_syncing_txg(spa);
0dc2366f7b9f9f36e10909b1e95edbf2a261c2acVenugopal Iyer } else if (spa->spa_claiming) {
da14cebe459d3275048785f25bd869cb09b5307fEric Cheng ASSERT(flags & ZIO_FLAG_IO_REPAIR);
da14cebe459d3275048785f25bd869cb09b5307fEric Cheng commit_txg = spa_first_txg(spa);
da14cebe459d3275048785f25bd869cb09b5307fEric Cheng }
da14cebe459d3275048785f25bd869cb09b5307fEric Cheng ASSERT(commit_txg >= spa_syncing_txg(spa));
da14cebe459d3275048785f25bd869cb09b5307fEric Cheng if (vdev_dtl_contains(vd, DTL_MISSING, txg, 1))
da14cebe459d3275048785f25bd869cb09b5307fEric Cheng return;
9da57d7b0ddd8d73b676ce12c040362132cdd538bt for (pvd = vd; pvd != rvd; pvd = pvd->vdev_parent)
9da57d7b0ddd8d73b676ce12c040362132cdd538bt vdev_dtl_dirty(pvd, DTL_PARTIAL, txg, 1);
da14cebe459d3275048785f25bd869cb09b5307fEric Cheng vdev_dirty(vd->vdev_top, VDD_DTL, vd, commit_txg);
da14cebe459d3275048785f25bd869cb09b5307fEric Cheng }
da14cebe459d3275048785f25bd869cb09b5307fEric Cheng if (vd != rvd)
da14cebe459d3275048785f25bd869cb09b5307fEric Cheng vdev_dtl_dirty(vd, DTL_MISSING, txg, 1);
da14cebe459d3275048785f25bd869cb09b5307fEric Cheng }
da14cebe459d3275048785f25bd869cb09b5307fEric Cheng}
da14cebe459d3275048785f25bd869cb09b5307fEric Cheng
da14cebe459d3275048785f25bd869cb09b5307fEric Cheng/*
da14cebe459d3275048785f25bd869cb09b5307fEric Cheng * Update the in-core space usage stats for this vdev, its metaslab class,
da14cebe459d3275048785f25bd869cb09b5307fEric Cheng * and the root vdev.
da14cebe459d3275048785f25bd869cb09b5307fEric Cheng */
da14cebe459d3275048785f25bd869cb09b5307fEric Chengvoid
da14cebe459d3275048785f25bd869cb09b5307fEric Chengvdev_space_update(vdev_t *vd, int64_t alloc_delta, int64_t defer_delta,
da14cebe459d3275048785f25bd869cb09b5307fEric Cheng int64_t space_delta)
da14cebe459d3275048785f25bd869cb09b5307fEric Cheng{
da14cebe459d3275048785f25bd869cb09b5307fEric Cheng int64_t dspace_delta = space_delta;
da14cebe459d3275048785f25bd869cb09b5307fEric Cheng spa_t *spa = vd->vdev_spa;
da14cebe459d3275048785f25bd869cb09b5307fEric Cheng vdev_t *rvd = spa->spa_root_vdev;
da14cebe459d3275048785f25bd869cb09b5307fEric Cheng metaslab_group_t *mg = vd->vdev_mg;
da14cebe459d3275048785f25bd869cb09b5307fEric Cheng metaslab_class_t *mc = mg ? mg->mg_class : NULL;
9da57d7b0ddd8d73b676ce12c040362132cdd538bt
9da57d7b0ddd8d73b676ce12c040362132cdd538bt ASSERT(vd == vd->vdev_top);
9da57d7b0ddd8d73b676ce12c040362132cdd538bt
9da57d7b0ddd8d73b676ce12c040362132cdd538bt /*
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 */
9da57d7b0ddd8d73b676ce12c040362132cdd538bt ASSERT((dspace_delta & (SPA_MINBLOCKSIZE-1)) == 0);
9da57d7b0ddd8d73b676ce12c040362132cdd538bt ASSERT(vd->vdev_deflate_ratio != 0 || vd->vdev_isl2cache);
9da57d7b0ddd8d73b676ce12c040362132cdd538bt dspace_delta = (dspace_delta >> SPA_MINBLOCKSHIFT) *
9da57d7b0ddd8d73b676ce12c040362132cdd538bt vd->vdev_deflate_ratio;
9da57d7b0ddd8d73b676ce12c040362132cdd538bt
9da57d7b0ddd8d73b676ce12c040362132cdd538bt mutex_enter(&vd->vdev_stat_lock);
9da57d7b0ddd8d73b676ce12c040362132cdd538bt vd->vdev_stat.vs_alloc += alloc_delta;
9da57d7b0ddd8d73b676ce12c040362132cdd538bt vd->vdev_stat.vs_space += space_delta;
9da57d7b0ddd8d73b676ce12c040362132cdd538bt vd->vdev_stat.vs_dspace += dspace_delta;
9da57d7b0ddd8d73b676ce12c040362132cdd538bt mutex_exit(&vd->vdev_stat_lock);
9da57d7b0ddd8d73b676ce12c040362132cdd538bt
9da57d7b0ddd8d73b676ce12c040362132cdd538bt if (mc == spa_normal_class(spa)) {
9da57d7b0ddd8d73b676ce12c040362132cdd538bt mutex_enter(&rvd->vdev_stat_lock);
9da57d7b0ddd8d73b676ce12c040362132cdd538bt rvd->vdev_stat.vs_alloc += alloc_delta;
9da57d7b0ddd8d73b676ce12c040362132cdd538bt rvd->vdev_stat.vs_space += space_delta;
9da57d7b0ddd8d73b676ce12c040362132cdd538bt rvd->vdev_stat.vs_dspace += dspace_delta;
9da57d7b0ddd8d73b676ce12c040362132cdd538bt mutex_exit(&rvd->vdev_stat_lock);
9da57d7b0ddd8d73b676ce12c040362132cdd538bt }
9da57d7b0ddd8d73b676ce12c040362132cdd538bt
9da57d7b0ddd8d73b676ce12c040362132cdd538bt if (mc != NULL) {
9da57d7b0ddd8d73b676ce12c040362132cdd538bt ASSERT(rvd == vd->vdev_parent);
9da57d7b0ddd8d73b676ce12c040362132cdd538bt ASSERT(vd->vdev_ms_count != 0);
9da57d7b0ddd8d73b676ce12c040362132cdd538bt
9da57d7b0ddd8d73b676ce12c040362132cdd538bt metaslab_class_space_update(mc,
9da57d7b0ddd8d73b676ce12c040362132cdd538bt alloc_delta, defer_delta, space_delta, dspace_delta);
9da57d7b0ddd8d73b676ce12c040362132cdd538bt }
9da57d7b0ddd8d73b676ce12c040362132cdd538bt}
9da57d7b0ddd8d73b676ce12c040362132cdd538bt
9da57d7b0ddd8d73b676ce12c040362132cdd538bt/*
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 */
9da57d7b0ddd8d73b676ce12c040362132cdd538btvoid
9da57d7b0ddd8d73b676ce12c040362132cdd538btvdev_config_dirty(vdev_t *vd)
9da57d7b0ddd8d73b676ce12c040362132cdd538bt{
9da57d7b0ddd8d73b676ce12c040362132cdd538bt spa_t *spa = vd->vdev_spa;
9da57d7b0ddd8d73b676ce12c040362132cdd538bt vdev_t *rvd = spa->spa_root_vdev;
9da57d7b0ddd8d73b676ce12c040362132cdd538bt int c;
9da57d7b0ddd8d73b676ce12c040362132cdd538bt
9da57d7b0ddd8d73b676ce12c040362132cdd538bt ASSERT(spa_writeable(spa));
9da57d7b0ddd8d73b676ce12c040362132cdd538bt
9da57d7b0ddd8d73b676ce12c040362132cdd538bt /*
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 */
9da57d7b0ddd8d73b676ce12c040362132cdd538bt if (vd->vdev_aux != NULL) {
9da57d7b0ddd8d73b676ce12c040362132cdd538bt spa_aux_vdev_t *sav = vd->vdev_aux;
9da57d7b0ddd8d73b676ce12c040362132cdd538bt nvlist_t **aux;
9da57d7b0ddd8d73b676ce12c040362132cdd538bt uint_t naux;
9da57d7b0ddd8d73b676ce12c040362132cdd538bt
9da57d7b0ddd8d73b676ce12c040362132cdd538bt for (c = 0; c < sav->sav_count; c++) {
9da57d7b0ddd8d73b676ce12c040362132cdd538bt if (sav->sav_vdevs[c] == vd)
9da57d7b0ddd8d73b676ce12c040362132cdd538bt break;
9da57d7b0ddd8d73b676ce12c040362132cdd538bt }
9da57d7b0ddd8d73b676ce12c040362132cdd538bt
9da57d7b0ddd8d73b676ce12c040362132cdd538bt if (c == sav->sav_count) {
9da57d7b0ddd8d73b676ce12c040362132cdd538bt /*
9da57d7b0ddd8d73b676ce12c040362132cdd538bt * We're being removed. There's nothing more to do.
9da57d7b0ddd8d73b676ce12c040362132cdd538bt */
9da57d7b0ddd8d73b676ce12c040362132cdd538bt ASSERT(sav->sav_sync == B_TRUE);
9da57d7b0ddd8d73b676ce12c040362132cdd538bt return;
9da57d7b0ddd8d73b676ce12c040362132cdd538bt }
9da57d7b0ddd8d73b676ce12c040362132cdd538bt
9da57d7b0ddd8d73b676ce12c040362132cdd538bt sav->sav_sync = B_TRUE;
9da57d7b0ddd8d73b676ce12c040362132cdd538bt
9da57d7b0ddd8d73b676ce12c040362132cdd538bt if (nvlist_lookup_nvlist_array(sav->sav_config,
9da57d7b0ddd8d73b676ce12c040362132cdd538bt ZPOOL_CONFIG_L2CACHE, &aux, &naux) != 0) {
9da57d7b0ddd8d73b676ce12c040362132cdd538bt VERIFY(nvlist_lookup_nvlist_array(sav->sav_config,
9da57d7b0ddd8d73b676ce12c040362132cdd538bt ZPOOL_CONFIG_SPARES, &aux, &naux) == 0);
9da57d7b0ddd8d73b676ce12c040362132cdd538bt }
9da57d7b0ddd8d73b676ce12c040362132cdd538bt
9da57d7b0ddd8d73b676ce12c040362132cdd538bt ASSERT(c < naux);
9da57d7b0ddd8d73b676ce12c040362132cdd538bt
9da57d7b0ddd8d73b676ce12c040362132cdd538bt /*
9da57d7b0ddd8d73b676ce12c040362132cdd538bt * Setting the nvlist in the middle if the array is a little
9da57d7b0ddd8d73b676ce12c040362132cdd538bt * sketchy, but it will work.
9da57d7b0ddd8d73b676ce12c040362132cdd538bt */
9da57d7b0ddd8d73b676ce12c040362132cdd538bt nvlist_free(aux[c]);
9da57d7b0ddd8d73b676ce12c040362132cdd538bt aux[c] = vdev_config_generate(spa, vd, B_TRUE, 0);
9da57d7b0ddd8d73b676ce12c040362132cdd538bt
9da57d7b0ddd8d73b676ce12c040362132cdd538bt return;
9da57d7b0ddd8d73b676ce12c040362132cdd538bt }
69b5a878d62fdee1b12e78371ce6cc8abddcad15Dan McDonald
9da57d7b0ddd8d73b676ce12c040362132cdd538bt /*
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 */
0dc2366f7b9f9f36e10909b1e95edbf2a261c2acVenugopal Iyer ASSERT(spa_config_held(spa, SCL_CONFIG, RW_WRITER) ||
0dc2366f7b9f9f36e10909b1e95edbf2a261c2acVenugopal Iyer (dsl_pool_sync_context(spa_get_dsl(spa)) &&
0dc2366f7b9f9f36e10909b1e95edbf2a261c2acVenugopal Iyer spa_config_held(spa, SCL_CONFIG, RW_READER)));
0dc2366f7b9f9f36e10909b1e95edbf2a261c2acVenugopal Iyer
0dc2366f7b9f9f36e10909b1e95edbf2a261c2acVenugopal Iyer if (vd == rvd) {
0dc2366f7b9f9f36e10909b1e95edbf2a261c2acVenugopal Iyer for (c = 0; c < rvd->vdev_children; c++)
0dc2366f7b9f9f36e10909b1e95edbf2a261c2acVenugopal Iyer vdev_config_dirty(rvd->vdev_child[c]);
0dc2366f7b9f9f36e10909b1e95edbf2a261c2acVenugopal Iyer } else {
0dc2366f7b9f9f36e10909b1e95edbf2a261c2acVenugopal Iyer ASSERT(vd == vd->vdev_top);
0dc2366f7b9f9f36e10909b1e95edbf2a261c2acVenugopal Iyer
0dc2366f7b9f9f36e10909b1e95edbf2a261c2acVenugopal Iyer if (!list_link_active(&vd->vdev_config_dirty_node) &&
0dc2366f7b9f9f36e10909b1e95edbf2a261c2acVenugopal Iyer !vd->vdev_ishole)
0dc2366f7b9f9f36e10909b1e95edbf2a261c2acVenugopal Iyer list_insert_head(&spa->spa_config_dirty_list, vd);
0dc2366f7b9f9f36e10909b1e95edbf2a261c2acVenugopal Iyer }
0dc2366f7b9f9f36e10909b1e95edbf2a261c2acVenugopal Iyer}
0dc2366f7b9f9f36e10909b1e95edbf2a261c2acVenugopal Iyer
0dc2366f7b9f9f36e10909b1e95edbf2a261c2acVenugopal Iyervoid
0dc2366f7b9f9f36e10909b1e95edbf2a261c2acVenugopal Iyervdev_config_clean(vdev_t *vd)
0dc2366f7b9f9f36e10909b1e95edbf2a261c2acVenugopal Iyer{
0dc2366f7b9f9f36e10909b1e95edbf2a261c2acVenugopal Iyer spa_t *spa = vd->vdev_spa;
0dc2366f7b9f9f36e10909b1e95edbf2a261c2acVenugopal Iyer
0dc2366f7b9f9f36e10909b1e95edbf2a261c2acVenugopal Iyer ASSERT(spa_config_held(spa, SCL_CONFIG, RW_WRITER) ||
0dc2366f7b9f9f36e10909b1e95edbf2a261c2acVenugopal Iyer (dsl_pool_sync_context(spa_get_dsl(spa)) &&
0dc2366f7b9f9f36e10909b1e95edbf2a261c2acVenugopal Iyer spa_config_held(spa, SCL_CONFIG, RW_READER)));
0dc2366f7b9f9f36e10909b1e95edbf2a261c2acVenugopal Iyer
0dc2366f7b9f9f36e10909b1e95edbf2a261c2acVenugopal Iyer ASSERT(list_link_active(&vd->vdev_config_dirty_node));
0dc2366f7b9f9f36e10909b1e95edbf2a261c2acVenugopal Iyer list_remove(&spa->spa_config_dirty_list, vd);
0dc2366f7b9f9f36e10909b1e95edbf2a261c2acVenugopal Iyer}
0dc2366f7b9f9f36e10909b1e95edbf2a261c2acVenugopal Iyer
69b5a878d62fdee1b12e78371ce6cc8abddcad15Dan McDonald/*
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 */
0dc2366f7b9f9f36e10909b1e95edbf2a261c2acVenugopal Iyervoid
0dc2366f7b9f9f36e10909b1e95edbf2a261c2acVenugopal Iyervdev_state_dirty(vdev_t *vd)
0dc2366f7b9f9f36e10909b1e95edbf2a261c2acVenugopal Iyer{
69b5a878d62fdee1b12e78371ce6cc8abddcad15Dan McDonald spa_t *spa = vd->vdev_spa;
69b5a878d62fdee1b12e78371ce6cc8abddcad15Dan McDonald
0dc2366f7b9f9f36e10909b1e95edbf2a261c2acVenugopal Iyer ASSERT(spa_writeable(spa));
0dc2366f7b9f9f36e10909b1e95edbf2a261c2acVenugopal Iyer ASSERT(vd == vd->vdev_top);
0dc2366f7b9f9f36e10909b1e95edbf2a261c2acVenugopal Iyer
0dc2366f7b9f9f36e10909b1e95edbf2a261c2acVenugopal Iyer /*
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 */
0dc2366f7b9f9f36e10909b1e95edbf2a261c2acVenugopal Iyer ASSERT(spa_config_held(spa, SCL_STATE, RW_WRITER) ||
0dc2366f7b9f9f36e10909b1e95edbf2a261c2acVenugopal Iyer (dsl_pool_sync_context(spa_get_dsl(spa)) &&
0dc2366f7b9f9f36e10909b1e95edbf2a261c2acVenugopal Iyer spa_config_held(spa, SCL_STATE, RW_READER)));
0dc2366f7b9f9f36e10909b1e95edbf2a261c2acVenugopal Iyer
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}
0dc2366f7b9f9f36e10909b1e95edbf2a261c2acVenugopal Iyer
0dc2366f7b9f9f36e10909b1e95edbf2a261c2acVenugopal Iyervoid
0dc2366f7b9f9f36e10909b1e95edbf2a261c2acVenugopal Iyervdev_state_clean(vdev_t *vd)
0dc2366f7b9f9f36e10909b1e95edbf2a261c2acVenugopal Iyer{
0dc2366f7b9f9f36e10909b1e95edbf2a261c2acVenugopal Iyer spa_t *spa = vd->vdev_spa;
0dc2366f7b9f9f36e10909b1e95edbf2a261c2acVenugopal Iyer
0dc2366f7b9f9f36e10909b1e95edbf2a261c2acVenugopal Iyer ASSERT(spa_config_held(spa, SCL_STATE, RW_WRITER) ||
0dc2366f7b9f9f36e10909b1e95edbf2a261c2acVenugopal Iyer (dsl_pool_sync_context(spa_get_dsl(spa)) &&
0dc2366f7b9f9f36e10909b1e95edbf2a261c2acVenugopal Iyer spa_config_held(spa, SCL_STATE, RW_READER)));
0dc2366f7b9f9f36e10909b1e95edbf2a261c2acVenugopal Iyer
0dc2366f7b9f9f36e10909b1e95edbf2a261c2acVenugopal Iyer ASSERT(list_link_active(&vd->vdev_state_dirty_node));
0dc2366f7b9f9f36e10909b1e95edbf2a261c2acVenugopal Iyer list_remove(&spa->spa_state_dirty_list, vd);
0dc2366f7b9f9f36e10909b1e95edbf2a261c2acVenugopal Iyer}
19843f01b1bef3453f717c23c8f89fb9313f6749Paul Guo
0dc2366f7b9f9f36e10909b1e95edbf2a261c2acVenugopal Iyer/*
0dc2366f7b9f9f36e10909b1e95edbf2a261c2acVenugopal Iyer * Propagate vdev state up from children to parent.
0dc2366f7b9f9f36e10909b1e95edbf2a261c2acVenugopal Iyer */
9da57d7b0ddd8d73b676ce12c040362132cdd538btvoid
9da57d7b0ddd8d73b676ce12c040362132cdd538btvdev_propagate_state(vdev_t *vd)
9da57d7b0ddd8d73b676ce12c040362132cdd538bt{
9da57d7b0ddd8d73b676ce12c040362132cdd538bt spa_t *spa = vd->vdev_spa;
9da57d7b0ddd8d73b676ce12c040362132cdd538bt vdev_t *rvd = spa->spa_root_vdev;
9da57d7b0ddd8d73b676ce12c040362132cdd538bt int degraded = 0, faulted = 0;
9da57d7b0ddd8d73b676ce12c040362132cdd538bt int corrupted = 0;
9da57d7b0ddd8d73b676ce12c040362132cdd538bt vdev_t *child;
9da57d7b0ddd8d73b676ce12c040362132cdd538bt
9da57d7b0ddd8d73b676ce12c040362132cdd538bt if (vd->vdev_children > 0) {
9da57d7b0ddd8d73b676ce12c040362132cdd538bt for (int c = 0; c < vd->vdev_children; c++) {
9da57d7b0ddd8d73b676ce12c040362132cdd538bt child = vd->vdev_child[c];
9da57d7b0ddd8d73b676ce12c040362132cdd538bt
9da57d7b0ddd8d73b676ce12c040362132cdd538bt /*
9da57d7b0ddd8d73b676ce12c040362132cdd538bt * Don't factor holes into the decision.
9da57d7b0ddd8d73b676ce12c040362132cdd538bt */
9da57d7b0ddd8d73b676ce12c040362132cdd538bt if (child->vdev_ishole)
9da57d7b0ddd8d73b676ce12c040362132cdd538bt continue;
9da57d7b0ddd8d73b676ce12c040362132cdd538bt
9da57d7b0ddd8d73b676ce12c040362132cdd538bt if (!vdev_readable(child) ||
9da57d7b0ddd8d73b676ce12c040362132cdd538bt (!vdev_writeable(child) && spa_writeable(spa))) {
9da57d7b0ddd8d73b676ce12c040362132cdd538bt /*
9da57d7b0ddd8d73b676ce12c040362132cdd538bt * Root special: if there is a top-level log
9da57d7b0ddd8d73b676ce12c040362132cdd538bt * device, treat the root vdev as if it were
9da57d7b0ddd8d73b676ce12c040362132cdd538bt * degraded.
9da57d7b0ddd8d73b676ce12c040362132cdd538bt */
9da57d7b0ddd8d73b676ce12c040362132cdd538bt if (child->vdev_islog && vd == rvd)
9da57d7b0ddd8d73b676ce12c040362132cdd538bt degraded++;
9da57d7b0ddd8d73b676ce12c040362132cdd538bt else
9da57d7b0ddd8d73b676ce12c040362132cdd538bt faulted++;
9da57d7b0ddd8d73b676ce12c040362132cdd538bt } else if (child->vdev_state <= VDEV_STATE_DEGRADED) {
9da57d7b0ddd8d73b676ce12c040362132cdd538bt degraded++;
9da57d7b0ddd8d73b676ce12c040362132cdd538bt }
9da57d7b0ddd8d73b676ce12c040362132cdd538bt
9da57d7b0ddd8d73b676ce12c040362132cdd538bt if (child->vdev_stat.vs_aux == VDEV_AUX_CORRUPT_DATA)
9da57d7b0ddd8d73b676ce12c040362132cdd538bt corrupted++;
9da57d7b0ddd8d73b676ce12c040362132cdd538bt }
9da57d7b0ddd8d73b676ce12c040362132cdd538bt
9da57d7b0ddd8d73b676ce12c040362132cdd538bt vd->vdev_ops->vdev_op_state_change(vd, faulted, degraded);
9da57d7b0ddd8d73b676ce12c040362132cdd538bt
9da57d7b0ddd8d73b676ce12c040362132cdd538bt /*
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'.
9da57d7b0ddd8d73b676ce12c040362132cdd538bt */
9da57d7b0ddd8d73b676ce12c040362132cdd538bt if (corrupted && vd == rvd &&
9da57d7b0ddd8d73b676ce12c040362132cdd538bt rvd->vdev_state == VDEV_STATE_CANT_OPEN)
9da57d7b0ddd8d73b676ce12c040362132cdd538bt vdev_set_state(rvd, B_FALSE, VDEV_STATE_CANT_OPEN,
9da57d7b0ddd8d73b676ce12c040362132cdd538bt VDEV_AUX_CORRUPT_DATA);
9da57d7b0ddd8d73b676ce12c040362132cdd538bt }
9da57d7b0ddd8d73b676ce12c040362132cdd538bt
da14cebe459d3275048785f25bd869cb09b5307fEric Cheng if (vd->vdev_parent)
9da57d7b0ddd8d73b676ce12c040362132cdd538bt vdev_propagate_state(vd->vdev_parent);
9da57d7b0ddd8d73b676ce12c040362132cdd538bt}
9da57d7b0ddd8d73b676ce12c040362132cdd538bt
73cd555c10e70dac413ae4b40de8450a291750acBin Tu - Sun Microsystems - Beijing China/*
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.
73cd555c10e70dac413ae4b40de8450a291750acBin Tu - Sun Microsystems - Beijing China *
9da57d7b0ddd8d73b676ce12c040362132cdd538bt * If this routine places a device in a faulted state, an appropriate ereport is
9da57d7b0ddd8d73b676ce12c040362132cdd538bt * generated.
9da57d7b0ddd8d73b676ce12c040362132cdd538bt */
9da57d7b0ddd8d73b676ce12c040362132cdd538btvoid
9da57d7b0ddd8d73b676ce12c040362132cdd538btvdev_set_state(vdev_t *vd, boolean_t isopen, vdev_state_t state, vdev_aux_t aux)
13740cb230f19fcbf1a6468d1a6a0ba9a0a09c22Paul Guo{
13740cb230f19fcbf1a6468d1a6a0ba9a0a09c22Paul Guo uint64_t save_state;
13740cb230f19fcbf1a6468d1a6a0ba9a0a09c22Paul Guo spa_t *spa = vd->vdev_spa;
9da57d7b0ddd8d73b676ce12c040362132cdd538bt
9da57d7b0ddd8d73b676ce12c040362132cdd538bt if (state == vd->vdev_state) {
9da57d7b0ddd8d73b676ce12c040362132cdd538bt vd->vdev_stat.vs_aux = aux;
9da57d7b0ddd8d73b676ce12c040362132cdd538bt return;
13740cb230f19fcbf1a6468d1a6a0ba9a0a09c22Paul Guo }
13740cb230f19fcbf1a6468d1a6a0ba9a0a09c22Paul Guo
13740cb230f19fcbf1a6468d1a6a0ba9a0a09c22Paul Guo save_state = vd->vdev_state;
9da57d7b0ddd8d73b676ce12c040362132cdd538bt
9da57d7b0ddd8d73b676ce12c040362132cdd538bt vd->vdev_state = state;
9da57d7b0ddd8d73b676ce12c040362132cdd538bt vd->vdev_stat.vs_aux = aux;
da14cebe459d3275048785f25bd869cb09b5307fEric Cheng
da14cebe459d3275048785f25bd869cb09b5307fEric Cheng /*
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 * children.
da14cebe459d3275048785f25bd869cb09b5307fEric Cheng */
da14cebe459d3275048785f25bd869cb09b5307fEric Cheng if (!vd->vdev_delayed_close && vdev_is_dead(vd) &&
da14cebe459d3275048785f25bd869cb09b5307fEric Cheng vd->vdev_ops->vdev_op_leaf)
da14cebe459d3275048785f25bd869cb09b5307fEric Cheng vd->vdev_ops->vdev_op_close(vd);
0dc2366f7b9f9f36e10909b1e95edbf2a261c2acVenugopal Iyer
0dc2366f7b9f9f36e10909b1e95edbf2a261c2acVenugopal Iyer /*
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.
0dc2366f7b9f9f36e10909b1e95edbf2a261c2acVenugopal Iyer */
da14cebe459d3275048785f25bd869cb09b5307fEric Cheng if (state == VDEV_STATE_HEALTHY && vd->vdev_ops->vdev_op_leaf &&
da14cebe459d3275048785f25bd869cb09b5307fEric Cheng vd->vdev_prevstate != state)
9da57d7b0ddd8d73b676ce12c040362132cdd538bt zfs_post_state_change(spa, vd);
9da57d7b0ddd8d73b676ce12c040362132cdd538bt
9da57d7b0ddd8d73b676ce12c040362132cdd538bt if (vd->vdev_removed &&
9da57d7b0ddd8d73b676ce12c040362132cdd538bt state == VDEV_STATE_CANT_OPEN &&
da14cebe459d3275048785f25bd869cb09b5307fEric Cheng (aux == VDEV_AUX_OPEN_FAILED || vd->vdev_checkremove)) {
9da57d7b0ddd8d73b676ce12c040362132cdd538bt /*
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
c971fb7ec0a19c6cd00c5614a94c97f953b6e8b1gg * fault.
9da57d7b0ddd8d73b676ce12c040362132cdd538bt */
c971fb7ec0a19c6cd00c5614a94c97f953b6e8b1gg vd->vdev_state = VDEV_STATE_REMOVED;
9da57d7b0ddd8d73b676ce12c040362132cdd538bt vd->vdev_stat.vs_aux = VDEV_AUX_NONE;
c971fb7ec0a19c6cd00c5614a94c97f953b6e8b1gg } else if (state == VDEV_STATE_REMOVED) {
ffd8e8832e01f996f32459073f4dd308fe5265baWinson Wang - Sun Microsystems - Beijing China vd->vdev_removed = B_TRUE;
ffd8e8832e01f996f32459073f4dd308fe5265baWinson Wang - Sun Microsystems - Beijing China } else if (state == VDEV_STATE_CANT_OPEN) {
9da57d7b0ddd8d73b676ce12c040362132cdd538bt /*
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.
69b5a878d62fdee1b12e78371ce6cc8abddcad15Dan McDonald */
69b5a878d62fdee1b12e78371ce6cc8abddcad15Dan McDonald if ((spa_load_state(spa) == SPA_LOAD_IMPORT ||
69b5a878d62fdee1b12e78371ce6cc8abddcad15Dan McDonald spa_load_state(spa) == SPA_LOAD_RECOVER) &&
73cd555c10e70dac413ae4b40de8450a291750acBin Tu - Sun Microsystems - Beijing China vd->vdev_ops->vdev_op_leaf)
73cd555c10e70dac413ae4b40de8450a291750acBin Tu - Sun Microsystems - Beijing China vd->vdev_not_present = 1;
73cd555c10e70dac413ae4b40de8450a291750acBin Tu - Sun Microsystems - Beijing China
c971fb7ec0a19c6cd00c5614a94c97f953b6e8b1gg /*
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 *
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 */
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;
69b5a878d62fdee1b12e78371ce6cc8abddcad15Dan McDonald
ffd8e8832e01f996f32459073f4dd308fe5265baWinson Wang - Sun Microsystems - Beijing China switch (aux) {
69b5a878d62fdee1b12e78371ce6cc8abddcad15Dan McDonald case VDEV_AUX_OPEN_FAILED:
ffd8e8832e01f996f32459073f4dd308fe5265baWinson Wang - Sun Microsystems - Beijing China class = FM_EREPORT_ZFS_DEVICE_OPEN_FAILED;
ffd8e8832e01f996f32459073f4dd308fe5265baWinson Wang - Sun Microsystems - Beijing China break;
9da57d7b0ddd8d73b676ce12c040362132cdd538bt case VDEV_AUX_CORRUPT_DATA:
9da57d7b0ddd8d73b676ce12c040362132cdd538bt class = FM_EREPORT_ZFS_DEVICE_CORRUPT_DATA;
9da57d7b0ddd8d73b676ce12c040362132cdd538bt break;
9da57d7b0ddd8d73b676ce12c040362132cdd538bt case VDEV_AUX_NO_REPLICAS:
9da57d7b0ddd8d73b676ce12c040362132cdd538bt class = FM_EREPORT_ZFS_DEVICE_NO_REPLICAS;
9da57d7b0ddd8d73b676ce12c040362132cdd538bt break;
9da57d7b0ddd8d73b676ce12c040362132cdd538bt case VDEV_AUX_BAD_GUID_SUM:
9da57d7b0ddd8d73b676ce12c040362132cdd538bt class = FM_EREPORT_ZFS_DEVICE_BAD_GUID_SUM;
9da57d7b0ddd8d73b676ce12c040362132cdd538bt break;
9da57d7b0ddd8d73b676ce12c040362132cdd538bt case VDEV_AUX_TOO_SMALL:
9da57d7b0ddd8d73b676ce12c040362132cdd538bt class = FM_EREPORT_ZFS_DEVICE_TOO_SMALL;
9da57d7b0ddd8d73b676ce12c040362132cdd538bt break;
9da57d7b0ddd8d73b676ce12c040362132cdd538bt case VDEV_AUX_BAD_LABEL:
9da57d7b0ddd8d73b676ce12c040362132cdd538bt class = FM_EREPORT_ZFS_DEVICE_BAD_LABEL;
9da57d7b0ddd8d73b676ce12c040362132cdd538bt break;
9da57d7b0ddd8d73b676ce12c040362132cdd538bt default:
9da57d7b0ddd8d73b676ce12c040362132cdd538bt class = FM_EREPORT_ZFS_DEVICE_UNKNOWN;
9da57d7b0ddd8d73b676ce12c040362132cdd538bt }
9da57d7b0ddd8d73b676ce12c040362132cdd538bt
9da57d7b0ddd8d73b676ce12c040362132cdd538bt zfs_ereport_post(class, spa, vd, NULL, save_state, 0);
ea65739ebec0cbd625d8c89e19592be58fa186a6chenlu chen - Sun Microsystems - Beijing China }
ea65739ebec0cbd625d8c89e19592be58fa186a6chenlu chen - Sun Microsystems - Beijing China
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 } else {
69b5a878d62fdee1b12e78371ce6cc8abddcad15Dan McDonald vd->vdev_removed = B_FALSE;
ea65739ebec0cbd625d8c89e19592be58fa186a6chenlu chen - Sun Microsystems - Beijing China }
ea65739ebec0cbd625d8c89e19592be58fa186a6chenlu chen - Sun Microsystems - Beijing China
73cd555c10e70dac413ae4b40de8450a291750acBin Tu - Sun Microsystems - Beijing China if (!isopen && vd->vdev_parent)
69b5a878d62fdee1b12e78371ce6cc8abddcad15Dan McDonald vdev_propagate_state(vd->vdev_parent);
ea65739ebec0cbd625d8c89e19592be58fa186a6chenlu chen - Sun Microsystems - Beijing China}
43fab1a9f38ff02e665a874ea0a8eb3818e61ff3Saso Kiselkov
43fab1a9f38ff02e665a874ea0a8eb3818e61ff3Saso Kiselkov/*
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 China */
ea65739ebec0cbd625d8c89e19592be58fa186a6chenlu chen - Sun Microsystems - Beijing Chinaboolean_t
ea65739ebec0cbd625d8c89e19592be58fa186a6chenlu chen - Sun Microsystems - Beijing Chinavdev_is_bootable(vdev_t *vd)
ea65739ebec0cbd625d8c89e19592be58fa186a6chenlu chen - Sun Microsystems - Beijing China{
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
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 }
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 }
ea65739ebec0cbd625d8c89e19592be58fa186a6chenlu chen - Sun Microsystems - Beijing China
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 }
ea65739ebec0cbd625d8c89e19592be58fa186a6chenlu chen - Sun Microsystems - Beijing China return (B_TRUE);
ea65739ebec0cbd625d8c89e19592be58fa186a6chenlu chen - Sun Microsystems - Beijing China}
ea65739ebec0cbd625d8c89e19592be58fa186a6chenlu chen - Sun Microsystems - Beijing China
9da57d7b0ddd8d73b676ce12c040362132cdd538bt/*
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 */
9da57d7b0ddd8d73b676ce12c040362132cdd538btvoid
9da57d7b0ddd8d73b676ce12c040362132cdd538btvdev_load_log_state(vdev_t *nvd, vdev_t *ovd)
9da57d7b0ddd8d73b676ce12c040362132cdd538bt{
9da57d7b0ddd8d73b676ce12c040362132cdd538bt spa_t *spa = nvd->vdev_spa;
9da57d7b0ddd8d73b676ce12c040362132cdd538bt
9da57d7b0ddd8d73b676ce12c040362132cdd538bt ASSERT(nvd->vdev_top->vdev_islog);
9da57d7b0ddd8d73b676ce12c040362132cdd538bt ASSERT(spa_config_held(spa, SCL_STATE_ALL, RW_WRITER) == SCL_STATE_ALL);
9da57d7b0ddd8d73b676ce12c040362132cdd538bt ASSERT3U(nvd->vdev_guid, ==, ovd->vdev_guid);
9da57d7b0ddd8d73b676ce12c040362132cdd538bt
9da57d7b0ddd8d73b676ce12c040362132cdd538bt for (int c = 0; c < nvd->vdev_children; c++)
9da57d7b0ddd8d73b676ce12c040362132cdd538bt vdev_load_log_state(nvd->vdev_child[c], ovd->vdev_child[c]);
9da57d7b0ddd8d73b676ce12c040362132cdd538bt
9da57d7b0ddd8d73b676ce12c040362132cdd538bt if (nvd->vdev_ops->vdev_op_leaf) {
9da57d7b0ddd8d73b676ce12c040362132cdd538bt /*
9da57d7b0ddd8d73b676ce12c040362132cdd538bt * Restore the persistent vdev state
9da57d7b0ddd8d73b676ce12c040362132cdd538bt */
9da57d7b0ddd8d73b676ce12c040362132cdd538bt nvd->vdev_offline = ovd->vdev_offline;
9da57d7b0ddd8d73b676ce12c040362132cdd538bt nvd->vdev_faulted = ovd->vdev_faulted;
9da57d7b0ddd8d73b676ce12c040362132cdd538bt nvd->vdev_degraded = ovd->vdev_degraded;
9da57d7b0ddd8d73b676ce12c040362132cdd538bt nvd->vdev_removed = ovd->vdev_removed;
9da57d7b0ddd8d73b676ce12c040362132cdd538bt }
9da57d7b0ddd8d73b676ce12c040362132cdd538bt}
9da57d7b0ddd8d73b676ce12c040362132cdd538bt
9da57d7b0ddd8d73b676ce12c040362132cdd538bt/*
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.
9da57d7b0ddd8d73b676ce12c040362132cdd538bt */
9da57d7b0ddd8d73b676ce12c040362132cdd538btboolean_t
9da57d7b0ddd8d73b676ce12c040362132cdd538btvdev_log_state_valid(vdev_t *vd)
9da57d7b0ddd8d73b676ce12c040362132cdd538bt{
9da57d7b0ddd8d73b676ce12c040362132cdd538bt if (vd->vdev_ops->vdev_op_leaf && !vd->vdev_faulted &&
9da57d7b0ddd8d73b676ce12c040362132cdd538bt !vd->vdev_removed)
9da57d7b0ddd8d73b676ce12c040362132cdd538bt return (B_TRUE);
9da57d7b0ddd8d73b676ce12c040362132cdd538bt
3cfa0eb9019abbded0c93bce072ab4e73b989c13chenlu chen - Sun Microsystems - Beijing China for (int c = 0; c < vd->vdev_children; c++)
9da57d7b0ddd8d73b676ce12c040362132cdd538bt if (vdev_log_state_valid(vd->vdev_child[c]))
3cfa0eb9019abbded0c93bce072ab4e73b989c13chenlu chen - Sun Microsystems - Beijing China return (B_TRUE);
3cfa0eb9019abbded0c93bce072ab4e73b989c13chenlu chen - Sun Microsystems - Beijing China
3cfa0eb9019abbded0c93bce072ab4e73b989c13chenlu chen - Sun Microsystems - Beijing China return (B_FALSE);
3cfa0eb9019abbded0c93bce072ab4e73b989c13chenlu chen - Sun Microsystems - Beijing China}
3cfa0eb9019abbded0c93bce072ab4e73b989c13chenlu chen - Sun Microsystems - Beijing China
9da57d7b0ddd8d73b676ce12c040362132cdd538bt/*
3cfa0eb9019abbded0c93bce072ab4e73b989c13chenlu chen - Sun Microsystems - Beijing China * Expand a vdev if possible.
3cfa0eb9019abbded0c93bce072ab4e73b989c13chenlu chen - Sun Microsystems - Beijing China */
9da57d7b0ddd8d73b676ce12c040362132cdd538btvoid
3cfa0eb9019abbded0c93bce072ab4e73b989c13chenlu chen - Sun Microsystems - Beijing Chinavdev_expand(vdev_t *vd, uint64_t txg)
3cfa0eb9019abbded0c93bce072ab4e73b989c13chenlu chen - Sun Microsystems - Beijing China{
9da57d7b0ddd8d73b676ce12c040362132cdd538bt ASSERT(vd->vdev_top == vd);
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
3cfa0eb9019abbded0c93bce072ab4e73b989c13chenlu chen - Sun Microsystems - Beijing China if ((vd->vdev_asize >> vd->vdev_ms_shift) > vd->vdev_ms_count) {
9da57d7b0ddd8d73b676ce12c040362132cdd538bt VERIFY(vdev_metaslab_init(vd, txg) == 0);
3cfa0eb9019abbded0c93bce072ab4e73b989c13chenlu chen - Sun Microsystems - Beijing China vdev_config_dirty(vd);
3cfa0eb9019abbded0c93bce072ab4e73b989c13chenlu chen - Sun Microsystems - Beijing China }
3cfa0eb9019abbded0c93bce072ab4e73b989c13chenlu chen - Sun Microsystems - Beijing China}
9da57d7b0ddd8d73b676ce12c040362132cdd538bt
9da57d7b0ddd8d73b676ce12c040362132cdd538bt/*
9da57d7b0ddd8d73b676ce12c040362132cdd538bt * Split a vdev.
3cfa0eb9019abbded0c93bce072ab4e73b989c13chenlu chen - Sun Microsystems - Beijing China */
3cfa0eb9019abbded0c93bce072ab4e73b989c13chenlu chen - Sun Microsystems - Beijing Chinavoid
73cd555c10e70dac413ae4b40de8450a291750acBin Tu - Sun Microsystems - Beijing Chinavdev_split(vdev_t *vd)
73cd555c10e70dac413ae4b40de8450a291750acBin Tu - Sun Microsystems - Beijing China{
9da57d7b0ddd8d73b676ce12c040362132cdd538bt vdev_t *cvd, *pvd = vd->vdev_parent;
73cd555c10e70dac413ae4b40de8450a291750acBin Tu - Sun Microsystems - Beijing China
9da57d7b0ddd8d73b676ce12c040362132cdd538bt vdev_remove_child(pvd, vd);
9da57d7b0ddd8d73b676ce12c040362132cdd538bt vdev_compact_children(pvd);
9da57d7b0ddd8d73b676ce12c040362132cdd538bt
9da57d7b0ddd8d73b676ce12c040362132cdd538bt cvd = pvd->vdev_child[0];
9da57d7b0ddd8d73b676ce12c040362132cdd538bt if (pvd->vdev_children == 1) {
9da57d7b0ddd8d73b676ce12c040362132cdd538bt vdev_remove_parent(cvd);
62e6e1adfc8d795f477410703cc7a88dc5b82622Paul Guo cvd->vdev_splitting = B_TRUE;
62e6e1adfc8d795f477410703cc7a88dc5b82622Paul Guo }
62e6e1adfc8d795f477410703cc7a88dc5b82622Paul Guo vdev_propagate_state(cvd);
9da57d7b0ddd8d73b676ce12c040362132cdd538bt}
13740cb230f19fcbf1a6468d1a6a0ba9a0a09c22Paul Guo
62e6e1adfc8d795f477410703cc7a88dc5b82622Paul Guovoid
9da57d7b0ddd8d73b676ce12c040362132cdd538btvdev_deadman(vdev_t *vd)
9da57d7b0ddd8d73b676ce12c040362132cdd538bt{
9da57d7b0ddd8d73b676ce12c040362132cdd538bt for (int c = 0; c < vd->vdev_children; c++) {
9da57d7b0ddd8d73b676ce12c040362132cdd538bt vdev_t *cvd = vd->vdev_child[c];
9da57d7b0ddd8d73b676ce12c040362132cdd538bt
9da57d7b0ddd8d73b676ce12c040362132cdd538bt vdev_deadman(cvd);
62e6e1adfc8d795f477410703cc7a88dc5b82622Paul Guo }
9da57d7b0ddd8d73b676ce12c040362132cdd538bt
62e6e1adfc8d795f477410703cc7a88dc5b82622Paul Guo if (vd->vdev_ops->vdev_op_leaf) {
9da57d7b0ddd8d73b676ce12c040362132cdd538bt vdev_queue_t *vq = &vd->vdev_queue;
62e6e1adfc8d795f477410703cc7a88dc5b82622Paul Guo
62e6e1adfc8d795f477410703cc7a88dc5b82622Paul Guo mutex_enter(&vq->vq_lock);
73cd555c10e70dac413ae4b40de8450a291750acBin Tu - Sun Microsystems - Beijing China if (avl_numnodes(&vq->vq_active_tree) > 0) {
69b5a878d62fdee1b12e78371ce6cc8abddcad15Dan McDonald spa_t *spa = vd->vdev_spa;
73cd555c10e70dac413ae4b40de8450a291750acBin Tu - Sun Microsystems - Beijing China zio_t *fio;
9da57d7b0ddd8d73b676ce12c040362132cdd538bt uint64_t delta;
9da57d7b0ddd8d73b676ce12c040362132cdd538bt
9da57d7b0ddd8d73b676ce12c040362132cdd538bt /*
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 */
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",
73cd555c10e70dac413ae4b40de8450a291750acBin Tu - Sun Microsystems - Beijing China fio->io_timestamp, delta,
9da57d7b0ddd8d73b676ce12c040362132cdd538bt vq->vq_io_complete_ts);
9da57d7b0ddd8d73b676ce12c040362132cdd538bt fm_panic("I/O to pool '%s' appears to be "
9da57d7b0ddd8d73b676ce12c040362132cdd538bt "hung.", spa_name(spa));
9da57d7b0ddd8d73b676ce12c040362132cdd538bt }
9da57d7b0ddd8d73b676ce12c040362132cdd538bt }
9da57d7b0ddd8d73b676ce12c040362132cdd538bt mutex_exit(&vq->vq_lock);
62e6e1adfc8d795f477410703cc7a88dc5b82622Paul Guo }
62e6e1adfc8d795f477410703cc7a88dc5b82622Paul Guo}
62e6e1adfc8d795f477410703cc7a88dc5b82622Paul Guo