Blame SOURCES/xfsprogs-5.10.0-xfs-use-the-finobt-block-counts-to-speed-up-mount-ti.patch

0bf83d
From eb2c6897f36d560f84ed5124b246f2759c470f11 Mon Sep 17 00:00:00 2001
0bf83d
From: "Darrick J. Wong" <darrick.wong@oracle.com>
0bf83d
Date: Tue, 10 Nov 2020 15:11:09 -0500
0bf83d
Subject: [PATCH] xfs: use the finobt block counts to speed up mount times
0bf83d
0bf83d
Source kernel commit: 1ac35f061af011442eeb731632f6daae991ecf7c
0bf83d
0bf83d
Now that we have reliable finobt block counts, use them to speed up the
0bf83d
per-AG block reservation calculations at mount time.
0bf83d
0bf83d
Signed-off-by: Darrick J. Wong <darrick.wong@oracle.com>
0bf83d
Reviewed-by: Brian Foster <bfoster@redhat.com>
0bf83d
Signed-off-by: Eric Sandeen <sandeen@sandeen.net>
0bf83d
---
0bf83d
0bf83d
diff --git a/libxfs/xfs_ialloc_btree.c b/libxfs/xfs_ialloc_btree.c
0bf83d
index 9db87e9..b1adc80 100644
0bf83d
--- a/libxfs/xfs_ialloc_btree.c
0bf83d
+++ b/libxfs/xfs_ialloc_btree.c
0bf83d
@@ -593,6 +593,28 @@ xfs_inobt_count_blocks(
0bf83d
 	return error;
0bf83d
 }
0bf83d
 
0bf83d
+/* Read finobt block count from AGI header. */
0bf83d
+static int
0bf83d
+xfs_finobt_read_blocks(
0bf83d
+	struct xfs_mount	*mp,
0bf83d
+	struct xfs_trans	*tp,
0bf83d
+	xfs_agnumber_t		agno,
0bf83d
+	xfs_extlen_t		*tree_blocks)
0bf83d
+{
0bf83d
+	struct xfs_buf		*agbp;
0bf83d
+	struct xfs_agi		*agi;
0bf83d
+	int			error;
0bf83d
+
0bf83d
+	error = xfs_ialloc_read_agi(mp, tp, agno, &agbp);
0bf83d
+	if (error)
0bf83d
+		return error;
0bf83d
+
0bf83d
+	agi = agbp->b_addr;
0bf83d
+	*tree_blocks = be32_to_cpu(agi->agi_fblocks);
0bf83d
+	xfs_trans_brelse(tp, agbp);
0bf83d
+	return 0;
0bf83d
+}
0bf83d
+
0bf83d
 /*
0bf83d
  * Figure out how many blocks to reserve and how many are used by this btree.
0bf83d
  */
0bf83d
@@ -610,7 +632,11 @@ xfs_finobt_calc_reserves(
0bf83d
 	if (!xfs_sb_version_hasfinobt(&mp->m_sb))
0bf83d
 		return 0;
0bf83d
 
0bf83d
-	error = xfs_inobt_count_blocks(mp, tp, agno, XFS_BTNUM_FINO, &tree_len);
0bf83d
+	if (xfs_sb_version_hasinobtcounts(&mp->m_sb))
0bf83d
+		error = xfs_finobt_read_blocks(mp, tp, agno, &tree_len);
0bf83d
+	else
0bf83d
+		error = xfs_inobt_count_blocks(mp, tp, agno, XFS_BTNUM_FINO,
0bf83d
+				&tree_len);
0bf83d
 	if (error)
0bf83d
 		return error;
0bf83d