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 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		log_must check_state $TESTPOOL $disk "online"
58
59	done
60}
61
62log_assert "Executing 'zpool online' with correct options succeeds"
63
64log_onexit cleanup
65
66if [[ -z $DISKLIST ]]; then
67	log_fail "DISKLIST is empty."
68fi
69
70typeset -i i=0
71typeset -i j=0
72
73for disk in $DISKLIST; do
74	i=0
75	while [[ $i -lt ${#args[*]} ]]; do
76
77		sync_pool $TESTPOOL
78		log_must zpool offline $TESTPOOL $disk
79		log_must check_state $TESTPOOL $disk "offline"
80
81		log_must zpool online ${args[$i]} $TESTPOOL $disk
82		log_must check_state $TESTPOOL $disk "online"
83
84		while [[ $j -lt 20 ]]; do
85			is_pool_resilvered $TESTPOOL && break
86			sleep 0.5
87			(( j = j + 1 ))
88		done
89		is_pool_resilvered $TESTPOOL || \
90		    log_file "Pool didn't resilver after online"
91
92		(( i = i + 1 ))
93	done
94done
95
96log_note "Issuing repeated 'zpool online' commands succeeds."
97
98typeset -i iters=20
99typeset -i index=0
100
101for disk in $DISKLIST; do
102        i=0
103        while [[ $i -lt $iters ]]; do
104		index=`expr $RANDOM % ${#args[*]}`
105                log_must zpool online ${args[$index]} $TESTPOOL $disk
106                log_must check_state $TESTPOOL $disk "online"
107
108                (( i = i + 1 ))
109        done
110done
111
112log_pass "'zpool online' with correct options succeeded"
113