10f214f4c9f0ea54b36028ea523190eb8cfae8f5
[xfstests-dev.git] / 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 # creator
24 owner=anand.jain@oracle.com
25
26 seq=`basename $0`
27 echo "QA output created by $seq"
28
29 here=`pwd`
30 tmp=/tmp/$$
31 status=1        # failure is the default!
32 dev_removed=0
33 trap "_cleanup; exit \$status" 0 1 2 3 15
34
35 _cleanup()
36 {
37     cd /
38     rm -f $tmp.*
39     if [ $dev_removed == 1 ]; then
40         umount $SCRATCH_MNT
41         _devmgt_add "${DEVHTL}"
42     fi
43 }
44
45 # get standard environment, filters and checks
46 . ./common.rc
47 . ./common.filter
48
49 _need_to_be_root
50 _supported_fs btrfs
51 _supported_os Linux
52 _require_scratch
53 _require_scratch_dev_pool
54 _require_deletable_scratch_dev_pool
55
56 # Test cases related to raid in btrfs
57 _test_raid0()
58 {
59         export MKFS_OPTIONS="-m raid0 -d raid0"
60         _scratch_mkfs $SCRATCH_DEV_POOL > /dev/null 2>&1 || _fail "mkfs failed"
61         _scratch_mount
62         dirp=`mktemp -duq $SCRATCH_MNT/dir.XXXXXX`
63         _populate_fs -n 1 -f 20 -d 10 -r $dirp -s 10
64         umount $SCRATCH_MNT
65 }
66
67 _test_raid1()
68 {
69         export MKFS_OPTIONS="-m raid1 -d raid1"
70         _scratch_mkfs $SCRATCH_DEV_POOL > /dev/null 2>&1 || _fail "mkfs failed"
71         _scratch_mount
72         dirp=`mktemp -duq $SCRATCH_MNT/dir.XXXXXX`
73         _populate_fs -n 1 -f 20 -d 10 -r $dirp -s 10
74         umount $SCRATCH_MNT
75 }
76
77 _test_raid10()
78 {
79         export MKFS_OPTIONS="-m raid10 -d raid10"
80         _scratch_mkfs $SCRATCH_DEV_POOL > /dev/null 2>&1 || _fail "mkfs failed"
81         _scratch_mount
82         dirp=`mktemp -duq $SCRATCH_MNT/dir.XXXXXX`
83         _populate_fs -n 1 -f 20 -d 10 -r $dirp -s 10
84         umount $SCRATCH_MNT
85 }
86
87 _test_single()
88 {
89         export MKFS_OPTIONS="-m single -d single"
90         _scratch_mkfs $SCRATCH_DEV_POOL > /dev/null 2>&1 || _fail "mkfs failed"
91         _scratch_mount
92         dirp=`mktemp -duq $SCRATCH_MNT/dir.XXXXXX`
93         _populate_fs -n 1 -f 20 -d 10 -r $dirp -s 10
94         umount $SCRATCH_MNT
95 }
96
97 _test_add()
98 {
99         local i
100         local devs[]="( $SCRATCH_DEV_POOL )"
101         local n=${#devs[@]}
102
103         n=$(($n-1))
104
105         export MKFS_OPTIONS=""
106         _scratch_mkfs > /dev/null 2>&1 || _fail "mkfs failed"
107         _scratch_mount
108         dirp=`mktemp -duq $SCRATCH_MNT/dir.XXXXXX`
109         _populate_fs -n 1 -f 20 -d 10 -r $dirp -s 10
110         for i in `seq 1 $n`; do
111                 btrfs device add ${devs[$i]} $SCRATCH_MNT > /dev/null 2>&1 || _fail "device add failed"
112         done
113         btrfs filesystem balance $SCRATCH_MNT || _fail "balance failed"
114         umount $SCRATCH_MNT
115 }
116
117 _test_replace()
118 {
119         local i
120         local devs=( $SCRATCH_DEV_POOL )
121         local n=${#devs[@]}
122         local ds
123         local d
124         local DEVHTL=""
125
126         # exclude the last disk in the disk pool
127         n=$(($n-1))
128         ds=${devs[@]:0:$n}
129
130         export MKFS_OPTIONS="-m raid1 -d raid1"
131         _scratch_mkfs "$ds" > /dev/null 2>&1 || _fail "tr: mkfs failed"
132         _scratch_mount
133         dirp=`mktemp -duq $SCRATCH_MNT/dir.XXXXXX`
134         _populate_fs -n 1 -f 20 -d 10 -r $dirp -s 10
135
136         #pick the 2nd last disk 
137         ds=${devs[@]:$(($n-1)):1}
138
139         # retrive the HTL for this scsi disk
140         d=`echo $ds|cut -d"/" -f3`
141         DEVHTL=`ls -l /sys/class/block/${d} | rev | cut -d "/" -f 3 | rev`
142
143         #fail disk
144         _devmgt_remove ${DEVHTL}
145         dev_removed=1
146
147         btrfs fi show $SCRATCH_DEV | grep "Some devices missing" > /dev/null || _fail \
148                                                         "btrfs did not report device missing"
149
150         # add a new disk to btrfs
151         ds=${devs[@]:$(($n)):1}
152         btrfs device add ${ds} $SCRATCH_MNT > /dev/null 2>&1 || _fail "dev add failed"
153         # in some system balance fails if there is no delay (a bug)
154         # putting sleep 10 to work around as of now
155         # sleep 10
156         btrfs fi balance $SCRATCH_MNT || _fail "dev balance failed"
157
158         # cleaup. add the removed disk
159         umount $SCRATCH_MNT
160         _devmgt_add "${DEVHTL}"
161         dev_removed=0
162 }
163
164 _test_remove()
165 {
166         _scratch_mkfs "$SCRATCH_DEV_POOL" > /dev/null 2>&1 || _fail "mkfs failed"
167         _scratch_mount
168         dirp=`mktemp -duq $SCRATCH_MNT/dir.XXXXXX`
169         _populate_fs -n 1 -f 20 -d 10 -r $dirp -s 10
170
171         # pick last dev in the list
172         dev_del=`echo ${SCRATCH_DEV_POOL} | awk '{print $NF}'`
173         btrfs device delete $dev_del $SCRATCH_MNT || _fail "btrfs device delete failed"
174         btrfs fi show $SCRATCH_DEV 2>&1 | grep $dev_del > /dev/null && _fail "btrfs still shows the deleted dev"
175         umount $SCRATCH_MNT
176 }
177
178 _test_raid0
179 _test_raid1
180 _test_raid10
181 _test_single
182 _test_add
183 _test_replace
184 _test_remove
185
186 echo "Silence is golden"
187 status=0; exit