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