Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

xfs: pass perag to xfs_alloc_read_agf()

xfs_alloc_read_agf() 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.

Whilst modifying the xfs_reflink_find_shared() function definition,
declare it static and remove the extern declaration as it is an
internal function only these days.

Signed-off-by: Dave Chinner <dchinner@redhat.com>
Reviewed-by: Christoph Hellwig <hch@lst.de>
Reviewed-by: Darrick J. Wong <djwong@kernel.org>

authored by

Dave Chinner and committed by
Dave Chinner
08d3e84f 76b47e52

+70 -83
+8 -12
fs/xfs/libxfs/xfs_ag.c
··· 120 120 121 121 for (index = 0; index < agcount; index++) { 122 122 /* 123 - * read the agf, then the agi. This gets us 124 - * all the information we need and populates the 125 - * per-ag structures for us. 123 + * Read the AGF and AGI buffers to populate the per-ag 124 + * structures for us. 126 125 */ 127 - error = xfs_alloc_read_agf(mp, NULL, index, 0, NULL); 128 - if (error) 129 - return error; 130 - 131 126 pag = xfs_perag_get(mp, index); 132 - error = xfs_ialloc_read_agi(pag, NULL, NULL); 127 + error = xfs_alloc_read_agf(pag, NULL, 0, NULL); 128 + if (!error) 129 + error = xfs_ialloc_read_agi(pag, NULL, NULL); 133 130 if (error) { 134 131 xfs_perag_put(pag); 135 132 return error; ··· 789 792 790 793 agi = agibp->b_addr; 791 794 792 - error = xfs_alloc_read_agf(mp, *tpp, pag->pag_agno, 0, &agfbp); 795 + error = xfs_alloc_read_agf(pag, *tpp, 0, &agfbp); 793 796 if (error) 794 797 return error; 795 798 ··· 907 910 /* 908 911 * Change agf length. 909 912 */ 910 - error = xfs_alloc_read_agf(pag->pag_mount, tp, pag->pag_agno, 0, &bp); 913 + error = xfs_alloc_read_agf(pag, tp, 0, &bp); 911 914 if (error) 912 915 return error; 913 916 ··· 950 953 error = xfs_ialloc_read_agi(pag, NULL, &agi_bp); 951 954 if (error) 952 955 return error; 953 - error = xfs_alloc_read_agf(pag->pag_mount, NULL, pag->pag_agno, 0, 954 - &agf_bp); 956 + error = xfs_alloc_read_agf(pag, NULL, 0, &agf_bp); 955 957 if (error) 956 958 goto out_agi; 957 959
+1 -1
fs/xfs/libxfs/xfs_ag_resv.c
··· 322 322 * address. 323 323 */ 324 324 if (has_resv) { 325 - error2 = xfs_alloc_read_agf(mp, tp, pag->pag_agno, 0, NULL); 325 + error2 = xfs_alloc_read_agf(pag, tp, 0, NULL); 326 326 if (error2) 327 327 return error2; 328 328
+14 -17
fs/xfs/libxfs/xfs_alloc.c
··· 2609 2609 ASSERT(tp->t_flags & XFS_TRANS_PERM_LOG_RES); 2610 2610 2611 2611 if (!pag->pagf_init) { 2612 - error = xfs_alloc_read_agf(mp, tp, args->agno, flags, &agbp); 2612 + error = xfs_alloc_read_agf(pag, tp, flags, &agbp); 2613 2613 if (error) { 2614 2614 /* Couldn't lock the AGF so skip this AG. */ 2615 2615 if (error == -EAGAIN) ··· 2639 2639 * Can fail if we're not blocking on locks, and it's held. 2640 2640 */ 2641 2641 if (!agbp) { 2642 - error = xfs_alloc_read_agf(mp, tp, args->agno, flags, &agbp); 2642 + error = xfs_alloc_read_agf(pag, tp, flags, &agbp); 2643 2643 if (error) { 2644 2644 /* Couldn't lock the AGF so skip this AG. */ 2645 2645 if (error == -EAGAIN) ··· 3080 3080 * perag structure if necessary. If the caller provides @agfbpp, then return the 3081 3081 * locked buffer to the caller, otherwise free it. 3082 3082 */ 3083 - int /* error */ 3083 + int 3084 3084 xfs_alloc_read_agf( 3085 - struct xfs_mount *mp, /* mount point structure */ 3086 - struct xfs_trans *tp, /* transaction pointer */ 3087 - xfs_agnumber_t agno, /* allocation group number */ 3088 - int flags, /* XFS_ALLOC_FLAG_... */ 3085 + struct xfs_perag *pag, 3086 + struct xfs_trans *tp, 3087 + int flags, 3089 3088 struct xfs_buf **agfbpp) 3090 3089 { 3091 3090 struct xfs_buf *agfbp; 3092 - struct xfs_agf *agf; /* ag freelist header */ 3093 - struct xfs_perag *pag; /* per allocation group data */ 3091 + struct xfs_agf *agf; 3094 3092 int error; 3095 3093 int allocbt_blks; 3096 3094 3097 - trace_xfs_alloc_read_agf(mp, agno); 3095 + trace_xfs_alloc_read_agf(pag->pag_mount, pag->pag_agno); 3098 3096 3099 3097 /* We don't support trylock when freeing. */ 3100 3098 ASSERT((flags & (XFS_ALLOC_FLAG_FREEING | XFS_ALLOC_FLAG_TRYLOCK)) != 3101 3099 (XFS_ALLOC_FLAG_FREEING | XFS_ALLOC_FLAG_TRYLOCK)); 3102 - ASSERT(agno != NULLAGNUMBER); 3103 - error = xfs_read_agf(mp, tp, agno, 3100 + error = xfs_read_agf(pag->pag_mount, tp, pag->pag_agno, 3104 3101 (flags & XFS_ALLOC_FLAG_TRYLOCK) ? XBF_TRYLOCK : 0, 3105 3102 &agfbp); 3106 3103 if (error) 3107 3104 return error; 3108 3105 3109 3106 agf = agfbp->b_addr; 3110 - pag = agfbp->b_pag; 3111 3107 if (!pag->pagf_init) { 3112 3108 pag->pagf_freeblks = be32_to_cpu(agf->agf_freeblks); 3113 3109 pag->pagf_btreeblks = be32_to_cpu(agf->agf_btreeblks); ··· 3117 3121 be32_to_cpu(agf->agf_levels[XFS_BTNUM_RMAPi]); 3118 3122 pag->pagf_refcount_level = be32_to_cpu(agf->agf_refcount_level); 3119 3123 pag->pagf_init = 1; 3120 - pag->pagf_agflreset = xfs_agfl_needs_reset(mp, agf); 3124 + pag->pagf_agflreset = xfs_agfl_needs_reset(pag->pag_mount, agf); 3121 3125 3122 3126 /* 3123 3127 * Update the in-core allocbt counter. Filter out the rmapbt ··· 3127 3131 * counter only tracks non-root blocks. 3128 3132 */ 3129 3133 allocbt_blks = pag->pagf_btreeblks; 3130 - if (xfs_has_rmapbt(mp)) 3134 + if (xfs_has_rmapbt(pag->pag_mount)) 3131 3135 allocbt_blks -= be32_to_cpu(agf->agf_rmap_blocks) - 1; 3132 3136 if (allocbt_blks > 0) 3133 - atomic64_add(allocbt_blks, &mp->m_allocbt_blks); 3137 + atomic64_add(allocbt_blks, 3138 + &pag->pag_mount->m_allocbt_blks); 3134 3139 } 3135 3140 #ifdef DEBUG 3136 - else if (!xfs_is_shutdown(mp)) { 3141 + else if (!xfs_is_shutdown(pag->pag_mount)) { 3137 3142 ASSERT(pag->pagf_freeblks == be32_to_cpu(agf->agf_freeblks)); 3138 3143 ASSERT(pag->pagf_btreeblks == be32_to_cpu(agf->agf_btreeblks)); 3139 3144 ASSERT(pag->pagf_flcount == be32_to_cpu(agf->agf_flcount));
+2 -11
fs/xfs/libxfs/xfs_alloc.h
··· 135 135 int btreeblk); /* owner was a AGF btree */ 136 136 137 137 /* 138 - * Read in the allocation group header (free/alloc section). 139 - */ 140 - int /* error */ 141 - xfs_alloc_read_agf( 142 - struct xfs_mount *mp, /* mount point structure */ 143 - struct xfs_trans *tp, /* transaction pointer */ 144 - xfs_agnumber_t agno, /* allocation group number */ 145 - int flags, /* XFS_ALLOC_FLAG_... */ 146 - struct xfs_buf **bpp); /* buffer for the ag freelist header */ 147 - 148 - /* 149 138 * Allocate an extent (variable-size). 150 139 */ 151 140 int /* error */ ··· 187 198 188 199 int xfs_read_agf(struct xfs_mount *mp, struct xfs_trans *tp, 189 200 xfs_agnumber_t agno, int flags, struct xfs_buf **bpp); 201 + int xfs_alloc_read_agf(struct xfs_perag *pag, struct xfs_trans *tp, int flags, 202 + struct xfs_buf **agfbpp); 190 203 int xfs_alloc_read_agfl(struct xfs_mount *mp, struct xfs_trans *tp, 191 204 xfs_agnumber_t agno, struct xfs_buf **bpp); 192 205 int xfs_free_agfl_block(struct xfs_trans *, xfs_agnumber_t, xfs_agblock_t,
+1 -1
fs/xfs/libxfs/xfs_bmap.c
··· 3185 3185 3186 3186 pag = xfs_perag_get(mp, ag); 3187 3187 if (!pag->pagf_init) { 3188 - error = xfs_alloc_read_agf(mp, tp, ag, XFS_ALLOC_FLAG_TRYLOCK, 3188 + error = xfs_alloc_read_agf(pag, tp, XFS_ALLOC_FLAG_TRYLOCK, 3189 3189 NULL); 3190 3190 if (error) { 3191 3191 /* Couldn't lock the AGF, so skip this AG. */
+1 -1
fs/xfs/libxfs/xfs_ialloc.c
··· 1621 1621 return false; 1622 1622 1623 1623 if (!pag->pagf_init) { 1624 - error = xfs_alloc_read_agf(mp, tp, pag->pag_agno, flags, NULL); 1624 + error = xfs_alloc_read_agf(pag, tp, flags, NULL); 1625 1625 if (error) 1626 1626 return false; 1627 1627 }
+3 -3
fs/xfs/libxfs/xfs_refcount.c
··· 1177 1177 *pcur = NULL; 1178 1178 } 1179 1179 if (rcur == NULL) { 1180 - error = xfs_alloc_read_agf(tp->t_mountp, tp, pag->pag_agno, 1181 - XFS_ALLOC_FLAG_FREEING, &agbp); 1180 + error = xfs_alloc_read_agf(pag, tp, XFS_ALLOC_FLAG_FREEING, 1181 + &agbp); 1182 1182 if (error) 1183 1183 goto out_drop; 1184 1184 ··· 1710 1710 if (error) 1711 1711 return error; 1712 1712 1713 - error = xfs_alloc_read_agf(mp, tp, pag->pag_agno, 0, &agbp); 1713 + error = xfs_alloc_read_agf(pag, tp, 0, &agbp); 1714 1714 if (error) 1715 1715 goto out_trans; 1716 1716 cur = xfs_refcountbt_init_cursor(mp, tp, agbp, pag);
+1 -1
fs/xfs/libxfs/xfs_refcount_btree.c
··· 493 493 if (!xfs_has_reflink(mp)) 494 494 return 0; 495 495 496 - error = xfs_alloc_read_agf(mp, tp, pag->pag_agno, 0, &agbp); 496 + error = xfs_alloc_read_agf(pag, tp, 0, &agbp); 497 497 if (error) 498 498 return error; 499 499
+1 -1
fs/xfs/libxfs/xfs_rmap_btree.c
··· 652 652 if (!xfs_has_rmapbt(mp)) 653 653 return 0; 654 654 655 - error = xfs_alloc_read_agf(mp, tp, pag->pag_agno, 0, &agbp); 655 + error = xfs_alloc_read_agf(pag, tp, 0, &agbp); 656 656 if (error) 657 657 return error; 658 658
+2 -4
fs/xfs/scrub/agheader_repair.c
··· 666 666 * nothing wrong with the AGF, but all the AG header repair functions 667 667 * have this chicken-and-egg problem. 668 668 */ 669 - error = xfs_alloc_read_agf(mp, sc->tp, sc->sa.pag->pag_agno, 0, 670 - &agf_bp); 669 + error = xfs_alloc_read_agf(sc->sa.pag, sc->tp, 0, &agf_bp); 671 670 if (error) 672 671 return error; 673 672 ··· 741 742 int error; 742 743 743 744 /* Read the AGF. */ 744 - error = xfs_alloc_read_agf(mp, sc->tp, sc->sa.pag->pag_agno, 0, 745 - &agf_bp); 745 + error = xfs_alloc_read_agf(sc->sa.pag, sc->tp, 0, &agf_bp); 746 746 if (error) 747 747 return error; 748 748
+1 -1
fs/xfs/scrub/bmap.c
··· 540 540 struct xfs_buf *agf; 541 541 int error; 542 542 543 - error = xfs_alloc_read_agf(sc->mp, sc->tp, pag->pag_agno, 0, &agf); 543 + error = xfs_alloc_read_agf(pag, sc->tp, 0, &agf); 544 544 if (error) 545 545 return error; 546 546
+1 -1
fs/xfs/scrub/common.c
··· 420 420 if (error && want_ag_read_header_failure(sc, XFS_SCRUB_TYPE_AGI)) 421 421 return error; 422 422 423 - error = xfs_alloc_read_agf(mp, sc->tp, agno, 0, &sa->agf_bp); 423 + error = xfs_alloc_read_agf(sa->pag, sc->tp, 0, &sa->agf_bp); 424 424 if (error && want_ag_read_header_failure(sc, XFS_SCRUB_TYPE_AGF)) 425 425 return error; 426 426
+1 -1
fs/xfs/scrub/fscounters.c
··· 81 81 error = xfs_ialloc_read_agi(pag, sc->tp, &agi_bp); 82 82 if (error) 83 83 break; 84 - error = xfs_alloc_read_agf(mp, sc->tp, agno, 0, &agf_bp); 84 + error = xfs_alloc_read_agf(pag, sc->tp, 0, &agf_bp); 85 85 if (error) 86 86 break; 87 87
+3 -2
fs/xfs/scrub/repair.c
··· 207 207 } 208 208 209 209 /* Now grab the block counters from the AGF. */ 210 - error = xfs_alloc_read_agf(mp, NULL, sm->sm_agno, 0, &bp); 210 + error = xfs_alloc_read_agf(pag, NULL, 0, &bp); 211 211 if (error) { 212 212 aglen = xfs_ag_block_count(mp, sm->sm_agno); 213 213 freelen = aglen; ··· 543 543 544 544 agno = XFS_FSB_TO_AGNO(sc->mp, fsbno); 545 545 agbno = XFS_FSB_TO_AGBNO(sc->mp, fsbno); 546 + ASSERT(agno == sc->sa.pag->pag_agno); 546 547 547 548 /* 548 549 * If we are repairing per-inode metadata, we need to read in the AGF ··· 551 550 * the AGF buffer that the setup functions already grabbed. 552 551 */ 553 552 if (sc->ip) { 554 - error = xfs_alloc_read_agf(sc->mp, sc->tp, agno, 0, &agf_bp); 553 + error = xfs_alloc_read_agf(sc->sa.pag, sc->tp, 0, &agf_bp); 555 554 if (error) 556 555 return error; 557 556 } else {
+1 -1
fs/xfs/xfs_discard.c
··· 45 45 */ 46 46 xfs_log_force(mp, XFS_LOG_SYNC); 47 47 48 - error = xfs_alloc_read_agf(mp, NULL, agno, 0, &agbp); 48 + error = xfs_alloc_read_agf(pag, NULL, 0, &agbp); 49 49 if (error) 50 50 goto out_put_perag; 51 51 agf = agbp->b_addr;
+5 -1
fs/xfs/xfs_extfree_item.c
··· 11 11 #include "xfs_bit.h" 12 12 #include "xfs_shared.h" 13 13 #include "xfs_mount.h" 14 + #include "xfs_ag.h" 14 15 #include "xfs_defer.h" 15 16 #include "xfs_trans.h" 16 17 #include "xfs_trans_priv.h" ··· 552 551 xfs_agnumber_t agno; 553 552 xfs_agblock_t agbno; 554 553 uint next_extent; 554 + struct xfs_perag *pag; 555 555 556 556 free = container_of(item, struct xfs_extent_free_item, xefi_list); 557 557 ASSERT(free->xefi_blockcount == 1); ··· 562 560 563 561 trace_xfs_agfl_free_deferred(mp, agno, 0, agbno, free->xefi_blockcount); 564 562 565 - error = xfs_alloc_read_agf(mp, tp, agno, 0, &agbp); 563 + pag = xfs_perag_get(mp, agno); 564 + error = xfs_alloc_read_agf(pag, tp, 0, &agbp); 566 565 if (!error) 567 566 error = xfs_free_agfl_block(tp, agno, agbno, agbp, &oinfo); 567 + xfs_perag_put(pag); 568 568 569 569 /* 570 570 * Mark the transaction dirty, even on error. This ensures the
+1 -1
fs/xfs/xfs_filestream.c
··· 126 126 pag = xfs_perag_get(mp, ag); 127 127 128 128 if (!pag->pagf_init) { 129 - err = xfs_alloc_read_agf(mp, NULL, ag, trylock, NULL); 129 + err = xfs_alloc_read_agf(pag, NULL, trylock, NULL); 130 130 if (err) { 131 131 if (err != -EAGAIN) { 132 132 xfs_perag_put(pag);
+1 -2
fs/xfs/xfs_fsmap.c
··· 642 642 info->agf_bp = NULL; 643 643 } 644 644 645 - error = xfs_alloc_read_agf(mp, tp, pag->pag_agno, 0, 646 - &info->agf_bp); 645 + error = xfs_alloc_read_agf(pag, tp, 0, &info->agf_bp); 647 646 if (error) 648 647 break; 649 648
+22 -18
fs/xfs/xfs_reflink.c
··· 125 125 * shared blocks. If there are no shared extents, fbno and flen will 126 126 * be set to NULLAGBLOCK and 0, respectively. 127 127 */ 128 - int 128 + static int 129 129 xfs_reflink_find_shared( 130 - struct xfs_mount *mp, 130 + struct xfs_perag *pag, 131 131 struct xfs_trans *tp, 132 - xfs_agnumber_t agno, 133 132 xfs_agblock_t agbno, 134 133 xfs_extlen_t aglen, 135 134 xfs_agblock_t *fbno, ··· 139 140 struct xfs_btree_cur *cur; 140 141 int error; 141 142 142 - error = xfs_alloc_read_agf(mp, tp, agno, 0, &agbp); 143 + error = xfs_alloc_read_agf(pag, tp, 0, &agbp); 143 144 if (error) 144 145 return error; 145 146 146 - cur = xfs_refcountbt_init_cursor(mp, tp, agbp, agbp->b_pag); 147 + cur = xfs_refcountbt_init_cursor(pag->pag_mount, tp, agbp, pag); 147 148 148 149 error = xfs_refcount_find_shared(cur, agbno, aglen, fbno, flen, 149 150 find_end_of_shared); ··· 170 171 struct xfs_bmbt_irec *irec, 171 172 bool *shared) 172 173 { 173 - xfs_agnumber_t agno; 174 + struct xfs_mount *mp = ip->i_mount; 175 + struct xfs_perag *pag; 174 176 xfs_agblock_t agbno; 175 177 xfs_extlen_t aglen; 176 178 xfs_agblock_t fbno; ··· 186 186 187 187 trace_xfs_reflink_trim_around_shared(ip, irec); 188 188 189 - agno = XFS_FSB_TO_AGNO(ip->i_mount, irec->br_startblock); 190 - agbno = XFS_FSB_TO_AGBNO(ip->i_mount, irec->br_startblock); 189 + pag = xfs_perag_get(mp, XFS_FSB_TO_AGNO(mp, irec->br_startblock)); 190 + agbno = XFS_FSB_TO_AGBNO(mp, irec->br_startblock); 191 191 aglen = irec->br_blockcount; 192 192 193 - error = xfs_reflink_find_shared(ip->i_mount, NULL, agno, agbno, 194 - aglen, &fbno, &flen, true); 193 + error = xfs_reflink_find_shared(pag, NULL, agbno, aglen, &fbno, &flen, 194 + true); 195 + xfs_perag_put(pag); 195 196 if (error) 196 197 return error; 197 198 ··· 1421 1420 struct xfs_bmbt_irec got; 1422 1421 struct xfs_mount *mp = ip->i_mount; 1423 1422 struct xfs_ifork *ifp; 1424 - xfs_agnumber_t agno; 1425 - xfs_agblock_t agbno; 1426 - xfs_extlen_t aglen; 1427 - xfs_agblock_t rbno; 1428 - xfs_extlen_t rlen; 1429 1423 struct xfs_iext_cursor icur; 1430 1424 bool found; 1431 1425 int error; ··· 1433 1437 *has_shared = false; 1434 1438 found = xfs_iext_lookup_extent(ip, ifp, 0, &icur, &got); 1435 1439 while (found) { 1440 + struct xfs_perag *pag; 1441 + xfs_agblock_t agbno; 1442 + xfs_extlen_t aglen; 1443 + xfs_agblock_t rbno; 1444 + xfs_extlen_t rlen; 1445 + 1436 1446 if (isnullstartblock(got.br_startblock) || 1437 1447 got.br_state != XFS_EXT_NORM) 1438 1448 goto next; 1439 - agno = XFS_FSB_TO_AGNO(mp, got.br_startblock); 1449 + 1450 + pag = xfs_perag_get(mp, XFS_FSB_TO_AGNO(mp, got.br_startblock)); 1440 1451 agbno = XFS_FSB_TO_AGBNO(mp, got.br_startblock); 1441 1452 aglen = got.br_blockcount; 1442 - 1443 - error = xfs_reflink_find_shared(mp, tp, agno, agbno, aglen, 1453 + error = xfs_reflink_find_shared(pag, tp, agbno, aglen, 1444 1454 &rbno, &rlen, false); 1455 + xfs_perag_put(pag); 1445 1456 if (error) 1446 1457 return error; 1458 + 1447 1459 /* Is there still a shared block here? */ 1448 1460 if (rbno != NULLAGBLOCK) { 1449 1461 *has_shared = true;
-3
fs/xfs/xfs_reflink.h
··· 16 16 return xfs_is_reflink_inode(ip) || xfs_is_always_cow_inode(ip); 17 17 } 18 18 19 - extern int xfs_reflink_find_shared(struct xfs_mount *mp, struct xfs_trans *tp, 20 - xfs_agnumber_t agno, xfs_agblock_t agbno, xfs_extlen_t aglen, 21 - xfs_agblock_t *fbno, xfs_extlen_t *flen, bool find_maximal); 22 19 extern int xfs_reflink_trim_around_shared(struct xfs_inode *ip, 23 20 struct xfs_bmbt_irec *irec, bool *shared); 24 21 int xfs_bmap_trim_cow(struct xfs_inode *ip, struct xfs_bmbt_irec *imap,