7a33c6b7b578ba9d0d250b00766703f91ff26dbc
[xfstests-dev.git] / tests / btrfs / 102
1 #! /bin/bash
2 # FSQA Test No. 102
3 #
4 # Regression test for an ENOSPC issue when attempting to write to a file in
5 # a filesystem without any data block groups allocated.
6 #
7 #-----------------------------------------------------------------------
8 #
9 # Copyright (C) 2015 SUSE Linux Products GmbH. All Rights Reserved.
10 # Author: Filipe Manana <fdmanana@suse.com>
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 tmp=/tmp/$$
31 status=1        # failure is the default!
32 trap "_cleanup; exit \$status" 0 1 2 3 15
33
34 _cleanup()
35 {
36         rm -f $tmp.*
37 }
38
39 # get standard environment, filters and checks
40 . ./common/rc
41 . ./common/filter
42
43 # real QA test starts here
44 _supported_fs btrfs
45 _supported_os Linux
46 _require_scratch
47
48 rm -f $seqres.full
49
50 _scratch_mkfs >>$seqres.full 2>&1
51
52 # Mount our filesystem without space caches enabled so that we do not get any
53 # space used from the initial data block group that mkfs creates (space caches
54 # used space from data block groups).
55 _scratch_mount "-o nospace_cache"
56
57 # Need an fs with at least 2Gb to make sure mkfs.btrfs does not create an fs
58 # using mixed block groups (used both for data and metadata). We really need
59 # to have dedicated block groups for data to reproduce the issue and mkfs.btrfs
60 # defaults to mixed block groups only for small filesystems (up to 1Gb).
61 _require_fs_space $SCRATCH_MNT $((2 * 1024 * 1024))
62
63 # Run balance with the purpose of deleting the unused data block group that
64 # mkfs created. We could also wait for the background kthread to automatically
65 # delete the unused block group, but we do not have a way to make it run and
66 # wait for it to complete, so just do a balance instead of some unreliable sleep
67 _run_btrfs_util_prog balance start -dusage=0 $SCRATCH_MNT
68
69 # Now unmount the filesystem, mount it again (either with or with space caches
70 # enabled, it does not matter to trigger the problem) and attempt to create a
71 # file with some data - this used to fail with ENOSPC because there were no
72 # data block groups when the filesystem was mounted and the data space info
73 # object was marked as full when initialized (because it had 0 total bytes),
74 # which prevented the file write path from attempting to allocate a data block
75 # group and fail immediately with ENOSPC.
76 _scratch_cycle_mount
77 echo "hello world" > $SCRATCH_MNT/foobar
78
79 echo "Silence is golden"
80 status=0
81 exit