2 # SPDX-License-Identifier: GPL-2.0
3 # Copyright (C) 2014 Fujitsu All Rights Reserved.
5 # FS QA Test No. btrfs/079
7 # Do write along with fiemap ioctl.
8 # Regression test for the kernel comit:
9 # 51f395ad btrfs: Use right extent length when inserting overlap extent map.
11 # When calling fiemap(without SYNC flag) and btrfs fs is commiting,
12 # it will cause race condition and cause btrfs to generate a wrong extent
13 # whose len is overflow and fail to insert into the extent map tree,
16 # Fixed by the following patches (not merged in mainline yet):
17 # btrfs: Fix and enhance merge_extent_mapping() to insert best fitted extent map
18 # btrfs: Fix the wrong condition judgment about subset extent map
21 seqres=$RESULT_DIR/$seq
22 echo "QA output created by $seq"
25 status=1 # failure is the default!
26 trap "_cleanup; exit \$status" 0 1 2 3 15
30 kill $dd_pid &> /dev/null
31 kill $fiemap_pid &> /dev/null
37 # get standard environment, filters and checks
41 # real QA test starts here
45 # Since xfs_io's fiemap always use SYNC flag and can't be unset,
46 # we must use filefrag to call fiemap without SYNC flag.
47 _require_command "$FILEFRAG_PROG" filefrag
48 _require_xfs_io_command "falloc"
50 filesize=$((10 * 1024 * 1024 * 1024)) #10G size
51 buffersize=$((1024 * 1024)) # 1M bs for dd
52 count=$(($filesize / $buffersize))
53 testfile=$SCRATCH_MNT/testfile
57 _scratch_mkfs >>$seqres.full 2>&1
59 _require_fs_space $SCRATCH_MNT $(($filesize / 1024))
60 $XFS_IO_PROG -f -c "falloc 0 $filesize" $testfile
64 dd if=/dev/zero of=$out bs=$buffersize count=$count \
65 conv=notrunc &> /dev/null
68 # There is a bug for e2fsprogs, at least in version 1.42.9, filefrag will
69 # leak the return value, so we can't judge return value only,
70 # but also to filter the output
72 # when filefrag fails FIEMAP ioctl, it will fall back to FIBMAP,
73 # which is not supported by btrfs and will report "FIBMAP: strerr()"
74 # However old e2fsprogs will use wrong errno EINVAL other than ENOTTY
75 # so only grep for "FIBMAP" for max compatibility.
82 $FILEFRAG_PROG $filename 2> $tmp.output 1> /dev/null
84 err=`cat $tmp.output | _filter_error`
85 if [ $ret -ne 0 -o -n "$err" ]; then
94 fiemap_work $testfile &
98 kill $fiemap_pid &> /dev/null
101 if [ $ddret -ne 0 ]; then
102 echo "Extent merge bug detected"
106 echo "Silence is golden"