aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorFilipe Manana <fdmanana@suse.com>2023-06-20 13:00:21 +0100
committerZorro Lang <zlang@kernel.org>2023-07-07 21:37:16 +0800
commitdb7fb78fda6960c853b12ae923a0e865a401edb8 (patch)
treee88201e2d3ad5ae2e303a288c00c96de845d06b8
parent06cee93225c9f9ea41d04efd6af911f7abb6e6a1 (diff)
downloadxfstests-dev-db7fb78fda6960c853b12ae923a0e865a401edb8.tar.gz
btrfs: test activating swapfile in the presence of snapshots
Test that if we have a subvolume with a non-active swap file, we can not activate it if there are any snapshots. Also test that after all the snapshots are removed, we will be able to activate the swapfile. Signed-off-by: Filipe Manana <fdmanana@suse.com> Reviewed-by: Josef Bacik <josef@toxicpanda.com> Signed-off-by: Zorro Lang <zlang@kernel.org>
-rwxr-xr-xtests/btrfs/29372
-rw-r--r--tests/btrfs/293.out17
2 files changed, 89 insertions, 0 deletions
diff --git a/tests/btrfs/293 b/tests/btrfs/293
new file mode 100755
index 0000000000..f51d40ddec
--- /dev/null
+++ b/tests/btrfs/293
@@ -0,0 +1,72 @@
+#! /bin/bash
+# SPDX-License-Identifier: GPL-2.0
+# Copyright (C) 2023 SUSE Linux Products GmbH. All Rights Reserved.
+#
+# FS QA Test No. 293
+#
+# Test that if we have a subvolume with a non-active swap file, we can not
+# activate it if there are any snapshots. Also test that after all the snapshots
+# are removed, we will be able to activate the swapfile.
+#
+. ./common/preamble
+_begin_fstest auto quick swap snapshot
+
+_cleanup()
+{
+ cd /
+ rm -f $tmp.*
+ test -n "$swap_file" && swapoff $swap_file &> /dev/null
+}
+
+. ./common/filter
+
+_supported_fs btrfs
+_fixed_by_kernel_commit deccae40e4b3 \
+ "btrfs: can_nocow_file_extent should pass down args->strict from callers"
+_require_scratch_swapfile
+
+_scratch_mkfs >> $seqres.full 2>&1
+_scratch_mount
+
+swap_file="$SCRATCH_MNT/swapfile"
+_format_swapfile $swap_file $(($(get_page_size) * 64)) >> $seqres.full
+
+echo "Creating first snapshot..."
+$BTRFS_UTIL_PROG subvolume snapshot -r $SCRATCH_MNT $SCRATCH_MNT/snap1 | _filter_scratch
+echo "Creating second snapshot..."
+$BTRFS_UTIL_PROG subvolume snapshot $SCRATCH_MNT $SCRATCH_MNT/snap2 | _filter_scratch
+
+echo "Activating swap file... (should fail due to snapshots)"
+_swapon_file $swap_file 2>&1 | _filter_scratch
+
+echo "Deleting first snapshot..."
+$BTRFS_UTIL_PROG subvolume delete -c $SCRATCH_MNT/snap1 | _filter_scratch
+
+# We deleted the snapshot and committed the transaction used to delete it (-c),
+# but all its extents are actually only deleted in the background, by the cleaner
+# kthread. So remount, which wakes up the cleaner kthread, with a commit interval
+# of 1 second and sleep for 1.1 seconds - after this we are guaranteed all
+# extents of the snapshot were deleted.
+echo "Remounting and waiting for cleaner thread to remove the first snapshot..."
+_scratch_remount commit=1
+sleep 1.2
+
+echo "Activating swap file... (should fail due to snapshot)"
+_swapon_file $swap_file 2>&1 | _filter_scratch
+
+echo "Deleting second snapshot..."
+$BTRFS_UTIL_PROG subvolume delete -c $SCRATCH_MNT/snap2 | _filter_scratch
+
+echo "Remounting and waiting for cleaner thread to remove the second snapshot..."
+_scratch_remount commit=1
+sleep 1.2
+
+# No more snapshots, we should be able to activate the swap file.
+echo "Activating swap file..."
+_swapon_file $swap_file
+echo "Disabling swap file..."
+swapoff $swap_file
+
+# success, all done
+status=0
+exit
diff --git a/tests/btrfs/293.out b/tests/btrfs/293.out
new file mode 100644
index 0000000000..2ac1663281
--- /dev/null
+++ b/tests/btrfs/293.out
@@ -0,0 +1,17 @@
+QA output created by 293
+Creating first snapshot...
+Create a readonly snapshot of 'SCRATCH_MNT' in 'SCRATCH_MNT/snap1'
+Creating second snapshot...
+Create a snapshot of 'SCRATCH_MNT' in 'SCRATCH_MNT/snap2'
+Activating swap file... (should fail due to snapshots)
+swapon: SCRATCH_MNT/swapfile: swapon failed: Invalid argument
+Deleting first snapshot...
+Delete subvolume (commit): 'SCRATCH_MNT/snap1'
+Remounting and waiting for cleaner thread to remove the first snapshot...
+Activating swap file... (should fail due to snapshot)
+swapon: SCRATCH_MNT/swapfile: swapon failed: Invalid argument
+Deleting second snapshot...
+Delete subvolume (commit): 'SCRATCH_MNT/snap2'
+Remounting and waiting for cleaner thread to remove the second snapshot...
+Activating swap file...
+Disabling swap file...