]> CyberLeo.Net >> Repos - FreeBSD/FreeBSD.git/blob - tests/zfs-tests/tests/functional/fault/auto_spare_ashift.ksh
Vendor import of openzfs master @ 184df27eef0abdc7ab2105b21257f753834b936b
[FreeBSD/FreeBSD.git] / tests / zfs-tests / tests / functional / fault / auto_spare_ashift.ksh
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
42 verify_runnable "both"
43
44 function 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
52 log_assert "ZED should replace a device using the configured ashift property"
53 log_onexit cleanup
54
55 # Clear events from previous runs
56 zed_events_drain
57
58 SAFE_DEVICE="$TEST_BASE_DIR/safe-dev"
59 FAIL_DEVICE="$TEST_BASE_DIR/fail-dev"
60
61 # 1. Create a pool from 512b devices and set "ashift" pool property accordingly
62 for vdev in $SAFE_DEVICE $FAIL_DEVICE; do
63         truncate -s $SPA_MINDEVSIZE $vdev
64 done
65 log_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"
67 for vdev in $SAFE_DEVICE $FAIL_DEVICE; do
68         verify_eq "9" "$(zdb -e -l $vdev | awk '/ashift: /{print $2}')" "ashift"
69 done
70 log_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
74 load_scsi_debug $(($SPA_MINDEVSIZE/1024/1024+32)) $SDHOSTS $SDTGTS $SDLUNS '512e'
75 SPARE_DEVICE=$(get_debug_device)
76 log_must_busy zpool add $TESTPOOL spare $SPARE_DEVICE
77
78 # 3. Inject IO errors with a zinject error handler
79 log_must zinject -d $FAIL_DEVICE -e io -T all -f 100 $TESTPOOL
80
81 # 4. Start a scrub
82 log_must zpool scrub $TESTPOOL
83
84 # 5. Verify the ZED kicks in a hot spare and expected pool/device status
85 log_note "Wait for ZED to auto-spare"
86 log_must wait_vdev_state $TESTPOOL $FAIL_DEVICE "FAULTED" 60
87 log_must wait_vdev_state $TESTPOOL $SPARE_DEVICE "ONLINE" 60
88 log_must wait_hotspare_state $TESTPOOL $SPARE_DEVICE "INUSE"
89 log_must check_state $TESTPOOL "" "DEGRADED"
90
91 # 6. Clear the fault
92 log_must zinject -c all
93 log_must zpool clear $TESTPOOL $FAIL_DEVICE
94
95 # 7. Verify the hot spare is available and expected pool/device status
96 log_must wait_vdev_state $TESTPOOL $FAIL_DEVICE "ONLINE" 60
97 log_must wait_hotspare_state $TESTPOOL $SPARE_DEVICE "AVAIL"
98 log_must is_pool_resilvered $TESTPOOL
99 log_must check_state $TESTPOOL "" "ONLINE"
100
101 log_pass "ZED successfully replaces a device using the configured ashift property"