summaryrefslogtreecommitdiff
path: root/tests/btrfs/091
blob: 6d2a23c80e9f9eed038058b48e3d669a4edd825d (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
#! /bin/bash
# SPDX-License-Identifier: GPL-2.0
# Copyright (c) 2015 Fujitsu. All Rights Reserved.
#
# FS QA Test No. 091
#
# Test for incorrect exclusive reference count after cloning file
# between subvolumes.
#
seq=`basename $0`
seqres=$RESULT_DIR/$seq
echo "QA output created by $seq"

here=`pwd`
tmp=/tmp/$$
status=1	# failure is the default!
trap "_cleanup; exit \$status" 0 1 2 3 15

_cleanup()
{
    rm -f $tmp.*
}

# get standard environment, filters and checks
. ./common/rc
. ./common/filter
. ./common/reflink

# real QA test starts here

_supported_fs btrfs
_supported_os Linux
_require_scratch
_require_cp_reflink

rm -f $seqres.full

# use largest node/leaf size (64K) to allow the test to be run on arch with
# page size > 4k.
NODESIZE=65536
SUPPORT_NOINODE_CACHE="yes"

run_check _scratch_mkfs "--nodesize $NODESIZE"

# inode cache will also take space in fs tree, disable them to get consistent
# result.
# discard error output since we will check return value manually.
# also disable all compression, or output will mismatch with golden output
_try_scratch_mount "-o noinode_cache,compress=no,compress-force=no" 2> /dev/null

# Check for old kernel which doesn't support 'noinode_cache' mount option
if [ $? -ne 0 ]; then
	support_noinode_cache="no"
	_scratch_mount
fi

_run_btrfs_util_prog subvolume create $SCRATCH_MNT/subv1
_run_btrfs_util_prog subvolume create $SCRATCH_MNT/subv2
_run_btrfs_util_prog subvolume create $SCRATCH_MNT/subv3

_run_btrfs_util_prog quota enable $SCRATCH_MNT
_run_btrfs_util_prog quota rescan -w $SCRATCH_MNT

# if we don't support noinode_cache mount option, then we should double check
# whether inode cache is enabled before executing the real test payload.
if [ $SUPPORT_NOINODE_CACHE == "no" ]; then
	EMPTY_SIZE=`$BTRFS_UTIL_PROG qgroup show $units $SCRATCH_MNT | \
		$SED_PROG -n '/[0-9]/p' | $AWK_PROG '{print $2}' | head -n1`
	if [ $EMPTY_SIZE != $NODESIZE ]; then
		_notrun "Kernel doesn't support to disable inode cache"
	fi
fi

$XFS_IO_PROG -f -c "pwrite 0 256K" $SCRATCH_MNT/subv1/file1 | _filter_xfs_io
cp --reflink $SCRATCH_MNT/subv1/file1 $SCRATCH_MNT/subv2/file1
cp --reflink $SCRATCH_MNT/subv1/file1 $SCRATCH_MNT/subv3/file1

# Current btrfs use tree search ioctl to show quota, which will only show info
# in commit tree. So need to sync to update the qgroup commit tree.
sync

units=`_btrfs_qgroup_units`
$BTRFS_UTIL_PROG qgroup show $units $SCRATCH_MNT | $SED_PROG -n '/[0-9]/p' | \
	$AWK_PROG '{print $2" "$3}'

# success, all done
status=0
exit