]> git.ipfire.org Git - thirdparty/xfsprogs-dev.git/commitdiff
xfs: pass perag to xfs_ialloc_read_agi()
authorDave Chinner <dchinner@redhat.com>
Mon, 22 Aug 2022 10:50:59 +0000 (12:50 +0200)
committerCarlos Maiolino <cem@kernel.org>
Tue, 30 Aug 2022 07:47:10 +0000 (09:47 +0200)
Source kernel commit: 99b13c7f0bd35dd3cf2cacb61beb4557dc2b6f9b

xfs_ialloc_read_agi() initialises the perag if it hasn't been done
yet, so it makes sense to pass it the perag rather than pull a
reference from the buffer. This allows callers to be per-ag centric
rather than passing mount/agno pairs everywhere.

Signed-off-by: Dave Chinner <dchinner@redhat.com>
Reviewed-by: Christoph Hellwig <hch@lst.de>
Reviewed-by: Darrick J. Wong <djwong@kernel.org>
Signed-off-by: Carlos Maiolino <cem@kernel.org>
libxfs/xfs_ag.c
libxfs/xfs_ialloc.c
libxfs/xfs_ialloc.h
libxfs/xfs_ialloc_btree.c

index fa884ae7cb2a52d9f096d6badf503c262e114ab1..904e82703d1039d98ba30099738e3b8fabd9ec8b 100644 (file)
@@ -126,11 +126,13 @@ xfs_initialize_perag_data(
                if (error)
                        return error;
 
-               error = xfs_ialloc_read_agi(mp, NULL, index, NULL);
-               if (error)
+               pag = xfs_perag_get(mp, index);
+               error = xfs_ialloc_read_agi(pag, NULL, NULL);
+               if (error) {
+                       xfs_perag_put(pag);
                        return error;
+               }
 
-               pag = xfs_perag_get(mp, index);
                ifree += pag->pagi_freecount;
                ialloc += pag->pagi_count;
                bfree += pag->pagf_freeblks;
@@ -782,7 +784,7 @@ xfs_ag_shrink_space(
        int                     error, err2;
 
        ASSERT(pag->pag_agno == mp->m_sb.sb_agcount - 1);
-       error = xfs_ialloc_read_agi(mp, *tpp, pag->pag_agno, &agibp);
+       error = xfs_ialloc_read_agi(pag, *tpp, &agibp);
        if (error)
                return error;
 
@@ -815,7 +817,7 @@ xfs_ag_shrink_space(
         * Disable perag reservations so it doesn't cause the allocation request
         * to fail. We'll reestablish reservation before we return.
         */
-       error = xfs_ag_resv_free(agibp->b_pag);
+       error = xfs_ag_resv_free(pag);
        if (error)
                return error;
 
@@ -844,7 +846,7 @@ xfs_ag_shrink_space(
        be32_add_cpu(&agi->agi_length, -delta);
        be32_add_cpu(&agf->agf_length, -delta);
 
-       err2 = xfs_ag_resv_init(agibp->b_pag, *tpp);
+       err2 = xfs_ag_resv_init(pag, *tpp);
        if (err2) {
                be32_add_cpu(&agi->agi_length, delta);
                be32_add_cpu(&agf->agf_length, delta);
@@ -868,8 +870,9 @@ xfs_ag_shrink_space(
        xfs_ialloc_log_agi(*tpp, agibp, XFS_AGI_LENGTH);
        xfs_alloc_log_agf(*tpp, agfbp, XFS_AGF_LENGTH);
        return 0;
+
 resv_init_out:
-       err2 = xfs_ag_resv_init(agibp->b_pag, *tpp);
+       err2 = xfs_ag_resv_init(pag, *tpp);
        if (!err2)
                return error;
 resv_err:
@@ -894,7 +897,7 @@ xfs_ag_extend_space(
 
        ASSERT(pag->pag_agno == pag->pag_mount->m_sb.sb_agcount - 1);
 
-       error = xfs_ialloc_read_agi(pag->pag_mount, tp, pag->pag_agno, &bp);
+       error = xfs_ialloc_read_agi(pag, tp, &bp);
        if (error)
                return error;
 
@@ -945,8 +948,7 @@ xfs_ag_get_geometry(
        int                     error;
 
        /* Lock the AG headers. */
-       error = xfs_ialloc_read_agi(pag->pag_mount, NULL, pag->pag_agno,
-                       &agi_bp);
+       error = xfs_ialloc_read_agi(pag, NULL, &agi_bp);
        if (error)
                return error;
        error = xfs_alloc_read_agf(pag->pag_mount, NULL, pag->pag_agno, 0,
index f2ab1d424a1545df3880b254f2c98cc9dcd16a98..4ccc6b5977dfbecf7f769ef87b62fa975181b22a 100644 (file)
@@ -1605,7 +1605,7 @@ xfs_dialloc_good_ag(
                return false;
 
        if (!pag->pagi_init) {
-               error = xfs_ialloc_read_agi(mp, tp, pag->pag_agno, NULL);
+               error = xfs_ialloc_read_agi(pag, tp, NULL);
                if (error)
                        return false;
        }
@@ -1674,7 +1674,7 @@ xfs_dialloc_try_ag(
         * Then read in the AGI buffer and recheck with the AGI buffer
         * lock held.
         */
-       error = xfs_ialloc_read_agi(pag->pag_mount, *tpp, pag->pag_agno, &agbp);
+       error = xfs_ialloc_read_agi(pag, *tpp, &agbp);
        if (error)
                return error;
 
@@ -2164,7 +2164,7 @@ xfs_difree(
        /*
         * Get the allocation group header.
         */
-       error = xfs_ialloc_read_agi(mp, tp, pag->pag_agno, &agbp);
+       error = xfs_ialloc_read_agi(pag, tp, &agbp);
        if (error) {
                xfs_warn(mp, "%s: xfs_ialloc_read_agi() returned error %d.",
                        __func__, error);
@@ -2210,7 +2210,7 @@ xfs_imap_lookup(
        int                     error;
        int                     i;
 
-       error = xfs_ialloc_read_agi(mp, tp, pag->pag_agno, &agbp);
+       error = xfs_ialloc_read_agi(pag, tp, &agbp);
        if (error) {
                xfs_alert(mp,
                        "%s: xfs_ialloc_read_agi() returned error %d, agno %d",
@@ -2594,24 +2594,21 @@ xfs_read_agi(
  */
 int
 xfs_ialloc_read_agi(
-       struct xfs_mount        *mp,    /* file system mount structure */
-       struct xfs_trans        *tp,    /* transaction pointer */
-       xfs_agnumber_t          agno,   /* allocation group number */
+       struct xfs_perag        *pag,
+       struct xfs_trans        *tp,
        struct xfs_buf          **agibpp)
 {
        struct xfs_buf          *agibp;
-       struct xfs_agi          *agi;   /* allocation group header */
-       struct xfs_perag        *pag;   /* per allocation group data */
+       struct xfs_agi          *agi;
        int                     error;
 
-       trace_xfs_ialloc_read_agi(mp, agno);
+       trace_xfs_ialloc_read_agi(pag->pag_mount, pag->pag_agno);
 
-       error = xfs_read_agi(mp, tp, agno, &agibp);
+       error = xfs_read_agi(pag->pag_mount, tp, pag->pag_agno, &agibp);
        if (error)
                return error;
 
        agi = agibp->b_addr;
-       pag = agibp->b_pag;
        if (!pag->pagi_init) {
                pag->pagi_freecount = be32_to_cpu(agi->agi_freecount);
                pag->pagi_count = be32_to_cpu(agi->agi_count);
@@ -2623,7 +2620,7 @@ xfs_ialloc_read_agi(
         * we are in the middle of a forced shutdown.
         */
        ASSERT(pag->pagi_freecount == be32_to_cpu(agi->agi_freecount) ||
-               xfs_is_shutdown(mp));
+               xfs_is_shutdown(pag->pag_mount));
        if (agibpp)
                *agibpp = agibp;
        else
index 1ff42bf1e4b33c1c2d301e52549d59131a9cd30a..72cb33170d9fe35e8f1dafc87e1feeb1cd3790c6 100644 (file)
@@ -66,11 +66,8 @@ xfs_ialloc_log_agi(
  * Read in the allocation group header (inode allocation section)
  */
 int                                    /* error */
-xfs_ialloc_read_agi(
-       struct xfs_mount *mp,           /* file system mount structure */
-       struct xfs_trans *tp,           /* transaction pointer */
-       xfs_agnumber_t  agno,           /* allocation group number */
-       struct xfs_buf  **bpp);         /* allocation group hdr buf */
+xfs_ialloc_read_agi(struct xfs_perag *pag, struct xfs_trans *tp,
+               struct xfs_buf **agibpp);
 
 /*
  * Lookup a record by ino in the btree given by cur.
index 1dbb536089107995be448c621faaafaaa6187889..fe8df688b0ecb2e6fa6eed8a7851954fd4ac7118 100644 (file)
@@ -721,7 +721,7 @@ xfs_inobt_cur(
        ASSERT(*agi_bpp == NULL);
        ASSERT(*curpp == NULL);
 
-       error = xfs_ialloc_read_agi(mp, tp, pag->pag_agno, agi_bpp);
+       error = xfs_ialloc_read_agi(pag, tp, agi_bpp);
        if (error)
                return error;
 
@@ -756,16 +756,15 @@ xfs_inobt_count_blocks(
 /* Read finobt block count from AGI header. */
 static int
 xfs_finobt_read_blocks(
-       struct xfs_mount        *mp,
-       struct xfs_trans        *tp,
        struct xfs_perag        *pag,
+       struct xfs_trans        *tp,
        xfs_extlen_t            *tree_blocks)
 {
        struct xfs_buf          *agbp;
        struct xfs_agi          *agi;
        int                     error;
 
-       error = xfs_ialloc_read_agi(mp, tp, pag->pag_agno, &agbp);
+       error = xfs_ialloc_read_agi(pag, tp, &agbp);
        if (error)
                return error;
 
@@ -793,7 +792,7 @@ xfs_finobt_calc_reserves(
                return 0;
 
        if (xfs_has_inobtcounts(mp))
-               error = xfs_finobt_read_blocks(mp, tp, pag, &tree_len);
+               error = xfs_finobt_read_blocks(pag, tp, &tree_len);
        else
                error = xfs_inobt_count_blocks(mp, tp, pag, XFS_BTNUM_FINO,
                                &tree_len);