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