btrfs/057: Fix false alerts due to orphan files
[xfstests-dev.git] / tests / btrfs / 091
1 #! /bin/bash
2 # SPDX-License-Identifier: GPL-2.0
3 # Copyright (c) 2015 Fujitsu. All Rights Reserved.
4 #
5 # FS QA Test No. 091
6 #
7 # Test for incorrect exclusive reference count after cloning file
8 # between subvolumes.
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     rm -f $tmp.*
22 }
23
24 # get standard environment, filters and checks
25 . ./common/rc
26 . ./common/filter
27 . ./common/reflink
28
29 # real QA test starts here
30
31 _supported_fs btrfs
32 _supported_os Linux
33 _require_scratch
34 _require_cp_reflink
35
36 rm -f $seqres.full
37
38 # use largest node/leaf size (64K) to allow the test to be run on arch with
39 # page size > 4k.
40 NODESIZE=65536
41 SUPPORT_NOINODE_CACHE="yes"
42
43 run_check _scratch_mkfs "--nodesize $NODESIZE"
44
45 # inode cache will also take space in fs tree, disable them to get consistent
46 # result.
47 # discard error output since we will check return value manually.
48 # also disable all compression, or output will mismatch with golden output
49 _try_scratch_mount "-o noinode_cache,compress=no,compress-force=no" 2> /dev/null
50
51 # Check for old kernel which doesn't support 'noinode_cache' mount option
52 if [ $? -ne 0 ]; then
53         support_noinode_cache="no"
54         _scratch_mount
55 fi
56
57 _run_btrfs_util_prog subvolume create $SCRATCH_MNT/subv1
58 _run_btrfs_util_prog subvolume create $SCRATCH_MNT/subv2
59 _run_btrfs_util_prog subvolume create $SCRATCH_MNT/subv3
60
61 _run_btrfs_util_prog quota enable $SCRATCH_MNT
62 _run_btrfs_util_prog quota rescan -w $SCRATCH_MNT
63
64 # if we don't support noinode_cache mount option, then we should double check
65 # whether inode cache is enabled before executing the real test payload.
66 if [ $SUPPORT_NOINODE_CACHE == "no" ]; then
67         EMPTY_SIZE=`$BTRFS_UTIL_PROG qgroup show $units $SCRATCH_MNT | \
68                 $SED_PROG -n '/[0-9]/p' | $AWK_PROG '{print $2}' | head -n1`
69         if [ $EMPTY_SIZE != $NODESIZE ]; then
70                 _notrun "Kernel doesn't support to disable inode cache"
71         fi
72 fi
73
74 $XFS_IO_PROG -f -c "pwrite 0 256K" $SCRATCH_MNT/subv1/file1 | _filter_xfs_io
75 cp --reflink $SCRATCH_MNT/subv1/file1 $SCRATCH_MNT/subv2/file1
76 cp --reflink $SCRATCH_MNT/subv1/file1 $SCRATCH_MNT/subv3/file1
77
78 # Current btrfs use tree search ioctl to show quota, which will only show info
79 # in commit tree. So need to sync to update the qgroup commit tree.
80 sync
81
82 units=`_btrfs_qgroup_units`
83 $BTRFS_UTIL_PROG qgroup show $units $SCRATCH_MNT | $SED_PROG -n '/[0-9]/p' | \
84         $AWK_PROG '{print $2" "$3}'
85
86 # success, all done
87 status=0
88 exit