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 seqres=$RESULT_DIR/$seq
11 echo "QA output created by $seq"
15 status=1 # failure is the default!
16 trap "_cleanup; exit \$status" 0 1 2 3 15
24 # get standard environment, filters and checks
28 # remove previous $seqres.full before test
31 # real QA test starts here
33 # Modify as appropriate.
35 _require_scratch_dev_pool 3
36 _require_scratch_swapfile
38 # We check the filesystem manually because we move devices around.
39 rm -f "${RESULT_DIR}/require_scratch"
41 scratch_dev1="$(echo "${SCRATCH_DEV_POOL}" | awk '{ print $1 }')"
42 scratch_dev2="$(echo "${SCRATCH_DEV_POOL}" | awk '{ print $2 }')"
43 scratch_dev3="$(echo "${SCRATCH_DEV_POOL}" | awk '{ print $3 }')"
46 _scratch_mkfs >> $seqres.full 2>&1
48 _format_swapfile "$SCRATCH_MNT/swap" $(($(get_page_size) * 10))
49 $BTRFS_UTIL_PROG device add -f "$scratch_dev2" "$SCRATCH_MNT"
50 swapon "$SCRATCH_MNT/swap" 2>&1 | _filter_scratch
51 # We know the swap file is on device 1 because we added device 2 after it was
53 $BTRFS_UTIL_PROG device delete "$scratch_dev1" "$SCRATCH_MNT" 2>&1 | grep -o "Text file busy"
54 # Deleting/readding device 2 should still work.
55 $BTRFS_UTIL_PROG device delete "$scratch_dev2" "$SCRATCH_MNT"
56 $BTRFS_UTIL_PROG device add -f "$scratch_dev2" "$SCRATCH_MNT"
57 swapoff "$SCRATCH_MNT/swap" > /dev/null 2>&1
58 # Deleting device 1 should work again after swapoff.
59 $BTRFS_UTIL_PROG device delete "$scratch_dev1" "$SCRATCH_MNT"
61 _check_scratch_fs "$scratch_dev2"
64 _scratch_mkfs >> $seqres.full 2>&1
66 _format_swapfile "$SCRATCH_MNT/swap" $(($(get_page_size) * 10))
67 $BTRFS_UTIL_PROG device add -f "$scratch_dev2" "$SCRATCH_MNT"
68 swapon "$SCRATCH_MNT/swap" 2>&1 | _filter_scratch
69 # Again, we know the swap file is on device 1.
70 $BTRFS_UTIL_PROG replace start -fB "$scratch_dev1" "$scratch_dev3" "$SCRATCH_MNT" 2>&1 | grep -o "Text file busy"
71 # Replacing device 2 should still work.
72 $BTRFS_UTIL_PROG replace start -fB "$scratch_dev2" "$scratch_dev3" "$SCRATCH_MNT"
73 swapoff "$SCRATCH_MNT/swap" > /dev/null 2>&1
74 # Replacing device 1 should work again after swapoff.
75 $BTRFS_UTIL_PROG replace start -fB "$scratch_dev1" "$scratch_dev2" "$SCRATCH_MNT"
77 _check_scratch_fs "$scratch_dev2"