From: Darrick J. Wong Date: Thu, 7 Jun 2018 15:17:10 +0000 (-0700) Subject: generic: test swapfile creation, activation, and deactivation X-Git-Tag: v2022.05.01~1507 X-Git-Url: https://www.infradead.org/git/?a=commitdiff_plain;h=25ce9740065e1ac00b699b3fb84cc651aeaf5032;p=users%2Fhch%2Fxfstests-dev.git generic: test swapfile creation, activation, and deactivation Test swapfile activation and deactivation. Signed-off-by: Darrick J. Wong Reviewed-by: Eryu Guan Signed-off-by: Eryu Guan --- diff --git a/tests/generic/472 b/tests/generic/472 new file mode 100755 index 000000000..9cc29043e --- /dev/null +++ b/tests/generic/472 @@ -0,0 +1,91 @@ +#! /bin/bash +# FS QA Test No. 472 +# +# Test various swapfile activation oddities. +# +#----------------------------------------------------------------------- +# Copyright (c) 2018 Oracle. All Rights Reserved. +# +# This program is free software; you can redistribute it and/or +# modify it under the terms of the GNU General Public License as +# published by the Free Software Foundation. +# +# This program is distributed in the hope that it would be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program; if not, write the Free Software Foundation, +# Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA +# +#----------------------------------------------------------------------- + +seq=`basename $0` +seqres=$RESULT_DIR/$seq +echo "QA output created by $seq" + +here=`pwd` +tmp=/tmp/$$ +status=1 # failure is the default! +trap "_cleanup; exit \$status" 0 1 2 3 15 + +_cleanup() +{ + cd / + swapoff $swapfile 2> /dev/null + rm -f $tmp.* +} + +# get standard environment, filters and checks +. ./common/rc +. ./common/filter + +# remove previous $seqres.full before test +rm -f $seqres.full + +# real QA test starts here +_supported_fs generic +_supported_os Linux +_require_scratch_swapfile +_require_test_program mkswap +_require_test_program swapon + +rm -f $seqres.full +_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" + + # Swap files must be nocow on Btrfs. + $CHATTR_PROG +C $swapfile >> $seqres.full 2>&1 + "$here/src/mkswap" $swapfile >> $seqres.full + "$here/src/swapon" $swapfile 2>&1 | _filter_scratch + swapoff $swapfile 2>> $seeqres.full + rm -f $swapfile +} + +# Create a regular swap file +echo "regular swap" | tee -a $seqres.full +_pwrite_byte 0x58 0 $len $swapfile >> $seqres.full +swapfile_cycle $swapfile + +# Create a swap file with a little too much junk on the end +echo "too long swap" | tee -a $seqres.full +_pwrite_byte 0x58 0 $((len + 3)) $swapfile >> $seqres.full +swapfile_cycle $swapfile + +# Create a ridiculously small swap file. Each swap file must have at least +# two pages after the header page. +echo "tiny swap" | tee -a $seqres.full +tiny_len=$((page_size * 3)) +_pwrite_byte 0x58 0 $tiny_len $swapfile >> $seqres.full +swapfile_cycle $swapfile + +status=0 +exit diff --git a/tests/generic/472.out b/tests/generic/472.out new file mode 100644 index 000000000..e0e2b70ea --- /dev/null +++ b/tests/generic/472.out @@ -0,0 +1,4 @@ +QA output created by 472 +regular swap +too long swap +tiny swap diff --git a/tests/generic/496 b/tests/generic/496 new file mode 100755 index 000000000..4f661f8df --- /dev/null +++ b/tests/generic/496 @@ -0,0 +1,94 @@ +#! /bin/bash +# FS QA Test No. 496 +# +# Test various swapfile activation oddities on filesystems that support +# fallocated swapfiles. +# +#----------------------------------------------------------------------- +# Copyright (c) 2018 Oracle. All Rights Reserved. +# +# This program is free software; you can redistribute it and/or +# modify it under the terms of the GNU General Public License as +# published by the Free Software Foundation. +# +# This program is distributed in the hope that it would be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program; if not, write the Free Software Foundation, +# Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA +# +#----------------------------------------------------------------------- + +seq=`basename $0` +seqres=$RESULT_DIR/$seq +echo "QA output created by $seq" + +here=`pwd` +tmp=/tmp/$$ +status=1 # failure is the default! +trap "_cleanup; exit \$status" 0 1 2 3 15 + +_cleanup() +{ + cd / + swapoff $swapfile 2> /dev/null + rm -f $tmp.* +} + +# get standard environment, filters and checks +. ./common/rc +. ./common/filter + +# remove previous $seqres.full before test +rm -f $seqres.full + +# real QA test starts here +_supported_fs generic +_supported_os Linux +_require_scratch_swapfile +_require_test_program mkswap +_require_test_program swapon +_require_xfs_io_command "falloc" + +rm -f $seqres.full +_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" + + # Swap files must be nocow on Btrfs. + $CHATTR_PROG +C $swapfile >> $seqres.full 2>&1 + "$here/src/mkswap" $swapfile >> $seqres.full + "$here/src/swapon" $swapfile 2>&1 | _filter_scratch + swapoff $swapfile 2>> $seeqres.full + rm -f $swapfile +} + +# Create a fallocated swap file +echo "fallocate swap" | tee -a $seqres.full +$XFS_IO_PROG -f -c "falloc 0 $len" $swapfile >> $seqres.full +$CHATTR_PROG +C $swapfile >> $seqres.full 2>&1 +"$here/src/mkswap" $swapfile +"$here/src/swapon" $swapfile >> $seqres.full 2>&1 || \ + _notrun "fallocated swap not supported here" +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 diff --git a/tests/generic/496.out b/tests/generic/496.out new file mode 100644 index 000000000..d2a43a976 --- /dev/null +++ b/tests/generic/496.out @@ -0,0 +1,3 @@ +QA output created by 496 +fallocate swap +mixed swap diff --git a/tests/generic/497 b/tests/generic/497 new file mode 100755 index 000000000..8dd1d32b8 --- /dev/null +++ b/tests/generic/497 @@ -0,0 +1,98 @@ +#! /bin/bash +# FS QA Test No. 497 +# +# Test various swapfile activation oddities, having used fcollapse to +# create discontiguous ranges in the file. +# +#----------------------------------------------------------------------- +# Copyright (c) 2018 Oracle. All Rights Reserved. +# +# This program is free software; you can redistribute it and/or +# modify it under the terms of the GNU General Public License as +# published by the Free Software Foundation. +# +# This program is distributed in the hope that it would be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program; if not, write the Free Software Foundation, +# Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA +# +#----------------------------------------------------------------------- + +seq=`basename $0` +seqres=$RESULT_DIR/$seq +echo "QA output created by $seq" + +here=`pwd` +tmp=/tmp/$$ +status=1 # failure is the default! +trap "_cleanup; exit \$status" 0 1 2 3 15 + +_cleanup() +{ + cd / + swapoff $swapfile 2> /dev/null + rm -f $tmp.* +} + +# get standard environment, filters and checks +. ./common/rc +. ./common/filter + +# remove previous $seqres.full before test +rm -f $seqres.full + +# real QA test starts here +_supported_fs generic +_supported_os Linux +_require_scratch_swapfile +_require_test_program mkswap +_require_test_program swapon +_require_xfs_io_command "fcollapse" + +rm -f $seqres.full +_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" + + # Swap files must be nocow on Btrfs. + $CHATTR_PROG +C $swapfile >> $seqres.full 2>&1 + "$here/src/mkswap" $swapfile >> $seqres.full + "$here/src/swapon" $swapfile 2>&1 | _filter_scratch + swapoff $swapfile 2>> $seeqres.full + rm -f $swapfile +} + +# Create a swap file with a large discontiguous range(?) +echo "large discontig swap" | tee -a $seqres.full +_pwrite_byte 0x58 0 $((len * 2)) $swapfile >> $seqres.full +old_sz="$(stat -c '%s' $swapfile)" +$XFS_IO_PROG -c "fcollapse $((len / 2)) $len" $swapfile >> $seqres.full 2>&1 +new_sz="$(stat -c '%s' $swapfile)" +if [ $old_sz -gt $new_sz ]; then + swapfile_cycle $swapfile +fi +rm -f $swapfile + +# Create a swap file with a small discontiguous range(?) +echo "small discontig swap" | tee -a $seqres.full +_pwrite_byte 0x58 0 $((len + 1024)) $swapfile >> $seqres.full +old_sz="$(stat -c '%s' $swapfile)" +$XFS_IO_PROG -c "fcollapse 66560 1024" $swapfile >> $seqres.full 2>&1 +new_sz="$(stat -c '%s' $swapfile)" +if [ $old_sz -gt $new_sz ]; then + swapfile_cycle $swapfile +fi +rm -f $swapfile + +status=0 +exit diff --git a/tests/generic/497.out b/tests/generic/497.out new file mode 100644 index 000000000..a465c8c7c --- /dev/null +++ b/tests/generic/497.out @@ -0,0 +1,3 @@ +QA output created by 497 +large discontig swap +small discontig swap diff --git a/tests/generic/group b/tests/generic/group index 4339c64c0..397f9c1ce 100644 --- a/tests/generic/group +++ b/tests/generic/group @@ -474,6 +474,7 @@ 469 auto quick 470 auto quick dax 471 auto quick rw +472 auto quick swap 473 broken 474 auto quick shutdown metadata 475 shutdown auto log metadata @@ -497,3 +498,5 @@ 493 auto quick swap 494 auto quick swap punch 495 auto quick swap +496 auto quick swap +497 auto quick swap collapse