2 # SPDX-License-Identifier: GPL-2.0
3 # Copyright (C) 2018 SUSE Linux Products GmbH. All Rights Reserved.
7 # Test that fsync operations preserve extents allocated with fallocate(2) that
8 # are placed beyond a file's size.
11 _begin_fstest auto quick log metadata
13 # Override the default cleanup function.
21 # Import common functions.
26 # real QA test starts here
29 _require_dm_target flakey
30 _require_xfs_io_command "falloc" "-k"
31 _require_xfs_io_command "fiemap"
33 _scratch_mkfs >>$seqres.full 2>&1
34 _require_metadata_journaling $SCRATCH_DEV
38 # Create our test files.
39 $XFS_IO_PROG -f -c "pwrite -S 0xea 0 256K" $SCRATCH_MNT/foo >/dev/null
41 # Create a file with many extents. We later want to shrink truncate it and
42 # add a prealloc extent beyond its new size.
43 for ((i = 1; i <= 500; i++)); do
44 offset=$(((i - 1) * 4 * 1024))
45 $XFS_IO_PROG -f -s -c "pwrite -S 0xcf $offset 4K" \
46 $SCRATCH_MNT/bar >/dev/null
49 # A file which already has a prealloc extent beyond its size.
50 # The fsync done on it is motivated by differences in the btrfs implementation
51 # of fsync (first fsync has different logic from subsequent fsyncs).
52 $XFS_IO_PROG -f -c "pwrite -S 0xf1 0 256K" \
53 -c "falloc -k 256K 768K" \
55 $SCRATCH_MNT/baz >/dev/null
57 # Make sure everything done so far is durably persisted.
60 # Allocate an extent beyond the size of the first test file and fsync it.
61 $XFS_IO_PROG -c "falloc -k 256K 1M"\
65 # Do a shrinking truncate of our test file, add a prealloc extent to it after
66 # its new size and fsync it.
67 $XFS_IO_PROG -c "truncate 256K" \
68 -c "falloc -k 256K 1M"\
72 # Allocate another extent beyond the size of file baz.
73 $XFS_IO_PROG -c "falloc -k 1M 2M"\
77 # Simulate a power failure and mount the filesystem to check that the extents
78 # previously allocated were not lost and the file sizes are correct.
79 _flakey_drop_and_remount
81 echo "File foo fiemap:"
82 $XFS_IO_PROG -c "fiemap -v" $SCRATCH_MNT/foo | _filter_hole_fiemap
84 stat --format %s $SCRATCH_MNT/foo
86 echo "File bar fiemap:"
87 $XFS_IO_PROG -c "fiemap -v" $SCRATCH_MNT/bar | _filter_hole_fiemap
89 stat --format %s $SCRATCH_MNT/bar
91 echo "File baz fiemap:"
92 $XFS_IO_PROG -c "fiemap -v" $SCRATCH_MNT/baz | _filter_hole_fiemap
94 stat --format %s $SCRATCH_MNT/baz