xref: /freebsd/tests/sys/cddl/zfs/tests/zinject/zinject_003_pos.ksh (revision 47dd1d1b619cc035b82b49a91a25544309ff95ae)
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_003_pos.ksh	1.3	09/06/22 SMI"
30#
31
32###############################################################################
33#
34# __stc_assertion_start
35#
36# ID: zinject_003_pos
37#
38# DESCRIPTION:
39#
40# Inject an error into the first metadnode in the block
41# Verify the filesystem unmountable since dnode be injected.
42#
43# STRATEGY:
44# 1) Populate ZFS file system
45# 2) Inject an error into the first metadnode in the block.
46# 3) Verify the filesystem unmountable,
47#	and 'zpool status -v' will display the error as expect.
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 into first metadnode " \
64	"cause filesystem unmountable."
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 1
84
85	unmounted $TESTPOOL/$TESTFS || \
86		log_fail "$TESTPOOL/$TESTFS mount unexpected."
87
88	log_must check_status $TESTPOOL "$TESTPOOL/$TESTFS:<0x0>"
89
90	inject_clear
91
92	log_must $ZFS mount -a
93}
94
95function test_zinject
96{
97	typeset basedir=$1
98	typeset pooltype=$2
99	typeset -i i=0
100	typeset etype="dnode"
101
102	set -A errset "io" "ereport.fs.zfs.io ereport.fs.zfs.data"
103
104	((i=${#errset[*]}))
105	if [[ -n $pooltype ]] ; then
106		errset[i]="checksum"
107		errset[((i+1))]="ereport.fs.zfs.checksum ereport.fs.zfs.data"
108	else
109		errset[i]="checksum"
110		errset[((i+1))]="ereport.fs.zfs.data"
111	fi
112
113	i=0
114	while ((i < ${#errset[*]} )); do
115		for object in $basedir/testfile.$maxnumber \
116			$basedir/testdir.$maxnumber ; do
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/bad_dir $maxnumber
137
138	test_zinject $TESTDIR/bad_dir $type
139
140	cleanup_env
141done
142
143log_pass "Fault inject handle into first metadnode " \
144	"cause filesystem unmountable."
145