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
44 # Since xfs_io's fiemap always use SYNC flag and can't be unset,
45 # we must use filefrag to call fiemap without SYNC flag.
46 _require_command "$FILEFRAG_PROG" filefrag
47 _require_xfs_io_command "falloc"
49 filesize=$((10 * 1024 * 1024 * 1024)) #10G size
50 buffersize=$((1024 * 1024)) # 1M bs for dd
51 count=$(($filesize / $buffersize))
52 testfile=$SCRATCH_MNT/testfile
56 _scratch_mkfs >>$seqres.full 2>&1
58 _require_fs_space $SCRATCH_MNT $(($filesize / 1024))
59 $XFS_IO_PROG -f -c "falloc 0 $filesize" $testfile
63 dd if=/dev/zero of=$out bs=$buffersize count=$count \
64 conv=notrunc &> /dev/null
67 # There is a bug for e2fsprogs, at least in version 1.42.9, filefrag will
68 # leak the return value, so we can't judge return value only,
69 # but also to filter the output
71 # when filefrag fails FIEMAP ioctl, it will fall back to FIBMAP,
72 # which is not supported by btrfs and will report "FIBMAP: strerr()"
73 # However old e2fsprogs will use wrong errno EINVAL other than ENOTTY
74 # so only grep for "FIBMAP" for max compatibility.
79 # Wait for any running 'filefrag' subcommand before exitting so that
80 # after the test kills the subshell running this function, it does not
81 # fail with EBUSY when unmounting the scratch device because the filefrag
82 # subcommand is still running with an open file on the scratch fs.
83 trap "wait; exit" SIGTERM
87 $FILEFRAG_PROG $filename 2> $tmp.output 1> /dev/null
89 err=`cat $tmp.output | _filter_error`
90 if [ $ret -ne 0 -o -n "$err" ]; then
99 fiemap_work $testfile &
103 kill $fiemap_pid &> /dev/null
106 if [ $ddret -ne 0 ]; then
107 echo "Extent merge bug detected"
111 echo "Silence is golden"