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
34 _require_xfs_io_command "falloc" "-k"
39 _scratch_mkfs >>$seqres.full 2>&1
42 $XFS_IO_PROG -f -c "pwrite -S 0xaa 0 64K" $SCRATCH_MNT/foo1 | _filter_xfs_io
44 -c "pwrite -S 0xaa 0 64K" \
46 $SCRATCH_MNT/foo2 | _filter_xfs_io
48 -c "falloc -k 0 128K" \
49 -c "pwrite -S 0xaa 0 64K" \
50 $SCRATCH_MNT/foo3 | _filter_xfs_io
51 touch $SCRATCH_MNT/foo4
53 # Make sure everything done so far is durably persisted.
56 # Now overwrite the extent of the first file.
57 $XFS_IO_PROG -c "pwrite -S 0xff 0 64K" $SCRATCH_MNT/foo1 | _filter_xfs_io
59 # Write to a hole of the second file.
60 $XFS_IO_PROG -c "pwrite -S 0xff 64K 64K" $SCRATCH_MNT/foo2 | _filter_xfs_io
61 # Write again to the same location, just to test that the fs will not account
62 # the same write twice.
63 $XFS_IO_PROG -c "pwrite -S 0x20 64K 64K" $SCRATCH_MNT/foo2 | _filter_xfs_io
65 # Write beyond eof of the third file into the pre-allocated extent.
66 $XFS_IO_PROG -c "pwrite -S 0xff 64K 64K" $SCRATCH_MNT/foo3 | _filter_xfs_io
68 # Do a buffered write immediately followed by a direct IO write, without a
69 # fsync in between, just to test that page invalidation does not lead to an
70 # incorrect number of file blocks reported.
71 $XFS_IO_PROG -c "pwrite -S 0xab 0 64K" $SCRATCH_MNT/foo4 | _filter_xfs_io
72 $XFS_IO_PROG -d -c "pwrite -S 0xef 0 64K" $SCRATCH_MNT/foo4 | _filter_xfs_io
75 echo "Space used by file foo1:"
76 du -h $SCRATCH_MNT/foo1 | _filter_scratch
78 echo "Space used by file foo2:"
79 du -h $SCRATCH_MNT/foo2 | _filter_scratch
81 echo "Space used by file foo3:"
82 du -h $SCRATCH_MNT/foo3 | _filter_scratch
84 echo "Space used by file foo4:"
85 du -h $SCRATCH_MNT/foo4 | _filter_scratch
88 space_used > $SCRATCH_MNT/$seq.before
91 echo "Before writeback"
94 cat $SCRATCH_MNT/$seq.before
99 # We expect the same file sizes reported by 'du' after writeback finishes.
101 space_used > $SCRATCH_MNT/$seq.after
104 echo "After writeback"
107 cat $SCRATCH_MNT/$seq.after
110 if diff -q $SCRATCH_MNT/$seq.before $SCRATCH_MNT/$seq.after; then
111 echo "Space used before and after writeback is equal"