2 # SPDX-License-Identifier: GPL-2.0
3 # Copyright (c) 2016, Oracle and/or its affiliates. All Rights Reserved.
7 # See how well reflink handles overflowing reflink counts.
10 _begin_fstest auto quick clone
12 # Import common functions.
17 # real QA test starts here
19 _require_scratch_reflink
20 _require_scratch_nocheck
22 _require_test_program "punch-alternating"
24 echo "Format and mount"
25 _scratch_mkfs -d agcount=1 > $seqres.full 2>&1
26 _scratch_mount >> $seqres.full 2>&1
28 testdir=$SCRATCH_MNT/test-$seq
33 echo "Create original files"
34 _pwrite_byte 0x61 0 $blksz $testdir/file1 >> $seqres.full
35 _cp_reflink $testdir/file1 $testdir/file2 >> $seqres.full
37 echo "Change reference count"
39 echo "set refcount to -4" >> $seqres.full
40 _scratch_xfs_db -x -c 'agf 0' -c 'addr refcntroot' -c 'write recs[1].refcount 4294967292' >> $seqres.full
41 echo "check refcount after setting to -4" >> $seqres.full
42 _scratch_xfs_db -c 'agf 0' -c 'addr refcntroot' -c 'p recs[1]' >> $seqres.full
43 _scratch_mount >> $seqres.full
45 echo "Reflink the overlinked file"
46 _cp_reflink $testdir/file1 $testdir/file3 >> $seqres.full
47 _cp_reflink $testdir/file1 $testdir/file4 >> $seqres.full
48 _cp_reflink $testdir/file1 $testdir/file5 >> $seqres.full
49 _cp_reflink $testdir/file1 $testdir/file6 >> $seqres.full
50 _cp_reflink $testdir/file1 $testdir/file7 >> $seqres.full
52 echo "Check scratch fs"
54 echo "check refcount after reflinking 5 more times" >> $seqres.full
55 _scratch_xfs_db -c 'agf 0' -c 'addr refcntroot' -c 'p recs[1]' >> $seqres.full
56 _scratch_mount >> $seqres.full
58 echo "CoW a couple files"
59 _pwrite_byte 0x62 0 $blksz $testdir/file3 >> $seqres.full
60 _pwrite_byte 0x62 0 $blksz $testdir/file5 >> $seqres.full
61 _pwrite_byte 0x62 0 $blksz $testdir/file7 >> $seqres.full
63 echo "Check scratch fs"
65 echo "check refcount after cowing 3 files" >> $seqres.full
66 _scratch_xfs_db -c 'agf 0' -c 'addr refcntroot' -c 'p recs[1]' >> $seqres.full
67 _scratch_mount >> $seqres.full
69 echo "Remove reflinked files"
72 echo "Check scratch fs"
74 echo "check refcount after removing all files" >> $seqres.full
75 _scratch_xfs_db -c 'agf 0' -c 'addr refcntroot' -c 'p recs[1]' >> $seqres.full
76 _scratch_xfs_repair -o force_geometry -n >> $seqres.full 2>&1
78 if [ $res -eq 0 ]; then
79 # If repair succeeds then format the device so that the post-test
80 # check doesn't fail due to the single AG.
81 _scratch_mkfs >> $seqres.full 2>&1
83 _fail "xfs_repair fails"