xfstests: add _require_freeze and minor cleanups
[xfstests-dev.git] / 274
1 #! /bin/bash
2 # FS QA Test No. 274
3 #
4 # preallocation test:
5 # Preallocate space to a file, and fill the rest of the fs to 100%.
6 # Then test a write into that preallocated space, which should succeed.
7 #
8 #-----------------------------------------------------------------------
9 # Copyright (c) 2011-2012 Fujitsu, Inc.  All Rights Reserved.
10 #
11 # This program is free software; you can redistribute it and/or
12 # modify it under the terms of the GNU General Public License as
13 # published by the Free Software Foundation.
14 #
15 # This program is distributed in the hope that it would be useful,
16 # but WITHOUT ANY WARRANTY; without even the implied warranty of
17 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18 # GNU General Public License for more details.
19 #
20 # You should have received a copy of the GNU General Public License
21 # along with this program; if not, write the Free Software Foundation,
22 # Inc.,  51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
23 #
24 #-----------------------------------------------------------------------
25 #
26 #creator
27 owner=wu.bo@cn.fujitsu.com
28
29 seq=`basename $0`
30 echo "QA output created by $seq"
31
32 here=`pwd`
33 tmp=/tmp/$$
34 status=0    # success is the default!
35 trap "_cleanup; exit \$status" 0 1 2 3 15
36
37 _cleanup()
38 {
39         cd /
40         rm -f $tmp.*
41         _scratch_unmount
42 }
43
44 . ./common.rc
45 . ./common.filter
46
47 # real QA test starts here
48 _supported_fs generic
49 _supported_os IRIX Linux
50 _require_scratch
51 _require_xfs_io_falloc
52
53 echo "------------------------------"
54 echo "preallocation test"
55 echo "------------------------------"
56
57 rm -f $seq.full
58
59 umount $SCRATCH_DEV 2>/dev/null
60 _scratch_mkfs_sized $((1 * 1024 * 1024 * 1024)) >>$seq.full 2>&1
61 _scratch_mount
62
63 # Create a 4k file and Allocate 4M past EOF on that file
64 xfs_io -F -f -c "pwrite 0 4k" -c "falloc -k 4k 4m" $SCRATCH_MNT/test \
65         >>$seq.full 2>&1 || _fail "failed to create test file"
66
67 # Fill the rest of the fs completely
68 # Note, this will show ENOSPC errors in $seq.full, that's ok.
69 echo "Fill fs with 1M IOs; ENOSPC expected" >> $seq.full
70 dd if=/dev/zero of=$SCRATCH_MNT/tmp1 bs=1M >>$seq.full 2>&1
71 echo "Fill fs with 4K IOs; ENOSPC expected" >> $seq.full
72 dd if=/dev/zero of=$SCRATCH_MNT/tmp2 bs=4K >>$seq.full 2>&1
73 sync
74 # Last effort, use O_SYNC
75 echo "Fill fs with 4K DIOs; ENOSPC expected" >> $seq.full
76 dd if=/dev/zero of=$SCRATCH_MNT/tmp3 bs=4K oflag=sync >>$seq.full 2>&1
77 # Save space usage info
78 echo "Post-fill space:" >> $seq.full
79 df $SCRATCH_MNT >>$seq.full 2>&1
80
81 # Now attempt a write into all of the preallocated space -
82 # in a very nasty way, badly fragmenting it and then filling it in.
83 echo "Fill in prealloc space; fragment at offsets:" >> $seq.full
84 for i in `seq 1 2 1023`; do
85         echo -n "$i " >> $seq.full
86         dd if=/dev/zero of=$SCRATCH_MNT/test seek=$i bs=4K count=1 conv=notrunc \
87                 >>$seq.full 2>/dev/null || _fail "failed to write to test file"
88 done
89 sync
90 echo >> $seq.full
91 echo "Fill in prealloc space; fill holes at offsets:" >> $seq.full
92 for i in `seq 2 2 1023`; do
93         echo -n "$i " >> $seq.full
94         dd if=/dev/zero of=$SCRATCH_MNT/test seek=$i bs=4K count=1 conv=notrunc \
95                 >>$seq.full 2>/dev/null || _fail "failed to fill test file"
96 done
97 sync
98 echo >> $seq.full
99
100 echo "done"
101 exit