fa9e4066f08beec538e775443c5be79dd423fcabahrens * CDDL HEADER START
fa9e4066f08beec538e775443c5be79dd423fcabahrens * The contents of this file are subject to the terms of the
441d80aa4f613b6298fc8bd3151f4be02dbf84fclling * Common Development and Distribution License (the "License").
441d80aa4f613b6298fc8bd3151f4be02dbf84fclling * You may not use this file except in compliance with the License.
fa9e4066f08beec538e775443c5be79dd423fcabahrens * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
fa9e4066f08beec538e775443c5be79dd423fcabahrens * See the License for the specific language governing permissions
fa9e4066f08beec538e775443c5be79dd423fcabahrens * and limitations under the License.
fa9e4066f08beec538e775443c5be79dd423fcabahrens * When distributing Covered Code, include this CDDL HEADER in each
fa9e4066f08beec538e775443c5be79dd423fcabahrens * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
fa9e4066f08beec538e775443c5be79dd423fcabahrens * If applicable, add the following below this CDDL HEADER, with the
fa9e4066f08beec538e775443c5be79dd423fcabahrens * fields enclosed by brackets "[]" replaced with your own identifying
fa9e4066f08beec538e775443c5be79dd423fcabahrens * information: Portions Copyright [yyyy] [name of copyright owner]
fa9e4066f08beec538e775443c5be79dd423fcabahrens * CDDL HEADER END
98d1cbfec254295273b6a761bc1861c0374bdf02George Wilson * Copyright (c) 2005, 2010, Oracle and/or its affiliates. All rights reserved.
81cd5c555f505484180a62ca5a2fbb00d70c57d6Matthew Ahrens * Copyright (c) 2011, 2015 by Delphix. All rights reserved.
1a902ef8628b0dffd6df5442354ab59bb8530962Hans Rosenfeld * Copyright 2015 Nexenta Systems, Inc. All rights reserved.
c3d26abc9ee97b4f60233556aadeb57e0bd30bb9Matthew Ahrens * Copyright (c) 2014 Integros [integros.com]
c8811bd3e2427dddbac6c05a59cfe117d8fea370Toomas Soome * Copyright 2016 Toomas Soome <tsoome@me.com>
fa9e4066f08beec538e775443c5be79dd423fcabahrens * Virtual device management.
088f389458728c464569a5506b58070254fa4f7dahrens/* maximum scrub/resilver I/O queue per leaf vdev */
bf3e216c7efa56332b456f4cf19d208e21d63839Matthew Ahrens * When a vdev is added, it will be divided into approximately (but no
bf3e216c7efa56332b456f4cf19d208e21d63839Matthew Ahrens * more than) this number of metaslabs.
fa9e4066f08beec538e775443c5be79dd423fcabahrens * Given a vdev type, return the appropriate ops vector.
fa9e4066f08beec538e775443c5be79dd423fcabahrens for (opspp = vdev_ops_table; (ops = *opspp) != NULL; opspp++)
fa9e4066f08beec538e775443c5be79dd423fcabahrens * Default asize function: return the MAX of psize with the asize of
fa9e4066f08beec538e775443c5be79dd423fcabahrens * all children. This is what's used by anything other than RAID-Z.
ecc2d604e885a75cc75e647b5641af99d5a6f4a6bonwick uint64_t asize = P2ROUNDUP(psize, 1ULL << vd->vdev_top->vdev_ashift);
fa9e4066f08beec538e775443c5be79dd423fcabahrens csize = vdev_psize_to_asize(vd->vdev_child[c], psize);
573ca77e53dd31dcaebef023e7eb41969e6896c1George Wilson * Get the minimum allocatable size. We define the allocatable size as
573ca77e53dd31dcaebef023e7eb41969e6896c1George Wilson * the vdev's asize rounded to the nearest metaslab. This allows us to
573ca77e53dd31dcaebef023e7eb41969e6896c1George Wilson * replace or attach devices which don't have the same physical size but
573ca77e53dd31dcaebef023e7eb41969e6896c1George Wilson * can still satisfy the same number of allocations.
4263d13f00c9691fa14620eff82abef795be0693George Wilson * If our parent is NULL (inactive spare or cache) or is the root,
573ca77e53dd31dcaebef023e7eb41969e6896c1George Wilson * just return our own asize.
573ca77e53dd31dcaebef023e7eb41969e6896c1George Wilson * The top-level vdev just returns the allocatable size rounded
573ca77e53dd31dcaebef023e7eb41969e6896c1George Wilson * to the nearest metaslab.
573ca77e53dd31dcaebef023e7eb41969e6896c1George Wilson return (P2ALIGN(vd->vdev_asize, 1ULL << vd->vdev_ms_shift));
573ca77e53dd31dcaebef023e7eb41969e6896c1George Wilson * The allocatable space for a raidz vdev is N * sizeof(smallest child),
573ca77e53dd31dcaebef023e7eb41969e6896c1George Wilson * so each child must provide at least 1/Nth of its asize.
573ca77e53dd31dcaebef023e7eb41969e6896c1George Wilson return (pvd->vdev_min_asize / pvd->vdev_children);
e14bb3258d05c1b1077e2db7cf77088924e56919Jeff Bonwick ASSERT(spa_config_held(spa, SCL_ALL, RW_READER) != 0);
fa9e4066f08beec538e775443c5be79dd423fcabahrens if ((mvd = vdev_lookup_by_guid(vd->vdev_child[c], guid)) !=
12380e1e701fda28c9e9f32d01cafb54af279eb5Arne Jansen return (vdev_count_leaves_impl(spa->spa_root_vdev));
81cd5c555f505484180a62ca5a2fbb00d70c57d6Matthew Ahrens ASSERT(spa_config_held(spa, SCL_ALL, RW_WRITER) == SCL_ALL);
fa9e4066f08beec538e775443c5be79dd423fcabahrens ASSERT(id >= pvd->vdev_children || pvd->vdev_child[id] == NULL);
fa9e4066f08beec538e775443c5be79dd423fcabahrens pvd->vdev_children = MAX(pvd->vdev_children, id + 1);
fa9e4066f08beec538e775443c5be79dd423fcabahrens cvd->vdev_top = (pvd->vdev_top ? pvd->vdev_top: cvd);
fa9e4066f08beec538e775443c5be79dd423fcabahrens ASSERT(cvd->vdev_top->vdev_parent->vdev_parent == NULL);
fa9e4066f08beec538e775443c5be79dd423fcabahrens * Walk up all ancestors to update guid sum.
fa9e4066f08beec538e775443c5be79dd423fcabahrens * Walk up all ancestors to update guid sum.
fa9e4066f08beec538e775443c5be79dd423fcabahrens * Remove any holes in the child array.
e14bb3258d05c1b1077e2db7cf77088924e56919Jeff Bonwick ASSERT(spa_config_held(pvd->vdev_spa, SCL_ALL, RW_WRITER) == SCL_ALL);
fa9e4066f08beec538e775443c5be79dd423fcabahrens newchild = kmem_alloc(newc * sizeof (vdev_t *), KM_SLEEP);
fa9e4066f08beec538e775443c5be79dd423fcabahrens kmem_free(pvd->vdev_child, oldc * sizeof (vdev_t *));
fa9e4066f08beec538e775443c5be79dd423fcabahrens * Allocate and minimally initialize a vdev_t.
fa9e4066f08beec538e775443c5be79dd423fcabahrensvdev_alloc_common(spa_t *spa, uint_t id, uint64_t guid, vdev_ops_t *ops)
e9103aaee0c546d4644791198c54abb03c89969eGarrett D'Amore spa->spa_load_guid = spa_generate_guid(NULL);
0e34b6a7bff4918432f0aa6b1dfaf73ac9df45b1bonwick * The root vdev's guid will also be the pool guid,
0e34b6a7bff4918432f0aa6b1dfaf73ac9df45b1bonwick * which must be unique among all pools.
0e34b6a7bff4918432f0aa6b1dfaf73ac9df45b1bonwick * Any other vdev's guid must be unique within the pool.
fa9e4066f08beec538e775443c5be79dd423fcabahrens mutex_init(&vd->vdev_dtl_lock, NULL, MUTEX_DEFAULT, NULL);
5ad820458efd0fdb914baff9c1447c22b819fa23nd mutex_init(&vd->vdev_stat_lock, NULL, MUTEX_DEFAULT, NULL);
e14bb3258d05c1b1077e2db7cf77088924e56919Jeff Bonwick mutex_init(&vd->vdev_probe_lock, NULL, MUTEX_DEFAULT, NULL);
0f7643c7376dd69a08acbfc9d1d7d548b10c846aGeorge Wilson mutex_init(&vd->vdev_queue_lock, NULL, MUTEX_DEFAULT, NULL);
8ad4d6dd86f5bc65fb3afa566c8133f3bac21648Jeff Bonwick for (int t = 0; t < DTL_TYPES; t++) {
0713e232b7712cd27d99e1e935ebb8d5de61c57dGeorge Wilson vd->vdev_dtl[t] = range_tree_create(NULL, NULL,
fa9e4066f08beec538e775443c5be79dd423fcabahrens * Allocate a new vdev. The 'alloctype' is used to control whether we are
fa9e4066f08beec538e775443c5be79dd423fcabahrens * creating a new vdev or loading an existing one - the behavior is slightly
fa9e4066f08beec538e775443c5be79dd423fcabahrens * different for each case.
99653d4ee642c6528e88224f12409a5f23060994eschrockvdev_alloc(spa_t *spa, vdev_t **vdp, nvlist_t *nv, vdev_t *parent, uint_t id,
e14bb3258d05c1b1077e2db7cf77088924e56919Jeff Bonwick ASSERT(spa_config_held(spa, SCL_ALL, RW_WRITER) == SCL_ALL);
fa9e4066f08beec538e775443c5be79dd423fcabahrens if (nvlist_lookup_string(nv, ZPOOL_CONFIG_TYPE, &type) != 0)
fa9e4066f08beec538e775443c5be79dd423fcabahrens * If this is a load, get the vdev guid from the nvlist.
fa9e4066f08beec538e775443c5be79dd423fcabahrens * Otherwise, vdev_alloc_common() will generate one for us.
fa9e4066f08beec538e775443c5be79dd423fcabahrens if (nvlist_lookup_uint64(nv, ZPOOL_CONFIG_ID, &label_id) ||
fa9e4066f08beec538e775443c5be79dd423fcabahrens if (nvlist_lookup_uint64(nv, ZPOOL_CONFIG_GUID, &guid) != 0)
99653d4ee642c6528e88224f12409a5f23060994eschrock if (nvlist_lookup_uint64(nv, ZPOOL_CONFIG_GUID, &guid) != 0)
fa94a07fd0519b8abfd871ad8fe60e6bebe1e2bbbrendan if (nvlist_lookup_uint64(nv, ZPOOL_CONFIG_GUID, &guid) != 0)
21ecdf64e1e200cd74cadf771fc7ddc3d0062080Lin Ling if (nvlist_lookup_uint64(nv, ZPOOL_CONFIG_GUID, &guid) != 0)
99653d4ee642c6528e88224f12409a5f23060994eschrock * The first allocated vdev must be of type 'root'.
99653d4ee642c6528e88224f12409a5f23060994eschrock if (ops != &vdev_root_ops && spa->spa_root_vdev == NULL)
8654d0253136055bd4cc2423d87378e8a37f2eb5perrin * Determine whether we're a log vdev.
8654d0253136055bd4cc2423d87378e8a37f2eb5perrin (void) nvlist_lookup_uint64(nv, ZPOOL_CONFIG_IS_LOG, &islog);
88ecc943b4eb72f7c4fbbd8435997b85ef171fc3George Wilson if (ops == &vdev_hole_ops && spa_version(spa) < SPA_VERSION_HOLES)
8654d0253136055bd4cc2423d87378e8a37f2eb5perrin * Set the nparity property for RAID-Z vdevs.
b24ab6762772a3f6a89393947930c7fa61306783Jeff Bonwick if (nparity == 0 || nparity > VDEV_RAIDZ_MAXPARITY)
f94275ce205810a201404c5f35f4cc96057022b1Adam Leventhal * Previous versions could only support 1 or 2 parity
99653d4ee642c6528e88224f12409a5f23060994eschrock * We require the parity to be specified for SPAs that
99653d4ee642c6528e88224f12409a5f23060994eschrock * support multiple parity levels.
99653d4ee642c6528e88224f12409a5f23060994eschrock * Otherwise, we default to 1 parity device for RAID-Z.
8654d0253136055bd4cc2423d87378e8a37f2eb5perrin if (nvlist_lookup_string(nv, ZPOOL_CONFIG_PATH, &vd->vdev_path) == 0)
8654d0253136055bd4cc2423d87378e8a37f2eb5perrin if (nvlist_lookup_string(nv, ZPOOL_CONFIG_DEVID, &vd->vdev_devid) == 0)
6809eb4e2a4a94bcc76229c7b5108b96134537b6Eric Schrock if (nvlist_lookup_string(nv, ZPOOL_CONFIG_FRU, &vd->vdev_fru) == 0)
afefbcddfd8caf5f3b2da510d9439471ab225040eschrock * Set the whole_disk property. If it's not specified, leave the value
afefbcddfd8caf5f3b2da510d9439471ab225040eschrock if (nvlist_lookup_uint64(nv, ZPOOL_CONFIG_WHOLE_DISK,
ea8dc4b6d2251b437950c0056bc626b311c73c27eschrock * Look for the 'not present' flag. This will only be set if the device
ea8dc4b6d2251b437950c0056bc626b311c73c27eschrock * was not present at the time of import.
6809eb4e2a4a94bcc76229c7b5108b96134537b6Eric Schrock (void) nvlist_lookup_uint64(nv, ZPOOL_CONFIG_NOT_PRESENT,
ecc2d604e885a75cc75e647b5641af99d5a6f4a6bonwick * Get the alignment requirement.
ecc2d604e885a75cc75e647b5641af99d5a6f4a6bonwick (void) nvlist_lookup_uint64(nv, ZPOOL_CONFIG_ASHIFT, &vd->vdev_ashift);
88ecc943b4eb72f7c4fbbd8435997b85ef171fc3George Wilson * Retrieve the vdev creation time.
88ecc943b4eb72f7c4fbbd8435997b85ef171fc3George Wilson (void) nvlist_lookup_uint64(nv, ZPOOL_CONFIG_CREATE_TXG,
fa9e4066f08beec538e775443c5be79dd423fcabahrens * If we're a top-level vdev, try to load the allocation parameters.
1195e687f1c03c8d57417b5999578922e20a3554Mark J Musante (alloctype == VDEV_ALLOC_LOAD || alloctype == VDEV_ALLOC_SPLIT)) {
fa9e4066f08beec538e775443c5be79dd423fcabahrens (void) nvlist_lookup_uint64(nv, ZPOOL_CONFIG_METASLAB_ARRAY,
fa9e4066f08beec538e775443c5be79dd423fcabahrens (void) nvlist_lookup_uint64(nv, ZPOOL_CONFIG_METASLAB_SHIFT,
3f9d6ad73e45c6823b409f93b0c8d4f62861d2d5Lin Ling (void) nvlist_lookup_uint64(nv, ZPOOL_CONFIG_REMOVING,
215198a6ad15cf4832370e2f19247abeb36b951aJoe Stein (void) nvlist_lookup_uint64(nv, ZPOOL_CONFIG_VDEV_TOP_ZAP,
cd0837cc943a814d8b2e7ff44d61265f67220f66George Wilson if (parent && !parent->vdev_parent && alloctype != VDEV_ALLOC_ATTACH) {
a15215608b8bd90f714f6db21ee623b584607cb6Jeff Bonwick spa_log_class(spa) : spa_normal_class(spa), vd);
215198a6ad15cf4832370e2f19247abeb36b951aJoe Stein (alloctype == VDEV_ALLOC_LOAD || alloctype == VDEV_ALLOC_SPLIT)) {
3d7072f8bd27709dba14f6fe336f149d25d9e207eschrock * If we're a leaf vdev, try to load the DTL object and other state.
21ecdf64e1e200cd74cadf771fc7ddc3d0062080Lin Ling (alloctype == VDEV_ALLOC_LOAD || alloctype == VDEV_ALLOC_L2CACHE ||
c5904d138f3bdf0762dbf452a43d5a5c387ea6a8eschrock (void) nvlist_lookup_uint64(nv, ZPOOL_CONFIG_UNSPARE,
21ecdf64e1e200cd74cadf771fc7ddc3d0062080Lin Ling if (nvlist_lookup_uint64(nv, ZPOOL_CONFIG_IS_SPARE,
ecc2d604e885a75cc75e647b5641af99d5a6f4a6bonwick (void) nvlist_lookup_uint64(nv, ZPOOL_CONFIG_OFFLINE,
b4952e17e8858d3225793b28788278de9fe6038dGeorge Wilson (void) nvlist_lookup_uint64(nv, ZPOOL_CONFIG_RESILVER_TXG,
3d7072f8bd27709dba14f6fe336f149d25d9e207eschrock * When importing a pool, we want to ignore the persistent fault
3d7072f8bd27709dba14f6fe336f149d25d9e207eschrock * state, as the diagnosis made on another system may not be
069f55e237020c4a4907b235fc38fafc6442ce94Eric Schrock * valid in the current context. Local vdevs will
069f55e237020c4a4907b235fc38fafc6442ce94Eric Schrock * remain in the faulted state.
3d7072f8bd27709dba14f6fe336f149d25d9e207eschrock (void) nvlist_lookup_uint64(nv, ZPOOL_CONFIG_FAULTED,
3d7072f8bd27709dba14f6fe336f149d25d9e207eschrock (void) nvlist_lookup_uint64(nv, ZPOOL_CONFIG_DEGRADED,
3d7072f8bd27709dba14f6fe336f149d25d9e207eschrock (void) nvlist_lookup_uint64(nv, ZPOOL_CONFIG_REMOVED,
fa9e4066f08beec538e775443c5be79dd423fcabahrens * Add ourselves to the parent's list of children.
99653d4ee642c6528e88224f12409a5f23060994eschrock return (0);
fa9e4066f08beec538e775443c5be79dd423fcabahrens * vdev_free() implies closing the vdev first. This is simpler than
fa9e4066f08beec538e775443c5be79dd423fcabahrens * trying to ensure complicated semantics for all callers.
e14bb3258d05c1b1077e2db7cf77088924e56919Jeff Bonwick ASSERT(!list_link_active(&vd->vdev_config_dirty_node));
b24ab6762772a3f6a89393947930c7fa61306783Jeff Bonwick ASSERT(!list_link_active(&vd->vdev_state_dirty_node));
fa9e4066f08beec538e775443c5be79dd423fcabahrens * Free all children.
fa9e4066f08beec538e775443c5be79dd423fcabahrens * Discard allocation state.
fa9e4066f08beec538e775443c5be79dd423fcabahrens * Remove this vdev from its parent's child list.
3d7072f8bd27709dba14f6fe336f149d25d9e207eschrock * Clean up vdev structure.
8ad4d6dd86f5bc65fb3afa566c8133f3bac21648Jeff Bonwick for (int t = 0; t < DTL_TYPES; t++) {
0713e232b7712cd27d99e1e935ebb8d5de61c57dGeorge Wilson range_tree_vacate(vd->vdev_dtl[t], NULL, NULL);
fa9e4066f08beec538e775443c5be79dd423fcabahrens * Transfer top-level vdev state from svd to tvd.
99653d4ee642c6528e88224f12409a5f23060994eschrock tvd->vdev_stat.vs_dspace = svd->vdev_stat.vs_dspace;
fa9e4066f08beec538e775443c5be79dd423fcabahrens for (t = 0; t < TXG_SIZE; t++) {
fa9e4066f08beec538e775443c5be79dd423fcabahrens while ((msp = txg_list_remove(&svd->vdev_ms_list, t)) != NULL)
fa9e4066f08beec538e775443c5be79dd423fcabahrens while ((vd = txg_list_remove(&svd->vdev_dtl_list, t)) != NULL)
fa9e4066f08beec538e775443c5be79dd423fcabahrens if (txg_list_remove_this(&spa->spa_vdev_txg_list, svd, t))
fa9e4066f08beec538e775443c5be79dd423fcabahrens (void) txg_list_add(&spa->spa_vdev_txg_list, tvd, t);
e14bb3258d05c1b1077e2db7cf77088924e56919Jeff Bonwick if (list_link_active(&svd->vdev_config_dirty_node)) {
e14bb3258d05c1b1077e2db7cf77088924e56919Jeff Bonwick if (list_link_active(&svd->vdev_state_dirty_node)) {
fa9e4066f08beec538e775443c5be79dd423fcabahrens * Add a mirror/replacing vdev above an existing vdev.
e14bb3258d05c1b1077e2db7cf77088924e56919Jeff Bonwick ASSERT(spa_config_held(spa, SCL_ALL, RW_WRITER) == SCL_ALL);
fa9e4066f08beec538e775443c5be79dd423fcabahrens * Remove a 1-way mirror/replacing vdev from the tree.
e14bb3258d05c1b1077e2db7cf77088924e56919Jeff Bonwick ASSERT(spa_config_held(cvd->vdev_spa, SCL_ALL, RW_WRITER) == SCL_ALL);
e14bb3258d05c1b1077e2db7cf77088924e56919Jeff Bonwick * If cvd will replace mvd as a top-level vdev, preserve mvd's guid.
e14bb3258d05c1b1077e2db7cf77088924e56919Jeff Bonwick * Otherwise, we could have detached an offline device, and when we
e14bb3258d05c1b1077e2db7cf77088924e56919Jeff Bonwick * go to import the pool we'll think we have two top-level vdevs,
e14bb3258d05c1b1077e2db7cf77088924e56919Jeff Bonwick * instead of a different version of the same top-level vdev.
8ad4d6dd86f5bc65fb3afa566c8133f3bac21648Jeff Bonwick uint64_t guid_delta = mvd->vdev_guid - cvd->vdev_guid;
a15215608b8bd90f714f6db21ee623b584607cb6Jeff Bonwick ASSERT(txg == 0 || spa_config_held(spa, SCL_ALLOC, RW_WRITER));
88ecc943b4eb72f7c4fbbd8435997b85ef171fc3George Wilson * This vdev is not being allocated from yet or is a hole.
0e34b6a7bff4918432f0aa6b1dfaf73ac9df45b1bonwick return (0);
e6ca193ded880d478cc39e34ef82d4be36e4445dGeorge Wilson * Compute the raidz-deflation ratio. Note, we hard-code
b515258426fed6c7311fd3f1dea697cfbd4085c6Matthew Ahrens * in 128k (1 << 17) because it is the "typical" blocksize.
b515258426fed6c7311fd3f1dea697cfbd4085c6Matthew Ahrens * Even though SPA_MAXBLOCKSIZE changed, this algorithm can not change,
b515258426fed6c7311fd3f1dea697cfbd4085c6Matthew Ahrens * otherwise it would inconsistently account for existing bp's.
e6ca193ded880d478cc39e34ef82d4be36e4445dGeorge Wilson (vdev_psize_to_asize(vd, 1 << 17) >> SPA_MINBLOCKSHIFT);
ecc2d604e885a75cc75e647b5641af99d5a6f4a6bonwick mspp = kmem_zalloc(newc * sizeof (*mspp), KM_SLEEP);
ecc2d604e885a75cc75e647b5641af99d5a6f4a6bonwick if (oldc != 0) {
ecc2d604e885a75cc75e647b5641af99d5a6f4a6bonwick if (txg == 0) {
7bfdf011e081684f853a3242d0296695110d9d84Neil Perrin m * sizeof (uint64_t), sizeof (uint64_t), &object,
1e9bd7ec42f2d3bf854c2da35310901194833267Prakash Surya error = metaslab_init(vd->vdev_mg, m, object, txg,
a15215608b8bd90f714f6db21ee623b584607cb6Jeff Bonwick spa_config_enter(spa, SCL_ALLOC, FTAG, RW_WRITER);
3f9d6ad73e45c6823b409f93b0c8d4f62861d2d5Lin Ling * If the vdev is being removed we don't activate
3f9d6ad73e45c6823b409f93b0c8d4f62861d2d5Lin Ling * the metaslabs since we want to ensure that no new
3f9d6ad73e45c6823b409f93b0c8d4f62861d2d5Lin Ling * allocations are performed on this device.
ea8dc4b6d2251b437950c0056bc626b311c73c27eschrock return (0);
0713e232b7712cd27d99e1e935ebb8d5de61c57dGeorge Wilson for (m = 0; m < count; m++) {
fa9e4066f08beec538e775443c5be79dd423fcabahrens kmem_free(vd->vdev_ms, count * sizeof (metaslab_t *));
8ad4d6dd86f5bc65fb3afa566c8133f3bac21648Jeff Bonwick if (zio->io_error == 0 && spa_writeable(spa)) {
a3f829ae41ece20e7f5f63604e177aeeb8b24628Bill Moore zio_nowait(zio_write_phys(vd->vdev_probe_zio, vd,
e14bb3258d05c1b1077e2db7cf77088924e56919Jeff Bonwick ZIO_PRIORITY_SYNC_WRITE, vps->vps_flags, B_TRUE));
0f7643c7376dd69a08acbfc9d1d7d548b10c846aGeorge Wilson while ((pio = zio_walk_parents(zio, &zl)) != NULL)
f7170741490edba9d1d9c697c177c887172bc741Will Andrews * Determine whether this device is accessible.
f7170741490edba9d1d9c697c177c887172bc741Will Andrews * Read and write to several known locations: the pad regions of each
f7170741490edba9d1d9c697c177c887172bc741Will Andrews * vdev label but the first, which we leave alone in case it contains
a3f829ae41ece20e7f5f63604e177aeeb8b24628Bill Moore * Don't probe the probe.
a3f829ae41ece20e7f5f63604e177aeeb8b24628Bill Moore * To prevent 'probe storms' when a device fails, we create
a3f829ae41ece20e7f5f63604e177aeeb8b24628Bill Moore * just one probe i/o at a time. All zios that want to probe
a3f829ae41ece20e7f5f63604e177aeeb8b24628Bill Moore * this vdev will become parents of the probe io.
a3f829ae41ece20e7f5f63604e177aeeb8b24628Bill Moore vps->vps_flags = ZIO_FLAG_CANFAIL | ZIO_FLAG_PROBE |
a3f829ae41ece20e7f5f63604e177aeeb8b24628Bill Moore * vdev_cant_read and vdev_cant_write can only
a3f829ae41ece20e7f5f63604e177aeeb8b24628Bill Moore * transition from TRUE to FALSE when we have the
a3f829ae41ece20e7f5f63604e177aeeb8b24628Bill Moore * SCL_ZIO lock as writer; otherwise they can only
a3f829ae41ece20e7f5f63604e177aeeb8b24628Bill Moore * transition from FALSE to TRUE. This ensures that
a3f829ae41ece20e7f5f63604e177aeeb8b24628Bill Moore * any zio looking at these values can assume that
a3f829ae41ece20e7f5f63604e177aeeb8b24628Bill Moore * failures persist for the life of the I/O. That's
a3f829ae41ece20e7f5f63604e177aeeb8b24628Bill Moore * important because when a device has intermittent
a3f829ae41ece20e7f5f63604e177aeeb8b24628Bill Moore * connectivity problems, we want to ensure that
a3f829ae41ece20e7f5f63604e177aeeb8b24628Bill Moore * they're ascribed to the device (ENXIO) and not
a3f829ae41ece20e7f5f63604e177aeeb8b24628Bill Moore * the zio (EIO).
a3f829ae41ece20e7f5f63604e177aeeb8b24628Bill Moore * Since we hold SCL_ZIO as writer here, clear both
a3f829ae41ece20e7f5f63604e177aeeb8b24628Bill Moore * values so the probe can reevaluate from first
a3f829ae41ece20e7f5f63604e177aeeb8b24628Bill Moore * principles.
a3f829ae41ece20e7f5f63604e177aeeb8b24628Bill Moore vd->vdev_probe_zio = pio = zio_null(NULL, spa, vd,
98d1cbfec254295273b6a761bc1861c0374bdf02George Wilson * We can't change the vdev state in this context, so we
98d1cbfec254295273b6a761bc1861c0374bdf02George Wilson * kick off an async task to do it on our behalf.
e14bb3258d05c1b1077e2db7cf77088924e56919Jeff Bonwick ZIO_PRIORITY_SYNC_READ, vps->vps_flags, B_TRUE));
681d9761e8516a7dc5ab6589e2dfe717777e1123Eric Taylor if (vd->vdev_path && strncmp(vd->vdev_path, ZVOL_DIR,
681d9761e8516a7dc5ab6589e2dfe717777e1123Eric Taylor * in order to handle pools on top of zvols, do the opens
681d9761e8516a7dc5ab6589e2dfe717777e1123Eric Taylor * in a single thread so that the same thread holds the
681d9761e8516a7dc5ab6589e2dfe717777e1123Eric Taylor * spa_namespace_lock
681d9761e8516a7dc5ab6589e2dfe717777e1123Eric Taylor for (int c = 0; c < children; c++)
f64c0e34235c0ee36e44e9ff1cf0cd3764ed227dEric Taylor tq = taskq_create("vdev_open", children, minclsyspri,
f64c0e34235c0ee36e44e9ff1cf0cd3764ed227dEric Taylor for (int c = 0; c < children; c++)
f64c0e34235c0ee36e44e9ff1cf0cd3764ed227dEric Taylor VERIFY(taskq_dispatch(tq, vdev_open_child, vd->vdev_child[c],
fa9e4066f08beec538e775443c5be79dd423fcabahrens * Prepare a virtual device for access.
f64c0e34235c0ee36e44e9ff1cf0cd3764ed227dEric Taylor spa_config_held(spa, SCL_STATE_ALL, RW_WRITER) == SCL_STATE_ALL);
069f55e237020c4a4907b235fc38fafc6442ce94Eric Schrock * If this vdev is not removed, check its fault status. If it's
069f55e237020c4a4907b235fc38fafc6442ce94Eric Schrock * faulted, bail out of the open.
069f55e237020c4a4907b235fc38fafc6442ce94Eric Schrock ASSERT(vd->vdev_label_aux == VDEV_AUX_ERR_EXCEEDED ||
ea8dc4b6d2251b437950c0056bc626b311c73c27eschrock vdev_set_state(vd, B_TRUE, VDEV_STATE_OFFLINE, VDEV_AUX_NONE);
4263d13f00c9691fa14620eff82abef795be0693George Wilson error = vd->vdev_ops->vdev_op_open(vd, &osize, &max_osize, &ashift);
095bcd6622e3b3520eb3b71039a3be5cfab25b74George Wilson * Reset the vdev_reopening flag so that we actually close
095bcd6622e3b3520eb3b71039a3be5cfab25b74George Wilson * the vdev on error.
8956713aded83a741173fcd4f9ef1c83521fbea9Eric Schrock error = zio_handle_device_injection(vd, NULL, ENXIO);
096d22d43da2758693a6df66ce7d9ab54c9d464cEric Schrock * Recheck the faulted flag now that we have confirmed that
096d22d43da2758693a6df66ce7d9ab54c9d464cEric Schrock * the vdev is accessible. If we're faulted, bail.
096d22d43da2758693a6df66ce7d9ab54c9d464cEric Schrock ASSERT(vd->vdev_label_aux == VDEV_AUX_ERR_EXCEEDED ||
069f55e237020c4a4907b235fc38fafc6442ce94Eric Schrock vdev_set_state(vd, B_TRUE, VDEV_STATE_HEALTHY, 0);
88ecc943b4eb72f7c4fbbd8435997b85ef171fc3George Wilson * For hole or missing vdevs we just return success.
88ecc943b4eb72f7c4fbbd8435997b85ef171fc3George Wilson if (vd->vdev_ishole || vd->vdev_ops == &vdev_missing_ops)
ea8dc4b6d2251b437950c0056bc626b311c73c27eschrock if (vd->vdev_child[c]->vdev_state != VDEV_STATE_HEALTHY) {
fa9e4066f08beec538e775443c5be79dd423fcabahrens osize = P2ALIGN(osize, (uint64_t)sizeof (vdev_label_t));
4263d13f00c9691fa14620eff82abef795be0693George Wilson max_osize = P2ALIGN(max_osize, (uint64_t)sizeof (vdev_label_t));
fa9e4066f08beec538e775443c5be79dd423fcabahrens asize = osize - (VDEV_LABEL_START_SIZE + VDEV_LABEL_END_SIZE);
4263d13f00c9691fa14620eff82abef795be0693George Wilson max_asize = max_osize - (VDEV_LABEL_START_SIZE +
ecc2d604e885a75cc75e647b5641af99d5a6f4a6bonwick if (vd->vdev_parent != NULL && osize < SPA_MINDEVSIZE -
573ca77e53dd31dcaebef023e7eb41969e6896c1George Wilson * Make sure the allocatable size hasn't shrunk.
573ca77e53dd31dcaebef023e7eb41969e6896c1George Wilson vdev_set_state(vd, B_TRUE, VDEV_STATE_CANT_OPEN,
fa9e4066f08beec538e775443c5be79dd423fcabahrens * This is the first-ever open, so use the computed values.
ecc2d604e885a75cc75e647b5641af99d5a6f4a6bonwick * For testing purposes, a higher ashift can be requested.
2384d9f8fcca0a7ef8b3ae674d94df82832c0fceGeorge Wilson * Detect if the alignment requirement has increased.
2384d9f8fcca0a7ef8b3ae674d94df82832c0fceGeorge Wilson * We don't want to make the pool unavailable, just
2384d9f8fcca0a7ef8b3ae674d94df82832c0fceGeorge Wilson * issue a warning instead.
2384d9f8fcca0a7ef8b3ae674d94df82832c0fceGeorge Wilson "Disk, '%s', has a block alignment that is "
2384d9f8fcca0a7ef8b3ae674d94df82832c0fceGeorge Wilson "larger than the pool's alignment\n",
573ca77e53dd31dcaebef023e7eb41969e6896c1George Wilson * If all children are healthy and the asize has increased,
573ca77e53dd31dcaebef023e7eb41969e6896c1George Wilson * then we've experienced dynamic LUN growth. If automatic
573ca77e53dd31dcaebef023e7eb41969e6896c1George Wilson * expansion is enabled then use the additional space.
573ca77e53dd31dcaebef023e7eb41969e6896c1George Wilson if (vd->vdev_state == VDEV_STATE_HEALTHY && asize > vd->vdev_asize &&
0a4e9518a44f226be6d39383330b5b1792d2f184gw * Ensure we can issue some IO before declaring the
0a4e9518a44f226be6d39383330b5b1792d2f184gw * vdev open for business.
e14bb3258d05c1b1077e2db7cf77088924e56919Jeff Bonwick (error = zio_wait(vdev_probe(vd, NULL))) != 0) {
98d1cbfec254295273b6a761bc1861c0374bdf02George Wilson vdev_set_state(vd, B_TRUE, VDEV_STATE_FAULTED,
81cd5c555f505484180a62ca5a2fbb00d70c57d6Matthew Ahrens * Track the min and max ashift values for normal data devices.
81cd5c555f505484180a62ca5a2fbb00d70c57d6Matthew Ahrens if (vd->vdev_top == vd && vd->vdev_ashift != 0 &&
088f389458728c464569a5506b58070254fa4f7dahrens * If a leaf vdev has a DTL, and seems healthy, then kick off a
8ad4d6dd86f5bc65fb3afa566c8133f3bac21648Jeff Bonwick * resilver. But don't do this if we are doing a reopen for a scrub,
8ad4d6dd86f5bc65fb3afa566c8133f3bac21648Jeff Bonwick * since this would just restart the scrub we are already doing.
8ad4d6dd86f5bc65fb3afa566c8133f3bac21648Jeff Bonwick if (vd->vdev_ops->vdev_op_leaf && !spa->spa_scrub_reopen &&
fa9e4066f08beec538e775443c5be79dd423fcabahrens return (0);
560e6e964ab70b838deafc93f6d9da97f690ec25eschrock * Called once the vdevs are all opened, this routine validates the label
560e6e964ab70b838deafc93f6d9da97f690ec25eschrock * contents. This needs to be done before vdev_load() so that we don't
3d7072f8bd27709dba14f6fe336f149d25d9e207eschrock * inadvertently do repair I/Os to the wrong device.
d7f601ef8b0a2967964481b924713899dcc045bbGeorge Wilson * If 'strict' is false ignore the spa guid check. This is necessary because
d7f601ef8b0a2967964481b924713899dcc045bbGeorge Wilson * if the machine crashed during a re-guid the new guid might have been written
d7f601ef8b0a2967964481b924713899dcc045bbGeorge Wilson * to all of the vdev labels, but not the cached config. The strict check
d7f601ef8b0a2967964481b924713899dcc045bbGeorge Wilson * will be performed when the pool is opened again using the mos config.
560e6e964ab70b838deafc93f6d9da97f690ec25eschrock * This function will only return failure if one of the vdevs indicates that it
560e6e964ab70b838deafc93f6d9da97f690ec25eschrock * has since been destroyed or exported. This is only possible if
560e6e964ab70b838deafc93f6d9da97f690ec25eschrock * /etc/zfs/zpool.cache was readonly at the time. Otherwise, the vdev state
560e6e964ab70b838deafc93f6d9da97f690ec25eschrock * will be updated but the function will return 0.
d7f601ef8b0a2967964481b924713899dcc045bbGeorge Wilson if (vdev_validate(vd->vdev_child[c], strict) != 0)
b5989ec7cd031c9bb066c68877fb5017e45f205beschrock * If the device has already failed, or was marked offline, don't do
b5989ec7cd031c9bb066c68877fb5017e45f205beschrock * any further validation. Otherwise, label I/O will fail and we will
b5989ec7cd031c9bb066c68877fb5017e45f205beschrock * overwrite the previous state.
e14bb3258d05c1b1077e2db7cf77088924e56919Jeff Bonwick if (vd->vdev_ops->vdev_op_leaf && vdev_readable(vd)) {
bda8819455defbccd06981d9a13b240b682a3d50George Wilson uint64_t txg = spa_last_synced_txg(spa) != 0 ?
dfbb943217bf8ab22a1a9d2e9dca01d4da95ee0bGeorge Wilson if ((label = vdev_label_read_config(vd, txg)) == NULL) {
560e6e964ab70b838deafc93f6d9da97f690ec25eschrock return (0);
1195e687f1c03c8d57417b5999578922e20a3554Mark J Musante * Determine if this vdev has been split off into another
1195e687f1c03c8d57417b5999578922e20a3554Mark J Musante * pool. If so, then refuse to open it.
1195e687f1c03c8d57417b5999578922e20a3554Mark J Musante if (nvlist_lookup_uint64(label, ZPOOL_CONFIG_SPLIT_GUID,
1195e687f1c03c8d57417b5999578922e20a3554Mark J Musante &aux_guid) == 0 && aux_guid == spa_guid(spa)) {
1195e687f1c03c8d57417b5999578922e20a3554Mark J Musante vdev_set_state(vd, B_FALSE, VDEV_STATE_CANT_OPEN,
560e6e964ab70b838deafc93f6d9da97f690ec25eschrock return (0);
1195e687f1c03c8d57417b5999578922e20a3554Mark J Musante if (nvlist_lookup_nvlist(label, ZPOOL_CONFIG_VDEV_TREE, &nvl)
1195e687f1c03c8d57417b5999578922e20a3554Mark J Musante != 0 || nvlist_lookup_uint64(nvl, ZPOOL_CONFIG_ORIG_GUID,
e14bb3258d05c1b1077e2db7cf77088924e56919Jeff Bonwick * If this vdev just became a top-level vdev because its
e14bb3258d05c1b1077e2db7cf77088924e56919Jeff Bonwick * sibling was detached, it will have adopted the parent's
e14bb3258d05c1b1077e2db7cf77088924e56919Jeff Bonwick * vdev guid -- but the label may or may not be on disk yet.
e14bb3258d05c1b1077e2db7cf77088924e56919Jeff Bonwick * Fortunately, either version of the label will have the
e14bb3258d05c1b1077e2db7cf77088924e56919Jeff Bonwick * same top guid, so if we're a top-level vdev, we can
e14bb3258d05c1b1077e2db7cf77088924e56919Jeff Bonwick * safely compare to that instead.
1195e687f1c03c8d57417b5999578922e20a3554Mark J Musante * If we split this vdev off instead, then we also check the
1195e687f1c03c8d57417b5999578922e20a3554Mark J Musante * original pool's guid. We don't want to consider the vdev
1195e687f1c03c8d57417b5999578922e20a3554Mark J Musante * corrupt if it is partway through a split operation.
e14bb3258d05c1b1077e2db7cf77088924e56919Jeff Bonwick nvlist_lookup_uint64(label, ZPOOL_CONFIG_TOP_GUID,
1195e687f1c03c8d57417b5999578922e20a3554Mark J Musante ((vd->vdev_guid != guid && vd->vdev_guid != aux_guid) &&
e14bb3258d05c1b1077e2db7cf77088924e56919Jeff Bonwick (vd->vdev_guid != top_guid || vd != vd->vdev_top))) {
560e6e964ab70b838deafc93f6d9da97f690ec25eschrock return (0);
560e6e964ab70b838deafc93f6d9da97f690ec25eschrock if (nvlist_lookup_uint64(label, ZPOOL_CONFIG_POOL_STATE,
560e6e964ab70b838deafc93f6d9da97f690ec25eschrock return (0);
4b964ada391d44b89d97e7e930e6a9a136e0a2f4George Wilson * If this is a verbatim import, no need to check the
bc758434fd3df659cb5caf3de6b1e90d9b23ee79Lin Ling * state of the pool.
4b964ada391d44b89d97e7e930e6a9a136e0a2f4George Wilson if (!(spa->spa_import_flags & ZFS_IMPORT_VERBATIM) &&
51ece83525fa18f5e72627610f480dffc7e492fdeschrock * If we were able to open and validate a vdev that was
51ece83525fa18f5e72627610f480dffc7e492fdeschrock * previously marked permanently unavailable, clear that state
560e6e964ab70b838deafc93f6d9da97f690ec25eschrock return (0);
fa9e4066f08beec538e775443c5be79dd423fcabahrens * Close a virtual device.
8ad4d6dd86f5bc65fb3afa566c8133f3bac21648Jeff Bonwick ASSERT(spa_config_held(spa, SCL_STATE_ALL, RW_WRITER) == SCL_STATE_ALL);
1195e687f1c03c8d57417b5999578922e20a3554Mark J Musante * If our parent is reopening, then we are as well, unless we are
1195e687f1c03c8d57417b5999578922e20a3554Mark J Musante * going offline.
1195e687f1c03c8d57417b5999578922e20a3554Mark J Musante vd->vdev_reopening = (pvd->vdev_reopening && !vd->vdev_offline);
573ca77e53dd31dcaebef023e7eb41969e6896c1George Wilson * We record the previous state before we close it, so that if we are
560e6e964ab70b838deafc93f6d9da97f690ec25eschrock * doing a reopen(), we don't generate FMA ereports if we notice that
560e6e964ab70b838deafc93f6d9da97f690ec25eschrock * it's still faulted.
dcba9f3fbefe06ad19972b4de0351924601e5767George Wilson if (spa->spa_state == POOL_STATE_UNINITIALIZED)
095bcd6622e3b3520eb3b71039a3be5cfab25b74George Wilson * Reopen all interior vdevs and any unopened leaves. We don't actually
095bcd6622e3b3520eb3b71039a3be5cfab25b74George Wilson * reopen leaf vdevs which had previously been opened as they might deadlock
095bcd6622e3b3520eb3b71039a3be5cfab25b74George Wilson * on the spa_config_lock. Instead we only obtain the leaf's physical size.
095bcd6622e3b3520eb3b71039a3be5cfab25b74George Wilson * If the leaf has never been opened then open it, as usual.
e14bb3258d05c1b1077e2db7cf77088924e56919Jeff Bonwick ASSERT(spa_config_held(spa, SCL_STATE_ALL, RW_WRITER) == SCL_STATE_ALL);
1195e687f1c03c8d57417b5999578922e20a3554Mark J Musante /* set the reopening flag unless we're taking the vdev offline */
39c23413b8df94a95f67b34cfd4a4dfc3fd0b48deschrock * Call vdev_validate() here to make sure we have the same device.
39c23413b8df94a95f67b34cfd4a4dfc3fd0b48deschrock * Otherwise, a device with an invalid label could be successfully
39c23413b8df94a95f67b34cfd4a4dfc3fd0b48deschrock * opened in response to vdev_reopen().
3d7072f8bd27709dba14f6fe336f149d25d9e207eschrock * Reassess parent vdev's health.
99653d4ee642c6528e88224f12409a5f23060994eschrockvdev_create(vdev_t *vd, uint64_t txg, boolean_t isreplacing)
fa9e4066f08beec538e775443c5be79dd423fcabahrens * Normally, partial opens (e.g. of a mirror) are allowed.
fa9e4066f08beec538e775443c5be79dd423fcabahrens * For a create, however, we want to fail the request if
fa9e4066f08beec538e775443c5be79dd423fcabahrens * there are any components we can't open.
0713e232b7712cd27d99e1e935ebb8d5de61c57dGeorge Wilson * Recursively load DTLs and initialize all labels.
0713e232b7712cd27d99e1e935ebb8d5de61c57dGeorge Wilson (error = vdev_label_init(vd, txg, isreplacing ?
fa9e4066f08beec538e775443c5be79dd423fcabahrens return (0);
bf3e216c7efa56332b456f4cf19d208e21d63839Matthew Ahrens * Aim for roughly metaslabs_per_vdev (default 200) metaslabs per vdev.
bf3e216c7efa56332b456f4cf19d208e21d63839Matthew Ahrens vd->vdev_ms_shift = highbit64(vd->vdev_asize / metaslabs_per_vdev);
fa9e4066f08beec538e775443c5be79dd423fcabahrens vd->vdev_ms_shift = MAX(vd->vdev_ms_shift, SPA_MAXBLOCKSHIFT);
ecc2d604e885a75cc75e647b5641af99d5a6f4a6bonwickvdev_dirty(vdev_t *vd, int flags, void *arg, uint64_t txg)
ecc2d604e885a75cc75e647b5641af99d5a6f4a6bonwick (void) txg_list_add(&vd->vdev_spa->spa_vdev_txg_list, vd, txg);
0713e232b7712cd27d99e1e935ebb8d5de61c57dGeorge Wilsonvdev_dirty_leaves(vdev_t *vd, int flags, uint64_t txg)
0713e232b7712cd27d99e1e935ebb8d5de61c57dGeorge Wilson vdev_dirty_leaves(vd->vdev_child[c], flags, txg);
8ad4d6dd86f5bc65fb3afa566c8133f3bac21648Jeff Bonwick * A vdev's DTL (dirty time log) is the set of transaction groups for which
9fb35deba8248caea6ddae3a5c4c2952283f8603Eric Taylor * the vdev has less than perfect replication. There are four kinds of DTL:
8ad4d6dd86f5bc65fb3afa566c8133f3bac21648Jeff Bonwick * DTL_MISSING: txgs for which the vdev has no valid copies of the data
8ad4d6dd86f5bc65fb3afa566c8133f3bac21648Jeff Bonwick * DTL_PARTIAL: txgs for which data is available, but not fully replicated
8ad4d6dd86f5bc65fb3afa566c8133f3bac21648Jeff Bonwick * DTL_SCRUB: the txgs that could not be repaired by the last scrub; upon
8ad4d6dd86f5bc65fb3afa566c8133f3bac21648Jeff Bonwick * scrub completion, DTL_SCRUB replaces DTL_MISSING in the range of
8ad4d6dd86f5bc65fb3afa566c8133f3bac21648Jeff Bonwick * txgs that was scrubbed.
8ad4d6dd86f5bc65fb3afa566c8133f3bac21648Jeff Bonwick * DTL_OUTAGE: txgs which cannot currently be read, whether due to
8ad4d6dd86f5bc65fb3afa566c8133f3bac21648Jeff Bonwick * persistent errors or just some device being offline.
8ad4d6dd86f5bc65fb3afa566c8133f3bac21648Jeff Bonwick * Unlike the other three, the DTL_OUTAGE map is not generally
8ad4d6dd86f5bc65fb3afa566c8133f3bac21648Jeff Bonwick * maintained; it's only computed when needed, typically to
8ad4d6dd86f5bc65fb3afa566c8133f3bac21648Jeff Bonwick * determine whether a device can be detached.
8ad4d6dd86f5bc65fb3afa566c8133f3bac21648Jeff Bonwick * For leaf vdevs, DTL_MISSING and DTL_PARTIAL are identical: the device
8ad4d6dd86f5bc65fb3afa566c8133f3bac21648Jeff Bonwick * either has the data or it doesn't.
8ad4d6dd86f5bc65fb3afa566c8133f3bac21648Jeff Bonwick * For interior vdevs such as mirror and RAID-Z the picture is more complex.
8ad4d6dd86f5bc65fb3afa566c8133f3bac21648Jeff Bonwick * A vdev's DTL_PARTIAL is the union of its children's DTL_PARTIALs, because
8ad4d6dd86f5bc65fb3afa566c8133f3bac21648Jeff Bonwick * if any child is less than fully replicated, then so is its parent.
8ad4d6dd86f5bc65fb3afa566c8133f3bac21648Jeff Bonwick * A vdev's DTL_MISSING is a modified union of its children's DTL_MISSINGs,
8ad4d6dd86f5bc65fb3afa566c8133f3bac21648Jeff Bonwick * comprising only those txgs which appear in 'maxfaults' or more children;
8ad4d6dd86f5bc65fb3afa566c8133f3bac21648Jeff Bonwick * those are the txgs we don't have enough replication to read. For example,
8ad4d6dd86f5bc65fb3afa566c8133f3bac21648Jeff Bonwick * double-parity RAID-Z can tolerate up to two missing devices (maxfaults == 2);
8ad4d6dd86f5bc65fb3afa566c8133f3bac21648Jeff Bonwick * thus, its DTL_MISSING consists of the set of txgs that appear in more than
8ad4d6dd86f5bc65fb3afa566c8133f3bac21648Jeff Bonwick * two child DTL_MISSING maps.
8ad4d6dd86f5bc65fb3afa566c8133f3bac21648Jeff Bonwick * It should be clear from the above that to compute the DTLs and outage maps
8ad4d6dd86f5bc65fb3afa566c8133f3bac21648Jeff Bonwick * for all vdevs, it suffices to know just the leaf vdevs' DTL_MISSING maps.
8ad4d6dd86f5bc65fb3afa566c8133f3bac21648Jeff Bonwick * Therefore, that is all we keep on disk. When loading the pool, or after
8ad4d6dd86f5bc65fb3afa566c8133f3bac21648Jeff Bonwick * a configuration change, we generate all other DTLs from first principles.
8ad4d6dd86f5bc65fb3afa566c8133f3bac21648Jeff Bonwickvdev_dtl_dirty(vdev_t *vd, vdev_dtl_type_t t, uint64_t txg, uint64_t size)
8ad4d6dd86f5bc65fb3afa566c8133f3bac21648Jeff Bonwickvdev_dtl_contains(vdev_t *vd, vdev_dtl_type_t t, uint64_t txg, uint64_t size)
b4952e17e8858d3225793b28788278de9fe6038dGeorge Wilson * Returns the lowest txg in the DTL range.
0713e232b7712cd27d99e1e935ebb8d5de61c57dGeorge Wilson ASSERT3U(range_tree_space(vd->vdev_dtl[DTL_MISSING]), !=, 0);
0713e232b7712cd27d99e1e935ebb8d5de61c57dGeorge Wilson rs = avl_first(&vd->vdev_dtl[DTL_MISSING]->rt_root);
b4952e17e8858d3225793b28788278de9fe6038dGeorge Wilson * Returns the highest txg in the DTL.
0713e232b7712cd27d99e1e935ebb8d5de61c57dGeorge Wilson ASSERT3U(range_tree_space(vd->vdev_dtl[DTL_MISSING]), !=, 0);
0713e232b7712cd27d99e1e935ebb8d5de61c57dGeorge Wilson rs = avl_last(&vd->vdev_dtl[DTL_MISSING]->rt_root);
b4952e17e8858d3225793b28788278de9fe6038dGeorge Wilson * Determine if a resilvering vdev should remove any DTL entries from
b4952e17e8858d3225793b28788278de9fe6038dGeorge Wilson * its range. If the vdev was resilvering for the entire duration of the
b4952e17e8858d3225793b28788278de9fe6038dGeorge Wilson * scan then it should excise that range from its DTLs. Otherwise, this
b4952e17e8858d3225793b28788278de9fe6038dGeorge Wilson * vdev is considered partially resilvered and should leave its DTL
b4952e17e8858d3225793b28788278de9fe6038dGeorge Wilson * entries intact. The comment in vdev_dtl_reassess() describes how we
b4952e17e8858d3225793b28788278de9fe6038dGeorge Wilson * excise the DTLs.
0713e232b7712cd27d99e1e935ebb8d5de61c57dGeorge Wilson range_tree_space(vd->vdev_dtl[DTL_MISSING]) == 0)
b4952e17e8858d3225793b28788278de9fe6038dGeorge Wilson * When a resilver is initiated the scan will assign the scn_max_txg
b4952e17e8858d3225793b28788278de9fe6038dGeorge Wilson * value to the highest txg value that exists in all DTLs. If this
b4952e17e8858d3225793b28788278de9fe6038dGeorge Wilson * device's max DTL is not part of this scan (i.e. it is not in
b4952e17e8858d3225793b28788278de9fe6038dGeorge Wilson * the range (scn_min_txg, scn_max_txg] then it is not eligible
b4952e17e8858d3225793b28788278de9fe6038dGeorge Wilson * for excision.
b4952e17e8858d3225793b28788278de9fe6038dGeorge Wilson if (vdev_dtl_max(vd) <= scn->scn_phys.scn_max_txg) {
b4952e17e8858d3225793b28788278de9fe6038dGeorge Wilson ASSERT3U(scn->scn_phys.scn_min_txg, <=, vdev_dtl_min(vd));
b4952e17e8858d3225793b28788278de9fe6038dGeorge Wilson ASSERT3U(scn->scn_phys.scn_min_txg, <, vd->vdev_resilver_txg);
b4952e17e8858d3225793b28788278de9fe6038dGeorge Wilson ASSERT3U(vd->vdev_resilver_txg, <=, scn->scn_phys.scn_max_txg);
fa9e4066f08beec538e775443c5be79dd423fcabahrens * Reassess DTLs after a config change or scrub completion.
fa9e4066f08beec538e775443c5be79dd423fcabahrensvdev_dtl_reassess(vdev_t *vd, uint64_t txg, uint64_t scrub_txg, int scrub_done)
8ad4d6dd86f5bc65fb3afa566c8133f3bac21648Jeff Bonwick ASSERT(spa_config_held(spa, SCL_ALL, RW_READER) != 0);
b24ab6762772a3f6a89393947930c7fa61306783Jeff Bonwick if (vd == spa->spa_root_vdev || vd->vdev_ishole || vd->vdev_aux)
b4952e17e8858d3225793b28788278de9fe6038dGeorge Wilson * If we've completed a scan cleanly then determine
b4952e17e8858d3225793b28788278de9fe6038dGeorge Wilson * if this vdev should remove any DTLs. We only want to
b4952e17e8858d3225793b28788278de9fe6038dGeorge Wilson * excise regions on vdevs that were available during
b4952e17e8858d3225793b28788278de9fe6038dGeorge Wilson * the entire duration of this scan.
b4952e17e8858d3225793b28788278de9fe6038dGeorge Wilson (scn != NULL && scn->scn_phys.scn_errors == 0)) &&
088f389458728c464569a5506b58070254fa4f7dahrens * We completed a scrub up to scrub_txg. If we
088f389458728c464569a5506b58070254fa4f7dahrens * did it without rebooting, then the scrub dtl
088f389458728c464569a5506b58070254fa4f7dahrens * will be valid, so excise the old region and
088f389458728c464569a5506b58070254fa4f7dahrens * fold in the scrub dtl. Otherwise, leave the
088f389458728c464569a5506b58070254fa4f7dahrens * dtl as-is if there was an error.
8ad4d6dd86f5bc65fb3afa566c8133f3bac21648Jeff Bonwick * There's little trick here: to excise the beginning
8ad4d6dd86f5bc65fb3afa566c8133f3bac21648Jeff Bonwick * of the DTL_MISSING map, we put it into a reference
8ad4d6dd86f5bc65fb3afa566c8133f3bac21648Jeff Bonwick * tree and then add a segment with refcnt -1 that
8ad4d6dd86f5bc65fb3afa566c8133f3bac21648Jeff Bonwick * covers the range [0, scrub_txg). This means
8ad4d6dd86f5bc65fb3afa566c8133f3bac21648Jeff Bonwick * that each txg in that range has refcnt -1 or 0.
8ad4d6dd86f5bc65fb3afa566c8133f3bac21648Jeff Bonwick * We then add DTL_SCRUB with a refcnt of 2, so that
8ad4d6dd86f5bc65fb3afa566c8133f3bac21648Jeff Bonwick * entries in the range [0, scrub_txg) will have a
8ad4d6dd86f5bc65fb3afa566c8133f3bac21648Jeff Bonwick * positive refcnt -- either 1 or 2. We then convert
8ad4d6dd86f5bc65fb3afa566c8133f3bac21648Jeff Bonwick * the reference tree into the new DTL_MISSING map.
0713e232b7712cd27d99e1e935ebb8d5de61c57dGeorge Wilson space_reftree_add_seg(&reftree, 0, scrub_txg, -1);
0713e232b7712cd27d99e1e935ebb8d5de61c57dGeorge Wilson range_tree_vacate(vd->vdev_dtl[DTL_PARTIAL], NULL, NULL);
0713e232b7712cd27d99e1e935ebb8d5de61c57dGeorge Wilson range_tree_vacate(vd->vdev_dtl[DTL_SCRUB], NULL, NULL);
0713e232b7712cd27d99e1e935ebb8d5de61c57dGeorge Wilson range_tree_vacate(vd->vdev_dtl[DTL_OUTAGE], NULL, NULL);
0713e232b7712cd27d99e1e935ebb8d5de61c57dGeorge Wilson range_tree_add(vd->vdev_dtl[DTL_OUTAGE], 0, -1ULL);
b4952e17e8858d3225793b28788278de9fe6038dGeorge Wilson * If the vdev was resilvering and no longer has any
b4952e17e8858d3225793b28788278de9fe6038dGeorge Wilson * DTLs then reset its resilvering flag.
0713e232b7712cd27d99e1e935ebb8d5de61c57dGeorge Wilson range_tree_space(vd->vdev_dtl[DTL_MISSING]) == 0 &&
0713e232b7712cd27d99e1e935ebb8d5de61c57dGeorge Wilson range_tree_space(vd->vdev_dtl[DTL_OUTAGE]) == 0)
8ad4d6dd86f5bc65fb3afa566c8133f3bac21648Jeff Bonwick for (int t = 0; t < DTL_TYPES; t++) {
99bb17e292915cc12ff98869907cfba546aafdf3Eric Taylor /* account for child's outage in parent's missing map */
8ad4d6dd86f5bc65fb3afa566c8133f3bac21648Jeff Bonwick continue; /* leaf vdevs only */
8ad4d6dd86f5bc65fb3afa566c8133f3bac21648Jeff Bonwick minref = vd->vdev_children; /* any kind of mirror */
0713e232b7712cd27d99e1e935ebb8d5de61c57dGeorge Wilson space_reftree_add_map(&reftree, cvd->vdev_dtl[s], 1);
0713e232b7712cd27d99e1e935ebb8d5de61c57dGeorge Wilson space_reftree_generate_map(&reftree, vd->vdev_dtl[t], minref);
0713e232b7712cd27d99e1e935ebb8d5de61c57dGeorge Wilson if (vd->vdev_ops->vdev_op_leaf && vd->vdev_dtl_object != 0) {
0713e232b7712cd27d99e1e935ebb8d5de61c57dGeorge Wilson vd->vdev_dtl_object, 0, -1ULL, 0, &vd->vdev_dtl_lock);
0713e232b7712cd27d99e1e935ebb8d5de61c57dGeorge Wilson * Now that we've opened the space_map we need to update
0713e232b7712cd27d99e1e935ebb8d5de61c57dGeorge Wilson * the in-core DTL.
215198a6ad15cf4832370e2f19247abeb36b951aJoe Steinvdev_destroy_unlink_zap(vdev_t *vd, uint64_t zapobj, dmu_tx_t *tx)
215198a6ad15cf4832370e2f19247abeb36b951aJoe Stein VERIFY0(zap_destroy(spa->spa_meta_objset, zapobj, tx));
215198a6ad15cf4832370e2f19247abeb36b951aJoe Stein VERIFY0(zap_remove_int(spa->spa_meta_objset, spa->spa_all_vdev_zaps,
215198a6ad15cf4832370e2f19247abeb36b951aJoe Stein uint64_t zap = zap_create(spa->spa_meta_objset, DMU_OTN_ZAP_METADATA,
215198a6ad15cf4832370e2f19247abeb36b951aJoe Stein VERIFY0(zap_add_int(spa->spa_meta_objset, spa->spa_all_vdev_zaps,
215198a6ad15cf4832370e2f19247abeb36b951aJoe Stein if (vd->vdev_ops->vdev_op_leaf && vd->vdev_leaf_zap == 0) {
215198a6ad15cf4832370e2f19247abeb36b951aJoe Stein if (vd == vd->vdev_top && vd->vdev_top_zap == 0) {
215198a6ad15cf4832370e2f19247abeb36b951aJoe Stein for (uint64_t i = 0; i < vd->vdev_children; i++) {
0713e232b7712cd27d99e1e935ebb8d5de61c57dGeorge Wilson uint64_t object = space_map_object(vd->vdev_dtl_sm);
0713e232b7712cd27d99e1e935ebb8d5de61c57dGeorge Wilson if (vd->vdev_detached || vd->vdev_top->vdev_removing) {
215198a6ad15cf4832370e2f19247abeb36b951aJoe Stein * We only destroy the leaf ZAP for detached leaves or for
215198a6ad15cf4832370e2f19247abeb36b951aJoe Stein * removed log devices. Removed data devices handle leaf ZAP
215198a6ad15cf4832370e2f19247abeb36b951aJoe Stein * cleanup later, once cancellation is no longer possible.
215198a6ad15cf4832370e2f19247abeb36b951aJoe Stein if (vd->vdev_leaf_zap != 0 && (vd->vdev_detached ||
215198a6ad15cf4832370e2f19247abeb36b951aJoe Stein vdev_destroy_unlink_zap(vd, vd->vdev_leaf_zap, tx);
0713e232b7712cd27d99e1e935ebb8d5de61c57dGeorge Wilson VERIFY0(space_map_open(&vd->vdev_dtl_sm, mos, new_object,
0713e232b7712cd27d99e1e935ebb8d5de61c57dGeorge Wilson mutex_init(&rtlock, NULL, MUTEX_DEFAULT, NULL);
0713e232b7712cd27d99e1e935ebb8d5de61c57dGeorge Wilson rtsync = range_tree_create(NULL, NULL, &rtlock);
0713e232b7712cd27d99e1e935ebb8d5de61c57dGeorge Wilson space_map_write(vd->vdev_dtl_sm, rtsync, SM_ALLOC, tx);
0713e232b7712cd27d99e1e935ebb8d5de61c57dGeorge Wilson * If the object for the space map has changed then dirty
0713e232b7712cd27d99e1e935ebb8d5de61c57dGeorge Wilson * the top level so that we update the config.
0713e232b7712cd27d99e1e935ebb8d5de61c57dGeorge Wilson if (object != space_map_object(vd->vdev_dtl_sm)) {
0713e232b7712cd27d99e1e935ebb8d5de61c57dGeorge Wilson zfs_dbgmsg("txg %llu, spa %s, DTL old object %llu, "
0713e232b7712cd27d99e1e935ebb8d5de61c57dGeorge Wilson "new object %llu", txg, spa_name(spa), object,
8ad4d6dd86f5bc65fb3afa566c8133f3bac21648Jeff Bonwick * Determine whether the specified vdev can be offlined/detached/removed
8ad4d6dd86f5bc65fb3afa566c8133f3bac21648Jeff Bonwick * without losing data.
8ad4d6dd86f5bc65fb3afa566c8133f3bac21648Jeff Bonwick ASSERT(spa_config_held(spa, SCL_STATE_ALL, RW_WRITER) == SCL_STATE_ALL);
8ad4d6dd86f5bc65fb3afa566c8133f3bac21648Jeff Bonwick * Temporarily mark the device as unreadable, and then determine
8ad4d6dd86f5bc65fb3afa566c8133f3bac21648Jeff Bonwick * whether this results in any DTL outages in the top-level vdev.
8ad4d6dd86f5bc65fb3afa566c8133f3bac21648Jeff Bonwick * If not, we can safely offline/detach/remove the device.
cb04b8739c50e3e6d12e89b790fa7b8d0d899865Mark J Musante required = !!zio_handle_device_injection(vd, NULL, ECHILD);
088f389458728c464569a5506b58070254fa4f7dahrens * Determine if resilver is needed, and if so the txg range.
088f389458728c464569a5506b58070254fa4f7dahrensvdev_resilver_needed(vdev_t *vd, uint64_t *minp, uint64_t *maxp)
0713e232b7712cd27d99e1e935ebb8d5de61c57dGeorge Wilson if (range_tree_space(vd->vdev_dtl[DTL_MISSING]) != 0 &&
fa9e4066f08beec538e775443c5be79dd423fcabahrens * Recursively load all children.
0e34b6a7bff4918432f0aa6b1dfaf73ac9df45b1bonwick * If this is a top-level vdev, initialize its metaslabs.
fa9e4066f08beec538e775443c5be79dd423fcabahrens * If this is a leaf vdev, load its DTL.
560e6e964ab70b838deafc93f6d9da97f690ec25eschrock if (vd->vdev_ops->vdev_op_leaf && vdev_dtl_load(vd) != 0)
fa94a07fd0519b8abfd871ad8fe60e6bebe1e2bbbrendan * The special vdev case is used for hot spares and l2cache devices. Its
fa94a07fd0519b8abfd871ad8fe60e6bebe1e2bbbrendan * sole purpose it to set the vdev state for the associated vdev. To do this,
fa94a07fd0519b8abfd871ad8fe60e6bebe1e2bbbrendan * we make sure that we can open the underlying device, then try to read the
fa94a07fd0519b8abfd871ad8fe60e6bebe1e2bbbrendan * label, and make sure that the label is sane and that it hasn't been
fa94a07fd0519b8abfd871ad8fe60e6bebe1e2bbbrendan * repurposed to another pool.
c5904d138f3bdf0762dbf452a43d5a5c387ea6a8eschrock return (0);
dfbb943217bf8ab22a1a9d2e9dca01d4da95ee0bGeorge Wilson if ((label = vdev_label_read_config(vd, -1ULL)) == NULL) {
99653d4ee642c6528e88224f12409a5f23060994eschrock return (-1);
99653d4ee642c6528e88224f12409a5f23060994eschrock if (nvlist_lookup_uint64(label, ZPOOL_CONFIG_VERSION, &version) != 0 ||
99653d4ee642c6528e88224f12409a5f23060994eschrock nvlist_lookup_uint64(label, ZPOOL_CONFIG_GUID, &guid) != 0 ||
99653d4ee642c6528e88224f12409a5f23060994eschrock nvlist_lookup_uint64(label, ZPOOL_CONFIG_POOL_STATE, &state) != 0) {
99653d4ee642c6528e88224f12409a5f23060994eschrock return (-1);
99653d4ee642c6528e88224f12409a5f23060994eschrock * We don't actually check the pool state here. If it's in fact in
99653d4ee642c6528e88224f12409a5f23060994eschrock * use by another pool, we update this fact on the fly when requested.
99653d4ee642c6528e88224f12409a5f23060994eschrock return (0);
88ecc943b4eb72f7c4fbbd8435997b85ef171fc3George Wilson tx = dmu_tx_create_assigned(spa_get_dsl(spa), txg);
2e4c998613148111f2fc5371085331ffb39122ffGeorge Wilson metaslab_class_histogram_verify(mg->mg_class);
2e4c998613148111f2fc5371085331ffb39122ffGeorge Wilson * If the metaslab was not loaded when the vdev
2e4c998613148111f2fc5371085331ffb39122ffGeorge Wilson * was removed then the histogram accounting may
2e4c998613148111f2fc5371085331ffb39122ffGeorge Wilson * not be accurate. Update the histogram information
2e4c998613148111f2fc5371085331ffb39122ffGeorge Wilson * here so that we ensure that the metaslab group
2e4c998613148111f2fc5371085331ffb39122ffGeorge Wilson * and metaslab class are up-to-date.
2e4c998613148111f2fc5371085331ffb39122ffGeorge Wilson metaslab_class_histogram_verify(mg->mg_class);
2e4c998613148111f2fc5371085331ffb39122ffGeorge Wilson for (int i = 0; i < RANGE_TREE_HISTOGRAM_SIZE; i++)
88ecc943b4eb72f7c4fbbd8435997b85ef171fc3George Wilson (void) dmu_object_free(mos, vd->vdev_ms_array, tx);
215198a6ad15cf4832370e2f19247abeb36b951aJoe Stein vdev_destroy_unlink_zap(vd, vd->vdev_top_zap, tx);
80eb36f241abf8c076119fb4c49a55fd61ebc710George Wilson boolean_t reassess = !txg_list_empty(&vd->vdev_ms_list, TXG_CLEAN(txg));
fa9e4066f08beec538e775443c5be79dd423fcabahrens while (msp = txg_list_remove(&vd->vdev_ms_list, TXG_CLEAN(txg)))
ecc2d604e885a75cc75e647b5641af99d5a6f4a6bonwick if (vd->vdev_ms_array == 0 && vd->vdev_ms_shift != 0) {
ecc2d604e885a75cc75e647b5641af99d5a6f4a6bonwick tx = dmu_tx_create_assigned(spa->spa_dsl_pool, txg);
ecc2d604e885a75cc75e647b5641af99d5a6f4a6bonwick vd->vdev_ms_array = dmu_object_alloc(spa->spa_meta_objset,
3f9d6ad73e45c6823b409f93b0c8d4f62861d2d5Lin Ling * Remove the metadata associated with this vdev once it's empty.
3f9d6ad73e45c6823b409f93b0c8d4f62861d2d5Lin Ling if (vd->vdev_stat.vs_alloc == 0 && vd->vdev_removing)
ecc2d604e885a75cc75e647b5641af99d5a6f4a6bonwick while ((msp = txg_list_remove(&vd->vdev_ms_list, txg)) != NULL) {
ecc2d604e885a75cc75e647b5641af99d5a6f4a6bonwick (void) txg_list_add(&vd->vdev_ms_list, msp, TXG_CLEAN(txg));
fa9e4066f08beec538e775443c5be79dd423fcabahrens while ((lvd = txg_list_remove(&vd->vdev_dtl_list, txg)) != NULL)
fa9e4066f08beec538e775443c5be79dd423fcabahrens (void) txg_list_add(&spa->spa_vdev_txg_list, vd, TXG_CLEAN(txg));
3d7072f8bd27709dba14f6fe336f149d25d9e207eschrock * Mark the given vdev faulted. A faulted vdev behaves as if the device could
3d7072f8bd27709dba14f6fe336f149d25d9e207eschrock * not be opened, and no I/O is attempted.
069f55e237020c4a4907b235fc38fafc6442ce94Eric Schrockvdev_fault(spa_t *spa, uint64_t guid, vdev_aux_t aux)
c5904d138f3bdf0762dbf452a43d5a5c387ea6a8eschrock if ((vd = spa_lookup_by_guid(spa, guid, B_TRUE)) == NULL)
e14bb3258d05c1b1077e2db7cf77088924e56919Jeff Bonwick return (spa_vdev_state_exit(spa, NULL, ENODEV));
e14bb3258d05c1b1077e2db7cf77088924e56919Jeff Bonwick return (spa_vdev_state_exit(spa, NULL, ENOTSUP));
069f55e237020c4a4907b235fc38fafc6442ce94Eric Schrock * We don't directly use the aux state here, but if we do a
069f55e237020c4a4907b235fc38fafc6442ce94Eric Schrock * vdev_reopen(), we need this value to be present to remember why we
069f55e237020c4a4907b235fc38fafc6442ce94Eric Schrock * were faulted.
3d7072f8bd27709dba14f6fe336f149d25d9e207eschrock * Faulted state takes precedence over degraded.
069f55e237020c4a4907b235fc38fafc6442ce94Eric Schrock vdev_set_state(vd, B_FALSE, VDEV_STATE_FAULTED, aux);
c79790bc7e5ff02b3f37a265abf77a794682b0d0George Wilson * If this device has the only valid copy of the data, then
c79790bc7e5ff02b3f37a265abf77a794682b0d0George Wilson * back off and simply mark the vdev as degraded instead.
4b964ada391d44b89d97e7e930e6a9a136e0a2f4George Wilson if (!tvd->vdev_islog && vd->vdev_aux == NULL && vdev_dtl_required(vd)) {
3d7072f8bd27709dba14f6fe336f149d25d9e207eschrock * If we reopen the device and it's not dead, only then do we
3d7072f8bd27709dba14f6fe336f149d25d9e207eschrock * mark it degraded.
069f55e237020c4a4907b235fc38fafc6442ce94Eric Schrock vdev_set_state(vd, B_FALSE, VDEV_STATE_DEGRADED, aux);
3d7072f8bd27709dba14f6fe336f149d25d9e207eschrock * Mark the given vdev degraded. A degraded vdev is purely an indication to the
3d7072f8bd27709dba14f6fe336f149d25d9e207eschrock * user that something is wrong. The vdev continues to operate as normal as far
3d7072f8bd27709dba14f6fe336f149d25d9e207eschrock * as I/O is concerned.
069f55e237020c4a4907b235fc38fafc6442ce94Eric Schrockvdev_degrade(spa_t *spa, uint64_t guid, vdev_aux_t aux)
c5904d138f3bdf0762dbf452a43d5a5c387ea6a8eschrock if ((vd = spa_lookup_by_guid(spa, guid, B_TRUE)) == NULL)
e14bb3258d05c1b1077e2db7cf77088924e56919Jeff Bonwick return (spa_vdev_state_exit(spa, NULL, ENODEV));
e14bb3258d05c1b1077e2db7cf77088924e56919Jeff Bonwick return (spa_vdev_state_exit(spa, NULL, ENOTSUP));
3d7072f8bd27709dba14f6fe336f149d25d9e207eschrock * If the vdev is already faulted, then don't do anything.
f7170741490edba9d1d9c697c177c887172bc741Will Andrews * Online the given vdev.
f7170741490edba9d1d9c697c177c887172bc741Will Andrews * If 'ZFS_ONLINE_UNSPARE' is set, it implies two things. First, any attached
f7170741490edba9d1d9c697c177c887172bc741Will Andrews * spare device should be detached when the device finishes resilvering.
f7170741490edba9d1d9c697c177c887172bc741Will Andrews * Second, the online should be treated like a 'test' online case, so no FMA
f7170741490edba9d1d9c697c177c887172bc741Will Andrews * events are generated if the device fails to open.
e14bb3258d05c1b1077e2db7cf77088924e56919Jeff Bonwickvdev_online(spa_t *spa, uint64_t guid, uint64_t flags, vdev_state_t *newstate)
573ca77e53dd31dcaebef023e7eb41969e6896c1George Wilson vdev_t *vd, *tvd, *pvd, *rvd = spa->spa_root_vdev;
c5904d138f3bdf0762dbf452a43d5a5c387ea6a8eschrock if ((vd = spa_lookup_by_guid(spa, guid, B_TRUE)) == NULL)
e14bb3258d05c1b1077e2db7cf77088924e56919Jeff Bonwick return (spa_vdev_state_exit(spa, NULL, ENODEV));
e14bb3258d05c1b1077e2db7cf77088924e56919Jeff Bonwick return (spa_vdev_state_exit(spa, NULL, ENOTSUP));
1437283407f89cab03860accf49408f94559bc34Hans Rosenfeld (vd->vdev_offline == B_TRUE || vd->vdev_tmpoffline == B_TRUE) ?
e14bb3258d05c1b1077e2db7cf77088924e56919Jeff Bonwick vd->vdev_checkremove = !!(flags & ZFS_ONLINE_CHECKREMOVE);
e14bb3258d05c1b1077e2db7cf77088924e56919Jeff Bonwick vd->vdev_forcefault = !!(flags & ZFS_ONLINE_FORCEFAULT);
573ca77e53dd31dcaebef023e7eb41969e6896c1George Wilson /* XXX - L2ARC 1.0 does not support expansion */
573ca77e53dd31dcaebef023e7eb41969e6896c1George Wilson for (pvd = vd; pvd != rvd; pvd = pvd->vdev_parent)
573ca77e53dd31dcaebef023e7eb41969e6896c1George Wilson pvd->vdev_expanding = !!(flags & ZFS_ONLINE_EXPAND);
3d7072f8bd27709dba14f6fe336f149d25d9e207eschrock vd->vdev_checkremove = vd->vdev_forcefault = B_FALSE;
573ca77e53dd31dcaebef023e7eb41969e6896c1George Wilson for (pvd = vd; pvd != rvd; pvd = pvd->vdev_parent)
573ca77e53dd31dcaebef023e7eb41969e6896c1George Wilson if ((flags & ZFS_ONLINE_EXPAND) || spa->spa_autoexpand) {
573ca77e53dd31dcaebef023e7eb41969e6896c1George Wilson /* XXX - L2ARC 1.0 does not support expansion */
573ca77e53dd31dcaebef023e7eb41969e6896c1George Wilson return (spa_vdev_state_exit(spa, vd, ENOTSUP));
573ca77e53dd31dcaebef023e7eb41969e6896c1George Wilson spa_async_request(spa, SPA_ASYNC_CONFIG_UPDATE);
1437283407f89cab03860accf49408f94559bc34Hans Rosenfeld spa_event_notify(spa, vd, ESC_ZFS_VDEV_ONLINE);
a15215608b8bd90f714f6db21ee623b584607cb6Jeff Bonwickvdev_offline_locked(spa_t *spa, uint64_t guid, uint64_t flags)
c5904d138f3bdf0762dbf452a43d5a5c387ea6a8eschrock if ((vd = spa_lookup_by_guid(spa, guid, B_TRUE)) == NULL)
e14bb3258d05c1b1077e2db7cf77088924e56919Jeff Bonwick return (spa_vdev_state_exit(spa, NULL, ENODEV));
e14bb3258d05c1b1077e2db7cf77088924e56919Jeff Bonwick return (spa_vdev_state_exit(spa, NULL, ENOTSUP));
ecc2d604e885a75cc75e647b5641af99d5a6f4a6bonwick * If the device isn't already offline, try to offline it.
8ad4d6dd86f5bc65fb3afa566c8133f3bac21648Jeff Bonwick * If this device has the only valid copy of some data,
e6ca193ded880d478cc39e34ef82d4be36e4445dGeorge Wilson * don't allow it to be offlined. Log devices are always
e6ca193ded880d478cc39e34ef82d4be36e4445dGeorge Wilson * expendable.
e6ca193ded880d478cc39e34ef82d4be36e4445dGeorge Wilson if (!tvd->vdev_islog && vd->vdev_aux == NULL &&
e14bb3258d05c1b1077e2db7cf77088924e56919Jeff Bonwick return (spa_vdev_state_exit(spa, NULL, EBUSY));
b24ab6762772a3f6a89393947930c7fa61306783Jeff Bonwick * If the top-level is a slog and it has had allocations
b24ab6762772a3f6a89393947930c7fa61306783Jeff Bonwick * then proceed. We check that the vdev's metaslab group
b24ab6762772a3f6a89393947930c7fa61306783Jeff Bonwick * is not NULL since it's possible that we may have just
b24ab6762772a3f6a89393947930c7fa61306783Jeff Bonwick * added this vdev but not yet initialized its metaslabs.
8f18d1fadf6a0c20fac9ff7259a5368faa3c3bfbGeorge Wilson * Prevent any future allocations.
8f18d1fadf6a0c20fac9ff7259a5368faa3c3bfbGeorge Wilson * Check to see if the config has changed.
8f18d1fadf6a0c20fac9ff7259a5368faa3c3bfbGeorge Wilson if (error || generation != spa->spa_config_generation) {
ecc2d604e885a75cc75e647b5641af99d5a6f4a6bonwick * Offline this device and reopen its top-level vdev.
e6ca193ded880d478cc39e34ef82d4be36e4445dGeorge Wilson * If the top-level vdev is a log device then just offline
e6ca193ded880d478cc39e34ef82d4be36e4445dGeorge Wilson * it. Otherwise, if this action results in the top-level
e6ca193ded880d478cc39e34ef82d4be36e4445dGeorge Wilson * vdev becoming unusable, undo it and fail the request.
e6ca193ded880d478cc39e34ef82d4be36e4445dGeorge Wilson if (!tvd->vdev_islog && vd->vdev_aux == NULL &&
e14bb3258d05c1b1077e2db7cf77088924e56919Jeff Bonwick return (spa_vdev_state_exit(spa, NULL, EBUSY));
8f18d1fadf6a0c20fac9ff7259a5368faa3c3bfbGeorge Wilson * Add the device back into the metaslab rotor so that
8f18d1fadf6a0c20fac9ff7259a5368faa3c3bfbGeorge Wilson * once we online the device it's open for business.
e14bb3258d05c1b1077e2db7cf77088924e56919Jeff Bonwick vd->vdev_tmpoffline = !!(flags & ZFS_OFFLINE_TEMPORARY);
a15215608b8bd90f714f6db21ee623b584607cb6Jeff Bonwickvdev_offline(spa_t *spa, uint64_t guid, uint64_t flags)
ea8dc4b6d2251b437950c0056bc626b311c73c27eschrock * Clear the error counts associated with this vdev. Unlike vdev_online() and
ea8dc4b6d2251b437950c0056bc626b311c73c27eschrock * vdev_offline(), we assume the spa config is locked. We also clear all
ea8dc4b6d2251b437950c0056bc626b311c73c27eschrock * children. If 'vd' is NULL, then the user wants to clear all vdevs.
e14bb3258d05c1b1077e2db7cf77088924e56919Jeff Bonwick ASSERT(spa_config_held(spa, SCL_STATE_ALL, RW_WRITER) == SCL_STATE_ALL);
8a79c1b573d7814f1e432b1de8c9ed00bc876becek * If we're in the FAULTED state or have experienced failed I/O, then
8a79c1b573d7814f1e432b1de8c9ed00bc876becek * clear the persistent state and attempt to reopen the device. We
8a79c1b573d7814f1e432b1de8c9ed00bc876becek * also mark the vdev config dirty, so that the new faulted state is
8a79c1b573d7814f1e432b1de8c9ed00bc876becek * written out to disk.
096d22d43da2758693a6df66ce7d9ab54c9d464cEric Schrock * When reopening in reponse to a clear event, it may be due to
096d22d43da2758693a6df66ce7d9ab54c9d464cEric Schrock * a fmadm repair request. In this case, if the device is
096d22d43da2758693a6df66ce7d9ab54c9d464cEric Schrock * still broken, we want to still post the ereport again.
f9af39bacaaa0f9dda3b75ff6858b9f3988a39afGeorge Wilson if (vd != rvd && vdev_writeable(vd->vdev_top))
096d22d43da2758693a6df66ce7d9ab54c9d464cEric Schrock * When clearing a FMA-diagnosed fault, we always want to
096d22d43da2758693a6df66ce7d9ab54c9d464cEric Schrock * unspare the device, as we assume that the original spare was
096d22d43da2758693a6df66ce7d9ab54c9d464cEric Schrock * done in response to the FMA fault.
096d22d43da2758693a6df66ce7d9ab54c9d464cEric Schrock if (!vdev_is_dead(vd) && vd->vdev_parent != NULL &&
096d22d43da2758693a6df66ce7d9ab54c9d464cEric Schrock vd->vdev_parent->vdev_ops == &vdev_spare_ops &&
88ecc943b4eb72f7c4fbbd8435997b85ef171fc3George Wilson * Holes and missing devices are always considered "dead".
88ecc943b4eb72f7c4fbbd8435997b85ef171fc3George Wilson * This simplifies the code since we don't have to check for
88ecc943b4eb72f7c4fbbd8435997b85ef171fc3George Wilson * these types of devices in the various code paths.
88ecc943b4eb72f7c4fbbd8435997b85ef171fc3George Wilson * Instead we rely on the fact that we skip over dead devices
88ecc943b4eb72f7c4fbbd8435997b85ef171fc3George Wilson * before issuing I/O to them.
88ecc943b4eb72f7c4fbbd8435997b85ef171fc3George Wilson return (vd->vdev_state < VDEV_STATE_DEGRADED || vd->vdev_ishole ||
e14bb3258d05c1b1077e2db7cf77088924e56919Jeff Bonwick return (!vdev_is_dead(vd) && !vd->vdev_cant_read);
e14bb3258d05c1b1077e2db7cf77088924e56919Jeff Bonwick return (!vdev_is_dead(vd) && !vd->vdev_cant_write);
8ad4d6dd86f5bc65fb3afa566c8133f3bac21648Jeff Bonwick * We currently allow allocations from vdevs which may be in the
a31e67878a1bf006016a43cafa1fdffa37e432e6George Wilson * process of reopening (i.e. VDEV_STATE_CLOSED). If the device
a31e67878a1bf006016a43cafa1fdffa37e432e6George Wilson * fails to reopen then we'll catch it later when we're holding
8ad4d6dd86f5bc65fb3afa566c8133f3bac21648Jeff Bonwick * the proper locks. Note that we have to get the vdev state
8ad4d6dd86f5bc65fb3afa566c8133f3bac21648Jeff Bonwick * in a local variable because although it changes atomically,
8ad4d6dd86f5bc65fb3afa566c8133f3bac21648Jeff Bonwick * we're asking two separate questions about it.
8ad4d6dd86f5bc65fb3afa566c8133f3bac21648Jeff Bonwick return (!(state < VDEV_STATE_DEGRADED && state != VDEV_STATE_CLOSED) &&
e14bb3258d05c1b1077e2db7cf77088924e56919Jeff Bonwick if (vdev_is_dead(vd) || vd->vdev_remove_wanted)
fa9e4066f08beec538e775443c5be79dd423fcabahrens * Get statistics for the given vdev.
2e4c998613148111f2fc5371085331ffb39122ffGeorge Wilson ASSERT(spa_config_held(spa, SCL_ALL, RW_READER) != 0);
573ca77e53dd31dcaebef023e7eb41969e6896c1George Wilson vs->vs_rsize += VDEV_LABEL_START_SIZE + VDEV_LABEL_END_SIZE;
c39a2aae1e2c439d156021edfc20910dad7f9891George Wilson * Report expandable space on top-level, non-auxillary devices only.
c39a2aae1e2c439d156021edfc20910dad7f9891George Wilson * The expandable space is reported in terms of metaslab sized units
c39a2aae1e2c439d156021edfc20910dad7f9891George Wilson * since that determines how much space the pool can expand.
c39a2aae1e2c439d156021edfc20910dad7f9891George Wilson vs->vs_esize = P2ALIGN(vd->vdev_max_asize - vd->vdev_asize,
2986efa8094ce00f75df27fb74a184c65c38614aAlex Reece if (vd->vdev_aux == NULL && vd == vd->vdev_top && !vd->vdev_ishole) {
2e4c998613148111f2fc5371085331ffb39122ffGeorge Wilson vs->vs_fragmentation = vd->vdev_mg->mg_fragmentation;
fa9e4066f08beec538e775443c5be79dd423fcabahrens * If we're getting stats on the root vdev, aggregate the I/O counts
fa9e4066f08beec538e775443c5be79dd423fcabahrens * over all top-level vdevs (i.e. the direct children of the root).
e14bb3258d05c1b1077e2db7cf77088924e56919Jeff Bonwick for (int t = 0; t < ZIO_TYPES; t++) {
e14bb3258d05c1b1077e2db7cf77088924e56919Jeff Bonwick * If this i/o is a gang leader, it didn't do any actual work.
e14bb3258d05c1b1077e2db7cf77088924e56919Jeff Bonwick * If this is a root i/o, don't count it -- we've already
e14bb3258d05c1b1077e2db7cf77088924e56919Jeff Bonwick * counted the top-level vdevs, and vdev_get_stats() will
e14bb3258d05c1b1077e2db7cf77088924e56919Jeff Bonwick * aggregate them when asked. This reduces contention on
e14bb3258d05c1b1077e2db7cf77088924e56919Jeff Bonwick * the root vdev_stat_lock and implicitly handles blocks
e14bb3258d05c1b1077e2db7cf77088924e56919Jeff Bonwick * that compress away to holes, for which there is no i/o.
e14bb3258d05c1b1077e2db7cf77088924e56919Jeff Bonwick * (Holes never create vdev children, so all the counters
e14bb3258d05c1b1077e2db7cf77088924e56919Jeff Bonwick * remain zero, which is what we want.)
e14bb3258d05c1b1077e2db7cf77088924e56919Jeff Bonwick * Note: this only applies to successful i/o (io_error == 0)
e14bb3258d05c1b1077e2db7cf77088924e56919Jeff Bonwick * because unlike i/o counts, errors are not additive.
e14bb3258d05c1b1077e2db7cf77088924e56919Jeff Bonwick * When reading a ditto block, for example, failure of
e14bb3258d05c1b1077e2db7cf77088924e56919Jeff Bonwick * one top-level vdev does not imply a root-level error.
3f9d6ad73e45c6823b409f93b0c8d4f62861d2d5Lin Ling /* XXX cleanup? */
8956713aded83a741173fcd4f9ef1c83521fbea9Eric Schrock * If this is an I/O error that is going to be retried, then ignore the
8956713aded83a741173fcd4f9ef1c83521fbea9Eric Schrock * error. Otherwise, the user may interpret B_FAILFAST I/O errors as
8956713aded83a741173fcd4f9ef1c83521fbea9Eric Schrock * hard errors, when in reality they can happen for any number of
8956713aded83a741173fcd4f9ef1c83521fbea9Eric Schrock * innocuous reasons (bus resets, MPxIO link failure, etc).
8f18d1fadf6a0c20fac9ff7259a5368faa3c3bfbGeorge Wilson * Intent logs writes won't propagate their error to the root
8f18d1fadf6a0c20fac9ff7259a5368faa3c3bfbGeorge Wilson * I/O so don't mark these types of failures as pool-level
8f18d1fadf6a0c20fac9ff7259a5368faa3c3bfbGeorge Wilson if (zio->io_vd == NULL && (zio->io_flags & ZIO_FLAG_DONT_PROPAGATE))
b47119fdaa2618005a0c23ec6caa33975da6227aGeorge Wilson if (type == ZIO_TYPE_READ && !vdev_is_dead(vd)) {
b47119fdaa2618005a0c23ec6caa33975da6227aGeorge Wilson if (type == ZIO_TYPE_WRITE && !vdev_is_dead(vd))
b24ab6762772a3f6a89393947930c7fa61306783Jeff Bonwick * This is either a normal write (not a repair), or it's
b24ab6762772a3f6a89393947930c7fa61306783Jeff Bonwick * a repair induced by the scrub thread, or it's a repair
b24ab6762772a3f6a89393947930c7fa61306783Jeff Bonwick * made by zil_claim() during spa_load() in the first txg.
b24ab6762772a3f6a89393947930c7fa61306783Jeff Bonwick * In the normal case, we commit the DTL change in the same
b24ab6762772a3f6a89393947930c7fa61306783Jeff Bonwick * txg as the block was born. In the scrub-induced repair
b24ab6762772a3f6a89393947930c7fa61306783Jeff Bonwick * case, we know that scrubs run in first-pass syncing context,
b24ab6762772a3f6a89393947930c7fa61306783Jeff Bonwick * so we commit the DTL change in spa_syncing_txg(spa).
b24ab6762772a3f6a89393947930c7fa61306783Jeff Bonwick * In the zil_claim() case, we commit in spa_first_txg(spa).
8ad4d6dd86f5bc65fb3afa566c8133f3bac21648Jeff Bonwick * We currently do not make DTL entries for failed spontaneous
8ad4d6dd86f5bc65fb3afa566c8133f3bac21648Jeff Bonwick * self-healing writes triggered by normal (non-scrubbing)
8ad4d6dd86f5bc65fb3afa566c8133f3bac21648Jeff Bonwick * reads, because we have no transactional context in which to
8ad4d6dd86f5bc65fb3afa566c8133f3bac21648Jeff Bonwick * do so -- and it's not clear that it'd be desirable anyway.
8ad4d6dd86f5bc65fb3afa566c8133f3bac21648Jeff Bonwick if (vdev_dtl_contains(vd, DTL_MISSING, txg, 1))
8ad4d6dd86f5bc65fb3afa566c8133f3bac21648Jeff Bonwick for (pvd = vd; pvd != rvd; pvd = pvd->vdev_parent)
8ad4d6dd86f5bc65fb3afa566c8133f3bac21648Jeff Bonwick vdev_dirty(vd->vdev_top, VDD_DTL, vd, commit_txg);
b24ab6762772a3f6a89393947930c7fa61306783Jeff Bonwick * Update the in-core space usage stats for this vdev, its metaslab class,
b24ab6762772a3f6a89393947930c7fa61306783Jeff Bonwick * and the root vdev.
b24ab6762772a3f6a89393947930c7fa61306783Jeff Bonwickvdev_space_update(vdev_t *vd, int64_t alloc_delta, int64_t defer_delta,
b24ab6762772a3f6a89393947930c7fa61306783Jeff Bonwick metaslab_class_t *mc = mg ? mg->mg_class : NULL;
8654d0253136055bd4cc2423d87378e8a37f2eb5perrin * Apply the inverse of the psize-to-asize (ie. RAID-Z) space-expansion
8654d0253136055bd4cc2423d87378e8a37f2eb5perrin * factor. We must calculate this here and not at the root vdev
8654d0253136055bd4cc2423d87378e8a37f2eb5perrin * because the root vdev's psize-to-asize is simply the max of its
8654d0253136055bd4cc2423d87378e8a37f2eb5perrin * childrens', thus not accurate enough for us.
e6ca193ded880d478cc39e34ef82d4be36e4445dGeorge Wilson ASSERT(vd->vdev_deflate_ratio != 0 || vd->vdev_isl2cache);
b24ab6762772a3f6a89393947930c7fa61306783Jeff Bonwick alloc_delta, defer_delta, space_delta, dspace_delta);
fa9e4066f08beec538e775443c5be79dd423fcabahrens * Mark a top-level vdev's config as dirty, placing it on the dirty list
fa9e4066f08beec538e775443c5be79dd423fcabahrens * so that it will be written out next time the vdev configuration is synced.
fa9e4066f08beec538e775443c5be79dd423fcabahrens * If the root vdev is specified (vdev_top == NULL), dirty all top-level vdevs.
6809eb4e2a4a94bcc76229c7b5108b96134537b6Eric Schrock * If this is an aux vdev (as with l2cache and spare devices), then we
6809eb4e2a4a94bcc76229c7b5108b96134537b6Eric Schrock * update the vdev config manually and set the sync flag.
e14bb3258d05c1b1077e2db7cf77088924e56919Jeff Bonwick * We're being removed. There's nothing more to do.
6809eb4e2a4a94bcc76229c7b5108b96134537b6Eric Schrock if (nvlist_lookup_nvlist_array(sav->sav_config,
6809eb4e2a4a94bcc76229c7b5108b96134537b6Eric Schrock VERIFY(nvlist_lookup_nvlist_array(sav->sav_config,
c5904d138f3bdf0762dbf452a43d5a5c387ea6a8eschrock * Setting the nvlist in the middle if the array is a little
c5904d138f3bdf0762dbf452a43d5a5c387ea6a8eschrock * sketchy, but it will work.
e14bb3258d05c1b1077e2db7cf77088924e56919Jeff Bonwick * The dirty list is protected by the SCL_CONFIG lock. The caller
e14bb3258d05c1b1077e2db7cf77088924e56919Jeff Bonwick * must either hold SCL_CONFIG as writer, or must be the sync thread
e14bb3258d05c1b1077e2db7cf77088924e56919Jeff Bonwick * (which holds SCL_CONFIG as reader). There's only one sync thread,
5dabedee088a5b1080fff5e8b615fff203828fadbonwick * so this is sufficient to ensure mutual exclusion.
e14bb3258d05c1b1077e2db7cf77088924e56919Jeff Bonwick ASSERT(spa_config_held(spa, SCL_CONFIG, RW_WRITER) ||
88ecc943b4eb72f7c4fbbd8435997b85ef171fc3George Wilson if (!list_link_active(&vd->vdev_config_dirty_node) &&
e14bb3258d05c1b1077e2db7cf77088924e56919Jeff Bonwick list_insert_head(&spa->spa_config_dirty_list, vd);
e14bb3258d05c1b1077e2db7cf77088924e56919Jeff Bonwick ASSERT(spa_config_held(spa, SCL_CONFIG, RW_WRITER) ||
e14bb3258d05c1b1077e2db7cf77088924e56919Jeff Bonwick ASSERT(list_link_active(&vd->vdev_config_dirty_node));
e14bb3258d05c1b1077e2db7cf77088924e56919Jeff Bonwick * Mark a top-level vdev's state as dirty, so that the next pass of
e14bb3258d05c1b1077e2db7cf77088924e56919Jeff Bonwick * spa_sync() can convert this into vdev_config_dirty(). We distinguish
e14bb3258d05c1b1077e2db7cf77088924e56919Jeff Bonwick * the state changes from larger config changes because they require
e14bb3258d05c1b1077e2db7cf77088924e56919Jeff Bonwick * much less locking, and are often needed for administrative actions.
e14bb3258d05c1b1077e2db7cf77088924e56919Jeff Bonwick * The state list is protected by the SCL_STATE lock. The caller
e14bb3258d05c1b1077e2db7cf77088924e56919Jeff Bonwick * must either hold SCL_STATE as writer, or must be the sync thread
e14bb3258d05c1b1077e2db7cf77088924e56919Jeff Bonwick * (which holds SCL_STATE as reader). There's only one sync thread,
e14bb3258d05c1b1077e2db7cf77088924e56919Jeff Bonwick * so this is sufficient to ensure mutual exclusion.
e14bb3258d05c1b1077e2db7cf77088924e56919Jeff Bonwick ASSERT(spa_config_held(spa, SCL_STATE, RW_WRITER) ||
b24ab6762772a3f6a89393947930c7fa61306783Jeff Bonwick if (!list_link_active(&vd->vdev_state_dirty_node) && !vd->vdev_ishole)
e14bb3258d05c1b1077e2db7cf77088924e56919Jeff Bonwick list_insert_head(&spa->spa_state_dirty_list, vd);
e14bb3258d05c1b1077e2db7cf77088924e56919Jeff Bonwick ASSERT(spa_config_held(spa, SCL_STATE, RW_WRITER) ||
e14bb3258d05c1b1077e2db7cf77088924e56919Jeff Bonwick ASSERT(list_link_active(&vd->vdev_state_dirty_node));
32b87932f3ef0887d873b7f6d2d1943799b2afc0ek * Propagate vdev state up from children to parent.
88ecc943b4eb72f7c4fbbd8435997b85ef171fc3George Wilson * Don't factor holes into the decision.
8ad4d6dd86f5bc65fb3afa566c8133f3bac21648Jeff Bonwick (!vdev_writeable(child) && spa_writeable(spa))) {
51ece83525fa18f5e72627610f480dffc7e492fdeschrock * Root special: if there is a top-level log
51ece83525fa18f5e72627610f480dffc7e492fdeschrock * device, treat the root vdev as if it were
51ece83525fa18f5e72627610f480dffc7e492fdeschrock * degraded.
51ece83525fa18f5e72627610f480dffc7e492fdeschrock } else if (child->vdev_state <= VDEV_STATE_DEGRADED) {
3d7072f8bd27709dba14f6fe336f149d25d9e207eschrock if (child->vdev_stat.vs_aux == VDEV_AUX_CORRUPT_DATA)
3d7072f8bd27709dba14f6fe336f149d25d9e207eschrock vd->vdev_ops->vdev_op_state_change(vd, faulted, degraded);
e14bb3258d05c1b1077e2db7cf77088924e56919Jeff Bonwick * Root special: if there is a top-level vdev that cannot be
3d7072f8bd27709dba14f6fe336f149d25d9e207eschrock * opened due to corrupted metadata, then propagate the root
3d7072f8bd27709dba14f6fe336f149d25d9e207eschrock * vdev's aux state as 'corrupt' rather than 'insufficient
3d7072f8bd27709dba14f6fe336f149d25d9e207eschrock * replicas'.
ea8dc4b6d2251b437950c0056bc626b311c73c27eschrock * Set a vdev's state. If this is during an open, we don't update the parent
ea8dc4b6d2251b437950c0056bc626b311c73c27eschrock * state, because we're in the process of opening children depth-first.
ea8dc4b6d2251b437950c0056bc626b311c73c27eschrock * Otherwise, we propagate the change to the parent.
ea8dc4b6d2251b437950c0056bc626b311c73c27eschrock * If this routine places a device in a faulted state, an appropriate ereport is
ea8dc4b6d2251b437950c0056bc626b311c73c27eschrock * generated.
ea8dc4b6d2251b437950c0056bc626b311c73c27eschrockvdev_set_state(vdev_t *vd, boolean_t isopen, vdev_state_t state, vdev_aux_t aux)
3d7072f8bd27709dba14f6fe336f149d25d9e207eschrock * If we are setting the vdev state to anything but an open state, then
98d1cbfec254295273b6a761bc1861c0374bdf02George Wilson * always close the underlying device unless the device has requested
98d1cbfec254295273b6a761bc1861c0374bdf02George Wilson * a delayed close (i.e. we're about to remove or fault the device).
98d1cbfec254295273b6a761bc1861c0374bdf02George Wilson * Otherwise, we keep accessible but invalid devices open forever.
98d1cbfec254295273b6a761bc1861c0374bdf02George Wilson * We don't call vdev_close() itself, because that implies some extra
98d1cbfec254295273b6a761bc1861c0374bdf02George Wilson * checks (offline, etc) that we don't want here. This is limited to
98d1cbfec254295273b6a761bc1861c0374bdf02George Wilson * leaf devices, because otherwise closing the device will affect other
98d1cbfec254295273b6a761bc1861c0374bdf02George Wilson if (!vd->vdev_delayed_close && vdev_is_dead(vd) &&
069f55e237020c4a4907b235fc38fafc6442ce94Eric Schrock * If we have brought this vdev back into service, we need
069f55e237020c4a4907b235fc38fafc6442ce94Eric Schrock * to notify fmd so that it can gracefully repair any outstanding
069f55e237020c4a4907b235fc38fafc6442ce94Eric Schrock * cases due to a missing device. We do this in all cases, even those
069f55e237020c4a4907b235fc38fafc6442ce94Eric Schrock * that probably don't correlate to a repaired fault. This is sure to
069f55e237020c4a4907b235fc38fafc6442ce94Eric Schrock * catch all cases, and we let the zfs-retire agent sort it out. If
069f55e237020c4a4907b235fc38fafc6442ce94Eric Schrock * this is a transient state it's OK, as the retire agent will
069f55e237020c4a4907b235fc38fafc6442ce94Eric Schrock * double-check the state of the vdev before repairing it.
069f55e237020c4a4907b235fc38fafc6442ce94Eric Schrock if (state == VDEV_STATE_HEALTHY && vd->vdev_ops->vdev_op_leaf &&
3d7072f8bd27709dba14f6fe336f149d25d9e207eschrock (aux == VDEV_AUX_OPEN_FAILED || vd->vdev_checkremove)) {
3d7072f8bd27709dba14f6fe336f149d25d9e207eschrock * If the previous state is set to VDEV_STATE_REMOVED, then this
3d7072f8bd27709dba14f6fe336f149d25d9e207eschrock * device was previously marked removed and someone attempted to
3d7072f8bd27709dba14f6fe336f149d25d9e207eschrock * reopen it. If this failed due to a nonexistent device, then
3d7072f8bd27709dba14f6fe336f149d25d9e207eschrock * keep the device in the REMOVED state. We also let this be if
3d7072f8bd27709dba14f6fe336f149d25d9e207eschrock * it is one of our special test online cases, which is only
3d7072f8bd27709dba14f6fe336f149d25d9e207eschrock * attempting to online the device and shouldn't generate an FMA
cb04b8739c50e3e6d12e89b790fa7b8d0d899865Mark J Musante * If we fail to open a vdev during an import or recovery, we
cb04b8739c50e3e6d12e89b790fa7b8d0d899865Mark J Musante * mark it as "not available", which signifies that it was
cb04b8739c50e3e6d12e89b790fa7b8d0d899865Mark J Musante * never there to begin with. Failure to open such a device
cb04b8739c50e3e6d12e89b790fa7b8d0d899865Mark J Musante * is not considered an error.
cb04b8739c50e3e6d12e89b790fa7b8d0d899865Mark J Musante if ((spa_load_state(spa) == SPA_LOAD_IMPORT ||
560e6e964ab70b838deafc93f6d9da97f690ec25eschrock * Post the appropriate ereport. If the 'prevstate' field is
560e6e964ab70b838deafc93f6d9da97f690ec25eschrock * set to something other than VDEV_STATE_UNKNOWN, it indicates
560e6e964ab70b838deafc93f6d9da97f690ec25eschrock * that this is part of a vdev_reopen(). In this case, we don't
560e6e964ab70b838deafc93f6d9da97f690ec25eschrock * want to post the ereport if the device was already in the
560e6e964ab70b838deafc93f6d9da97f690ec25eschrock * CANT_OPEN state beforehand.
3d7072f8bd27709dba14f6fe336f149d25d9e207eschrock * If the 'checkremove' flag is set, then this is an attempt to
3d7072f8bd27709dba14f6fe336f149d25d9e207eschrock * online the device in response to an insertion event. If we
3d7072f8bd27709dba14f6fe336f149d25d9e207eschrock * hit this case, then we have detected an insertion event for a
3d7072f8bd27709dba14f6fe336f149d25d9e207eschrock * faulted or offline device that wasn't in the removed state.
3d7072f8bd27709dba14f6fe336f149d25d9e207eschrock * In this scenario, we don't post an ereport because we are
3d7072f8bd27709dba14f6fe336f149d25d9e207eschrock * about to replace the device, or attempt an online with
3d7072f8bd27709dba14f6fe336f149d25d9e207eschrock * vdev_forcefault, which will generate the fault for us.
3d7072f8bd27709dba14f6fe336f149d25d9e207eschrock if ((vd->vdev_prevstate != state || vd->vdev_forcefault) &&
c5904d138f3bdf0762dbf452a43d5a5c387ea6a8eschrock zfs_ereport_post(class, spa, vd, NULL, save_state, 0);
3d7072f8bd27709dba14f6fe336f149d25d9e207eschrock /* Erase any notion of persistent removed state */
15e6edf145a9c2bb0e0272cf8debe823bb97529bgw * Check the vdev configuration to ensure that it's capable of supporting
c8811bd3e2427dddbac6c05a59cfe117d8fea370Toomas Soome * a root pool. We do not support partial configuration.
c8811bd3e2427dddbac6c05a59cfe117d8fea370Toomas Soome * In addition, only a single top-level vdev is allowed.
c8811bd3e2427dddbac6c05a59cfe117d8fea370Toomas Soome } else if (strcmp(vdev_type, VDEV_TYPE_MISSING) == 0) {
88ecc943b4eb72f7c4fbbd8435997b85ef171fc3George Wilson * Load the state from the original vdev tree (ovd) which
88ecc943b4eb72f7c4fbbd8435997b85ef171fc3George Wilson * we've retrieved from the MOS config object. If the original
4b964ada391d44b89d97e7e930e6a9a136e0a2f4George Wilson * vdev was offline or faulted then we transfer that state to the
4b964ada391d44b89d97e7e930e6a9a136e0a2f4George Wilson * device in the current vdev tree (nvd).
88ecc943b4eb72f7c4fbbd8435997b85ef171fc3George Wilson ASSERT(spa_config_held(spa, SCL_STATE_ALL, RW_WRITER) == SCL_STATE_ALL);
88ecc943b4eb72f7c4fbbd8435997b85ef171fc3George Wilson vdev_load_log_state(nvd->vdev_child[c], ovd->vdev_child[c]);
4b964ada391d44b89d97e7e930e6a9a136e0a2f4George Wilson * Restore the persistent vdev state
4b964ada391d44b89d97e7e930e6a9a136e0a2f4George Wilson * Determine if a log device has valid content. If the vdev was
4b964ada391d44b89d97e7e930e6a9a136e0a2f4George Wilson * removed or faulted in the MOS config then we know that
4b964ada391d44b89d97e7e930e6a9a136e0a2f4George Wilson * the content on the log device has already been written to the pool.
4b964ada391d44b89d97e7e930e6a9a136e0a2f4George Wilson if (vd->vdev_ops->vdev_op_leaf && !vd->vdev_faulted &&
573ca77e53dd31dcaebef023e7eb41969e6896c1George Wilson * Expand a vdev if possible.
573ca77e53dd31dcaebef023e7eb41969e6896c1George Wilson ASSERT(spa_config_held(vd->vdev_spa, SCL_ALL, RW_WRITER) == SCL_ALL);
573ca77e53dd31dcaebef023e7eb41969e6896c1George Wilson if ((vd->vdev_asize >> vd->vdev_ms_shift) > vd->vdev_ms_count) {
1195e687f1c03c8d57417b5999578922e20a3554Mark J Musante * Split a vdev.
283b84606b6fc326692c03273de1774e8c122f9aGeorge.Wilson * Look at the head of all the pending queues,
283b84606b6fc326692c03273de1774e8c122f9aGeorge.Wilson * if any I/O has been outstanding for longer than
283b84606b6fc326692c03273de1774e8c122f9aGeorge.Wilson * the spa_deadman_synctime we panic the system.
c55e05cb35da47582b7afd38734d2f0d9c6deb40Matthew Ahrens "delta %lluns, last io %lluns",