Skip to content

Commit c7e693d

Browse files
committed
xfs: scrub rmap btrees
Check the reverse mapping records to make sure that the contents make sense. Signed-off-by: Darrick J. Wong <darrick.wong@oracle.com> Reviewed-by: Dave Chinner <dchinner@redhat.com>
1 parent 3daa664 commit c7e693d

File tree

6 files changed

+149
-1
lines changed

6 files changed

+149
-1
lines changed

fs/xfs/Makefile

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -148,6 +148,7 @@ xfs-y += $(addprefix scrub/, \
148148
btree.o \
149149
common.o \
150150
ialloc.o \
151+
rmap.o \
151152
scrub.o \
152153
)
153154
endif

fs/xfs/libxfs/xfs_fs.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -492,9 +492,10 @@ struct xfs_scrub_metadata {
492492
#define XFS_SCRUB_TYPE_CNTBT 6 /* freesp by length btree */
493493
#define XFS_SCRUB_TYPE_INOBT 7 /* inode btree */
494494
#define XFS_SCRUB_TYPE_FINOBT 8 /* free inode btree */
495+
#define XFS_SCRUB_TYPE_RMAPBT 9 /* reverse mapping btree */
495496

496497
/* Number of scrub subcommands. */
497-
#define XFS_SCRUB_TYPE_NR 9
498+
#define XFS_SCRUB_TYPE_NR 10
498499

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

fs/xfs/scrub/common.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,8 @@ int xfs_scrub_setup_ag_allocbt(struct xfs_scrub_context *sc,
8383
struct xfs_inode *ip);
8484
int xfs_scrub_setup_ag_iallocbt(struct xfs_scrub_context *sc,
8585
struct xfs_inode *ip);
86+
int xfs_scrub_setup_ag_rmapbt(struct xfs_scrub_context *sc,
87+
struct xfs_inode *ip);
8688

8789

8890
void xfs_scrub_ag_free(struct xfs_scrub_context *sc, struct xfs_scrub_ag *sa);

fs/xfs/scrub/rmap.c

Lines changed: 138 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,138 @@
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_ialloc.h"
34+
#include "xfs_rmap.h"
35+
#include "scrub/xfs_scrub.h"
36+
#include "scrub/scrub.h"
37+
#include "scrub/common.h"
38+
#include "scrub/btree.h"
39+
#include "scrub/trace.h"
40+
41+
/*
42+
* Set us up to scrub reverse mapping btrees.
43+
*/
44+
int
45+
xfs_scrub_setup_ag_rmapbt(
46+
struct xfs_scrub_context *sc,
47+
struct xfs_inode *ip)
48+
{
49+
return xfs_scrub_setup_ag_btree(sc, ip, false);
50+
}
51+
52+
/* Reverse-mapping scrubber. */
53+
54+
/* Scrub an rmapbt record. */
55+
STATIC int
56+
xfs_scrub_rmapbt_rec(
57+
struct xfs_scrub_btree *bs,
58+
union xfs_btree_rec *rec)
59+
{
60+
struct xfs_mount *mp = bs->cur->bc_mp;
61+
struct xfs_rmap_irec irec;
62+
xfs_agnumber_t agno = bs->cur->bc_private.a.agno;
63+
bool non_inode;
64+
bool is_unwritten;
65+
bool is_bmbt;
66+
bool is_attr;
67+
int error;
68+
69+
error = xfs_rmap_btrec_to_irec(rec, &irec);
70+
if (!xfs_scrub_btree_process_error(bs->sc, bs->cur, 0, &error))
71+
goto out;
72+
73+
/* Check extent. */
74+
if (irec.rm_startblock + irec.rm_blockcount <= irec.rm_startblock)
75+
xfs_scrub_btree_set_corrupt(bs->sc, bs->cur, 0);
76+
77+
if (irec.rm_owner == XFS_RMAP_OWN_FS) {
78+
/*
79+
* xfs_verify_agbno returns false for static fs metadata.
80+
* Since that only exists at the start of the AG, validate
81+
* that by hand.
82+
*/
83+
if (irec.rm_startblock != 0 ||
84+
irec.rm_blockcount != XFS_AGFL_BLOCK(mp) + 1)
85+
xfs_scrub_btree_set_corrupt(bs->sc, bs->cur, 0);
86+
} else {
87+
/*
88+
* Otherwise we must point somewhere past the static metadata
89+
* but before the end of the FS. Run the regular check.
90+
*/
91+
if (!xfs_verify_agbno(mp, agno, irec.rm_startblock) ||
92+
!xfs_verify_agbno(mp, agno, irec.rm_startblock +
93+
irec.rm_blockcount - 1))
94+
xfs_scrub_btree_set_corrupt(bs->sc, bs->cur, 0);
95+
}
96+
97+
/* Check flags. */
98+
non_inode = XFS_RMAP_NON_INODE_OWNER(irec.rm_owner);
99+
is_bmbt = irec.rm_flags & XFS_RMAP_BMBT_BLOCK;
100+
is_attr = irec.rm_flags & XFS_RMAP_ATTR_FORK;
101+
is_unwritten = irec.rm_flags & XFS_RMAP_UNWRITTEN;
102+
103+
if (is_bmbt && irec.rm_offset != 0)
104+
xfs_scrub_btree_set_corrupt(bs->sc, bs->cur, 0);
105+
106+
if (non_inode && irec.rm_offset != 0)
107+
xfs_scrub_btree_set_corrupt(bs->sc, bs->cur, 0);
108+
109+
if (is_unwritten && (is_bmbt || non_inode || is_attr))
110+
xfs_scrub_btree_set_corrupt(bs->sc, bs->cur, 0);
111+
112+
if (non_inode && (is_bmbt || is_unwritten || is_attr))
113+
xfs_scrub_btree_set_corrupt(bs->sc, bs->cur, 0);
114+
115+
if (!non_inode) {
116+
if (!xfs_verify_ino(mp, irec.rm_owner))
117+
xfs_scrub_btree_set_corrupt(bs->sc, bs->cur, 0);
118+
} else {
119+
/* Non-inode owner within the magic values? */
120+
if (irec.rm_owner <= XFS_RMAP_OWN_MIN ||
121+
irec.rm_owner > XFS_RMAP_OWN_FS)
122+
xfs_scrub_btree_set_corrupt(bs->sc, bs->cur, 0);
123+
}
124+
out:
125+
return error;
126+
}
127+
128+
/* Scrub the rmap btree for some AG. */
129+
int
130+
xfs_scrub_rmapbt(
131+
struct xfs_scrub_context *sc)
132+
{
133+
struct xfs_owner_info oinfo;
134+
135+
xfs_rmap_ag_owner(&oinfo, XFS_RMAP_OWN_AG);
136+
return xfs_scrub_btree(sc, sc->sa.rmap_cur, xfs_scrub_rmapbt_rec,
137+
&oinfo, NULL);
138+
}

fs/xfs/scrub/scrub.c

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -191,6 +191,11 @@ static const struct xfs_scrub_meta_ops meta_scrub_ops[] = {
191191
.scrub = xfs_scrub_finobt,
192192
.has = xfs_sb_version_hasfinobt,
193193
},
194+
{ /* rmapbt */
195+
.setup = xfs_scrub_setup_ag_rmapbt,
196+
.scrub = xfs_scrub_rmapbt,
197+
.has = xfs_sb_version_hasrmapbt,
198+
},
194199
};
195200

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

fs/xfs/scrub/scrub.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,5 +75,6 @@ int xfs_scrub_bnobt(struct xfs_scrub_context *sc);
7575
int xfs_scrub_cntbt(struct xfs_scrub_context *sc);
7676
int xfs_scrub_inobt(struct xfs_scrub_context *sc);
7777
int xfs_scrub_finobt(struct xfs_scrub_context *sc);
78+
int xfs_scrub_rmapbt(struct xfs_scrub_context *sc);
7879

7980
#endif /* __XFS_SCRUB_SCRUB_H__ */

0 commit comments

Comments
 (0)