1#!/usr/local/bin/ksh93 -p
2#
3# CDDL HEADER START
4#
5# The contents of this file are subject to the terms of the
6# Common Development and Distribution License (the "License").
7# You may not use this file except in compliance with the License.
8#
9# You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
10# or http://www.opensolaris.org/os/licensing.
11# See the License for the specific language governing permissions
12# and limitations under the License.
13#
14# When distributing Covered Code, include this CDDL HEADER in each
15# file and include the License file at usr/src/OPENSOLARIS.LICENSE.
16# If applicable, add the following below this CDDL HEADER, with the
17# fields enclosed by brackets "[]" replaced with your own identifying
18# information: Portions Copyright [yyyy] [name of copyright owner]
19#
20# CDDL HEADER END
21#
22
23#
24# Copyright (c) 2012-2014 Spectra Logic Corporation.  All rights reserved.
25# Use is subject to license terms.
26#
27
28. $STF_SUITE/include/libtest.kshlib
29. $STF_SUITE/tests/zfsd/zfsd.kshlib
30
31################################################################################
32#
33# __stc_assertion_start
34#
35# ID: zfsd_degrade_002_pos
36#
37# DESCRIPTION:
38#   If an active hotspare experiences checksum errors, it will become degraded.
39#
40#
41# STRATEGY:
42#   1. Create a storage pool with a hotspare.  Only use the file vdevs because
43#      it is easy to generate checksum errors on them.
44#   2. fault a vdev to active the hotspare
45#   3. Mostly fill the pool with data.
46#   4. Corrupt it by DDing to the hotspare's underlying file.
47#   5. Verify that the hotspare becomes DEGRADED.
48#   6. ONLINE it and verify that it resilvers and joins the pool.
49#
50# TESTABILITY: explicit
51#
52# TEST_AUTOMATION_LEVEL: automated
53#
54# CODING STATUS: COMPLETED (2014-05-13)
55#
56# __stc_assertion_end
57#
58###############################################################################
59
60verify_runnable "global"
61
62VDEV0=${TMPDIR}/file0.${TESTCASE_ID}
63VDEV1=${TMPDIR}/file1.${TESTCASE_ID}
64SPARE_VDEV=${TMPDIR}/file2.${TESTCASE_ID}
65BASIC_VDEVS="${VDEV0} ${VDEV1}"
66VDEVS="${BASIC_VDEVS} ${SPARE_VDEV}"
67TESTFILE=/$TESTPOOL/testfile
68VDEV_SIZE=192m
69
70
71function cleanup
72{
73	destroy_pool $TESTPOOL
74	$RM -f $VDEVS
75}
76
77log_assert "ZFS will degrade a spare vdev that produces checksum errors"
78
79log_onexit cleanup
80
81ensure_zfsd_running
82log_must create_vdevs $VDEV0 $VDEV1 $SPARE_VDEV
83
84for type in "mirror" "raidz"; do
85	log_note "Testing raid type $type"
86
87	create_pool $TESTPOOL $type ${BASIC_VDEVS} spare ${SPARE_VDEV}
88
89	# Activate the hotspare
90	$ZINJECT -d ${VDEV0} -A fault $TESTPOOL
91
92	# ZFSD can take up to 60 seconds to replace a failed device
93	# (though it's usually faster).
94	wait_for_pool_dev_state_change 60 $SPARE_VDEV INUSE
95
96	corrupt_pool_vdev $TESTPOOL $SPARE_VDEV $TESTFILE
97	destroy_pool $TESTPOOL
98done
99
100cleanup
101log_pass
102