]> www.infradead.org Git - linux.git/commitdiff
xfs: hide xfs_inode_is_allocated in scrub common code
authorDarrick J. Wong <djwong@kernel.org>
Thu, 10 Aug 2023 14:48:12 +0000 (07:48 -0700)
committerDarrick J. Wong <djwong@kernel.org>
Thu, 10 Aug 2023 14:48:12 +0000 (07:48 -0700)
This function is only used by online fsck, so let's move it there.
In the next patch, we'll fix it to work properly and to require that the
caller hold the AGI buffer locked.  No major changes aside from
adjusting the signature a bit.

Signed-off-by: Darrick J. Wong <djwong@kernel.org>
Reviewed-by: Dave Chinner <dchinner@redhat.com>
fs/xfs/scrub/common.c
fs/xfs/scrub/common.h
fs/xfs/scrub/ialloc.c
fs/xfs/xfs_icache.c
fs/xfs/xfs_icache.h

index 82d2a85d6461866b9617acc4b0f47f9a6fcf5f8b..3ba329526266cda2de8e86cc69a7771dada51944 100644 (file)
@@ -1230,3 +1230,40 @@ xchk_fsgates_enable(
 
        sc->flags |= scrub_fsgates;
 }
+
+/*
+ * Decide if this is this a cached inode that's also allocated.
+ *
+ * Look up an inode by number in the given file system.  If the inode is
+ * in cache and isn't in purgatory, return 1 if the inode is allocated
+ * and 0 if it is not.  For all other cases (not in cache, being torn
+ * down, etc.), return a negative error code.
+ *
+ * The caller has to prevent inode allocation and freeing activity,
+ * presumably by locking the AGI buffer.   This is to ensure that an
+ * inode cannot transition from allocated to freed until the caller is
+ * ready to allow that.  If the inode is in an intermediate state (new,
+ * reclaimable, or being reclaimed), -EAGAIN will be returned; if the
+ * inode is not in the cache, -ENOENT will be returned.  The caller must
+ * deal with these scenarios appropriately.
+ *
+ * This is a specialized use case for the online scrubber; if you're
+ * reading this, you probably want xfs_iget.
+ */
+int
+xchk_inode_is_allocated(
+       struct xfs_scrub        *sc,
+       xfs_ino_t               ino,
+       bool                    *inuse)
+{
+       struct xfs_inode        *ip;
+       int                     error;
+
+       error = xfs_iget(sc->mp, sc->tp, ino, XFS_IGET_INCORE, 0, &ip);
+       if (error)
+               return error;
+
+       *inuse = !!(VFS_I(ip)->i_mode);
+       xfs_irele(ip);
+       return 0;
+}
index 4f7cb410904d6025bf6ac4c52142da365d7690f7..a2d2e0749554e17e1bbc036cf70e853d4c28dc3f 100644 (file)
@@ -203,4 +203,6 @@ static inline bool xchk_need_intent_drain(struct xfs_scrub *sc)
 
 void xchk_fsgates_enable(struct xfs_scrub *sc, unsigned int scrub_fshooks);
 
+int xchk_inode_is_allocated(struct xfs_scrub *sc, xfs_ino_t ino, bool *inuse);
+
 #endif /* __XFS_SCRUB_COMMON_H__ */
index 575f22a02ebe526f4d68fcf4ea0ff00b068ef64b..3a3d750b02e0e1fc89197ef664b41468e73e29f4 100644 (file)
@@ -328,8 +328,7 @@ xchk_iallocbt_check_cluster_ifree(
                goto out;
        }
 
-       error = xfs_icache_inode_is_allocated(mp, bs->cur->bc_tp, fsino,
-                       &ino_inuse);
+       error = xchk_inode_is_allocated(bs->sc, fsino, &ino_inuse);
        if (error == -ENODATA) {
                /* Not cached, just read the disk buffer */
                freemask_ok = irec_free ^ !!(dip->di_mode);
index 453890942d9f556424cac0a394945f05aa057ac3..e541f5c0bc251c4a1e2d74b3094e32f30b6ccd94 100644 (file)
@@ -802,44 +802,6 @@ out_error_or_again:
        return error;
 }
 
-/*
- * "Is this a cached inode that's also allocated?"
- *
- * Look up an inode by number in the given file system.  If the inode is
- * in cache and isn't in purgatory, return 1 if the inode is allocated
- * and 0 if it is not.  For all other cases (not in cache, being torn
- * down, etc.), return a negative error code.
- *
- * The caller has to prevent inode allocation and freeing activity,
- * presumably by locking the AGI buffer.   This is to ensure that an
- * inode cannot transition from allocated to freed until the caller is
- * ready to allow that.  If the inode is in an intermediate state (new,
- * reclaimable, or being reclaimed), -EAGAIN will be returned; if the
- * inode is not in the cache, -ENOENT will be returned.  The caller must
- * deal with these scenarios appropriately.
- *
- * This is a specialized use case for the online scrubber; if you're
- * reading this, you probably want xfs_iget.
- */
-int
-xfs_icache_inode_is_allocated(
-       struct xfs_mount        *mp,
-       struct xfs_trans        *tp,
-       xfs_ino_t               ino,
-       bool                    *inuse)
-{
-       struct xfs_inode        *ip;
-       int                     error;
-
-       error = xfs_iget(mp, tp, ino, XFS_IGET_INCORE, 0, &ip);
-       if (error)
-               return error;
-
-       *inuse = !!(VFS_I(ip)->i_mode);
-       xfs_irele(ip);
-       return 0;
-}
-
 /*
  * Grab the inode for reclaim exclusively.
  *
index 1dcdcb23796edb848e2a4f444ec35f0998d37558..2fa6f2e09d078a2a884bf1bc88bec960eeea92aa 100644 (file)
@@ -71,10 +71,6 @@ void xfs_inode_set_cowblocks_tag(struct xfs_inode *ip);
 void xfs_inode_clear_cowblocks_tag(struct xfs_inode *ip);
 
 void xfs_blockgc_worker(struct work_struct *work);
-
-int xfs_icache_inode_is_allocated(struct xfs_mount *mp, struct xfs_trans *tp,
-                                 xfs_ino_t ino, bool *inuse);
-
 void xfs_blockgc_stop(struct xfs_mount *mp);
 void xfs_blockgc_start(struct xfs_mount *mp);