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 https://opensource.org/licenses/CDDL-1.0. 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) 2022, Klara Inc. 24# 25 26# DESCRIPTION: 27# Verify that vdev properties, checksum_n and checksum_t, work with ZED. 28# 29# STRATEGY: 30# 1. Create a pool with single vdev 31# 2. Set checksum_n/checksum_t to non-default values 32# 3. Inject checksum errors 33# 4. Verify that ZED degrades vdev 34# 35 36. $STF_SUITE/include/libtest.shlib 37. $STF_SUITE/tests/functional/events/events_common.kshlib 38 39verify_runnable "both" 40 41MOUNTDIR="$TEST_BASE_DIR/checksum_mount" 42FILEPATH="$MOUNTDIR/checksum_file" 43VDEV="$TEST_BASE_DIR/vdevfile.$$" 44POOL="checksum_pool" 45FILESIZE="10M" 46 47function cleanup 48{ 49 log_must zed_stop 50 51 log_must zinject -c all 52 if poolexists $POOL ; then 53 destroy_pool $POOL 54 fi 55 log_must rm -fd $VDEV $MOUNTDIR 56} 57 58log_onexit cleanup 59 60log_assert "Test ZED checksum_N and checksum_T configurability" 61 62function do_setup 63{ 64 log_must zpool create -f -m $MOUNTDIR $POOL $VDEV 65 log_must zpool events -c 66 log_must truncate -s 0 $ZED_DEBUG_LOG 67 log_must zfs set compression=off $POOL 68 log_must zfs set primarycache=none $POOL 69 log_must zfs set recordsize=512 $POOL 70} 71 72function do_clean 73{ 74 log_must zinject -c all 75 log_must zpool destroy $POOL 76} 77 78function must_degrade 79{ 80 log_must wait_vdev_state $POOL $VDEV "DEGRADED" 60 81} 82 83function mustnot_degrade 84{ 85 log_must file_wait $ZED_DEBUG_LOG 5 86 log_must wait_vdev_state $POOL $VDEV "ONLINE" 60 87} 88 89# Test default settings of ZED: 90# checksum_n=10 91# checksum_t=600 92# fire 10 events, should degrade. 93function default_degrade 94{ 95 do_setup 96 97 log_must mkfile $FILESIZE $FILEPATH 98 log_must zinject -a -t data -e checksum -T read -f 100 $FILEPATH 99 100 blk=0 101 for _ in {1..10}; do 102 dd if=$FILEPATH of=/dev/null bs=1 count=1 skip=$blk 2>/dev/null 103 blk=$((blk+512)) 104 done 105 106 must_degrade 107 108 do_clean 109} 110 111# Set checksum_t=1 112# fire 10 events over 2.5 seconds, should not degrade. 113function checksum_t_no_degrade 114{ 115 do_setup 116 117 log_must zpool set checksum_t=1 $POOL $VDEV 118 log_must mkfile $FILESIZE $FILEPATH 119 log_must zinject -a -t data -e checksum -T read -f 100 $FILEPATH 120 121 blk=0 122 for _ in {1..10}; do 123 dd if=$FILEPATH of=/dev/null bs=1 count=1 skip=$blk 2>/dev/null 124 blk=$((blk+512)) 125 sleep 0.25 126 done 127 128 mustnot_degrade 129 130 do_clean 131} 132 133# Set checksum_n=1 134# fire 1 event, should degrade. 135function checksum_n_degrade 136{ 137 do_setup 138 139 log_must zpool set checksum_n=1 $POOL $VDEV 140 log_must mkfile $FILESIZE $FILEPATH 141 log_must zinject -a -t data -e checksum -T read -f 100 $FILEPATH 142 143 dd if=$FILEPATH of=/dev/null bs=1 count=1 2>/dev/null 144 145 must_degrade 146 147 do_clean 148} 149 150log_must truncate -s $MINVDEVSIZE $VDEV 151log_must mkdir -p $MOUNTDIR 152 153log_must zed_start 154default_degrade 155checksum_n_degrade 156checksum_t_no_degrade 157 158log_pass "Test ZED checksum_N and checksum_T configurability" 159