Skip to content

Commit d671c28

Browse files
Ryan Moellerjsai20
authored andcommitted
ZTS: Add L1 corruption test
Add a new test case which corrupts all level 1 block in a file. Then verifies that corruption is detected and repaired. Reviewed-by: Brian Behlendorf <[email protected]> Signed-off-by: Ryan Moeller <[email protected]> Closes openzfs#11141
1 parent e9f6fa5 commit d671c28

File tree

4 files changed

+98
-4
lines changed

4 files changed

+98
-4
lines changed

tests/runfiles/common.run

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,8 @@ tests = ['tst.destroy_fs', 'tst.destroy_snap', 'tst.get_count_and_limit',
9999
tags = ['functional', 'channel_program', 'synctask_core']
100100

101101
[tests/functional/checksum]
102-
tests = ['run_sha2_test', 'run_skein_test', 'filetest_001_pos']
102+
tests = ['run_sha2_test', 'run_skein_test', 'filetest_001_pos',
103+
'filetest_002_pos']
103104
tags = ['functional', 'checksum']
104105

105106
[tests/functional/clean_mirror]

tests/zfs-tests/tests/functional/checksum/Makefile.am

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,8 @@ dist_pkgdata_SCRIPTS = \
1212
run_edonr_test.ksh \
1313
run_sha2_test.ksh \
1414
run_skein_test.ksh \
15-
filetest_001_pos.ksh
15+
filetest_001_pos.ksh \
16+
filetest_002_pos.ksh
1617

1718
dist_pkgdata_DATA = \
1819
default.cfg

tests/zfs-tests/tests/functional/checksum/filetest_001_pos.ksh

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,7 @@ log_assert "Create and read back files with using different checksum algorithms"
6262
log_onexit cleanup
6363

6464
WRITESZ=1048576
65+
NWRITES=5
6566

6667
# Get a list of vdevs in our pool
6768
set -A array $(get_disklist_fullpath)
@@ -75,7 +76,7 @@ while [[ $i -lt ${#CHECKSUM_TYPES[*]} ]]; do
7576
type=${CHECKSUM_TYPES[i]}
7677
log_must zfs set checksum=$type $TESTPOOL
7778
log_must file_write -o overwrite -f $TESTDIR/test_$type \
78-
-b $WRITESZ -c 5 -d R
79+
-b $WRITESZ -c $NWRITES -d R
7980
(( i = i + 1 ))
8081
done
8182

@@ -96,7 +97,7 @@ while [[ $j -lt ${#CHECKSUM_TYPES[*]} ]]; do
9697
type=${CHECKSUM_TYPES[$j]}
9798
log_must zfs set checksum=$type $TESTPOOL
9899
log_must file_write -o overwrite -f $TESTDIR/test_$type \
99-
-b $WRITESZ -c 5 -d R
100+
-b $WRITESZ -c $NWRITES -d R
100101

101102
# Corrupt the level 0 blocks of this file
102103
corrupt_blocks_at_level $TESTDIR/test_$type
Lines changed: 91 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,91 @@
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 (c) 2018, 2019 by Delphix. All rights reserved.
25+
#
26+
27+
. $STF_SUITE/include/libtest.shlib
28+
. $STF_SUITE/include/properties.shlib
29+
. $STF_SUITE/tests/functional/checksum/default.cfg
30+
31+
# DESCRIPTION:
32+
# Sanity test to make sure checksum algorithms work.
33+
# For each checksum, create a file in the pool using that checksum. Verify
34+
# that there are no checksum errors. Next, for each checksum, create a single
35+
# file in the pool using that checksum, corrupt the file, and verify that we
36+
# correctly catch the checksum errors.
37+
#
38+
# STRATEGY:
39+
# Test 1
40+
# 1. For each checksum:
41+
# 2. Create a file using the checksum
42+
# 3. Corrupt all level 1 blocks in the file
43+
# 4. Export and import the pool
44+
# 5. Verify that there are checksum errors
45+
46+
verify_runnable "both"
47+
48+
function cleanup
49+
{
50+
rm -fr $TESTDIR/*
51+
}
52+
53+
log_assert "Test corrupting files at L1 and seeing checksum errors"
54+
55+
log_onexit cleanup
56+
57+
WRITESZ=1048576
58+
NWRITES=5
59+
60+
# Get a list of vdevs in our pool
61+
set -A array $(get_disklist_fullpath)
62+
63+
# Get the first vdev, since we will corrupt it later
64+
firstvdev=${array[0]}
65+
66+
typeset -i j=1
67+
while [[ $j -lt ${#CHECKSUM_TYPES[*]} ]]; do
68+
type=${CHECKSUM_TYPES[$j]}
69+
log_must zfs set checksum=$type $TESTPOOL
70+
log_must file_write -o overwrite -f $TESTDIR/test_$type \
71+
-b $WRITESZ -c $NWRITES -d R
72+
73+
# Corrupt the level 1 blocks of this file
74+
corrupt_blocks_at_level $TESTDIR/test_$type 1
75+
76+
log_must zpool export $TESTPOOL
77+
log_must zpool import $TESTPOOL
78+
79+
log_mustnot eval "cat $TESTDIR/test_$type >/dev/null"
80+
81+
cksum=$(zpool status -P -v $TESTPOOL | grep "$firstvdev" | \
82+
awk '{print $5}')
83+
84+
log_assert "Checksum '$type' caught $cksum checksum errors"
85+
log_must [ $cksum -ne 0 ]
86+
87+
rm -f $TESTDIR/test_$type
88+
log_must zpool clear $TESTPOOL
89+
90+
(( j = j + 1 ))
91+
done

0 commit comments

Comments
 (0)