blob: 98b01476c963288ace3d8ff9bd5b298ab0f53124 (
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
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
|
#! /bin/bash
# SPDX-License-Identifier: GPL-2.0
# Copyright (c) 2016, Oracle and/or its affiliates. All Rights Reserved.
#
# FS QA Test No. 179
#
# See how well reflink handles overflowing reflink counts.
#
. ./common/preamble
_begin_fstest auto quick clone
# Import common functions.
. ./common/filter
. ./common/attr
. ./common/reflink
# real QA test starts here
_supported_fs xfs
_require_scratch_reflink
_require_scratch_nocheck
_require_cp_reflink
_require_test_program "punch-alternating"
_fixed_by_kernel_commit b25d1984aa88 \
"xfs: estimate post-merge refcounts correctly"
echo "Format and mount"
_scratch_mkfs -d agcount=1 > $seqres.full 2>&1
_scratch_mount >> $seqres.full 2>&1
# This test modifies the refcount btree on the data device, so we must force
# rtinherit off so that the test files are created there.
_xfs_force_bdev data $SCRATCH_MNT
testdir=$SCRATCH_MNT/test-$seq
mkdir $testdir
# Set the file size to 10x the block size to guarantee that the COW writes will
# touch multiple blocks and exercise the refcount extent merging code. This is
# necessary to catch a bug in the refcount extent merging code that handles
# MAXREFCOUNT edge cases.
blksz=65536
filesz=$((blksz * 10))
echo "Create original files"
_pwrite_byte 0x61 0 $filesz $testdir/file1 >> $seqres.full
_cp_reflink $testdir/file1 $testdir/file2 >> $seqres.full
echo "Change reference count"
_scratch_unmount
echo "set refcount to -4" >> $seqres.full
_scratch_xfs_db -x -c 'agf 0' -c 'addr refcntroot' -c 'write recs[1].refcount 4294967292' >> $seqres.full
echo "check refcount after setting to -4" >> $seqres.full
_scratch_xfs_db -c 'agf 0' -c 'addr refcntroot' -c 'p recs[1]' >> $seqres.full
_scratch_mount >> $seqres.full
echo "Reflink the overlinked file"
_cp_reflink $testdir/file1 $testdir/file3 >> $seqres.full
_cp_reflink $testdir/file1 $testdir/file4 >> $seqres.full
_cp_reflink $testdir/file1 $testdir/file5 >> $seqres.full
_cp_reflink $testdir/file1 $testdir/file6 >> $seqres.full
_cp_reflink $testdir/file1 $testdir/file7 >> $seqres.full
echo "Check scratch fs"
_scratch_unmount
echo "check refcount after reflinking 5 more times" >> $seqres.full
_scratch_xfs_db -c 'agf 0' -c 'addr refcntroot' -c 'p recs[1]' >> $seqres.full
_scratch_mount >> $seqres.full
echo "CoW a couple files"
_pwrite_byte 0x62 0 $filesz $testdir/file3 >> $seqres.full
_pwrite_byte 0x62 0 $filesz $testdir/file5 >> $seqres.full
# For the last COW test, write single blocks at the start, middle, and end of
# the shared file to exercise a refcount btree update that targets a single
# block of the multiblock refcount record that we just modified.
#
# This trips a bug where XFS didn't correctly identify refcount record merge
# candidates when any of the records are pinned at MAXREFCOUNT. The bug was
# originally discovered by enabling fsdax + reflink, but the bug can be
# triggered by any COW that doesn't target the entire extent.
#
# The bug was fixed by kernel commit b25d1984aa88 ("xfs: estimate post-merge
# refcounts correctly")
_pwrite_byte 0x62 0 $blksz $testdir/file7 >> $seqres.full
_pwrite_byte 0x62 $((blksz * 4)) $blksz $testdir/file7 >> $seqres.full
_pwrite_byte 0x62 $((filesz - blksz)) $blksz $testdir/file7 >> $seqres.full
echo "Check scratch fs"
_scratch_unmount
echo "check refcount after cowing 3 files" >> $seqres.full
_scratch_xfs_db -c 'agf 0' -c 'addr refcntroot' -c 'p recs[1]' >> $seqres.full
_scratch_mount >> $seqres.full
echo "Remove reflinked files"
rm -rf $testdir/file*
echo "Check scratch fs"
_scratch_unmount
echo "check refcount after removing all files" >> $seqres.full
_scratch_xfs_db -c 'agf 0' -c 'addr refcntroot' -c 'p recs[1]' >> $seqres.full
_scratch_xfs_repair -o force_geometry -n >> $seqres.full 2>&1
res=$?
if [ $res -eq 0 ]; then
# If repair succeeds then format the device so that the post-test
# check doesn't fail due to the single AG.
_scratch_mkfs >> $seqres.full 2>&1
else
_fail "xfs_repair fails"
fi
# success, all done
status=0
exit
|