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 #-----------------------------------------------------------------------
24 owner=anand.jain@oracle.com
27 echo "QA output created by $seq"
31 status=1 # failure is the default!
33 trap "_cleanup; exit \$status" 0 1 2 3 15
39 if [ $dev_removed == 1 ]; then
41 _devmgt_add "${DEVHTL}"
45 # get standard environment, filters and checks
53 _require_scratch_dev_pool
54 _require_deletable_scratch_dev_pool
56 # Test cases related to raid in btrfs
59 export MKFS_OPTIONS="-m raid0 -d raid0"
60 _scratch_mkfs $SCRATCH_DEV_POOL > /dev/null 2>&1 || _fail "mkfs failed"
62 dirp=`mktemp -duq $SCRATCH_MNT/dir.XXXXXX`
63 _populate_fs -n 1 -f 20 -d 10 -r $dirp -s 10
69 export MKFS_OPTIONS="-m raid1 -d raid1"
70 _scratch_mkfs $SCRATCH_DEV_POOL > /dev/null 2>&1 || _fail "mkfs failed"
72 dirp=`mktemp -duq $SCRATCH_MNT/dir.XXXXXX`
73 _populate_fs -n 1 -f 20 -d 10 -r $dirp -s 10
79 export MKFS_OPTIONS="-m raid10 -d raid10"
80 _scratch_mkfs $SCRATCH_DEV_POOL > /dev/null 2>&1 || _fail "mkfs failed"
82 dirp=`mktemp -duq $SCRATCH_MNT/dir.XXXXXX`
83 _populate_fs -n 1 -f 20 -d 10 -r $dirp -s 10
89 export MKFS_OPTIONS="-m single -d single"
90 _scratch_mkfs $SCRATCH_DEV_POOL > /dev/null 2>&1 || _fail "mkfs failed"
92 dirp=`mktemp -duq $SCRATCH_MNT/dir.XXXXXX`
93 _populate_fs -n 1 -f 20 -d 10 -r $dirp -s 10
100 local devs[]="( $SCRATCH_DEV_POOL )"
105 export MKFS_OPTIONS=""
106 _scratch_mkfs > /dev/null 2>&1 || _fail "mkfs failed"
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"
113 btrfs filesystem balance $SCRATCH_MNT || _fail "balance failed"
120 local devs=( $SCRATCH_DEV_POOL )
126 # exclude the last disk in the disk pool
130 export MKFS_OPTIONS="-m raid1 -d raid1"
131 _scratch_mkfs "$ds" > /dev/null 2>&1 || _fail "tr: mkfs failed"
133 dirp=`mktemp -duq $SCRATCH_MNT/dir.XXXXXX`
134 _populate_fs -n 1 -f 20 -d 10 -r $dirp -s 10
136 #pick the 2nd last disk
137 ds=${devs[@]:$(($n-1)):1}
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`
144 _devmgt_remove ${DEVHTL}
147 btrfs fi show $SCRATCH_DEV | grep "Some devices missing" > /dev/null || _fail \
148 "btrfs did not report device missing"
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
156 btrfs fi balance $SCRATCH_MNT || _fail "dev balance failed"
158 # cleaup. add the removed disk
160 _devmgt_add "${DEVHTL}"
166 _scratch_mkfs "$SCRATCH_DEV_POOL" > /dev/null 2>&1 || _fail "mkfs failed"
168 dirp=`mktemp -duq $SCRATCH_MNT/dir.XXXXXX`
169 _populate_fs -n 1 -f 20 -d 10 -r $dirp -s 10
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"
186 echo "Silence is golden"