btrfs: redirect device replace output to $seqres.full
[xfstests-dev.git] / tests / btrfs / 176
1 #! /bin/bash
2 # SPDX-License-Identifier: GPL-2.0
3 # Copyright (c) 2018 Facebook.  All Rights Reserved.
4 #
5 # FS QA Test 176
6 #
7 # Test device remove/replace with an active swap file.
8 #
9 . ./common/preamble
10 _begin_fstest auto quick swap volume
11
12 # Import common functions.
13 . ./common/filter
14
15 # real QA test starts here
16
17 # Modify as appropriate.
18 _supported_fs btrfs
19 _require_scratch_dev_pool 3
20 _require_scratch_swapfile
21
22 # We check the filesystem manually because we move devices around.
23 rm -f "${RESULT_DIR}/require_scratch"
24
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 }')"
28
29 echo "Remove device"
30 _scratch_mkfs >> $seqres.full 2>&1
31 _scratch_mount
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
36 # already created.
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"
44 _scratch_unmount
45 _check_scratch_fs "$scratch_dev2"
46
47 echo "Replace device"
48 _scratch_mkfs >> $seqres.full 2>&1
49 _scratch_mount
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" \
57         >> $seqres.full
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" \
61         >> $seqres.full
62 _scratch_unmount
63 _check_scratch_fs "$scratch_dev2"
64
65 # success, all done
66 status=0
67 exit