]> git.ipfire.org Git - thirdparty/xfsprogs-dev.git/commitdiff
xfs_repair: use libxfs_metafile_iget for quota/rt inodes
authorDarrick J. Wong <djwong@kernel.org>
Thu, 21 Nov 2024 00:24:19 +0000 (16:24 -0800)
committerDarrick J. Wong <djwong@kernel.org>
Tue, 24 Dec 2024 02:01:27 +0000 (18:01 -0800)
Use the new iget function for these metadata files so that we can check
types, etc.

Signed-off-by: "Darrick J. Wong" <djwong@kernel.org>
Reviewed-by: Christoph Hellwig <hch@lst.de>
repair/phase6.c
repair/quotacheck.c
repair/rt.c

index 1decfe2286fa47296007e3e16c91d2d6a3b2f26b..82e1687f9b278d6223824306980938cf551d52ce 100644 (file)
@@ -484,6 +484,11 @@ ensure_rtino(
        struct xfs_mount                *mp = tp->t_mountp;
        int                             error;
 
+       /*
+        * Don't use metafile iget here because we're resetting sb-rooted
+        * inodes that live at fixed inumbers, but these inodes could be in
+        * an arbitrary state.
+        */
        error = -libxfs_iget(mp, tp, ino, 0, ipp);
        if (error)
                return error;
@@ -524,16 +529,11 @@ static void
 fill_rbmino(
        struct xfs_mount        *mp)
 {
-       struct xfs_trans        *tp;
        struct xfs_inode        *ip;
        int                     error;
 
-       error = -libxfs_trans_alloc_rollable(mp, 10, &tp);
-       if (error)
-               res_failed(error);
-
-       error = -libxfs_iget(mp, tp, mp->m_sb.sb_rbmino, 0, &ip);
-       libxfs_trans_cancel(tp);
+       error = -libxfs_metafile_iget(mp, mp->m_sb.sb_rbmino,
+                       XFS_METAFILE_RTBITMAP, &ip);
        if (error)
                do_error(
 _("couldn't iget realtime bitmap inode, error %d\n"), error);
@@ -551,16 +551,11 @@ static void
 fill_rsumino(
        struct xfs_mount        *mp)
 {
-       struct xfs_trans        *tp;
        struct xfs_inode        *ip;
        int                     error;
 
-       error = -libxfs_trans_alloc_rollable(mp, 10, &tp);
-       if (error)
-               res_failed(error);
-
-       error = -libxfs_iget(mp, tp, mp->m_sb.sb_rsumino, 0, &ip);
-       libxfs_trans_cancel(tp);
+       error = -libxfs_metafile_iget(mp, mp->m_sb.sb_rsumino,
+                       XFS_METAFILE_RTSUMMARY, &ip);
        if (error)
                do_error(
 _("couldn't iget realtime summary inode, error %d\n"), error);
index 4cb38db3ddd6d75c175fdd5350018cc7c61fdb0c..d9e08059927f80cecf43908e6b4517ae81ec05f8 100644 (file)
@@ -403,21 +403,26 @@ quotacheck_verify(
        struct xfs_ifork        *ifp;
        struct qc_dquots        *dquots = NULL;
        struct avl64node        *node, *n;
+       struct xfs_trans        *tp;
        xfs_ino_t               ino = NULLFSINO;
+       enum xfs_metafile_type  metafile_type;
        int                     error;
 
        switch (type) {
        case XFS_DQTYPE_USER:
                ino = mp->m_sb.sb_uquotino;
                dquots = user_dquots;
+               metafile_type = XFS_METAFILE_USRQUOTA;
                break;
        case XFS_DQTYPE_GROUP:
                ino = mp->m_sb.sb_gquotino;
                dquots = group_dquots;
+               metafile_type = XFS_METAFILE_GRPQUOTA;
                break;
        case XFS_DQTYPE_PROJ:
                ino = mp->m_sb.sb_pquotino;
                dquots = proj_dquots;
+               metafile_type = XFS_METAFILE_PRJQUOTA;
                break;
        }
 
@@ -429,17 +434,21 @@ quotacheck_verify(
        if (!dquots || !chkd_flags)
                return;
 
-       error = -libxfs_iget(mp, NULL, ino, 0, &ip);
+       error = -libxfs_trans_alloc_empty(mp, &tp);
+       if (error)
+               do_error(_("could not alloc transaction to open quota file\n"));
+
+       error = -libxfs_trans_metafile_iget(tp, ino, metafile_type, &ip);
        if (error) {
                do_warn(
        _("could not open %s inode %"PRIu64" for quotacheck, err=%d\n"),
                        qflags_typestr(type), ino, error);
                chkd_flags = 0;
-               return;
+               goto out_trans;
        }
 
        ifp = xfs_ifork_ptr(ip, XFS_DATA_FORK);
-       error = -libxfs_iread_extents(NULL, ip, XFS_DATA_FORK);
+       error = -libxfs_iread_extents(tp, ip, XFS_DATA_FORK);
        if (error) {
                do_warn(
        _("could not read %s inode %"PRIu64" extents, err=%d\n"),
@@ -477,6 +486,8 @@ _("%s record for id %u not found on disk (bcount %"PRIu64" rtbcount %"PRIu64" ic
        }
 err:
        libxfs_irele(ip);
+out_trans:
+       libxfs_trans_cancel(tp);
 }
 
 /*
index 721c363cc1dd10a6fc92bb3c43ec71c715683a90..9ae421168e84b4059fa61fc13c14aa6fbb191835 100644 (file)
@@ -144,18 +144,34 @@ generate_rtinfo(
 static void
 check_rtfile_contents(
        struct xfs_mount        *mp,
-       const char              *filename,
-       xfs_ino_t               ino,
-       void                    *buf,
+       enum xfs_metafile_type  metafile_type,
        xfs_fileoff_t           filelen)
 {
        struct xfs_bmbt_irec    map;
        struct xfs_buf          *bp;
        struct xfs_inode        *ip;
+       const char              *filename;
+       void                    *buf;
+       xfs_ino_t               ino;
        xfs_fileoff_t           bno = 0;
        int                     error;
 
-       error = -libxfs_iget(mp, NULL, ino, 0, &ip);
+       switch (metafile_type) {
+       case XFS_METAFILE_RTBITMAP:
+               ino = mp->m_sb.sb_rbmino;
+               filename = "rtbitmap";
+               buf = btmcompute;
+               break;
+       case XFS_METAFILE_RTSUMMARY:
+               ino = mp->m_sb.sb_rsumino;
+               filename = "rtsummary";
+               buf = sumcompute;
+               break;
+       default:
+               return;
+       }
+
+       error = -libxfs_metafile_iget(mp, ino, metafile_type, &ip);
        if (error) {
                do_warn(_("unable to open %s file, err %d\n"), filename, error);
                return;
@@ -216,7 +232,7 @@ check_rtbitmap(
        if (need_rbmino)
                return;
 
-       check_rtfile_contents(mp, "rtbitmap", mp->m_sb.sb_rbmino, btmcompute,
+       check_rtfile_contents(mp, XFS_METAFILE_RTBITMAP,
                        mp->m_sb.sb_rbmblocks);
 }
 
@@ -227,6 +243,5 @@ check_rtsummary(
        if (need_rsumino)
                return;
 
-       check_rtfile_contents(mp, "rtsummary", mp->m_sb.sb_rsumino, sumcompute,
-                       mp->m_rsumblocks);
+       check_rtfile_contents(mp, XFS_METAFILE_RTSUMMARY, mp->m_rsumblocks);
 }