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 2009 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 offline' with valid parameters succeeds. 37# 38# STRATEGY: 39# 1. Create an array of correctly formed 'zpool offline' 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) 47set -A disks $DISKLIST 48typeset -i num=${#disks[*]} 49 50set -A args "" "-t" 51 52function cleanup 53{ 54 # 55 # Ensure we don't leave disks in the offline state 56 # 57 for disk in $DISKLIST; do 58 log_must zpool online $TESTPOOL $disk 59 check_state $TESTPOOL $disk "online" 60 if [[ $? != 0 ]]; then 61 log_fail "Unable to online $disk" 62 fi 63 64 done 65} 66 67log_assert "Executing 'zpool offline' with correct options succeeds" 68 69log_onexit cleanup 70 71if [[ -z $DISKLIST ]]; then 72 log_fail "DISKLIST is empty." 73fi 74 75typeset -i i=0 76typeset -i j=1 77 78for disk in $DISKLIST; do 79 i=0 80 while [[ $i -lt ${#args[*]} ]]; do 81 if (( j < num )) ; then 82 log_must zpool offline ${args[$i]} $TESTPOOL $disk 83 check_state $TESTPOOL $disk "offline" 84 if [[ $? != 0 ]]; then 85 log_fail "$disk of $TESTPOOL did not match offline state" 86 fi 87 else 88 log_mustnot zpool offline ${args[$i]} $TESTPOOL $disk 89 check_state $TESTPOOL $disk "online" 90 if [[ $? != 0 ]]; then 91 log_fail "$disk of $TESTPOOL did not match online state" 92 fi 93 fi 94 95 (( i = i + 1 )) 96 done 97 (( j = j + 1 )) 98done 99 100log_note "Issuing repeated 'zpool offline' commands succeeds." 101 102typeset -i iters=20 103typeset -i index=0 104 105for disk in $DISKLIST; do 106 i=0 107 while [[ $i -lt $iters ]]; do 108 index=`expr $RANDOM % ${#args[*]}` 109 log_must zpool offline ${args[$index]} $TESTPOOL $disk 110 check_state $TESTPOOL $disk "offline" 111 if [[ $? != 0 ]]; then 112 log_fail "$disk of $TESTPOOL is not offline." 113 fi 114 115 (( i = i + 1 )) 116 done 117 118 log_must zpool online $TESTPOOL $disk 119 check_state $TESTPOOL $disk "online" 120 if [[ $? != 0 ]]; then 121 log_fail "$disk of $TESTPOOL did not match online state" 122 fi 123done 124 125log_pass "'zpool offline' with correct options succeeded" 126