xfs: replace xfs_sb_version checks with feature flag checks
[linux-2.6-microblaze.git] / fs / xfs / scrub / common.c
index 8558ca0..26e38b5 100644 (file)
@@ -324,7 +324,7 @@ struct xchk_rmap_ownedby_info {
 STATIC int
 xchk_count_rmap_ownedby_irec(
        struct xfs_btree_cur            *cur,
-       struct xfs_rmap_irec            *rec,
+       const struct xfs_rmap_irec      *rec,
        void                            *priv)
 {
        struct xchk_rmap_ownedby_info   *sroi = priv;
@@ -394,11 +394,11 @@ want_ag_read_header_failure(
 }
 
 /*
- * Grab all the headers for an AG.
+ * Grab the perag structure and all the headers for an AG.
  *
- * The headers should be released by xchk_ag_free, but as a fail
- * safe we attach all the buffers we grab to the scrub transaction so
- * they'll all be freed when we cancel it.
+ * The headers should be released by xchk_ag_free, but as a fail safe we attach
+ * all the buffers we grab to the scrub transaction so they'll all be freed
+ * when we cancel it.  Returns ENOENT if we can't grab the perag structure.
  */
 int
 xchk_ag_read_headers(
@@ -409,22 +409,24 @@ xchk_ag_read_headers(
        struct xfs_mount        *mp = sc->mp;
        int                     error;
 
-       sa->agno = agno;
+       ASSERT(!sa->pag);
+       sa->pag = xfs_perag_get(mp, agno);
+       if (!sa->pag)
+               return -ENOENT;
 
        error = xfs_ialloc_read_agi(mp, sc->tp, agno, &sa->agi_bp);
        if (error && want_ag_read_header_failure(sc, XFS_SCRUB_TYPE_AGI))
-               goto out;
+               return error;
 
        error = xfs_alloc_read_agf(mp, sc->tp, agno, 0, &sa->agf_bp);
        if (error && want_ag_read_header_failure(sc, XFS_SCRUB_TYPE_AGF))
-               goto out;
+               return error;
 
        error = xfs_alloc_read_agfl(mp, sc->tp, agno, &sa->agfl_bp);
        if (error && want_ag_read_header_failure(sc, XFS_SCRUB_TYPE_AGFL))
-               goto out;
-       error = 0;
-out:
-       return error;
+               return error;
+
+       return 0;
 }
 
 /* Release all the AG btree cursors. */
@@ -461,7 +463,6 @@ xchk_ag_btcur_init(
 {
        struct xfs_mount        *mp = sc->mp;
 
-       xchk_perag_get(sc->mp, sa);
        if (sa->agf_bp &&
            xchk_ag_btree_healthy_enough(sc, sa->pag, XFS_BTNUM_BNO)) {
                /* Set up a bnobt cursor for cross-referencing. */
@@ -528,15 +529,14 @@ xchk_ag_free(
                xfs_perag_put(sa->pag);
                sa->pag = NULL;
        }
-       sa->agno = NULLAGNUMBER;
 }
 
 /*
- * For scrub, grab the AGI and the AGF headers, in that order.  Locking
- * order requires us to get the AGI before the AGF.  We use the
- * transaction to avoid deadlocking on crosslinked metadata buffers;
- * either the caller passes one in (bmap scrub) or we have to create a
- * transaction ourselves.
+ * For scrub, grab the perag structure, the AGI, and the AGF headers, in that
+ * order.  Locking order requires us to get the AGI before the AGF.  We use the
+ * transaction to avoid deadlocking on crosslinked metadata buffers; either the
+ * caller passes one in (bmap scrub) or we have to create a transaction
+ * ourselves.  Returns ENOENT if the perag struct cannot be grabbed.
  */
 int
 xchk_ag_init(
@@ -554,19 +554,6 @@ xchk_ag_init(
        return 0;
 }
 
-/*
- * Grab the per-ag structure if we haven't already gotten it.  Teardown of the
- * xchk_ag will release it for us.
- */
-void
-xchk_perag_get(
-       struct xfs_mount        *mp,
-       struct xchk_ag          *sa)
-{
-       if (!sa->pag)
-               sa->pag = xfs_perag_get(mp, sa->agno);
-}
-
 /* Per-scrubber setup functions */
 
 /*
@@ -842,7 +829,7 @@ xchk_metadata_inode_forks(
                return error;
 
        /* Look for incorrect shared blocks. */
-       if (xfs_sb_version_hasreflink(&sc->mp->m_sb)) {
+       if (xfs_has_reflink(sc->mp)) {
                error = xfs_reflink_inode_has_shared_extents(sc->tp, sc->ip,
                                &shared);
                if (!xchk_fblock_process_error(sc, XFS_DATA_FORK, 0,
@@ -884,6 +871,7 @@ xchk_stop_reaping(
 {
        sc->flags |= XCHK_REAPING_DISABLED;
        xfs_blockgc_stop(sc->mp);
+       xfs_inodegc_stop(sc->mp);
 }
 
 /* Restart background reaping of resources. */
@@ -891,6 +879,13 @@ void
 xchk_start_reaping(
        struct xfs_scrub        *sc)
 {
-       xfs_blockgc_start(sc->mp);
+       /*
+        * Readonly filesystems do not perform inactivation or speculative
+        * preallocation, so there's no need to restart the workers.
+        */
+       if (!(sc->mp->m_flags & XFS_MOUNT_RDONLY)) {
+               xfs_inodegc_start(sc->mp);
+               xfs_blockgc_start(sc->mp);
+       }
        sc->flags &= ~XCHK_REAPING_DISABLED;
 }