2 # SPDX-License-Identifier: GPL-2.0
3 # Copyright (c) 2011 Oracle. All Rights Reserved.
5 # FS QA Test No. btrfs/003
10 seqres=$RESULT_DIR/$seq
11 echo "QA output created by $seq"
15 status=1 # failure is the default!
18 trap "_cleanup; exit \$status" 0 1 2 3 15
20 # Check if all scratch dev pools are deletable
21 deletable_scratch_dev_pool()
25 for i in $SCRATCH_DEV_POOL; do
26 x=`echo $i | cut -d"/" -f 3`
27 if [ ! -f /sys/class/block/${x}/device/delete ]; then
39 if [ $dev_removed == 1 ]; then
41 _devmgt_add "${removed_dev_htl}"
45 # get standard environment, filters and checks
52 _require_scratch_dev_pool 4
53 _require_command "$WIPEFS_PROG" wipefs
57 # Test cases related to raid in btrfs
60 export MKFS_OPTIONS="-m raid0 -d raid0"
61 _scratch_pool_mkfs >> $seqres.full 2>&1 || _fail "mkfs failed"
63 dirp=`mktemp -duq $SCRATCH_MNT/dir.XXXXXX`
64 _populate_fs -n 1 -f 20 -d 10 -r $dirp -s 10 -c
70 export MKFS_OPTIONS="-m raid1 -d raid1"
71 _scratch_pool_mkfs >> $seqres.full 2>&1 || _fail "mkfs failed"
73 dirp=`mktemp -duq $SCRATCH_MNT/dir.XXXXXX`
74 _populate_fs -n 1 -f 20 -d 10 -r $dirp -s 10 -c
80 export MKFS_OPTIONS="-m raid10 -d raid10"
81 _scratch_pool_mkfs >> $seqres.full 2>&1 || _fail "mkfs failed"
83 dirp=`mktemp -duq $SCRATCH_MNT/dir.XXXXXX`
84 _populate_fs -n 1 -f 20 -d 10 -r $dirp -s 10
90 export MKFS_OPTIONS="-m single -d single"
91 _scratch_pool_mkfs >> $seqres.full 2>&1 || _fail "mkfs failed"
93 dirp=`mktemp -duq $SCRATCH_MNT/dir.XXXXXX`
94 _populate_fs -n 1 -f 20 -d 10 -r $dirp -s 10
101 local -a devs="( $SCRATCH_DEV_POOL )"
106 export MKFS_OPTIONS=""
107 _scratch_mkfs >> $seqres.full 2>&1 || _fail "mkfs failed"
109 dirp=`mktemp -duq $SCRATCH_MNT/dir.XXXXXX`
110 _populate_fs -n 1 -f 20 -d 10 -r $dirp -s 10
111 for i in `seq 2 $n`; do
112 $WIPEFS_PROG -a ${devs[$i]} >> $seqres.full 2>&1 || \
113 _fail "wipefs failed"
114 $BTRFS_UTIL_PROG device add ${devs[$i]} $SCRATCH_MNT >> $seqres.full 2>&1 || _fail "device add failed"
116 _run_btrfs_balance_start $SCRATCH_MNT >> $seqres.full
123 local devs=( $SCRATCH_DEV_POOL )
128 # If scratch devs are not deletable skip this test
129 if ! deletable_scratch_dev_pool; then return 0; fi
131 # exclude the first and the last disk in the disk pool
133 ds=${devs[@]:1:$(($n-1))}
135 export MKFS_OPTIONS="-m raid1 -d raid1"
136 _scratch_mkfs "$ds" >> $seqres.full 2>&1 || _fail "tr: mkfs failed"
138 dirp=`mktemp -duq $SCRATCH_MNT/dir.XXXXXX`
139 _populate_fs -n 1 -f 20 -d 10 -r $dirp -s 10
141 #pick the 2nd last disk
142 ds=${devs[@]:$(($n-1)):1}
144 # retrive the HTL for this scsi disk
145 d=`echo $ds|cut -d"/" -f3`
146 removed_dev_htl=`ls -l /sys/class/block/${d} | rev | cut -d "/" -f 3 | rev`
149 _devmgt_remove ${removed_dev_htl} $ds
152 $BTRFS_UTIL_PROG filesystem show $SCRATCH_DEV | grep "Some devices missing" >> $seqres.full || _fail \
153 "btrfs did not report device missing"
155 # add a new disk to btrfs
156 ds=${devs[@]:$(($n)):1}
157 $WIPEFS_PROG -a ${ds} >> $seqres.full 2>&1 || _fail "wipefs failed"
158 $BTRFS_UTIL_PROG device add ${ds} $SCRATCH_MNT >> $seqres.full 2>&1 || _fail "dev add failed"
159 # in some system balance fails if there is no delay (a bug)
160 # putting sleep 10 to work around as of now
162 _run_btrfs_balance_start $SCRATCH_MNT >> $seqres.full
164 # cleaup. add the removed disk
166 _devmgt_add "${removed_dev_htl}"
172 _scratch_pool_mkfs >> $seqres.full 2>&1 || _fail "mkfs failed"
174 dirp=`mktemp -duq $SCRATCH_MNT/dir.XXXXXX`
175 _populate_fs -n 1 -f 20 -d 10 -r $dirp -s 10
177 # pick last dev in the list
178 dev_del=`echo ${SCRATCH_DEV_POOL} | awk '{print $NF}'`
179 $BTRFS_UTIL_PROG device delete $dev_del $SCRATCH_MNT || _fail "btrfs device delete failed"
180 $BTRFS_UTIL_PROG filesystem show $SCRATCH_DEV 2>&1 | grep $dev_del >> $seqres.full && _fail "btrfs still shows the deleted dev"
192 echo "Silence is golden"