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