2 * Copyright (C) 2017 Oracle. All Rights Reserved.
4 * Author: Darrick J. Wong <darrick.wong@oracle.com>
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.
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.
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.
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"
29 #include "xfs_log_format.h"
30 #include "xfs_trans.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"
40 /* Set us up with the realtime metadata locked. */
43 struct xfs_scrub_context
*sc
,
48 error
= xfs_scrub_setup_fs(sc
, ip
);
52 sc
->ilock_flags
= XFS_ILOCK_EXCL
| XFS_ILOCK_RTBITMAP
;
53 sc
->ip
= sc
->mp
->m_rbmip
;
54 xfs_ilock(sc
->ip
, sc
->ilock_flags
);
59 /* Realtime bitmap. */
61 /* Scrub a free extent record from the realtime bitmap. */
63 xfs_scrub_rtbitmap_rec(
65 struct xfs_rtalloc_rec
*rec
,
68 struct xfs_scrub_context
*sc
= priv
;
70 if (rec
->ar_startblock
+ rec
->ar_blockcount
<= rec
->ar_startblock
||
71 !xfs_verify_rtbno(sc
->mp
, rec
->ar_startblock
) ||
72 !xfs_verify_rtbno(sc
->mp
, rec
->ar_startblock
+
73 rec
->ar_blockcount
- 1))
74 xfs_scrub_fblock_set_corrupt(sc
, XFS_DATA_FORK
, 0);
78 /* Scrub the realtime bitmap. */
81 struct xfs_scrub_context
*sc
)
85 error
= xfs_rtalloc_query_all(sc
->tp
, xfs_scrub_rtbitmap_rec
, sc
);
86 if (!xfs_scrub_fblock_process_error(sc
, XFS_DATA_FORK
, 0, &error
))
93 /* Scrub the realtime summary. */
96 struct xfs_scrub_context
*sc
)
98 /* XXX: implement this some day */
103 /* xref check that the extent is not free in the rtbitmap */
105 xfs_scrub_xref_is_used_rt_space(
106 struct xfs_scrub_context
*sc
,
113 xfs_ilock(sc
->mp
->m_rbmip
, XFS_ILOCK_SHARED
| XFS_ILOCK_RTBITMAP
);
114 error
= xfs_rtalloc_extent_is_free(sc
->mp
, sc
->tp
, fsbno
, len
,
116 if (!xfs_scrub_should_check_xref(sc
, &error
, NULL
))
119 xfs_scrub_ino_xref_set_corrupt(sc
, sc
->mp
->m_rbmip
->i_ino
,
122 xfs_iunlock(sc
->mp
->m_rbmip
, XFS_ILOCK_SHARED
| XFS_ILOCK_RTBITMAP
);