generic: test deadlock on O_DIRECT|O_DSYNC
[xfstests-dev.git] / tests / generic / 098
1 #! /bin/bash
2 # SPDX-License-Identifier: GPL-2.0
3 # Copyright (C) 2015 SUSE Linux Products GmbH. All Rights Reserved.
4 #
5 # FSQA Test No. 098
6 #
7 # Test that after truncating a file into the middle of a hole causes the new
8 # size of the file to be persisted after a clean unmount of the filesystem (or
9 # after the inode is evicted). This is for the case where all the data following
10 # the hole is not yet durably persisted, that is, that data is only present in
11 # the page cache.
12 #
13 # This test is motivated by an issue found in btrfs.
14 #
15 seq=`basename $0`
16 seqres=$RESULT_DIR/$seq
17 echo "QA output created by $seq"
18 tmp=/tmp/$$
19 status=1        # failure is the default!
20 trap "_cleanup; exit \$status" 0 1 2 3 15
21
22 _cleanup()
23 {
24         rm -f $tmp.*
25 }
26
27 # get standard environment, filters and checks
28 . ./common/rc
29 . ./common/filter
30
31 # real QA test starts here
32 _supported_fs generic
33 _supported_os Linux
34 _require_scratch
35
36 # This test was motivated by an issue found in btrfs when the btrfs no-holes
37 # feature is enabled (introduced in kernel 3.14). So enable the feature if the
38 # fs being tested is btrfs.
39 if [ $FSTYP == "btrfs" ]; then
40         _require_btrfs_fs_feature "no_holes"
41         _require_btrfs_mkfs_feature "no-holes"
42         MKFS_OPTIONS="$MKFS_OPTIONS -O no-holes"
43 fi
44
45 rm -f $seqres.full
46
47 _scratch_mkfs >>$seqres.full 2>&1
48 _scratch_mount
49
50 workout()
51 {
52         local need_sync=$1
53
54         # Create our test file with some data and durably persist it.
55         $XFS_IO_PROG -t -f -c "pwrite -S 0xaa 0 128K" $SCRATCH_MNT/foo | _filter_xfs_io
56         sync
57
58         # Append some data to the file, increasing its size, and leave a hole between
59         # the old size and the start offset if the following write. So our file gets
60         # a hole in the range [128Kb, 256Kb[.
61         $XFS_IO_PROG -c "pwrite -S 0xbb 256K 32K" $SCRATCH_MNT/foo | _filter_xfs_io
62
63         # This 'sync' is to flush file extent on disk and update on-disk inode size.
64         # This is required to trigger a bug in btrfs truncate where it updates on-disk
65         # inode size incorrectly.
66         if [ $need_sync -eq 1 ]; then
67                 sync
68         fi
69
70         # Now truncate our file to a smaller size that is in the middle of the hole we
71         # previously created.
72         # If we don't flush dirty page cache above, on most truncate
73         # implementations the data we appended before gets discarded from
74         # memory (with truncate_setsize()) and never ends up being written to
75         # disk.
76         $XFS_IO_PROG -c "truncate 160K" $SCRATCH_MNT/foo
77
78         _scratch_cycle_mount
79
80         # We expect to see a file with a size of 160Kb, with the first 128Kb of data all
81         # having the value 0xaa and the remaining 32Kb of data all having the value 0x00
82         echo "File content after remount:"
83         od -t x1 $SCRATCH_MNT/foo
84 }
85
86 workout 0
87 # flush after each write
88 workout 1
89
90 status=0
91 exit