btrfs: Verify falloc on multiple holes won't leak qgroup reserved data space
[xfstests-dev.git] / tests / btrfs / 122
1 #! /bin/bash
2 # SPDX-License-Identifier: GPL-2.0
3 # Copyright (C) 2016 SUSE Linux Products GmbH. All Rights Reserved.
4 #
5 # FS QA Test No. btrfs/122
6 #
7 # Test that qgroup counts are valid after snapshot creation. This has
8 # been broken in btrfs since Linux v4.1
9 #
10 seq=`basename $0`
11 seqres=$RESULT_DIR/$seq
12 echo "QA output created by $seq"
13
14 here=`pwd`
15 tmp=/tmp/$$
16 status=1        # failure is the default!
17 trap "_cleanup; exit \$status" 0 1 2 3 15
18
19 _cleanup()
20 {
21         cd /
22         rm -f $tmp.*
23 }
24
25 # get standard environment, filters and checks
26 . ./common/rc
27 . ./common/filter
28
29 # remove previous $seqres.full before test
30 rm -f $seqres.full
31
32 # real QA test starts here
33 _supported_fs btrfs
34 _supported_os Linux
35 _require_scratch
36 _require_btrfs_qgroup_report
37
38 rm -f $seqres.full
39
40 # Force a small leaf size to make it easier to blow out our root
41 # subvolume tree
42 _scratch_mkfs "--nodesize 16384" >/dev/null
43 _scratch_mount
44 _run_btrfs_util_prog quota enable $SCRATCH_MNT
45
46 mkdir "$SCRATCH_MNT/snaps"
47
48 # First make some simple snapshots - the bug was initially reproduced like this
49 _run_btrfs_util_prog subvolume snapshot $SCRATCH_MNT "$SCRATCH_MNT/snaps/empty1"
50 _run_btrfs_util_prog subvolume snapshot $SCRATCH_MNT "$SCRATCH_MNT/snaps/empty2"
51
52 # This forces the fs tree out past level 0, adding at least one tree
53 # block which must be properly accounted for when we make our next
54 # snapshots.
55 mkdir "$SCRATCH_MNT/data"
56 for i in `seq 0 640`; do
57         $XFS_IO_PROG -f -c "pwrite 0 1M" "$SCRATCH_MNT/data/file$i" > /dev/null 2>&1
58 done
59
60 # Snapshot twice.
61 _run_btrfs_util_prog subvolume snapshot $SCRATCH_MNT "$SCRATCH_MNT/snaps/snap1"
62 _run_btrfs_util_prog subvolume snapshot $SCRATCH_MNT "$SCRATCH_MNT/snaps/snap2"
63
64 _scratch_unmount
65
66
67 # qgroup will be checked by fstest at _check_scratch_fs()
68 status=0
69 exit