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 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		log_must check_state $TESTPOOL $disk "online"
59	done
60
61	kill $killpid >/dev/null 2>&1
62	[[ -e $TESTDIR ]] && log_must rm -rf $TESTDIR/*
63}
64
65log_assert "Turning both disks offline should fail."
66
67log_onexit cleanup
68
69file_trunc -f $((64 * 1024 * 1024)) -b 8192 -c 0 -r $TESTDIR/$TESTFILE1 &
70typeset killpid="$! "
71
72disks=($DISKLIST)
73
74#
75# The setup script will give us either a mirror or a raidz. The former can have
76# all but one vdev offlined, whereas with raidz there can be only one.
77#
78pooltype='mirror'
79zpool list -v $TESTPOOL | grep raidz >/dev/null 2>&1 && pooltype='raidz'
80
81typeset -i i=0
82while [[ $i -lt ${#disks[*]} ]]; do
83	typeset -i j=0
84	if [[ $pooltype = 'mirror' ]]; then
85		# Hold one disk online, verify the others can be offlined.
86		log_must zpool online $TESTPOOL ${disks[$i]}
87		check_state $TESTPOOL ${disks[$i]} "online" || \
88		    log_fail "Failed to set ${disks[$i]} online"
89		log_must zpool wait -t resilver $TESTPOOL
90		log_must zpool clear $TESTPOOL
91		while [[ $j -lt ${#disks[*]} ]]; do
92			if [[ $j -eq $i ]]; then
93				((j++))
94				continue
95			fi
96			log_must zpool offline $TESTPOOL ${disks[$j]}
97			check_state $TESTPOOL ${disks[$j]} "offline" || \
98			    log_fail "Failed to set ${disks[$j]} offline"
99			((j++))
100		done
101	elif [[ $pooltype = 'raidz' ]]; then
102		# Hold one disk offline, verify the others can't be offlined.
103		log_must zpool offline $TESTPOOL ${disks[$i]}
104		check_state $TESTPOOL ${disks[$i]} "offline" || \
105		    log_fail "Failed to set ${disks[$i]} offline"
106		while [[ $j -lt ${#disks[*]} ]]; do
107			if [[ $j -eq $i ]]; then
108				((j++))
109				continue
110			fi
111			log_mustnot zpool offline $TESTPOOL ${disks[$j]}
112			check_state $TESTPOOL ${disks[$j]} "online" || \
113			    log_fail "Failed to set ${disks[$j]} online"
114			check_state $TESTPOOL ${disks[$i]} "offline" || \
115			    log_fail "Failed to set ${disks[$i]} offline"
116			((j++))
117		done
118		log_must zpool online $TESTPOOL ${disks[$i]}
119		check_state $TESTPOOL ${disks[$i]} "online" || \
120		    log_fail "Failed to set ${disks[$i]} online"
121		log_must zpool wait -t resilver $TESTPOOL
122		log_must zpool clear $TESTPOOL
123	fi
124	((i++))
125done
126
127log_must kill $killpid
128sync_all_pools
129log_must sync
130
131typeset dir=$(get_device_dir $DISKS)
132verify_filesys "$TESTPOOL" "$TESTPOOL/$TESTFS" "$dir"
133
134log_pass
135