several fixes from Greg. (btw, keeping width to 80 chars for readability).
[xfstests-dev.git] / 068
1 #! /bin/sh
2 # XFS QA Test No. 068
3 # $Id: 068,v 1.3 2002/09/03 23:15:38 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=/tmp/$$
50 mkdir "$tmp"
51 status=1        # failure is the default!
52
53 # Either "dd" or "fsstress" can be used to generate io load.
54 # Setting both to "FALSE" tests with no io load.
55 GENERATE_IO_LOAD_VIA_DD=TRUE
56 GENERATE_IO_LOAD_VIA_FSSTRESS=TRUE
57 DELAY_BETWEEN_ITERATIONS=10
58 #ITERATIONS=10000
59 ITERATIONS=2
60
61 VG=/dev/VGscratch
62 SCRATCH_SNAP_MNT="$tmp/scratch_snap"
63
64 # Only needed if running by hand,  ie.  check sets these
65 #SCRATCH_LVM_DEV=/dev/xxxx
66 #SCRATCH_MNT=/scratch
67
68 _cleanup()
69 {
70         echo Cleanup beginning
71
72         rm "$tmp/running" > /dev/null 2>&1
73         xfs_freeze -u "$SCRATCH_MNT"
74
75         sleep 10      # Give the dd loop time to finish
76
77         # Comment out unless needed.
78         # If needed, wrap with logic to ensure the FS is mounted.
79         # Kill off any other possible stray stragglers that may be out there.
80         # There should not be any.
81         #fuser -k -m "$SCRATCH_SNAP_MNT/dummy"     >/dev/null 2>&1
82         #fuser -k -m "$SCRATCH_MNT/dummy"         >/dev/null 2>&1
83
84         wait
85
86         umount "$SCRATCH_SNAP_MNT" > /dev/null 2>&1
87         rmdir "$SCRATCH_SNAP_MNT" > /dev/null 2>&1
88         umount "$SCRATCH_MNT" > /dev/null 2>&1
89
90         lvremove -f "$VG/scratch_snap" > /dev/null 2>&1
91         lvremove -f "$VG/scratch" > /dev/null 2>&1
92
93 #TODO   vgremove "$VG"
94
95         rm -rf "$tmp"   # if we ever use tmp files
96         trap 0 1 2 3 15
97         exit $status
98 }
99
100 trap "_cleanup" 0 1 2 3 15
101
102
103 # get standard environment, filters and checks
104 . ./common.rc
105 . ./common.filter
106
107 if [ -e "$SCRATCH_SNAP_MNT" ]; then
108         rmdir "$SCRATCH_SNAP_MNT" || _notrun "Cannot rmdir $SCRATCH_SNAP_MNT"
109 mkdir "$SCRATCH_SNAP_MNT"
110
111 #Verify we have the lvm user tools
112 [ -x /sbin/lvcreate ] || _notrun "lvcreate utility is not installed in /sbin"
113 [ -x /sbin/lvremove ] || _notrun "lvremove utility is not installed in /sbin"
114
115 # If the above fails for LVM 2, the below may be useful notes
116 #    try "lvm vgdisplay --version" and look for a > 1.9x version number, eg,
117
118 #     LVM version:     1.95.10-cvs (2002-05-31)
119 #     Library version: 0.96.03-ioctl-cvs (2002-06-27)
120 #     Driver version:  1.0.3
121
122
123 LVM=false
124
125 # Check if LVM 1 is in the kernel
126 if grep lvm /proc/devices > /dev/null 2>&1; then LVM=true; fi
127
128 # Check if LVM 2 is in the kernel
129 if grep device-mapper /proc/devices > /dev/null 2>&1; then LVM=true; fi
130
131 # Check if EVMS is in the kernel
132 #TODO   # I don't know how to do this one.
133
134 [ "$LVM" = false ] && _notrun "LVM is not present in the running kernel."
135
136
137 # real QA test starts here
138
139 # Create a PV set from the scratch partition
140 #TODO # (I don't know if this is needed.and it is dangerous because it intentionally deletes the partition table!!! 
141 #TODO # dd if=/dev/zero of="$SCRATCH_LVM_DEV" bs=512 count=1
142 #TODO # pvcreate "$SCRATCH_LVM_DEV"
143
144 # Create a VG from the PV
145 #TODO # vgcreate "$VG" "$SCRATCH_LVM_DEV"
146
147 # Create a LV in the VG to snapshot
148 #TODO # lvcreate -L 2G -n scratch "$VG"
149
150 # Mount the LV
151 mkdir "$SCRATCH_MNT" > /dev/null 2&>1
152
153 mount "$VG/scratch" "$SCRATCH_MNT"
154
155 touch "$tmp/running"
156
157 if [ "$GENERATE_IO_LOAD_VIA_DD" != FALSE ];
158 then
159         # Create a large 64 Meg zero filled file on the LV
160         dd if=/dev/zero of=$SCRATCH_MNT/dummy bs=64k count=1000 >/dev/null 2>&1
161
162         # Setup infinite loop copying the large file, thus generating heavy I/O
163         touch "$tmp/running"
164         while [ -f "$tmp/running" ]
165         do
166                 dd if="$SCRATCH_MNT/dummy" of="$SCRATCH_MNT/junk" bs=64k \
167                         > /dev/null 2>&1
168                 # This forces metadata updates the next time around
169                 rm "$SCRATCH_MNT/junk"
170                 sync
171         done 
172 fi &
173
174 if [ "$GENERATE_IO_LOAD_VIA_FSSTRESS" != FALSE ];
175 then
176         STRESS_DIR="$SCRATCH_MNT/fsstress_test_dir"
177         mkdir "$STRESS_DIR"
178
179         while [ -f "$tmp/running" ]
180         do
181                 # -n 10 makes this take about 10 seconds,
182                 # This allows the loop to end shortly after $tmp/running
183                 # is deleted
184                 $here/src/fsstress -d "$STRESS_DIR" -n 10  > /dev/null 2>&1
185                 sync
186         done
187
188         rm -rf "$STRESS_DIR"
189 fi &
190
191 ii=1
192
193 while [ $ii -le "$ITERATIONS" ]
194 do
195
196         # Useful if running interactively, but not from the xfs test scripts
197         #echo $ii
198
199         # If the VFS lock patch is present, the calls to xfs_freeze
200         # are redundant, but should cause no problems
201         #       OPTIONAL
202         xfs_freeze -f "$SCRATCH_MNT"
203         if [ $? != 0 ] ; then
204                 echo xfs_freeze -f "$SCRATCH_MNT" failed
205         fi
206         (
207                 lvcreate --snapshot --size 1G --name scratch_snap "$VG/scratch"\
208                         > /dev/null 2>&1
209                 ret=$?
210                 [ $ret != 0 ] && \
211                         echo "Snapshot $SCRATCH_MNT create failed, status=$ret"
212         ) &
213         SNAPSHOT_shell_pid=$!
214
215         # If the Snapshot has not completed in ten minutes, kill it
216         (
217                 # I have NOT figured out how to kill the sleep 600 before
218                 # it exits naturally.
219                 # This does not cause a problem, but it clutters the ps table.
220                 sleep 600
221
222                 # The kill $TIMEOUT_shell_pid keeps the below from occuring
223                 echo Snapshot Lockup Occured on loop $ii
224                 xfs_freeze -u "$SCRATCH_MNT"
225                 kill $$
226         ) &
227         TIMEOUT_shell_pid=$!
228
229         wait "$SNAPSHOT_shell_pid"
230
231         exec 2> /dev/null               # Send the shells stderr to /dev/null
232         kill "$TIMEOUT_shell_pid"       # Cancel the timeout
233         wait "$TIMEOUT_shell_pid"       # This causes consistent shell
234                                         # notification for some unknown reason
235         exec 2>&1                       # Put it back to the same as stdout
236
237         # If the VFS lock patch is present, the calls to xfs_freeze
238         # are redundant, but should cause no problems
239         #       OPTIONAL
240         xfs_freeze -u "$SCRATCH_MNT"
241         if [ $? != 0 ] ; then
242                 echo xfs_freeze -u "$SCRATCH_MNT" failed
243         fi
244         #         MANDANTORY   (end)
245
246         mount -t xfs -o ro,nouuid "$VG/scratch_snap" "$SCRATCH_SNAP_MNT"
247         if [ $? != 0 ] ; then
248                 echo mount for "$SCRATCH_SNAP_MNT" failed
249         fi
250         umount "$SCRATCH_SNAP_MNT"
251         if [ $? != 0 ] ; then
252                 echo umount for "$SCRATCH_SNAP_MNT" failed
253         fi
254         lvremove -f "$VG/scratch_snap" > /dev/null 2>&1
255         if [ $? != 0 ] ; then
256                echo lvremove for "$VG/scratch_snap" failed
257         fi
258
259         ii=`expr $ii + 1`
260
261         sleep "$DELAY_BETWEEN_ITERATIONS"      
262         # The VG seems to need time to stabalize between snapshots
263         # With LVM 1.0.3 and XFS 1.1, I have tried this at 3600 seconds
264         # and still had failures
265
266 done
267
268 # success, all done
269 echo SUCCESS, COMPLETED ALL ITERATIONS WITH NO TIME OUTS!!!!!!!!!!!!
270 status=0
271 _cleanup
272 exit 1   # _cleanup should exit, so we should never get here.