1#!/bin/ksh -p 2# SPDX-License-Identifier: CDDL-1.0 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 2018, loli10K <ezomori.nozomu@gmail.com>. All rights reserved. 20# 21 22. $STF_SUITE/include/libtest.shlib 23. $STF_SUITE/include/math.shlib 24. $STF_SUITE/tests/functional/fault/fault.cfg 25 26# 27# DESCRIPTION: 28# Spare devices (both files and disks) can be shared among different ZFS pools. 29# 30# STRATEGY: 31# 1. Create two pools 32# 2. Add the same spare device to different pools 33# 3. Inject IO errors with a zinject error handler 34# 4. Start a scrub 35# 5. Verify the ZED kicks in a hot spare and check pool/device status 36# 6. Clear the fault 37# 7. Verify the hot spare is available and check pool/device status 38# 39 40verify_runnable "both" 41 42if is_linux; then 43 # Add one 512b spare device (4Kn would generate IO errors on replace) 44 # NOTE: must be larger than other "file" vdevs and minimum SPA devsize: 45 # add 32m of fudge 46 load_scsi_debug $(($MINVDEVSIZE/1024/1024+32)) 1 1 1 '512b' 47else 48 log_unsupported "scsi debug module unsupported" 49fi 50 51function cleanup 52{ 53 log_must zinject -c all 54 destroy_pool $TESTPOOL 55 destroy_pool $TESTPOOL1 56 unload_scsi_debug 57 rm -f $SAFE_FILEDEVPOOL1 $SAFE_FILEDEVPOOL2 $FAIL_FILEDEVPOOL1 \ 58 $FAIL_FILEDEVPOOL2 $SPARE_FILEDEV 59} 60 61log_assert "Spare devices can be shared among different ZFS pools" 62log_onexit cleanup 63 64# Clear events from previous runs 65zed_events_drain 66 67SAFE_FILEDEVPOOL1="$TEST_BASE_DIR/file-safe-dev1" 68FAIL_FILEDEVPOOL1="$TEST_BASE_DIR/file-fail-dev1" 69SAFE_FILEDEVPOOL2="$TEST_BASE_DIR/file-safe-dev2" 70FAIL_FILEDEVPOOL2="$TEST_BASE_DIR/file-fail-dev2" 71SPARE_FILEDEV="$TEST_BASE_DIR/file-spare-dev" 72SPARE_DISKDEV="$(get_debug_device)" 73 74log_must truncate -s $MINVDEVSIZE $SAFE_FILEDEVPOOL1 $SAFE_FILEDEVPOOL2 $FAIL_FILEDEVPOOL1 $FAIL_FILEDEVPOOL2 $SPARE_FILEDEV 75 76for spare in $SPARE_FILEDEV $SPARE_DISKDEV; do 77 # 1. Create two pools 78 log_must zpool create -f $TESTPOOL mirror $SAFE_FILEDEVPOOL1 $FAIL_FILEDEVPOOL1 79 log_must zpool create -f $TESTPOOL1 mirror $SAFE_FILEDEVPOOL2 $FAIL_FILEDEVPOOL2 80 81 # 2. Add the same spare device to different pools 82 log_must_busy zpool add $TESTPOOL spare $spare 83 log_must_busy zpool add $TESTPOOL1 spare $spare 84 log_must wait_hotspare_state $TESTPOOL $spare "AVAIL" 85 log_must wait_hotspare_state $TESTPOOL1 $spare "AVAIL" 86 87 # 3. Inject IO errors with a zinject error handler 88 log_must zinject -d $FAIL_FILEDEVPOOL1 -e io -T all -f 100 $TESTPOOL 89 log_must zinject -d $FAIL_FILEDEVPOOL2 -e io -T all -f 100 $TESTPOOL1 90 91 # 4. Start a scrub 92 log_must zpool scrub $TESTPOOL 93 log_must zpool scrub $TESTPOOL1 94 95 # 5. Verify the ZED kicks in a hot spare and check pool/device status 96 log_note "Wait for ZED to auto-spare" 97 log_must wait_vdev_state $TESTPOOL $FAIL_FILEDEVPOOL1 "FAULTED" 60 98 log_must wait_vdev_state $TESTPOOL $spare "ONLINE" 60 99 log_must wait_hotspare_state $TESTPOOL $spare "INUSE" 100 log_must check_state $TESTPOOL "" "DEGRADED" 101 102 # 6. Clear the fault 103 log_must zinject -c all 104 log_must zpool clear $TESTPOOL $FAIL_FILEDEVPOOL1 105 106 # 7. Verify the hot spare is available and check pool/device status 107 log_must wait_vdev_state $TESTPOOL $FAIL_FILEDEVPOOL1 "ONLINE" 60 108 log_must wait_hotspare_state $TESTPOOL $spare "AVAIL" 109 log_must is_pool_resilvered $TESTPOOL 110 log_must check_state $TESTPOOL "" "ONLINE" 111 112 # Cleanup 113 destroy_pool $TESTPOOL 114 destroy_pool $TESTPOOL1 115done 116 117log_pass "Spare devices can be shared among different ZFS pools" 118