generic/233,270: unlimit the max locked memory size for io_uring
[xfstests-dev.git] / tests / btrfs / 027
1 #! /bin/bash
2 # SPDX-License-Identifier: GPL-2.0
3 # Copyright (c) 2016 Facebook.  All Rights Reserved.
4 #
5 # FS QA Test 027
6 #
7 # Test replace of a missing device on various data and metadata profiles.
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 _supported_fs btrfs
34 # we check scratch dev after each loop
35 _require_scratch_nocheck
36 _require_scratch_dev_pool 5
37 _require_scratch_dev_pool_equal_size
38 _btrfs_get_profile_configs replace-missing
39 _require_command "$WIPEFS_PROG" wipefs
40
41 run_test()
42 {
43         local mkfs_opts=$1
44         local ndevs=`echo $SCRATCH_DEV_POOL | wc -w`
45
46         # reserve one for replace target
47         ((ndevs--))
48
49         _scratch_dev_pool_get $ndevs
50         _spare_dev_get
51
52         echo "Test $mkfs_opts" >>$seqres.full
53
54         _scratch_pool_mkfs $mkfs_opts >>$seqres.full 2>&1
55         # make sure we created btrfs with desired options
56         if [ $? -ne 0 ]; then
57                 echo "mkfs $mkfs_opts failed"
58                 _spare_dev_put
59                 _scratch_dev_pool_put
60                 return
61         fi
62         _scratch_mount >>$seqres.full 2>&1
63
64         local missing_dev=`echo $SCRATCH_DEV_POOL | awk '{print $2}'`
65         local missing_dev_id=`$BTRFS_UTIL_PROG filesystem show $SCRATCH_MNT | grep $missing_dev | awk '{print $2}'`
66
67         # get some data on the filesystem so there's something to replace
68         _ddt of="$SCRATCH_MNT"/file1 bs=1M count=1 >> $seqres.full 2>&1
69         _ddt of="$SCRATCH_MNT"/file2 bs=1M count=2 >> $seqres.full 2>&1
70         _ddt of="$SCRATCH_MNT"/file3 bs=1M count=4 >> $seqres.full 2>&1
71
72         # nuke a device and remount in degraded mode
73         _scratch_unmount
74         $WIPEFS_PROG -a "$missing_dev" >>$seqres.full 2>&1
75         _scratch_mount -o degraded >>$seqres.full 2>&1
76
77         # replace $missing_dev with $replace_dev and scrub it to double-check
78         $BTRFS_UTIL_PROG replace start -B -f -r $missing_dev_id $SPARE_DEV \
79                 $SCRATCH_MNT >>$seqres.full 2>&1
80         if [ $? -ne 0 ]; then
81                 echo "btrfs replace failed"
82                 _scratch_unmount
83                 _spare_dev_put
84                 _scratch_dev_pool_put
85                 return
86         fi
87         $BTRFS_UTIL_PROG scrub start -B $SCRATCH_MNT >>$seqres.full 2>&1
88         if [ $? -ne 0 ]; then
89                 echo "btrfs scrub failed"
90                 _scratch_unmount
91                 _spare_dev_put
92                 _scratch_dev_pool_put
93                 return
94         fi
95
96         _scratch_unmount
97         # we called _require_scratch_nocheck instead of _require_scratch
98         # do check after test for each profile config
99         _check_scratch_fs
100         _spare_dev_put
101         _scratch_dev_pool_put
102 }
103
104 echo "Silence is golden"
105 for t in "${_btrfs_profile_configs[@]}"; do
106         run_test "$t"
107 done
108
109 status=0
110 exit