Fix the get_dirattrs dmapi test tool
[xfstests-dev.git] / 068
1 #! /bin/sh
2 # FS QA Test No. 068
3 #
4 # Test Linux LVM snapshot creation
5 #
6 # The timing and placement of kills and waits is particularily sensitive.
7 # Don't change them unless you want to spend some time getting it right again.
8 #
9 #-----------------------------------------------------------------------
10 # Copyright (c) 2000, 2002 Silicon Graphics, Inc.  All Rights Reserved.
11
12 # This program is free software; you can redistribute it and/or modify it
13 # under the terms of version 2 of the GNU General Public License as
14 # published by the Free Software Foundation.
15
16 # This program is distributed in the hope that it would be useful, but
17 # WITHOUT ANY WARRANTY; without even the implied warranty of
18 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
19
20 # Further, this software is distributed without any warranty that it is
21 # free of the rightful claim of any third person regarding infringement
22 # or the like.  Any license provided herein, whether implied or
23 # otherwise, applies only to this software file.  Patent licenses, if
24 # any, provided herein do not apply to combinations of this program with
25 # other software, or any other product whatsoever.
26
27 # You should have received a copy of the GNU General Public License along
28 # with this program; if not, write the Free Software Foundation, Inc., 59
29 # Temple Place - Suite 330, Boston MA 02111-1307, USA.
30
31 # Contact information: Silicon Graphics, Inc., 1600 Amphitheatre Pkwy,
32 # Mountain View, CA  94043, or:
33
34 # http://www.sgi.com 
35
36 # For further information regarding this notice, see: 
37
38 # http://oss.sgi.com/projects/GenInfo/SGIGPLNoticeExplan/
39 #-----------------------------------------------------------------------
40 #
41 # creator
42 owner=freemyer@NorcrossGroup.com
43
44 seq=`basename $0`
45 echo "QA output created by $seq"
46
47 here=`pwd`
48 tmp=/tmp/$$
49 mkdir "$tmp"
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"
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 # real QA test starts here
107 _supported_fs xfs
108 _supported_os Linux
109
110 if [ -e "$SCRATCH_SNAP_MNT" ]; then
111         rmdir "$SCRATCH_SNAP_MNT" || _notrun "Cannot rmdir $SCRATCH_SNAP_MNT"
112 fi
113 mkdir "$SCRATCH_SNAP_MNT"
114
115 #Verify we have the lvm user tools
116 [ -x /sbin/lvcreate ] || _notrun "lvcreate utility is not installed in /sbin"
117 [ -x /sbin/lvremove ] || _notrun "lvremove utility is not installed in /sbin"
118
119 # If the above fails for LVM 2, the below may be useful notes
120 #    try "lvm vgdisplay --version" and look for a > 1.9x version number, eg,
121
122 #     LVM version:     1.95.10-cvs (2002-05-31)
123 #     Library version: 0.96.03-ioctl-cvs (2002-06-27)
124 #     Driver version:  1.0.3
125
126
127 LVM=false
128
129 # Check if LVM 1 is in the kernel
130 if grep lvm /proc/devices > /dev/null; then LVM=true; fi
131
132 # Check if LVM 2 is in the kernel
133 if grep device-mapper /proc/devices > /dev/null; then LVM=true; fi
134
135 # Check if EVMS is in the kernel
136 #TODO   # I don't know how to do this one.
137
138 [ "$LVM" = false ] && _notrun "LVM is not present in the running kernel."
139
140
141 # Create a PV set from the scratch partition
142 #TODO # (I don't know if this is needed.and it is dangerous because it intentionally deletes the partition table!!! 
143 #TODO # dd if=/dev/zero of="$SCRATCH_LVM_DEV" bs=512 count=1
144 #TODO # pvcreate "$SCRATCH_LVM_DEV"
145
146 # Create a VG from the PV
147 #TODO # vgcreate "$VG" "$SCRATCH_LVM_DEV"
148
149 # Create a LV in the VG to snapshot
150 #TODO # lvcreate -L 2G -n scratch "$VG"
151
152 # Mount the LV
153 mkdir "$SCRATCH_MNT"
154
155 mount "$VG/scratch" "$SCRATCH_MNT"
156
157 touch "$tmp/running"
158
159 if [ "$GENERATE_IO_LOAD_VIA_DD" != FALSE ]
160 then
161         # Create a large 64 Meg zero filled file on the LV
162         dd if=/dev/zero of=$SCRATCH_MNT/dummy bs=64k count=1000 >/dev/null 2>&1
163
164         # Setup infinite loop copying the large file, thus generating heavy I/O
165         touch "$tmp/running"
166         while [ -f "$tmp/running" ]
167         do
168                 dd if="$SCRATCH_MNT/dummy" of="$SCRATCH_MNT/junk" bs=64k \
169                         > /dev/null 2>&1
170                 # This forces metadata updates the next time around
171                 rm "$SCRATCH_MNT/junk"
172                 sync
173         done 
174 fi &
175
176 if [ "$GENERATE_IO_LOAD_VIA_FSSTRESS" != FALSE ]
177 then
178         STRESS_DIR="$SCRATCH_MNT/fsstress_test_dir"
179         mkdir "$STRESS_DIR"
180
181         while [ -f "$tmp/running" ]
182         do
183                 # -n 10 makes this take about 10 seconds,
184                 # This allows the loop to end shortly after $tmp/running
185                 # is deleted
186                 $here/ltp/fsstress -d "$STRESS_DIR" -n 10  > /dev/null 2>&1
187                 sync
188         done
189
190         rm -rf "$STRESS_DIR"
191 fi &
192
193 ii=1
194
195 while [ $ii -le "$ITERATIONS" ]
196 do
197
198         # Useful if running interactively, but not from the xfs test scripts
199         #echo $ii
200
201         # If the VFS lock patch is present, the calls to xfs_freeze
202         # are redundant, but should cause no problems
203         #       OPTIONAL
204         xfs_freeze -f "$SCRATCH_MNT"
205         [ $? != 0 ] && echo xfs_freeze -f "$SCRATCH_MNT" failed
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         [ $? != 0 ] && echo xfs_freeze -u "$SCRATCH_MNT" failed
242         #         MANDANTORY   (end)
243
244         mount -t xfs -o ro,nouuid "$VG/scratch_snap" "$SCRATCH_SNAP_MNT"
245         [ $? -eq 0 ] || echo mount for "$SCRATCH_SNAP_MNT" failed
246
247         umount "$SCRATCH_SNAP_MNT"
248         [ $? -eq 0 ] || echo umount for "$SCRATCH_SNAP_MNT" failed
249
250         lvremove -f "$VG/scratch_snap" > /dev/null 2>&1
251         [ $? -eq 0 ] || echo lvremove for "$VG/scratch_snap" failed
252
253         ii=`expr $ii + 1`
254
255         sleep "$DELAY_BETWEEN_ITERATIONS"      
256         # The VG seems to need time to stabalize between snapshots
257         # With LVM 1.0.3 and XFS 1.1, I have tried this at 3600 seconds
258         # and still had failures
259
260 done
261
262 # success, all done
263 echo SUCCESS, COMPLETED ALL ITERATIONS WITH NO TIME OUTS!!!!!!!!!!!!
264 status=0
265 _cleanup
266 exit 1   # _cleanup should exit, so we should never get here.