xfstests: detect gdbm library correctly
[xfstests-dev.git] / 264
1 #!/bin/bash
2 # FS QA Test No. 264
3 #
4 # Extented btrfs snapshot test cases
5 #
6 #-----------------------------------------------------------------------
7 # Copyright (c) 2011 Oracle  All Rights Reserved.
8 #
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.
12 #
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.
17 #
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 #
22 #-----------------------------------------------------------------------
23 #
24 # creator
25 owner=anand.jain@oracle.com
26
27 seq=`basename $0`
28 echo "QA output created by $seq"
29
30 here=`pwd`
31 tmp=/tmp/$$
32 status=1        # failure is the default!
33
34 _cleanup()
35 {
36     rm -f $tmp.*
37 }
38
39 trap "_cleanup ; exit \$status" 0 1 2 3 15
40
41 # get standard environment, filters and checks
42 . ./common.rc
43 . ./common.filter
44
45 _need_to_be_root
46 _supported_fs btrfs
47 _supported_os Linux
48 _require_scratch
49
50 _scratch_mkfs $SCRATCH_DEV_POOL > /dev/null 2>&1 || _fail "mkfs failed"
51 _scratch_mount
52
53 # Create and save sha256sum
54 # arg1 FS to generate sha256
55 # arg2 File name to save the sha256 output
56 _save_checksum()
57 {
58         local i=0
59         >$2
60         cd $1
61         for i in `find . -type f`; do sha256sum $i >> $2; done
62         cd $OLDPWD
63 }
64
65 # Verify the sha256sum for a FS
66 # arg1 FS to be tested
67 # arg2 sha256 file
68 _verify_checksum()
69 {
70         cd $1
71         [ -f $2 ] || _fail "checksum file $2 not found"
72         sha256sum -c $2 | grep "FAILED"
73         cd $OLDPWD
74 }
75
76 # Create a snapshot
77 # arg1 dest dir
78 # Return snapshot name in the SNAPNAME
79 _create_snap()
80 {
81         local x
82         [ -d $1 ] || _fail "Destination dir $1 not present"
83         SNAPNAME=`mktemp -u $SCRATCH_MNT/snap.XXXXXX`
84         btrfs subvolume snapshot $1 $SNAPNAME > /dev/null || _fail "snapshot create failed"
85 }
86
87 # Reads and writes new data but does not allocate new blocks
88 # arg1 FS to be modified
89 _read_modify_write()
90 {
91         local i
92         local FSIZE
93         for i in `find $1 -type f`
94         do
95                 FSIZE=`stat -t $i | cut -d" " -f2`
96                 dd if=$i of=/dev/null obs=$FSIZE count=1 status=noxfer 2>/dev/null &
97                 dd if=/dev/urandom of=$i obs=$FSIZE count=1 status=noxfer 2>/dev/null &
98         done
99         wait $!
100 }
101
102 # Fills the allocated blocks
103 # arg1 FS in question
104 _fill_blk()
105 {
106         local FSIZE
107         local BLKS
108         local NBLK
109         local FALLOC
110         local WS
111
112         for i in `find /$1 -type f`
113         do
114                 FSIZE=`stat -t $i | cut -d" " -f2`
115                 BLKS=`stat -c "%B" $i`
116                 NBLK=`stat -c "%b" $i`
117                 FALLOC=$(($BLKS * $NBLK))
118                 WS=$(($FALLOC - $FSIZE))
119                 dd if=/dev/urandom of=$i oseek=$FSIZE obs=$WS count=1 status=noxfer 2>/dev/null &
120         done
121         wait $!
122 }
123
124
125 # Append a random size to the files
126 # arg1 : FS in question
127 _append_file()
128 {
129         local FSIZE
130         local X
131         local N
132         local i
133         N=0
134         for i in `find $1 -type f`
135         do
136                 if [ $N == 0 ]; then
137                         X=$i
138                         FSIZE=`stat -t $X | cut -d" " -f2`
139                         dd if=$X of=$X seek=1 bs=$FSIZE obs=$FSIZE count=1 status=noxfer 2>/dev/null &
140                         N=$(($N+1))
141                         continue
142                 fi
143                 FSIZE=`stat -t $i | cut -d" " -f2`
144                 dd if=$X of=$i seek=1 bs=$FSIZE obs=$FSIZE count=1 status=noxfer 2>/dev/null &
145                 X=$i
146         done
147         wait $!
148 }
149
150 ##################### real QA test starts here###################################
151 # sv1 - is just a name nothing spl
152 firstvol="$SCRATCH_MNT/sv1"
153 btrfs subvolume create $firstvol > /dev/null || _fail "btrfs subvolume create $firstvol failed"
154 dirp=`mktemp -duq $firstvol/dir.XXXXXX`
155 _populate_fs -n 1 -f 20 -d 10 -r $dirp -s 10 -x
156 SNAPNAME=0
157 _create_snap $firstvol
158 _save_checksum $firstvol $tmp.sv1.sum
159 _verify_checksum $SNAPNAME $tmp.sv1.sum
160
161 #Append1 the files
162 _fill_blk $SNAPNAME
163 _verify_checksum $firstvol $tmp.sv1.sum
164
165 #Append2 the files
166 _append_file $SNAPNAME
167 _verify_checksum $firstvol $tmp.sv1.sum
168
169 #read modify write
170 _read_modify_write $SNAPNAME
171 _verify_checksum $firstvol $tmp.sv1.sum
172
173 #nested snapshot test
174 src_vol=$firstvol
175 for i in `seq 1 7`; do
176         SNAPNAME=0
177         _create_snap $src_vol
178         _verify_checksum $SNAPNAME $tmp.sv1.sum
179         src_vol=$SNAPNAME
180 done
181
182 # file delete test
183 SNAPNAME=0
184 _create_snap $firstvol
185 tname=`echo $SNAPNAME | rev | cut -d"/" -f1 | rev`
186 _save_checksum $SNAPNAME $tmp.$tname.sum
187 \rm -rf $firstvol/*
188 _verify_checksum $SNAPNAME $tmp.$tname.sum
189
190 umount $SCRATCH_DEV || _fail "unmount failed"
191
192 echo "Silence is golden"
193 status=0; exit