fstests: move test group info to test files
[xfstests-dev.git] / tests / btrfs / 079
1 #! /bin/bash
2 # SPDX-License-Identifier: GPL-2.0
3 # Copyright (C) 2014 Fujitsu All Rights Reserved.
4 #
5 # FS QA Test No. btrfs/079
6 #
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.
10 #
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,
14 # returning -EEXIST.
15 #
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
19 #
20 . ./common/preamble
21 _begin_fstest auto rw metadata
22
23 # Override the default cleanup function.
24 _cleanup()
25 {
26         kill $dd_pid &> /dev/null
27         kill $fiemap_pid &> /dev/null
28         wait
29         rm -fr $testfile
30         rm -fr $tmp.* $tmp
31 }
32
33 # Import common functions.
34 . ./common/filter
35
36 # real QA test starts here
37 _supported_fs btrfs
38 _require_scratch
39 # Since xfs_io's fiemap always use SYNC flag and can't be unset,
40 # we must use filefrag to call fiemap without SYNC flag.
41 _require_command "$FILEFRAG_PROG" filefrag
42 _require_xfs_io_command "falloc"
43
44 filesize=$((10 * 1024 * 1024 * 1024)) #10G size
45 buffersize=$((1024 * 1024)) # 1M bs for dd
46 count=$(($filesize / $buffersize))
47 testfile=$SCRATCH_MNT/testfile
48
49 _scratch_mkfs >>$seqres.full 2>&1
50 _scratch_mount
51 _require_fs_space $SCRATCH_MNT $(($filesize / 1024))
52 $XFS_IO_PROG -f -c "falloc 0 $filesize" $testfile
53
54 dd_work() {
55         out=$1
56         dd if=/dev/zero of=$out bs=$buffersize count=$count \
57            conv=notrunc &> /dev/null
58 }
59
60 # There is a bug for e2fsprogs, at least in version 1.42.9, filefrag will
61 # leak the return value, so we can't judge return value only,
62 # but also to filter the output
63 _filter_error() {
64         # when filefrag fails FIEMAP ioctl, it will fall back to FIBMAP,
65         # which is not supported by btrfs and will report "FIBMAP: strerr()"
66         # However old e2fsprogs will use wrong errno EINVAL other than ENOTTY
67         # so only grep for "FIBMAP" for max compatibility.
68         grep "FIBMAP"
69 }
70
71 fiemap_work() {
72         # Wait for any running 'filefrag' subcommand before exitting so that
73         # after the test kills the subshell running this function, it does not
74         # fail with EBUSY when unmounting the scratch device because the filefrag
75         # subcommand is still running with an open file on the scratch fs.
76         trap "wait; exit" SIGTERM
77
78         filename=$1
79         while true; do
80                 $FILEFRAG_PROG $filename 2> $tmp.output 1> /dev/null
81                 ret=$?
82                 err=`cat $tmp.output | _filter_error`
83                 if [ $ret -ne 0 -o -n "$err" ]; then
84                         kill $dd_pid
85                         return 1
86                 fi
87         done
88 }
89
90 dd_work $testfile &
91 dd_pid=$!
92 fiemap_work $testfile &
93 fiemap_pid=$!
94 wait $dd_pid
95 ddret=$?
96 kill $fiemap_pid &> /dev/null
97 wait $fiemap_pid
98
99 if [ $ddret -ne 0 ]; then
100         echo "Extent merge bug detected"
101         status=1
102         exit
103 else
104         echo "Silence is golden"
105         status=0
106         exit
107 fi