]>
git.proxmox.com Git - mirror_ubuntu-jammy-kernel.git/blob - fs/xfs/scrub/alloc.c
1 // SPDX-License-Identifier: GPL-2.0+
3 * Copyright (C) 2017 Oracle. All Rights Reserved.
4 * Author: Darrick J. Wong <darrick.wong@oracle.com>
8 #include "xfs_shared.h"
9 #include "xfs_format.h"
10 #include "xfs_trans_resv.h"
11 #include "xfs_mount.h"
12 #include "xfs_defer.h"
13 #include "xfs_btree.h"
15 #include "xfs_log_format.h"
16 #include "xfs_trans.h"
18 #include "xfs_alloc.h"
20 #include "xfs_alloc.h"
21 #include "scrub/xfs_scrub.h"
22 #include "scrub/scrub.h"
23 #include "scrub/common.h"
24 #include "scrub/btree.h"
25 #include "scrub/trace.h"
28 * Set us up to scrub free space btrees.
31 xfs_scrub_setup_ag_allocbt(
32 struct xfs_scrub_context
*sc
,
35 return xfs_scrub_setup_ag_btree(sc
, ip
, false);
38 /* Free space btree scrubber. */
40 * Ensure there's a corresponding cntbt/bnobt record matching this
41 * bnobt/cntbt record, respectively.
44 xfs_scrub_allocbt_xref_other(
45 struct xfs_scrub_context
*sc
,
49 struct xfs_btree_cur
**pcur
;
55 if (sc
->sm
->sm_type
== XFS_SCRUB_TYPE_BNOBT
)
56 pcur
= &sc
->sa
.cnt_cur
;
58 pcur
= &sc
->sa
.bno_cur
;
59 if (!*pcur
|| xfs_scrub_skip_xref(sc
->sm
))
62 error
= xfs_alloc_lookup_le(*pcur
, agbno
, len
, &has_otherrec
);
63 if (!xfs_scrub_should_check_xref(sc
, &error
, pcur
))
66 xfs_scrub_btree_xref_set_corrupt(sc
, *pcur
, 0);
70 error
= xfs_alloc_get_rec(*pcur
, &fbno
, &flen
, &has_otherrec
);
71 if (!xfs_scrub_should_check_xref(sc
, &error
, pcur
))
74 xfs_scrub_btree_xref_set_corrupt(sc
, *pcur
, 0);
78 if (fbno
!= agbno
|| flen
!= len
)
79 xfs_scrub_btree_xref_set_corrupt(sc
, *pcur
, 0);
82 /* Cross-reference with the other btrees. */
84 xfs_scrub_allocbt_xref(
85 struct xfs_scrub_context
*sc
,
89 if (sc
->sm
->sm_flags
& XFS_SCRUB_OFLAG_CORRUPT
)
92 xfs_scrub_allocbt_xref_other(sc
, agbno
, len
);
93 xfs_scrub_xref_is_not_inode_chunk(sc
, agbno
, len
);
94 xfs_scrub_xref_has_no_owner(sc
, agbno
, len
);
95 xfs_scrub_xref_is_not_shared(sc
, agbno
, len
);
98 /* Scrub a bnobt/cntbt record. */
100 xfs_scrub_allocbt_rec(
101 struct xfs_scrub_btree
*bs
,
102 union xfs_btree_rec
*rec
)
104 struct xfs_mount
*mp
= bs
->cur
->bc_mp
;
105 xfs_agnumber_t agno
= bs
->cur
->bc_private
.a
.agno
;
110 bno
= be32_to_cpu(rec
->alloc
.ar_startblock
);
111 len
= be32_to_cpu(rec
->alloc
.ar_blockcount
);
113 if (bno
+ len
<= bno
||
114 !xfs_verify_agbno(mp
, agno
, bno
) ||
115 !xfs_verify_agbno(mp
, agno
, bno
+ len
- 1))
116 xfs_scrub_btree_set_corrupt(bs
->sc
, bs
->cur
, 0);
118 xfs_scrub_allocbt_xref(bs
->sc
, bno
, len
);
123 /* Scrub the freespace btrees for some AG. */
126 struct xfs_scrub_context
*sc
,
129 struct xfs_owner_info oinfo
;
130 struct xfs_btree_cur
*cur
;
132 xfs_rmap_ag_owner(&oinfo
, XFS_RMAP_OWN_AG
);
133 cur
= which
== XFS_BTNUM_BNO
? sc
->sa
.bno_cur
: sc
->sa
.cnt_cur
;
134 return xfs_scrub_btree(sc
, cur
, xfs_scrub_allocbt_rec
, &oinfo
, NULL
);
139 struct xfs_scrub_context
*sc
)
141 return xfs_scrub_allocbt(sc
, XFS_BTNUM_BNO
);
146 struct xfs_scrub_context
*sc
)
148 return xfs_scrub_allocbt(sc
, XFS_BTNUM_CNT
);
151 /* xref check that the extent is not free */
153 xfs_scrub_xref_is_used_space(
154 struct xfs_scrub_context
*sc
,
161 if (!sc
->sa
.bno_cur
|| xfs_scrub_skip_xref(sc
->sm
))
164 error
= xfs_alloc_has_record(sc
->sa
.bno_cur
, agbno
, len
, &is_freesp
);
165 if (!xfs_scrub_should_check_xref(sc
, &error
, &sc
->sa
.bno_cur
))
168 xfs_scrub_btree_xref_set_corrupt(sc
, sc
->sa
.bno_cur
, 0);