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 2007 Sun Microsystems, Inc.  All rights reserved.
25# Use is subject to license terms.
26#
27
28#
29# Copyright (c) 2016 by Delphix. All rights reserved.
30#
31
32. $STF_SUITE/include/libtest.shlib
33
34#
35# DESCRIPTION:
36# Executing 'zpool online' with valid parameters succeeds.
37#
38# STRATEGY:
39# 1. Create an array of correctly formed 'zpool online' options
40# 2. Execute each element of the array.
41# 3. Verify use of each option is successful.
42#
43
44verify_runnable "global"
45
46DISKLIST=$(get_disklist $TESTPOOL)
47
48set -A args ""
49
50function cleanup
51{
52	#
53	# Ensure we don't leave disks in temporary online state (-t)
54	#
55	for disk in $DISKLIST; do
56		log_must zpool online $TESTPOOL $disk
57		check_state $TESTPOOL $disk "online"
58		if [[ $? != 0 ]]; then
59			log_fail "Unable to online $disk"
60		fi
61
62	done
63}
64
65log_assert "Executing 'zpool online' with correct options succeeds"
66
67log_onexit cleanup
68
69if [[ -z $DISKLIST ]]; then
70	log_fail "DISKLIST is empty."
71fi
72
73typeset -i i=0
74typeset -i j=0
75
76for disk in $DISKLIST; do
77	i=0
78	while [[ $i -lt ${#args[*]} ]]; do
79
80		sync_pool $TESTPOOL
81		log_must zpool offline $TESTPOOL $disk
82		check_state $TESTPOOL $disk "offline"
83		if [[ $? != 0 ]]; then
84			log_fail "$disk of $TESTPOOL did not match offline state"
85		fi
86
87		log_must zpool online ${args[$i]} $TESTPOOL $disk
88		check_state $TESTPOOL $disk "online"
89		if [[ $? != 0 ]]; then
90			log_fail "$disk of $TESTPOOL did not match online state"
91		fi
92
93		while [[ $j -lt 20 ]]; do
94			is_pool_resilvered $TESTPOOL && break
95			sleep 0.5
96			(( j = j + 1 ))
97		done
98		is_pool_resilvered $TESTPOOL || \
99		    log_file "Pool didn't resilver after online"
100
101		(( i = i + 1 ))
102	done
103done
104
105log_note "Issuing repeated 'zpool online' commands succeeds."
106
107typeset -i iters=20
108typeset -i index=0
109
110for disk in $DISKLIST; do
111        i=0
112        while [[ $i -lt $iters ]]; do
113		index=`expr $RANDOM % ${#args[*]}`
114                log_must zpool online ${args[$index]} $TESTPOOL $disk
115                check_state $TESTPOOL $disk "online"
116                if [[ $? != 0 ]]; then
117                        log_fail "$disk of $TESTPOOL did not match online state"
118                fi
119
120                (( i = i + 1 ))
121        done
122done
123
124log_pass "'zpool online' with correct options succeeded"
125