xfstests: remove _need_to_be_root
[xfstests-dev.git] / tests / btrfs / 091
1 #! /bin/bash
2 # FS QA Test No. 091
3 #
4 # Test for incorrect exclusive reference count after cloning file
5 # between subvolumes.
6 #
7 #-----------------------------------------------------------------------
8 # Copyright (c) 2015 Fujitsu. All Rights Reserved.
9 #
10 # This program is free software; you can redistribute it and/or
11 # modify it under the terms of the GNU General Public License as
12 # published by the Free Software Foundation.
13 #
14 # This program is distributed in the hope that it would be useful,
15 # but WITHOUT ANY WARRANTY; without even the implied warranty of
16 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
17 # GNU General Public License for more details.
18 #
19 # You should have received a copy of the GNU General Public License
20 # along with this program; if not, write the Free Software Foundation,
21 # Inc.,  51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
22 #-----------------------------------------------------------------------
23 #
24
25 seq=`basename $0`
26 seqres=$RESULT_DIR/$seq
27 echo "QA output created by $seq"
28
29 here=`pwd`
30 tmp=/tmp/$$
31 status=1        # failure is the default!
32 trap "_cleanup; exit \$status" 0 1 2 3 15
33
34 _cleanup()
35 {
36     rm -f $tmp.*
37 }
38
39 # get standard environment, filters and checks
40 . ./common/rc
41 . ./common/filter
42 . ./common/reflink
43
44 # real QA test starts here
45
46 _supported_fs btrfs
47 _supported_os Linux
48 _require_scratch
49 _require_cp_reflink
50
51 rm -f $seqres.full
52
53 # use largest node/leaf size (64K) to allow the test to be run on arch with
54 # page size > 4k.
55 NODESIZE=65536
56 SUPPORT_NOINODE_CACHE="yes"
57
58 run_check _scratch_mkfs "--nodesize $NODESIZE"
59
60 # inode cache will also take space in fs tree, disable them to get consistent
61 # result.
62 # discard error output since we will check return value manually.
63 _scratch_mount "-o noinode_cache" 2> /dev/null
64
65 # Check for old kernel which doesn't support 'noinode_cache' mount option
66 if [ $? -ne 0 ]; then
67         support_noinode_cache="no"
68         run_check _scratch_mount
69 fi
70
71 _run_btrfs_util_prog subvolume create $SCRATCH_MNT/subv1
72 _run_btrfs_util_prog subvolume create $SCRATCH_MNT/subv2
73 _run_btrfs_util_prog subvolume create $SCRATCH_MNT/subv3
74
75 _run_btrfs_util_prog quota enable $SCRATCH_MNT
76 _run_btrfs_util_prog quota rescan -w $SCRATCH_MNT
77
78 # if we don't support noinode_cache mount option, then we should double check
79 # whether inode cache is enabled before executing the real test payload.
80 if [ $SUPPORT_NOINODE_CACHE == "no" ]; then
81         EMPTY_SIZE=`$BTRFS_UTIL_PROG qgroup show $units $SCRATCH_MNT | \
82                 $SED_PROG -n '/[0-9]/p' | $AWK_PROG '{print $2}' | head -n1`
83         if [ $EMPTY_SIZE != $NODESIZE ]; then
84                 _notrun "Kernel doesn't support to disable inode cache"
85         fi
86 fi
87
88 $XFS_IO_PROG -f -c "pwrite 0 256K" $SCRATCH_MNT/subv1/file1 | _filter_xfs_io
89 cp --reflink $SCRATCH_MNT/subv1/file1 $SCRATCH_MNT/subv2/file1
90 cp --reflink $SCRATCH_MNT/subv1/file1 $SCRATCH_MNT/subv3/file1
91
92 # Current btrfs use tree search ioctl to show quota, which will only show info
93 # in commit tree. So need to sync to update the qgroup commit tree.
94 sync
95
96 units=`_btrfs_qgroup_units`
97 $BTRFS_UTIL_PROG qgroup show $units $SCRATCH_MNT | $SED_PROG -n '/[0-9]/p' | \
98         $AWK_PROG '{print $2" "$3}'
99
100 # success, all done
101 status=0
102 exit