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 2009 Sun Microsystems, Inc.  All rights reserved.
25# Use is subject to license terms.
26#
27# ident	"@(#)zinject_004_pos.ksh	1.6	09/06/22 SMI"
28#
29
30###############################################################################
31#
32# __stc_assertion_start
33#
34# ID: zinject_004_pos
35#
36# DESCRIPTION:
37#
38# Inject an error into the device of a pool.
39# Verify fmdump will get the expect ereport,
40# and the fault class of "fault.fs.zfs.vdev.io" be generated.
41#
42# STRATEGY:
43# 1) Populate ZFS file system
44# 2) Inject an error into the device of the pool.
45# 3) Verify fmdump get the ereport as expected.
46#	<Errno>		<Expect ereport>
47#	nxio		ereport.fs.zfs.probe_failure
48#	io		ereport.fs.zfs.probe_failure
49# 4) Verify the fault class of "fault.fs.zfs.vdev.io" be generated.
50#
51# TESTABILITY: explicit
52#
53# TEST_AUTOMATION_LEVEL: automated
54#
55# CODING_STATUS: COMPLETED (2007-05-31)
56#
57# __stc_assertion_end
58#
59################################################################################
60
61. $STF_SUITE/tests/zinject/zinject.kshlib
62
63verify_runnable "global"
64
65log_assert "Verify fault inject handle device error successfully."
66log_onexit cleanup_env
67
68set -A types "mirror" "raidz" "raidz2"
69
70typeset -i maxnumber=1
71
72function test_zinject
73{
74	typeset basedir=$1
75	typeset -i i=0
76	typeset etype="device"
77	typeset fclass="fault.fs.zfs.vdev.io"
78
79	set -A errset \
80		"nxio" "ereport.fs.zfs.probe_failure" \
81		"io" "ereport.fs.zfs.probe_failure"
82
83	set -A alldevarray $alldevs
84
85	for device in $(random_string alldevarray 1); do
86		i=0
87		while ((i < ${#errset[*]} )); do
88			now=`date '+%m/%d/%y %H:%M:%S'`
89			inject_device $device $TESTPOOL ${errset[i]}
90
91			trigger_inject $etype $basedir/testfile.$maxnumber "file"
92			log_must check_ereport "$now" ${errset[((i+1))]}
93			log_must check_fault "$now" $fclass
94
95			inject_clear
96
97			now=`date '+%m/%d/%y %H:%M:%S'`
98			inject_device $device $TESTPOOL ${errset[i]}
99
100			trigger_inject $etype $basedir/testdir.$maxnumber "dir"
101			log_must check_ereport "$now" ${errset[((i+1))]}
102			log_must check_fault "$now" $fclass
103
104			inject_clear
105
106			(( i = i + 2 ))
107		done
108	done
109}
110
111inject_clear
112for type in "${types[@]}"; do
113	create_pool $TESTPOOL $type $pooldevs spare $sparedevs
114
115	log_must $ZPOOL add -f $TESTPOOL log $logdevs
116	log_must $ZPOOL add -f $TESTPOOL cache $cachedevs
117
118        log_must $ZPOOL replace $TESTPOOL $VDEV0 $sparedevs
119	log_must $ZFS create $TESTPOOL/$TESTFS
120	log_must $ZFS set mountpoint=$TESTDIR $TESTPOOL/$TESTFS
121
122	populate_test_env $TESTDIR $maxnumber
123	test_zinject $TESTDIR
124
125	cleanup_env
126done
127
128log_pass "Fault inject handle device error successfully."
129