generic: test for non-zero used blocks while writing into a file
[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 seq=`basename $0`
10 seqres=$RESULT_DIR/$seq
11 echo "QA output created by $seq"
12
13 here=`pwd`
14 tmp=/tmp/$$
15 status=1        # failure is the default!
16 trap "_cleanup; exit \$status" 0 1 2 3 15
17
18 _cleanup()
19 {
20         cd /
21         rm -f $tmp.*
22 }
23
24 # get standard environment, filters and checks
25 . ./common/rc
26 . ./common/filter
27
28 # remove previous $seqres.full before test
29 rm -f $seqres.full
30
31 # real QA test starts here
32
33 # Modify as appropriate.
34 _supported_fs btrfs
35 _require_scratch_dev_pool 3
36 _require_scratch_swapfile
37
38 # We check the filesystem manually because we move devices around.
39 rm -f "${RESULT_DIR}/require_scratch"
40
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 }')"
44
45 echo "Remove device"
46 _scratch_mkfs >> $seqres.full 2>&1
47 _scratch_mount
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
52 # already created.
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"
60 _scratch_unmount
61 _check_scratch_fs "$scratch_dev2"
62
63 echo "Replace device"
64 _scratch_mkfs >> $seqres.full 2>&1
65 _scratch_mount
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"
76 _scratch_unmount
77 _check_scratch_fs "$scratch_dev2"
78
79 # success, all done
80 status=0
81 exit