Skip to contentSkip to conversation

xfstests: generic swap file tests

PATCH Superseded Omar Sandoval 2 participants 6 messages May 16, 2018

v1 of 3 Superseded Latest is v3 →

lore
Share & tools
lore
#0 lore raw

cover xfstests: generic swap file tests

From: Omar Sandoval <[email protected]>

Hi,

I picked up my Btrfs swap file series again and added a few tests as a result. I'm still working on the Btrfs-specific tests, but since Darrick has a pending swap file test, I figured I'd send these out and see if we can combine them. They're a little rough around the edges.

Thanks!

Omar Sandoval (4):
generic: enable swapfile tests on Btrfs
generic: add test for dedupe on an active swapfile
generic: add test for truncate/fpunch of an active swapfile
generic: test invalid swap file activation

 .gitignore            |  2 ++
 common/rc             |  3 ++
 src/Makefile          |  2 +-
 src/mkswap.c          | 83 +++++++++++++++++++++++++++++++++++++++++++
 src/swapon.c          | 24 +++++++++++++
 tests/generic/356     |  6 +++-
 tests/generic/357     |  6 +++-
 tests/generic/488     | 78 ++++++++++++++++++++++++++++++++++++++++
 tests/generic/488.out |  7 ++++
 tests/generic/489     | 77 +++++++++++++++++++++++++++++++++++++++
 tests/generic/489.out |  8 +++++
 tests/generic/490     | 75 ++++++++++++++++++++++++++++++++++++++
 tests/generic/490.out |  5 +++
 tests/generic/group   |  2 ++
 14 files changed, 375 insertions(+), 3 deletions(-)
 create mode 100644 src/mkswap.c
 create mode 100644 src/swapon.c
 create mode 100755 tests/generic/488
 create mode 100644 tests/generic/488.out
 create mode 100755 tests/generic/489
 create mode 100644 tests/generic/489.out
 create mode 100755 tests/generic/490
 create mode 100644 tests/generic/490.out
Signature · 1 line
2.17.0
#1 lore raw

PATCH 1/4 generic: enable swapfile tests on Btrfs

From: Omar Sandoval <[email protected]>

Commit 8c96cfbfe530 ("generic/35[67]: disable swapfile tests on Btrfs") disabled the swapfile tests on Btrfs because it did not support swapfiles at the time. Now that we're adding support, we want these tests to run, but they don't. _require_scratch_swapfile always fails for Btrfs because swapfiles on Btrfs must be set to nocow. After fixing that, generic/356 and generic/357 fail for the same reason. After fixing _that_, both tests still fail because we don't allow reflinking a non-checksummed extent (which nocow implies) to a checksummed extent. Do the chattrs everywhere, which gets these tests running on kernels supporting Btrfs swapfiles.

---
 common/rc         | 3 +++
 tests/generic/356 | 6 +++++-
 tests/generic/357 | 6 +++++-
 3 files changed, 13 insertions(+), 2 deletions(-)
common/rc +3 -0
index ffe53236..5405f7d0 100644
@@ -2233,6 +2233,9 @@ _require_scratch_swapfile()
 	# Minimum size for mkswap is 10 pages
 	local size=$(($(get_page_size) * 10))
 
+	touch "$SCRATCH_MNT/swap"
+	chmod 0600 "$SCRATCH_MNT/swap"
+	chattr +C "$SCRATCH_MNT/swap" >/dev/null 2>&1
 	_pwrite_byte 0x61 0 "$size" "$SCRATCH_MNT/swap" >/dev/null 2>&1
 	mkswap "$SCRATCH_MNT/swap" >/dev/null 2>&1
 	if ! swapon "$SCRATCH_MNT/swap" >/dev/null 2>&1; then
tests/generic/356 +5 -1
index 51eeb652..09c146a9 100755
@@ -59,7 +59,11 @@ blocks=160
 blksz=65536
 
 echo "Initialize file"
-echo >> $seqres.full
+touch "$testdir/file1"
+chmod 0600 "$testdir/file1"
+chattr +C "$testdir/file1" >/dev/null 2>&1
+touch "$testdir/file2"
+chattr +C "$testdir/file2" >/dev/null 2>&1
 _pwrite_byte 0x61 0 $((blocks * blksz)) $testdir/file1 >> $seqres.full
 mkswap -U 27376b42-ff65-42ca-919f-6c9b62292a5c $testdir/file1 >> $seqres.full
 swapon $testdir/file1
tests/generic/357 +5 -1
index 0dd0c10f..742f37d1 100755
@@ -59,7 +59,11 @@ blocks=160
 blksz=65536
 
 echo "Initialize file"
-echo >> $seqres.full
+touch "$testdir/file1"
+chmod 0600 "$testdir/file1"
+chattr +C "$testdir/file1" >/dev/null 2>&1
+touch "$testdir/file2"
+chattr +C "$testdir/file2" >/dev/null 2>&1
 _pwrite_byte 0x61 0 $((blocks * blksz)) $testdir/file1 >> $seqres.full
 mkswap -U 27376b42-ff65-42ca-919f-6c9b62292a5c $testdir/file1 >> $seqres.full
 _cp_reflink $testdir/file1 $testdir/file2 2>&1 | _filter_scratch
Signature · 1 line
2.17.0
#2 lore raw

Re: [PATCH 1/4] generic: enable swapfile tests on Btrfs

Quoted 57 lines · Omar Sandoval

From: Omar Sandoval <[email protected]>

Commit 8c96cfbfe530 ("generic/35[67]: disable swapfile tests on Btrfs") disabled the swapfile tests on Btrfs because it did not support swapfiles at the time. Now that we're adding support, we want these tests to run, but they don't. _require_scratch_swapfile always fails for Btrfs because swapfiles on Btrfs must be set to nocow. After fixing that, generic/356 and generic/357 fail for the same reason. After fixing _that_, both tests still fail because we don't allow reflinking a non-checksummed extent (which nocow implies) to a checksummed extent. Do the chattrs everywhere, which gets these tests running on kernels supporting Btrfs swapfiles.

---
 common/rc         | 3 +++
 tests/generic/356 | 6 +++++-
 tests/generic/357 | 6 +++++-
 3 files changed, 13 insertions(+), 2 deletions(-)
common/rc +3 -0
index ffe53236..5405f7d0 100644
@@ -2233,6 +2233,9 @@ _require_scratch_swapfile()
 	# Minimum size for mkswap is 10 pages
 	local size=$(($(get_page_size) * 10))
 
+	touch "$SCRATCH_MNT/swap"
+	chmod 0600 "$SCRATCH_MNT/swap"
+	chattr +C "$SCRATCH_MNT/swap" >/dev/null 2>&1
 	_pwrite_byte 0x61 0 "$size" "$SCRATCH_MNT/swap" >/dev/null 2>&1
 	mkswap "$SCRATCH_MNT/swap" >/dev/null 2>&1
 	if ! swapon "$SCRATCH_MNT/swap" >/dev/null 2>&1; then
tests/generic/356 +5 -1
index 51eeb652..09c146a9 100755
@@ -59,7 +59,11 @@ blocks=160
 blksz=65536
 
 echo "Initialize file"
-echo >> $seqres.full
+touch "$testdir/file1"
+chmod 0600 "$testdir/file1"
+chattr +C "$testdir/file1" >/dev/null 2>&1
+touch "$testdir/file2"
+chattr +C "$testdir/file2" >/dev/null 2>&1
 _pwrite_byte 0x61 0 $((blocks * blksz)) $testdir/file1 >> $seqres.full
 mkswap -U 27376b42-ff65-42ca-919f-6c9b62292a5c $testdir/file1 >> $seqres.full
 swapon $testdir/file1
tests/generic/357 +0 -0
index 0dd0c10f..742f37d1 100755
@@ -59,7 +59,11 @@ blocks=160
 blksz=65536

tests/generic/357 blocks=160 · line 68

Quoted 10 lines
tests/generic/357 +5 -1
 
 echo "Initialize file"
-echo >> $seqres.full
+touch "$testdir/file1"
+chmod 0600 "$testdir/file1"
+chattr +C "$testdir/file1" >/dev/null 2>&1
+touch "$testdir/file2"
+chattr +C "$testdir/file2" >/dev/null 2>&1
 _pwrite_byte 0x61 0 $((blocks * blksz)) $testdir/file1 >> $seqres.full
 mkswap -U 27376b42-ff65-42ca-919f-6c9b62292a5c $testdir/file1 >> $seqres.full

Should this get refactored into a _format_swapfile or something, rather than open coding this everywhere?

_format_swapfile() {
	local fname=$1
	local sz=$2

	touch $fname
	chmod 0600 $fname
	chattr +C $fname > /dev/null 2>&1
	_pwrite_byte 0x61 0 $sz $fname >> $seqres.full
	mkswap -U 27376b42-ff65-42ca-919f-6c9b62292a5c $fname >> $seqres.full
}

--D

Quoted 8 lines
tests/generic/357 +0 -0
 _cp_reflink $testdir/file1 $testdir/file2 2>&1 | _filter_scratch
Signature · 6 lines
2.17.0

--
To unsubscribe from this list: send the line "unsubscribe fstests" in
the body of a message to [email protected]
More majordomo info at  http://vger.kernel.org/majordomo-info.html
#3 lore raw

PATCH 2/4 generic: add test for dedupe on an active swapfile

In reply to Omar Sandoval

From: Omar Sandoval <[email protected]>

Similar to generic/356 that makes sure we can't reflink an active swapfile.

---
 tests/generic/488     | 78 +++++++++++++++++++++++++++++++++++++++++++
 tests/generic/488.out |  7 ++++
 tests/generic/group   |  1 +
 3 files changed, 86 insertions(+)
 create mode 100755 tests/generic/488
 create mode 100644 tests/generic/488.out
tests/generic/488 new file +78 -0
new file mode 100755
index 00000000..6e05048c
@@ -0,0 +1,78 @@
+#! /bin/bash
+# FS QA Test 488
+#
+# Check that we can't dedupe a swapfile.
+#
+#-----------------------------------------------------------------------
+# Copyright (c) 2018 Facebook.  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 /
+	rm -f $tmp.*
+}
+
+. ./common/rc
+. ./common/filter
+. ./common/reflink
+
+rm -f $seqres.full
+
+_supported_fs generic
+_supported_os Linux
+_require_scratch_dedupe
+
+echo "Format and mount"
+_scratch_mkfs > $seqres.full 2>&1
+_scratch_mount >> $seqres.full 2>&1
+
+testdir=$SCRATCH_MNT/test-$seq
+mkdir $testdir
+
+blocks=160
+blksz=65536
+
+echo "Initialize file"
+touch "$testdir/file1"
+chmod 0600 "$testdir/file1"
+chattr +C "$testdir/file1" >/dev/null 2>&1
+touch "$testdir/file2"
+chattr +C "$testdir/file2" >/dev/null 2>&1
+_pwrite_byte 0x61 0 $((blocks * blksz)) $testdir/file1 >> $seqres.full
+mkswap -U 27376b42-ff65-42ca-919f-6c9b62292a5c $testdir/file1 >> $seqres.full
+swapon $testdir/file1
+
+echo "Try to dedupe"
+cp $testdir/file1 $testdir/file2
+_dedupe_range $testdir/file1 0 $testdir/file2 0 $((blocks * blksz))
+_dedupe_range $testdir/file2 0 $testdir/file1 0 $((blocks * blksz))
+
+echo "Tear it down"
+swapoff $testdir/file1
+
+status=0
+exit
tests/generic/488.out new file +7 -0
new file mode 100644
index 00000000..e5a195d1
@@ -0,0 +1,7 @@
+QA output created by 488
+Format and mount
+Initialize file
+Try to dedupe
+XFS_IOC_FILE_EXTENT_SAME: Text file busy
+XFS_IOC_FILE_EXTENT_SAME: Text file busy
+Tear it down
tests/generic/group +1 -0
index dc637c96..6266213e 100644
@@ -490,3 +490,4 @@
 485 auto quick insert
 486 auto quick attr
 487 auto quick
+488 auto quick
Signature · 1 line
2.17.0
#4 lore raw

PATCH 3/4 generic: add test for truncate/fpunch of an active swapfile

In reply to Omar Sandoval

From: Omar Sandoval <[email protected]>

These should not be allowed.

---
 tests/generic/489     | 77 +++++++++++++++++++++++++++++++++++++++++++
 tests/generic/489.out |  8 +++++
 tests/generic/group   |  1 +
 3 files changed, 86 insertions(+)
 create mode 100755 tests/generic/489
 create mode 100644 tests/generic/489.out
tests/generic/489 new file +77 -0
new file mode 100755
index 00000000..a38f7dcb
@@ -0,0 +1,77 @@
+#! /bin/bash
+# FS QA Test 489
+#
+# Test truncation/hole punching of an active swapfile.
+#
+#-----------------------------------------------------------------------
+# Copyright (c) 2018 Facebook.  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 /
+	rm -f $tmp.*
+}
+
+. ./common/rc
+. ./common/filter
+
+rm -f $seqres.full
+
+_supported_fs generic
+_supported_os Linux
+_require_scratch_swapfile
+_require_xfs_io_command "fpunch"
+
+echo "Format and mount"
+_scratch_mkfs > $seqres.full 2>&1
+_scratch_mount >> $seqres.full 2>&1
+
+testdir=$SCRATCH_MNT/test-$seq
+mkdir $testdir
+
+blocks=160
+blksz=65536
+
+echo "Initialize file"
+touch "$testdir/file1"
+chmod 0600 "$testdir/file1"
+chattr +C "$testdir/file1" >/dev/null 2>&1
+_pwrite_byte 0x61 0 $((blocks * blksz)) $testdir/file1 >> $seqres.full
+mkswap -U 27376b42-ff65-42ca-919f-6c9b62292a5c $testdir/file1 >> $seqres.full
+swapon $testdir/file1
+
+echo "Try to truncate"
+$XFS_IO_PROG -c "truncate $blksz" $testdir/file1
+
+echo "Try to punch hole"
+$XFS_IO_PROG -c "fpunch $blksz $((2 * blksz))" $testdir/file1
+
+echo "Tear it down"
+swapoff $testdir/file1
+
+status=0
+exit
tests/generic/489.out new file +8 -0
new file mode 100644
index 00000000..e2ebc530
@@ -0,0 +1,8 @@
+QA output created by 489
+Format and mount
+Initialize file
+Try to truncate
+ftruncate: Text file busy
+Try to punch hole
+fallocate: Text file busy
+Tear it down
tests/generic/group +1 -0
index 6266213e..daba9073 100644
@@ -491,3 +491,4 @@
 486 auto quick attr
 487 auto quick
 488 auto quick
+489 auto quick
Signature · 1 line
2.17.0
#5 lore raw

PATCH 4/4 generic: test invalid swap file activation

In reply to Omar Sandoval

From: Omar Sandoval <[email protected]>

Swap files cannot have holes, and they must be at least two pages. swapon(8) and mkswap(8) have stricter restrictions, so add versions of those commands without any restrictions.

---
 .gitignore            |  2 ++
 src/Makefile          |  2 +-
 src/mkswap.c          | 83 +++++++++++++++++++++++++++++++++++++++++++
 src/swapon.c          | 24 +++++++++++++
 tests/generic/490     | 75 ++++++++++++++++++++++++++++++++++++++
 tests/generic/490.out |  5 +++
 6 files changed, 190 insertions(+), 1 deletion(-)
 create mode 100644 src/mkswap.c
 create mode 100644 src/swapon.c
 create mode 100755 tests/generic/490
 create mode 100644 tests/generic/490.out
.gitignore +2 -0
index 53029e24..efc73a7c 100644
@@ -92,6 +92,7 @@
 /src/lstat64
 /src/makeextents
 /src/metaperf
+/src/mkswap
 /src/mmapcat
 /src/multi_open_unlink
 /src/nametest
@@ -111,6 +112,7 @@
 /src/seek_sanity_test
 /src/stale_handle
 /src/stat_test
+/src/swapon
 /src/t_access_root
 /src/t_dir_offset
 /src/t_dir_offset2
src/Makefile +1 -1
index c42d3bb1..01fe99ef 100644
@@ -26,7 +26,7 @@ LINUX_TARGETS = xfsctl bstat t_mtab getdevicesize preallo_rw_pattern_reader \
 	renameat2 t_getcwd e4compact test-nextquota punch-alternating \
 	attr-list-by-handle-cursor-test listxattr dio-interleaved t_dir_type \
 	dio-invalidate-cache stat_test t_encrypted_d_revalidate \
-	attr_replace_test
+	attr_replace_test swapon mkswap
 
 SUBDIRS = log-writes perf
 
src/mkswap.c new file +83 -0

83 lines not on this page · raw message

src/swapon.c new file +24 -0
new file mode 100644
index 00000000..0cb7108a
@@ -0,0 +1,24 @@
+/* swapon(8) without any sanity checks; simply calls swapon(2) directly. */
+
+#include <stdio.h>
+#include <stdlib.h>
+#include <unistd.h>
+#include <sys/swap.h>
+
+int main(int argc, char **argv)
+{
+	int ret;
+
+	if (argc != 2) {
+		fprintf(stderr, "usage: %s PATH\n", argv[0]);
+		return EXIT_FAILURE;
+	}
+
+	ret = swapon(argv[1], 0);
+	if (ret) {
+		perror("swapon");
+		return EXIT_FAILURE;
+	}
+
+	return EXIT_SUCCESS;
+}
tests/generic/490 new file +75 -0

75 lines not on this page · raw message

tests/generic/490.out new file +5 -0
new file mode 100644
index 00000000..96226c64
@@ -0,0 +1,5 @@
+QA output created by 490
+File with holes
+swapon: Invalid argument
+Empty swap file (only swap header)
+swapon: Invalid argument
Signature · 1 line
2.17.0