fstests: convert remaining tests to SPDX license tags
[xfstests-dev.git] / tests / xfs / 179
1 #! /bin/bash
2 # SPDX-License-Identifier: GPL-2.0
3 # Copyright (c) 2016, Oracle and/or its affiliates.  All Rights Reserved.
4 #
5 # FS QA Test No. 179
6 #
7 # See how well reflink handles overflowing reflink counts.
8 #
9 seq=`basename $0`
10 seqres=$RESULT_DIR/$seq
11 echo "QA output created by $seq"
12
13 here=`pwd`
14 tmp=/tmp/$$
15 status=1    # failure is the default!
16 trap "_cleanup; exit \$status" 0 1 2 3 15
17
18 _cleanup()
19 {
20     cd /
21     rm -rf $tmp.*
22 }
23
24 # get standard environment, filters and checks
25 . ./common/rc
26 . ./common/filter
27 . ./common/attr
28 . ./common/reflink
29
30 # real QA test starts here
31 _supported_os Linux
32 _supported_fs xfs
33 _require_scratch_reflink
34 _require_scratch_nocheck
35 _require_cp_reflink
36 _require_test_program "punch-alternating"
37
38 rm -f $seqres.full
39
40 echo "Format and mount"
41 _scratch_mkfs -d agcount=1 > $seqres.full 2>&1
42 _scratch_mount >> $seqres.full 2>&1
43
44 testdir=$SCRATCH_MNT/test-$seq
45 mkdir $testdir
46
47 blksz=65536
48
49 echo "Create original files"
50 _pwrite_byte 0x61 0 $blksz $testdir/file1 >> $seqres.full
51 _cp_reflink $testdir/file1 $testdir/file2 >> $seqres.full
52
53 echo "Change reference count"
54 _scratch_unmount
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
60
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
67
68 echo "Check scratch fs"
69 _scratch_unmount
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
73
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
78
79 echo "Check scratch fs"
80 _scratch_unmount
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
84
85 echo "Remove reflinked files"
86 rm -rf $testdir/file*
87
88 echo "Check scratch fs"
89 _scratch_unmount
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
93 res=$?
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
98 else
99         _fail "xfs_repair fails"
100 fi
101
102 # success, all done
103 status=0
104 exit