xfstests: remove _need_to_be_root
[xfstests-dev.git] / tests / btrfs / 017
1 #! /bin/bash
2 # FS QA Test No. 017
3 #
4 # Verify that removing shared extents can end up incorrect qgroup accounting.
5 #
6 # Regression of 'commit fcebe4562dec ("Btrfs: rework qgroup accounting")',
7 # this will throw a warning into dmesg.
8 #
9 # The issue is fixed by https://patchwork.kernel.org/patch/5499981/
10 # "Btrfs: fix a warning of qgroup account on shared extents"
11 #
12 #-----------------------------------------------------------------------
13 # Copyright (c) 2014 Liu Bo.  All Rights Reserved.
14 #
15 # This program is free software; you can redistribute it and/or
16 # modify it under the terms of the GNU General Public License as
17 # published by the Free Software Foundation.
18 #
19 # This program is distributed in the hope that it would be useful,
20 # but WITHOUT ANY WARRANTY; without even the implied warranty of
21 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
22 # GNU General Public License for more details.
23 #
24 # You should have received a copy of the GNU General Public License
25 # along with this program; if not, write the Free Software Foundation,
26 # Inc.,  51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
27 #-----------------------------------------------------------------------
28 #
29
30 seq=`basename $0`
31 seqres=$RESULT_DIR/$seq
32 echo "QA output created by $seq"
33
34 here=`pwd`
35 tmp=/tmp/$$
36 status=1        # failure is the default!
37 trap "_cleanup; exit \$status" 0 1 2 3 15
38
39 _cleanup()
40 {
41     cd /
42     rm -f $tmp.*
43 }
44
45 # get standard environment, filters and checks
46 . ./common/rc
47 . ./common/filter
48
49 # real QA test starts here
50
51 _supported_fs btrfs
52 _supported_os Linux
53 _require_scratch
54 _require_cloner
55
56 rm -f $seqres.full
57
58 # Currently in btrfs the node/leaf size can not be smaller than the page
59 # size (but it can be greater than the page size). So use the largest
60 # supported node/leaf size (64Kb) so that the test can run on any platform
61 # that Linux supports.
62 _scratch_mkfs "--nodesize 65536" >>$seqres.full 2>&1
63 _scratch_mount
64
65 BLOCK_SIZE=$(get_block_size $SCRATCH_MNT)
66 EXTENT_SIZE=$((2 * $BLOCK_SIZE))
67
68 $XFS_IO_PROG -f -d -c "pwrite 0 $EXTENT_SIZE" $SCRATCH_MNT/foo \
69         | _filter_xfs_io_blocks_modified
70
71 _run_btrfs_util_prog subvolume snapshot $SCRATCH_MNT $SCRATCH_MNT/snap
72
73 $CLONER_PROG -s 0 -d 0 -l $EXTENT_SIZE $SCRATCH_MNT/foo $SCRATCH_MNT/foo-reflink
74
75 $CLONER_PROG -s 0 -d 0 -l $EXTENT_SIZE $SCRATCH_MNT/foo \
76              $SCRATCH_MNT/snap/foo-reflink
77
78 $CLONER_PROG -s 0 -d 0 -l $EXTENT_SIZE $SCRATCH_MNT/foo \
79              $SCRATCH_MNT/snap/foo-reflink2
80
81 _run_btrfs_util_prog quota enable $SCRATCH_MNT
82 _run_btrfs_util_prog quota rescan -w $SCRATCH_MNT
83
84 rm -fr $SCRATCH_MNT/foo*
85 rm -fr $SCRATCH_MNT/snap/foo*
86
87 sync
88
89 units=`_btrfs_qgroup_units`
90 $BTRFS_UTIL_PROG qgroup show $units $SCRATCH_MNT | $AWK_PROG '/[0-9]/ {print $2" "$3}'
91
92 # success, all done
93 status=0
94 exit