]> www.infradead.org Git - users/hch/xfs.git/commitdiff
xfs: factor out a xfs_iwalk_args helper
authorChristoph Hellwig <hch@lst.de>
Sun, 22 Sep 2024 03:02:42 +0000 (05:02 +0200)
committerChristoph Hellwig <hch@lst.de>
Sun, 22 Sep 2024 05:37:30 +0000 (07:37 +0200)
Add a helper to share more code between xfs_iwalk and xfs_inobt_walk,
and at the same time do away with the extra flags indirect so that
everyone use the same names for the same flags when using the common
iwalk code.

Signed-off-by: Christoph Hellwig <hch@lst.de>
fs/xfs/xfs_iwalk.c
fs/xfs/xfs_iwalk.h

index d4ef7485e8f7401f35dde545c5e042b83e071ad8..a89ae2aef7c4458b8bfa7e0644c1af5d2a890e5c 100644 (file)
@@ -534,6 +534,35 @@ xfs_iwalk_prefetch(
        return max(inobt_records, 2U);
 }
 
+static int
+xfs_iwalk_args(
+       struct xfs_iwalk_ag     *iwag,
+       unsigned int            flags)
+{
+       struct xfs_mount        *mp = iwag->mp;
+       xfs_agnumber_t          agno = XFS_INO_TO_AGNO(mp, iwag->startino);
+       int                     error;
+
+       ASSERT(agno < mp->m_sb.sb_agcount);
+       ASSERT(!(flags & ~XFS_IWALK_FLAGS_ALL));
+
+       error = xfs_iwalk_alloc(iwag);
+       if (error)
+               return error;
+
+       for_each_perag_from(mp, agno, iwag->pag) {
+               error = xfs_iwalk_ag(iwag);
+               if (error || (flags & XFS_IWALK_SAME_AG)) {
+                       xfs_perag_rele(iwag->pag);
+                       break;
+               }
+               iwag->startino = XFS_AGINO_TO_INO(mp, agno + 1, 0);
+       }
+
+       xfs_iwalk_free(iwag);
+       return error;
+}
+
 /*
  * Walk all inodes in the filesystem starting from @startino.  The @iwalk_fn
  * will be called for each allocated inode, being passed the inode's number and
@@ -562,32 +591,8 @@ xfs_iwalk(
                .pwork          = XFS_PWORK_SINGLE_THREADED,
                .lastino        = NULLFSINO,
        };
-       struct xfs_perag        *pag;
-       xfs_agnumber_t          agno = XFS_INO_TO_AGNO(mp, startino);
-       int                     error;
-
-       ASSERT(agno < mp->m_sb.sb_agcount);
-       ASSERT(!(flags & ~XFS_IWALK_FLAGS_ALL));
 
-       error = xfs_iwalk_alloc(&iwag);
-       if (error)
-               return error;
-
-       for_each_perag_from(mp, agno, pag) {
-               iwag.pag = pag;
-               error = xfs_iwalk_ag(&iwag);
-               if (error)
-                       break;
-               iwag.startino = XFS_AGINO_TO_INO(mp, agno + 1, 0);
-               if (flags & XFS_INOBT_WALK_SAME_AG)
-                       break;
-               iwag.pag = NULL;
-       }
-
-       if (iwag.pag)
-               xfs_perag_rele(pag);
-       xfs_iwalk_free(&iwag);
-       return error;
+       return xfs_iwalk_args(&iwag, flags);
 }
 
 /* Run per-thread iwalk work. */
@@ -673,7 +678,7 @@ xfs_iwalk_threaded(
                iwag->lastino = NULLFSINO;
                xfs_pwork_queue(&pctl, &iwag->pwork);
                startino = XFS_AGINO_TO_INO(mp, pag->pag_agno + 1, 0);
-               if (flags & XFS_INOBT_WALK_SAME_AG)
+               if (flags & XFS_IWALK_SAME_AG)
                        break;
        }
        if (pag)
@@ -747,30 +752,6 @@ xfs_inobt_walk(
                .pwork          = XFS_PWORK_SINGLE_THREADED,
                .lastino        = NULLFSINO,
        };
-       struct xfs_perag        *pag;
-       xfs_agnumber_t          agno = XFS_INO_TO_AGNO(mp, startino);
-       int                     error;
 
-       ASSERT(agno < mp->m_sb.sb_agcount);
-       ASSERT(!(flags & ~XFS_INOBT_WALK_FLAGS_ALL));
-
-       error = xfs_iwalk_alloc(&iwag);
-       if (error)
-               return error;
-
-       for_each_perag_from(mp, agno, pag) {
-               iwag.pag = pag;
-               error = xfs_iwalk_ag(&iwag);
-               if (error)
-                       break;
-               iwag.startino = XFS_AGINO_TO_INO(mp, pag->pag_agno + 1, 0);
-               if (flags & XFS_INOBT_WALK_SAME_AG)
-                       break;
-               iwag.pag = NULL;
-       }
-
-       if (iwag.pag)
-               xfs_perag_rele(pag);
-       xfs_iwalk_free(&iwag);
-       return error;
+       return xfs_iwalk_args(&iwag, flags);
 }
index 83699089755ebb3a5fc8dfcfa203c3523054837a..17a5a2c6debb15b6ce8f894575c5f5ec1d6ed6fb 100644 (file)
@@ -25,7 +25,7 @@ int xfs_iwalk_threaded(struct xfs_mount *mp, xfs_ino_t startino,
                unsigned int flags, xfs_iwalk_fn iwalk_fn,
                unsigned int inode_records, bool poll, void *data);
 
-/* Only iterate inodes within the same AG as @startino. */
+/* Only iterate within the same AG as @startino. */
 #define XFS_IWALK_SAME_AG      (1U << 0)
 
 #define XFS_IWALK_FLAGS_ALL    (XFS_IWALK_SAME_AG)
@@ -41,9 +41,4 @@ int xfs_inobt_walk(struct xfs_mount *mp, struct xfs_trans *tp,
                xfs_inobt_walk_fn inobt_walk_fn, unsigned int inobt_records,
                void *data);
 
-/* Only iterate inobt records within the same AG as @startino. */
-#define XFS_INOBT_WALK_SAME_AG (XFS_IWALK_SAME_AG)
-
-#define XFS_INOBT_WALK_FLAGS_ALL (XFS_INOBT_WALK_SAME_AG)
-
 #endif /* __XFS_IWALK_H__ */