blob: c6fedb698008146b6842a511d49c6f7dbb1f9eb2 [file] [log] [blame]
Darrick J. Wong29b07672017-10-17 21:37:46 -07001/*
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_rtalloc.h"
34#include "xfs_inode.h"
35#include "scrub/xfs_scrub.h"
36#include "scrub/scrub.h"
37#include "scrub/common.h"
38#include "scrub/trace.h"
39
40/* Set us up with the realtime metadata locked. */
41int
42xfs_scrub_setup_rt(
43 struct xfs_scrub_context *sc,
44 struct xfs_inode *ip)
45{
46 struct xfs_mount *mp = sc->mp;
47 int error = 0;
48
49 /*
50 * If userspace gave us an AG number or inode data, they don't
51 * know what they're doing. Get out.
52 */
53 if (sc->sm->sm_agno || sc->sm->sm_ino || sc->sm->sm_gen)
54 return -EINVAL;
55
56 error = xfs_scrub_setup_fs(sc, ip);
57 if (error)
58 return error;
59
60 sc->ilock_flags = XFS_ILOCK_EXCL | XFS_ILOCK_RTBITMAP;
61 sc->ip = mp->m_rbmip;
62 xfs_ilock(sc->ip, sc->ilock_flags);
63
64 return 0;
65}
66
67/* Realtime bitmap. */
68
69/* Scrub a free extent record from the realtime bitmap. */
70STATIC int
71xfs_scrub_rtbitmap_rec(
72 struct xfs_trans *tp,
73 struct xfs_rtalloc_rec *rec,
74 void *priv)
75{
76 struct xfs_scrub_context *sc = priv;
77
78 if (rec->ar_startblock + rec->ar_blockcount <= rec->ar_startblock ||
79 !xfs_verify_rtbno(sc->mp, rec->ar_startblock) ||
80 !xfs_verify_rtbno(sc->mp, rec->ar_startblock +
81 rec->ar_blockcount - 1))
82 xfs_scrub_fblock_set_corrupt(sc, XFS_DATA_FORK, 0);
83 return 0;
84}
85
86/* Scrub the realtime bitmap. */
87int
88xfs_scrub_rtbitmap(
89 struct xfs_scrub_context *sc)
90{
91 int error;
92
93 error = xfs_rtalloc_query_all(sc->tp, xfs_scrub_rtbitmap_rec, sc);
94 if (!xfs_scrub_fblock_process_error(sc, XFS_DATA_FORK, 0, &error))
95 goto out;
96
97out:
98 return error;
99}
100
101/* Scrub the realtime summary. */
102int
103xfs_scrub_rtsummary(
104 struct xfs_scrub_context *sc)
105{
106 /* XXX: implement this some day */
107 return -ENOENT;
108}