7260 disable libdiskmgmt in zfstest unless it's required
[unleashed.git] / usr / src / test / zfs-tests / tests / functional / inuse / inuse_003_pos.ksh
blob9f17f9db6f6e4d42ae187d79940fd7099077b2ac
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) 2012, 2015 by Delphix. All rights reserved.
32 . $STF_SUITE/include/libtest.shlib
33 . $STF_SUITE/tests/functional/inuse/inuse.cfg
36 # DESCRIPTION:
37 # ZFS will not interfere with devices that are in use by ufsdump or
38 # ufsrestore.
40 # STRATEGY:
41 # 1. newfs a disk
42 # 2. mount the disk
43 # 3. create files and dirs on disk
44 # 4. umount the disk
45 # 5. ufsdump this disk to a backup disk
46 # 6. Try to create a ZFS pool with same disk (also as a spare device)
47 # 7. ufsrestore the disk from backup
48 # 8. try to create a zpool during the ufsrestore
51 verify_runnable "global"
53 function cleanup
55 poolexists $TESTPOOL1 && destroy_pool $TESTPOOL1
57 poolexists $TESTPOOL2 && destroy_pool $TESTPOOL2
59 log_note "Kill off ufsdump process if still running"
60 $KILL -0 $PIDUFSDUMP > /dev/null 2>&1 && \
61 log_must $KILL -9 $PIDUFSDUMP > /dev/null 2>&1
63 # Note: It would appear that ufsdump spawns a number of processes
64 # which are not killed when the $PIDUFSDUMP is whacked. So best bet
65 # is to find the rest of the them and deal with them individually.
67 for all in `$PGREP ufsdump`
69 $KILL -9 $all > /dev/null 2>&1
70 done
72 log_note "Kill off ufsrestore process if still running"
73 $KILL -0 $PIDUFSRESTORE > /dev/null 2>&1 && \
74 log_must $KILL -9 $PIDUFSRESTORE > /dev/null 2>&1
76 ismounted $UFSMP ufs && log_must $UMOUNT $UFSMP
78 $RM -rf $UFSMP
79 $RM -rf $TESTDIR
82 # Tidy up the disks we used.
84 log_must cleanup_devices $vdisks $sdisks
87 log_assert "Ensure ZFS does not interfere with devices that are in use by " \
88 "ufsdump or ufsrestore"
90 log_onexit cleanup
92 typeset bigdir="${UFSMP}/bigdirectory"
93 typeset restored_files="${UFSMP}/restored_files"
94 typeset -i dirnum=0
95 typeset -i filenum=0
96 typeset cwd=""
98 for num in 0 1 2; do
99 eval typeset slice=\${FS_SIDE$num}
100 disk=${slice%s*}
101 slice=${slice##*s}
102 log_must set_partition $slice "" $FS_SIZE $disk
103 done
105 log_note "Make a ufs filesystem on source $rawdisk1"
106 $ECHO "y" | $NEWFS -v $rawdisk1 > /dev/null 2>&1
107 (($? != 0)) && log_untested "Unable to create ufs filesystem on $rawdisk1"
109 log_must $MKDIR -p $UFSMP
111 log_note "mount source $disk1 on $UFSMP"
112 log_must $MOUNT $disk1 $UFSMP
114 log_note "Now create some directories and files to be ufsdump'ed"
115 while (($dirnum <= 2)); do
116 log_must $MKDIR $bigdir${dirnum}
117 while (( $filenum <= 2 )); do
118 $FILE_WRITE -o create -f $bigdir${dirnum}/file${filenum} \
119 -b $BLOCK_SIZE -c $BLOCK_COUNT
120 if [[ $? -ne 0 ]]; then
121 if [[ $dirnum -lt 3 ]]; then
122 log_fail "$FILE_WRITE only wrote" \
123 "<(( $dirnum * 3 + $filenum ))>" \
124 "files, this is not enough"
127 ((filenum = filenum + 1))
128 done
129 filenum=0
130 ((dirnum = dirnum + 1))
131 done
133 log_must $UMOUNT $UFSMP
135 log_note "Start ufsdump in the background"
136 log_note "$UFSDUMP 0bf 512 $rawdisk0 $disk1"
137 $UFSDUMP 0bf 512 $rawdisk0 $disk1 &
138 PIDUFSDUMP=$!
140 unset NOINUSE_CHECK
141 log_note "Attempt to zpool the source device in use by ufsdump"
142 log_mustnot $ZPOOL create $TESTPOOL1 "$disk1"
143 log_mustnot poolexists $TESTPOOL1
145 log_note "Attempt to take the source device in use by ufsdump as spare device"
146 log_mustnot $ZPOOL create $TESTPOOL1 "$FS_SIDE2" spare "$disk1"
147 log_mustnot poolexists $TESTPOOL1
149 wait $PIDUFSDUMP
150 typeset -i retval=$?
151 (($retval != 0)) && log_fail "$UFSDUMP failed with error code $ret_val"
153 log_must $MOUNT $disk1 $UFSMP
155 log_must $RM -rf $UFSMP/*
156 log_must $MKDIR $restored_files
158 cwd=$PWD
159 log_must cd $restored_files
160 log_note "Start ufsrestore in the background from the target device"
161 log_note "$UFSRESTORE rbf 512 $rawdisk0"
162 $UFSRESTORE rbf 512 $rawdisk0 &
163 PIDUFSRESTORE=$!
164 log_must cd $cwd
166 log_note "Attempt to zpool the restored device in use by ufsrestore"
167 log_mustnot $ZPOOL create -f $TESTPOOL2 "$disk1"
168 log_mustnot poolexists $TESTPOOL2
170 log_note "Attempt to take the restored device in use by ufsrestore as spare" \
171 "device"
172 log_mustnot $ZPOOL create -f $TESTPOOL2 "$FS_SIDE2" spare "$disk1"
173 log_mustnot poolexists $TESTPOOL2
175 log_pass "Unable to zpool over a device in use by ufsdump or ufsrestore"