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