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