]> CyberLeo.Net >> Repos - FreeBSD/FreeBSD.git/blob - tests/zfs-tests/tests/functional/cli_root/zpool_offline/zpool_offline_003_pos.ksh
Vendor import of openzfs master @ 184df27eef0abdc7ab2105b21257f753834b936b
[FreeBSD/FreeBSD.git] / tests / zfs-tests / tests / functional / cli_root / zpool_offline / zpool_offline_003_pos.ksh
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 # 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
44 verify_runnable "global"
45
46 DISKLIST=$(get_disklist $TESTPOOL)
47 set -A disks $DISKLIST
48 typeset -i num=${#disks[*]}
49
50 set -A args "" "-t"
51
52 function 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                 check_state $TESTPOOL $disk "online"
58                 if [[ $? != 0 ]]; then
59                         log_fail "Unable to online $disk"
60                 fi
61         done
62 }
63
64 log_assert "Executing 'zpool offline -f' with correct options succeeds"
65
66 log_onexit cleanup
67
68 if [[ -z $DISKLIST ]]; then
69         log_fail "DISKLIST is empty."
70 fi
71
72 typeset -i i=0
73 typeset -i j=1
74
75 # Get name of the first disk in the pool
76 disk=${DISKLIST%% *}
77
78 # Test temporary and persistent faults
79 for arg in f tf ; do
80         # Force fault disk, and clear the fault
81         log_must zpool offline -$arg $TESTPOOL $disk
82         check_state $TESTPOOL $disk "faulted"
83         log_must zpool clear $TESTPOOL $disk
84         check_state $TESTPOOL $disk "online"
85
86         # Offline a disk, force fault it, clear the fault, and online it
87         log_must zpool offline $TESTPOOL $disk
88         check_state $TESTPOOL $disk "offline"
89         log_must zpool offline -$arg $TESTPOOL $disk
90         check_state $TESTPOOL $disk "faulted"
91         log_must zpool clear $TESTPOOL $disk
92         check_state $TESTPOOL $disk "offline"
93         log_must zpool online $TESTPOOL $disk
94         check_state $TESTPOOL $disk "online"
95
96         # Test faults across imports
97         log_must zpool offline -tf $TESTPOOL $disk
98         check_state $TESTPOOL $disk "faulted"
99         log_must zpool export $TESTPOOL
100         log_must zpool import $TESTPOOL
101         log_note "-$arg now imported"
102         if [[ "$arg" = "f" ]] ; then
103                 # Persistent fault
104                 check_state $TESTPOOL $disk "faulted"
105                 log_must zpool clear $TESTPOOL $disk
106         else
107                 # Temporary faults get cleared by imports
108                 check_state $TESTPOOL $disk "online"
109         fi
110 done
111 log_pass "'zpool offline -f' with correct options succeeded"