From 03430168fc93a170fb884dfd92badd3237c6b1a7 Mon Sep 17 00:00:00 2001 From: Christoph Hellwig Date: Sat, 13 Apr 2024 08:19:18 +0200 Subject: [PATCH] db: explicitly lookup metadata inodes 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 --- db/check.c | 9 +++------ db/dquot.c | 7 ++++--- db/init.c | 51 +++++++++++++++++++++++++++++++++++++++++++++++++++ db/init.h | 6 ++++++ db/inode.c | 10 +++++----- db/metadump.c | 10 +++++----- 6 files changed, 74 insertions(+), 19 deletions(-) diff --git a/db/check.c b/db/check.c index f535ada28..726ed8602 100644 --- a/db/check.c +++ b/db/check.c @@ -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) diff --git a/db/dquot.c b/db/dquot.c index 338d06499..ff4498512 100644 --- a/db/dquot.c +++ b/db/dquot.c @@ -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); diff --git a/db/init.c b/db/init.c index 17fb09429..f703e1e20 100644 --- 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 */ diff --git a/db/init.h b/db/init.h index aa6d843d8..ed2e77ab9 100644 --- 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; diff --git a/db/inode.c b/db/inode.c index d7ce7eb77..271292aad 100644 --- a/db/inode.c +++ b/db/inode.c @@ -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; diff --git a/db/metadump.c b/db/metadump.c index 40a8e25a4..3357e210c 100644 --- a/db/metadump.c +++ b/db/metadump.c @@ -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 -- 2.50.1