From 77d412d0ef5c21166f8e280320d3365d2fc7ba07 Mon Sep 17 00:00:00 2001 From: Christoph Hellwig Date: Wed, 17 Jul 2024 08:39:40 +0200 Subject: [PATCH] repair: refactor ensure_rtgroup_file Refactor ensure_rtgroup_file so that re-population of the inodes is handled by the callers, and by using the generic xfs_rtginode_create helper instead of open coding it. Signed-off-by: Christoph Hellwig --- repair/phase6.c | 98 ++++++++++++++------------------------ repair/rmap.h | 4 +- repair/rtrefcount_repair.c | 2 +- repair/rtrmap_repair.c | 2 +- 4 files changed, 39 insertions(+), 67 deletions(-) diff --git a/repair/phase6.c b/repair/phase6.c index 773daef96..7b9c6b49b 100644 --- a/repair/phase6.c +++ b/repair/phase6.c @@ -828,36 +828,36 @@ mark_ino_inuse( set_inode_isadir(irec, ino_offset); } -static struct xfs_inode * +static bool ensure_rtgroup_file( struct xfs_rtgroup *rtg, - enum xfs_rtg_inodes type, - const char *name, - int (*create)(struct xfs_rtgroup *rtg, - struct xfs_inode *ip, - struct xfs_trans *tp, - bool init)) + enum xfs_rtg_inodes type) { struct xfs_mount *mp = rtg->rtg_mount; struct xfs_inode *ip = rtg->rtg_inodes[type]; - struct xfs_imeta_update upd = { }; - const char *path; + const char *name = xfs_rtginode_name(type); int error; + if (!xfs_rtginode_enabled(rtg, type)) + return false; + if (no_modify) { if (!ip) - do_warn(_("would reset rtgroup %u %s btree\n"), + do_warn(_("would reset rtgroup %u %s inode\n"), rtg->rtg_rgno, name); - return NULL; + return false; } - path = xfs_rtginode_path(rtg->rtg_rgno, type); - if (!path) - do_error( + if (ip) { + struct xfs_imeta_update upd = { }; + const char *path; + + path = xfs_rtginode_path(rtg->rtg_rgno, type); + if (!path) + do_error( _("Couldn't create rtgroup %u %s file path\n"), - rtg->rtg_rgno, name); + rtg->rtg_rgno, name); - if (ip) { /* * Since we're reattaching this file to the metadata directory * tree, try to remove all the parent pointers that might be @@ -881,46 +881,36 @@ ensure_rtgroup_file( /* Reset the link count to something sane. */ set_nlink(VFS_I(ip), 1); libxfs_trans_log_inode(upd.tp, ip, XFS_ILOG_CORE); + + error = -libxfs_imeta_commit(&upd); + if (error) + do_error( + _("Couldn't commit new rtgroup %u %s inode %llu, error %d\n"), + rtg->rtg_rgno, name, + (unsigned long long)upd.ip->i_ino, + error); + kfree(path); } else { /* * The inode was bad or gone, so just make a new one and give * our reference to the rtgroup structure. */ - do_warn(_("resetting rtgroup %u %s btree\n"), + do_warn(_("resetting rtgroup %u %s inode\n"), rtg->rtg_rgno, name); - error = -libxfs_imeta_start_create(mp->m_rtdirip, path, &upd); - if (error) - do_error( - _("Couldn't grab resources to recreate rtgroup %u %s, error %d\n"), - rtg->rtg_rgno, name, error); - - error = -xfs_imeta_create(&upd, S_IFREG); + error = -xfs_rtginode_create(rtg, type, false); if (error) do_error( _("Couldn't create rtgroup %u %s inode, error %d\n"), rtg->rtg_rgno, name, error); - error = -create(rtg, upd.ip, upd.tp, false); - if (error) - do_error( - _("Couldn't create rtgroup %u %s inode, error %d\n"), - rtg->rtg_rgno, name, error); + ip = rtg->rtg_inodes[type]; } /* Mark the inode in use. */ - mark_ino_inuse(mp, upd.ip->i_ino, S_IFREG, upd.dp->i_ino); - mark_ino_metadata(mp, upd.ip->i_ino); - - error = -libxfs_imeta_commit(&upd); - if (error) - do_error( - _("Couldn't commit new rtgroup %u %s inode %llu, error %d\n"), - rtg->rtg_rgno, name, (unsigned long long)upd.ip->i_ino, - error); - - kfree(path); - return upd.ip; + mark_ino_inuse(mp, ip->i_ino, S_IFREG, mp->m_rtdirip->i_ino); + mark_ino_metadata(mp, ip->i_ino); + return true; } static void @@ -928,17 +918,8 @@ ensure_rtgroup_rmapbt( struct xfs_rtgroup *rtg, xfs_filblks_t est_fdblocks) { - struct xfs_inode *ip; - - if (!xfs_has_rtrmapbt(rtg->rtg_mount)) - return; - - ip = ensure_rtgroup_file(rtg, XFS_RTG_RMAP, "rmap", - libxfs_rtrmapbt_create); - if (ip) { - populate_rtgroup_rmapbt(rtg, ip, est_fdblocks); - libxfs_irele(ip); - } + if (ensure_rtgroup_file(rtg, XFS_RTG_RMAP)) + populate_rtgroup_rmapbt(rtg, est_fdblocks); } static void @@ -946,17 +927,8 @@ ensure_rtgroup_refcountbt( struct xfs_rtgroup *rtg, xfs_filblks_t est_fdblocks) { - struct xfs_inode *ip; - - if (!xfs_has_rtreflink(rtg->rtg_mount)) - return; - - ip = ensure_rtgroup_file(rtg, XFS_RTG_REFCOUNT, "refcount", - libxfs_rtrefcountbt_create); - if (ip) { - populate_rtgroup_refcountbt(rtg, ip, est_fdblocks); - libxfs_irele(ip); - } + if (ensure_rtgroup_file(rtg, XFS_RTG_REFCOUNT)) + populate_rtgroup_refcountbt(rtg, est_fdblocks); } /* Initialize a root directory. */ diff --git a/repair/rmap.h b/repair/rmap.h index 3e617615b..4eed1376a 100644 --- a/repair/rmap.h +++ b/repair/rmap.h @@ -61,11 +61,11 @@ int rmap_init_mem_cursor(struct xfs_mount *mp, struct xfs_trans *tp, bool isrt, xfs_agnumber_t agno, struct xfs_btree_cur **rmcurp); int rmap_get_mem_rec(struct xfs_btree_cur *rmcur, struct xfs_rmap_irec *irec); -void populate_rtgroup_rmapbt(struct xfs_rtgroup *rtg, struct xfs_inode *ip, +void populate_rtgroup_rmapbt(struct xfs_rtgroup *rtg, xfs_filblks_t est_fdblocks); xfs_filblks_t estimate_rtrmapbt_blocks(struct xfs_rtgroup *rtg); -void populate_rtgroup_refcountbt(struct xfs_rtgroup *rtg, struct xfs_inode *ip, +void populate_rtgroup_refcountbt(struct xfs_rtgroup *rtg, xfs_filblks_t est_fdblocks); xfs_filblks_t estimate_rtrefcountbt_blocks(struct xfs_rtgroup *rtg); diff --git a/repair/rtrefcount_repair.c b/repair/rtrefcount_repair.c index fede5c725..cf4fdfbbe 100644 --- a/repair/rtrefcount_repair.c +++ b/repair/rtrefcount_repair.c @@ -222,10 +222,10 @@ err_newbt: void populate_rtgroup_refcountbt( struct xfs_rtgroup *rtg, - struct xfs_inode *ip, xfs_filblks_t est_fdblocks) { struct xfs_mount *mp = rtg->rtg_mount; + struct xfs_inode *ip = rtg->rtg_inodes[XFS_RTG_REFCOUNT]; struct repair_ctx sc = { .mp = mp, .ip = ip, diff --git a/repair/rtrmap_repair.c b/repair/rtrmap_repair.c index 231213a87..d9f66e7de 100644 --- a/repair/rtrmap_repair.c +++ b/repair/rtrmap_repair.c @@ -227,10 +227,10 @@ err_newbt: void populate_rtgroup_rmapbt( struct xfs_rtgroup *rtg, - struct xfs_inode *ip, xfs_filblks_t est_fdblocks) { struct xfs_mount *mp = rtg->rtg_mount; + struct xfs_inode *ip = rtg->rtg_inodes[XFS_RTG_RMAP]; struct repair_ctx sc = { .mp = mp, .ip = ip, -- 2.50.1