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