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
33 _require_scratch_reflink
34 _require_scratch_nocheck
36 _require_test_program "punch-alternating"
40 echo "Format and mount"
41 _scratch_mkfs -d agcount=1 > $seqres.full 2>&1
42 _scratch_mount >> $seqres.full 2>&1
44 testdir=$SCRATCH_MNT/test-$seq
49 echo "Create original files"
50 _pwrite_byte 0x61 0 $blksz $testdir/file1 >> $seqres.full
51 _cp_reflink $testdir/file1 $testdir/file2 >> $seqres.full
53 echo "Change reference count"
55 echo "set refcount to -4" >> $seqres.full
56 _scratch_xfs_db -x -c 'agf 0' -c 'addr refcntroot' -c 'write recs[1].refcount 4294967292' >> $seqres.full
57 echo "check refcount after setting to -4" >> $seqres.full
58 _scratch_xfs_db -c 'agf 0' -c 'addr refcntroot' -c 'p recs[1]' >> $seqres.full
59 _scratch_mount >> $seqres.full
61 echo "Reflink the overlinked file"
62 _cp_reflink $testdir/file1 $testdir/file3 >> $seqres.full
63 _cp_reflink $testdir/file1 $testdir/file4 >> $seqres.full
64 _cp_reflink $testdir/file1 $testdir/file5 >> $seqres.full
65 _cp_reflink $testdir/file1 $testdir/file6 >> $seqres.full
66 _cp_reflink $testdir/file1 $testdir/file7 >> $seqres.full
68 echo "Check scratch fs"
70 echo "check refcount after reflinking 5 more times" >> $seqres.full
71 _scratch_xfs_db -c 'agf 0' -c 'addr refcntroot' -c 'p recs[1]' >> $seqres.full
72 _scratch_mount >> $seqres.full
74 echo "CoW a couple files"
75 _pwrite_byte 0x62 0 $blksz $testdir/file3 >> $seqres.full
76 _pwrite_byte 0x62 0 $blksz $testdir/file5 >> $seqres.full
77 _pwrite_byte 0x62 0 $blksz $testdir/file7 >> $seqres.full
79 echo "Check scratch fs"
81 echo "check refcount after cowing 3 files" >> $seqres.full
82 _scratch_xfs_db -c 'agf 0' -c 'addr refcntroot' -c 'p recs[1]' >> $seqres.full
83 _scratch_mount >> $seqres.full
85 echo "Remove reflinked files"
88 echo "Check scratch fs"
90 echo "check refcount after removing all files" >> $seqres.full
91 _scratch_xfs_db -c 'agf 0' -c 'addr refcntroot' -c 'p recs[1]' >> $seqres.full
92 _scratch_xfs_repair -o force_geometry -n >> $seqres.full 2>&1
94 if [ $res -eq 0 ]; then
95 # If repair succeeds then format the device so that the post-test
96 # check doesn't fail due to the single AG.
97 _scratch_mkfs >> $seqres.full 2>&1
99 _fail "xfs_repair fails"