btrfs: check qgroup doesn't crash when beyond limit
[xfstests-dev.git] / tests / btrfs / 197
1 #! /bin/bash
2 # SPDX-License-Identifier: GPL-2.0
3 # Copyright (c) 2019 Oracle.  All Rights Reserved.
4 #
5 # FS QA Test 197
6 #
7 # Test stale and alien btrfs-device in the fs devices list.
8 #  Bug fixed in the kernel patch:
9 #   btrfs: include non-missing as a qualifier for the latest_bdev
10 #   btrfs: remove identified alien btrfs device in open_fs_devices
11 #
12 seq=`basename $0`
13 seqres=$RESULT_DIR/$seq
14 echo "QA output created by $seq"
15
16 here=`pwd`
17 tmp=/tmp/$$
18 status=1        # failure is the default!
19 trap "_cleanup; exit \$status" 0 1 2 3 15
20
21 _cleanup()
22 {
23         $UMOUNT_PROG $TEST_DIR/$seq.mnt >/dev/null 2>&1
24         rm -rf $TEST_DIR/$seq.mnt
25         cd /
26         rm -f $tmp.*
27 }
28
29 # get standard environment, filters and checks
30 . ./common/rc
31 . ./common/filter
32 . ./common/filter.btrfs
33
34 # remove previous $seqres.full before test
35 rm -f $seqres.full
36
37 # real QA test starts here
38 _supported_fs btrfs
39 _require_test
40 _require_scratch
41 _require_scratch_dev_pool 5
42
43 workout()
44 {
45         raid=$1
46         device_nr=$2
47
48         echo $raid
49         _scratch_dev_pool_get $device_nr
50         _spare_dev_get
51
52         _mkfs_dev $SPARE_DEV
53         mkdir -p $TEST_DIR/$seq.mnt
54         _mount $SPARE_DEV $TEST_DIR/$seq.mnt
55
56         _scratch_pool_mkfs "-d$raid -m$raid" >> $seqres.full 2>&1 || \
57                                                         _fail "mkfs failed"
58
59         # Make device_1 an alien btrfs device for the raid created above by
60         # adding it to the $TEST_DIR/$seq.mnt
61
62         # don't test with the first device as auto fs check (_check_scratch_fs)
63         # picks the first device
64         device_1=$(echo $SCRATCH_DEV_POOL | awk '{print $2}')
65         $BTRFS_UTIL_PROG device add -f "$device_1" "$TEST_DIR/$seq.mnt"
66
67         device_2=$(echo $SCRATCH_DEV_POOL | awk '{print $1}')
68         _mount -o degraded $device_2 $SCRATCH_MNT
69         # Check if missing device is reported as in the .out
70         $BTRFS_UTIL_PROG filesystem show -m $SCRATCH_MNT | \
71                                                 _filter_btrfs_filesystem_show
72
73         $BTRFS_UTIL_PROG device remove "$device_1" "$TEST_DIR/$seq.mnt"
74         $UMOUNT_PROG $TEST_DIR/$seq.mnt
75         _scratch_unmount
76         _spare_dev_put
77         _scratch_dev_pool_put
78 }
79
80 workout "raid1" "2"
81 workout "raid5" "3"
82 workout "raid6" "4"
83 workout "raid10" "4"
84
85 # success, all done
86 status=0
87 exit