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 seqres=$RESULT_DIR/$seq
11 echo "QA output created by $seq"
15 status=1 # failure is the default!
16 trap "_cleanup; exit \$status" 0 1 2 3 15
24 # get standard environment, filters and checks
30 # real QA test starts here
32 _require_scratch_reflink
33 _require_scratch_nocheck
35 _require_test_program "punch-alternating"
39 echo "Format and mount"
40 _scratch_mkfs -d agcount=1 > $seqres.full 2>&1
41 _scratch_mount >> $seqres.full 2>&1
43 testdir=$SCRATCH_MNT/test-$seq
48 echo "Create original files"
49 _pwrite_byte 0x61 0 $blksz $testdir/file1 >> $seqres.full
50 _cp_reflink $testdir/file1 $testdir/file2 >> $seqres.full
52 echo "Change reference count"
54 echo "set refcount to -4" >> $seqres.full
55 _scratch_xfs_db -x -c 'agf 0' -c 'addr refcntroot' -c 'write recs[1].refcount 4294967292' >> $seqres.full
56 echo "check refcount after setting to -4" >> $seqres.full
57 _scratch_xfs_db -c 'agf 0' -c 'addr refcntroot' -c 'p recs[1]' >> $seqres.full
58 _scratch_mount >> $seqres.full
60 echo "Reflink the overlinked file"
61 _cp_reflink $testdir/file1 $testdir/file3 >> $seqres.full
62 _cp_reflink $testdir/file1 $testdir/file4 >> $seqres.full
63 _cp_reflink $testdir/file1 $testdir/file5 >> $seqres.full
64 _cp_reflink $testdir/file1 $testdir/file6 >> $seqres.full
65 _cp_reflink $testdir/file1 $testdir/file7 >> $seqres.full
67 echo "Check scratch fs"
69 echo "check refcount after reflinking 5 more times" >> $seqres.full
70 _scratch_xfs_db -c 'agf 0' -c 'addr refcntroot' -c 'p recs[1]' >> $seqres.full
71 _scratch_mount >> $seqres.full
73 echo "CoW a couple files"
74 _pwrite_byte 0x62 0 $blksz $testdir/file3 >> $seqres.full
75 _pwrite_byte 0x62 0 $blksz $testdir/file5 >> $seqres.full
76 _pwrite_byte 0x62 0 $blksz $testdir/file7 >> $seqres.full
78 echo "Check scratch fs"
80 echo "check refcount after cowing 3 files" >> $seqres.full
81 _scratch_xfs_db -c 'agf 0' -c 'addr refcntroot' -c 'p recs[1]' >> $seqres.full
82 _scratch_mount >> $seqres.full
84 echo "Remove reflinked files"
87 echo "Check scratch fs"
89 echo "check refcount after removing all files" >> $seqres.full
90 _scratch_xfs_db -c 'agf 0' -c 'addr refcntroot' -c 'p recs[1]' >> $seqres.full
91 _scratch_xfs_repair -o force_geometry -n >> $seqres.full 2>&1
93 if [ $res -eq 0 ]; then
94 # If repair succeeds then format the device so that the post-test
95 # check doesn't fail due to the single AG.
96 _scratch_mkfs >> $seqres.full 2>&1
98 _fail "xfs_repair fails"