]> Git Repo - linux.git/blob - fs/xfs/scrub/rgsuper.c
Linux 6.14-rc3
[linux.git] / fs / xfs / scrub / rgsuper.c
1 // SPDX-License-Identifier: GPL-2.0-or-later
2 /*
3  * Copyright (c) 2022-2024 Oracle.  All Rights Reserved.
4  * Author: Darrick J. Wong <[email protected]>
5  */
6 #include "xfs.h"
7 #include "xfs_fs.h"
8 #include "xfs_shared.h"
9 #include "xfs_format.h"
10 #include "xfs_trans_resv.h"
11 #include "xfs_mount.h"
12 #include "xfs_rtgroup.h"
13 #include "xfs_log_format.h"
14 #include "xfs_trans.h"
15 #include "xfs_sb.h"
16 #include "xfs_rmap.h"
17 #include "scrub/scrub.h"
18 #include "scrub/common.h"
19 #include "scrub/repair.h"
20
21 /* Set us up with a transaction and an empty context. */
22 int
23 xchk_setup_rgsuperblock(
24         struct xfs_scrub        *sc)
25 {
26         return xchk_trans_alloc(sc, 0);
27 }
28
29 /* Cross-reference with the other rt metadata. */
30 STATIC void
31 xchk_rgsuperblock_xref(
32         struct xfs_scrub        *sc)
33 {
34         if (sc->sm->sm_flags & XFS_SCRUB_OFLAG_CORRUPT)
35                 return;
36
37         xchk_xref_is_used_rt_space(sc, xfs_rgbno_to_rtb(sc->sr.rtg, 0), 1);
38         xchk_xref_is_only_rt_owned_by(sc, 0, 1, &XFS_RMAP_OINFO_FS);
39 }
40
41 int
42 xchk_rgsuperblock(
43         struct xfs_scrub        *sc)
44 {
45         xfs_rgnumber_t          rgno = sc->sm->sm_agno;
46         int                     error;
47
48         /*
49          * Only rtgroup 0 has a superblock.  We may someday want to use higher
50          * rgno for other functions, similar to what we do with the primary
51          * super scrub function.
52          */
53         if (rgno != 0)
54                 return -ENOENT;
55
56         /*
57          * Grab an active reference to the rtgroup structure.  If we can't get
58          * it, we're racing with something that's tearing down the group, so
59          * signal that the group no longer exists.  Take the rtbitmap in shared
60          * mode so that the group can't change while we're doing things.
61          */
62         error = xchk_rtgroup_init_existing(sc, rgno, &sc->sr);
63         if (!xchk_xref_process_error(sc, 0, 0, &error))
64                 return error;
65
66         error = xchk_rtgroup_lock(sc, &sc->sr, XFS_RTGLOCK_BITMAP_SHARED);
67         if (error)
68                 return error;
69
70         /*
71          * Since we already validated the rt superblock at mount time, we don't
72          * need to check its contents again.  All we need is to cross-reference.
73          */
74         xchk_rgsuperblock_xref(sc);
75         return 0;
76 }
77
78 #ifdef CONFIG_XFS_ONLINE_REPAIR
79 int
80 xrep_rgsuperblock(
81         struct xfs_scrub        *sc)
82 {
83         ASSERT(rtg_rgno(sc->sr.rtg) == 0);
84
85         xfs_log_sb(sc->tp);
86         return 0;
87 }
88 #endif /* CONFIG_XFS_ONLINE_REPAIR */
This page took 0.034561 seconds and 4 git commands to generate.