1#!/bin/ksh -p 2 3# 4# CDDL HEADER START 5# 6# This file and its contents are supplied under the terms of the 7# Common Development and Distribution License ("CDDL"), version 1.0. 8# You may only use this file in accordance with the terms of version 9# 1.0 of the CDDL. 10# 11# A full copy of the text of the CDDL should have accompanied this 12# source. A copy of the CDDL is also available via the Internet at 13# http://www.illumos.org/license/CDDL. 14# 15# CDDL HEADER END 16# 17 18# 19# Copyright (c) 2017 by Intel Corporation. All rights reserved. 20# Copyright 2017, loli10K <ezomori.nozomu@gmail.com>. All rights reserved. 21# 22 23. $STF_SUITE/include/libtest.shlib 24. $STF_SUITE/include/math.shlib 25. $STF_SUITE/tests/functional/fault/fault.cfg 26 27# 28# DESCRIPTION: 29# Testing Fault Management Agent ZED Logic - Automated Auto-Spare Test when 30# drive is faulted and a custom ashift value needs to be provided to replace it. 31# 32# STRATEGY: 33# 1. Create a pool from 512b devices and set "ashift" pool property accordingly 34# 2. Add one 512e spare device (4Kn would generate IO errors on replace) 35# 3. Inject IO errors with a zinject error handler 36# 4. Start a scrub 37# 5. Verify the ZED kicks in the hot spare and expected pool/device status 38# 6. Clear the fault 39# 7. Verify the hot spare is available and expected pool/device status 40# 41 42verify_runnable "both" 43 44function cleanup 45{ 46 log_must zinject -c all 47 destroy_pool $TESTPOOL 48 unload_scsi_debug 49 rm -f $SAFE_DEVICE $FAIL_DEVICE 50} 51 52log_assert "ZED should replace a device using the configured ashift property" 53log_onexit cleanup 54 55# Clear events from previous runs 56zed_events_drain 57 58SAFE_DEVICE="$TEST_BASE_DIR/safe-dev" 59FAIL_DEVICE="$TEST_BASE_DIR/fail-dev" 60 61# 1. Create a pool from 512b devices and set "ashift" pool property accordingly 62for vdev in $SAFE_DEVICE $FAIL_DEVICE; do 63 truncate -s $MINVDEVSIZE $vdev 64done 65log_must zpool create -f $TESTPOOL mirror $SAFE_DEVICE $FAIL_DEVICE 66# NOTE: file VDEVs should be added as 512b devices, verify this "just in case" 67for vdev in $SAFE_DEVICE $FAIL_DEVICE; do 68 verify_eq "9" "$(zdb -e -l $vdev | awk '/ashift: /{print $2}')" "ashift" 69done 70log_must zpool set ashift=9 $TESTPOOL 71 72# 2. Add one 512e spare device (4Kn would generate IO errors on replace) 73# NOTE: must be larger than the existing 512b devices, add 32m of fudge 74load_scsi_debug $(($MINVDEVSIZE/1024/1024+32)) $SDHOSTS $SDTGTS $SDLUNS '512e' 75SPARE_DEVICE=$(get_debug_device) 76log_must_busy zpool add $TESTPOOL spare $SPARE_DEVICE 77 78# 3. Inject IO errors with a zinject error handler 79log_must zinject -d $FAIL_DEVICE -e io -T all -f 100 $TESTPOOL 80 81# 4. Start a scrub 82log_must zpool scrub $TESTPOOL 83 84# 5. Verify the ZED kicks in a hot spare and expected pool/device status 85log_note "Wait for ZED to auto-spare" 86log_must wait_vdev_state $TESTPOOL $FAIL_DEVICE "FAULTED" 60 87log_must wait_vdev_state $TESTPOOL $SPARE_DEVICE "ONLINE" 60 88log_must wait_hotspare_state $TESTPOOL $SPARE_DEVICE "INUSE" 89log_must check_state $TESTPOOL "" "DEGRADED" 90 91# 6. Clear the fault 92log_must zinject -c all 93log_must zpool clear $TESTPOOL $FAIL_DEVICE 94 95# 7. Verify the hot spare is available and expected pool/device status 96log_must wait_vdev_state $TESTPOOL $FAIL_DEVICE "ONLINE" 60 97log_must wait_hotspare_state $TESTPOOL $SPARE_DEVICE "AVAIL" 98log_must is_pool_resilvered $TESTPOOL 99log_must check_state $TESTPOOL "" "ONLINE" 100 101log_pass "ZED successfully replaces a device using the configured ashift property" 102