Line data Source code
1 : // SPDX-License-Identifier: GPL-2.0-or-later 2 : /* 3 : * Copyright (C) 2022-2023 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 13216 : xchk_setup_rgsuperblock( 19 : struct xfs_scrub *sc) 20 : { 21 13216 : return xchk_trans_alloc(sc, 0); 22 : } 23 : 24 : /* Cross-reference with the other rt metadata. */ 25 : STATIC void 26 13216 : xchk_rgsuperblock_xref( 27 : struct xfs_scrub *sc) 28 : { 29 13216 : struct xfs_mount *mp = sc->mp; 30 13216 : xfs_rgnumber_t rgno = sc->sr.rtg->rtg_rgno; 31 13216 : xfs_rtblock_t rtbno; 32 : 33 13216 : if (sc->sm->sm_flags & XFS_SCRUB_OFLAG_CORRUPT) 34 : return; 35 : 36 13216 : rtbno = xfs_rgbno_to_rtb(mp, rgno, 0); 37 13216 : xchk_xref_is_used_rt_space(sc, rtbno, 1); 38 : } 39 : 40 : int 41 13216 : xchk_rgsuperblock( 42 : struct xfs_scrub *sc) 43 : { 44 13216 : struct xfs_buf *bp; 45 13216 : xfs_rgnumber_t rgno = sc->sm->sm_agno; 46 13216 : int error; 47 : 48 : /* 49 : * Grab an active reference to the rtgroup structure. If we can't get 50 : * it, we're racing with something that's tearing down the group, so 51 : * signal that the group no longer exists. Take the rtbitmap in shared 52 : * mode so that the group can't change while we're doing things. 53 : */ 54 13216 : error = xchk_rtgroup_init(sc, rgno, &sc->sr, XFS_RTGLOCK_BITMAP_SHARED); 55 13215 : if (error) 56 : return error; 57 : 58 : /* 59 : * If this is the primary rtgroup superblock, we know it passed the 60 : * verifier checks at mount time and do not need to load the buffer 61 : * again. 62 : */ 63 13215 : if (sc->sr.rtg->rtg_rgno == 0) { 64 2642 : xchk_rgsuperblock_xref(sc); 65 2642 : return 0; 66 : } 67 : 68 : /* The secondary rt super is checked by the read verifier. */ 69 21147 : error = xfs_buf_read_uncached(sc->mp->m_rtdev_targp, XFS_RTSB_DADDR, 70 10573 : XFS_FSB_TO_BB(sc->mp, 1), 0, &bp, &xfs_rtsb_buf_ops); 71 10574 : if (!xchk_process_rt_error(sc, rgno, 0, &error)) 72 0 : return error; 73 : 74 10573 : xchk_rgsuperblock_xref(sc); 75 10572 : xfs_buf_relse(bp); 76 10572 : return 0; 77 : }