Skip to content

Commit efa7a99

Browse files
committed
xfs: scrub free space btrees
Check the extent records free space btrees to ensure that the values look sane. Signed-off-by: Darrick J. Wong <darrick.wong@oracle.com> Reviewed-by: Dave Chinner <dchinner@redhat.com>
1 parent a12890a commit efa7a99

File tree

7 files changed

+138
-1
lines changed

7 files changed

+138
-1
lines changed

fs/xfs/Makefile

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -144,6 +144,7 @@ ifeq ($(CONFIG_XFS_ONLINE_SCRUB),y)
144144
xfs-y += $(addprefix scrub/, \
145145
trace.o \
146146
agheader.o \
147+
alloc.o \
147148
btree.o \
148149
common.o \
149150
scrub.o \

fs/xfs/libxfs/xfs_fs.h

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -488,9 +488,11 @@ struct xfs_scrub_metadata {
488488
#define XFS_SCRUB_TYPE_AGF 2 /* AG free header */
489489
#define XFS_SCRUB_TYPE_AGFL 3 /* AG free list */
490490
#define XFS_SCRUB_TYPE_AGI 4 /* AG inode header */
491+
#define XFS_SCRUB_TYPE_BNOBT 5 /* freesp by block btree */
492+
#define XFS_SCRUB_TYPE_CNTBT 6 /* freesp by length btree */
491493

492494
/* Number of scrub subcommands. */
493-
#define XFS_SCRUB_TYPE_NR 5
495+
#define XFS_SCRUB_TYPE_NR 7
494496

495497
/* i: Repair this metadata. */
496498
#define XFS_SCRUB_IFLAG_REPAIR (1 << 0)

fs/xfs/scrub/alloc.c

Lines changed: 102 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,102 @@
1+
/*
2+
* Copyright (C) 2017 Oracle. All Rights Reserved.
3+
*
4+
* Author: Darrick J. Wong <darrick.wong@oracle.com>
5+
*
6+
* This program is free software; you can redistribute it and/or
7+
* modify it under the terms of the GNU General Public License
8+
* as published by the Free Software Foundation; either version 2
9+
* of the License, or (at your option) any later version.
10+
*
11+
* This program is distributed in the hope that it would be useful,
12+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
13+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14+
* GNU General Public License for more details.
15+
*
16+
* You should have received a copy of the GNU General Public License
17+
* along with this program; if not, write the Free Software Foundation,
18+
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA.
19+
*/
20+
#include "xfs.h"
21+
#include "xfs_fs.h"
22+
#include "xfs_shared.h"
23+
#include "xfs_format.h"
24+
#include "xfs_trans_resv.h"
25+
#include "xfs_mount.h"
26+
#include "xfs_defer.h"
27+
#include "xfs_btree.h"
28+
#include "xfs_bit.h"
29+
#include "xfs_log_format.h"
30+
#include "xfs_trans.h"
31+
#include "xfs_sb.h"
32+
#include "xfs_alloc.h"
33+
#include "xfs_rmap.h"
34+
#include "scrub/xfs_scrub.h"
35+
#include "scrub/scrub.h"
36+
#include "scrub/common.h"
37+
#include "scrub/btree.h"
38+
#include "scrub/trace.h"
39+
40+
/*
41+
* Set us up to scrub free space btrees.
42+
*/
43+
int
44+
xfs_scrub_setup_ag_allocbt(
45+
struct xfs_scrub_context *sc,
46+
struct xfs_inode *ip)
47+
{
48+
return xfs_scrub_setup_ag_btree(sc, ip, false);
49+
}
50+
51+
/* Free space btree scrubber. */
52+
53+
/* Scrub a bnobt/cntbt record. */
54+
STATIC int
55+
xfs_scrub_allocbt_rec(
56+
struct xfs_scrub_btree *bs,
57+
union xfs_btree_rec *rec)
58+
{
59+
struct xfs_mount *mp = bs->cur->bc_mp;
60+
xfs_agnumber_t agno = bs->cur->bc_private.a.agno;
61+
xfs_agblock_t bno;
62+
xfs_extlen_t len;
63+
int error = 0;
64+
65+
bno = be32_to_cpu(rec->alloc.ar_startblock);
66+
len = be32_to_cpu(rec->alloc.ar_blockcount);
67+
68+
if (bno + len <= bno ||
69+
!xfs_verify_agbno(mp, agno, bno) ||
70+
!xfs_verify_agbno(mp, agno, bno + len - 1))
71+
xfs_scrub_btree_set_corrupt(bs->sc, bs->cur, 0);
72+
73+
return error;
74+
}
75+
76+
/* Scrub the freespace btrees for some AG. */
77+
STATIC int
78+
xfs_scrub_allocbt(
79+
struct xfs_scrub_context *sc,
80+
xfs_btnum_t which)
81+
{
82+
struct xfs_owner_info oinfo;
83+
struct xfs_btree_cur *cur;
84+
85+
xfs_rmap_ag_owner(&oinfo, XFS_RMAP_OWN_AG);
86+
cur = which == XFS_BTNUM_BNO ? sc->sa.bno_cur : sc->sa.cnt_cur;
87+
return xfs_scrub_btree(sc, cur, xfs_scrub_allocbt_rec, &oinfo, NULL);
88+
}
89+
90+
int
91+
xfs_scrub_bnobt(
92+
struct xfs_scrub_context *sc)
93+
{
94+
return xfs_scrub_allocbt(sc, XFS_BTNUM_BNO);
95+
}
96+
97+
int
98+
xfs_scrub_cntbt(
99+
struct xfs_scrub_context *sc)
100+
{
101+
return xfs_scrub_allocbt(sc, XFS_BTNUM_CNT);
102+
}

fs/xfs/scrub/common.c

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -443,3 +443,19 @@ xfs_scrub_setup_fs(
443443
{
444444
return xfs_scrub_trans_alloc(sc->sm, sc->mp, &sc->tp);
445445
}
446+
447+
/* Set us up with AG headers and btree cursors. */
448+
int
449+
xfs_scrub_setup_ag_btree(
450+
struct xfs_scrub_context *sc,
451+
struct xfs_inode *ip,
452+
bool force_log)
453+
{
454+
int error;
455+
456+
error = xfs_scrub_setup_ag_header(sc, ip);
457+
if (error)
458+
return error;
459+
460+
return xfs_scrub_ag_init(sc, sc->sm->sm_agno, &sc->sa);
461+
}

fs/xfs/scrub/common.h

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,9 @@ void xfs_scrub_set_incomplete(struct xfs_scrub_context *sc);
7878
int xfs_scrub_setup_fs(struct xfs_scrub_context *sc, struct xfs_inode *ip);
7979
int xfs_scrub_setup_ag_header(struct xfs_scrub_context *sc,
8080
struct xfs_inode *ip);
81+
int xfs_scrub_setup_ag_allocbt(struct xfs_scrub_context *sc,
82+
struct xfs_inode *ip);
83+
8184

8285
void xfs_scrub_ag_free(struct xfs_scrub_context *sc, struct xfs_scrub_ag *sa);
8386
int xfs_scrub_ag_init(struct xfs_scrub_context *sc, xfs_agnumber_t agno,
@@ -93,4 +96,7 @@ int xfs_scrub_walk_agfl(struct xfs_scrub_context *sc,
9396
void *),
9497
void *priv);
9598

99+
int xfs_scrub_setup_ag_btree(struct xfs_scrub_context *sc,
100+
struct xfs_inode *ip, bool force_log);
101+
96102
#endif /* __XFS_SCRUB_COMMON_H__ */

fs/xfs/scrub/scrub.c

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -174,6 +174,14 @@ static const struct xfs_scrub_meta_ops meta_scrub_ops[] = {
174174
.setup = xfs_scrub_setup_ag_header,
175175
.scrub = xfs_scrub_agi,
176176
},
177+
{ /* bnobt */
178+
.setup = xfs_scrub_setup_ag_allocbt,
179+
.scrub = xfs_scrub_bnobt,
180+
},
181+
{ /* cntbt */
182+
.setup = xfs_scrub_setup_ag_allocbt,
183+
.scrub = xfs_scrub_cntbt,
184+
},
177185
};
178186

179187
/* This isn't a stable feature, warn once per day. */

fs/xfs/scrub/scrub.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,5 +71,7 @@ int xfs_scrub_superblock(struct xfs_scrub_context *sc);
7171
int xfs_scrub_agf(struct xfs_scrub_context *sc);
7272
int xfs_scrub_agfl(struct xfs_scrub_context *sc);
7373
int xfs_scrub_agi(struct xfs_scrub_context *sc);
74+
int xfs_scrub_bnobt(struct xfs_scrub_context *sc);
75+
int xfs_scrub_cntbt(struct xfs_scrub_context *sc);
7476

7577
#endif /* __XFS_SCRUB_SCRUB_H__ */

0 commit comments

Comments
 (0)