]> git.ipfire.org Git - thirdparty/xfsprogs-dev.git/commitdiff
xfs: hoist xfs_scrub_agfl_walk to libxfs as xfs_agfl_walk
authorDarrick J. Wong <darrick.wong@oracle.com>
Thu, 28 Jun 2018 20:11:56 +0000 (15:11 -0500)
committerEric Sandeen <sandeen@redhat.com>
Thu, 28 Jun 2018 20:11:56 +0000 (15:11 -0500)
Source kernel commit: 9f3a080ef19b1c182a8fb1edbfb707fdb811437c

This function is basically a generic AGFL block iterator, so promote it
to libxfs ahead of online repair wanting to use it.

Signed-off-by: Darrick J. Wong <darrick.wong@oracle.com>
Reviewed-by: Brian Foster <bfoster@redhat.com>
Signed-off-by: Eric Sandeen <sandeen@sandeen.net>
libxfs/xfs_alloc.c
libxfs/xfs_alloc.h

index a5a65849a9b33467ba8b6fe81ec9f57f233fc867..5205d5ce06bd3b4ff651231425e7f833b479ff0e 100644 (file)
@@ -3177,3 +3177,40 @@ xfs_alloc_has_record(
 
        return xfs_btree_has_record(cur, &low, &high, exists);
 }
+
+/*
+ * Walk all the blocks in the AGFL.  The @walk_fn can return any negative
+ * error code or XFS_BTREE_QUERY_RANGE_ABORT.
+ */
+int
+xfs_agfl_walk(
+       struct xfs_mount        *mp,
+       struct xfs_agf          *agf,
+       struct xfs_buf          *agflbp,
+       xfs_agfl_walk_fn        walk_fn,
+       void                    *priv)
+{
+       __be32                  *agfl_bno;
+       unsigned int            i;
+       int                     error;
+
+       agfl_bno = XFS_BUF_TO_AGFL_BNO(mp, agflbp);
+       i = be32_to_cpu(agf->agf_flfirst);
+
+       /* Nothing to walk in an empty AGFL. */
+       if (agf->agf_flcount == cpu_to_be32(0))
+               return 0;
+
+       /* Otherwise, walk from first to last, wrapping as needed. */
+       for (;;) {
+               error = walk_fn(mp, be32_to_cpu(agfl_bno[i]), priv);
+               if (error)
+                       return error;
+               if (i == be32_to_cpu(agf->agf_fllast))
+                       break;
+               if (++i == xfs_agfl_size(mp))
+                       i = 0;
+       }
+
+       return 0;
+}
index 46d48c6f83b7bad9100b4479b6bd02a1845338ec..0747adcd57d63acc66c441e10a028710dab21ef4 100644 (file)
@@ -262,4 +262,9 @@ bool xfs_verify_fsbno(struct xfs_mount *mp, xfs_fsblock_t fsbno);
 int xfs_alloc_has_record(struct xfs_btree_cur *cur, xfs_agblock_t bno,
                xfs_extlen_t len, bool *exist);
 
+typedef int (*xfs_agfl_walk_fn)(struct xfs_mount *mp, xfs_agblock_t bno,
+               void *priv);
+int xfs_agfl_walk(struct xfs_mount *mp, struct xfs_agf *agf,
+               struct xfs_buf *agflbp, xfs_agfl_walk_fn walk_fn, void *priv);
+
 #endif /* __XFS_ALLOC_H__ */