4 # Run fsstress to create a reasonably strange file system, make a
5 # snapshot and run more fsstress. Then select some files from that fs,
6 # run filefrag to get the extent mapping and follow the backrefs.
7 # We check to end up back at the original file with the correct offset.
9 #-----------------------------------------------------------------------
10 # Copyright (C) 2011 STRATO. All rights reserved.
12 # This program is free software; you can redistribute it and/or
13 # modify it under the terms of the GNU General Public License as
14 # published by the Free Software Foundation.
16 # This program is distributed in the hope that it would be useful,
17 # but WITHOUT ANY WARRANTY; without even the implied warranty of
18 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 # GNU General Public License for more details.
21 # You should have received a copy of the GNU General Public License
22 # along with this program; if not, write the Free Software Foundation,
23 # Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
25 #-----------------------------------------------------------------------
28 owner=list.btrfs@jan-o-sch.net
31 echo "QA output created by $seq"
40 if [ $noise_pid -ne 0 ]; then
41 echo "background noise kill $noise_pid" >>$seq.full
47 umount $SCRATCH_MNT 2>/dev/null
50 trap "_cleanup; exit \$status" 0 1 2 3 15
52 # get standard environment, filters and checks
56 # real QA test starts here
61 _require_no_large_scratch_dev
62 _require_btrfs inspect-internal
63 _require_command "/usr/sbin/filefrag"
67 FILEFRAG_FILTER='if (/, blocksize (\d+)/) {$blocksize = $1; next} ($ext, '\
68 '$logical, $physical, $expected, $length, $flags) = (/^\s*(\d+)\s+(\d+)'\
69 '\s+(\d+)\s+(?:(\d+)\s+)?(\d+)\s+(.*)/) or next; $flags =~ '\
70 '/(?:^|,)inline(?:,|$)/ and next; print $physical * $blocksize, "#", '\
71 '$length * $blocksize, "#", $logical * $blocksize, " "'
73 # this makes filefrag output script readable by using a perl helper.
74 # output is one extent per line, with three numbers separated by '#'
75 # the numbers are: physical, length, logical (all in bytes)
76 # sample output: "1234#10#5678" -> physical 1234, length 10, logical 5678
79 tee -a $seq.full | $PERL_PROG -ne "$FILEFRAG_FILTER"
85 echo "# $cmd" >> $seq.full
86 out=`$cmd | _filter_extents`
87 if [ -z "$out" ]; then
90 echo "after filter: $out" >> $seq.full
95 # use a logical address and walk the backrefs back to the inode.
96 # compare to the expected result.
97 # returns 0 on success, 1 on error (with output made)
105 cmd="$BTRFS_UTIL_PROG inspect-internal logical-resolve -P $addr $mp"
106 echo "# $cmd" >> $seq.full
108 echo "$out" >> $seq.full
109 grep_expr="inode $expect_inum offset $expect_addr root"
110 echo "$out" | grep "^$grep_expr 5$" >/dev/null
112 if [ $ret -eq 0 ]; then
113 # look for a root number that is not 5
114 echo "$out" | grep "^$grep_expr \([0-46-9][0-9]*\|5[0-9]\+\)$" \
118 if [ $ret -eq 0 ]; then
121 echo "unexpected output from"
123 echo "expected inum: $expect_inum, expected address: $expect_addr,"\
129 # use an inode number and walk the backrefs back to the file name.
130 # compare to the expected result.
131 # returns 0 on success, 1 on error (with output made)
132 _btrfs_inspect_inum()
137 mp="$SCRATCH_MNT/$snap_name"
138 cmd="$BTRFS_UTIL_PROG inspect-internal inode-resolve $inum $mp"
139 echo "# $cmd" >> $seq.full
141 echo "$out" >> $seq.full
143 cnt=`echo "$out" | grep "$grep_expr" | wc -l`
144 if [ $cnt -ge "1" ]; then
147 echo "unexpected output from"
149 echo "expected path: $file, got:"
154 _btrfs_inspect_check()
161 cmd="stat -c %i $file"
162 echo "# $cmd" >> $seq.full
164 echo "$inum" >> $seq.full
165 _btrfs_inspect_addr $SCRATCH_MNT $physical $logical $inum $file
167 if [ $ret -eq 0 ]; then
168 _btrfs_inspect_inum $file $inum $snap_name
182 umount $SCRATCH_DEV >/dev/null 2>&1
183 echo "*** mkfs -dsize=$fsz" >>$seq.full
185 _scratch_mkfs_sized $fsz >>$seq.full 2>&1 \
186 || _fail "size=$fsz mkfs failed"
187 run_check _scratch_mount
188 # -w ensures that the only ops are ones which cause write I/O
189 run_check $FSSTRESS_PROG -d $SCRATCH_MNT -w -p $procs -n 2000 \
192 run_check $BTRFS_UTIL_PROG subvol snap $SCRATCH_MNT \
193 $SCRATCH_MNT/$snap_name
195 run_check umount $SCRATCH_DEV >/dev/null 2>&1
196 run_check _scratch_mount "-o compress=lzo"
198 # make some noise but ensure we're not touching existing data
200 run_check $FSSTRESS_PROG -d $SCRATCH_MNT -p $procs -n 4000 \
201 -z -f chown=3 -f link=1 -f mkdir=2 -f mknod=2 \
202 -f rename=2 -f setxattr=1 -f symlink=2
204 clean_dir="$SCRATCH_MNT/next"
206 # now make more files to get a higher tree
207 run_check $FSSTRESS_PROG -d $clean_dir -w -p $procs -n 2000 \
209 run_check umount $SCRATCH_DEV >/dev/null 2>&1
210 run_check _scratch_mount "-o atime"
212 if [ $do_bg_noise -ne 0 ]; then
213 # make background noise while backrefs are being walked
215 echo background fsstress >>$seq.full
216 run_check $FSSTRESS_PROG -d $SCRATCH_MNT/bgnoise -n 999
217 echo background rm >>$seq.full
218 rm -rf $SCRATCH_MNT/bgnoise/
220 noise_pid=`jobs -p %1`
221 echo "background noise by $noise_pid" >>$seq.full
226 dir="$SCRATCH_MNT/$snap_name/"
227 for file in `find $dir -name f\* -size +0 | sort -R`; do
228 extents=`_check_file_extents $file`
230 if [ $ret -ne 0 ]; then
233 for i in $extents; do
237 physical=`echo $physical | sed -e 's/#.*//'`
238 length=`echo $length | sed -e 's/[^#]+#//'`
239 length=`echo $length | sed -e 's/#.*//'`
240 logical=`echo $logical | sed -e 's/.*#//'`
241 _btrfs_inspect_check $file $physical $length $logical \
244 if [ $ret -ne 0 ]; then
245 errcnt=`expr $errcnt + 1`
249 if [ $cnt -ge $nfiles ]; then
254 if [ $errcnt -gt 0 ]; then
255 _fail "test failed: $errcnt error(s)"
259 echo "*** test backref walking"
262 filesize=`expr 2000 \* 1024 \* 1024`
267 workout $filesize $nfiles $numprocs $snap_name $do_bg_noise