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
45	destroy_pool $TESTPOOL
46	rm -f $VDEV_FILES $SPARE_FILE
47}
48
49log_assert "Testing automated auto-spare FMA test"
50
51log_onexit cleanup
52
53# Events not supported on FreeBSD
54if ! is_freebsd; then
55	# Clear events from previous runs
56	zed_events_drain
57fi
58
59TESTFILE="/$TESTPOOL/$TESTFS/testfile"
60
61for type in "mirror" "raidz" "raidz2"; do
62	# 1. Create a pool with hot spares
63	truncate -s $SPA_MINDEVSIZE $VDEV_FILES $SPARE_FILE
64	log_must zpool create -f $TESTPOOL $type $VDEV_FILES spare $SPARE_FILE
65
66	# 2. Create a filesystem with the primary cache disable to force reads
67	log_must zfs create -o primarycache=none $TESTPOOL/$TESTFS
68	log_must zfs set recordsize=16k $TESTPOOL/$TESTFS
69
70	# 3. Write a file to the pool to be read back
71	log_must dd if=/dev/urandom of=$TESTFILE bs=1M count=16
72
73	# 4. Inject CHECKSUM ERRORS on read with a zinject error handler
74	log_must zinject -d $FAULT_FILE -e corrupt -f 50 -T read $TESTPOOL
75	log_must cp $TESTFILE /dev/null
76
77	# 5. Verify the ZED kicks in a hot spare and expected pool/device status
78	log_note "Wait for ZED to auto-spare"
79	log_must wait_vdev_state $TESTPOOL $FAULT_FILE "DEGRADED" 60
80	log_must wait_vdev_state $TESTPOOL $SPARE_FILE "ONLINE" 60
81	log_must wait_hotspare_state $TESTPOOL $SPARE_FILE "INUSE"
82	log_must check_state $TESTPOOL "" "DEGRADED"
83
84	# 6. Clear the fault
85	log_must zinject -c all
86	log_must zpool clear $TESTPOOL $FAULT_FILE
87
88	# 7. Verify the hot spare is available and expected pool/device status
89	log_must wait_vdev_state $TESTPOOL $FAULT_FILE "ONLINE" 60
90	log_must wait_hotspare_state $TESTPOOL $SPARE_FILE "AVAIL"
91	log_must check_state $TESTPOOL "" "ONLINE"
92
93	cleanup
94done
95
96log_pass "Auto-spare test successful"
97