Skip to content

Commit 0a4d797

Browse files
Christoph HellwigDarrick J. Wong
authored andcommitted
xfs: factor out a xfs_iwalk_args helper
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 <[email protected]> Reviewed-by: Darrick J. Wong <[email protected]> Signed-off-by: Darrick J. Wong <[email protected]>
1 parent d664965 commit 0a4d797

File tree

2 files changed

+33
-57
lines changed

2 files changed

+33
-57
lines changed

fs/xfs/xfs_iwalk.c

Lines changed: 32 additions & 51 deletions
Original file line numberDiff line numberDiff line change
@@ -534,6 +534,35 @@ xfs_iwalk_prefetch(
534534
return max(inobt_records, 2U);
535535
}
536536

537+
static int
538+
xfs_iwalk_args(
539+
struct xfs_iwalk_ag *iwag,
540+
unsigned int flags)
541+
{
542+
struct xfs_mount *mp = iwag->mp;
543+
xfs_agnumber_t agno = XFS_INO_TO_AGNO(mp, iwag->startino);
544+
int error;
545+
546+
ASSERT(agno < mp->m_sb.sb_agcount);
547+
ASSERT(!(flags & ~XFS_IWALK_FLAGS_ALL));
548+
549+
error = xfs_iwalk_alloc(iwag);
550+
if (error)
551+
return error;
552+
553+
for_each_perag_from(mp, agno, iwag->pag) {
554+
error = xfs_iwalk_ag(iwag);
555+
if (error || (flags & XFS_IWALK_SAME_AG)) {
556+
xfs_perag_rele(iwag->pag);
557+
break;
558+
}
559+
iwag->startino = XFS_AGINO_TO_INO(mp, agno + 1, 0);
560+
}
561+
562+
xfs_iwalk_free(iwag);
563+
return error;
564+
}
565+
537566
/*
538567
* Walk all inodes in the filesystem starting from @startino. The @iwalk_fn
539568
* will be called for each allocated inode, being passed the inode's number and
@@ -562,32 +591,8 @@ xfs_iwalk(
562591
.pwork = XFS_PWORK_SINGLE_THREADED,
563592
.lastino = NULLFSINO,
564593
};
565-
struct xfs_perag *pag;
566-
xfs_agnumber_t agno = XFS_INO_TO_AGNO(mp, startino);
567-
int error;
568-
569-
ASSERT(agno < mp->m_sb.sb_agcount);
570-
ASSERT(!(flags & ~XFS_IWALK_FLAGS_ALL));
571594

572-
error = xfs_iwalk_alloc(&iwag);
573-
if (error)
574-
return error;
575-
576-
for_each_perag_from(mp, agno, pag) {
577-
iwag.pag = pag;
578-
error = xfs_iwalk_ag(&iwag);
579-
if (error)
580-
break;
581-
iwag.startino = XFS_AGINO_TO_INO(mp, agno + 1, 0);
582-
if (flags & XFS_INOBT_WALK_SAME_AG)
583-
break;
584-
iwag.pag = NULL;
585-
}
586-
587-
if (iwag.pag)
588-
xfs_perag_rele(pag);
589-
xfs_iwalk_free(&iwag);
590-
return error;
595+
return xfs_iwalk_args(&iwag, flags);
591596
}
592597

593598
/* Run per-thread iwalk work. */
@@ -673,7 +678,7 @@ xfs_iwalk_threaded(
673678
iwag->lastino = NULLFSINO;
674679
xfs_pwork_queue(&pctl, &iwag->pwork);
675680
startino = XFS_AGINO_TO_INO(mp, pag->pag_agno + 1, 0);
676-
if (flags & XFS_INOBT_WALK_SAME_AG)
681+
if (flags & XFS_IWALK_SAME_AG)
677682
break;
678683
}
679684
if (pag)
@@ -747,30 +752,6 @@ xfs_inobt_walk(
747752
.pwork = XFS_PWORK_SINGLE_THREADED,
748753
.lastino = NULLFSINO,
749754
};
750-
struct xfs_perag *pag;
751-
xfs_agnumber_t agno = XFS_INO_TO_AGNO(mp, startino);
752-
int error;
753755

754-
ASSERT(agno < mp->m_sb.sb_agcount);
755-
ASSERT(!(flags & ~XFS_INOBT_WALK_FLAGS_ALL));
756-
757-
error = xfs_iwalk_alloc(&iwag);
758-
if (error)
759-
return error;
760-
761-
for_each_perag_from(mp, agno, pag) {
762-
iwag.pag = pag;
763-
error = xfs_iwalk_ag(&iwag);
764-
if (error)
765-
break;
766-
iwag.startino = XFS_AGINO_TO_INO(mp, pag->pag_agno + 1, 0);
767-
if (flags & XFS_INOBT_WALK_SAME_AG)
768-
break;
769-
iwag.pag = NULL;
770-
}
771-
772-
if (iwag.pag)
773-
xfs_perag_rele(pag);
774-
xfs_iwalk_free(&iwag);
775-
return error;
756+
return xfs_iwalk_args(&iwag, flags);
776757
}

fs/xfs/xfs_iwalk.h

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ int xfs_iwalk_threaded(struct xfs_mount *mp, xfs_ino_t startino,
2525
unsigned int flags, xfs_iwalk_fn iwalk_fn,
2626
unsigned int inode_records, bool poll, void *data);
2727

28-
/* Only iterate inodes within the same AG as @startino. */
28+
/* Only iterate within the same AG as @startino. */
2929
#define XFS_IWALK_SAME_AG (1U << 0)
3030

3131
#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,
4141
xfs_inobt_walk_fn inobt_walk_fn, unsigned int inobt_records,
4242
void *data);
4343

44-
/* Only iterate inobt records within the same AG as @startino. */
45-
#define XFS_INOBT_WALK_SAME_AG (XFS_IWALK_SAME_AG)
46-
47-
#define XFS_INOBT_WALK_FLAGS_ALL (XFS_INOBT_WALK_SAME_AG)
48-
4944
#endif /* __XFS_IWALK_H__ */

0 commit comments

Comments
 (0)