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]
23 . $STF_SUITE/include/libtest.shlib
24 . $STF_SUITE/include/properties.shlib
27 # Sanity test to make sure checksum algorithms work.
28 # For each checksum, create a file in the pool using that checksum. Verify
29 # that there are no checksum errors. Next, for each checksum, create a single
30 # file in the pool using that checksum, scramble the underlying vdev, and
31 # verify that we correctly catch the checksum errors.
35 # 1. Create a mirrored pool
36 # 2. Create a file using each checksum
37 # 3. Export/import/scrub the pool
38 # 4. Verify there's no checksum errors.
42 # 6. For each checksum:
43 # 7. Create a file using the checksum
45 # 9. Scramble the data on one of the underlying VDEVs
48 # 12. Verify that there are checksum errors
50 verify_runnable "both"
55 [[ -e $TESTDIR ]] && \
56 log_must $RM -rf $TESTDIR/* > /dev/null 2>&1
59 log_assert "Create and read back files with using different checksum algorithms"
63 FSSIZE=$($ZPOOL list -Hp -o size $TESTPOOL)
65 WRITECNT=$((($FSSIZE) / $WRITESZ ))
66 # Skip the first and last 4MB
68 SKIPCNT=$((($SKIP / $WRITESZ )))
69 SKIPCNT=$((($SKIPCNT * 2)))
70 WRITECNT=$((($WRITECNT - $SKIPCNT)))
72 # Get a list of vdevs in our pool
73 set -A array $(get_disklist_fullpath)
75 # Get the first vdev, since we will corrupt it later
78 # First test each checksum by writing a file using it, and confirm there's no
80 for ((count = 0; count < ${#checksum_props[*]} ; count++)); do
81 i=${checksum_props[$count]}
82 $ZFS set checksum=$i $TESTPOOL
83 $FILE_WRITE -o overwrite -f $TESTDIR/test_$i -b $WRITESZ -c 5 -d R
85 $ZPOOL export $TESTPOOL
86 $ZPOOL import $TESTPOOL
87 $ZPOOL scrub $TESTPOOL
88 while is_pool_scrubbing $TESTPOOL; do
91 $ZPOOL status -P -v $TESTPOOL | grep $firstvdev | read -r name state rd wr cksum
92 log_assert "Normal file write test saw $cksum checksum errors"
93 log_must [ $cksum -eq 0 ]
97 log_assert "Test scrambling the disk and seeing checksum errors"
98 for ((count = 0; count < ${#checksum_props[*]} ; count++)); do
99 i=${checksum_props[$count]}
100 $ZFS set checksum=$i $TESTPOOL
101 $FILE_WRITE -o overwrite -f $TESTDIR/test_$i -b $WRITESZ -c 5 -d R
103 $ZPOOL export $TESTPOOL
105 # Scramble the data on the first vdev in our pool.
106 # Skip the first and last 16MB of data, then scramble the rest after that
108 $FILE_WRITE -o overwrite -f $firstvdev -s $SKIP -c $WRITECNT -b $WRITESZ -d R
110 $ZPOOL import $TESTPOOL
112 i=${checksum_props[$count]}
113 $ZPOOL scrub $TESTPOOL
114 while is_pool_scrubbing $TESTPOOL; do
118 $ZPOOL status -P -v $TESTPOOL | grep $firstvdev | read -r name state rd wr cksum
120 log_assert "Checksum '$i' caught $cksum checksum errors"
121 log_must [ $cksum -ne 0 ]
123 rm -f $TESTDIR/test_$i
124 $ZPOOL clear $TESTPOOL