2 # SPDX-License-Identifier: GPL-2.0
3 # Copyright (c) 2018 Facebook. All Rights Reserved.
7 # Test device remove/replace with an active swap file.
10 _begin_fstest auto quick swap volume
12 # Import common functions.
15 # real QA test starts here
17 # Modify as appropriate.
19 _require_scratch_dev_pool 3
20 _require_scratch_swapfile
22 # We check the filesystem manually because we move devices around.
23 rm -f "${RESULT_DIR}/require_scratch"
25 scratch_dev1="$(echo "${SCRATCH_DEV_POOL}" | awk '{ print $1 }')"
26 scratch_dev2="$(echo "${SCRATCH_DEV_POOL}" | awk '{ print $2 }')"
27 scratch_dev3="$(echo "${SCRATCH_DEV_POOL}" | awk '{ print $3 }')"
30 _scratch_mkfs >> $seqres.full 2>&1
32 _format_swapfile "$SCRATCH_MNT/swap" $(($(get_page_size) * 10)) > /dev/null
33 $BTRFS_UTIL_PROG device add -f "$scratch_dev2" "$SCRATCH_MNT" >> $seqres.full
34 swapon "$SCRATCH_MNT/swap" 2>&1 | _filter_scratch
35 # We know the swap file is on device 1 because we added device 2 after it was
37 $BTRFS_UTIL_PROG device delete "$scratch_dev1" "$SCRATCH_MNT" 2>&1 | grep -o "Text file busy"
38 # Deleting/readding device 2 should still work.
39 $BTRFS_UTIL_PROG device delete "$scratch_dev2" "$SCRATCH_MNT"
40 $BTRFS_UTIL_PROG device add -f "$scratch_dev2" "$SCRATCH_MNT" >> $seqres.full
41 swapoff "$SCRATCH_MNT/swap" > /dev/null 2>&1
42 # Deleting device 1 should work again after swapoff.
43 $BTRFS_UTIL_PROG device delete "$scratch_dev1" "$SCRATCH_MNT"
45 _check_scratch_fs "$scratch_dev2"
48 _scratch_mkfs >> $seqres.full 2>&1
50 _format_swapfile "$SCRATCH_MNT/swap" $(($(get_page_size) * 10)) > /dev/null
51 $BTRFS_UTIL_PROG device add -f "$scratch_dev2" "$SCRATCH_MNT" >> $seqres.full
52 swapon "$SCRATCH_MNT/swap" 2>&1 | _filter_scratch
53 # Again, we know the swap file is on device 1.
54 $BTRFS_UTIL_PROG replace start -fB "$scratch_dev1" "$scratch_dev3" "$SCRATCH_MNT" 2>&1 | grep -o "Text file busy"
55 # Replacing device 2 should still work.
56 $BTRFS_UTIL_PROG replace start -fB "$scratch_dev2" "$scratch_dev3" "$SCRATCH_MNT" \
58 swapoff "$SCRATCH_MNT/swap" > /dev/null 2>&1
59 # Replacing device 1 should work again after swapoff.
60 $BTRFS_UTIL_PROG replace start -fB "$scratch_dev1" "$scratch_dev2" "$SCRATCH_MNT" \
63 _check_scratch_fs "$scratch_dev2"