]> www.infradead.org Git - users/hch/xfsprogs.git/commitdiff
db: explicitly lookup metadata inodes
authorChristoph Hellwig <hch@lst.de>
Sat, 13 Apr 2024 06:19:18 +0000 (08:19 +0200)
committerChristoph Hellwig <hch@lst.de>
Mon, 15 Apr 2024 17:08:49 +0000 (19:08 +0200)
Prepare for the automatic recording of the metadir inodes in the in-core
super block by manually doing the lookup.

Signed-off-by: Christoph Hellwig <hch@lst.de>
db/check.c
db/dquot.c
db/init.c
db/init.h
db/inode.c
db/metadump.c

index f535ada28b9f197f705c52b8a8f4d361966fea7f..726ed8602378f41aad9e35b4475feeeddbf4e0c4 100644 (file)
@@ -4270,16 +4270,13 @@ quota_check(
 static void
 quota_init(void)
 {
-       qudo = mp->m_sb.sb_uquotino != 0 &&
-              mp->m_sb.sb_uquotino != NULLFSINO &&
+       qudo = uquotino != NULLFSINO &&
               (mp->m_sb.sb_qflags & XFS_UQUOTA_ACCT) &&
               (mp->m_sb.sb_qflags & XFS_UQUOTA_CHKD);
-       qgdo = mp->m_sb.sb_gquotino != 0 &&
-              mp->m_sb.sb_gquotino != NULLFSINO &&
+       qgdo = gquotino != NULLFSINO &&
               (mp->m_sb.sb_qflags & XFS_GQUOTA_ACCT) &&
               (mp->m_sb.sb_qflags & XFS_GQUOTA_CHKD);
-       qpdo = mp->m_sb.sb_pquotino != 0 &&
-              mp->m_sb.sb_pquotino != NULLFSINO &&
+       qpdo = pquotino != NULLFSINO &&
               (mp->m_sb.sb_qflags & XFS_PQUOTA_ACCT) &&
               (mp->m_sb.sb_qflags & XFS_PQUOTA_CHKD);
        if (qudo)
index 338d064995155ed598dc187def559d3b8b3faf42..ff44985121a4f25b3b5704cd8d3ab06d08ed1324 100644 (file)
@@ -123,11 +123,12 @@ dquot_f(
                dbprintf(_("dquot command requires one %s id argument\n"), s);
                return 0;
        }
-       ino = mp->m_sb.sb_uquotino;
        if (doprj)
-               ino = mp->m_sb.sb_pquotino;
+               ino = pquotino;
        else if (dogrp)
-               ino = mp->m_sb.sb_gquotino;
+               ino = gquotino;
+       else
+               ino = uquotino;
 
        if (ino == 0 || ino == NULLFSINO) {
                dbprintf(_("no %s quota inode present\n"), s);
index 17fb094296c2b8a72c29d95f908ef1569b156d9b..f703e1e20b28ef6737b86b2107e49e0bb6fe73fe 100644 (file)
--- a/db/init.c
+++ b/db/init.c
@@ -29,6 +29,54 @@ static struct xlog   xlog;
 xfs_agnumber_t         cur_agno = NULLAGNUMBER;
 struct libxfs_init     x;
 
+xfs_ino_t rbmino = NULLFSINO;
+xfs_ino_t rsumino = NULLFSINO;
+xfs_ino_t uquotino = NULLFSINO;
+xfs_ino_t gquotino = NULLFSINO;
+xfs_ino_t pquotino = NULLFSINO;
+
+static void
+try_lookup_meta_inode(
+       struct xfs_trans        *tp,
+       const struct xfs_imeta_path *path,
+       xfs_ino_t               *inop,
+       int                     *errp)
+{
+       int                     error;
+
+       error = -libxfs_imeta_lookup(tp, path, inop);
+       if (error && error != ENOENT)
+               *errp = error;
+}
+
+static int
+find_meta_inodes(
+       struct xfs_mount        *mp)
+{
+       int                     error = 0;
+       struct xfs_trans        *tp;
+
+       if (!xfs_has_metadir(mp)) {
+               rbmino = mp->m_sb.sb_rbmino;
+               rsumino =  mp->m_sb.sb_rsumino;
+               uquotino = mp->m_sb.sb_uquotino;
+               gquotino = mp->m_sb.sb_gquotino;
+               pquotino = mp->m_sb.sb_pquotino;
+               return 0;
+       }
+
+       error = -libxfs_trans_alloc_empty(mp, &tp);
+       if (error)
+               return error;
+       try_lookup_meta_inode(tp, &XFS_IMETA_RTBITMAP, &rbmino, &error);
+       try_lookup_meta_inode(tp, &XFS_IMETA_RTSUMMARY, &rsumino, &error);
+       try_lookup_meta_inode(tp, &XFS_IMETA_USRQUOTA, &uquotino, &error);
+       try_lookup_meta_inode(tp, &XFS_IMETA_GRPQUOTA, &gquotino, &error);
+       try_lookup_meta_inode(tp, &XFS_IMETA_PRJQUOTA, &pquotino, &error);
+       libxfs_trans_cancel(tp);
+       return error;
+}
+
 static void
 usage(void)
 {
@@ -147,6 +195,9 @@ init(
        if (sbp->sb_agcount != agcount)
                exitcode = 1;
 
+       if (sbp->sb_rootino != NULLFSINO)
+               find_meta_inodes(mp);
+
        /*
         * xfs_check needs corrected incore superblock values
         */
index aa6d843d8d31ab36cf86029fc0c5cc0b65680212..ed2e77ab9cc9720f35bf6afc99b7ef357862b504 100644 (file)
--- a/db/init.h
+++ b/db/init.h
@@ -10,3 +10,9 @@ extern int            expert_mode;
 extern xfs_mount_t     *mp;
 extern struct libxfs_init x;
 extern xfs_agnumber_t  cur_agno;
+
+extern xfs_ino_t       rbmino;
+extern xfs_ino_t       rsumino;
+extern xfs_ino_t       uquotino;
+extern xfs_ino_t       gquotino;
+extern xfs_ino_t       pquotino;
index d7ce7eb77365fea7cf1d8c71ef9ef650d65478b1..271292aadb035ec5bd37a3b26991015eab1c24cf 100644 (file)
@@ -821,18 +821,18 @@ inode_next_type(void)
        case S_IFLNK:
                return TYP_SYMLINK;
        case S_IFREG:
-               if (iocur_top->ino == mp->m_sb.sb_rbmino) {
+               if (iocur_top->ino == rbmino) {
                        if (xfs_has_rtgroups(mp))
                                return TYP_RGBITMAP;
                        return TYP_RTBITMAP;
-               } else if (iocur_top->ino == mp->m_sb.sb_rsumino) {
+               } else if (iocur_top->ino == rsumino) {
                        if (xfs_has_rtgroups(mp))
                                return TYP_RGSUMMARY;
                        return TYP_RTSUMMARY;
                }
-               else if (iocur_top->ino == mp->m_sb.sb_uquotino ||
-                        iocur_top->ino == mp->m_sb.sb_gquotino ||
-                        iocur_top->ino == mp->m_sb.sb_pquotino)
+               else if (iocur_top->ino == uquotino ||
+                        iocur_top->ino == gquotino ||
+                        iocur_top->ino == pquotino)
                        return TYP_DQBLK;
                else if (is_rtrmap_inode(iocur_top->ino))
                        return TYP_RTRMAPBT;
index 40a8e25a4548cb133842d44e2c502730c5e2a48f..3357e210c88c9c40130c7bb14aa94396f75babc2 100644 (file)
@@ -3145,19 +3145,19 @@ pop_out:
 static int
 copy_sb_inodes(void)
 {
-       if (!copy_ino(mp->m_sb.sb_rbmino, TYP_RTBITMAP))
+       if (!copy_ino(rbmino, TYP_RTBITMAP))
                return 0;
 
-       if (!copy_ino(mp->m_sb.sb_rsumino, TYP_RTSUMMARY))
+       if (!copy_ino(rsumino, TYP_RTSUMMARY))
                return 0;
 
-       if (!copy_ino(mp->m_sb.sb_uquotino, TYP_DQBLK))
+       if (!copy_ino(uquotino, TYP_DQBLK))
                return 0;
 
-       if (!copy_ino(mp->m_sb.sb_gquotino, TYP_DQBLK))
+       if (!copy_ino(gquotino, TYP_DQBLK))
                return 0;
 
-       return copy_ino(mp->m_sb.sb_pquotino, TYP_DQBLK);
+       return copy_ino(pquotino, TYP_DQBLK);
 }
 
 static int