6 #-----------------------------------------------------------------------
7 # Copyright (c) 2011 Oracle. All Rights Reserved.
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.
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.
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 #-----------------------------------------------------------------------
25 echo "QA output created by $seq"
29 status=1 # failure is the default!
31 trap "_cleanup; exit \$status" 0 1 2 3 15
37 if [ $dev_removed == 1 ]; then
39 _devmgt_add "${DEVHTL}"
43 # get standard environment, filters and checks
51 _require_scratch_dev_pool
52 _require_deletable_scratch_dev_pool
54 # Test cases related to raid in btrfs
57 export MKFS_OPTIONS="-m raid0 -d raid0"
58 _scratch_mkfs $SCRATCH_DEV_POOL > /dev/null 2>&1 || _fail "mkfs failed"
60 dirp=`mktemp -duq $SCRATCH_MNT/dir.XXXXXX`
61 _populate_fs -n 1 -f 20 -d 10 -r $dirp -s 10
67 export MKFS_OPTIONS="-m raid1 -d raid1"
68 _scratch_mkfs $SCRATCH_DEV_POOL > /dev/null 2>&1 || _fail "mkfs failed"
70 dirp=`mktemp -duq $SCRATCH_MNT/dir.XXXXXX`
71 _populate_fs -n 1 -f 20 -d 10 -r $dirp -s 10
77 export MKFS_OPTIONS="-m raid10 -d raid10"
78 _scratch_mkfs $SCRATCH_DEV_POOL > /dev/null 2>&1 || _fail "mkfs failed"
80 dirp=`mktemp -duq $SCRATCH_MNT/dir.XXXXXX`
81 _populate_fs -n 1 -f 20 -d 10 -r $dirp -s 10
87 export MKFS_OPTIONS="-m single -d single"
88 _scratch_mkfs $SCRATCH_DEV_POOL > /dev/null 2>&1 || _fail "mkfs failed"
90 dirp=`mktemp -duq $SCRATCH_MNT/dir.XXXXXX`
91 _populate_fs -n 1 -f 20 -d 10 -r $dirp -s 10
98 local devs[]="( $SCRATCH_DEV_POOL )"
103 export MKFS_OPTIONS=""
104 _scratch_mkfs > /dev/null 2>&1 || _fail "mkfs failed"
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"
111 btrfs filesystem balance $SCRATCH_MNT || _fail "balance failed"
118 local devs=( $SCRATCH_DEV_POOL )
124 # exclude the last disk in the disk pool
128 export MKFS_OPTIONS="-m raid1 -d raid1"
129 _scratch_mkfs "$ds" > /dev/null 2>&1 || _fail "tr: mkfs failed"
131 dirp=`mktemp -duq $SCRATCH_MNT/dir.XXXXXX`
132 _populate_fs -n 1 -f 20 -d 10 -r $dirp -s 10
134 #pick the 2nd last disk
135 ds=${devs[@]:$(($n-1)):1}
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`
142 _devmgt_remove ${DEVHTL}
145 btrfs fi show $SCRATCH_DEV | grep "Some devices missing" > /dev/null || _fail \
146 "btrfs did not report device missing"
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
154 btrfs fi balance $SCRATCH_MNT || _fail "dev balance failed"
156 # cleaup. add the removed disk
158 _devmgt_add "${DEVHTL}"
164 _scratch_mkfs "$SCRATCH_DEV_POOL" > /dev/null 2>&1 || _fail "mkfs failed"
166 dirp=`mktemp -duq $SCRATCH_MNT/dir.XXXXXX`
167 _populate_fs -n 1 -f 20 -d 10 -r $dirp -s 10
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"
184 echo "Silence is golden"