40b248c677b6a528e40f4a9b7eaaa0f6c0a41026
[xfstests-dev.git] / tests / btrfs / 151
1 #! /bin/bash
2 # FS QA Test 151
3 #
4 # Test if it's losing data chunk's raid profile after 'btrfs device
5 # remove'.
6 #
7 # The fix is
8 #       Btrfs: avoid losing data raid profile when deleting a device
9 #
10 #-----------------------------------------------------------------------
11 # Copyright (c) 2017 Oracle.  All Rights Reserved.
12 #
13 # This program is free software; you can redistribute it and/or
14 # modify it under the terms of the GNU General Public License as
15 # published by the Free Software Foundation.
16 #
17 # This program is distributed in the hope that it would be useful,
18 # but WITHOUT ANY WARRANTY; without even the implied warranty of
19 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
20 # GNU General Public License for more details.
21 #
22 # You should have received a copy of the GNU General Public License
23 # along with this program; if not, write the Free Software Foundation,
24 # Inc.,  51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
25 #-----------------------------------------------------------------------
26 #
27
28 seq=`basename $0`
29 seqres=$RESULT_DIR/$seq
30 echo "QA output created by $seq"
31
32 here=`pwd`
33 tmp=/tmp/$$
34 status=1        # failure is the default!
35 trap "_cleanup; exit \$status" 0 1 2 3 15
36
37 _cleanup()
38 {
39         cd /
40         rm -f $tmp.*
41 }
42
43 # get standard environment, filters and checks
44 . ./common/rc
45 . ./common/filter
46
47 # remove previous $seqres.full before test
48 rm -f $seqres.full
49
50 # real QA test starts here
51
52 # Modify as appropriate.
53 _supported_fs btrfs
54 _supported_os Linux
55 _require_scratch
56 _require_scratch_dev_pool 3
57 _require_btrfs_dev_del_by_devid
58
59 # We need exactly 3 disks to form a fixed stripe layout for this test.
60 _scratch_dev_pool_get 3
61
62 # create raid1 for data
63 _scratch_pool_mkfs "-d raid1 -b 1G" >> $seqres.full 2>&1
64
65 # we need an empty data chunk, so nospace_cache is required.
66 _scratch_mount -onospace_cache
67
68 # if data chunk is empty, 'btrfs device remove' can change raid1 to
69 # single.
70 $BTRFS_UTIL_PROG device delete 2 $SCRATCH_MNT >> $seqres.full 2>&1
71
72 # save btrfs filesystem df output for debug purpose
73 $BTRFS_UTIL_PROG filesystem df $SCRATCH_MNT 2>&1 | \
74     tee -a $seqres.full | $AWK_PROG -F ':' '/Data,/ {print $1}'
75
76 _scratch_dev_pool_put
77
78 # success, all done
79 status=0
80 exit