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 http://www.opensolaris.org/os/licensing. 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 2009 Sun Microsystems, Inc. All rights reserved. 25# Use is subject to license terms. 26# 27 28# 29# Copyright (c) 2013, 2016 by Delphix. All rights reserved. 30# 31 32. $STF_SUITE/include/libtest.shlib 33. $STF_SUITE/tests/functional/online_offline/online_offline.cfg 34 35# 36# DESCRIPTION: 37# Turning disks in a pool offline should fail when there is no longer 38# sufficient redundancy. 39# 40# STRATEGY: 41# 1. Start some random I/O on the mirror or raidz. 42# 2. Verify that we can offline as many disks as the redundancy level 43# will support, but not more. 44# 3. Verify the integrity of the file system and the resilvering. 45# 46 47verify_runnable "global" 48 49DISKLIST=$(get_disklist $TESTPOOL) 50 51function cleanup 52{ 53 # 54 # Ensure we don't leave disks in the offline state 55 # 56 for disk in $DISKLIST; do 57 log_must zpool online $TESTPOOL $disk 58 check_state $TESTPOOL $disk "online" 59 if [[ $? != 0 ]]; then 60 log_fail "Unable to online $disk" 61 fi 62 63 done 64 65 kill $killpid >/dev/null 2>&1 66 [[ -e $TESTDIR ]] && log_must rm -rf $TESTDIR/* 67} 68 69log_assert "Turning both disks offline should fail." 70 71log_onexit cleanup 72 73file_trunc -f $((64 * 1024 * 1024)) -b 8192 -c 0 -r $TESTDIR/$TESTFILE1 & 74typeset killpid="$! " 75 76disks=($DISKLIST) 77 78# 79# The setup script will give us either a mirror or a raidz. The former can have 80# all but one vdev offlined, whereas with raidz there can be only one. 81# 82pooltype='mirror' 83zpool list -v $TESTPOOL | grep raidz >/dev/null 2>&1 && pooltype='raidz' 84 85typeset -i i=0 86while [[ $i -lt ${#disks[*]} ]]; do 87 typeset -i j=0 88 if [[ $pooltype = 'mirror' ]]; then 89 # Hold one disk online, verify the others can be offlined. 90 log_must zpool online $TESTPOOL ${disks[$i]} 91 check_state $TESTPOOL ${disks[$i]} "online" || \ 92 log_fail "Failed to set ${disks[$i]} online" 93 log_must zpool wait -t resilver $TESTPOOL 94 log_must zpool clear $TESTPOOL 95 while [[ $j -lt ${#disks[*]} ]]; do 96 if [[ $j -eq $i ]]; then 97 ((j++)) 98 continue 99 fi 100 log_must zpool offline $TESTPOOL ${disks[$j]} 101 check_state $TESTPOOL ${disks[$j]} "offline" || \ 102 log_fail "Failed to set ${disks[$j]} offline" 103 ((j++)) 104 done 105 elif [[ $pooltype = 'raidz' ]]; then 106 # Hold one disk offline, verify the others can't be offlined. 107 log_must zpool offline $TESTPOOL ${disks[$i]} 108 check_state $TESTPOOL ${disks[$i]} "offline" || \ 109 log_fail "Failed to set ${disks[$i]} offline" 110 while [[ $j -lt ${#disks[*]} ]]; do 111 if [[ $j -eq $i ]]; then 112 ((j++)) 113 continue 114 fi 115 log_mustnot zpool offline $TESTPOOL ${disks[$j]} 116 check_state $TESTPOOL ${disks[$j]} "online" || \ 117 log_fail "Failed to set ${disks[$j]} online" 118 check_state $TESTPOOL ${disks[$i]} "offline" || \ 119 log_fail "Failed to set ${disks[$i]} offline" 120 ((j++)) 121 done 122 log_must zpool online $TESTPOOL ${disks[$i]} 123 check_state $TESTPOOL ${disks[$i]} "online" || \ 124 log_fail "Failed to set ${disks[$i]} online" 125 log_must zpool wait -t resilver $TESTPOOL 126 log_must zpool clear $TESTPOOL 127 fi 128 ((i++)) 129done 130 131log_must kill $killpid 132sync 133 134typeset dir=$(get_device_dir $DISKS) 135verify_filesys "$TESTPOOL" "$TESTPOOL/$TESTFS" "$dir" 136 137log_pass 138