4 # Test various swapfile activation oddities on filesystems that support
5 # fallocated swapfiles.
7 #-----------------------------------------------------------------------
8 # Copyright (c) 2018 Oracle. All Rights Reserved.
10 # This program is free software; you can redistribute it and/or
11 # modify it under the terms of the GNU General Public License as
12 # published by the Free Software Foundation.
14 # This program is distributed in the hope that it would be useful,
15 # but WITHOUT ANY WARRANTY; without even the implied warranty of
16 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 # GNU General Public License for more details.
19 # You should have received a copy of the GNU General Public License
20 # along with this program; if not, write the Free Software Foundation,
21 # Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
23 #-----------------------------------------------------------------------
26 seqres=$RESULT_DIR/$seq
27 echo "QA output created by $seq"
31 status=1 # failure is the default!
32 trap "_cleanup; exit \$status" 0 1 2 3 15
37 swapoff $swapfile 2> /dev/null
41 # get standard environment, filters and checks
45 # remove previous $seqres.full before test
48 # real QA test starts here
51 _require_scratch_swapfile
52 _require_test_program mkswap
53 _require_test_program swapon
54 _require_xfs_io_command "falloc"
57 _scratch_mkfs >>$seqres.full 2>&1
58 _scratch_mount >>$seqres.full 2>&1
60 swapfile=$SCRATCH_MNT/swap
62 page_size=$(get_page_size)
67 # Swap files must be nocow on Btrfs.
68 $CHATTR_PROG +C $swapfile >> $seqres.full 2>&1
69 "$here/src/mkswap" $swapfile >> $seqres.full
70 "$here/src/swapon" $swapfile 2>&1 | _filter_scratch
71 swapoff $swapfile 2>> $seeqres.full
75 # Create a fallocated swap file
76 echo "fallocate swap" | tee -a $seqres.full
77 $XFS_IO_PROG -f -c "falloc 0 $len" $swapfile >> $seqres.full
78 $CHATTR_PROG +C $swapfile >> $seqres.full 2>&1
79 "$here/src/mkswap" $swapfile
80 "$here/src/swapon" $swapfile >> $seqres.full 2>&1 || \
81 _notrun "fallocated swap not supported here"
84 # Create a fallocated swap file and touch every other $PAGE_SIZE to create
85 # a mess of written/unwritten extent records
86 echo "mixed swap" | tee -a $seqres.full
87 $XFS_IO_PROG -f -c "falloc 0 $len" $swapfile >> $seqres.full
88 seq $page_size $((page_size * 2)) $len | while read offset; do
89 _pwrite_byte 0x58 $offset 1 $swapfile >> $seqres.full
91 swapfile_cycle $swapfile