]> git.proxmox.com Git - mirror_zfs.git/blob - tests/zfs-tests/tests/functional/online_offline/online_offline_002_neg.ksh
Enable remaining tests
[mirror_zfs.git] / tests / zfs-tests / tests / functional / online_offline / online_offline_002_neg.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) 2013, 2016 by Delphix. All rights reserved.
30 #
31
32 . $STF_SUITE/include/libtest.shlib
33 . $STF_SUITE/tests/functional/online_offline/online_offline.cfg
34
35 #
36 # DESCRIPTION:
37 # Turning disks in a pool offline should fail when there is no longer
38 # sufficient redundancy.
39 #
40 # STRATEGY:
41 # 1. Start some random I/O on the mirror or raidz.
42 # 2. Verify that we can offline as many disks as the redundancy level
43 # will support, but not more.
44 # 3. Verify the integrity of the file system and the resilvering.
45 #
46
47 verify_runnable "global"
48
49 DISKLIST=$(get_disklist $TESTPOOL)
50
51 function cleanup
52 {
53 #
54 # Ensure we don't leave disks in the offline state
55 #
56 for disk in $DISKLIST; do
57 log_must zpool online $TESTPOOL $disk
58 check_state $TESTPOOL $disk "online"
59 if [[ $? != 0 ]]; then
60 log_fail "Unable to online $disk"
61 fi
62
63 done
64
65 kill $killpid >/dev/null 2>&1
66 [[ -e $TESTDIR ]] && log_must rm -rf $TESTDIR/*
67 }
68
69 log_assert "Turning both disks offline should fail."
70
71 log_onexit cleanup
72
73 file_trunc -f $((64 * 1024 * 1024)) -b 8192 -c 0 -r $TESTDIR/$TESTFILE1 &
74 typeset killpid="$! "
75
76 disks=($DISKLIST)
77
78 #
79 # The setup script will give us either a mirror or a raidz. The former can have
80 # all but one vdev offlined, whereas with raidz there can be only one.
81 #
82 pooltype='mirror'
83 zpool list -v $TESTPOOL | grep raidz >/dev/null 2>&1 && pooltype='raidz'
84
85 typeset -i i=0
86 while [[ $i -lt ${#disks[*]} ]]; do
87 typeset -i j=0
88 if [[ $pooltype = 'mirror' ]]; then
89 # Hold one disk online, verify the others can be offlined.
90 log_must zpool online $TESTPOOL ${disks[$i]}
91 check_state $TESTPOOL ${disks[$i]} "online" || \
92 log_fail "Failed to set ${disks[$i]} online"
93 # Delay for resilver to complete
94 while ! is_pool_resilvered $TESTPOOL; do
95 log_must sleep 1
96 done
97 log_must zpool clear $TESTPOOL
98 while [[ $j -lt ${#disks[*]} ]]; do
99 if [[ $j -eq $i ]]; then
100 ((j++))
101 continue
102 fi
103 log_must zpool offline $TESTPOOL ${disks[$j]}
104 check_state $TESTPOOL ${disks[$j]} "offline" || \
105 log_fail "Failed to set ${disks[$j]} offline"
106 ((j++))
107 done
108 elif [[ $pooltype = 'raidz' ]]; then
109 # Hold one disk offline, verify the others can't be offlined.
110 log_must zpool offline $TESTPOOL ${disks[$i]}
111 check_state $TESTPOOL ${disks[$i]} "offline" || \
112 log_fail "Failed to set ${disks[$i]} offline"
113 while [[ $j -lt ${#disks[*]} ]]; do
114 if [[ $j -eq $i ]]; then
115 ((j++))
116 continue
117 fi
118 log_mustnot zpool offline $TESTPOOL ${disks[$j]}
119 check_state $TESTPOOL ${disks[$j]} "online" || \
120 log_fail "Failed to set ${disks[$j]} online"
121 check_state $TESTPOOL ${disks[$i]} "offline" || \
122 log_fail "Failed to set ${disks[$i]} offline"
123 ((j++))
124 done
125 log_must zpool online $TESTPOOL ${disks[$i]}
126 check_state $TESTPOOL ${disks[$i]} "online" || \
127 log_fail "Failed to set ${disks[$i]} online"
128 # Delay for resilver to complete
129 while ! is_pool_resilvered $TESTPOOL; do
130 log_must sleep 1
131 done
132 log_must zpool clear $TESTPOOL
133 fi
134 ((i++))
135 done
136
137 log_must kill $killpid
138 sync
139
140 typeset dir=$(get_device_dir $DISKS)
141 verify_filesys "$TESTPOOL" "$TESTPOOL/$TESTFS" "$dir"
142
143 log_pass