btrfs/079: fix failure to umount scratch fs due to running filefrag process
[xfstests-dev.git] / tests / btrfs / 102
1 #! /bin/bash
2 # SPDX-License-Identifier: GPL-2.0
3 # Copyright (C) 2015 SUSE Linux Products GmbH. All Rights Reserved.
4 #
5 # FSQA Test No. 102
6 #
7 # Regression test for an ENOSPC issue when attempting to write to a file in
8 # a filesystem without any data block groups allocated.
9 #
10 seq=`basename $0`
11 seqres=$RESULT_DIR/$seq
12 echo "QA output created by $seq"
13 tmp=/tmp/$$
14 status=1        # failure is the default!
15 trap "_cleanup; exit \$status" 0 1 2 3 15
16
17 _cleanup()
18 {
19         rm -f $tmp.*
20 }
21
22 # get standard environment, filters and checks
23 . ./common/rc
24 . ./common/filter
25
26 # real QA test starts here
27 _supported_fs btrfs
28 _supported_os Linux
29 _require_scratch
30
31 rm -f $seqres.full
32
33 _scratch_mkfs >>$seqres.full 2>&1
34
35 # Mount our filesystem without space caches enabled so that we do not get any
36 # space used from the initial data block group that mkfs creates (space caches
37 # used space from data block groups).
38 _scratch_mount "-o nospace_cache"
39
40 # Need an fs with at least 2Gb to make sure mkfs.btrfs does not create an fs
41 # using mixed block groups (used both for data and metadata). We really need
42 # to have dedicated block groups for data to reproduce the issue and mkfs.btrfs
43 # defaults to mixed block groups only for small filesystems (up to 1Gb).
44 _require_fs_space $SCRATCH_MNT $((2 * 1024 * 1024))
45
46 # Run balance with the purpose of deleting the unused data block group that
47 # mkfs created. We could also wait for the background kthread to automatically
48 # delete the unused block group, but we do not have a way to make it run and
49 # wait for it to complete, so just do a balance instead of some unreliable sleep
50 _run_btrfs_util_prog balance start -dusage=0 $SCRATCH_MNT
51
52 # Now unmount the filesystem, mount it again (either with or with space caches
53 # enabled, it does not matter to trigger the problem) and attempt to create a
54 # file with some data - this used to fail with ENOSPC because there were no
55 # data block groups when the filesystem was mounted and the data space info
56 # object was marked as full when initialized (because it had 0 total bytes),
57 # which prevented the file write path from attempting to allocate a data block
58 # group and fail immediately with ENOSPC.
59 _scratch_cycle_mount
60 echo "hello world" > $SCRATCH_MNT/foobar
61
62 echo "Silence is golden"
63 status=0
64 exit