summaryrefslogtreecommitdiff
path: root/tests/generic/422
blob: 455d7aeb6862126f83fb72477590381f39845b12 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
#! /bin/bash
# SPDX-License-Identifier: GPL-2.0
# Copyright (C) 2017 SUSE Linux Products GmbH. All Rights Reserved.
#
# FS QA Test No. generic/422
#
# Test that a filesystem's implementation of the stat(2) system call reports
# correct values for the number of blocks allocated for a file when there are
# delayed allocations.
#
. ./common/preamble
_begin_fstest auto quick prealloc

# Import common functions.
. ./common/filter

# real QA test starts here
_supported_fs generic
_require_test
_require_scratch
_require_xfs_io_command "falloc" "-k"
_require_odirect

_scratch_mkfs >>$seqres.full 2>&1
_scratch_mount

$XFS_IO_PROG -f -c "pwrite -S 0xaa 0 64K" $SCRATCH_MNT/foo1 | _filter_xfs_io
$XFS_IO_PROG -f \
     -c "pwrite -S 0xaa 0 64K" \
     -c "truncate 128K" \
     $SCRATCH_MNT/foo2 | _filter_xfs_io
$XFS_IO_PROG -f \
     -c "falloc -k 0 128K" \
     -c "pwrite -S 0xaa 0 64K" \
     $SCRATCH_MNT/foo3 | _filter_xfs_io
touch $SCRATCH_MNT/foo4

# Make sure everything done so far is durably persisted.
sync

# Now overwrite the extent of the first file.
$XFS_IO_PROG -c "pwrite -S 0xff 0 64K" $SCRATCH_MNT/foo1 | _filter_xfs_io

# Write to a hole of the second file.
$XFS_IO_PROG -c "pwrite -S 0xff 64K 64K" $SCRATCH_MNT/foo2 | _filter_xfs_io
# Write again to the same location, just to test that the fs will not account
# the same write twice.
$XFS_IO_PROG -c "pwrite -S 0x20 64K 64K" $SCRATCH_MNT/foo2 | _filter_xfs_io

# Write beyond eof of the third file into the pre-allocated extent.
$XFS_IO_PROG -c "pwrite -S 0xff 64K 64K" $SCRATCH_MNT/foo3 | _filter_xfs_io

# Do a buffered write immediately followed by a direct IO write, without a
# fsync in between, just to test that page invalidation does not lead to an
# incorrect number of file blocks reported.
$XFS_IO_PROG -c "pwrite -S 0xab 0 64K" $SCRATCH_MNT/foo4 | _filter_xfs_io
$XFS_IO_PROG -d -c "pwrite -S 0xef 0 64K" $SCRATCH_MNT/foo4 | _filter_xfs_io

space_used() {
    echo "Space used by file foo1:"
    du -h $SCRATCH_MNT/foo1 | _filter_scratch

    echo "Space used by file foo2:"
    du -h $SCRATCH_MNT/foo2 | _filter_scratch

    echo "Space used by file foo3:"
    du -h $SCRATCH_MNT/foo3 | _filter_scratch

    echo "Space used by file foo4:"
    du -h $SCRATCH_MNT/foo4 | _filter_scratch
}

space_used > $SCRATCH_MNT/$seq.before
(
    echo
    echo "Before writeback"
    echo

    cat $SCRATCH_MNT/$seq.before
) >> $seqres.full

sync

# We expect the same file sizes reported by 'du' after writeback finishes.

space_used > $SCRATCH_MNT/$seq.after
(
    echo
    echo "After writeback"
    echo

    cat $SCRATCH_MNT/$seq.after
) >> $seqres.full

if diff -q $SCRATCH_MNT/$seq.before $SCRATCH_MNT/$seq.after; then
	echo "Space used before and after writeback is equal"
fi

status=0
exit