generic: test deadlock on O_DIRECT|O_DSYNC
[xfstests-dev.git] / tests / generic / 497
1 #! /bin/bash
2 # SPDX-License-Identifier: GPL-2.0
3 # Copyright (c) 2018 Oracle.  All Rights Reserved.
4 #
5 # FS QA Test No. 497
6 #
7 # Test various swapfile activation oddities, having used fcollapse to
8 # create discontiguous ranges in the file.
9 #
10 seq=`basename $0`
11 seqres=$RESULT_DIR/$seq
12 echo "QA output created by $seq"
13
14 here=`pwd`
15 tmp=/tmp/$$
16 status=1        # failure is the default!
17 trap "_cleanup; exit \$status" 0 1 2 3 15
18
19 _cleanup()
20 {
21         cd /
22         swapoff $swapfile 2> /dev/null
23         rm -f $tmp.*
24 }
25
26 # get standard environment, filters and checks
27 . ./common/rc
28 . ./common/filter
29
30 # remove previous $seqres.full before test
31 rm -f $seqres.full
32
33 # real QA test starts here
34 _supported_fs generic
35 _supported_os Linux
36 _require_scratch_swapfile
37 _require_test_program mkswap
38 _require_test_program swapon
39 _require_xfs_io_command "fcollapse"
40
41 rm -f $seqres.full
42 _scratch_mkfs >>$seqres.full 2>&1
43 _scratch_mount >>$seqres.full 2>&1
44
45 swapfile=$SCRATCH_MNT/swap
46 len=$((2 * 1048576))
47 page_size=$(get_page_size)
48
49 swapfile_cycle() {
50         local swapfile="$1"
51
52         # Swap files must be nocow on Btrfs.
53         $CHATTR_PROG +C $swapfile >> $seqres.full 2>&1
54         "$here/src/mkswap" $swapfile >> $seqres.full
55         "$here/src/swapon" $swapfile 2>&1 | _filter_scratch
56         swapoff $swapfile 2>> $seqres.full
57         rm -f $swapfile
58 }
59
60 # Create a swap file with a large discontiguous range(?)
61 echo "large discontig swap" | tee -a $seqres.full
62 _pwrite_byte 0x58 0 $((len * 2)) $swapfile >> $seqres.full
63 old_sz="$(_get_filesize $swapfile)"
64 $XFS_IO_PROG -c "fcollapse $((len / 2)) $len" $swapfile >> $seqres.full 2>&1
65 new_sz="$(_get_filesize $swapfile)"
66 if [ $old_sz -gt $new_sz ]; then
67         swapfile_cycle $swapfile
68 fi
69 rm -f $swapfile
70
71 # Create a swap file with a small discontiguous range(?)
72 echo "small discontig swap" | tee -a $seqres.full
73 _pwrite_byte 0x58 0 $((len + 1024)) $swapfile >> $seqres.full
74 old_sz="$(_get_filesize $swapfile)"
75 $XFS_IO_PROG -c "fcollapse 66560 1024" $swapfile >> $seqres.full 2>&1
76 new_sz="$(_get_filesize $swapfile)"
77 if [ $old_sz -gt $new_sz ]; then
78         swapfile_cycle $swapfile
79 fi
80 rm -f $swapfile
81
82 status=0
83 exit