xfs: force file creation to the data device for certain layout tests
[xfstests-dev.git] / tests / btrfs / 193
1 #! /bin/bash
2 # SPDX-License-Identifier: GPL-2.0
3 # Copyright (C) 2019 SUSE Linux Products GmbH. All Rights Reserved.
4 #
5 # FS QA Test btrfs/193
6 #
7 # Test if btrfs is going to leak qgroup reserved data space when
8 # falloc on multiple holes fails.
9 # The fix is titled:
10 # "btrfs: qgroup: Fix the wrong target io_tree when freeing reserved data space"
11 #
12 seq=`basename $0`
13 seqres=$RESULT_DIR/$seq
14 echo "QA output created by $seq"
15
16 here=`pwd`
17 tmp=/tmp/$$
18 status=1        # failure is the default!
19 trap "_cleanup; exit \$status" 0 1 2 3 15
20
21 _cleanup()
22 {
23         cd /
24         rm -f $tmp.*
25 }
26
27 # get standard environment, filters and checks
28 . ./common/rc
29 . ./common/filter
30
31 # remove previous $seqres.full before test
32 rm -f $seqres.full
33
34 # real QA test starts here
35
36 # Modify as appropriate.
37 _supported_fs btrfs
38 _require_scratch
39 _require_xfs_io_command falloc
40
41 _scratch_mkfs > /dev/null
42 _scratch_mount
43
44 $BTRFS_UTIL_PROG quota enable "$SCRATCH_MNT" > /dev/null
45 $BTRFS_UTIL_PROG quota rescan -w "$SCRATCH_MNT" > /dev/null
46 $BTRFS_UTIL_PROG qgroup limit -e 256M "$SCRATCH_MNT"
47
48 # Create a file with the following layout:
49 # 0         128M      256M      384M
50 # |  Hole   |4K| Hole |4K| Hole |
51 # The total hole size will be 384M - 8k
52 truncate -s 384m "$SCRATCH_MNT/file"
53 $XFS_IO_PROG -c "pwrite 128m 4k" -c "pwrite 256m 4k" \
54         "$SCRATCH_MNT/file" | _filter_xfs_io
55
56 # Falloc 0~384M range, it's going to fail due to the qgroup limit
57 $XFS_IO_PROG -c "falloc 0 384m" "$SCRATCH_MNT/file" | _filter_xfs_io_error
58 rm -f "$SCRATCH_MNT/file"
59
60 # Ensure above delete reaches disk and free some space
61 sync
62
63 # We should be able to write at least 3/4 of the limit
64 $XFS_IO_PROG -f -c "pwrite 0 192m" "$SCRATCH_MNT/file" | _filter_xfs_io
65
66 # success, all done
67 status=0
68 exit