summaryrefslogtreecommitdiff
path: root/tests/btrfs/293
blob: 09139f195d127b2485465f994441118facb21953 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
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 remount

_cleanup()
{
	cd /
	rm -f $tmp.*
	test -n "$swap_file" && swapoff $swap_file &> /dev/null
}

. ./common/filter.btrfs

_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 subvolume snapshot -r $SCRATCH_MNT $SCRATCH_MNT/snap1
echo "Creating second snapshot..."
_btrfs subvolume snapshot $SCRATCH_MNT $SCRATCH_MNT/snap2

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_btrfs_subvol_delete

# 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_btrfs_subvol_delete

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