common/rc: factor out _scratch_xfs_[get|set]_sb_field
[xfstests-dev.git] / tests / xfs / 179
1 #! /bin/bash
2 # FS QA Test No. 179
3 #
4 # See how well reflink handles overflowing reflink counts.
5 #
6 #-----------------------------------------------------------------------
7 # Copyright (c) 2016, Oracle and/or its affiliates.  All Rights Reserved.
8 #
9 # This program is free software; you can redistribute it and/or
10 # modify it under the terms of the GNU General Public License as
11 # published by the Free Software Foundation.
12 #
13 # This program is distributed in the hope that it would be useful,
14 # but WITHOUT ANY WARRANTY; without even the implied warranty of
15 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
16 # GNU General Public License for more details.
17 #
18 # You should have received a copy of the GNU General Public License
19 # along with this program; if not, write the Free Software Foundation,
20 # Inc.,  51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
21 #-----------------------------------------------------------------------
22
23 seq=`basename $0`
24 seqres=$RESULT_DIR/$seq
25 echo "QA output created by $seq"
26
27 here=`pwd`
28 tmp=/tmp/$$
29 status=1    # failure is the default!
30 trap "_cleanup; exit \$status" 0 1 2 3 15
31
32 _cleanup()
33 {
34     cd /
35     rm -rf $tmp.*
36 }
37
38 # get standard environment, filters and checks
39 . ./common/rc
40 . ./common/filter
41 . ./common/attr
42 . ./common/reflink
43
44 # real QA test starts here
45 _supported_os Linux
46 _supported_fs xfs
47 _require_scratch_reflink
48 _require_scratch_nocheck
49 _require_cp_reflink
50 _require_test_program "punch-alternating"
51
52 rm -f $seqres.full
53
54 echo "Format and mount"
55 _scratch_mkfs -d agcount=1 > $seqres.full 2>&1
56 _scratch_mount >> $seqres.full 2>&1
57
58 testdir=$SCRATCH_MNT/test-$seq
59 mkdir $testdir
60
61 blksz=65536
62
63 echo "Create original files"
64 _pwrite_byte 0x61 0 $blksz $testdir/file1 >> $seqres.full
65 _cp_reflink $testdir/file1 $testdir/file2 >> $seqres.full
66
67 echo "Change reference count"
68 _scratch_unmount
69 echo "set refcount to -4" >> $seqres.full
70 _scratch_xfs_db -x -c 'agf 0' -c 'addr refcntroot' -c 'write recs[1].refcount 4294967292' >> $seqres.full
71 echo "check refcount after setting to -4" >> $seqres.full
72 _scratch_xfs_db -c 'agf 0' -c 'addr refcntroot' -c 'p recs[1]' >> $seqres.full
73 _scratch_mount >> $seqres.full
74
75 echo "Reflink the overlinked file"
76 _cp_reflink $testdir/file1 $testdir/file3 >> $seqres.full
77 _cp_reflink $testdir/file1 $testdir/file4 >> $seqres.full
78 _cp_reflink $testdir/file1 $testdir/file5 >> $seqres.full
79 _cp_reflink $testdir/file1 $testdir/file6 >> $seqres.full
80 _cp_reflink $testdir/file1 $testdir/file7 >> $seqres.full
81
82 echo "Check scratch fs"
83 _scratch_unmount
84 echo "check refcount after reflinking 5 more times" >> $seqres.full
85 _scratch_xfs_db -c 'agf 0' -c 'addr refcntroot' -c 'p recs[1]' >> $seqres.full
86 _scratch_mount >> $seqres.full
87
88 echo "CoW a couple files"
89 _pwrite_byte 0x62 0 $blksz $testdir/file3 >> $seqres.full
90 _pwrite_byte 0x62 0 $blksz $testdir/file5 >> $seqres.full
91 _pwrite_byte 0x62 0 $blksz $testdir/file7 >> $seqres.full
92
93 echo "Check scratch fs"
94 _scratch_unmount
95 echo "check refcount after cowing 3 files" >> $seqres.full
96 _scratch_xfs_db -c 'agf 0' -c 'addr refcntroot' -c 'p recs[1]' >> $seqres.full
97 _scratch_mount >> $seqres.full
98
99 echo "Remove reflinked files"
100 rm -rf $testdir/file*
101
102 echo "Check scratch fs"
103 _scratch_unmount
104 echo "check refcount after removing all files" >> $seqres.full
105 _scratch_xfs_db -c 'agf 0' -c 'addr refcntroot' -c 'p recs[1]' >> $seqres.full
106 _scratch_xfs_repair -o force_geometry -n >> $seqres.full 2>&1
107 res=$?
108 if [ $res -eq 0 ]; then
109         # If repair succeeds then format the device so that the post-test
110         # check doesn't fail due to the single AG.
111         _scratch_mkfs >> $seqres.full 2>&1
112 else
113         _fail "xfs_repair fails"
114 fi
115
116 # success, all done
117 status=0
118 exit