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 https://opensource.org/licenses/CDDL-1.0. 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. Create a mirrored pool 41# 2. Create a file using each checksum 42# 3. Export/import/scrub the pool 43# 4. Verify there's no checksum errors. 44# 5. Clear the pool 45# 46# Test 2 47# 6. For each checksum: 48# 7. Create a file using the checksum 49# 8. Corrupt all level 0 blocks in the file 50# 9. Scrub the pool 51# 10. Verify that there are checksum errors 52 53verify_runnable "both" 54 55function cleanup 56{ 57 rm -fr $TESTDIR/* 58} 59 60log_assert "Create and read back files with using different checksum algorithms" 61 62log_onexit cleanup 63 64WRITESZ=1048576 65NWRITES=5 66 67# Get a list of vdevs in our pool 68set -A array $(get_disklist_fullpath) 69 70# Get the first vdev, since we will corrupt it later 71firstvdev=${array[0]} 72 73# Test each checksum by writing a file using it, confirm there are no errors. 74typeset -i i=1 75while [[ $i -lt ${#CHECKSUM_TYPES[*]} ]]; do 76 type=${CHECKSUM_TYPES[i]} 77 log_must zfs set checksum=$type $TESTPOOL 78 log_must file_write -o overwrite -f $TESTDIR/test_$type \ 79 -b $WRITESZ -c $NWRITES -d R 80 (( i = i + 1 )) 81done 82 83log_must zpool export $TESTPOOL 84log_must zpool import $TESTPOOL 85log_must zpool scrub $TESTPOOL 86log_must wait_scrubbed $TESTPOOL 87 88cksum=$(zpool status -P -v $TESTPOOL | awk -v v="$firstvdev" '$0 ~ v {print $5}') 89log_assert "Normal file write test saw $cksum checksum errors" 90log_must [ $cksum -eq 0 ] 91 92rm -fr $TESTDIR/* 93 94log_assert "Test corrupting the files and seeing checksum errors" 95typeset -i j=1 96while [[ $j -lt ${#CHECKSUM_TYPES[*]} ]]; do 97 type=${CHECKSUM_TYPES[$j]} 98 log_must zfs set checksum=$type $TESTPOOL 99 log_must file_write -o overwrite -f $TESTDIR/test_$type \ 100 -b $WRITESZ -c $NWRITES -d R 101 102 # Corrupt the level 0 blocks of this file 103 corrupt_blocks_at_level $TESTDIR/test_$type 104 105 log_must zpool scrub $TESTPOOL 106 log_must wait_scrubbed $TESTPOOL 107 108 cksum=$(zpool status -P -v $TESTPOOL | awk -v v="$firstvdev" '$0 ~ v {print $5}') 109 110 log_assert "Checksum '$type' caught $cksum checksum errors" 111 log_must [ $cksum -ne 0 ] 112 113 rm -f $TESTDIR/test_$type 114 log_must zpool clear $TESTPOOL 115 116 (( j = j + 1 )) 117done 118