generic: test MADV_POPULATE_READ with IO errors
[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 . ./common/preamble
13 _begin_fstest auto quick volume
14
15 # Override the default cleanup function.
16 _cleanup()
17 {
18         $UMOUNT_PROG $TEST_DIR/$seq.mnt >/dev/null 2>&1
19         rm -rf $TEST_DIR/$seq.mnt
20         cd /
21         rm -f $tmp.*
22 }
23
24 # Import common functions.
25 . ./common/filter
26 . ./common/filter.btrfs
27
28 # real QA test starts here
29 _supported_fs btrfs
30 _require_test
31 _require_scratch
32 _require_scratch_dev_pool 5
33 # Zoned btrfs only supports SINGLE profile
34 _require_non_zoned_device ${SCRATCH_DEV}
35
36 workout()
37 {
38         raid=$1
39         device_nr=$2
40
41         echo $raid
42         _scratch_dev_pool_get $device_nr
43         _spare_dev_get
44
45         _mkfs_dev $SPARE_DEV
46         mkdir -p $TEST_DIR/$seq.mnt
47         _mount $SPARE_DEV $TEST_DIR/$seq.mnt
48
49         _scratch_pool_mkfs "-d$raid -m$raid" >> $seqres.full 2>&1 || \
50                                                         _fail "mkfs failed"
51
52         # Make device_1 an alien btrfs device for the raid created above by
53         # adding it to the $TEST_DIR/$seq.mnt
54
55         # don't test with the first device as auto fs check (_check_scratch_fs)
56         # picks the first device
57         device_1=$(echo $SCRATCH_DEV_POOL | awk '{print $2}')
58         $BTRFS_UTIL_PROG device add -f "$device_1" "$TEST_DIR/$seq.mnt" >> \
59                 $seqres.full
60
61         device_2=$(echo $SCRATCH_DEV_POOL | awk '{print $1}')
62         _mount -o degraded $device_2 $SCRATCH_MNT
63         # Check if missing device is reported as in the .out
64         $BTRFS_UTIL_PROG filesystem show -m $SCRATCH_MNT | \
65                                                 _filter_btrfs_filesystem_show
66
67         $BTRFS_UTIL_PROG device remove "$device_1" "$TEST_DIR/$seq.mnt"
68         $UMOUNT_PROG $TEST_DIR/$seq.mnt
69         _scratch_unmount
70         _spare_dev_put
71         _scratch_dev_pool_put
72 }
73
74 workout "raid1" "2"
75 workout "raid5" "3"
76 workout "raid6" "4"
77 workout "raid10" "4"
78
79 # success, all done
80 status=0
81 exit