2 # SPDX-License-Identifier: GPL-2.0
3 # Copyright (C) 2017 SUSE Linux Products GmbH. All Rights Reserved.
5 # FS QA Test No. generic/422
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
12 seqres=$RESULT_DIR/$seq
13 echo "QA output created by $seq"
16 status=1 # failure is the default!
17 trap "_cleanup; exit \$status" 0 1 2 3 15
25 # get standard environment, filters and checks
29 # real QA test starts here
33 _require_xfs_io_command "falloc" "-k"
38 _scratch_mkfs >>$seqres.full 2>&1
41 $XFS_IO_PROG -f -c "pwrite -S 0xaa 0 64K" $SCRATCH_MNT/foo1 | _filter_xfs_io
43 -c "pwrite -S 0xaa 0 64K" \
45 $SCRATCH_MNT/foo2 | _filter_xfs_io
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
52 # Make sure everything done so far is durably persisted.
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
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
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
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
74 echo "Space used by file foo1:"
75 du -h $SCRATCH_MNT/foo1 | _filter_scratch
77 echo "Space used by file foo2:"
78 du -h $SCRATCH_MNT/foo2 | _filter_scratch
80 echo "Space used by file foo3:"
81 du -h $SCRATCH_MNT/foo3 | _filter_scratch
83 echo "Space used by file foo4:"
84 du -h $SCRATCH_MNT/foo4 | _filter_scratch
87 space_used > $SCRATCH_MNT/$seq.before
90 echo "Before writeback"
93 cat $SCRATCH_MNT/$seq.before
98 # We expect the same file sizes reported by 'du' after writeback finishes.
100 space_used > $SCRATCH_MNT/$seq.after
103 echo "After writeback"
106 cat $SCRATCH_MNT/$seq.after
109 if diff -q $SCRATCH_MNT/$seq.before $SCRATCH_MNT/$seq.after; then
110 echo "Space used before and after writeback is equal"