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###############################################################################
28#
29# __stc_assertion_start
30#
31# ID: zinject_001_pos
32#
33# DESCRIPTION:
34#
35# Inject an error into the plain file contents of a file.
36# Verify fmdump will get the expect ereport
37#
38# STRATEGY:
39# 1) Populate ZFS file system
40# 2) Inject an error into the plain file contents of a file.
41# 3) Verify fmdump get the ereport as expect.
42#	<Errno>		<Expect ereport>		<Comments>
43#	io 		ereport.fs.zfs.io
44#			ereport.fs.zfs.data
45#	checksum	ereport.fs.zfs.checksum		Non-stripe pool
46#			ereport.fs.zfs.data
47#	checksum	ereport.fs.zfs.data		Stripe pool only
48#
49# TESTABILITY: explicit
50#
51# TEST_AUTOMATION_LEVEL: automated
52#
53# CODING_STATUS: COMPLETED (2007-02-01)
54#
55# __stc_assertion_end
56#
57################################################################################
58
59. $STF_SUITE/tests/zinject/zinject.kshlib
60
61verify_runnable "global"
62
63log_assert "Verify fault inject handle content error successfully."
64log_onexit cleanup_env
65
66set -A types "" "mirror" "raidz" "raidz2"
67
68typeset -i maxnumber=300
69
70function test_zinject_unit
71{
72	typeset etype=$1
73	typeset object=$2
74	typeset errno=$3
75	typeset ereport=$4
76	typeset now
77
78	typeset otype="file"
79	[[ -d $object ]] && otype="dir"
80
81	now=`date '+%m/%d/%y %H:%M:%S'`
82	inject_fault $etype $object $errno
83
84	trigger_inject $etype $object $otype
85
86	log_must check_ereport "$now" $ereport
87
88	log_must check_status $TESTPOOL $object
89
90	inject_clear
91}
92
93function test_zinject
94{
95	typeset basedir=$1
96	typeset pooltype=$2
97	typeset -i i=0
98	typeset etype="data"
99
100	set -A errset "io" "ereport.fs.zfs.io ereport.fs.zfs.data"
101
102	((i=${#errset[*]}))
103	if [[ -n $pooltype ]] ; then
104		errset[i]="checksum"
105		errset[((i+1))]="ereport.fs.zfs.checksum ereport.fs.zfs.data"
106	else
107		errset[i]="checksum"
108		errset[((i+1))]="ereport.fs.zfs.data"
109	fi
110
111	i=0
112	while ((i < ${#errset[*]} )); do
113
114		for object in $basedir/testfile.$maxnumber \
115			$basedir/testdir.$maxnumber ; do
116
117			test_zinject_unit $etype $object \
118				${errset[i]} "${errset[((i+1))]}"
119		done
120
121		(( i = i + 2 ))
122	done
123}
124
125inject_clear
126for type in "${types[@]}"; do
127	create_pool $TESTPOOL $type $pooldevs spare $sparedevs
128
129	log_must $ZPOOL add -f $TESTPOOL log $logdevs
130	log_must $ZPOOL add -f $TESTPOOL cache $cachedevs
131
132	log_must $ZPOOL replace $TESTPOOL $VDEV0 $sparedevs
133	log_must $ZFS create $TESTPOOL/$TESTFS
134	log_must $ZFS set mountpoint=$TESTDIR $TESTPOOL/$TESTFS
135
136	populate_test_env $TESTDIR $maxnumber
137	test_zinject $TESTDIR $type
138
139	cleanup_env
140done
141
142log_pass "Fault inject handle content error successfully."
143