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 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# Test force faulting a VDEV with 'zpool offline -f'
37#
38# STRATEGY:
39# For both temporary and persistent faults, do the following:
40# 1. Force fault a vdev, and clear the fault.
41# 2. Offline a vdev, force fault it, clear the fault, and online it.
42# 3. Force fault a vdev, export it, then import it.
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	# Ensure we don't leave disks in the offline state
55	for disk in $DISKLIST; do
56		log_must zpool online $TESTPOOL $disk
57		log_must check_state $TESTPOOL $disk "online"
58	done
59}
60
61log_assert "Executing 'zpool offline -f' with correct options succeeds"
62
63log_onexit cleanup
64
65if [[ -z $DISKLIST ]]; then
66	log_fail "DISKLIST is empty."
67fi
68
69typeset -i i=0
70typeset -i j=1
71
72# Get name of the first disk in the pool
73disk=${DISKLIST%% *}
74
75# Test temporary and persistent faults
76for arg in f tf ; do
77	# Force fault disk, and clear the fault
78	log_must zpool offline -$arg $TESTPOOL $disk
79	check_state $TESTPOOL $disk "faulted"
80	log_must zpool clear $TESTPOOL $disk
81	check_state $TESTPOOL $disk "online"
82
83	# Offline a disk, force fault it, clear the fault, and online it
84	log_must zpool offline $TESTPOOL $disk
85	check_state $TESTPOOL $disk "offline"
86	log_must zpool offline -$arg $TESTPOOL $disk
87	check_state $TESTPOOL $disk "faulted"
88	log_must zpool clear $TESTPOOL $disk
89	check_state $TESTPOOL $disk "offline"
90	log_must zpool online $TESTPOOL $disk
91	check_state $TESTPOOL $disk "online"
92
93	# Test faults across imports
94	log_must zpool offline -tf $TESTPOOL $disk
95	check_state $TESTPOOL $disk "faulted"
96	log_must zpool export $TESTPOOL
97	log_must zpool import $TESTPOOL
98	log_note "-$arg now imported"
99	if [[ "$arg" = "f" ]] ; then
100		# Persistent fault
101		check_state $TESTPOOL $disk "faulted"
102		log_must zpool clear $TESTPOOL $disk
103	else
104		# Temporary faults get cleared by imports
105		check_state $TESTPOOL $disk "online"
106	fi
107done
108log_pass "'zpool offline -f' with correct options succeeded"
109