Commit 99b13c7f authored by Dave Chinner's avatar Dave Chinner Committed by Dave Chinner

xfs: pass perag to xfs_ialloc_read_agi()

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: default avatarDave Chinner <dchinner@redhat.com>
Reviewed-by: default avatarChristoph Hellwig <hch@lst.de>
Reviewed-by: default avatarDarrick J. Wong <djwong@kernel.org>
parent a95fee40
...@@ -128,11 +128,13 @@ xfs_initialize_perag_data( ...@@ -128,11 +128,13 @@ xfs_initialize_perag_data(
if (error) if (error)
return error; return error;
error = xfs_ialloc_read_agi(mp, NULL, index, NULL); pag = xfs_perag_get(mp, index);
if (error) error = xfs_ialloc_read_agi(pag, NULL, NULL);
if (error) {
xfs_perag_put(pag);
return error; return error;
}
pag = xfs_perag_get(mp, index);
ifree += pag->pagi_freecount; ifree += pag->pagi_freecount;
ialloc += pag->pagi_count; ialloc += pag->pagi_count;
bfree += pag->pagf_freeblks; bfree += pag->pagf_freeblks;
...@@ -784,7 +786,7 @@ xfs_ag_shrink_space( ...@@ -784,7 +786,7 @@ xfs_ag_shrink_space(
int error, err2; int error, err2;
ASSERT(pag->pag_agno == mp->m_sb.sb_agcount - 1); 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) if (error)
return error; return error;
...@@ -817,7 +819,7 @@ xfs_ag_shrink_space( ...@@ -817,7 +819,7 @@ xfs_ag_shrink_space(
* Disable perag reservations so it doesn't cause the allocation request * Disable perag reservations so it doesn't cause the allocation request
* to fail. We'll reestablish reservation before we return. * 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) if (error)
return error; return error;
...@@ -846,7 +848,7 @@ xfs_ag_shrink_space( ...@@ -846,7 +848,7 @@ xfs_ag_shrink_space(
be32_add_cpu(&agi->agi_length, -delta); be32_add_cpu(&agi->agi_length, -delta);
be32_add_cpu(&agf->agf_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) { if (err2) {
be32_add_cpu(&agi->agi_length, delta); be32_add_cpu(&agi->agi_length, delta);
be32_add_cpu(&agf->agf_length, delta); be32_add_cpu(&agf->agf_length, delta);
...@@ -870,8 +872,9 @@ xfs_ag_shrink_space( ...@@ -870,8 +872,9 @@ xfs_ag_shrink_space(
xfs_ialloc_log_agi(*tpp, agibp, XFS_AGI_LENGTH); xfs_ialloc_log_agi(*tpp, agibp, XFS_AGI_LENGTH);
xfs_alloc_log_agf(*tpp, agfbp, XFS_AGF_LENGTH); xfs_alloc_log_agf(*tpp, agfbp, XFS_AGF_LENGTH);
return 0; return 0;
resv_init_out: resv_init_out:
err2 = xfs_ag_resv_init(agibp->b_pag, *tpp); err2 = xfs_ag_resv_init(pag, *tpp);
if (!err2) if (!err2)
return error; return error;
resv_err: resv_err:
...@@ -896,7 +899,7 @@ xfs_ag_extend_space( ...@@ -896,7 +899,7 @@ xfs_ag_extend_space(
ASSERT(pag->pag_agno == pag->pag_mount->m_sb.sb_agcount - 1); 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) if (error)
return error; return error;
...@@ -947,8 +950,7 @@ xfs_ag_get_geometry( ...@@ -947,8 +950,7 @@ xfs_ag_get_geometry(
int error; int error;
/* Lock the AG headers. */ /* Lock the AG headers. */
error = xfs_ialloc_read_agi(pag->pag_mount, NULL, pag->pag_agno, error = xfs_ialloc_read_agi(pag, NULL, &agi_bp);
&agi_bp);
if (error) if (error)
return error; return error;
error = xfs_alloc_read_agf(pag->pag_mount, NULL, pag->pag_agno, 0, error = xfs_alloc_read_agf(pag->pag_mount, NULL, pag->pag_agno, 0,
......
...@@ -1610,7 +1610,7 @@ xfs_dialloc_good_ag( ...@@ -1610,7 +1610,7 @@ xfs_dialloc_good_ag(
return false; return false;
if (!pag->pagi_init) { 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) if (error)
return false; return false;
} }
...@@ -1679,7 +1679,7 @@ xfs_dialloc_try_ag( ...@@ -1679,7 +1679,7 @@ xfs_dialloc_try_ag(
* Then read in the AGI buffer and recheck with the AGI buffer * Then read in the AGI buffer and recheck with the AGI buffer
* lock held. * 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) if (error)
return error; return error;
...@@ -2169,7 +2169,7 @@ xfs_difree( ...@@ -2169,7 +2169,7 @@ xfs_difree(
/* /*
* Get the allocation group header. * 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) { if (error) {
xfs_warn(mp, "%s: xfs_ialloc_read_agi() returned error %d.", xfs_warn(mp, "%s: xfs_ialloc_read_agi() returned error %d.",
__func__, error); __func__, error);
...@@ -2215,7 +2215,7 @@ xfs_imap_lookup( ...@@ -2215,7 +2215,7 @@ xfs_imap_lookup(
int error; int error;
int i; int i;
error = xfs_ialloc_read_agi(mp, tp, pag->pag_agno, &agbp); error = xfs_ialloc_read_agi(pag, tp, &agbp);
if (error) { if (error) {
xfs_alert(mp, xfs_alert(mp,
"%s: xfs_ialloc_read_agi() returned error %d, agno %d", "%s: xfs_ialloc_read_agi() returned error %d, agno %d",
...@@ -2599,24 +2599,21 @@ xfs_read_agi( ...@@ -2599,24 +2599,21 @@ xfs_read_agi(
*/ */
int int
xfs_ialloc_read_agi( xfs_ialloc_read_agi(
struct xfs_mount *mp, /* file system mount structure */ struct xfs_perag *pag,
struct xfs_trans *tp, /* transaction pointer */ struct xfs_trans *tp,
xfs_agnumber_t agno, /* allocation group number */
struct xfs_buf **agibpp) struct xfs_buf **agibpp)
{ {
struct xfs_buf *agibp; struct xfs_buf *agibp;
struct xfs_agi *agi; /* allocation group header */ struct xfs_agi *agi;
struct xfs_perag *pag; /* per allocation group data */
int error; 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) if (error)
return error; return error;
agi = agibp->b_addr; agi = agibp->b_addr;
pag = agibp->b_pag;
if (!pag->pagi_init) { if (!pag->pagi_init) {
pag->pagi_freecount = be32_to_cpu(agi->agi_freecount); pag->pagi_freecount = be32_to_cpu(agi->agi_freecount);
pag->pagi_count = be32_to_cpu(agi->agi_count); pag->pagi_count = be32_to_cpu(agi->agi_count);
...@@ -2628,7 +2625,7 @@ xfs_ialloc_read_agi( ...@@ -2628,7 +2625,7 @@ xfs_ialloc_read_agi(
* we are in the middle of a forced shutdown. * we are in the middle of a forced shutdown.
*/ */
ASSERT(pag->pagi_freecount == be32_to_cpu(agi->agi_freecount) || ASSERT(pag->pagi_freecount == be32_to_cpu(agi->agi_freecount) ||
xfs_is_shutdown(mp)); xfs_is_shutdown(pag->pag_mount));
if (agibpp) if (agibpp)
*agibpp = agibp; *agibpp = agibp;
else else
......
...@@ -66,11 +66,8 @@ xfs_ialloc_log_agi( ...@@ -66,11 +66,8 @@ xfs_ialloc_log_agi(
* Read in the allocation group header (inode allocation section) * Read in the allocation group header (inode allocation section)
*/ */
int /* error */ int /* error */
xfs_ialloc_read_agi( xfs_ialloc_read_agi(struct xfs_perag *pag, struct xfs_trans *tp,
struct xfs_mount *mp, /* file system mount structure */ struct xfs_buf **agibpp);
struct xfs_trans *tp, /* transaction pointer */
xfs_agnumber_t agno, /* allocation group number */
struct xfs_buf **bpp); /* allocation group hdr buf */
/* /*
* Lookup a record by ino in the btree given by cur. * Lookup a record by ino in the btree given by cur.
......
...@@ -722,7 +722,7 @@ xfs_inobt_cur( ...@@ -722,7 +722,7 @@ xfs_inobt_cur(
ASSERT(*agi_bpp == NULL); ASSERT(*agi_bpp == NULL);
ASSERT(*curpp == 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) if (error)
return error; return error;
...@@ -757,16 +757,15 @@ xfs_inobt_count_blocks( ...@@ -757,16 +757,15 @@ xfs_inobt_count_blocks(
/* Read finobt block count from AGI header. */ /* Read finobt block count from AGI header. */
static int static int
xfs_finobt_read_blocks( xfs_finobt_read_blocks(
struct xfs_mount *mp,
struct xfs_trans *tp,
struct xfs_perag *pag, struct xfs_perag *pag,
struct xfs_trans *tp,
xfs_extlen_t *tree_blocks) xfs_extlen_t *tree_blocks)
{ {
struct xfs_buf *agbp; struct xfs_buf *agbp;
struct xfs_agi *agi; struct xfs_agi *agi;
int error; int error;
error = xfs_ialloc_read_agi(mp, tp, pag->pag_agno, &agbp); error = xfs_ialloc_read_agi(pag, tp, &agbp);
if (error) if (error)
return error; return error;
...@@ -794,7 +793,7 @@ xfs_finobt_calc_reserves( ...@@ -794,7 +793,7 @@ xfs_finobt_calc_reserves(
return 0; return 0;
if (xfs_has_inobtcounts(mp)) 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 else
error = xfs_inobt_count_blocks(mp, tp, pag, XFS_BTNUM_FINO, error = xfs_inobt_count_blocks(mp, tp, pag, XFS_BTNUM_FINO,
&tree_len); &tree_len);
......
...@@ -416,7 +416,7 @@ xchk_ag_read_headers( ...@@ -416,7 +416,7 @@ xchk_ag_read_headers(
if (!sa->pag) if (!sa->pag)
return -ENOENT; return -ENOENT;
error = xfs_ialloc_read_agi(mp, sc->tp, agno, &sa->agi_bp); error = xfs_ialloc_read_agi(sa->pag, sc->tp, &sa->agi_bp);
if (error && want_ag_read_header_failure(sc, XFS_SCRUB_TYPE_AGI)) if (error && want_ag_read_header_failure(sc, XFS_SCRUB_TYPE_AGI))
return error; return error;
......
...@@ -78,7 +78,7 @@ xchk_fscount_warmup( ...@@ -78,7 +78,7 @@ xchk_fscount_warmup(
continue; continue;
/* Lock both AG headers. */ /* Lock both AG headers. */
error = xfs_ialloc_read_agi(mp, sc->tp, agno, &agi_bp); error = xfs_ialloc_read_agi(pag, sc->tp, &agi_bp);
if (error) if (error)
break; break;
error = xfs_alloc_read_agf(mp, sc->tp, agno, 0, &agf_bp); error = xfs_alloc_read_agf(mp, sc->tp, agno, 0, &agf_bp);
......
...@@ -199,7 +199,7 @@ xrep_calc_ag_resblks( ...@@ -199,7 +199,7 @@ xrep_calc_ag_resblks(
icount = pag->pagi_count; icount = pag->pagi_count;
} else { } else {
/* Try to get the actual counters from disk. */ /* Try to get the actual counters from disk. */
error = xfs_ialloc_read_agi(mp, NULL, sm->sm_agno, &bp); error = xfs_ialloc_read_agi(pag, NULL, &bp);
if (!error) { if (!error) {
icount = pag->pagi_count; icount = pag->pagi_count;
xfs_buf_relse(bp); xfs_buf_relse(bp);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment