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 echo "QA output created by $seq"
30 status=1 # failure is the default!
37 trap "_cleanup ; exit \$status" 0 1 2 3 15
39 # get standard environment, filters and checks
48 _scratch_mkfs $SCRATCH_DEV_POOL > /dev/null 2>&1 || _fail "mkfs failed"
51 # Create and save sha256sum
52 # arg1 FS to generate sha256
53 # arg2 File name to save the sha256 output
59 for i in `find . -type f`; do sha256sum $i >> $2; done
63 # Verify the sha256sum for a FS
64 # arg1 FS to be tested
69 [ -f $2 ] || _fail "checksum file $2 not found"
70 sha256sum -c $2 | grep "FAILED"
76 # Return snapshot name in the SNAPNAME
80 [ -d $1 ] || _fail "Destination dir $1 not present"
81 SNAPNAME=`mktemp -u $SCRATCH_MNT/snap.XXXXXX`
82 btrfs subvolume snapshot $1 $SNAPNAME > /dev/null || _fail "snapshot create failed"
85 # Reads and writes new data but does not allocate new blocks
86 # arg1 FS to be modified
91 for i in `find $1 -type f`
93 FSIZE=`stat -t $i | cut -d" " -f2`
94 dd if=$i of=/dev/null obs=$FSIZE count=1 status=noxfer 2>/dev/null &
95 dd if=/dev/urandom of=$i obs=$FSIZE count=1 status=noxfer 2>/dev/null &
100 # Fills the allocated blocks
101 # arg1 FS in question
110 for i in `find /$1 -type f`
112 FSIZE=`stat -t $i | cut -d" " -f2`
113 BLKS=`stat -c "%B" $i`
114 NBLK=`stat -c "%b" $i`
115 FALLOC=$(($BLKS * $NBLK))
116 WS=$(($FALLOC - $FSIZE))
117 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 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"