]> www.infradead.org Git - users/hch/xfsprogs.git/commitdiff
repair: refactor ensure_rtgroup_file
authorChristoph Hellwig <hch@lst.de>
Wed, 17 Jul 2024 06:39:40 +0000 (08:39 +0200)
committerChristoph Hellwig <hch@lst.de>
Wed, 17 Jul 2024 12:31:20 +0000 (14:31 +0200)
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 <hch@lst.de>
repair/phase6.c
repair/rmap.h
repair/rtrefcount_repair.c
repair/rtrmap_repair.c

index 773daef9689a6855ba497e18d6eb2224f3d65a95..7b9c6b49b0cbe25692f5b2aca8ec39b02154ab55 100644 (file)
@@ -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. */
index 3e617615bc73c71e52da156f9fee48c98690f087..4eed1376ac8ad1eeaa721141de239f3a9161c4e9 100644 (file)
@@ -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);
 
index fede5c725b3b6f9140c6c702ea7b3d078b442111..cf4fdfbbe93e90f1835d37b2542b37661f46769b 100644 (file)
@@ -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,
index 231213a87f5179d99f832df963eb45f19af97263..d9f66e7de0d9ccba701479c6df8834022d39f7de 100644 (file)
@@ -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,