]> git.ipfire.org Git - thirdparty/linux.git/commitdiff
xfs: merge the perag freeing helpers
authorChristoph Hellwig <hch@lst.de>
Mon, 14 Oct 2024 06:04:51 +0000 (08:04 +0200)
committerCarlos Maiolino <cem@kernel.org>
Tue, 22 Oct 2024 11:37:18 +0000 (13:37 +0200)
There is no good reason to have two different routines for freeing perag
structures for the unmount and error cases.  Add two arguments to specify
the range of AGs to free to xfs_free_perag, and use that to replace
xfs_free_unused_perag_range.

The addition RCU grace period for the error case is harmless, and the
extra check for the AG to actually exist is not required now that the
callers pass the exact known allocated range.

Signed-off-by: Christoph Hellwig <hch@lst.de>
Reviewed-by: Brian Foster <bfoster@redhat.com>
Reviewed-by: Darrick J. Wong <djwong@kernel.org>
Signed-off-by: Carlos Maiolino <cem@kernel.org>
fs/xfs/libxfs/xfs_ag.c
fs/xfs/libxfs/xfs_ag.h
fs/xfs/xfs_fsops.c
fs/xfs/xfs_mount.c

index 464f682eab4690fe22db1db5ce1e3708e0a9e82f..8ace2cc200a60e8b979e3dc86183c19d7564645f 100644 (file)
@@ -185,17 +185,20 @@ out:
 }
 
 /*
- * Free up the per-ag resources associated with the mount structure.
+ * Free up the per-ag resources  within the specified AG range.
  */
 void
-xfs_free_perag(
-       struct xfs_mount        *mp)
+xfs_free_perag_range(
+       struct xfs_mount        *mp,
+       xfs_agnumber_t          first_agno,
+       xfs_agnumber_t          end_agno)
+
 {
-       struct xfs_perag        *pag;
        xfs_agnumber_t          agno;
 
-       for (agno = 0; agno < mp->m_sb.sb_agcount; agno++) {
-               pag = xa_erase(&mp->m_perags, agno);
+       for (agno = first_agno; agno < end_agno; agno++) {
+               struct xfs_perag        *pag = xa_erase(&mp->m_perags, agno);
+
                ASSERT(pag);
                XFS_IS_CORRUPT(pag->pag_mount, atomic_read(&pag->pag_ref) != 0);
                xfs_defer_drain_free(&pag->pag_intents_drain);
@@ -270,29 +273,6 @@ xfs_agino_range(
        return __xfs_agino_range(mp, xfs_ag_block_count(mp, agno), first, last);
 }
 
-/*
- * Free perag within the specified AG range, it is only used to free unused
- * perags under the error handling path.
- */
-void
-xfs_free_unused_perag_range(
-       struct xfs_mount        *mp,
-       xfs_agnumber_t          agstart,
-       xfs_agnumber_t          agend)
-{
-       struct xfs_perag        *pag;
-       xfs_agnumber_t          index;
-
-       for (index = agstart; index < agend; index++) {
-               pag = xa_erase(&mp->m_perags, index);
-               if (!pag)
-                       break;
-               xfs_buf_cache_destroy(&pag->pag_bcache);
-               xfs_defer_drain_free(&pag->pag_intents_drain);
-               kfree(pag);
-       }
-}
-
 int
 xfs_initialize_perag(
        struct xfs_mount        *mp,
@@ -366,7 +346,7 @@ out_remove_pag:
 out_free_pag:
        kfree(pag);
 out_unwind_new_pags:
-       xfs_free_unused_perag_range(mp, old_agcount, index);
+       xfs_free_perag_range(mp, old_agcount, index);
        return error;
 }
 
index 69fc31e7b8472832c23d63091737399e46158983..6e68d6a3161a0f98638ce381ef487a0bd1f72d9a 100644 (file)
@@ -144,13 +144,12 @@ __XFS_AG_OPSTATE(prefers_metadata, PREFERS_METADATA)
 __XFS_AG_OPSTATE(allows_inodes, ALLOWS_INODES)
 __XFS_AG_OPSTATE(agfl_needs_reset, AGFL_NEEDS_RESET)
 
-void xfs_free_unused_perag_range(struct xfs_mount *mp, xfs_agnumber_t agstart,
-                       xfs_agnumber_t agend);
 int xfs_initialize_perag(struct xfs_mount *mp, xfs_agnumber_t old_agcount,
                xfs_agnumber_t agcount, xfs_rfsblock_t dcount,
                xfs_agnumber_t *maxagi);
+void xfs_free_perag_range(struct xfs_mount *mp, xfs_agnumber_t first_agno,
+               xfs_agnumber_t end_agno);
 int xfs_initialize_perag_data(struct xfs_mount *mp, xfs_agnumber_t agno);
-void xfs_free_perag(struct xfs_mount *mp);
 
 /* Passive AG references */
 struct xfs_perag *xfs_perag_get(struct xfs_mount *mp, xfs_agnumber_t agno);
index de2bf0594cb47489f2cf7977d48a84d452086f89..b247d895c276d2b436eafe16c1d8611422c531b7 100644 (file)
@@ -229,7 +229,7 @@ out_trans_cancel:
        xfs_trans_cancel(tp);
 out_free_unused_perag:
        if (nagcount > oagcount)
-               xfs_free_unused_perag_range(mp, oagcount, nagcount);
+               xfs_free_perag_range(mp, oagcount, nagcount);
        return error;
 }
 
index 6fa7239a4a01b630dea6def67292182c6a593d87..25bbcc3f4ee08ba57b7525261483f975455c5de2 100644 (file)
@@ -1048,7 +1048,7 @@ xfs_mountfs(
                xfs_buftarg_drain(mp->m_logdev_targp);
        xfs_buftarg_drain(mp->m_ddev_targp);
  out_free_perag:
-       xfs_free_perag(mp);
+       xfs_free_perag_range(mp, 0, mp->m_sb.sb_agcount);
  out_free_dir:
        xfs_da_unmount(mp);
  out_remove_uuid:
@@ -1129,8 +1129,7 @@ xfs_unmountfs(
        xfs_errortag_clearall(mp);
 #endif
        shrinker_free(mp->m_inodegc_shrinker);
-       xfs_free_perag(mp);
-
+       xfs_free_perag_range(mp, 0, mp->m_sb.sb_agcount);
        xfs_errortag_del(mp);
        xfs_error_sysfs_del(mp);
        xchk_stats_unregister(mp->m_scrub_stats);