xfstests: move remaining tests out of top level directory
[xfstests-dev.git] / tests / btrfs / 265
1 #! /bin/bash
2 # FS QA Test No. 265
3 #
4 # btrfs vol tests
5 #
6 #-----------------------------------------------------------------------
7 # Copyright (c) 2011 Oracle.  All Rights Reserved.
8 #
9 # This program is free software; you can redistribute it and/or
10 # modify it under the terms of the GNU General Public License as
11 # published by the Free Software Foundation.
12 #
13 # This program is distributed in the hope that it would be useful,
14 # but WITHOUT ANY WARRANTY; without even the implied warranty of
15 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
16 # GNU General Public License for more details.
17 #
18 # You should have received a copy of the GNU General Public License
19 # along with this program; if not, write the Free Software Foundation,
20 # Inc.,  51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
21 #-----------------------------------------------------------------------
22 #
23
24 seq=`basename $0`
25 echo "QA output created by $seq"
26
27 here=`pwd`
28 tmp=/tmp/$$
29 status=1        # failure is the default!
30 dev_removed=0
31 trap "_cleanup; exit \$status" 0 1 2 3 15
32
33 _cleanup()
34 {
35     cd /
36     rm -f $tmp.*
37     if [ $dev_removed == 1 ]; then
38         umount $SCRATCH_MNT
39         _devmgt_add "${DEVHTL}"
40     fi
41 }
42
43 # get standard environment, filters and checks
44 . ./common.rc
45 . ./common.filter
46
47 _need_to_be_root
48 _supported_fs btrfs
49 _supported_os Linux
50 _require_scratch
51 _require_scratch_dev_pool
52 _require_deletable_scratch_dev_pool
53
54 # Test cases related to raid in btrfs
55 _test_raid0()
56 {
57         export MKFS_OPTIONS="-m raid0 -d raid0"
58         _scratch_mkfs $SCRATCH_DEV_POOL > /dev/null 2>&1 || _fail "mkfs failed"
59         _scratch_mount
60         dirp=`mktemp -duq $SCRATCH_MNT/dir.XXXXXX`
61         _populate_fs -n 1 -f 20 -d 10 -r $dirp -s 10
62         umount $SCRATCH_MNT
63 }
64
65 _test_raid1()
66 {
67         export MKFS_OPTIONS="-m raid1 -d raid1"
68         _scratch_mkfs $SCRATCH_DEV_POOL > /dev/null 2>&1 || _fail "mkfs failed"
69         _scratch_mount
70         dirp=`mktemp -duq $SCRATCH_MNT/dir.XXXXXX`
71         _populate_fs -n 1 -f 20 -d 10 -r $dirp -s 10
72         umount $SCRATCH_MNT
73 }
74
75 _test_raid10()
76 {
77         export MKFS_OPTIONS="-m raid10 -d raid10"
78         _scratch_mkfs $SCRATCH_DEV_POOL > /dev/null 2>&1 || _fail "mkfs failed"
79         _scratch_mount
80         dirp=`mktemp -duq $SCRATCH_MNT/dir.XXXXXX`
81         _populate_fs -n 1 -f 20 -d 10 -r $dirp -s 10
82         umount $SCRATCH_MNT
83 }
84
85 _test_single()
86 {
87         export MKFS_OPTIONS="-m single -d single"
88         _scratch_mkfs $SCRATCH_DEV_POOL > /dev/null 2>&1 || _fail "mkfs failed"
89         _scratch_mount
90         dirp=`mktemp -duq $SCRATCH_MNT/dir.XXXXXX`
91         _populate_fs -n 1 -f 20 -d 10 -r $dirp -s 10
92         umount $SCRATCH_MNT
93 }
94
95 _test_add()
96 {
97         local i
98         local devs[]="( $SCRATCH_DEV_POOL )"
99         local n=${#devs[@]}
100
101         n=$(($n-1))
102
103         export MKFS_OPTIONS=""
104         _scratch_mkfs > /dev/null 2>&1 || _fail "mkfs failed"
105         _scratch_mount
106         dirp=`mktemp -duq $SCRATCH_MNT/dir.XXXXXX`
107         _populate_fs -n 1 -f 20 -d 10 -r $dirp -s 10
108         for i in `seq 1 $n`; do
109                 btrfs device add ${devs[$i]} $SCRATCH_MNT > /dev/null 2>&1 || _fail "device add failed"
110         done
111         btrfs filesystem balance $SCRATCH_MNT || _fail "balance failed"
112         umount $SCRATCH_MNT
113 }
114
115 _test_replace()
116 {
117         local i
118         local devs=( $SCRATCH_DEV_POOL )
119         local n=${#devs[@]}
120         local ds
121         local d
122         local DEVHTL=""
123
124         # exclude the last disk in the disk pool
125         n=$(($n-1))
126         ds=${devs[@]:0:$n}
127
128         export MKFS_OPTIONS="-m raid1 -d raid1"
129         _scratch_mkfs "$ds" > /dev/null 2>&1 || _fail "tr: mkfs failed"
130         _scratch_mount
131         dirp=`mktemp -duq $SCRATCH_MNT/dir.XXXXXX`
132         _populate_fs -n 1 -f 20 -d 10 -r $dirp -s 10
133
134         #pick the 2nd last disk 
135         ds=${devs[@]:$(($n-1)):1}
136
137         # retrive the HTL for this scsi disk
138         d=`echo $ds|cut -d"/" -f3`
139         DEVHTL=`ls -l /sys/class/block/${d} | rev | cut -d "/" -f 3 | rev`
140
141         #fail disk
142         _devmgt_remove ${DEVHTL}
143         dev_removed=1
144
145         btrfs fi show $SCRATCH_DEV | grep "Some devices missing" > /dev/null || _fail \
146                                                         "btrfs did not report device missing"
147
148         # add a new disk to btrfs
149         ds=${devs[@]:$(($n)):1}
150         btrfs device add ${ds} $SCRATCH_MNT > /dev/null 2>&1 || _fail "dev add failed"
151         # in some system balance fails if there is no delay (a bug)
152         # putting sleep 10 to work around as of now
153         # sleep 10
154         btrfs fi balance $SCRATCH_MNT || _fail "dev balance failed"
155
156         # cleaup. add the removed disk
157         umount $SCRATCH_MNT
158         _devmgt_add "${DEVHTL}"
159         dev_removed=0
160 }
161
162 _test_remove()
163 {
164         _scratch_mkfs "$SCRATCH_DEV_POOL" > /dev/null 2>&1 || _fail "mkfs failed"
165         _scratch_mount
166         dirp=`mktemp -duq $SCRATCH_MNT/dir.XXXXXX`
167         _populate_fs -n 1 -f 20 -d 10 -r $dirp -s 10
168
169         # pick last dev in the list
170         dev_del=`echo ${SCRATCH_DEV_POOL} | awk '{print $NF}'`
171         btrfs device delete $dev_del $SCRATCH_MNT || _fail "btrfs device delete failed"
172         btrfs fi show $SCRATCH_DEV 2>&1 | grep $dev_del > /dev/null && _fail "btrfs still shows the deleted dev"
173         umount $SCRATCH_MNT
174 }
175
176 _test_raid0
177 _test_raid1
178 _test_raid10
179 _test_single
180 _test_add
181 _test_replace
182 _test_remove
183
184 echo "Silence is golden"
185 status=0; exit