All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH 0/7] fstests: test Btrfs swapfile support
@ 2018-11-02 21:29 Omar Sandoval
  2018-11-02 21:29 ` [PATCH 1/7] generic/{472,496,497}: fix $seeqres typo Omar Sandoval
                   ` (7 more replies)
  0 siblings, 8 replies; 12+ messages in thread
From: Omar Sandoval @ 2018-11-02 21:29 UTC (permalink / raw)
  To: fstests; +Cc: kernel-team, linux-btrfs

From: Omar Sandoval <osandov@fb.com>

This series fixes a couple of generic swapfile tests and adds some
Btrfs-specific swapfile tests. Btrfs swapfile support is scheduled for
4.21 [1].

1: https://www.spinics.net/lists/linux-btrfs/msg83454.html

Thanks!

Omar Sandoval (7):
  generic/{472,496,497}: fix $seeqres typo
  generic/{472,496}: fix swap file creation on Btrfs
  btrfs: test swap file activation restrictions
  btrfs: test invalid operations on a swap file
  btrfs: test swap files on multiple devices
  btrfs: test device add/remove/replace with an active swap file
  btrfs: test balance and resize with an active swap file

 tests/btrfs/173     | 55 ++++++++++++++++++++++++++++++
 tests/btrfs/173.out |  5 +++
 tests/btrfs/174     | 66 ++++++++++++++++++++++++++++++++++++
 tests/btrfs/174.out | 10 ++++++
 tests/btrfs/175     | 73 ++++++++++++++++++++++++++++++++++++++++
 tests/btrfs/175.out |  8 +++++
 tests/btrfs/176     | 82 +++++++++++++++++++++++++++++++++++++++++++++
 tests/btrfs/176.out |  5 +++
 tests/btrfs/177     | 64 +++++++++++++++++++++++++++++++++++
 tests/btrfs/177.out |  6 ++++
 tests/btrfs/group   |  5 +++
 tests/generic/472   | 16 ++++-----
 tests/generic/496   |  8 ++---
 tests/generic/497   |  2 +-
 14 files changed, 391 insertions(+), 14 deletions(-)
 create mode 100755 tests/btrfs/173
 create mode 100644 tests/btrfs/173.out
 create mode 100755 tests/btrfs/174
 create mode 100644 tests/btrfs/174.out
 create mode 100755 tests/btrfs/175
 create mode 100644 tests/btrfs/175.out
 create mode 100755 tests/btrfs/176
 create mode 100644 tests/btrfs/176.out
 create mode 100755 tests/btrfs/177
 create mode 100644 tests/btrfs/177.out

-- 
2.19.1


^ permalink raw reply	[flat|nested] 12+ messages in thread

* [PATCH 1/7] generic/{472,496,497}: fix $seeqres typo
  2018-11-02 21:29 [PATCH 0/7] fstests: test Btrfs swapfile support Omar Sandoval
@ 2018-11-02 21:29 ` Omar Sandoval
  2018-11-02 21:29 ` [PATCH 2/7] generic/{472,496}: fix swap file creation on Btrfs Omar Sandoval
                   ` (6 subsequent siblings)
  7 siblings, 0 replies; 12+ messages in thread
From: Omar Sandoval @ 2018-11-02 21:29 UTC (permalink / raw)
  To: fstests; +Cc: kernel-team, linux-btrfs

From: Omar Sandoval <osandov@fb.com>

Signed-off-by: Omar Sandoval <osandov@fb.com>
---
 tests/generic/472 | 2 +-
 tests/generic/496 | 2 +-
 tests/generic/497 | 2 +-
 3 files changed, 3 insertions(+), 3 deletions(-)

diff --git a/tests/generic/472 b/tests/generic/472
index c74d6c70..04ed3e73 100755
--- a/tests/generic/472
+++ b/tests/generic/472
@@ -51,7 +51,7 @@ swapfile_cycle() {
 	$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
+	swapoff $swapfile 2>> $seqres.full
 	rm -f $swapfile
 }
 
diff --git a/tests/generic/496 b/tests/generic/496
index 1c9651ad..968b8012 100755
--- a/tests/generic/496
+++ b/tests/generic/496
@@ -53,7 +53,7 @@ swapfile_cycle() {
 	$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
+	swapoff $swapfile 2>> $seqres.full
 	rm -f $swapfile
 }
 
diff --git a/tests/generic/497 b/tests/generic/497
index 584af58a..3d5502ef 100755
--- a/tests/generic/497
+++ b/tests/generic/497
@@ -53,7 +53,7 @@ swapfile_cycle() {
 	$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
+	swapoff $swapfile 2>> $seqres.full
 	rm -f $swapfile
 }
 
-- 
2.19.1


^ permalink raw reply related	[flat|nested] 12+ messages in thread

* [PATCH 2/7] generic/{472,496}: fix swap file creation on Btrfs
  2018-11-02 21:29 [PATCH 0/7] fstests: test Btrfs swapfile support Omar Sandoval
  2018-11-02 21:29 ` [PATCH 1/7] generic/{472,496,497}: fix $seeqres typo Omar Sandoval
@ 2018-11-02 21:29 ` Omar Sandoval
  2018-11-02 21:29 ` [PATCH 3/7] btrfs: test swap file activation restrictions Omar Sandoval
                   ` (5 subsequent siblings)
  7 siblings, 0 replies; 12+ messages in thread
From: Omar Sandoval @ 2018-11-02 21:29 UTC (permalink / raw)
  To: fstests; +Cc: kernel-team, linux-btrfs

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(-)

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"
-- 
2.19.1


^ permalink raw reply related	[flat|nested] 12+ messages in thread

* [PATCH 3/7] btrfs: test swap file activation restrictions
  2018-11-02 21:29 [PATCH 0/7] fstests: test Btrfs swapfile support Omar Sandoval
  2018-11-02 21:29 ` [PATCH 1/7] generic/{472,496,497}: fix $seeqres typo Omar Sandoval
  2018-11-02 21:29 ` [PATCH 2/7] generic/{472,496}: fix swap file creation on Btrfs Omar Sandoval
@ 2018-11-02 21:29 ` Omar Sandoval
  2018-11-02 21:29 ` [PATCH 4/7] btrfs: test invalid operations on a swap file Omar Sandoval
                   ` (4 subsequent siblings)
  7 siblings, 0 replies; 12+ messages in thread
From: Omar Sandoval @ 2018-11-02 21:29 UTC (permalink / raw)
  To: fstests; +Cc: kernel-team, linux-btrfs

From: Omar Sandoval <osandov@fb.com>

Swap files on Btrfs have some restrictions not applicable to other
filesystems.

Signed-off-by: Omar Sandoval <osandov@fb.com>
---
 tests/btrfs/173     | 55 +++++++++++++++++++++++++++++++++++++++++++++
 tests/btrfs/173.out |  5 +++++
 tests/btrfs/group   |  1 +
 3 files changed, 61 insertions(+)
 create mode 100755 tests/btrfs/173
 create mode 100644 tests/btrfs/173.out

diff --git a/tests/btrfs/173 b/tests/btrfs/173
new file mode 100755
index 00000000..665bec39
--- /dev/null
+++ b/tests/btrfs/173
@@ -0,0 +1,55 @@
+#! /bin/bash
+# SPDX-License-Identifier: GPL-2.0
+# Copyright (c) 2018 Facebook.  All Rights Reserved.
+#
+# FS QA Test 173
+#
+# Test swap file activation restrictions specific to Btrfs.
+#
+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
+
+_scratch_mkfs >> $seqres.full 2>&1
+_scratch_mount
+
+echo "COW file"
+# We can't use _format_swapfile because we don't want chattr +C, and we can't
+# unset it after the swap file has been created.
+rm -f "$SCRATCH_MNT/swap"
+touch "$SCRATCH_MNT/swap"
+chmod 0600 "$SCRATCH_MNT/swap"
+_pwrite_byte 0x61 0 $(($(get_page_size) * 10)) "$SCRATCH_MNT/swap" >> $seqres.full
+mkswap "$SCRATCH_MNT/swap" >> $seqres.full
+swapon "$SCRATCH_MNT/swap" 2>&1 | _filter_scratch
+swapoff "$SCRATCH_MNT/swap" >/dev/null 2>&1
+
+echo "Compressed file"
+rm -f "$SCRATCH_MNT/swap"
+_format_swapfile "$SCRATCH_MNT/swap" $(($(get_page_size) * 10))
+$CHATTR_PROG +c "$SCRATCH_MNT/swap"
+swapon "$SCRATCH_MNT/swap" 2>&1 | _filter_scratch
+swapoff "$SCRATCH_MNT/swap" >/dev/null 2>&1
+
+status=0
+exit
diff --git a/tests/btrfs/173.out b/tests/btrfs/173.out
new file mode 100644
index 00000000..6d7856bf
--- /dev/null
+++ b/tests/btrfs/173.out
@@ -0,0 +1,5 @@
+QA output created by 173
+COW file
+swapon: SCRATCH_MNT/swap: swapon failed: Invalid argument
+Compressed file
+swapon: SCRATCH_MNT/swap: swapon failed: Invalid argument
diff --git a/tests/btrfs/group b/tests/btrfs/group
index a490d7eb..3525014f 100644
--- a/tests/btrfs/group
+++ b/tests/btrfs/group
@@ -175,3 +175,4 @@
 170 auto quick snapshot
 171 auto quick qgroup
 172 auto quick punch
+173 auto quick swap
-- 
2.19.1


^ permalink raw reply related	[flat|nested] 12+ messages in thread

* [PATCH 4/7] btrfs: test invalid operations on a swap file
  2018-11-02 21:29 [PATCH 0/7] fstests: test Btrfs swapfile support Omar Sandoval
                   ` (2 preceding siblings ...)
  2018-11-02 21:29 ` [PATCH 3/7] btrfs: test swap file activation restrictions Omar Sandoval
@ 2018-11-02 21:29 ` Omar Sandoval
  2018-11-02 21:29 ` [PATCH 5/7] btrfs: test swap files on multiple devices Omar Sandoval
                   ` (3 subsequent siblings)
  7 siblings, 0 replies; 12+ messages in thread
From: Omar Sandoval @ 2018-11-02 21:29 UTC (permalink / raw)
  To: fstests; +Cc: kernel-team, linux-btrfs

From: Omar Sandoval <osandov@fb.com>

Btrfs forbids some operations which should not be done on a swap file.

Signed-off-by: Omar Sandoval <osandov@fb.com>
---
 tests/btrfs/174     | 66 +++++++++++++++++++++++++++++++++++++++++++++
 tests/btrfs/174.out | 10 +++++++
 tests/btrfs/group   |  1 +
 3 files changed, 77 insertions(+)
 create mode 100755 tests/btrfs/174
 create mode 100644 tests/btrfs/174.out

diff --git a/tests/btrfs/174 b/tests/btrfs/174
new file mode 100755
index 00000000..a26e6669
--- /dev/null
+++ b/tests/btrfs/174
@@ -0,0 +1,66 @@
+#! /bin/bash
+# SPDX-License-Identifier: GPL-2.0
+# Copyright (c) 2018 Facebook.  All Rights Reserved.
+#
+# FS QA Test 174
+#
+# Test restrictions on operations that can be done on an active swap file
+# specific to Btrfs.
+#
+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
+
+_scratch_mkfs >> $seqres.full 2>&1
+_scratch_mount
+
+$BTRFS_UTIL_PROG subvol create "$SCRATCH_MNT/swapvol" >> $seqres.full
+swapfile="$SCRATCH_MNT/swapvol/swap"
+_format_swapfile "$swapfile" $(($(get_page_size) * 10))
+swapon "$swapfile"
+
+# Turning off nowcow doesn't do anything because the file is not empty, not
+# because the file is a swap file, but make sure this works anyways.
+echo "Disable nocow"
+$CHATTR_PROG -C "$swapfile"
+lsattr -l "$swapfile" | _filter_scratch | _filter_spaces
+
+# Compression we reject outright.
+echo "Enable compression"
+$CHATTR_PROG +c "$swapfile" 2>&1 | grep -o "Text file busy"
+lsattr -l "$swapfile" | _filter_scratch | _filter_spaces
+
+echo "Snapshot"
+$BTRFS_UTIL_PROG subvol snap "$SCRATCH_MNT/swapvol" \
+	"$SCRATCH_MNT/swapsnap" 2>&1 | grep -o "Text file busy"
+
+echo "Defrag"
+# We pass the -c (compress) flag to force defrag even if the file isn't
+# fragmented.
+$BTRFS_UTIL_PROG filesystem defrag -c "$swapfile" 2>&1 | grep -o "Text file busy"
+
+swapoff "$swapfile"
+_scratch_unmount
+
+status=0
+exit
diff --git a/tests/btrfs/174.out b/tests/btrfs/174.out
new file mode 100644
index 00000000..bc24f1fb
--- /dev/null
+++ b/tests/btrfs/174.out
@@ -0,0 +1,10 @@
+QA output created by 174
+Disable nocow
+SCRATCH_MNT/swapvol/swap No_COW
+Enable compression
+Text file busy
+SCRATCH_MNT/swapvol/swap No_COW
+Snapshot
+Text file busy
+Defrag
+Text file busy
diff --git a/tests/btrfs/group b/tests/btrfs/group
index 3525014f..2e10f7df 100644
--- a/tests/btrfs/group
+++ b/tests/btrfs/group
@@ -176,3 +176,4 @@
 171 auto quick qgroup
 172 auto quick punch
 173 auto quick swap
+174 auto quick swap
-- 
2.19.1


^ permalink raw reply related	[flat|nested] 12+ messages in thread

* [PATCH 5/7] btrfs: test swap files on multiple devices
  2018-11-02 21:29 [PATCH 0/7] fstests: test Btrfs swapfile support Omar Sandoval
                   ` (3 preceding siblings ...)
  2018-11-02 21:29 ` [PATCH 4/7] btrfs: test invalid operations on a swap file Omar Sandoval
@ 2018-11-02 21:29 ` Omar Sandoval
  2018-11-02 21:29 ` [PATCH 6/7] btrfs: test device add/remove/replace with an active swap file Omar Sandoval
                   ` (2 subsequent siblings)
  7 siblings, 0 replies; 12+ messages in thread
From: Omar Sandoval @ 2018-11-02 21:29 UTC (permalink / raw)
  To: fstests; +Cc: kernel-team, linux-btrfs

From: Omar Sandoval <osandov@fb.com>

Swap files currently need to exist on exactly one device in exactly one
place.

Signed-off-by: Omar Sandoval <osandov@fb.com>
---
 tests/btrfs/175     | 73 +++++++++++++++++++++++++++++++++++++++++++++
 tests/btrfs/175.out |  8 +++++
 tests/btrfs/group   |  1 +
 3 files changed, 82 insertions(+)
 create mode 100755 tests/btrfs/175
 create mode 100644 tests/btrfs/175.out

diff --git a/tests/btrfs/175 b/tests/btrfs/175
new file mode 100755
index 00000000..64afc4f0
--- /dev/null
+++ b/tests/btrfs/175
@@ -0,0 +1,73 @@
+#! /bin/bash
+# SPDX-License-Identifier: GPL-2.0
+# Copyright (c) 2018 Facebook.  All Rights Reserved.
+#
+# FS QA Test 175
+#
+# Test swap file activation on multiple devices.
+#
+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_dev_pool 2
+_require_scratch_swapfile
+
+cycle_swapfile() {
+	local sz=${1:-$(($(get_page_size) * 10))}
+	_format_swapfile "$SCRATCH_MNT/swap" "$sz"
+	swapon "$SCRATCH_MNT/swap" 2>&1 | _filter_scratch
+	swapoff "$SCRATCH_MNT/swap" > /dev/null 2>&1
+}
+
+echo "RAID 1"
+_scratch_pool_mkfs -d raid1 -m raid1 >> $seqres.full 2>&1
+_scratch_mount
+cycle_swapfile
+_scratch_unmount
+
+echo "DUP"
+_scratch_pool_mkfs -d dup -m dup >> $seqres.full 2>&1
+_scratch_mount
+cycle_swapfile
+_scratch_unmount
+
+echo "Single on multiple devices"
+_scratch_pool_mkfs -d single -m raid1 -b $((1024 * 1024 * 1024)) >> $seqres.full 2>&1
+_scratch_mount
+# Each device is only 1 GB, so 1.5 GB must be split across multiple devices.
+cycle_swapfile $((3 * 1024 * 1024 * 1024 / 2))
+_scratch_unmount
+
+echo "Single on one device"
+_scratch_mkfs >> $seqres.full 2>&1
+_scratch_mount
+# Create the swap file, then add the device. That way we know it's all on one
+# device.
+_format_swapfile "$SCRATCH_MNT/swap" $(($(get_page_size) * 10))
+scratch_dev2="$(echo "${SCRATCH_DEV_POOL}" | awk '{ print $2 }')"
+$BTRFS_UTIL_PROG device add -f "$scratch_dev2" "$SCRATCH_MNT"
+swapon "$SCRATCH_MNT/swap" 2>&1 | _filter_scratch
+swapoff "$SCRATCH_MNT/swap" > /dev/null 2>&1
+_scratch_unmount
+
+status=0
+exit
diff --git a/tests/btrfs/175.out b/tests/btrfs/175.out
new file mode 100644
index 00000000..ce2e5992
--- /dev/null
+++ b/tests/btrfs/175.out
@@ -0,0 +1,8 @@
+QA output created by 175
+RAID 1
+swapon: SCRATCH_MNT/swap: swapon failed: Invalid argument
+DUP
+swapon: SCRATCH_MNT/swap: swapon failed: Invalid argument
+Single on multiple devices
+swapon: SCRATCH_MNT/swap: swapon failed: Invalid argument
+Single on one device
diff --git a/tests/btrfs/group b/tests/btrfs/group
index 2e10f7df..b6160b72 100644
--- a/tests/btrfs/group
+++ b/tests/btrfs/group
@@ -177,3 +177,4 @@
 172 auto quick punch
 173 auto quick swap
 174 auto quick swap
+175 auto quick swap
-- 
2.19.1


^ permalink raw reply related	[flat|nested] 12+ messages in thread

* [PATCH 6/7] btrfs: test device add/remove/replace with an active swap file
  2018-11-02 21:29 [PATCH 0/7] fstests: test Btrfs swapfile support Omar Sandoval
                   ` (4 preceding siblings ...)
  2018-11-02 21:29 ` [PATCH 5/7] btrfs: test swap files on multiple devices Omar Sandoval
@ 2018-11-02 21:29 ` Omar Sandoval
  2018-11-02 21:29 ` [PATCH 7/7] btrfs: test balance and resize " Omar Sandoval
  2018-11-04 16:09 ` [PATCH 0/7] fstests: test Btrfs swapfile support Eryu Guan
  7 siblings, 0 replies; 12+ messages in thread
From: Omar Sandoval @ 2018-11-02 21:29 UTC (permalink / raw)
  To: fstests; +Cc: kernel-team, linux-btrfs

From: Omar Sandoval <osandov@fb.com>

Make sure that we don't remove or replace a device with an active swap
file but can add, remove, and replace other devices.

Signed-off-by: Omar Sandoval <osandov@fb.com>
---
 tests/btrfs/176     | 82 +++++++++++++++++++++++++++++++++++++++++++++
 tests/btrfs/176.out |  5 +++
 tests/btrfs/group   |  1 +
 3 files changed, 88 insertions(+)
 create mode 100755 tests/btrfs/176
 create mode 100644 tests/btrfs/176.out

diff --git a/tests/btrfs/176 b/tests/btrfs/176
new file mode 100755
index 00000000..1e576149
--- /dev/null
+++ b/tests/btrfs/176
@@ -0,0 +1,82 @@
+#! /bin/bash
+# SPDX-License-Identifier: GPL-2.0
+# Copyright (c) 2018 Facebook.  All Rights Reserved.
+#
+# FS QA Test 176
+#
+# Test device remove/replace with an active swap file.
+#
+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.*
+}
+
+# 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
+
+# Modify as appropriate.
+_supported_fs generic
+_supported_os Linux
+_require_scratch_dev_pool 3
+_require_scratch_swapfile
+
+# We check the filesystem manually because we move devices around.
+rm -f "${RESULT_DIR}/require_scratch"
+
+scratch_dev1="$(echo "${SCRATCH_DEV_POOL}" | awk '{ print $1 }')"
+scratch_dev2="$(echo "${SCRATCH_DEV_POOL}" | awk '{ print $2 }')"
+scratch_dev3="$(echo "${SCRATCH_DEV_POOL}" | awk '{ print $3 }')"
+
+echo "Remove device"
+_scratch_mkfs >> $seqres.full 2>&1
+_scratch_mount
+_format_swapfile "$SCRATCH_MNT/swap" $(($(get_page_size) * 10))
+$BTRFS_UTIL_PROG device add -f "$scratch_dev2" "$SCRATCH_MNT"
+swapon "$SCRATCH_MNT/swap" 2>&1 | _filter_scratch
+# We know the swap file is on device 1 because we added device 2 after it was
+# already created.
+$BTRFS_UTIL_PROG device delete "$scratch_dev1" "$SCRATCH_MNT" 2>&1 | grep -o "Text file busy"
+# Deleting/readding device 2 should still work.
+$BTRFS_UTIL_PROG device delete "$scratch_dev2" "$SCRATCH_MNT"
+$BTRFS_UTIL_PROG device add -f "$scratch_dev2" "$SCRATCH_MNT"
+swapoff "$SCRATCH_MNT/swap" > /dev/null 2>&1
+# Deleting device 1 should work again after swapoff.
+$BTRFS_UTIL_PROG device delete "$scratch_dev1" "$SCRATCH_MNT"
+_scratch_unmount
+_check_scratch_fs "$scratch_dev2"
+
+echo "Replace device"
+_scratch_mkfs >> $seqres.full 2>&1
+_scratch_mount
+_format_swapfile "$SCRATCH_MNT/swap" $(($(get_page_size) * 10))
+$BTRFS_UTIL_PROG device add -f "$scratch_dev2" "$SCRATCH_MNT"
+swapon "$SCRATCH_MNT/swap" 2>&1 | _filter_scratch
+# Again, we know the swap file is on device 1.
+$BTRFS_UTIL_PROG replace start -fB "$scratch_dev1" "$scratch_dev3" "$SCRATCH_MNT" 2>&1 | grep -o "Text file busy"
+# Replacing device 2 should still work.
+$BTRFS_UTIL_PROG replace start -fB "$scratch_dev2" "$scratch_dev3" "$SCRATCH_MNT"
+swapoff "$SCRATCH_MNT/swap" > /dev/null 2>&1
+# Replacing device 1 should work again after swapoff.
+$BTRFS_UTIL_PROG replace start -fB "$scratch_dev1" "$scratch_dev2" "$SCRATCH_MNT"
+_scratch_unmount
+_check_scratch_fs "$scratch_dev2"
+
+# success, all done
+status=0
+exit
diff --git a/tests/btrfs/176.out b/tests/btrfs/176.out
new file mode 100644
index 00000000..5c99e0fd
--- /dev/null
+++ b/tests/btrfs/176.out
@@ -0,0 +1,5 @@
+QA output created by 176
+Remove device
+Text file busy
+Replace device
+Text file busy
diff --git a/tests/btrfs/group b/tests/btrfs/group
index b6160b72..3562420b 100644
--- a/tests/btrfs/group
+++ b/tests/btrfs/group
@@ -178,3 +178,4 @@
 173 auto quick swap
 174 auto quick swap
 175 auto quick swap
+176 auto quick swap
-- 
2.19.1


^ permalink raw reply related	[flat|nested] 12+ messages in thread

* [PATCH 7/7] btrfs: test balance and resize with an active swap file
  2018-11-02 21:29 [PATCH 0/7] fstests: test Btrfs swapfile support Omar Sandoval
                   ` (5 preceding siblings ...)
  2018-11-02 21:29 ` [PATCH 6/7] btrfs: test device add/remove/replace with an active swap file Omar Sandoval
@ 2018-11-02 21:29 ` Omar Sandoval
  2018-11-06 13:44   ` David Sterba
  2018-11-04 16:09 ` [PATCH 0/7] fstests: test Btrfs swapfile support Eryu Guan
  7 siblings, 1 reply; 12+ messages in thread
From: Omar Sandoval @ 2018-11-02 21:29 UTC (permalink / raw)
  To: fstests; +Cc: kernel-team, linux-btrfs

From: Omar Sandoval <osandov@fb.com>

Make sure we don't shrink the device past an active swap file, but allow
shrinking otherwise, as well as growing and balance.

Signed-off-by: Omar Sandoval <osandov@fb.com>
---
 tests/btrfs/177     | 64 +++++++++++++++++++++++++++++++++++++++++++++
 tests/btrfs/177.out |  6 +++++
 tests/btrfs/group   |  1 +
 3 files changed, 71 insertions(+)
 create mode 100755 tests/btrfs/177
 create mode 100644 tests/btrfs/177.out

diff --git a/tests/btrfs/177 b/tests/btrfs/177
new file mode 100755
index 00000000..12dad8fc
--- /dev/null
+++ b/tests/btrfs/177
@@ -0,0 +1,64 @@
+#! /bin/bash
+# SPDX-License-Identifier: GPL-2.0
+# Copyright (c) 2018 Facebook.  All Rights Reserved.
+#
+# FS QA Test 177
+#
+# Test relocation (balance and resize) with an active swap file.
+#
+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/btrfs
+
+rm -f $seqres.full
+
+# Modify as appropriate.
+_supported_fs generic
+_supported_os Linux
+_require_scratch_swapfile
+
+swapfile="$SCRATCH_MNT/swap"
+
+# First, create a 1GB filesystem and fill it up.
+_scratch_mkfs_sized $((1024 * 1024 * 1024)) >> $seqres.full 2>&1
+_scratch_mount
+dd if=/dev/zero of="$SCRATCH_MNT/fill" bs=1024k >> $seqres.full 2>&1
+# Now add more space and create a swap file. We know that the first 1GB of the
+# filesystem was used, so the swap file must be in the new part of the
+# filesystem.
+$BTRFS_UTIL_PROG filesystem resize 2G "$SCRATCH_MNT" | _filter_scratch
+_format_swapfile "$swapfile" $((32 * 1024 * 1024))
+swapon "$swapfile"
+# Add even more space which we know is unused.
+$BTRFS_UTIL_PROG filesystem resize 3G "$SCRATCH_MNT" | _filter_scratch
+# Free up the first 1GB of the filesystem.
+rm -f "$SCRATCH_MNT/fill"
+# Get rid of empty block groups and also make sure that balance skips block
+# groups containing active swap files.
+_run_btrfs_balance_start "$SCRATCH_MNT"
+# Shrink away the unused space.
+$BTRFS_UTIL_PROG filesystem resize 2G "$SCRATCH_MNT" | _filter_scratch
+# Try to shrink away the area occupied by the swap file, which should fail.
+$BTRFS_UTIL_PROG filesystem resize 1G "$SCRATCH_MNT" 2>&1 | grep -o "Text file busy"
+swapoff "$swapfile"
+# It should work again after swapoff.
+$BTRFS_UTIL_PROG filesystem resize 1G "$SCRATCH_MNT" | _filter_scratch
+_scratch_unmount
+
+status=0
+exit
diff --git a/tests/btrfs/177.out b/tests/btrfs/177.out
new file mode 100644
index 00000000..6ced01da
--- /dev/null
+++ b/tests/btrfs/177.out
@@ -0,0 +1,6 @@
+QA output created by 177
+Resize 'SCRATCH_MNT' of '2G'
+Resize 'SCRATCH_MNT' of '3G'
+Resize 'SCRATCH_MNT' of '2G'
+Text file busy
+Resize 'SCRATCH_MNT' of '1G'
diff --git a/tests/btrfs/group b/tests/btrfs/group
index 3562420b..0b62e58a 100644
--- a/tests/btrfs/group
+++ b/tests/btrfs/group
@@ -179,3 +179,4 @@
 174 auto quick swap
 175 auto quick swap
 176 auto quick swap
+177 auto quick swap
-- 
2.19.1


^ permalink raw reply related	[flat|nested] 12+ messages in thread

* Re: [PATCH 0/7] fstests: test Btrfs swapfile support
  2018-11-02 21:29 [PATCH 0/7] fstests: test Btrfs swapfile support Omar Sandoval
                   ` (6 preceding siblings ...)
  2018-11-02 21:29 ` [PATCH 7/7] btrfs: test balance and resize " Omar Sandoval
@ 2018-11-04 16:09 ` Eryu Guan
  2018-11-06 13:06   ` David Sterba
  7 siblings, 1 reply; 12+ messages in thread
From: Eryu Guan @ 2018-11-04 16:09 UTC (permalink / raw)
  To: Omar Sandoval; +Cc: fstests, kernel-team, linux-btrfs

On Fri, Nov 02, 2018 at 02:29:35PM -0700, Omar Sandoval wrote:
> From: Omar Sandoval <osandov@fb.com>
> 
> This series fixes a couple of generic swapfile tests and adds some
> Btrfs-specific swapfile tests. Btrfs swapfile support is scheduled for
> 4.21 [1].
> 
> 1: https://www.spinics.net/lists/linux-btrfs/msg83454.html
> 
> Thanks!

Thanks for the fixes and new tests!

> 
> Omar Sandoval (7):
>   generic/{472,496,497}: fix $seeqres typo
>   generic/{472,496}: fix swap file creation on Btrfs

I've merged above two patches, they're two obvious bug fixes.

>   btrfs: test swap file activation restrictions
>   btrfs: test invalid operations on a swap file
>   btrfs: test swap files on multiple devices
>   btrfs: test device add/remove/replace with an active swap file
>   btrfs: test balance and resize with an active swap file

These tests look fine to me, but it'd be really great if btrfs folks
could help review above tests and provide Reviewed-by tags.

And perhaps we could add test 17[56] to 'volume' group, as they do
device operations. And similarly, add the last test to 'balance' group.

Thanks,
Eryu

> 
>  tests/btrfs/173     | 55 ++++++++++++++++++++++++++++++
>  tests/btrfs/173.out |  5 +++
>  tests/btrfs/174     | 66 ++++++++++++++++++++++++++++++++++++
>  tests/btrfs/174.out | 10 ++++++
>  tests/btrfs/175     | 73 ++++++++++++++++++++++++++++++++++++++++
>  tests/btrfs/175.out |  8 +++++
>  tests/btrfs/176     | 82 +++++++++++++++++++++++++++++++++++++++++++++
>  tests/btrfs/176.out |  5 +++
>  tests/btrfs/177     | 64 +++++++++++++++++++++++++++++++++++
>  tests/btrfs/177.out |  6 ++++
>  tests/btrfs/group   |  5 +++
>  tests/generic/472   | 16 ++++-----
>  tests/generic/496   |  8 ++---
>  tests/generic/497   |  2 +-
>  14 files changed, 391 insertions(+), 14 deletions(-)
>  create mode 100755 tests/btrfs/173
>  create mode 100644 tests/btrfs/173.out
>  create mode 100755 tests/btrfs/174
>  create mode 100644 tests/btrfs/174.out
>  create mode 100755 tests/btrfs/175
>  create mode 100644 tests/btrfs/175.out
>  create mode 100755 tests/btrfs/176
>  create mode 100644 tests/btrfs/176.out
>  create mode 100755 tests/btrfs/177
>  create mode 100644 tests/btrfs/177.out
> 
> -- 
> 2.19.1
> 

^ permalink raw reply	[flat|nested] 12+ messages in thread

* Re: [PATCH 0/7] fstests: test Btrfs swapfile support
  2018-11-04 16:09 ` [PATCH 0/7] fstests: test Btrfs swapfile support Eryu Guan
@ 2018-11-06 13:06   ` David Sterba
  2018-11-11 14:37     ` Eryu Guan
  0 siblings, 1 reply; 12+ messages in thread
From: David Sterba @ 2018-11-06 13:06 UTC (permalink / raw)
  To: Eryu Guan; +Cc: Omar Sandoval, fstests, kernel-team, linux-btrfs

On Mon, Nov 05, 2018 at 12:09:31AM +0800, Eryu Guan wrote:
> On Fri, Nov 02, 2018 at 02:29:35PM -0700, Omar Sandoval wrote:
> > From: Omar Sandoval <osandov@fb.com>
> > 
> > This series fixes a couple of generic swapfile tests and adds some
> > Btrfs-specific swapfile tests. Btrfs swapfile support is scheduled for
> > 4.21 [1].
> > 
> > 1: https://www.spinics.net/lists/linux-btrfs/msg83454.html
> > 
> > Thanks!
> 
> Thanks for the fixes and new tests!
> 
> > 
> > Omar Sandoval (7):
> >   generic/{472,496,497}: fix $seeqres typo
> >   generic/{472,496}: fix swap file creation on Btrfs
> 
> I've merged above two patches, they're two obvious bug fixes.
> 
> >   btrfs: test swap file activation restrictions
> >   btrfs: test invalid operations on a swap file
> >   btrfs: test swap files on multiple devices
> >   btrfs: test device add/remove/replace with an active swap file
> >   btrfs: test balance and resize with an active swap file
> 
> These tests look fine to me, but it'd be really great if btrfs folks
> could help review above tests and provide Reviewed-by tags.

All look good to me,

Reviewed-by: David Sterba <dsterba@suse.com>

A few nits I saw:

- the command names should not be shortened, ie. 'btrfs subvolume
  snapshot' instead of 'btrfs subvol snap'
- the test description (eg. 3/7 and 4/7) could mention which case is
  tested, eg. swapfile with compression or COW or snapshot
- 4/7 has typo 'nowcow' in a comment

^ permalink raw reply	[flat|nested] 12+ messages in thread

* Re: [PATCH 7/7] btrfs: test balance and resize with an active swap file
  2018-11-02 21:29 ` [PATCH 7/7] btrfs: test balance and resize " Omar Sandoval
@ 2018-11-06 13:44   ` David Sterba
  0 siblings, 0 replies; 12+ messages in thread
From: David Sterba @ 2018-11-06 13:44 UTC (permalink / raw)
  To: Omar Sandoval; +Cc: fstests, kernel-team, linux-btrfs

On Fri, Nov 02, 2018 at 02:29:42PM -0700, Omar Sandoval wrote:
> From: Omar Sandoval <osandov@fb.com>
> 
> Make sure we don't shrink the device past an active swap file, but allow
> shrinking otherwise, as well as growing and balance.
> 
> Signed-off-by: Omar Sandoval <osandov@fb.com>
> ---
>  tests/btrfs/177     | 64 +++++++++++++++++++++++++++++++++++++++++++++
>  tests/btrfs/177.out |  6 +++++
>  tests/btrfs/group   |  1 +
>  3 files changed, 71 insertions(+)
>  create mode 100755 tests/btrfs/177
>  create mode 100644 tests/btrfs/177.out
> 
> diff --git a/tests/btrfs/177 b/tests/btrfs/177
> new file mode 100755
> index 00000000..12dad8fc
> --- /dev/null
> +++ b/tests/btrfs/177
> @@ -0,0 +1,64 @@
> +#! /bin/bash
> +# SPDX-License-Identifier: GPL-2.0
> +# Copyright (c) 2018 Facebook.  All Rights Reserved.
> +#
> +# FS QA Test 177
> +#
> +# Test relocation (balance and resize) with an active swap file.
> +#
> +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/btrfs
> +
> +rm -f $seqres.full
> +
> +# Modify as appropriate.
> +_supported_fs generic
> +_supported_os Linux
> +_require_scratch_swapfile
> +
> +swapfile="$SCRATCH_MNT/swap"
> +
> +# First, create a 1GB filesystem and fill it up.
> +_scratch_mkfs_sized $((1024 * 1024 * 1024)) >> $seqres.full 2>&1
> +_scratch_mount
> +dd if=/dev/zero of="$SCRATCH_MNT/fill" bs=1024k >> $seqres.full 2>&1

Can this be replaced by fallocate? Though it's just a 1GiB of data, it
still takes some seconds on rotational storage.

^ permalink raw reply	[flat|nested] 12+ messages in thread

* Re: [PATCH 0/7] fstests: test Btrfs swapfile support
  2018-11-06 13:06   ` David Sterba
@ 2018-11-11 14:37     ` Eryu Guan
  0 siblings, 0 replies; 12+ messages in thread
From: Eryu Guan @ 2018-11-11 14:37 UTC (permalink / raw)
  To: dsterba; +Cc: Omar Sandoval, fstests, kernel-team, linux-btrfs

On Tue, Nov 06, 2018 at 02:06:30PM +0100, David Sterba wrote:
> On Mon, Nov 05, 2018 at 12:09:31AM +0800, Eryu Guan wrote:
> > On Fri, Nov 02, 2018 at 02:29:35PM -0700, Omar Sandoval wrote:
> > > From: Omar Sandoval <osandov@fb.com>
> > > 
> > > This series fixes a couple of generic swapfile tests and adds some
> > > Btrfs-specific swapfile tests. Btrfs swapfile support is scheduled for
> > > 4.21 [1].
> > > 
> > > 1: https://www.spinics.net/lists/linux-btrfs/msg83454.html
> > > 
> > > Thanks!
> > 
> > Thanks for the fixes and new tests!
> > 
> > > 
> > > Omar Sandoval (7):
> > >   generic/{472,496,497}: fix $seeqres typo
> > >   generic/{472,496}: fix swap file creation on Btrfs
> > 
> > I've merged above two patches, they're two obvious bug fixes.
> > 
> > >   btrfs: test swap file activation restrictions
> > >   btrfs: test invalid operations on a swap file
> > >   btrfs: test swap files on multiple devices
> > >   btrfs: test device add/remove/replace with an active swap file
> > >   btrfs: test balance and resize with an active swap file
> > 
> > These tests look fine to me, but it'd be really great if btrfs folks
> > could help review above tests and provide Reviewed-by tags.
> 
> All look good to me,
> 
> Reviewed-by: David Sterba <dsterba@suse.com>

Thanks a lot for the review!

> 
> A few nits I saw:
> 
> - the command names should not be shortened, ie. 'btrfs subvolume
>   snapshot' instead of 'btrfs subvol snap'
> - the test description (eg. 3/7 and 4/7) could mention which case is
>   tested, eg. swapfile with compression or COW or snapshot
> - 4/7 has typo 'nowcow' in a comment

I've addressed these nits on commit.

Thanks,
Eryu

^ permalink raw reply	[flat|nested] 12+ messages in thread

end of thread, other threads:[~2018-11-11 14:38 UTC | newest]

Thread overview: 12+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2018-11-02 21:29 [PATCH 0/7] fstests: test Btrfs swapfile support Omar Sandoval
2018-11-02 21:29 ` [PATCH 1/7] generic/{472,496,497}: fix $seeqres typo Omar Sandoval
2018-11-02 21:29 ` [PATCH 2/7] generic/{472,496}: fix swap file creation on Btrfs Omar Sandoval
2018-11-02 21:29 ` [PATCH 3/7] btrfs: test swap file activation restrictions Omar Sandoval
2018-11-02 21:29 ` [PATCH 4/7] btrfs: test invalid operations on a swap file Omar Sandoval
2018-11-02 21:29 ` [PATCH 5/7] btrfs: test swap files on multiple devices Omar Sandoval
2018-11-02 21:29 ` [PATCH 6/7] btrfs: test device add/remove/replace with an active swap file Omar Sandoval
2018-11-02 21:29 ` [PATCH 7/7] btrfs: test balance and resize " Omar Sandoval
2018-11-06 13:44   ` David Sterba
2018-11-04 16:09 ` [PATCH 0/7] fstests: test Btrfs swapfile support Eryu Guan
2018-11-06 13:06   ` David Sterba
2018-11-11 14:37     ` Eryu Guan

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.