Skip to content

Commit 4ce0c71

Browse files
Christoph HellwigDarrick J. Wong
authored andcommitted
xfs: consolidate btree block verification
Add a __xfs_btree_check_block helper that can be called by the scrub code to validate a btree block of any form, and move the duplicate error handling code from xfs_btree_check_sblock and xfs_btree_check_lblock into xfs_btree_check_block and thus remove these two helpers. Signed-off-by: Christoph Hellwig <hch@lst.de> Reviewed-by: Darrick J. Wong <djwong@kernel.org> Signed-off-by: Darrick J. Wong <djwong@kernel.org>
1 parent d477f17 commit 4ce0c71

3 files changed

Lines changed: 32 additions & 58 deletions

File tree

fs/xfs/libxfs/xfs_btree.c

Lines changed: 30 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,7 @@ xfs_btree_check_sblock_siblings(
9898
* Check a long btree block header. Return the address of the failing check,
9999
* or NULL if everything is ok.
100100
*/
101-
xfs_failaddr_t
101+
static xfs_failaddr_t
102102
__xfs_btree_check_lblock(
103103
struct xfs_btree_cur *cur,
104104
struct xfs_btree_block *block,
@@ -147,33 +147,11 @@ __xfs_btree_check_lblock(
147147
return fa;
148148
}
149149

150-
/* Check a long btree block header. */
151-
static int
152-
xfs_btree_check_lblock(
153-
struct xfs_btree_cur *cur,
154-
struct xfs_btree_block *block,
155-
int level,
156-
struct xfs_buf *bp)
157-
{
158-
struct xfs_mount *mp = cur->bc_mp;
159-
xfs_failaddr_t fa;
160-
161-
fa = __xfs_btree_check_lblock(cur, block, level, bp);
162-
if (XFS_IS_CORRUPT(mp, fa != NULL) ||
163-
XFS_TEST_ERROR(false, mp, XFS_ERRTAG_BTREE_CHECK_LBLOCK)) {
164-
if (bp)
165-
trace_xfs_btree_corrupt(bp, _RET_IP_);
166-
xfs_btree_mark_sick(cur);
167-
return -EFSCORRUPTED;
168-
}
169-
return 0;
170-
}
171-
172150
/*
173151
* Check a short btree block header. Return the address of the failing check,
174152
* or NULL if everything is ok.
175153
*/
176-
xfs_failaddr_t
154+
static xfs_failaddr_t
177155
__xfs_btree_check_sblock(
178156
struct xfs_btree_cur *cur,
179157
struct xfs_btree_block *block,
@@ -209,26 +187,28 @@ __xfs_btree_check_sblock(
209187
return fa;
210188
}
211189

212-
/* Check a short btree block header. */
213-
STATIC int
214-
xfs_btree_check_sblock(
190+
/*
191+
* Internal btree block check.
192+
*
193+
* Return NULL if the block is ok or the address of the failed check otherwise.
194+
*/
195+
xfs_failaddr_t
196+
__xfs_btree_check_block(
215197
struct xfs_btree_cur *cur,
216198
struct xfs_btree_block *block,
217199
int level,
218200
struct xfs_buf *bp)
219201
{
220-
struct xfs_mount *mp = cur->bc_mp;
221-
xfs_failaddr_t fa;
202+
if (cur->bc_ops->ptr_len == XFS_BTREE_SHORT_PTR_LEN)
203+
return __xfs_btree_check_sblock(cur, block, level, bp);
204+
return __xfs_btree_check_lblock(cur, block, level, bp);
205+
}
222206

223-
fa = __xfs_btree_check_sblock(cur, block, level, bp);
224-
if (XFS_IS_CORRUPT(mp, fa != NULL) ||
225-
XFS_TEST_ERROR(false, mp, XFS_ERRTAG_BTREE_CHECK_SBLOCK)) {
226-
if (bp)
227-
trace_xfs_btree_corrupt(bp, _RET_IP_);
228-
xfs_btree_mark_sick(cur);
229-
return -EFSCORRUPTED;
230-
}
231-
return 0;
207+
static inline unsigned int xfs_btree_block_errtag(struct xfs_btree_cur *cur)
208+
{
209+
if (cur->bc_ops->ptr_len == XFS_BTREE_SHORT_PTR_LEN)
210+
return XFS_ERRTAG_BTREE_CHECK_SBLOCK;
211+
return XFS_ERRTAG_BTREE_CHECK_LBLOCK;
232212
}
233213

234214
/*
@@ -241,10 +221,18 @@ xfs_btree_check_block(
241221
int level, /* level of the btree block */
242222
struct xfs_buf *bp) /* buffer containing block, if any */
243223
{
244-
if (cur->bc_ops->ptr_len == XFS_BTREE_LONG_PTR_LEN)
245-
return xfs_btree_check_lblock(cur, block, level, bp);
246-
else
247-
return xfs_btree_check_sblock(cur, block, level, bp);
224+
struct xfs_mount *mp = cur->bc_mp;
225+
xfs_failaddr_t fa;
226+
227+
fa = __xfs_btree_check_block(cur, block, level, bp);
228+
if (XFS_IS_CORRUPT(mp, fa != NULL) ||
229+
XFS_TEST_ERROR(false, mp, xfs_btree_block_errtag(cur))) {
230+
if (bp)
231+
trace_xfs_btree_corrupt(bp, _RET_IP_);
232+
xfs_btree_mark_sick(cur);
233+
return -EFSCORRUPTED;
234+
}
235+
return 0;
248236
}
249237

250238
int

fs/xfs/libxfs/xfs_btree.h

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -334,15 +334,8 @@ xfs_btree_cur_sizeof(unsigned int nlevels)
334334
*/
335335
#define XFS_BUF_TO_BLOCK(bp) ((struct xfs_btree_block *)((bp)->b_addr))
336336

337-
/*
338-
* Internal long and short btree block checks. They return NULL if the
339-
* block is ok or the address of the failed check otherwise.
340-
*/
341-
xfs_failaddr_t __xfs_btree_check_lblock(struct xfs_btree_cur *cur,
337+
xfs_failaddr_t __xfs_btree_check_block(struct xfs_btree_cur *cur,
342338
struct xfs_btree_block *block, int level, struct xfs_buf *bp);
343-
xfs_failaddr_t __xfs_btree_check_sblock(struct xfs_btree_cur *cur,
344-
struct xfs_btree_block *block, int level, struct xfs_buf *bp);
345-
346339
int __xfs_btree_check_ptr(struct xfs_btree_cur *cur,
347340
const union xfs_btree_ptr *ptr, int index, int level);
348341

fs/xfs/scrub/btree.c

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -584,7 +584,6 @@ xchk_btree_get_block(
584584
struct xfs_btree_block **pblock,
585585
struct xfs_buf **pbp)
586586
{
587-
xfs_failaddr_t failed_at;
588587
int error;
589588

590589
*pblock = NULL;
@@ -596,13 +595,7 @@ xchk_btree_get_block(
596595
return error;
597596

598597
xfs_btree_get_block(bs->cur, level, pbp);
599-
if (bs->cur->bc_ops->ptr_len == XFS_BTREE_LONG_PTR_LEN)
600-
failed_at = __xfs_btree_check_lblock(bs->cur, *pblock,
601-
level, *pbp);
602-
else
603-
failed_at = __xfs_btree_check_sblock(bs->cur, *pblock,
604-
level, *pbp);
605-
if (failed_at) {
598+
if (__xfs_btree_check_block(bs->cur, *pblock, level, *pbp)) {
606599
xchk_btree_set_corrupt(bs->sc, bs->cur, level);
607600
return 0;
608601
}

0 commit comments

Comments
 (0)