2 # SPDX-License-Identifier: GPL-2.0
3 # Copyright (c) 2018 Oracle. All Rights Reserved.
7 # Test various swapfile activation oddities, having used fcollapse to
8 # create discontiguous ranges in the file.
11 seqres=$RESULT_DIR/$seq
12 echo "QA output created by $seq"
16 status=1 # failure is the default!
17 trap "_cleanup; exit \$status" 0 1 2 3 15
22 swapoff $swapfile 2> /dev/null
26 # get standard environment, filters and checks
30 # remove previous $seqres.full before test
33 # real QA test starts here
35 _require_scratch_swapfile
36 _require_test_program mkswap
37 _require_test_program swapon
38 _require_xfs_io_command "fcollapse"
41 _scratch_mkfs >>$seqres.full 2>&1
42 _scratch_mount >>$seqres.full 2>&1
44 swapfile=$SCRATCH_MNT/swap
46 page_size=$(get_page_size)
51 # Swap files must be nocow on Btrfs.
52 $CHATTR_PROG +C $swapfile >> $seqres.full 2>&1
53 "$here/src/mkswap" $swapfile >> $seqres.full
54 "$here/src/swapon" $swapfile 2>&1 | _filter_scratch
55 swapoff $swapfile 2>> $seqres.full
59 # Create a swap file with a large discontiguous range(?)
60 echo "large discontig swap" | tee -a $seqres.full
61 _pwrite_byte 0x58 0 $((len * 2)) $swapfile >> $seqres.full
62 old_sz="$(_get_filesize $swapfile)"
63 $XFS_IO_PROG -c "fcollapse $((len / 2)) $len" $swapfile >> $seqres.full 2>&1
64 new_sz="$(_get_filesize $swapfile)"
65 if [ $old_sz -gt $new_sz ]; then
66 swapfile_cycle $swapfile
70 # Create a swap file with a small discontiguous range(?)
71 echo "small discontig swap" | tee -a $seqres.full
72 _pwrite_byte 0x58 0 $((len + 1024)) $swapfile >> $seqres.full
73 old_sz="$(_get_filesize $swapfile)"
74 $XFS_IO_PROG -c "fcollapse 66560 1024" $swapfile >> $seqres.full 2>&1
75 new_sz="$(_get_filesize $swapfile)"
76 if [ $old_sz -gt $new_sz ]; then
77 swapfile_cycle $swapfile