btrfs: Check false ENOSPC bug caused by incorrect metadata reserve
[xfstests-dev.git] / tests / btrfs / 132
1 #! /bin/bash
2 # FS QA Test 132
3 #
4 # Check if false ENOSPC will happen when parallel buffer write happens
5 # The problem is caused by incorrect metadata reservation for any buffered
6 # write whose max extent size is not 128M (including compression and in-band
7 # dedupe).
8 #
9 #-----------------------------------------------------------------------
10 # Copyright (c) 2016 Fujitsu.  All Rights Reserved.
11 #
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.
15 #
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.
20 #
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
24 #-----------------------------------------------------------------------
25 #
26
27 seq=`basename $0`
28 seqres=$RESULT_DIR/$seq
29 echo "QA output created by $seq"
30
31 here=`pwd`
32 tmp=/tmp/$$
33 status=1        # failure is the default!
34 trap "_cleanup; exit \$status" 0 1 2 3 15
35
36 _cleanup()
37 {
38         cd /
39         rm -f $tmp.*
40         kill $pids &> /dev/null
41         wait
42 }
43
44 # get standard environment, filters and checks
45 . ./common/rc
46 . ./common/filter
47
48 # remove previous $seqres.full before test
49 rm -f $seqres.full
50
51 # real QA test starts here
52
53 # Modify as appropriate.
54 _supported_fs btrfs
55 _supported_os Linux
56 _require_scratch
57
58 # Use small filesystem to trigger the bug more easily
59 # It's highly recommened to run this test case with MKFS_OPTIONS="-n 64k"
60 # to further increase the possibility
61 # Since the false ENOSPC happens due to incorrect metadata reservation,
62 # larger nodesize and small fs will make it much easier to reproduce
63 _scratch_mkfs_sized $((512 * 1024 * 1024)) >> $seqres.full 2>&1
64
65 # Recommended to use MOUNT_OPTIONS="-o compress" to trigger the bug
66 _scratch_mount
67
68 sleep_time=$(($TIME_FACTOR * 30))
69 loop_writer()
70 {
71         offset=$1
72         len=$2
73         file=$3
74
75         while true; do
76                 # Only need stderr, and we need to specify small block size
77                 # but still large enough trigger compression
78                 $XFS_IO_PROG -c "pwrite -b 8K $offset $len" $file > /dev/null
79         done
80 }
81
82 touch $SCRATCH_MNT/testfile
83
84 # Start 2 writter writting into the same file
85 # The file is 142M, which is smaller than 1/2 of the filesystem,
86 # so no other cause can lead to ENOSPC.
87 loop_writer 0 128M $SCRATCH_MNT/testfile &
88 pids=$!
89 loop_writer 128M 16M $SCRATCH_MNT/testfile &
90 pids="$pids $!"
91
92 sleep $sleep_time
93
94 kill $pids
95 wait
96
97 # Sync the fs to avoid EBUSY while umount, which is quite common for btrfs
98 # compression
99 sync
100
101 echo "Silence is golden"
102 status=0
103 exit