7290 ZFS test suite needs to control what utilities it can run
[unleashed.git] / usr / src / test / zfs-tests / tests / functional / replacement / replacement_003_pos.ksh
blobe143114eff49ee4a65eb8faf74564f5c1c120f34
1 #!/usr/bin/ksh -p
3 # CDDL HEADER START
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.
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.
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]
20 # CDDL HEADER END
24 # Copyright 2008 Sun Microsystems, Inc. All rights reserved.
25 # Use is subject to license terms.
29 # Copyright (c) 2013, 2016 by Delphix. All rights reserved.
32 . $STF_SUITE/include/libtest.shlib
33 . $STF_SUITE/tests/functional/replacement/replacement.cfg
36 # DESCRIPTION:
37 # Detaching disks during I/O should pass for supported pools.
39 # STRATEGY:
40 # 1. Create multidisk pools (stripe/mirror/raidz) and
41 # start some random I/O
42 # 2. Detach a disk from the pool.
43 # 3. Verify the integrity of the file system and the resilvering.
46 verify_runnable "global"
48 function cleanup
50 if [[ -n "$child_pids" ]]; then
51 for wait_pid in $child_pids
53 kill $wait_pid
54 done
57 if poolexists $TESTPOOL1; then
58 destroy_pool $TESTPOOL1
61 [[ -e $TESTDIR ]] && log_must rm -rf $TESTDIR/*
64 log_assert "Replacing a disk during I/O completes."
66 options=""
67 options_display="default options"
69 log_onexit cleanup
71 [[ -n "$HOLES_FILESIZE" ]] && options=" $options -f $HOLES_FILESIZE "
73 [[ -n "$HOLES_BLKSIZE" ]] && options="$options -b $HOLES_BLKSIZE "
75 [[ -n "$HOLES_COUNT" ]] && options="$options -c $HOLES_COUNT "
77 [[ -n "$HOLES_SEED" ]] && options="$options -s $HOLES_SEED "
79 [[ -n "$HOLES_FILEOFFSET" ]] && options="$options -o $HOLES_FILEOFFSET "
81 ptions="$options -r "
83 [[ -n "$options" ]] && options_display=$options
85 child_pids=""
87 function detach_test
89 typeset -i iters=2
90 typeset -i index=0
91 typeset disk1=$1
93 typeset i=0
94 while [[ $i -lt $iters ]]; do
95 log_note "Invoking file_trunc with: $options_display"
96 file_trunc $options $TESTDIR/$TESTFILE.$i &
97 typeset pid=$!
99 sleep 1
100 if ! ps -p $pid > /dev/null 2>&1; then
101 log_fail "file_trunc $options $TESTDIR/$TESTFILE.$i"
104 child_pids="$child_pids $pid"
105 ((i = i + 1))
106 done
108 log_must zpool detach $TESTPOOL1 $disk1
110 sleep 10
112 for wait_pid in $child_pids
114 kill $wait_pid
115 done
116 child_pids=""
118 log_must zpool export $TESTPOOL1
119 log_must zpool import -d $TESTDIR $TESTPOOL1
120 log_must zfs umount $TESTPOOL1/$TESTFS1
121 log_must zdb -cdui $TESTPOOL1/$TESTFS1
122 log_must zfs mount $TESTPOOL1/$TESTFS1
125 specials_list=""
127 while [[ $i != 2 ]]; do
128 mkfile $MINVDEVSIZE $TESTDIR/$TESTFILE1.$i
129 specials_list="$specials_list $TESTDIR/$TESTFILE1.$i"
131 ((i = i + 1))
132 done
134 create_pool $TESTPOOL1 mirror $specials_list
135 log_must zfs create $TESTPOOL1/$TESTFS1
136 log_must zfs set mountpoint=$TESTDIR1 $TESTPOOL1/$TESTFS1
138 detach_test $TESTDIR/$TESTFILE1.1
140 zpool iostat -v $TESTPOOL1 | grep "$TESTDIR/$TESTFILE1.1"
141 if [[ $? -eq 0 ]]; then
142 log_fail "$TESTFILE1.1 should no longer be present."
145 destroy_pool $TESTPOOL1
147 log_note "Verify 'zpool detach' fails with non-mirrors."
149 for type in "" "raidz" "raidz1" ; do
150 create_pool $TESTPOOL1 $type $specials_list
151 log_must zfs create $TESTPOOL1/$TESTFS1
152 log_must zfs set mountpoint=$TESTDIR1 $TESTPOOL1/$TESTFS1
154 log_mustnot zpool detach $TESTDIR/$TESTFILE1.1
156 zpool iostat -v $TESTPOOL1 | grep "$TESTDIR/$TESTFILE1.1"
157 if [[ $? -ne 0 ]]; then
158 log_fail "$TESTFILE1.1 is not present."
161 destroy_pool $TESTPOOL1
162 done
164 log_pass