2 # FS QA Test No. btrfs/002
4 # Extented btrfs snapshot test cases
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
22 #-----------------------------------------------------------------------
26 seqres=$RESULT_DIR/$seq
27 echo "QA output created by $seq"
31 status=1 # failure is the default!
38 trap "_cleanup ; exit \$status" 0 1 2 3 15
40 # get standard environment, filters and checks
49 _scratch_mkfs > /dev/null 2>&1 || _fail "mkfs failed"
52 # Create and save sha256sum
53 # arg1 FS to generate sha256
54 # arg2 File name to save the sha256 output
60 for i in `find . -type f`; do sha256sum $i >> $2; done
64 # Verify the sha256sum for a FS
65 # arg1 FS to be tested
70 [ -f $2 ] || _fail "checksum file $2 not found"
71 sha256sum -c $2 | grep "FAILED"
77 # Return snapshot name in the SNAPNAME
81 [ -d $1 ] || _fail "Destination dir $1 not present"
82 SNAPNAME=`mktemp -u $SCRATCH_MNT/snap.XXXXXX`
83 $BTRFS_UTIL_PROG subvolume snapshot $1 $SNAPNAME > /dev/null || _fail "snapshot create failed"
86 # Reads and writes new data but does not allocate new blocks
87 # arg1 FS to be modified
92 for i in `find $1 -type f`
94 FSIZE=`stat -t $i | cut -d" " -f2`
95 dd if=$i of=/dev/null obs=$FSIZE count=1 status=noxfer 2>/dev/null &
96 dd if=/dev/urandom of=$i obs=$FSIZE count=1 status=noxfer 2>/dev/null &
101 # Fills the allocated blocks
102 # arg1 FS in question
111 for i in `find /$1 -type f`
113 FSIZE=`stat -t $i | cut -d" " -f2`
114 BLKS=`stat -c "%B" $i`
115 NBLK=`stat -c "%b" $i`
116 FALLOC=$(($BLKS * $NBLK))
117 WS=$(($FALLOC - $FSIZE))
118 dd if=/dev/urandom of=$i oseek=$FSIZE obs=$WS count=1 status=noxfer 2>/dev/null &
123 # Append a random size to the files
124 # arg1 : FS in question
132 for i in `find $1 -type f`
136 FSIZE=`stat -t $X | cut -d" " -f2`
137 dd if=$X of=$X seek=1 bs=$FSIZE obs=$FSIZE count=1 status=noxfer 2>/dev/null &
141 FSIZE=`stat -t $i | cut -d" " -f2`
142 dd if=$X of=$i seek=1 bs=$FSIZE obs=$FSIZE count=1 status=noxfer 2>/dev/null &
148 ##################### real QA test starts here###################################
149 # sv1 - is just a name nothing spl
150 firstvol="$SCRATCH_MNT/sv1"
151 $BTRFS_UTIL_PROG subvolume create $firstvol > /dev/null || _fail "btrfs subvolume create $firstvol failed"
152 dirp=`mktemp -duq $firstvol/dir.XXXXXX`
153 _populate_fs -n 1 -f 20 -d 10 -r $dirp -s 10 -x
155 _create_snap $firstvol
156 _save_checksum $firstvol $tmp.sv1.sum
157 _verify_checksum $SNAPNAME $tmp.sv1.sum
161 _verify_checksum $firstvol $tmp.sv1.sum
164 _append_file $SNAPNAME
165 _verify_checksum $firstvol $tmp.sv1.sum
168 _read_modify_write $SNAPNAME
169 _verify_checksum $firstvol $tmp.sv1.sum
171 #nested snapshot test
173 for i in `seq 1 7`; do
175 _create_snap $src_vol
176 _verify_checksum $SNAPNAME $tmp.sv1.sum
182 _create_snap $firstvol
183 tname=`echo $SNAPNAME | rev | cut -d"/" -f1 | rev`
184 _save_checksum $SNAPNAME $tmp.$tname.sum
186 _verify_checksum $SNAPNAME $tmp.$tname.sum
188 umount $SCRATCH_DEV || _fail "unmount failed"
190 echo "Silence is golden"