]> CyberLeo.Net >> Repos - FreeBSD/FreeBSD.git/blob - sys/contrib/openzfs/tests/zfs-tests/tests/functional/cli_root/zpool_events/zpool_events_errors.ksh
MFH
[FreeBSD/FreeBSD.git] / sys / contrib / openzfs / tests / zfs-tests / tests / functional / cli_root / zpool_events / zpool_events_errors.ksh
1 #!/bin/ksh -p
2 # CDDL HEADER START
3 #
4 # The contents of this file are subject to the terms of the
5 # Common Development and Distribution License (the "License").
6 # You may not use this file except in compliance with the License.
7 #
8 # You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
9 # or http://www.opensolaris.org/os/licensing.
10 # See the License for the specific language governing permissions
11 # and limitations under the License.
12 #
13 # When distributing Covered Code, include this CDDL HEADER in each
14 # file and include the License file at usr/src/OPENSOLARIS.LICENSE.
15 # If applicable, add the following below this CDDL HEADER, with the
16 # fields enclosed by brackets "[]" replaced with your own identifying
17 # information: Portions Copyright [yyyy] [name of copyright owner]
18 #
19 # CDDL HEADER END
20 #
21
22 #
23 # Copyright (c) 2018 by Lawrence Livermore National Security, LLC.
24 #
25
26 # DESCRIPTION:
27 #       Verify the number of IO and checksum events match the error counters
28 #       in zpool status.
29 #
30 # STRATEGY:
31 #       1. Create a raidz or mirror pool
32 #       2. Inject read/write IO errors or checksum errors
33 #       3. Verify the number of errors in zpool status match the corresponding
34 #          number of error events.
35 #       4. Repeat for all combinations of raidz/mirror and io/checksum errors.
36 #
37
38 . $STF_SUITE/include/libtest.shlib
39
40 verify_runnable "both"
41
42 MOUNTDIR=$TEST_BASE_DIR/mount
43 VDEV1=$TEST_BASE_DIR/file1
44 VDEV2=$TEST_BASE_DIR/file2
45 VDEV3=$TEST_BASE_DIR/file3
46 POOL=error_pool
47 FILESIZE=$((20 * 1024 * 1024))
48 OLD_CHECKSUMS=$(get_tunable CHECKSUM_EVENTS_PER_SECOND)
49 OLD_LEN_MAX=$(get_tunable ZEVENT_LEN_MAX)
50
51 function cleanup
52 {
53         log_must set_tunable64 CHECKSUM_EVENTS_PER_SECOND $OLD_CHECKSUMS
54         log_must set_tunable64 ZEVENT_LEN_MAX $OLD_LEN_MAX
55
56         log_must zinject -c all
57         log_must zpool events -c
58         if poolexists $POOL ; then
59                 log_must destroy_pool $POOL
60         fi
61         log_must rm -f $VDEV1 $VDEV2 $VDEV3
62 }
63
64 log_assert "Check that the number of zpool errors match the number of events"
65
66 log_onexit cleanup
67
68 # Set our thresholds high so we never ratelimit or drop events.
69 set_tunable64 CHECKSUM_EVENTS_PER_SECOND 20000
70 set_tunable64 ZEVENT_LEN_MAX 20000
71
72 log_must truncate -s $MINVDEVSIZE $VDEV1 $VDEV2 $VDEV3
73 log_must mkdir -p $MOUNTDIR
74
75 # Run error test on a specific type of pool
76 #
77 # $1: pool - raidz, mirror
78 # $2: test type - corrupt (checksum error), io
79 # $3: read, write
80 function do_test
81 {
82         POOLTYPE=$1
83         ERR=$2
84         RW=$3
85
86         log_note "Testing $ERR $RW on $POOLTYPE"
87         log_must zpool create -f -m $MOUNTDIR -o failmode=continue $POOL $POOLTYPE $VDEV1 $VDEV2 $VDEV3
88         log_must zpool events -c
89         log_must zfs set compression=off $POOL
90
91         if [ "$RW" == "read" ] ; then
92                 log_must mkfile $FILESIZE $MOUNTDIR/file
93         fi
94
95         log_must zinject -d $VDEV1 -e $ERR -T $RW -f 100 $POOL
96
97         if [ "$RW" == "write" ] ; then
98                 log_must mkfile $FILESIZE $MOUNTDIR/file
99                 log_must zpool sync $POOL
100         else
101                 log_must zpool scrub $POOL
102                 wait_scrubbed $POOL
103         fi
104
105         log_must zinject -c all
106
107         # Wait for the pool to settle down and finish resilvering (if
108         # necessary).  We want the errors to stop incrementing before we
109         # check the error and event counts.
110         while is_pool_resilvering $POOL ; do
111                 sleep 1
112         done
113
114         out="$(zpool status -p | grep $VDEV1)"
115
116         if [ "$ERR" == "corrupt" ] ; then
117                 events=$(zpool events | grep checksum | wc -l)
118                 val=$(echo "$out" | awk '{print $5}')
119                 str="checksum"
120         elif [ "$ERR" == "io" ] ; then
121                 allevents=$(zpool events | grep io)
122                 events=$(echo "$allevents" | wc -l)
123                 if [ "$RW" == "read" ] ; then
124                         str="read IO"
125                         val=$(echo "$out" | awk '{print $3}')
126                 else
127                         str="write IO"
128                         val=$(echo "$out" | awk '{print $4}')
129                 fi
130         fi
131
132         if [ -z "$val" -o $val -eq 0 -o -z "$events" -o $events -eq 0 ] ; then
133                 log_fail "Didn't see any errors or events ($val/$events)"
134         fi
135
136         if [ $val -ne $events ] ; then
137                 log_fail "$val $POOLTYPE $str errors != $events events"
138         else
139                 log_note "$val $POOLTYPE $str errors == $events events"
140         fi
141
142         log_must zpool destroy $POOL
143 }
144
145 # Test all types of errors on mirror and raidz pools
146 for pooltype in mirror raidz ; do
147         do_test $pooltype corrupt read
148         do_test $pooltype io read
149         do_test $pooltype io write
150 done
151
152 log_pass "The number of errors matched the number of events"