Do a better job of cleaning up after autoconf.
[xfstests-dev.git] / 068
1 #! /bin/sh
2 # XFS QA Test No. 068
3 # $Id: 068,v 1.1 2002/09/02 06:04:01 nathans Exp $
4 #
5 # Test Linux LVM snapshot creation
6 #
7 # The timing and placement of kills and waits is particularily sensitive.
8 # Don't change them unless you want to spend some time getting it right again.
9 #
10 #-----------------------------------------------------------------------
11 # Copyright (c) 2000, 2002 Silicon Graphics, Inc.  All Rights Reserved.
12
13 # This program is free software; you can redistribute it and/or modify it
14 # under the terms of version 2 of the GNU General Public License as
15 # published by the Free Software Foundation.
16
17 # This program is distributed in the hope that it would be useful, but
18 # WITHOUT ANY WARRANTY; without even the implied warranty of
19 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
20
21 # Further, this software is distributed without any warranty that it is
22 # free of the rightful claim of any third person regarding infringement
23 # or the like.  Any license provided herein, whether implied or
24 # otherwise, applies only to this software file.  Patent licenses, if
25 # any, provided herein do not apply to combinations of this program with
26 # other software, or any other product whatsoever.
27
28 # You should have received a copy of the GNU General Public License along
29 # with this program; if not, write the Free Software Foundation, Inc., 59
30 # Temple Place - Suite 330, Boston MA 02111-1307, USA.
31
32 # Contact information: Silicon Graphics, Inc., 1600 Amphitheatre Pkwy,
33 # Mountain View, CA  94043, or:
34
35 # http://www.sgi.com 
36
37 # For further information regarding this notice, see: 
38
39 # http://oss.sgi.com/projects/GenInfo/SGIGPLNoticeExplan/
40 #-----------------------------------------------------------------------
41 #
42 # creator
43 owner=freemyer@NorcrossGroup.com
44
45 seq=`basename $0`
46 echo "QA output created by $seq"
47
48 here=`pwd`
49 tmp=`mktemp -d /tmp/xfstest.XXXXXX` || exit 1
50 status=1        # failure is the default!
51
52 # Either "dd" or "fsstress" can be used to generate io load.
53 # Setting both to "FALSE" tests with no io load.
54 GENERATE_IO_LOAD_VIA_DD=TRUE
55 GENERATE_IO_LOAD_VIA_FSSTRESS=TRUE
56 DELAY_BETWEEN_ITERATIONS=10
57 #ITERATIONS=10000
58 ITERATIONS=2
59
60 VG=/dev/VGscratch
61 SCRATCH_SNAP_MNT="$tmp/scratch_snap"
62
63 # Only needed if running by hand,  ie.  check sets these
64 #SCRATCH_LVM_DEV=/dev/xxxx
65 #SCRATCH_MNT=/scratch
66
67 _cleanup()
68 {
69         echo Cleanup beginning
70
71         rm "$tmp/running" > /dev/null 2>&1
72         xfs_freeze -u "$SCRATCH_MNT"
73
74         sleep 10      # Give the dd loop time to finish
75
76         # Comment out unless needed.
77         # If needed, wrap with logic to ensure the FS is mounted.
78         # Kill off any other possible stray stragglers that may be out there.
79         # There should not be any.
80         #fuser -k -m "$SCRATCH_SNAP_MNT/dummy"     >/dev/null 2>&1
81         #fuser -k -m "$SCRATCH_MNT/dummy"         >/dev/null 2>&1
82
83         wait
84
85         umount "$SCRATCH_SNAP_MNT" > /dev/null 2>&1
86         rmdir "$SCRATCH_SNAP_MNT" > /dev/null 2>&1
87         umount "$SCRATCH_MNT" > /dev/null 2>&1
88
89         lvremove -f "$VG/scratch_snap" > /dev/null 2>&1
90         lvremove -f "$VG/scratch" > /dev/null 2>&1
91
92 #TODO   vgremove "$VG"
93
94         rm -rf "$tmp"   # if we ever use tmp files
95         trap 0 1 2 3 15
96         exit $status
97 }
98
99 trap "_cleanup" 0 1 2 3 15
100
101
102 # get standard environment, filters and checks
103 . ./common.rc
104 . ./common.filter
105
106 [ -e "$SCRATCH_SNAP_MNT" ] && rm -rf "$SCRATCH_SNAP_MNT"
107 mkdir "$SCRATCH_SNAP_MNT"
108
109 #Verify we have the lvm user tools
110 [ -x /sbin/lvcreate ] || _notrun "lvcreate utility is not installed in /sbin"
111 [ -x /sbin/lvremove ] || _notrun "lvremove utility is not installed in /sbin"
112
113 # If the above fails for LVM 2, the below may be useful notes
114 #    try "lvm vgdisplay --version" and look for a > 1.9x version number, eg,
115
116 #     LVM version:     1.95.10-cvs (2002-05-31)
117 #     Library version: 0.96.03-ioctl-cvs (2002-06-27)
118 #     Driver version:  1.0.3
119
120
121 LVM=false
122
123 # Check if LVM 1 is in the kernel
124 if grep lvm /proc/devices > /dev/null 2>&1; then LVM=true; fi
125
126 # Check if LVM 2 is in the kernel
127 if grep device-mapper /proc/devices > /dev/null 2>&1; then LVM=true; fi
128
129 # Check if EVMS is in the kernel
130 #TODO   # I don't know how to do this one.
131
132 [ "$LVM" = false ] && _notrun "LVM is not present in the running kernel."
133
134
135 # real QA test starts here
136
137 # Create a PV set from the scratch partition
138 #TODO # (I don't know if this is needed.and it is dangerous because it intentionally deletes the partition table!!! 
139 #TODO # dd if=/dev/zero of="$SCRATCH_LVM_DEV" bs=512 count=1
140 #TODO # pvcreate "$SCRATCH_LVM_DEV"
141
142 # Create a VG from the PV
143 #TODO # vgcreate "$VG" "$SCRATCH_LVM_DEV"
144
145 # Create a LV in the VG to snapshot
146 #TODO # lvcreate -L 2G -n scratch "$VG"
147
148 # Mount the LV
149 mkdir "$SCRATCH_MNT" > /dev/null 2&>1
150
151 mount "$VG/scratch" "$SCRATCH_MNT"
152
153 touch "$tmp/running"
154
155 if [ "$GENERATE_IO_LOAD_VIA_DD" != FALSE ];
156 then
157         # Create a large 64 Meg zero filled file on the LV
158         dd if=/dev/zero of=$SCRATCH_MNT/dummy bs=64k count=1000 >/dev/null 2>&1
159
160         # Setup infinite loop copying the large file, thus generating heavy I/O
161         touch "$tmp/running"
162         while [ -f "$tmp/running" ]
163         do
164                 dd if="$SCRATCH_MNT/dummy" of="$SCRATCH_MNT/junk" bs=64k \
165                         > /dev/null 2>&1
166                 # This forces metadata updates the next time around
167                 rm "$SCRATCH_MNT/junk"
168                 sync
169         done 
170 fi &
171
172 if [ "$GENERATE_IO_LOAD_VIA_FSSTRESS" != FALSE ];
173 then
174         STRESS_DIR="$SCRATCH_MNT/fsstress_test_dir"
175         mkdir "$STRESS_DIR"
176
177         while [ -f "$tmp/running" ]
178         do
179                 # -n 10 makes this take about 10 seconds,
180                 # This allows the loop to end shortly after $tmp/running
181                 # is deleted
182                 $here/src/fsstress -d "$STRESS_DIR" -n 10  > /dev/null 2>&1
183                 sync
184         done
185
186         rm -rf "$STRESS_DIR"
187 fi &
188
189 ii=1
190
191 while [ $ii -le "$ITERATIONS" ]
192 do
193
194         # Useful if running interactively, but not from the xfs test scripts
195         #echo $ii
196
197         # If the VFS lock patch is present, the calls to xfs_freeze
198         # are redundant, but should cause no problems
199         #       OPTIONAL
200         xfs_freeze -f "$SCRATCH_MNT"
201         if [ $? != 0 ] ; then
202                 echo xfs_freeze -f "$SCRATCH_MNT" failed
203         fi
204         (
205                 lvcreate --snapshot --size 1G --name scratch_snap "$VG/scratch"\
206                         > /dev/null 2>&1
207                 ret=$?
208                 [ $ret != 0 ] && \
209                         echo "Snapshot $SCRATCH_MNT create failed, status=$ret"
210                 fi
211         ) &
212         SNAPSHOT_shell_pid=$!
213
214         # If the Snapshot has not completed in ten minutes, kill it
215         (
216                 # I have NOT figured out how to kill the sleep 600 before
217                 # it exits naturally.
218                 # This does not cause a problem, but it clutters the ps table.
219                 sleep 600
220
221                 # The kill $TIMEOUT_shell_pid keeps the below from occuring
222                 echo Snapshot Lockup Occured on loop $ii
223                 xfs_freeze -u "$SCRATCH_MNT"
224                 kill $$
225         ) &
226         TIMEOUT_shell_pid=$!
227
228         wait "$SNAPSHOT_shell_pid"
229
230         exec 2> /dev/null               # Send the shells stderr to /dev/null
231         kill "$TIMEOUT_shell_pid"       # Cancel the timeout
232         wait "$TIMEOUT_shell_pid"       # This causes consistent shell
233                                         # notification for some unknown reason
234         exec 2>&1                       # Put it back to the same as stdout
235
236         # If the VFS lock patch is present, the calls to xfs_freeze
237         # are redundant, but should cause no problems
238         #       OPTIONAL
239         xfs_freeze -u "$SCRATCH_MNT"
240         if [ $? != 0 ] ; then
241                 echo xfs_freeze -u "$SCRATCH_MNT" failed
242         fi
243         #         MANDANTORY   (end)
244
245         mount -t xfs -o ro,nouuid "$VG/scratch_snap" "$SCRATCH_SNAP_MNT"
246         if [ $? != 0 ] ; then
247                 echo mount for "$SCRATCH_SNAP_MNT" failed
248         fi
249         umount "$SCRATCH_SNAP_MNT"
250         if [ $? != 0 ] ; then
251                 echo umount for "$SCRATCH_SNAP_MNT" failed
252         fi
253         lvremove -f "$VG/scratch_snap" > /dev/null 2>&1
254         if [ $? != 0 ] ; then
255                echo lvremove for "$VG/scratch_snap" failed
256         fi
257
258         ii=`expr $ii + 1`
259
260         sleep "$DELAY_BETWEEN_ITERATIONS"      
261         # The VG seems to need time to stabalize between snapshots
262         # With LVM 1.0.3 and XFS 1.1, I have tried this at 3600 seconds
263         # and still had failures
264
265 done
266
267 # success, all done
268 echo SUCCESS, COMPLETED ALL ITERATIONS WITH NO TIME OUTS!!!!!!!!!!!!
269 status=0
270 _cleanup
271 exit 1   # _cleanup should exit, so we should never get here.