1#!/bin/ksh -p 2# SPDX-License-Identifier: CDDL-1.0 3 4# 5# CDDL HEADER START 6# 7# This file and its contents are supplied under the terms of the 8# Common Development and Distribution License ("CDDL"), version 1.0. 9# You may only use this file in accordance with the terms of version 10# 1.0 of the CDDL. 11# 12# A full copy of the text of the CDDL should have accompanied this 13# source. A copy of the CDDL is also available via the Internet at 14# http://www.illumos.org/license/CDDL. 15# 16# CDDL HEADER END 17# 18 19# 20# Copyright (c) 2017 by Intel Corporation. All rights reserved. 21# 22 23. $STF_SUITE/include/libtest.shlib 24. $STF_SUITE/tests/functional/fault/fault.cfg 25 26# 27# DESCRIPTION: 28# Testing Fault Management Agent ZED Logic - Automated Auto-Spare Test when 29# drive is faulted due to CHECKSUM ERRORS. 30# 31# STRATEGY: 32# 1. Create a pool with hot spares 33# 2. Create a filesystem with the primary cache disable to force reads 34# 3. Write a file to the pool to be read back 35# 4. Inject CHECKSUM ERRORS on read with a zinject error handler 36# 5. Verify the ZED kicks in a hot spare and expected pool/device status 37# 6. Clear the fault 38# 7. Verify the hot spare is available and expected pool/device status 39# 40 41verify_runnable "both" 42 43function cleanup 44{ 45 log_must zinject -c all 46 destroy_pool $TESTPOOL 47 rm -f $VDEV_FILES $SPARE_FILE 48} 49 50log_assert "Testing automated auto-spare FMA test" 51 52log_onexit cleanup 53 54# Events not supported on FreeBSD 55if ! is_freebsd; then 56 # Clear events from previous runs 57 zed_events_drain 58fi 59 60TESTFILE="/$TESTPOOL/$TESTFS/testfile" 61 62for type in "mirror" "raidz" "raidz2"; do 63 # 1. Create a pool with hot spares 64 log_must truncate -s $MINVDEVSIZE $VDEV_FILES $SPARE_FILE 65 log_must zpool create -f $TESTPOOL $type $VDEV_FILES \ 66 spare $SPARE_FILE 67 68 # 2. Create a filesystem with the primary cache disable to force reads 69 log_must zfs create -o primarycache=none $TESTPOOL/$TESTFS 70 log_must zfs set recordsize=16k $TESTPOOL/$TESTFS 71 72 # 3. Write a file to the pool to be read back 73 log_must dd if=/dev/urandom of=$TESTFILE bs=1M count=64 74 75 # 4. Inject CHECKSUM ERRORS on read with a zinject error handler 76 log_must zinject -d $FAULT_FILE -e corrupt -f 50 -T read $TESTPOOL 77 log_must dd if=$TESTFILE of=/dev/null bs=1M count=64 78 79 # 5. Verify the ZED kicks in a hot spare and expected pool/device status 80 log_note "Wait for ZED to auto-spare" 81 log_must wait_vdev_state $TESTPOOL $FAULT_FILE "DEGRADED" 60 82 log_must wait_vdev_state $TESTPOOL $SPARE_FILE "ONLINE" 60 83 log_must wait_hotspare_state $TESTPOOL $SPARE_FILE "INUSE" 84 log_must check_state $TESTPOOL "" "DEGRADED" 85 86 # 6. Clear the fault 87 log_must zinject -c all 88 log_must zpool clear $TESTPOOL $FAULT_FILE 89 90 # 7. Verify the hot spare is available and expected pool/device status 91 log_must wait_vdev_state $TESTPOOL $FAULT_FILE "ONLINE" 60 92 log_must wait_hotspare_state $TESTPOOL $SPARE_FILE "AVAIL" 93 log_must check_state $TESTPOOL "" "ONLINE" 94 95 cleanup 96done 97 98log_pass "Auto-spare test successful" 99