|
| 1 | +// SPDX-License-Identifier: GPL-2.0-or-later |
| 2 | +/* |
| 3 | + * Copyright (c) 2022-2024 Oracle. All Rights Reserved. |
| 4 | + * Author: Darrick J. Wong <djwong@kernel.org> |
| 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 "scrub/scrub.h" |
| 14 | +#include "scrub/common.h" |
| 15 | + |
| 16 | +/* Set us up with a transaction and an empty context. */ |
| 17 | +int |
| 18 | +xchk_setup_rgsuperblock( |
| 19 | + struct xfs_scrub *sc) |
| 20 | +{ |
| 21 | + return xchk_trans_alloc(sc, 0); |
| 22 | +} |
| 23 | + |
| 24 | +/* Cross-reference with the other rt metadata. */ |
| 25 | +STATIC void |
| 26 | +xchk_rgsuperblock_xref( |
| 27 | + struct xfs_scrub *sc) |
| 28 | +{ |
| 29 | + if (sc->sm->sm_flags & XFS_SCRUB_OFLAG_CORRUPT) |
| 30 | + return; |
| 31 | + |
| 32 | + xchk_xref_is_used_rt_space(sc, xfs_rgbno_to_rtb(sc->sr.rtg, 0), 1); |
| 33 | +} |
| 34 | + |
| 35 | +int |
| 36 | +xchk_rgsuperblock( |
| 37 | + struct xfs_scrub *sc) |
| 38 | +{ |
| 39 | + xfs_rgnumber_t rgno = sc->sm->sm_agno; |
| 40 | + int error; |
| 41 | + |
| 42 | + /* |
| 43 | + * Only rtgroup 0 has a superblock. We may someday want to use higher |
| 44 | + * rgno for other functions, similar to what we do with the primary |
| 45 | + * super scrub function. |
| 46 | + */ |
| 47 | + if (rgno != 0) |
| 48 | + return -ENOENT; |
| 49 | + |
| 50 | + /* |
| 51 | + * Grab an active reference to the rtgroup structure. If we can't get |
| 52 | + * it, we're racing with something that's tearing down the group, so |
| 53 | + * signal that the group no longer exists. Take the rtbitmap in shared |
| 54 | + * mode so that the group can't change while we're doing things. |
| 55 | + */ |
| 56 | + error = xchk_rtgroup_init_existing(sc, rgno, &sc->sr); |
| 57 | + if (!xchk_xref_process_error(sc, 0, 0, &error)) |
| 58 | + return error; |
| 59 | + |
| 60 | + xchk_rtgroup_lock(&sc->sr, XFS_RTGLOCK_BITMAP_SHARED); |
| 61 | + |
| 62 | + /* |
| 63 | + * Since we already validated the rt superblock at mount time, we don't |
| 64 | + * need to check its contents again. All we need is to cross-reference. |
| 65 | + */ |
| 66 | + xchk_rgsuperblock_xref(sc); |
| 67 | + return 0; |
| 68 | +} |
0 commit comments