generic/520: Remove sync in clean_dir
[xfstests-dev.git] / tests / generic / 483
1 #! /bin/bash
2 # SPDX-License-Identifier: GPL-2.0
3 # Copyright (C) 2018 SUSE Linux Products GmbH. All Rights Reserved.
4 #
5 # FSQA Test No. 483
6 #
7 # Test that fsync operations preserve extents allocated with fallocate(2) that
8 # are placed beyond a file's size.
9 #
10 seq=`basename $0`
11 seqres=$RESULT_DIR/$seq
12 echo "QA output created by $seq"
13 tmp=/tmp/$$
14 status=1        # failure is the default!
15 trap "_cleanup; exit \$status" 0 1 2 3 15
16
17 _cleanup()
18 {
19         _cleanup_flakey
20         cd /
21         rm -f $tmp.*
22 }
23
24 # get standard environment, filters and checks
25 . ./common/rc
26 . ./common/filter
27 . ./common/dmflakey
28 . ./common/punch
29
30 # real QA test starts here
31 _supported_fs generic
32 _supported_os Linux
33 _require_scratch
34 _require_dm_target flakey
35 _require_xfs_io_command "falloc" "-k"
36 _require_xfs_io_command "fiemap"
37
38 rm -f $seqres.full
39
40 _scratch_mkfs >>$seqres.full 2>&1
41 _require_metadata_journaling $SCRATCH_DEV
42 _init_flakey
43 _mount_flakey
44
45 # Create our test files.
46 $XFS_IO_PROG -f -c "pwrite -S 0xea 0 256K" $SCRATCH_MNT/foo >/dev/null
47
48 # Create a file with many extents. We later want to shrink truncate it and
49 # add a prealloc extent beyond its new size.
50 for ((i = 1; i <= 500; i++)); do
51         offset=$(((i - 1) * 4 * 1024))
52         $XFS_IO_PROG -f -s -c "pwrite -S 0xcf $offset 4K" \
53                 $SCRATCH_MNT/bar >/dev/null
54 done
55
56 # A file which already has a prealloc extent beyond its size.
57 # The fsync done on it is motivated by differences in the btrfs implementation
58 # of fsync (first fsync has different logic from subsequent fsyncs).
59 $XFS_IO_PROG -f -c "pwrite -S 0xf1 0 256K" \
60              -c "falloc -k 256K 768K" \
61              -c "fsync" \
62              $SCRATCH_MNT/baz >/dev/null
63
64 # Make sure everything done so far is durably persisted.
65 sync
66
67 # Allocate an extent beyond the size of the first test file and fsync it.
68 $XFS_IO_PROG -c "falloc -k 256K 1M"\
69              -c "fsync" \
70              $SCRATCH_MNT/foo
71
72 # Do a shrinking truncate of our test file, add a prealloc extent to it after
73 # its new size and fsync it.
74 $XFS_IO_PROG -c "truncate 256K" \
75              -c "falloc -k 256K 1M"\
76              -c "fsync" \
77              $SCRATCH_MNT/bar
78
79 # Allocate another extent beyond the size of file baz.
80 $XFS_IO_PROG -c "falloc -k 1M 2M"\
81              -c "fsync" \
82              $SCRATCH_MNT/baz
83
84 # Simulate a power failure and mount the filesystem to check that the extents
85 # previously allocated were not lost and the file sizes are correct.
86 _flakey_drop_and_remount
87
88 echo "File foo fiemap:"
89 $XFS_IO_PROG -c "fiemap -v" $SCRATCH_MNT/foo | _filter_hole_fiemap
90 echo "File foo size:"
91 stat --format %s $SCRATCH_MNT/foo
92
93 echo "File bar fiemap:"
94 $XFS_IO_PROG -c "fiemap -v" $SCRATCH_MNT/bar | _filter_hole_fiemap
95 echo "File bar size:"
96 stat --format %s $SCRATCH_MNT/bar
97
98 echo "File baz fiemap:"
99 $XFS_IO_PROG -c "fiemap -v" $SCRATCH_MNT/baz | _filter_hole_fiemap
100 echo "File baz size:"
101 stat --format %s $SCRATCH_MNT/baz
102
103 _unmount_flakey
104 _cleanup_flakey
105
106 status=0
107 exit