xfs: force file creation to the data device for certain layout tests
[xfstests-dev.git] / tests / generic / 422
1 #! /bin/bash
2 # SPDX-License-Identifier: GPL-2.0
3 # Copyright (C) 2017 SUSE Linux Products GmbH. All Rights Reserved.
4 #
5 # FS QA Test No. generic/422
6 #
7 # Test that a filesystem's implementation of the stat(2) system call reports
8 # correct values for the number of blocks allocated for a file when there are
9 # delayed allocations.
10 #
11 seq=`basename $0`
12 seqres=$RESULT_DIR/$seq
13 echo "QA output created by $seq"
14
15 tmp=/tmp/$$
16 status=1        # failure is the default!
17 trap "_cleanup; exit \$status" 0 1 2 3 15
18
19 _cleanup()
20 {
21         cd /
22         rm -f $tmp.*
23 }
24
25 # get standard environment, filters and checks
26 . ./common/rc
27 . ./common/filter
28
29 # real QA test starts here
30 _supported_fs generic
31 _require_test
32 _require_scratch
33 _require_xfs_io_command "falloc" "-k"
34 _require_odirect
35
36 rm -f $seqres.full
37
38 _scratch_mkfs >>$seqres.full 2>&1
39 _scratch_mount
40
41 $XFS_IO_PROG -f -c "pwrite -S 0xaa 0 64K" $SCRATCH_MNT/foo1 | _filter_xfs_io
42 $XFS_IO_PROG -f \
43      -c "pwrite -S 0xaa 0 64K" \
44      -c "truncate 128K" \
45      $SCRATCH_MNT/foo2 | _filter_xfs_io
46 $XFS_IO_PROG -f \
47      -c "falloc -k 0 128K" \
48      -c "pwrite -S 0xaa 0 64K" \
49      $SCRATCH_MNT/foo3 | _filter_xfs_io
50 touch $SCRATCH_MNT/foo4
51
52 # Make sure everything done so far is durably persisted.
53 sync
54
55 # Now overwrite the extent of the first file.
56 $XFS_IO_PROG -c "pwrite -S 0xff 0 64K" $SCRATCH_MNT/foo1 | _filter_xfs_io
57
58 # Write to a hole of the second file.
59 $XFS_IO_PROG -c "pwrite -S 0xff 64K 64K" $SCRATCH_MNT/foo2 | _filter_xfs_io
60 # Write again to the same location, just to test that the fs will not account
61 # the same write twice.
62 $XFS_IO_PROG -c "pwrite -S 0x20 64K 64K" $SCRATCH_MNT/foo2 | _filter_xfs_io
63
64 # Write beyond eof of the third file into the pre-allocated extent.
65 $XFS_IO_PROG -c "pwrite -S 0xff 64K 64K" $SCRATCH_MNT/foo3 | _filter_xfs_io
66
67 # Do a buffered write immediately followed by a direct IO write, without a
68 # fsync in between, just to test that page invalidation does not lead to an
69 # incorrect number of file blocks reported.
70 $XFS_IO_PROG -c "pwrite -S 0xab 0 64K" $SCRATCH_MNT/foo4 | _filter_xfs_io
71 $XFS_IO_PROG -d -c "pwrite -S 0xef 0 64K" $SCRATCH_MNT/foo4 | _filter_xfs_io
72
73 space_used() {
74     echo "Space used by file foo1:"
75     du -h $SCRATCH_MNT/foo1 | _filter_scratch
76
77     echo "Space used by file foo2:"
78     du -h $SCRATCH_MNT/foo2 | _filter_scratch
79
80     echo "Space used by file foo3:"
81     du -h $SCRATCH_MNT/foo3 | _filter_scratch
82
83     echo "Space used by file foo4:"
84     du -h $SCRATCH_MNT/foo4 | _filter_scratch
85 }
86
87 space_used > $SCRATCH_MNT/$seq.before
88 (
89     echo
90     echo "Before writeback"
91     echo
92
93     cat $SCRATCH_MNT/$seq.before
94 ) >> $seqres.full
95
96 sync
97
98 # We expect the same file sizes reported by 'du' after writeback finishes.
99
100 space_used > $SCRATCH_MNT/$seq.after
101 (
102     echo
103     echo "After writeback"
104     echo
105
106     cat $SCRATCH_MNT/$seq.after
107 ) >> $seqres.full
108
109 if diff -q $SCRATCH_MNT/$seq.before $SCRATCH_MNT/$seq.after; then
110         echo "Space used before and after writeback is equal"
111 fi
112
113 status=0
114 exit