btrfs/012: check free size of scratch device before copying files
[xfstests-dev.git] / tests / generic / 214
1 #! /bin/bash
2 # SPDX-License-Identifier: GPL-2.0
3 # Copyright (c) 2009 Red Hat, Inc. All Rights Reserved.
4 #
5 # FS QA Test No. 214
6 #
7 # Basic unwritten extent sanity checks
8 #
9 seq=`basename $0`
10 seqres=$RESULT_DIR/$seq
11 echo "QA output created by $seq"
12
13 _cleanup()
14 {
15         rm -f $TEST_DIR/ouch*
16         cd /
17         rm -f $tmp.*
18 }
19
20 here=`pwd`
21 tmp=$TEST_DIR/$$
22 status=1        # failure is the default!
23 trap "_cleanup; exit \$status" 0 1 2 3 15
24
25 # get standard environment, filters and checks
26 . ./common/rc
27 . ./common/filter
28
29 # real QA test starts here
30 # generic, but xfs_io's fallocate must work
31 _supported_fs generic
32 # only Linux supports fallocate
33 _require_test
34
35 [ -n "$XFS_IO_PROG" ] || _notrun "xfs_io executable not found"
36
37 rm -f $seqres.full
38 rm -f $TEST_DIR/ouch*
39
40 _require_xfs_io_command "falloc"
41 _require_odirect
42
43 # Ok, off we go.
44
45 # We don't remove files after they are written to check
46 # for subsequent fs corruption at the end
47 rm -f $TEST_DIR/test214-*
48
49 # Super-trivial; preallocate a region and read it; get 0s.
50 echo "=== falloc & read  ==="
51 $XFS_IO_PROG -f                 \
52         -c 'falloc 0 4096'      \
53         -c 'pread -v 0 4096'    \
54         $TEST_DIR/test214-1 | _filter_xfs_io_unique
55
56 # Preallocate a chunk, write 1 byte, read it all back.
57 # Should get no stale data.  Early ext4 bug.
58
59 echo "=== falloc, write beginning, read ==="
60 $XFS_IO_PROG -f                 \
61         -c 'falloc 0 512'       \
62         -c 'pwrite 0 1'         \
63         -c 'pread -v 0 512'     \
64         $TEST_DIR/test214-2 | _filter_xfs_io_unique
65
66 # Same but write in the middle of the region
67 echo "=== falloc, write middle, read ==="
68 $XFS_IO_PROG -f                 \
69         -c 'falloc 0 512'       \
70         -c 'pwrite 256 1'       \
71         -c 'pread -v 0 512'     \
72         $TEST_DIR/test214-3 | _filter_xfs_io_unique
73
74 # Same but write the end of the region
75 echo "=== falloc, write end, read ==="
76 $XFS_IO_PROG -f                 \
77         -c 'falloc 0 512'       \
78         -c 'pwrite 511 1'       \
79         -c 'pread -v 0 512'     \
80         $TEST_DIR/test214-4 | _filter_xfs_io_unique
81
82 # Reported by IBM on ext4.
83 #
84 # Fixed by commit a41f20716975910d9beb90b7efc61107901492b8
85 #
86 # The file was previously preallocated, and then initialized the middle of
87 # the preallocation area using Direct IO write, then overwrite part of
88 # initialized area. Later after truncate the file (to the middle of the
89 # initialized data), the initialized data *before* the new file size was
90 # gone after remount the filesystem.
91
92 echo "=== falloc, write, sync, truncate, read ==="
93 # Allocate, write, sync, truncate (buffered)
94 $XFS_IO_PROG -f                                 \
95         -c 'falloc         0x0     0x65C00'     \
96         -c 'pwrite -S 0xAA 0x12000 0x10000'     \
97         -c 'fsync'                              \
98         -c 'truncate 0x16000'                   \
99         $TEST_DIR/test214-5 | _filter_xfs_io_unique
100
101 # now do a direct read and see what's on-disk
102 $XFS_IO_PROG -f -d                              \
103         -c 'pread -v 0 0x16000'                 \
104         $TEST_DIR/test214-5 | _filter_xfs_io_unique
105
106 # Reported by Ted Ts'o on linux-ext4, 12/31/2009
107 # double-allocation on ext4 when fallocating over delalloc blocks
108 # Regression due to d21cd8f163ac44b15c465aab7306db931c606908
109
110 echo "=== delalloc write 16k; fallocate same range ==="
111 # delalloc write 16k, fallocate same range.
112 # Should get caught on fsck when we're done.
113
114 $XFS_IO_PROG -f                                 \
115         -c "pwrite 0 16k"                       \
116         -c "falloc 0 16k"                       \
117         -c "fsync"                              \
118         $TEST_DIR/test214-6 | _filter_xfs_io_unique
119
120 # Another ext4 failure
121
122 echo "=== ext4 testcase 2 ==="
123
124 $XFS_IO_PROG -f \
125         -c "fsync"                      \
126         -c "pwrite 551917 41182"        \
127         -c "falloc 917633 392230"       \
128         -c "pwrite 285771 77718"        \
129         -c "pwrite 1136718 104115"      \
130         $TEST_DIR/test214-7 | _filter_xfs_io_unique
131
132 # success, all done
133 status=0
134 exit