| #! /bin/bash |
| # SPDX-License-Identifier: GPL-2.0 |
| # Copyright (c) 2018 Oracle. All Rights Reserved. |
| # |
| # FS QA Test No. 496 |
| # |
| # Test various swapfile activation oddities on filesystems that support |
| # fallocated swapfiles (for given fs ext4/xfs) |
| # |
| . ./common/preamble |
| _begin_fstest auto quick swap prealloc |
| |
| # Override the default cleanup function. |
| _cleanup() |
| { |
| cd / |
| swapoff $swapfile 2> /dev/null |
| rm -f $tmp.* |
| } |
| |
| # Import common functions. |
| . ./common/filter |
| |
| # real QA test starts here |
| _supported_fs generic |
| _require_scratch_swapfile |
| _require_test_program mkswap |
| _require_test_program swapon |
| _require_xfs_io_command "falloc" |
| |
| _scratch_mkfs >>$seqres.full 2>&1 |
| _scratch_mount >>$seqres.full 2>&1 |
| |
| swapfile=$SCRATCH_MNT/swap |
| len=$((2 * 1048576)) |
| page_size=$(_get_page_size) |
| |
| swapfile_cycle() { |
| local swapfile="$1" |
| |
| "$here/src/mkswap" $swapfile >> $seqres.full |
| "$here/src/swapon" $swapfile 2>&1 | _filter_scratch |
| swapoff $swapfile 2>> $seqres.full |
| rm -f $swapfile |
| } |
| |
| # Create a fallocated swap file |
| echo "fallocate swap" | tee -a $seqres.full |
| touch $swapfile |
| # Swap files must be nocow on Btrfs. |
| $CHATTR_PROG +C $swapfile >> $seqres.full 2>&1 |
| $XFS_IO_PROG -f -c "falloc 0 $len" $swapfile >> $seqres.full |
| "$here/src/mkswap" $swapfile |
| |
| # ext4/xfs should not fail for swapon on fallocated files |
| case $FSTYP in |
| ext4|xfs) |
| "$here/src/swapon" $swapfile >> $seqres.full 2>&1 || \ |
| _fail "swapon failed on fallocated file" |
| ;; |
| *) |
| "$here/src/swapon" $swapfile >> $seqres.full 2>&1 || \ |
| _notrun "fallocated swap not supported here" |
| ;; |
| esac |
| swapoff $swapfile |
| |
| # Create a fallocated swap file and touch every other $PAGE_SIZE to create |
| # a mess of written/unwritten extent records |
| echo "mixed swap" | tee -a $seqres.full |
| $XFS_IO_PROG -f -c "falloc 0 $len" $swapfile >> $seqres.full |
| seq $page_size $((page_size * 2)) $len | while read offset; do |
| _pwrite_byte 0x58 $offset 1 $swapfile >> $seqres.full |
| done |
| swapfile_cycle $swapfile |
| |
| status=0 |
| exit |