1#!/usr/local/bin/ksh93 -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# Copyright 2014 Spectra Logic Corporation.
26# Use is subject to license terms.
27#
28
29. $STF_SUITE/include/libtest.kshlib
30
31verify_runnable "global"
32
33function verify_assertion
34{
35	keyword="$1"
36	typeset -i redundancy
37	set -A DISKLIST $DISKS
38
39	case "$keyword" in
40		"") redundancy=0 ;;
41		"mirror") (( redundancy=${#DISKLIST[@]} - 1 )) ;;
42		"raidz") redundancy=1 ;;
43		"raidz2") redundancy=2 ;;
44		"raidz3") redundancy=3 ;;
45		*) log_fail "Unknown keyword" ;;
46	esac
47
48	echo redundancy is $redundancy
49
50	if [ ${#DISKLIST[@]} -le "$redundancy" ]; then
51		log_fail "Insufficiently many disks configured for this test"
52	fi
53
54	busy_path $TESTDIR
55	# Offline the allowed number of disks
56	for ((i=0; i<$redundancy; i=$i+1 )); do
57		log_must $ZPOOL offline $TESTPOOL ${DISKLIST[$i]}
58	done
59
60	#Verify that offlining any additional disks should fail
61	for ((i=$redundancy; i<${#DISKLIST[@]}; i=$i+1 )); do
62		log_mustnot $ZPOOL offline $TESTPOOL ${DISKLIST[$i]}
63	done
64	reap_children
65
66	typeset dir=$(get_device_dir $DISKS)
67	verify_filesys "$TESTPOOL" "$TESTPOOL/$TESTFS" "$dir"
68}
69
70log_assert "Turning both disks offline should fail."
71
72for keyword in "" "mirror" "raidz" "raidz2"; do
73	child_pids=""
74	default_setup_noexit "$keyword $DISKS"
75	verify_assertion "$keyword"
76	destroy_pool $TESTPOOL
77done
78
79log_pass
80