[2/7] generic/{472,496}: fix swap file creation on Btrfs
diff mbox series

Message ID 6da5f398715af4f7478554920470a85e8a186b50.1541193856.git.osandov@fb.com
State New
Headers show
Series
  • fstests: test Btrfs swapfile support
Related show

Commit Message

Omar Sandoval Nov. 2, 2018, 9:29 p.m. UTC
From: Omar Sandoval <osandov@fb.com>

The swap file must be set nocow before it is written to, otherwise it is
ignored and Btrfs refuses to activate it as swap.

Fixes: 25ce9740065e ("generic: test swapfile creation, activation, and deactivation")
Signed-off-by: Omar Sandoval <osandov@fb.com>
---
 tests/generic/472 | 14 ++++++--------
 tests/generic/496 |  6 +++---
 2 files changed, 9 insertions(+), 11 deletions(-)

Patch
diff mbox series

diff --git a/tests/generic/472 b/tests/generic/472
index 04ed3e73..aba4a007 100755
--- a/tests/generic/472
+++ b/tests/generic/472
@@ -42,13 +42,15 @@  _scratch_mount >>$seqres.full 2>&1
 
 swapfile=$SCRATCH_MNT/swap
 len=$((2 * 1048576))
-page_size=$(get_page_size)
 
 swapfile_cycle() {
 	local swapfile="$1"
+	local len="$2"
 
+	touch $swapfile
 	# Swap files must be nocow on Btrfs.
 	$CHATTR_PROG +C $swapfile >> $seqres.full 2>&1
+	_pwrite_byte 0x58 0 $len $swapfile >> $seqres.full
 	"$here/src/mkswap" $swapfile >> $seqres.full
 	"$here/src/swapon" $swapfile 2>&1 | _filter_scratch
 	swapoff $swapfile 2>> $seqres.full
@@ -57,20 +59,16 @@  swapfile_cycle() {
 
 # Create a regular swap file
 echo "regular swap" | tee -a $seqres.full
-_pwrite_byte 0x58 0 $len $swapfile >> $seqres.full
-swapfile_cycle $swapfile
+swapfile_cycle $swapfile $len
 
 # 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
+swapfile_cycle $swapfile $((len + 3))
 
 # 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
+swapfile_cycle $swapfile $(($(get_page_size) * 3))
 
 status=0
 exit
diff --git a/tests/generic/496 b/tests/generic/496
index 968b8012..3083eef0 100755
--- a/tests/generic/496
+++ b/tests/generic/496
@@ -49,8 +49,6 @@  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>> $seqres.full
@@ -59,8 +57,10 @@  swapfile_cycle() {
 
 # Create a fallocated swap file
 echo "fallocate swap" | tee -a $seqres.full
-$XFS_IO_PROG -f -c "falloc 0 $len" $swapfile >> $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
 "$here/src/swapon" $swapfile >> $seqres.full 2>&1 || \
 	_notrun "fallocated swap not supported here"