]>
git.proxmox.com Git - mirror_zfs.git/blob - tests/zfs-tests/tests/functional/cli_root/zpool_clear/zpool_clear_001_pos.ksh
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.
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.
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]
24 # Copyright 2007 Sun Microsystems, Inc. All rights reserved.
25 # Use is subject to license terms.
29 # Copyright (c) 2012, 2016 by Delphix. All rights reserved.
32 .
$STF_SUITE/include
/libtest.shlib
33 .
$STF_SUITE/tests
/functional
/cli_root
/zpool_clear
/zpool_clear.cfg
37 # Verify 'zpool clear' can clear pool errors.
40 # 1. Create various configuration pools
41 # 2. Make errors to pool
42 # 3. Use zpool clear to clear errors
43 # 4. Verify the errors has been cleared.
46 verify_runnable
"global"
50 poolexists
$TESTPOOL1 && \
51 log_must zpool destroy
-f $TESTPOOL1
53 for file in `ls $TEST_BASE_DIR/file.*`; do
59 log_assert
"Verify 'zpool clear' can clear errors of a storage pool."
62 #make raw files to create various configuration pools
65 log_must truncate
-s $FILESIZE $TEST_BASE_DIR/file.
$i
70 fbase
=$TEST_BASE_DIR/file
71 set -A poolconf
"mirror $fbase.0 $fbase.1 $fbase.2" \
72 "raidz1 $fbase.0 $fbase.1 $fbase.2" \
73 "raidz2 $fbase.0 $fbase.1 $fbase.2"
75 function check_err
# <pool> [<vdev>]
88 typeset tmpfile
=/var
/tmp
/file.$$
89 typeset healthstr
="pool '$pool' is healthy"
90 typeset output
="`zpool status -x $pool`"
92 [[ "$output" == "$healthstr" ]] && return $errnum
94 zpool status
-x $pool |
grep -v "^$" |
grep -v "pool:" \
95 |
grep -v "state:" |
grep -v "config:" \
96 |
grep -v "errors:" > $tmpfile
98 typeset
-i fetchbegin
=1
100 if (( $fetchbegin != 0 )); then
101 echo $line |
grep "NAME" >/dev
/null
2>&1
102 (( $?
== 0 )) && (( fetchbegin
= 0 ))
106 if [[ -n $checkvdev ]]; then
107 echo $line |
grep $checkvdev >/dev
/null
2>&1
108 (( $?
!= 0 )) && continue
109 c_read
=`echo $line | awk '{print $3}'`
110 c_write
=`echo $line | awk '{print $4}'`
111 c_cksum
=`echo $line | awk '{print $5}'`
112 if [ $c_read != 0 ] ||
[ $c_write != 0 ] || \
115 (( errnum
= errnum
+ 1 ))
120 c_read
=`echo $line | awk '{print $3}'`
121 c_write
=`echo $line | awk '{print $4}'`
122 c_cksum
=`echo $line | awk '{print $5}'`
123 if [ $c_read != 0 ] ||
[ $c_write != 0 ] || \
126 (( errnum
= errnum
+ 1 ))
133 function do_testing
#<clear type> <vdevs>
135 typeset FS
=$TESTPOOL1/fs
141 log_must zpool create
-f $TESTPOOL1 $vdev
142 log_must zfs create
$FS
144 # Partially fill up the zfs filesystem in order to make data block
145 # errors. It's not necessary to fill the entire filesystem.
147 avail
=$
(get_prop available
$FS)
148 fill_mb
=$
(((avail
/ 1024 / 1024) * 25 / 100))
149 log_must
dd if=/dev
/urandom of
=$file.
$i bs
=$BLOCKSZ count
=$fill_mb
152 # Make errors to the testing pool by overwrite the vdev device with
153 # /usr/bin/dd command. We do not want to have a full overwrite. That
154 # may cause the system panic. So, we should skip the vdev label space.
156 (( i
= $RANDOM % 3 ))
161 (( size
= ${FILESIZE%%[g|G]} ))
162 (( wcount
= size
*1024*1024 - 512 ))
165 (( size
= ${FILESIZE%%[m|M]} ))
166 (( wcount
= size
*1024 - 512 ))
169 (( size
= ${FILESIZE%%[k|K]} ))
170 (( wcount
= size
- 512 ))
173 (( wcount
= FILESIZE
/1024 - 512 ))
176 dd if=/dev
/zero of
=$fbase.
$i seek
=512 bs
=1024 count
=$wcount conv
=notrunc \
179 log_must zpool scrub
$TESTPOOL1
180 # Wait for the completion of scrub operation
181 while is_pool_scrubbing
$TESTPOOL1; do
185 check_err
$TESTPOOL1 && \
186 log_fail
"No error generated."
187 if [[ $type == "device" ]]; then
188 log_must zpool
clear $TESTPOOL1 $fbase.
$i
189 ! check_err
$TESTPOOL1 $fbase.
$i && \
190 log_fail
"'zpool clear' fails to clear error for $fbase.$i device."
193 if [[ $type == "pool" ]]; then
194 log_must zpool
clear $TESTPOOL1
195 ! check_err
$TESTPOOL1 && \
196 log_fail
"'zpool clear' fails to clear error for pool $TESTPOOL1."
199 log_must zpool destroy
$TESTPOOL1
202 log_note
"'zpool clear' clears leaf-device error."
203 for devconf
in "${poolconf[@]}"; do
204 do_testing
"device" $devconf
206 log_note
"'zpool clear' clears top-level pool error."
207 for devconf
in "${poolconf[@]}"; do
208 do_testing
"pool" $devconf
211 log_pass
"'zpool clear' clears pool errors as expected."