xfs: Check for extent overflow when trivally adding a new extent
[xfstests-dev.git] / tests / btrfs / 017
1 #! /bin/bash
2 # SPDX-License-Identifier: GPL-2.0
3 # Copyright (c) 2014 Liu Bo.  All Rights Reserved.
4 #
5 # FS QA Test No. 017
6 #
7 # Verify that removing shared extents can end up incorrect qgroup accounting.
8 #
9 # Regression of 'commit fcebe4562dec ("Btrfs: rework qgroup accounting")',
10 # this will throw a warning into dmesg.
11 #
12 # The issue is fixed by https://patchwork.kernel.org/patch/5499981/
13 # "Btrfs: fix a warning of qgroup account on shared extents"
14 #
15 seq=`basename $0`
16 seqres=$RESULT_DIR/$seq
17 echo "QA output created by $seq"
18
19 here=`pwd`
20 tmp=/tmp/$$
21 status=1        # failure is the default!
22 trap "_cleanup; exit \$status" 0 1 2 3 15
23
24 _cleanup()
25 {
26     cd /
27     rm -f $tmp.*
28 }
29
30 # get standard environment, filters and checks
31 . ./common/rc
32 . ./common/filter
33
34 # real QA test starts here
35
36 _supported_fs btrfs
37 _require_scratch
38 _require_cloner
39
40 rm -f $seqres.full
41
42 # Currently in btrfs the node/leaf size can not be smaller than the page
43 # size (but it can be greater than the page size). So use the largest
44 # supported node/leaf size (64Kb) so that the test can run on any platform
45 # that Linux supports.
46 _scratch_mkfs "--nodesize 65536" >>$seqres.full 2>&1
47 _scratch_mount
48
49 BLOCK_SIZE=$(_get_block_size $SCRATCH_MNT)
50 EXTENT_SIZE=$((2 * $BLOCK_SIZE))
51
52 $XFS_IO_PROG -f -d -c "pwrite 0 $EXTENT_SIZE" $SCRATCH_MNT/foo \
53         | _filter_xfs_io_blocks_modified
54
55 _run_btrfs_util_prog subvolume snapshot $SCRATCH_MNT $SCRATCH_MNT/snap
56
57 $CLONER_PROG -s 0 -d 0 -l $EXTENT_SIZE $SCRATCH_MNT/foo $SCRATCH_MNT/foo-reflink
58
59 $CLONER_PROG -s 0 -d 0 -l $EXTENT_SIZE $SCRATCH_MNT/foo \
60              $SCRATCH_MNT/snap/foo-reflink
61
62 $CLONER_PROG -s 0 -d 0 -l $EXTENT_SIZE $SCRATCH_MNT/foo \
63              $SCRATCH_MNT/snap/foo-reflink2
64
65 _run_btrfs_util_prog quota enable $SCRATCH_MNT
66 _run_btrfs_util_prog quota rescan -w $SCRATCH_MNT
67
68 rm -fr $SCRATCH_MNT/foo*
69 rm -fr $SCRATCH_MNT/snap/foo*
70
71 sync
72
73 units=`_btrfs_qgroup_units`
74 $BTRFS_UTIL_PROG qgroup show $units $SCRATCH_MNT | $AWK_PROG '/[0-9]/ {print $2" "$3}'
75
76 # success, all done
77 status=0
78 exit