public inbox for linux-xfs@vger.kernel.org
 help / color / mirror / Atom feed
From: Dave Chinner <david@fromorbit.com>
To: linux-xfs@vger.kernel.org
Subject: [PATCH 03/50] xfs: pass perag to xfs_ialloc_read_agi()
Date: Sat, 11 Jun 2022 11:26:12 +1000	[thread overview]
Message-ID: <20220611012659.3418072-4-david@fromorbit.com> (raw)
In-Reply-To: <20220611012659.3418072-1-david@fromorbit.com>

From: Dave Chinner <dchinner@redhat.com>

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>
---
 fs/xfs/libxfs/xfs_ag.c           | 23 +++++++++++++----------
 fs/xfs/libxfs/xfs_ialloc.c       | 23 ++++++++++-------------
 fs/xfs/libxfs/xfs_ialloc.h       |  7 ++-----
 fs/xfs/libxfs/xfs_ialloc_btree.c |  9 ++++-----
 fs/xfs/scrub/common.c            |  2 +-
 fs/xfs/scrub/fscounters.c        |  2 +-
 fs/xfs/scrub/repair.c            |  2 +-
 7 files changed, 32 insertions(+), 36 deletions(-)

diff --git a/fs/xfs/libxfs/xfs_ag.c b/fs/xfs/libxfs/xfs_ag.c
index 355af8fe90c8..74862823311a 100644
--- a/fs/xfs/libxfs/xfs_ag.c
+++ b/fs/xfs/libxfs/xfs_ag.c
@@ -128,11 +128,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;
@@ -784,7 +786,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;
 
@@ -816,7 +818,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;
 
@@ -833,7 +835,7 @@ xfs_ag_shrink_space(
 		xfs_trans_bhold(*tpp, agfbp);
 		err2 = xfs_trans_roll(tpp);
 		if (err2)
-			return err2;
+			return error;
 		xfs_trans_bjoin(*tpp, agfbp);
 		goto resv_init_out;
 	}
@@ -845,7 +847,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);
@@ -869,8 +871,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:
@@ -895,7 +898,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;
 
@@ -946,7 +949,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, &agf_bp);
diff --git a/fs/xfs/libxfs/xfs_ialloc.c b/fs/xfs/libxfs/xfs_ialloc.c
index cefac2a1ba0c..a7259404377d 100644
--- a/fs/xfs/libxfs/xfs_ialloc.c
+++ b/fs/xfs/libxfs/xfs_ialloc.c
@@ -1610,7 +1610,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;
 	}
@@ -1679,7 +1679,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;
 
@@ -2169,7 +2169,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);
@@ -2215,7 +2215,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",
@@ -2599,24 +2599,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);
@@ -2628,7 +2625,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
diff --git a/fs/xfs/libxfs/xfs_ialloc.h b/fs/xfs/libxfs/xfs_ialloc.h
index 1ff42bf1e4b3..72cb33170d9f 100644
--- a/fs/xfs/libxfs/xfs_ialloc.h
+++ b/fs/xfs/libxfs/xfs_ialloc.h
@@ -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.
diff --git a/fs/xfs/libxfs/xfs_ialloc_btree.c b/fs/xfs/libxfs/xfs_ialloc_btree.c
index b2ad2fdc40f5..aa4367a0a0de 100644
--- a/fs/xfs/libxfs/xfs_ialloc_btree.c
+++ b/fs/xfs/libxfs/xfs_ialloc_btree.c
@@ -722,7 +722,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;
 
@@ -757,16 +757,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;
 
@@ -794,7 +793,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);
diff --git a/fs/xfs/scrub/common.c b/fs/xfs/scrub/common.c
index 97b54ac3075f..62997791694a 100644
--- a/fs/xfs/scrub/common.c
+++ b/fs/xfs/scrub/common.c
@@ -416,7 +416,7 @@ xchk_ag_read_headers(
 	if (!sa->pag)
 		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))
 		return error;
 
diff --git a/fs/xfs/scrub/fscounters.c b/fs/xfs/scrub/fscounters.c
index 48a6cbdf95d0..bd06a184c81c 100644
--- a/fs/xfs/scrub/fscounters.c
+++ b/fs/xfs/scrub/fscounters.c
@@ -78,7 +78,7 @@ xchk_fscount_warmup(
 			continue;
 
 		/* 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)
 			break;
 		error = xfs_alloc_read_agf(mp, sc->tp, agno, 0, &agf_bp);
diff --git a/fs/xfs/scrub/repair.c b/fs/xfs/scrub/repair.c
index 1e7b6b209ee8..14acf1df3dd3 100644
--- a/fs/xfs/scrub/repair.c
+++ b/fs/xfs/scrub/repair.c
@@ -199,7 +199,7 @@ xrep_calc_ag_resblks(
 		icount = pag->pagi_count;
 	} else {
 		/* 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) {
 			icount = pag->pagi_count;
 			xfs_buf_relse(bp);
-- 
2.35.1


  parent reply	other threads:[~2022-06-11  1:27 UTC|newest]

Thread overview: 69+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-06-11  1:26 [RFC] [PATCH 00/50] xfs: per-ag centric allocation alogrithms Dave Chinner
2022-06-11  1:26 ` [PATCH 01/50] xfs: make last AG grow/shrink perag centric Dave Chinner
2022-06-16  7:30   ` Christoph Hellwig
2022-06-11  1:26 ` [PATCH 02/50] xfs: kill xfs_ialloc_pagi_init() Dave Chinner
2022-06-16  7:32   ` Christoph Hellwig
2022-06-11  1:26 ` Dave Chinner [this message]
2022-06-16  7:34   ` [PATCH 03/50] xfs: pass perag to xfs_ialloc_read_agi() Christoph Hellwig
2022-06-11  1:26 ` [PATCH 04/50] xfs: kill xfs_alloc_pagf_init() Dave Chinner
2022-06-16  7:35   ` Christoph Hellwig
2022-06-11  1:26 ` [PATCH 05/50] xfs: pass perag to xfs_alloc_read_agf() Dave Chinner
2022-06-11  2:37   ` kernel test robot
2022-06-11 12:04   ` kernel test robot
2022-06-11 13:46   ` kernel test robot
2022-06-14 12:17   ` kernel test robot
2022-06-16  7:38   ` Christoph Hellwig
2022-06-11  1:26 ` [PATCH 06/50] xfs: pass perag to xfs_read_agi Dave Chinner
2022-06-16  7:39   ` Christoph Hellwig
2022-06-16  7:39   ` Christoph Hellwig
2022-06-11  1:26 ` [PATCH 07/50] xfs: pass perag to xfs_read_agf Dave Chinner
2022-06-16  7:40   ` Christoph Hellwig
2022-06-11  1:26 ` [PATCH 08/50] xfs: pass perag to xfs_alloc_get_freelist Dave Chinner
2022-06-16  7:40   ` Christoph Hellwig
2022-06-11  1:26 ` [PATCH 09/50] xfs: pass perag to xfs_alloc_put_freelist Dave Chinner
2022-06-16  7:40   ` Christoph Hellwig
2022-06-11  1:26 ` [PATCH 10/50] xfs: pass perag to xfs_alloc_read_agfl Dave Chinner
2022-06-16  7:41   ` Christoph Hellwig
2022-06-11  1:26 ` [PATCH 11/50] xfs: Pre-calculate per-AG agbno geometry Dave Chinner
2022-06-11  1:26 ` [PATCH 12/50] xfs: Pre-calculate per-AG agino geometry Dave Chinner
2022-06-11  3:08   ` kernel test robot
2022-06-11  1:26 ` [PATCH 13/50] xfs: replace xfs_ag_block_count() with perag accesses Dave Chinner
2022-06-11  1:26 ` [PATCH 14/50] xfs: make is_log_ag() a first class helper Dave Chinner
2022-06-11  1:26 ` [PATCH 15/50] xfs: active perag reference counting Dave Chinner
2022-06-11  1:26 ` [PATCH 16/50] xfs: rework the perag trace points to be perag centric Dave Chinner
2022-06-11  1:26 ` [PATCH 17/50] xfs: convert xfs_imap() to take a perag Dave Chinner
2022-06-11  1:26 ` [PATCH 18/50] xfs: use active perag references for inode allocation Dave Chinner
2022-06-11  1:26 ` [PATCH 19/50] xfs: inobt can use perags in many more places than it does Dave Chinner
2022-06-11  1:26 ` [PATCH 20/50] xfs: convert xfs_ialloc_next_ag() to an atomic Dave Chinner
2022-06-11  1:26 ` [PATCH 21/50] xfs: perags need atomic operational state Dave Chinner
2022-06-11  1:26 ` [PATCH 22/50] xfs: introduce xfs_for_each_perag_wrap() Dave Chinner
2022-06-11  1:26 ` [PATCH 23/50] xfs: rework xfs_alloc_vextent() Dave Chinner
2022-06-11  1:26 ` [PATCH 24/50] xfs: use xfs_alloc_vextent_this_ag() in _iterate_ags() Dave Chinner
2022-06-11  1:26 ` [PATCH 25/50] xfs: combine __xfs_alloc_vextent_this_ag and xfs_alloc_ag_vextent Dave Chinner
2022-06-11  1:26 ` [PATCH 26/50] xfs: use xfs_alloc_vextent_this_ag() where appropriate Dave Chinner
2022-06-11  1:26 ` [PATCH 27/50] xfs: factor xfs_bmap_btalloc() Dave Chinner
2022-06-11  1:26 ` [PATCH 28/50] xfs: use xfs_alloc_vextent_first_ag() where appropriate Dave Chinner
2022-06-11  1:26 ` [PATCH 29/50] xfs: use xfs_alloc_vextent_start_bno() " Dave Chinner
2022-06-11  1:26 ` [PATCH 30/50] xfs: introduce xfs_alloc_vextent_near_bno() Dave Chinner
2022-06-11  1:26 ` [PATCH 31/50] xfs: introduce xfs_alloc_vextent_exact_bno() Dave Chinner
2022-06-11  1:26 ` [PATCH 32/50] xfs: introduce xfs_alloc_vextent_prepare() Dave Chinner
2022-06-11  1:26 ` [PATCH 33/50] xfs: move allocation accounting to xfs_alloc_vextent_set_fsbno() Dave Chinner
2022-06-11  1:26 ` [PATCH 34/50] xfs: fold xfs_alloc_ag_vextent() into callers Dave Chinner
2022-06-11  1:26 ` [PATCH 35/50] xfs: convert xfs_alloc_vextent_iterate_ags() to use perag walker Dave Chinner
2022-06-11  1:26 ` [PATCH 36/50] xfs: convert trim to use for_each_perag_range Dave Chinner
2022-06-11  1:26 ` [PATCH 37/50] xfs: factor out filestreams from xfs_bmap_btalloc_nullfb Dave Chinner
2022-06-11  1:26 ` [PATCH 38/50] xfs: get rid of notinit from xfs_bmap_longest_free_extent Dave Chinner
2022-06-11  1:26 ` [PATCH 39/50] xfs: use xfs_bmap_longest_free_extent() in filestreams Dave Chinner
2022-06-11  1:26 ` [PATCH 40/50] xfs: move xfs_bmap_btalloc_filestreams() to xfs_filestreams.c Dave Chinner
2022-06-11  1:26 ` [PATCH 41/50] xfs: merge filestream AG lookup into xfs_filestream_select_ag() Dave Chinner
2022-06-11  1:26 ` [PATCH 42/50] xfs: merge new filestream AG selection " Dave Chinner
2022-06-11  1:26 ` [PATCH 43/50] xfs: remove xfs_filestream_select_ag() longest extent check Dave Chinner
2022-06-11  1:26 ` [PATCH 44/50] xfs: factor out MRU hit case in xfs_filestream_select_ag Dave Chinner
2022-06-11  1:26 ` [PATCH 45/50] xfs: track an active perag reference in filestreams Dave Chinner
2022-06-11  1:26 ` [PATCH 46/50] xfs: use for_each_perag_wrap in xfs_filestream_pick_ag Dave Chinner
2022-06-11  1:26 ` [PATCH 47/50] xfs: pass perag to filestreams tracing Dave Chinner
2022-06-11  1:26 ` [PATCH 48/50] xfs: return a referenced perag from filestreams allocator Dave Chinner
2022-06-11  1:26 ` [PATCH 49/50] xfs: refactor the filestreams allocator pick functions Dave Chinner
2022-06-11  1:26 ` [PATCH 50/50] xfs: fix low space alloc deadlock Dave Chinner
2022-06-16 12:01 ` [RFC] [PATCH 00/50] xfs: per-ag centric allocation alogrithms Christoph Hellwig
2022-06-21  2:08   ` Dave Chinner

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20220611012659.3418072-4-david@fromorbit.com \
    --to=david@fromorbit.com \
    --cc=linux-xfs@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox