4 # Test recovery of "lost" CoW blocks:
5 # - Use the debugger to fake a leftover CoW extent
6 # - See if mount/umount fixes it
8 #-----------------------------------------------------------------------
9 # Copyright (c) 2016, Oracle and/or its affiliates. All Rights Reserved.
11 # This program is free software; you can redistribute it and/or
12 # modify it under the terms of the GNU General Public License as
13 # published by the Free Software Foundation.
15 # This program is distributed in the hope that it would be useful,
16 # but WITHOUT ANY WARRANTY; without even the implied warranty of
17 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 # GNU General Public License for more details.
20 # You should have received a copy of the GNU General Public License
21 # along with this program; if not, write the Free Software Foundation,
22 # Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
23 #-----------------------------------------------------------------------
26 seqres=$RESULT_DIR/$seq
27 echo "QA output created by $seq"
31 status=1 # failure is the default!
32 trap "_cleanup; exit \$status" 0 1 2 3 15
40 # get standard environment, filters and checks
45 # real QA test starts here
48 _require_scratch_reflink
53 _scratch_mkfs > $seqres.full 2>&1
54 _scratch_mount >> $seqres.full
55 is_rmap=$(xfs_info $SCRATCH_MNT | grep -c "rmapbt=1")
62 xfs_db -c 'agf 1' "$@" -c "p $field" $SCRATCH_DEV | awk '{print $3}'
70 xfs_db -x -c 'agf 1' "$@" -c "write $field -- $value" $SCRATCH_DEV >> $seqres.full
77 xfs_db -c 'sb 0' "$@" -c "p $field" $SCRATCH_DEV | awk '{print $3}'
85 xfs_db -x -c 'sb 0' "$@" -c "write $field -- $value" $SCRATCH_DEV >> $seqres.full
89 grep "^leftover" | sed -e "s/[0-9]\+/NR/g"
94 xfs_db -c 'sb 0' -c p $SCRATCH_DEV
96 xfs_db -c 'agf 1' -c p $SCRATCH_DEV
98 xfs_db -c 'agf 1' -c 'addr refcntroot' -c p $SCRATCH_DEV
100 test $is_rmap -gt 0 && xfs_db -c 'agf 1' -c 'addr rmaproot' -c p $SCRATCH_DEV
102 xfs_db -c 'agf 1' -c 'addr bnoroot' -c p $SCRATCH_DEV
104 xfs_db -c 'agf 1' -c 'addr cntroot' -c p $SCRATCH_DEV
107 echo "We need AG1 to have a single free extent"
108 bno_lvl=$(_get_agf_data level -c 'addr bnoroot')
109 bno_nr=$(_get_agf_data numrecs -c 'addr bnoroot')
110 refc_lvl=$(_get_agf_data level -c 'addr refcntroot')
111 refc_nr=$(_get_agf_data numrecs -c 'addr refcntroot')
113 test $bno_lvl -eq 0 || echo " AG 1 bnobt must only have one level"
114 test $bno_nr -eq 1 || echo " AG 1 bnobt must only have one record"
115 test $refc_lvl -eq 0 || echo " AG 1 refcountbt must only have one level"
116 test $refc_nr -eq 0 || echo " AG 1 refcountbt must only have one record"
118 if [ $is_rmap -gt 0 ]; then
119 rmap_lvl=$(_get_agf_data level -c 'addr rmaproot')
120 rmap_nr=$(_get_agf_data numrecs -c 'addr rmaproot')
121 test $rmap_lvl -eq 0 || echo " AG 1 rmapbt must only have one level"
124 echo "Find our extent and old counter values"
125 bno=$(_get_agf_data "recs[1].startblock" -c 'addr bnoroot')
126 len=$(_get_agf_data "recs[1].blockcount" -c 'addr bnoroot')
127 agf_freeblks=$(_get_agf_data freeblks)
128 sb_fdblocks=$(_get_sb_data fdblocks)
130 test $len -ge 200 || echo " AG 1 doesn't have enough free blocks"
132 # Take the last 100 blocks of the free extent
134 debris_bno=$((bno + len - debris_len))
136 echo "Remove the extent from the freesp btrees"
137 _set_agf_data "recs[1].blockcount" $((len - debris_len)) -c 'addr bnoroot'
138 _set_agf_data "recs[1].blockcount" $((len - debris_len)) -c 'addr cntroot'
139 _set_agf_data freeblks $((agf_freeblks - debris_len))
140 _set_agf_data longest $((len - debris_len))
141 _set_sb_data fdblocks $((sb_fdblocks - debris_len))
143 echo "Add the extent to the refcount btree"
144 _set_agf_data numrecs 1 -c 'addr refcntroot'
145 _set_agf_data "recs[1].startblock" $debris_bno -c 'addr refcntroot'
146 _set_agf_data "recs[1].blockcount" $debris_len -c 'addr refcntroot'
147 _set_agf_data "recs[1].refcount" 1 -c 'addr refcntroot'
148 _set_agf_data "recs[1].cowflag" 1 -c 'addr refcntroot'
150 if [ $is_rmap -gt 0 ]; then
151 rmap_nr=$((rmap_nr + 1))
152 _set_agf_data numrecs $rmap_nr -c 'addr rmaproot'
153 _set_agf_data "recs[$rmap_nr].startblock" $debris_bno -c 'addr rmaproot'
154 _set_agf_data "recs[$rmap_nr].blockcount" $debris_len -c 'addr rmaproot'
155 _set_agf_data "recs[$rmap_nr].owner" -9 -c 'addr rmaproot'
156 _set_agf_data "recs[$rmap_nr].offset" 0 -c 'addr rmaproot'
159 _dump_status "broken fs config" >> $seqres.full
161 echo "Look for leftover warning in xfs_check"
162 _scratch_xfs_check | _filter_leftover
164 echo "Look for leftover warning in xfs_repair"
165 _scratch_xfs_repair -n 2>&1 | _filter_leftover
167 echo "Mount filesystem"
171 _dump_status "supposedly fixed fs config" >> $seqres.full
173 echo "Look for no more leftover warning in xfs_check"
174 _scratch_xfs_check | _filter_leftover
176 echo "Look for no more leftover warning in xfs_repair"
177 _scratch_xfs_repair -n 2>&1 | _filter_leftover