1#!/bin/ksh -p 2# 3# CDDL HEADER START 4# 5# The contents of this file are subject to the terms of the 6# Common Development and Distribution License (the "License"). 7# You may not use this file except in compliance with the License. 8# 9# You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE 10# or https://opensource.org/licenses/CDDL-1.0. 11# See the License for the specific language governing permissions 12# and limitations under the License. 13# 14# When distributing Covered Code, include this CDDL HEADER in each 15# file and include the License file at usr/src/OPENSOLARIS.LICENSE. 16# If applicable, add the following below this CDDL HEADER, with the 17# fields enclosed by brackets "[]" replaced with your own identifying 18# information: Portions Copyright [yyyy] [name of copyright owner] 19# 20# CDDL HEADER END 21# 22 23# 24# Copyright 2017, loli10K <ezomori.nozomu@gmail.com>. All rights reserved. 25# 26 27. $STF_SUITE/include/libtest.shlib 28 29# 30# DESCRIPTION: 31# 'zpool add' works with nested replacing/spare vdevs 32# 33# STRATEGY: 34# 1. Create a redundant pool with a spare device 35# 2. Manually fault a device, wait for the hot-spare and then replace it: 36# this creates a situation where replacing and spare vdevs are nested. 37# 3. Verify 'zpool add' is able to add new devices to the pool. 38# 39 40verify_runnable "global" 41 42function cleanup 43{ 44 zed_stop 45 zed_cleanup 46 log_must zinject -c all 47 destroy_pool $TESTPOOL 48 log_must rm -f $DATA_DEVS $SPARE_DEVS 49} 50 51log_assert "'zpool add' works with nested replacing/spare vdevs" 52log_onexit cleanup 53 54FAULT_DEV="$TEST_BASE_DIR/fault-dev" 55SAFE_DEV1="$TEST_BASE_DIR/safe-dev1" 56SAFE_DEV2="$TEST_BASE_DIR/safe-dev2" 57SAFE_DEV3="$TEST_BASE_DIR/safe-dev3" 58SAFE_DEVS="$SAFE_DEV1 $SAFE_DEV2 $SAFE_DEV3" 59REPLACE_DEV="$TEST_BASE_DIR/replace-dev" 60ADD_DEV="$TEST_BASE_DIR/add-dev" 61DATA_DEVS="$FAULT_DEV $SAFE_DEVS $REPLACE_DEV $ADD_DEV" 62SPARE_DEV1="$TEST_BASE_DIR/spare-dev1" 63SPARE_DEV2="$TEST_BASE_DIR/spare-dev2" 64SPARE_DEVS="$SPARE_DEV1 $SPARE_DEV2" 65 66# We need ZED running to work with spares 67zed_setup 68zed_start 69# Clear events from previous runs 70zed_events_drain 71 72for type in "mirror" "raidz1" "raidz2" "raidz3" 73do 74 # 1. Create a redundant pool with a spare device 75 truncate -s $SPA_MINDEVSIZE $DATA_DEVS $SPARE_DEVS 76 log_must zpool create $TESTPOOL $type $FAULT_DEV $SAFE_DEVS 77 log_must zpool add $TESTPOOL spare $SPARE_DEV1 78 79 # 2.1 Fault a device, verify the spare is kicked in 80 log_must zinject -d $FAULT_DEV -e nxio -T all -f 100 $TESTPOOL 81 log_must zpool reopen $TESTPOOL 82 log_must wait_vdev_state $TESTPOOL $FAULT_DEV "UNAVAIL" 60 83 log_must wait_vdev_state $TESTPOOL $SPARE_DEV1 "ONLINE" 60 84 log_must wait_hotspare_state $TESTPOOL $SPARE_DEV1 "INUSE" 85 log_must check_state $TESTPOOL "" "DEGRADED" 86 87 # 2.2 Replace the faulted device: this creates a replacing vdev inside a 88 # spare vdev 89 log_must zpool replace $TESTPOOL $FAULT_DEV $REPLACE_DEV 90 log_must wait_vdev_state $TESTPOOL $REPLACE_DEV "ONLINE" 60 91 zpool status | awk -v poolname="$TESTPOOL" -v type="$type" 'BEGIN {s=""} 92 $1 ~ poolname {c=4}; (c && c--) { s=s$1":" } 93 END { if (s != poolname":"type"-0:spare-0:replacing-0:") exit 1; }' || 94 log_fail "Pool does not contain nested replacing/spare vdevs" 95 96 # 3. Verify 'zpool add' is able to add new devices 97 log_must zpool add $TESTPOOL spare $SPARE_DEV2 98 log_must wait_hotspare_state $TESTPOOL $SPARE_DEV2 "AVAIL" 99 log_must zpool add -f $TESTPOOL $ADD_DEV 100 log_must wait_vdev_state $TESTPOOL $ADD_DEV "ONLINE" 60 101 102 # Cleanup 103 log_must zinject -c all 104 destroy_pool $TESTPOOL 105 log_must rm -f $DATA_DEVS $SPARE_DEVS 106done 107 108log_pass "'zpool add' works with nested replacing/spare vdevs" 109