]> git.proxmox.com Git - mirror_zfs.git/blame - tests/zfs-tests/tests/functional/replacement/replacement_003_pos.ksh
freebsd: changes necessary to coexist with dtrace in tree
[mirror_zfs.git] / tests / zfs-tests / tests / functional / replacement / replacement_003_pos.ksh
CommitLineData
6bb24f4d
BB
1#!/bin/ksh -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 2008 Sun Microsystems, Inc. All rights reserved.
25# Use is subject to license terms.
26#
27
28#
c1d9abf9 29# Copyright (c) 2013, 2016 by Delphix. All rights reserved.
6bb24f4d
BB
30#
31
32. $STF_SUITE/include/libtest.shlib
33. $STF_SUITE/tests/functional/replacement/replacement.cfg
34
35#
36# DESCRIPTION:
37# Detaching disks during I/O should pass for supported pools.
38#
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.
44#
45
46verify_runnable "global"
47
48function cleanup
49{
50 if [[ -n "$child_pids" ]]; then
51 for wait_pid in $child_pids
52 do
c1d9abf9 53 kill $wait_pid
6bb24f4d
BB
54 done
55 fi
56
57 if poolexists $TESTPOOL1; then
58 destroy_pool $TESTPOOL1
59 fi
60
c1d9abf9 61 [[ -e $TESTDIR ]] && log_must rm -rf $TESTDIR/*
6bb24f4d
BB
62}
63
64log_assert "Replacing a disk during I/O completes."
65
66options=""
67options_display="default options"
68
69log_onexit cleanup
70
71[[ -n "$HOLES_FILESIZE" ]] && options=" $options -f $HOLES_FILESIZE "
72
73[[ -n "$HOLES_BLKSIZE" ]] && options="$options -b $HOLES_BLKSIZE "
74
75[[ -n "$HOLES_COUNT" ]] && options="$options -c $HOLES_COUNT "
76
77[[ -n "$HOLES_SEED" ]] && options="$options -s $HOLES_SEED "
78
79[[ -n "$HOLES_FILEOFFSET" ]] && options="$options -o $HOLES_FILEOFFSET "
80
81ptions="$options -r "
82
83[[ -n "$options" ]] && options_display=$options
84
85child_pids=""
86
87function detach_test
88{
89 typeset -i iters=2
90 typeset -i index=0
91 typeset disk1=$1
92
93 typeset i=0
94 while [[ $i -lt $iters ]]; do
c1d9abf9
JWK
95 log_note "Invoking file_trunc with: $options_display"
96 file_trunc $options $TESTDIR/$TESTFILE.$i &
6bb24f4d
BB
97 typeset pid=$!
98
c1d9abf9 99 sleep 1
6bb24f4d
BB
100
101 child_pids="$child_pids $pid"
102 ((i = i + 1))
103 done
104
c1d9abf9 105 log_must zpool detach $TESTPOOL1 $disk1
6bb24f4d 106
c1d9abf9 107 sleep 10
6bb24f4d
BB
108
109 for wait_pid in $child_pids
110 do
c1d9abf9 111 kill $wait_pid
6bb24f4d
BB
112 done
113 child_pids=""
114
c1d9abf9
JWK
115 log_must zpool export $TESTPOOL1
116 log_must zpool import -d $TESTDIR $TESTPOOL1
117 log_must zfs umount $TESTPOOL1/$TESTFS1
118 log_must zdb -cdui $TESTPOOL1/$TESTFS1
119 log_must zfs mount $TESTPOOL1/$TESTFS1
6bb24f4d
BB
120}
121
122specials_list=""
123i=0
124while [[ $i != 2 ]]; do
c1d9abf9 125 mkfile $MINVDEVSIZE $TESTDIR/$TESTFILE1.$i
6bb24f4d
BB
126 specials_list="$specials_list $TESTDIR/$TESTFILE1.$i"
127
128 ((i = i + 1))
129done
130
131create_pool $TESTPOOL1 mirror $specials_list
c1d9abf9
JWK
132log_must zfs create $TESTPOOL1/$TESTFS1
133log_must zfs set mountpoint=$TESTDIR1 $TESTPOOL1/$TESTFS1
6bb24f4d
BB
134
135detach_test $TESTDIR/$TESTFILE1.1
136
c1d9abf9 137zpool iostat -v $TESTPOOL1 | grep "$TESTDIR/$TESTFILE1.1"
6bb24f4d
BB
138if [[ $? -eq 0 ]]; then
139 log_fail "$TESTFILE1.1 should no longer be present."
140fi
141
142destroy_pool $TESTPOOL1
143
144log_note "Verify 'zpool detach' fails with non-mirrors."
145
146for type in "" "raidz" "raidz1" ; do
147 create_pool $TESTPOOL1 $type $specials_list
c1d9abf9
JWK
148 log_must zfs create $TESTPOOL1/$TESTFS1
149 log_must zfs set mountpoint=$TESTDIR1 $TESTPOOL1/$TESTFS1
6bb24f4d 150
c1d9abf9 151 log_mustnot zpool detach $TESTDIR/$TESTFILE1.1
6bb24f4d 152
c1d9abf9 153 zpool iostat -v $TESTPOOL1 | grep "$TESTDIR/$TESTFILE1.1"
6bb24f4d
BB
154 if [[ $? -ne 0 ]]; then
155 log_fail "$TESTFILE1.1 is not present."
156 fi
157
158 destroy_pool $TESTPOOL1
159done
160
161log_pass