]> git.proxmox.com Git - mirror_zfs.git/blame - tests/zfs-tests/tests/functional/fault/auto_spare_002_pos.ksh
Add Linux posix_fadvise support
[mirror_zfs.git] / tests / zfs-tests / tests / functional / fault / auto_spare_002_pos.ksh
CommitLineData
d9daa7ab
DQ
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#
21
22. $STF_SUITE/include/libtest.shlib
23. $STF_SUITE/tests/functional/fault/fault.cfg
24
25#
26# DESCRIPTION:
27# Testing Fault Management Agent ZED Logic - Automated Auto-Spare Test when
28# drive is faulted due to CHECKSUM ERRORS.
29#
30# STRATEGY:
31# 1. Create a pool with hot spares
32# 2. Create a filesystem with the primary cache disable to force reads
33# 3. Write a file to the pool to be read back
34# 4. Inject CHECKSUM ERRORS on read with a zinject error handler
35# 5. Verify the ZED kicks in a hot spare and expected pool/device status
36# 6. Clear the fault
37# 7. Verify the hot spare is available and expected pool/device status
38#
39
40verify_runnable "both"
41
42function cleanup
43{
44 log_must zinject -c all
4e9b1569 45 destroy_pool $TESTPOOL
d9daa7ab
DQ
46 rm -f $VDEV_FILES $SPARE_FILE
47}
48
49log_assert "Testing automated auto-spare FMA test"
50
51log_onexit cleanup
52
7839c4b5
MM
53# Events not supported on FreeBSD
54if ! is_freebsd; then
55 # Clear events from previous runs
56 zed_events_drain
57fi
4e9b1569 58
d9daa7ab
DQ
59TESTFILE="/$TESTPOOL/$TESTFS/testfile"
60
61for type in "mirror" "raidz" "raidz2"; do
62 # 1. Create a pool with hot spares
b2255edc
BB
63 log_must truncate -s $MINVDEVSIZE $VDEV_FILES $SPARE_FILE
64 log_must zpool create -f $TESTPOOL $type $VDEV_FILES \
65 spare $SPARE_FILE
d9daa7ab
DQ
66
67 # 2. Create a filesystem with the primary cache disable to force reads
68 log_must zfs create -o primarycache=none $TESTPOOL/$TESTFS
69 log_must zfs set recordsize=16k $TESTPOOL/$TESTFS
70
71 # 3. Write a file to the pool to be read back
b2255edc 72 log_must dd if=/dev/urandom of=$TESTFILE bs=1M count=64
d9daa7ab
DQ
73
74 # 4. Inject CHECKSUM ERRORS on read with a zinject error handler
75 log_must zinject -d $FAULT_FILE -e corrupt -f 50 -T read $TESTPOOL
320f0c60 76 log_must dd if=$TESTFILE of=/dev/null bs=1M count=64
d9daa7ab
DQ
77
78 # 5. Verify the ZED kicks in a hot spare and expected pool/device status
79 log_note "Wait for ZED to auto-spare"
80 log_must wait_vdev_state $TESTPOOL $FAULT_FILE "DEGRADED" 60
81 log_must wait_vdev_state $TESTPOOL $SPARE_FILE "ONLINE" 60
82 log_must wait_hotspare_state $TESTPOOL $SPARE_FILE "INUSE"
83 log_must check_state $TESTPOOL "" "DEGRADED"
84
85 # 6. Clear the fault
86 log_must zinject -c all
87 log_must zpool clear $TESTPOOL $FAULT_FILE
88
89 # 7. Verify the hot spare is available and expected pool/device status
90 log_must wait_vdev_state $TESTPOOL $FAULT_FILE "ONLINE" 60
91 log_must wait_hotspare_state $TESTPOOL $SPARE_FILE "AVAIL"
92 log_must check_state $TESTPOOL "" "ONLINE"
93
94 cleanup
95done
96
97log_pass "Auto-spare test successful"