2 # FS QA Test No. btrfs/079
4 # Do write along with fiemap ioctl.
5 # Regression test for the kernel comit:
6 # 51f395ad btrfs: Use right extent length when inserting overlap extent map.
8 # When calling fiemap(without SYNC flag) and btrfs fs is commiting,
9 # it will cause race condition and cause btrfs to generate a wrong extent
10 # whose len is overflow and fail to insert into the extent map tree,
13 # Fixed by the following patches (not merged in mainline yet):
14 # btrfs: Fix and enhance merge_extent_mapping() to insert best fitted extent map
15 # btrfs: Fix the wrong condition judgment about subset extent map
17 #-----------------------------------------------------------------------
18 # Copyright (C) 2014 Fujitsu All Rights Reserved.
19 # Author: Qu Wenruo <quwenruo@cn.fujitsu.com>
21 # This program is free software; you can redistribute it and/or
22 # modify it under the terms of the GNU General Public License as
23 # published by the Free Software Foundation.
25 # This program is distributed in the hope that it would be useful,
26 # but WITHOUT ANY WARRANTY; without even the implied warranty of
27 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
28 # GNU General Public License for more details.
30 # You should have received a copy of the GNU General Public License
31 # along with this program; if not, write the Free Software Foundation,
32 # Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
33 #-----------------------------------------------------------------------
37 seqres=$RESULT_DIR/$seq
38 echo "QA output created by $seq"
41 status=1 # failure is the default!
42 trap "_cleanup; exit \$status" 0 1 2 3 15
46 kill $dd_pid &> /dev/null
47 kill $fiemap_pid &> /dev/null
53 # get standard environment, filters and checks
57 # real QA test starts here
61 # Since xfs_io's fiemap always use SYNC flag and can't be unset,
62 # we must use filefrag to call fiemap without SYNC flag.
63 _require_command "$FILEFRAG_PROG" filefrag
64 _require_xfs_io_command "falloc"
66 filesize=$((10 * 1024 * 1024 * 1024)) #10G size
67 buffersize=$((1024 * 1024)) # 1M bs for dd
68 count=$(($filesize / $buffersize))
69 testfile=$SCRATCH_MNT/testfile
73 _scratch_mkfs >>$seqres.full 2>&1
75 _require_fs_space $SCRATCH_MNT $(($filesize / 1024))
76 $XFS_IO_PROG -f -c "falloc 0 $filesize" $testfile
80 dd if=/dev/zero of=$out bs=$buffersize count=$count \
81 conv=notrunc &> /dev/null
84 # There is a bug for e2fsprogs, at least in version 1.42.9, filefrag will
85 # leak the return value, so we can't judge return value only,
86 # but also to filter the output
88 # when filefrag fails FIEMAP ioctl, it will fall back to FIBMAP,
89 # which is not supported by btrfs and will report "FIBMAP: strerr()"
90 # However old e2fsprogs will use wrong errno EINVAL other than ENOTTY
91 # so only grep for "FIBMAP" for max compatibility.
98 $FILEFRAG_PROG $filename 2> $tmp.output 1> /dev/null
100 err=`cat $tmp.output | _filter_error`
101 if [ $ret -ne 0 -o -n "$err" ]; then
110 fiemap_work $testfile &
114 kill $fiemap_pid &> /dev/null
117 if [ $ddret -ne 0 ]; then
118 echo "Extent merge bug detected"
122 echo "Silence is golden"