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.
36 _require_scratch_dev_pool 3
37 _require_scratch_swapfile
39 # We check the filesystem manually because we move devices around.
40 rm -f "${RESULT_DIR}/require_scratch"
42 scratch_dev1="$(echo "${SCRATCH_DEV_POOL}" | awk '{ print $1 }')"
43 scratch_dev2="$(echo "${SCRATCH_DEV_POOL}" | awk '{ print $2 }')"
44 scratch_dev3="$(echo "${SCRATCH_DEV_POOL}" | awk '{ print $3 }')"
47 _scratch_mkfs >> $seqres.full 2>&1
49 _format_swapfile "$SCRATCH_MNT/swap" $(($(get_page_size) * 10))
50 $BTRFS_UTIL_PROG device add -f "$scratch_dev2" "$SCRATCH_MNT"
51 swapon "$SCRATCH_MNT/swap" 2>&1 | _filter_scratch
52 # We know the swap file is on device 1 because we added device 2 after it was
54 $BTRFS_UTIL_PROG device delete "$scratch_dev1" "$SCRATCH_MNT" 2>&1 | grep -o "Text file busy"
55 # Deleting/readding device 2 should still work.
56 $BTRFS_UTIL_PROG device delete "$scratch_dev2" "$SCRATCH_MNT"
57 $BTRFS_UTIL_PROG device add -f "$scratch_dev2" "$SCRATCH_MNT"
58 swapoff "$SCRATCH_MNT/swap" > /dev/null 2>&1
59 # Deleting device 1 should work again after swapoff.
60 $BTRFS_UTIL_PROG device delete "$scratch_dev1" "$SCRATCH_MNT"
62 _check_scratch_fs "$scratch_dev2"
65 _scratch_mkfs >> $seqres.full 2>&1
67 _format_swapfile "$SCRATCH_MNT/swap" $(($(get_page_size) * 10))
68 $BTRFS_UTIL_PROG device add -f "$scratch_dev2" "$SCRATCH_MNT"
69 swapon "$SCRATCH_MNT/swap" 2>&1 | _filter_scratch
70 # Again, we know the swap file is on device 1.
71 $BTRFS_UTIL_PROG replace start -fB "$scratch_dev1" "$scratch_dev3" "$SCRATCH_MNT" 2>&1 | grep -o "Text file busy"
72 # Replacing device 2 should still work.
73 $BTRFS_UTIL_PROG replace start -fB "$scratch_dev2" "$scratch_dev3" "$SCRATCH_MNT"
74 swapoff "$SCRATCH_MNT/swap" > /dev/null 2>&1
75 # Replacing device 1 should work again after swapoff.
76 $BTRFS_UTIL_PROG replace start -fB "$scratch_dev1" "$scratch_dev2" "$SCRATCH_MNT"
78 _check_scratch_fs "$scratch_dev2"