All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH 0/4] xfs-5.0: cleanups
@ 2018-11-28 23:26 Darrick J. Wong
  2018-11-28 23:26 ` [PATCH 1/4] xfs: remove xfs_rmap_ag_owner and friends Darrick J. Wong
                   ` (3 more replies)
  0 siblings, 4 replies; 7+ messages in thread
From: Darrick J. Wong @ 2018-11-28 23:26 UTC (permalink / raw)
  To: darrick.wong; +Cc: linux-xfs

Hi all,

Here are some cleanups I made against the rmap code and the inode
geometry code, which came up as part of review comments on the scrub
inode fixes posted earlier.  It then fixes some problems with the inode
btree scrub code, namely that the existing code does not handle the case
where a single inode cluster is mapped by multiple inobt records.

The first patch creates some global const XFS_RMAP_OINFO_* objects for
static fs metadata.  This enables us to reduce stack usage here and
there, and remove a surprising amount of oinfo setup clutter in the
scrub code.

The next three patches add some inode <-> block conversion macros and
adds precomputed inode cluster size and alignment geometry information
in struct xfs_mount instead of calculating it over and over.

Comments and questions are, as always, welcome.

--D

[1] https://git.kernel.org/cgit/linux/kernel/git/djwong/xfs-linux.git/log/?h=djwong-devel

^ permalink raw reply	[flat|nested] 7+ messages in thread

* [PATCH 1/4] xfs: remove xfs_rmap_ag_owner and friends
  2018-11-28 23:26 [PATCH 0/4] xfs-5.0: cleanups Darrick J. Wong
@ 2018-11-28 23:26 ` Darrick J. Wong
  2018-11-29 15:00   ` Brian Foster
  2018-11-28 23:26 ` [PATCH 2/4] xfs: add a block to inode count converter Darrick J. Wong
                   ` (2 subsequent siblings)
  3 siblings, 1 reply; 7+ messages in thread
From: Darrick J. Wong @ 2018-11-28 23:26 UTC (permalink / raw)
  To: darrick.wong; +Cc: linux-xfs

From: Darrick J. Wong <darrick.wong@oracle.com>

Owner information for static fs metadata can be defined readonly at
build time because it never changes across filesystems.  This enables us
to reduce stack usage (particularly in scrub) because we can use the
statically defined oinfo structures.

Signed-off-by: Darrick J. Wong <darrick.wong@oracle.com>
---
 fs/xfs/libxfs/xfs_ag.c             |    9 ++++-----
 fs/xfs/libxfs/xfs_alloc.c          |    9 ++++-----
 fs/xfs/libxfs/xfs_bmap.c           |    4 ++--
 fs/xfs/libxfs/xfs_ialloc.c         |    8 +++-----
 fs/xfs/libxfs/xfs_ialloc_btree.c   |    7 ++-----
 fs/xfs/libxfs/xfs_refcount_btree.c |    6 ++----
 fs/xfs/libxfs/xfs_rmap.c           |   28 ++++++++++++++++++++++++++++
 fs/xfs/libxfs/xfs_rmap.h           |   34 ++++++++++------------------------
 fs/xfs/scrub/agheader.c            |   25 +++++++------------------
 fs/xfs/scrub/agheader_repair.c     |    5 ++---
 fs/xfs/scrub/alloc.c               |    4 +---
 fs/xfs/scrub/ialloc.c              |   28 +++++++++-------------------
 fs/xfs/scrub/inode.c               |    4 +---
 fs/xfs/scrub/refcount.c            |   15 +++++----------
 fs/xfs/scrub/repair.c              |    4 +---
 fs/xfs/scrub/rmap.c                |    5 +----
 fs/xfs/xfs_extfree_item.c          |    5 ++---
 17 files changed, 84 insertions(+), 116 deletions(-)


diff --git a/fs/xfs/libxfs/xfs_ag.c b/fs/xfs/libxfs/xfs_ag.c
index 9345802c99f7..999ad8d00d43 100644
--- a/fs/xfs/libxfs/xfs_ag.c
+++ b/fs/xfs/libxfs/xfs_ag.c
@@ -414,7 +414,6 @@ xfs_ag_extend_space(
 	struct aghdr_init_data	*id,
 	xfs_extlen_t		len)
 {
-	struct xfs_owner_info	oinfo;
 	struct xfs_buf		*bp;
 	struct xfs_agi		*agi;
 	struct xfs_agf		*agf;
@@ -448,17 +447,17 @@ xfs_ag_extend_space(
 	/*
 	 * Free the new space.
 	 *
-	 * XFS_RMAP_OWN_NULL is used here to tell the rmap btree that
+	 * XFS_RMAP_OINFO_SKIP_UPDATE is used here to tell the rmap btree that
 	 * this doesn't actually exist in the rmap btree.
 	 */
-	xfs_rmap_ag_owner(&oinfo, XFS_RMAP_OWN_NULL);
 	error = xfs_rmap_free(tp, bp, id->agno,
 				be32_to_cpu(agf->agf_length) - len,
-				len, &oinfo);
+				len, &XFS_RMAP_OINFO_SKIP_UPDATE);
 	if (error)
 		return error;
 
 	return  xfs_free_extent(tp, XFS_AGB_TO_FSB(mp, id->agno,
 					be32_to_cpu(agf->agf_length) - len),
-				len, &oinfo, XFS_AG_RESV_NONE);
+				len, &XFS_RMAP_OINFO_SKIP_UPDATE,
+				XFS_AG_RESV_NONE);
 }
diff --git a/fs/xfs/libxfs/xfs_alloc.c b/fs/xfs/libxfs/xfs_alloc.c
index ef039777f314..2b900eb2aec2 100644
--- a/fs/xfs/libxfs/xfs_alloc.c
+++ b/fs/xfs/libxfs/xfs_alloc.c
@@ -1594,7 +1594,6 @@ xfs_alloc_ag_vextent_small(
 	xfs_extlen_t	*flenp,	/* result length */
 	int		*stat)	/* status: 0-freelist, 1-normal/none */
 {
-	struct xfs_owner_info	oinfo;
 	int		error;
 	xfs_agblock_t	fbno;
 	xfs_extlen_t	flen;
@@ -1648,9 +1647,8 @@ xfs_alloc_ag_vextent_small(
 			 * doesn't live in the free space, we need to clear
 			 * out the OWN_AG rmap.
 			 */
-			xfs_rmap_ag_owner(&oinfo, XFS_RMAP_OWN_AG);
 			error = xfs_rmap_free(args->tp, args->agbp, args->agno,
-					fbno, 1, &oinfo);
+					fbno, 1, &XFS_RMAP_OINFO_AG);
 			if (error)
 				goto error0;
 
@@ -2314,10 +2312,11 @@ xfs_alloc_fix_freelist(
 	 * repair/rmap.c in xfsprogs for details.
 	 */
 	memset(&targs, 0, sizeof(targs));
+	/* struct copy below */
 	if (flags & XFS_ALLOC_FLAG_NORMAP)
-		xfs_rmap_skip_owner_update(&targs.oinfo);
+		targs.oinfo = XFS_RMAP_OINFO_SKIP_UPDATE;
 	else
-		xfs_rmap_ag_owner(&targs.oinfo, XFS_RMAP_OWN_AG);
+		targs.oinfo = XFS_RMAP_OINFO_AG;
 	while (!(flags & XFS_ALLOC_FLAG_NOSHRINK) && pag->pagf_flcount > need) {
 		error = xfs_alloc_get_freelist(tp, agbp, &bno, 0);
 		if (error)
diff --git a/fs/xfs/libxfs/xfs_bmap.c b/fs/xfs/libxfs/xfs_bmap.c
index d5672ab58b1f..332eefa2700b 100644
--- a/fs/xfs/libxfs/xfs_bmap.c
+++ b/fs/xfs/libxfs/xfs_bmap.c
@@ -564,7 +564,7 @@ __xfs_bmap_add_free(
 	if (oinfo)
 		new->xefi_oinfo = *oinfo;
 	else
-		xfs_rmap_skip_owner_update(&new->xefi_oinfo);
+		new->xefi_oinfo = XFS_RMAP_OINFO_SKIP_UPDATE;
 	new->xefi_skip_discard = skip_discard;
 	trace_xfs_bmap_free_defer(tp->t_mountp,
 			XFS_FSB_TO_AGNO(tp->t_mountp, bno), 0,
@@ -3453,7 +3453,7 @@ xfs_bmap_btalloc(
 	args.tp = ap->tp;
 	args.mp = mp;
 	args.fsbno = ap->blkno;
-	xfs_rmap_skip_owner_update(&args.oinfo);
+	args.oinfo = XFS_RMAP_OINFO_SKIP_UPDATE;
 
 	/* Trim the allocation back to the maximum an AG can fit. */
 	args.maxlen = min(ap->length, mp->m_ag_max_usable);
diff --git a/fs/xfs/libxfs/xfs_ialloc.c b/fs/xfs/libxfs/xfs_ialloc.c
index a8f6db735d5d..fcf0d17405d8 100644
--- a/fs/xfs/libxfs/xfs_ialloc.c
+++ b/fs/xfs/libxfs/xfs_ialloc.c
@@ -641,7 +641,7 @@ xfs_ialloc_ag_alloc(
 	args.tp = tp;
 	args.mp = tp->t_mountp;
 	args.fsbno = NULLFSBLOCK;
-	xfs_rmap_ag_owner(&args.oinfo, XFS_RMAP_OWN_INODES);
+	args.oinfo = XFS_RMAP_OINFO_INODES;
 
 #ifdef DEBUG
 	/* randomly do sparse inode allocations */
@@ -1849,14 +1849,12 @@ xfs_difree_inode_chunk(
 	int				nextbit;
 	xfs_agblock_t			agbno;
 	int				contigblk;
-	struct xfs_owner_info		oinfo;
 	DECLARE_BITMAP(holemask, XFS_INOBT_HOLEMASK_BITS);
-	xfs_rmap_ag_owner(&oinfo, XFS_RMAP_OWN_INODES);
 
 	if (!xfs_inobt_issparse(rec->ir_holemask)) {
 		/* not sparse, calculate extent info directly */
 		xfs_bmap_add_free(tp, XFS_AGB_TO_FSB(mp, agno, sagbno),
-				  mp->m_ialloc_blks, &oinfo);
+				  mp->m_ialloc_blks, &XFS_RMAP_OINFO_INODES);
 		return;
 	}
 
@@ -1900,7 +1898,7 @@ xfs_difree_inode_chunk(
 		ASSERT(agbno % mp->m_sb.sb_spino_align == 0);
 		ASSERT(contigblk % mp->m_sb.sb_spino_align == 0);
 		xfs_bmap_add_free(tp, XFS_AGB_TO_FSB(mp, agno, agbno),
-				  contigblk, &oinfo);
+				  contigblk, &XFS_RMAP_OINFO_INODES);
 
 		/* reset range to current bit and carry on... */
 		startidx = endidx = nextbit;
diff --git a/fs/xfs/libxfs/xfs_ialloc_btree.c b/fs/xfs/libxfs/xfs_ialloc_btree.c
index 7fbf8af0b159..9b25e7a0df47 100644
--- a/fs/xfs/libxfs/xfs_ialloc_btree.c
+++ b/fs/xfs/libxfs/xfs_ialloc_btree.c
@@ -84,7 +84,7 @@ __xfs_inobt_alloc_block(
 	memset(&args, 0, sizeof(args));
 	args.tp = cur->bc_tp;
 	args.mp = cur->bc_mp;
-	xfs_rmap_ag_owner(&args.oinfo, XFS_RMAP_OWN_INOBT);
+	args.oinfo = XFS_RMAP_OINFO_INOBT;
 	args.fsbno = XFS_AGB_TO_FSB(args.mp, cur->bc_private.a.agno, sbno);
 	args.minlen = 1;
 	args.maxlen = 1;
@@ -136,12 +136,9 @@ __xfs_inobt_free_block(
 	struct xfs_buf		*bp,
 	enum xfs_ag_resv_type	resv)
 {
-	struct xfs_owner_info	oinfo;
-
-	xfs_rmap_ag_owner(&oinfo, XFS_RMAP_OWN_INOBT);
 	return xfs_free_extent(cur->bc_tp,
 			XFS_DADDR_TO_FSB(cur->bc_mp, XFS_BUF_ADDR(bp)), 1,
-			&oinfo, resv);
+			&XFS_RMAP_OINFO_INOBT, resv);
 }
 
 STATIC int
diff --git a/fs/xfs/libxfs/xfs_refcount_btree.c b/fs/xfs/libxfs/xfs_refcount_btree.c
index 1aaa01c97517..d9eab657b63e 100644
--- a/fs/xfs/libxfs/xfs_refcount_btree.c
+++ b/fs/xfs/libxfs/xfs_refcount_btree.c
@@ -70,7 +70,7 @@ xfs_refcountbt_alloc_block(
 	args.type = XFS_ALLOCTYPE_NEAR_BNO;
 	args.fsbno = XFS_AGB_TO_FSB(cur->bc_mp, cur->bc_private.a.agno,
 			xfs_refc_block(args.mp));
-	xfs_rmap_ag_owner(&args.oinfo, XFS_RMAP_OWN_REFC);
+	args.oinfo = XFS_RMAP_OINFO_REFC;
 	args.minlen = args.maxlen = args.prod = 1;
 	args.resv = XFS_AG_RESV_METADATA;
 
@@ -106,15 +106,13 @@ xfs_refcountbt_free_block(
 	struct xfs_buf		*agbp = cur->bc_private.a.agbp;
 	struct xfs_agf		*agf = XFS_BUF_TO_AGF(agbp);
 	xfs_fsblock_t		fsbno = XFS_DADDR_TO_FSB(mp, XFS_BUF_ADDR(bp));
-	struct xfs_owner_info	oinfo;
 	int			error;
 
 	trace_xfs_refcountbt_free_block(cur->bc_mp, cur->bc_private.a.agno,
 			XFS_FSB_TO_AGBNO(cur->bc_mp, fsbno), 1);
-	xfs_rmap_ag_owner(&oinfo, XFS_RMAP_OWN_REFC);
 	be32_add_cpu(&agf->agf_refcount_blocks, -1);
 	xfs_alloc_log_agf(cur->bc_tp, agbp, XFS_AGF_REFCOUNT_BLOCKS);
-	error = xfs_free_extent(cur->bc_tp, fsbno, 1, &oinfo,
+	error = xfs_free_extent(cur->bc_tp, fsbno, 1, &XFS_RMAP_OINFO_REFC,
 			XFS_AG_RESV_METADATA);
 	if (error)
 		return error;
diff --git a/fs/xfs/libxfs/xfs_rmap.c b/fs/xfs/libxfs/xfs_rmap.c
index e7d06295338d..8ed885507dd8 100644
--- a/fs/xfs/libxfs/xfs_rmap.c
+++ b/fs/xfs/libxfs/xfs_rmap.c
@@ -2550,3 +2550,31 @@ xfs_rmap_has_other_keys(
 	*has_rmap = rks.has_rmap;
 	return error;
 }
+
+const struct xfs_owner_info XFS_RMAP_OINFO_SKIP_UPDATE = {
+	.oi_owner = XFS_RMAP_OWN_NULL,
+};
+const struct xfs_owner_info XFS_RMAP_OINFO_ANY_OWNER = {
+	.oi_owner = XFS_RMAP_OWN_UNKNOWN,
+};
+const struct xfs_owner_info XFS_RMAP_OINFO_FS = {
+	.oi_owner = XFS_RMAP_OWN_FS,
+};
+const struct xfs_owner_info XFS_RMAP_OINFO_LOG = {
+	.oi_owner = XFS_RMAP_OWN_LOG,
+};
+const struct xfs_owner_info XFS_RMAP_OINFO_AG = {
+	.oi_owner = XFS_RMAP_OWN_AG,
+};
+const struct xfs_owner_info XFS_RMAP_OINFO_INOBT = {
+	.oi_owner = XFS_RMAP_OWN_INOBT,
+};
+const struct xfs_owner_info XFS_RMAP_OINFO_INODES = {
+	.oi_owner = XFS_RMAP_OWN_INODES,
+};
+const struct xfs_owner_info XFS_RMAP_OINFO_REFC = {
+	.oi_owner = XFS_RMAP_OWN_REFC,
+};
+const struct xfs_owner_info XFS_RMAP_OINFO_COW = {
+	.oi_owner = XFS_RMAP_OWN_COW,
+};
diff --git a/fs/xfs/libxfs/xfs_rmap.h b/fs/xfs/libxfs/xfs_rmap.h
index 6d32838aa184..e21ed0294e5c 100644
--- a/fs/xfs/libxfs/xfs_rmap.h
+++ b/fs/xfs/libxfs/xfs_rmap.h
@@ -6,16 +6,6 @@
 #ifndef __XFS_RMAP_H__
 #define __XFS_RMAP_H__
 
-static inline void
-xfs_rmap_ag_owner(
-	struct xfs_owner_info	*oi,
-	uint64_t		owner)
-{
-	oi->oi_owner = owner;
-	oi->oi_offset = 0;
-	oi->oi_flags = 0;
-}
-
 static inline void
 xfs_rmap_ino_bmbt_owner(
 	struct xfs_owner_info	*oi,
@@ -43,13 +33,6 @@ xfs_rmap_ino_owner(
 		oi->oi_flags |= XFS_OWNER_INFO_ATTR_FORK;
 }
 
-static inline void
-xfs_rmap_skip_owner_update(
-	struct xfs_owner_info	*oi)
-{
-	xfs_rmap_ag_owner(oi, XFS_RMAP_OWN_NULL);
-}
-
 static inline bool
 xfs_rmap_should_skip_owner_update(
 	const struct xfs_owner_info	*oi)
@@ -57,13 +40,6 @@ xfs_rmap_should_skip_owner_update(
 	return oi->oi_owner == XFS_RMAP_OWN_NULL;
 }
 
-static inline void
-xfs_rmap_any_owner_update(
-	struct xfs_owner_info	*oi)
-{
-	xfs_rmap_ag_owner(oi, XFS_RMAP_OWN_UNKNOWN);
-}
-
 /* Reverse mapping functions. */
 
 struct xfs_buf;
@@ -225,4 +201,14 @@ int xfs_rmap_has_other_keys(struct xfs_btree_cur *cur, xfs_agblock_t bno,
 		bool *has_rmap);
 int xfs_rmap_map_raw(struct xfs_btree_cur *cur, struct xfs_rmap_irec *rmap);
 
+extern const struct xfs_owner_info XFS_RMAP_OINFO_SKIP_UPDATE;
+extern const struct xfs_owner_info XFS_RMAP_OINFO_ANY_OWNER;
+extern const struct xfs_owner_info XFS_RMAP_OINFO_FS;
+extern const struct xfs_owner_info XFS_RMAP_OINFO_LOG;
+extern const struct xfs_owner_info XFS_RMAP_OINFO_AG;
+extern const struct xfs_owner_info XFS_RMAP_OINFO_INOBT;
+extern const struct xfs_owner_info XFS_RMAP_OINFO_INODES;
+extern const struct xfs_owner_info XFS_RMAP_OINFO_REFC;
+extern const struct xfs_owner_info XFS_RMAP_OINFO_COW;
+
 #endif	/* __XFS_RMAP_H__ */
diff --git a/fs/xfs/scrub/agheader.c b/fs/xfs/scrub/agheader.c
index 3068a9382feb..90955ab1e895 100644
--- a/fs/xfs/scrub/agheader.c
+++ b/fs/xfs/scrub/agheader.c
@@ -32,7 +32,6 @@ xchk_superblock_xref(
 	struct xfs_scrub	*sc,
 	struct xfs_buf		*bp)
 {
-	struct xfs_owner_info	oinfo;
 	struct xfs_mount	*mp = sc->mp;
 	xfs_agnumber_t		agno = sc->sm->sm_agno;
 	xfs_agblock_t		agbno;
@@ -49,8 +48,7 @@ xchk_superblock_xref(
 
 	xchk_xref_is_used_space(sc, agbno, 1);
 	xchk_xref_is_not_inode_chunk(sc, agbno, 1);
-	xfs_rmap_ag_owner(&oinfo, XFS_RMAP_OWN_FS);
-	xchk_xref_is_owned_by(sc, agbno, 1, &oinfo);
+	xchk_xref_is_owned_by(sc, agbno, 1, &XFS_RMAP_OINFO_FS);
 	xchk_xref_is_not_shared(sc, agbno, 1);
 
 	/* scrub teardown will take care of sc->sa for us */
@@ -484,7 +482,6 @@ STATIC void
 xchk_agf_xref(
 	struct xfs_scrub	*sc)
 {
-	struct xfs_owner_info	oinfo;
 	struct xfs_mount	*mp = sc->mp;
 	xfs_agblock_t		agbno;
 	int			error;
@@ -502,8 +499,7 @@ xchk_agf_xref(
 	xchk_agf_xref_freeblks(sc);
 	xchk_agf_xref_cntbt(sc);
 	xchk_xref_is_not_inode_chunk(sc, agbno, 1);
-	xfs_rmap_ag_owner(&oinfo, XFS_RMAP_OWN_FS);
-	xchk_xref_is_owned_by(sc, agbno, 1, &oinfo);
+	xchk_xref_is_owned_by(sc, agbno, 1, &XFS_RMAP_OINFO_FS);
 	xchk_agf_xref_btreeblks(sc);
 	xchk_xref_is_not_shared(sc, agbno, 1);
 	xchk_agf_xref_refcblks(sc);
@@ -598,7 +594,6 @@ xchk_agf(
 /* AGFL */
 
 struct xchk_agfl_info {
-	struct xfs_owner_info	oinfo;
 	unsigned int		sz_entries;
 	unsigned int		nr_entries;
 	xfs_agblock_t		*entries;
@@ -609,15 +604,14 @@ struct xchk_agfl_info {
 STATIC void
 xchk_agfl_block_xref(
 	struct xfs_scrub	*sc,
-	xfs_agblock_t		agbno,
-	struct xfs_owner_info	*oinfo)
+	xfs_agblock_t		agbno)
 {
 	if (sc->sm->sm_flags & XFS_SCRUB_OFLAG_CORRUPT)
 		return;
 
 	xchk_xref_is_used_space(sc, agbno, 1);
 	xchk_xref_is_not_inode_chunk(sc, agbno, 1);
-	xchk_xref_is_owned_by(sc, agbno, 1, oinfo);
+	xchk_xref_is_owned_by(sc, agbno, 1, &XFS_RMAP_OINFO_AG);
 	xchk_xref_is_not_shared(sc, agbno, 1);
 }
 
@@ -638,7 +632,7 @@ xchk_agfl_block(
 	else
 		xchk_block_set_corrupt(sc, sc->sa.agfl_bp);
 
-	xchk_agfl_block_xref(sc, agbno, priv);
+	xchk_agfl_block_xref(sc, agbno);
 
 	if (sc->sm->sm_flags & XFS_SCRUB_OFLAG_CORRUPT)
 		return XFS_BTREE_QUERY_RANGE_ABORT;
@@ -662,7 +656,6 @@ STATIC void
 xchk_agfl_xref(
 	struct xfs_scrub	*sc)
 {
-	struct xfs_owner_info	oinfo;
 	struct xfs_mount	*mp = sc->mp;
 	xfs_agblock_t		agbno;
 	int			error;
@@ -678,8 +671,7 @@ xchk_agfl_xref(
 
 	xchk_xref_is_used_space(sc, agbno, 1);
 	xchk_xref_is_not_inode_chunk(sc, agbno, 1);
-	xfs_rmap_ag_owner(&oinfo, XFS_RMAP_OWN_FS);
-	xchk_xref_is_owned_by(sc, agbno, 1, &oinfo);
+	xchk_xref_is_owned_by(sc, agbno, 1, &XFS_RMAP_OINFO_FS);
 	xchk_xref_is_not_shared(sc, agbno, 1);
 
 	/*
@@ -732,7 +724,6 @@ xchk_agfl(
 	}
 
 	/* Check the blocks in the AGFL. */
-	xfs_rmap_ag_owner(&sai.oinfo, XFS_RMAP_OWN_AG);
 	error = xfs_agfl_walk(sc->mp, XFS_BUF_TO_AGF(sc->sa.agf_bp),
 			sc->sa.agfl_bp, xchk_agfl_block, &sai);
 	if (error == XFS_BTREE_QUERY_RANGE_ABORT) {
@@ -791,7 +782,6 @@ STATIC void
 xchk_agi_xref(
 	struct xfs_scrub	*sc)
 {
-	struct xfs_owner_info	oinfo;
 	struct xfs_mount	*mp = sc->mp;
 	xfs_agblock_t		agbno;
 	int			error;
@@ -808,8 +798,7 @@ xchk_agi_xref(
 	xchk_xref_is_used_space(sc, agbno, 1);
 	xchk_xref_is_not_inode_chunk(sc, agbno, 1);
 	xchk_agi_xref_icounts(sc);
-	xfs_rmap_ag_owner(&oinfo, XFS_RMAP_OWN_FS);
-	xchk_xref_is_owned_by(sc, agbno, 1, &oinfo);
+	xchk_xref_is_owned_by(sc, agbno, 1, &XFS_RMAP_OINFO_FS);
 	xchk_xref_is_not_shared(sc, agbno, 1);
 
 	/* scrub teardown will take care of sc->sa for us */
diff --git a/fs/xfs/scrub/agheader_repair.c b/fs/xfs/scrub/agheader_repair.c
index f7568a4b5fe5..03d1e15cceba 100644
--- a/fs/xfs/scrub/agheader_repair.c
+++ b/fs/xfs/scrub/agheader_repair.c
@@ -646,7 +646,6 @@ int
 xrep_agfl(
 	struct xfs_scrub	*sc)
 {
-	struct xfs_owner_info	oinfo;
 	struct xfs_bitmap	agfl_extents;
 	struct xfs_mount	*mp = sc->mp;
 	struct xfs_buf		*agf_bp;
@@ -708,8 +707,8 @@ xrep_agfl(
 		goto err;
 
 	/* Dump any AGFL overflow. */
-	xfs_rmap_ag_owner(&oinfo, XFS_RMAP_OWN_AG);
-	return xrep_reap_extents(sc, &agfl_extents, &oinfo, XFS_AG_RESV_AGFL);
+	return xrep_reap_extents(sc, &agfl_extents, &XFS_RMAP_OINFO_AG,
+			XFS_AG_RESV_AGFL);
 err:
 	xfs_bitmap_destroy(&agfl_extents);
 	return error;
diff --git a/fs/xfs/scrub/alloc.c b/fs/xfs/scrub/alloc.c
index 376bcb585ae6..44883e9112ad 100644
--- a/fs/xfs/scrub/alloc.c
+++ b/fs/xfs/scrub/alloc.c
@@ -125,12 +125,10 @@ xchk_allocbt(
 	struct xfs_scrub	*sc,
 	xfs_btnum_t		which)
 {
-	struct xfs_owner_info	oinfo;
 	struct xfs_btree_cur	*cur;
 
-	xfs_rmap_ag_owner(&oinfo, XFS_RMAP_OWN_AG);
 	cur = which == XFS_BTNUM_BNO ? sc->sa.bno_cur : sc->sa.cnt_cur;
-	return xchk_btree(sc, cur, xchk_allocbt_rec, &oinfo, NULL);
+	return xchk_btree(sc, cur, xchk_allocbt_rec, &XFS_RMAP_OINFO_AG, NULL);
 }
 
 int
diff --git a/fs/xfs/scrub/ialloc.c b/fs/xfs/scrub/ialloc.c
index 224dba937492..72f45b298fa5 100644
--- a/fs/xfs/scrub/ialloc.c
+++ b/fs/xfs/scrub/ialloc.c
@@ -82,15 +82,12 @@ xchk_iallocbt_chunk_xref(
 	xfs_agblock_t			agbno,
 	xfs_extlen_t			len)
 {
-	struct xfs_owner_info		oinfo;
-
 	if (sc->sm->sm_flags & XFS_SCRUB_OFLAG_CORRUPT)
 		return;
 
 	xchk_xref_is_used_space(sc, agbno, len);
 	xchk_iallocbt_chunk_xref_other(sc, irec, agino);
-	xfs_rmap_ag_owner(&oinfo, XFS_RMAP_OWN_INODES);
-	xchk_xref_is_owned_by(sc, agbno, len, &oinfo);
+	xchk_xref_is_owned_by(sc, agbno, len, &XFS_RMAP_OINFO_INODES);
 	xchk_xref_is_not_shared(sc, agbno, len);
 }
 
@@ -186,7 +183,6 @@ xchk_iallocbt_check_freemask(
 	struct xchk_btree		*bs,
 	struct xfs_inobt_rec_incore	*irec)
 {
-	struct xfs_owner_info		oinfo;
 	struct xfs_imap			imap;
 	struct xfs_mount		*mp = bs->cur->bc_mp;
 	struct xfs_dinode		*dip;
@@ -205,7 +201,6 @@ xchk_iallocbt_check_freemask(
 	/* Make sure the freemask matches the inode records. */
 	blks_per_cluster = xfs_icluster_size_fsb(mp);
 	nr_inodes = XFS_OFFBNO_TO_AGINO(mp, blks_per_cluster, 0);
-	xfs_rmap_ag_owner(&oinfo, XFS_RMAP_OWN_INODES);
 
 	for (agino = irec->ir_startino;
 	     agino < irec->ir_startino + XFS_INODES_PER_CHUNK;
@@ -230,12 +225,13 @@ xchk_iallocbt_check_freemask(
 		/* If any part of this is a hole, skip it. */
 		if (ir_holemask) {
 			xchk_xref_is_not_owned_by(bs->sc, agbno,
-					blks_per_cluster, &oinfo);
+					blks_per_cluster,
+					&XFS_RMAP_OINFO_INODES);
 			continue;
 		}
 
 		xchk_xref_is_owned_by(bs->sc, agbno, blks_per_cluster,
-				&oinfo);
+				&XFS_RMAP_OINFO_INODES);
 
 		/* Grab the inode cluster buffer. */
 		imap.im_blkno = XFS_AGB_TO_DADDR(mp, bs->cur->bc_private.a.agno,
@@ -366,7 +362,6 @@ xchk_iallocbt_xref_rmap_btreeblks(
 	struct xfs_scrub	*sc,
 	int			which)
 {
-	struct xfs_owner_info	oinfo;
 	xfs_filblks_t		blocks;
 	xfs_extlen_t		inobt_blocks = 0;
 	xfs_extlen_t		finobt_blocks = 0;
@@ -388,9 +383,8 @@ xchk_iallocbt_xref_rmap_btreeblks(
 			return;
 	}
 
-	xfs_rmap_ag_owner(&oinfo, XFS_RMAP_OWN_INOBT);
-	error = xchk_count_rmap_ownedby_ag(sc, sc->sa.rmap_cur, &oinfo,
-			&blocks);
+	error = xchk_count_rmap_ownedby_ag(sc, sc->sa.rmap_cur,
+			&XFS_RMAP_OINFO_INOBT, &blocks);
 	if (!xchk_should_check_xref(sc, &error, &sc->sa.rmap_cur))
 		return;
 	if (blocks != inobt_blocks + finobt_blocks)
@@ -407,7 +401,6 @@ xchk_iallocbt_xref_rmap_inodes(
 	int			which,
 	xfs_filblks_t		inode_blocks)
 {
-	struct xfs_owner_info	oinfo;
 	xfs_filblks_t		blocks;
 	int			error;
 
@@ -415,9 +408,8 @@ xchk_iallocbt_xref_rmap_inodes(
 		return;
 
 	/* Check that we saw as many inode blocks as the rmap knows about. */
-	xfs_rmap_ag_owner(&oinfo, XFS_RMAP_OWN_INODES);
-	error = xchk_count_rmap_ownedby_ag(sc, sc->sa.rmap_cur, &oinfo,
-			&blocks);
+	error = xchk_count_rmap_ownedby_ag(sc, sc->sa.rmap_cur,
+			&XFS_RMAP_OINFO_INODES, &blocks);
 	if (!xchk_should_check_xref(sc, &error, &sc->sa.rmap_cur))
 		return;
 	if (blocks != inode_blocks)
@@ -431,13 +423,11 @@ xchk_iallocbt(
 	xfs_btnum_t		which)
 {
 	struct xfs_btree_cur	*cur;
-	struct xfs_owner_info	oinfo;
 	xfs_filblks_t		inode_blocks = 0;
 	int			error;
 
-	xfs_rmap_ag_owner(&oinfo, XFS_RMAP_OWN_INOBT);
 	cur = which == XFS_BTNUM_INO ? sc->sa.ino_cur : sc->sa.fino_cur;
-	error = xchk_btree(sc, cur, xchk_iallocbt_rec, &oinfo,
+	error = xchk_btree(sc, cur, xchk_iallocbt_rec, &XFS_RMAP_OINFO_INOBT,
 			&inode_blocks);
 	if (error)
 		return error;
diff --git a/fs/xfs/scrub/inode.c b/fs/xfs/scrub/inode.c
index e386c9b0b4ab..e213efc194a1 100644
--- a/fs/xfs/scrub/inode.c
+++ b/fs/xfs/scrub/inode.c
@@ -509,7 +509,6 @@ xchk_inode_xref(
 	xfs_ino_t		ino,
 	struct xfs_dinode	*dip)
 {
-	struct xfs_owner_info	oinfo;
 	xfs_agnumber_t		agno;
 	xfs_agblock_t		agbno;
 	int			error;
@@ -526,8 +525,7 @@ xchk_inode_xref(
 
 	xchk_xref_is_used_space(sc, agbno, 1);
 	xchk_inode_xref_finobt(sc, ino);
-	xfs_rmap_ag_owner(&oinfo, XFS_RMAP_OWN_INODES);
-	xchk_xref_is_owned_by(sc, agbno, 1, &oinfo);
+	xchk_xref_is_owned_by(sc, agbno, 1, &XFS_RMAP_OINFO_INODES);
 	xchk_xref_is_not_shared(sc, agbno, 1);
 	xchk_inode_xref_bmap(sc, dip);
 
diff --git a/fs/xfs/scrub/refcount.c b/fs/xfs/scrub/refcount.c
index b7ade620acee..708b4158eb90 100644
--- a/fs/xfs/scrub/refcount.c
+++ b/fs/xfs/scrub/refcount.c
@@ -385,7 +385,6 @@ xchk_refcount_xref_rmap(
 	struct xfs_scrub	*sc,
 	xfs_filblks_t		cow_blocks)
 {
-	struct xfs_owner_info	oinfo;
 	xfs_extlen_t		refcbt_blocks = 0;
 	xfs_filblks_t		blocks;
 	int			error;
@@ -394,21 +393,19 @@ xchk_refcount_xref_rmap(
 		return;
 
 	/* Check that we saw as many refcbt blocks as the rmap knows about. */
-	xfs_rmap_ag_owner(&oinfo, XFS_RMAP_OWN_REFC);
 	error = xfs_btree_count_blocks(sc->sa.refc_cur, &refcbt_blocks);
 	if (!xchk_btree_process_error(sc, sc->sa.refc_cur, 0, &error))
 		return;
-	error = xchk_count_rmap_ownedby_ag(sc, sc->sa.rmap_cur, &oinfo,
-			&blocks);
+	error = xchk_count_rmap_ownedby_ag(sc, sc->sa.rmap_cur,
+			&XFS_RMAP_OINFO_REFC, &blocks);
 	if (!xchk_should_check_xref(sc, &error, &sc->sa.rmap_cur))
 		return;
 	if (blocks != refcbt_blocks)
 		xchk_btree_xref_set_corrupt(sc, sc->sa.rmap_cur, 0);
 
 	/* Check that we saw as many cow blocks as the rmap knows about. */
-	xfs_rmap_ag_owner(&oinfo, XFS_RMAP_OWN_COW);
-	error = xchk_count_rmap_ownedby_ag(sc, sc->sa.rmap_cur, &oinfo,
-			&blocks);
+	error = xchk_count_rmap_ownedby_ag(sc, sc->sa.rmap_cur,
+			&XFS_RMAP_OINFO_COW, &blocks);
 	if (!xchk_should_check_xref(sc, &error, &sc->sa.rmap_cur))
 		return;
 	if (blocks != cow_blocks)
@@ -420,13 +417,11 @@ int
 xchk_refcountbt(
 	struct xfs_scrub	*sc)
 {
-	struct xfs_owner_info	oinfo;
 	xfs_agblock_t		cow_blocks = 0;
 	int			error;
 
-	xfs_rmap_ag_owner(&oinfo, XFS_RMAP_OWN_REFC);
 	error = xchk_btree(sc, sc->sa.refc_cur, xchk_refcountbt_rec,
-			&oinfo, &cow_blocks);
+			&XFS_RMAP_OINFO_REFC, &cow_blocks);
 	if (error)
 		return error;
 
diff --git a/fs/xfs/scrub/repair.c b/fs/xfs/scrub/repair.c
index 90ae9e173de7..1c8eecfe52b8 100644
--- a/fs/xfs/scrub/repair.c
+++ b/fs/xfs/scrub/repair.c
@@ -505,7 +505,6 @@ xrep_put_freelist(
 	struct xfs_scrub	*sc,
 	xfs_agblock_t		agbno)
 {
-	struct xfs_owner_info	oinfo;
 	int			error;
 
 	/* Make sure there's space on the freelist. */
@@ -518,9 +517,8 @@ xrep_put_freelist(
 	 * create an rmap for the block prior to merging it or else other
 	 * parts will break.
 	 */
-	xfs_rmap_ag_owner(&oinfo, XFS_RMAP_OWN_AG);
 	error = xfs_rmap_alloc(sc->tp, sc->sa.agf_bp, sc->sa.agno, agbno, 1,
-			&oinfo);
+			&XFS_RMAP_OINFO_AG);
 	if (error)
 		return error;
 
diff --git a/fs/xfs/scrub/rmap.c b/fs/xfs/scrub/rmap.c
index 8a5bf15d544d..92a140c5b55e 100644
--- a/fs/xfs/scrub/rmap.c
+++ b/fs/xfs/scrub/rmap.c
@@ -174,11 +174,8 @@ int
 xchk_rmapbt(
 	struct xfs_scrub	*sc)
 {
-	struct xfs_owner_info	oinfo;
-
-	xfs_rmap_ag_owner(&oinfo, XFS_RMAP_OWN_AG);
 	return xchk_btree(sc, sc->sa.rmap_cur, xchk_rmapbt_rec,
-			&oinfo, NULL);
+			&XFS_RMAP_OINFO_AG, NULL);
 }
 
 /* xref check that the extent is owned by a given owner */
diff --git a/fs/xfs/xfs_extfree_item.c b/fs/xfs/xfs_extfree_item.c
index d9da66c718bb..74ddf66f4cfe 100644
--- a/fs/xfs/xfs_extfree_item.c
+++ b/fs/xfs/xfs_extfree_item.c
@@ -494,7 +494,6 @@ xfs_efi_recover(
 	int			error = 0;
 	xfs_extent_t		*extp;
 	xfs_fsblock_t		startblock_fsb;
-	struct xfs_owner_info	oinfo;
 
 	ASSERT(!test_bit(XFS_EFI_RECOVERED, &efip->efi_flags));
 
@@ -526,11 +525,11 @@ xfs_efi_recover(
 		return error;
 	efdp = xfs_trans_get_efd(tp, efip, efip->efi_format.efi_nextents);
 
-	xfs_rmap_any_owner_update(&oinfo);
 	for (i = 0; i < efip->efi_format.efi_nextents; i++) {
 		extp = &efip->efi_format.efi_extents[i];
 		error = xfs_trans_free_extent(tp, efdp, extp->ext_start,
-					      extp->ext_len, &oinfo, false);
+					      extp->ext_len,
+					      &XFS_RMAP_OINFO_ANY_OWNER, false);
 		if (error)
 			goto abort_error;
 

^ permalink raw reply related	[flat|nested] 7+ messages in thread

* [PATCH 2/4] xfs: add a block to inode count converter
  2018-11-28 23:26 [PATCH 0/4] xfs-5.0: cleanups Darrick J. Wong
  2018-11-28 23:26 ` [PATCH 1/4] xfs: remove xfs_rmap_ag_owner and friends Darrick J. Wong
@ 2018-11-28 23:26 ` Darrick J. Wong
  2018-11-28 23:26 ` [PATCH 3/4] xfs: precalculate inodes and blocks per inode cluster Darrick J. Wong
  2018-11-28 23:26 ` [PATCH 4/4] xfs: precalculate cluster alignment in inodes and blocks Darrick J. Wong
  3 siblings, 0 replies; 7+ messages in thread
From: Darrick J. Wong @ 2018-11-28 23:26 UTC (permalink / raw)
  To: darrick.wong; +Cc: linux-xfs, Brian Foster

From: Darrick J. Wong <darrick.wong@oracle.com>

Add new helpers to convert units of fs blocks into inodes, and AG blocks
into AG inodes, respectively.  Convert all the open-coded conversions
and XFS_OFFBNO_TO_AGINO(, , 0) calls to use them, as appropriate.  The
OFFBNO_TO_AGINO macro is retained for xfs_repair.

Signed-off-by: Darrick J. Wong <darrick.wong@oracle.com>
Reviewed-by: Brian Foster <bfoster@redhat.com>
---
 fs/xfs/libxfs/xfs_format.h |    2 ++
 fs/xfs/libxfs/xfs_ialloc.c |   17 ++++++++---------
 fs/xfs/libxfs/xfs_types.c  |    4 ++--
 fs/xfs/scrub/ialloc.c      |    2 +-
 fs/xfs/xfs_fsops.c         |    2 +-
 fs/xfs/xfs_inode.c         |    2 +-
 fs/xfs/xfs_itable.c        |    2 +-
 fs/xfs/xfs_super.c         |    4 ++--
 8 files changed, 18 insertions(+), 17 deletions(-)


diff --git a/fs/xfs/libxfs/xfs_format.h b/fs/xfs/libxfs/xfs_format.h
index 9995d5ae380b..b15412e4c535 100644
--- a/fs/xfs/libxfs/xfs_format.h
+++ b/fs/xfs/libxfs/xfs_format.h
@@ -1083,6 +1083,8 @@ static inline void xfs_dinode_put_rdev(struct xfs_dinode *dip, xfs_dev_t rdev)
 	((i) & XFS_INO_MASK(XFS_INO_OFFSET_BITS(mp)))
 #define	XFS_OFFBNO_TO_AGINO(mp,b,o)	\
 	((xfs_agino_t)(((b) << XFS_INO_OFFSET_BITS(mp)) | (o)))
+#define	XFS_FSB_TO_INO(mp, b)	((xfs_ino_t)((b) << XFS_INO_OFFSET_BITS(mp)))
+#define	XFS_AGB_TO_AGINO(mp, b)	((xfs_agino_t)((b) << XFS_INO_OFFSET_BITS(mp)))
 
 #define	XFS_MAXINUMBER		((xfs_ino_t)((1ULL << 56) - 1ULL))
 #define	XFS_MAXINUMBER_32	((xfs_ino_t)((1ULL << 32) - 1ULL))
diff --git a/fs/xfs/libxfs/xfs_ialloc.c b/fs/xfs/libxfs/xfs_ialloc.c
index fcf0d17405d8..3ac4a836428d 100644
--- a/fs/xfs/libxfs/xfs_ialloc.c
+++ b/fs/xfs/libxfs/xfs_ialloc.c
@@ -300,7 +300,7 @@ xfs_ialloc_inode_init(
 	 * blocks size.
 	 */
 	blks_per_cluster = xfs_icluster_size_fsb(mp);
-	inodes_per_cluster = blks_per_cluster << mp->m_sb.sb_inopblog;
+	inodes_per_cluster = XFS_FSB_TO_INO(mp, blks_per_cluster);
 	nbufs = length / blks_per_cluster;
 
 	/*
@@ -312,7 +312,7 @@ xfs_ialloc_inode_init(
 	 *
 	 * For v3 inodes, we also need to write the inode number into the inode,
 	 * so calculate the first inode number of the chunk here as
-	 * XFS_OFFBNO_TO_AGINO() only works within a filesystem block, not
+	 * XFS_AGB_TO_AGINO() only works within a filesystem block, not
 	 * across multiple filesystem blocks (such as a cluster) and so cannot
 	 * be used in the cluster buffer loop below.
 	 *
@@ -324,8 +324,7 @@ xfs_ialloc_inode_init(
 	 */
 	if (xfs_sb_version_hascrc(&mp->m_sb)) {
 		version = 3;
-		ino = XFS_AGINO_TO_INO(mp, agno,
-				       XFS_OFFBNO_TO_AGINO(mp, agbno, 0));
+		ino = XFS_AGINO_TO_INO(mp, agno, XFS_AGB_TO_AGINO(mp, agbno));
 
 		/*
 		 * log the initialisation that is about to take place as an
@@ -445,7 +444,7 @@ xfs_align_sparse_ino(
 		return;
 
 	/* calculate the inode offset and align startino */
-	offset = mod << mp->m_sb.sb_inopblog;
+	offset = XFS_AGB_TO_AGINO(mp, mod);
 	*startino -= offset;
 
 	/*
@@ -797,7 +796,7 @@ xfs_ialloc_ag_alloc(
 		if (error)
 			return error;
 
-		newlen = args.len << args.mp->m_sb.sb_inopblog;
+		newlen = XFS_AGB_TO_AGINO(args.mp, args.len);
 		ASSERT(newlen <= XFS_INODES_PER_CHUNK);
 		allocmask = (1 << (newlen / XFS_INODES_PER_HOLEMASK_BIT)) - 1;
 	}
@@ -825,7 +824,7 @@ xfs_ialloc_ag_alloc(
 	/*
 	 * Convert the results.
 	 */
-	newino = XFS_OFFBNO_TO_AGINO(args.mp, args.agbno, 0);
+	newino = XFS_AGB_TO_AGINO(args.mp, args.agbno);
 
 	if (xfs_inobt_issparse(~allocmask)) {
 		/*
@@ -2724,8 +2723,8 @@ xfs_ialloc_has_inodes_at_extent(
 	xfs_agino_t		low;
 	xfs_agino_t		high;
 
-	low = XFS_OFFBNO_TO_AGINO(cur->bc_mp, bno, 0);
-	high = XFS_OFFBNO_TO_AGINO(cur->bc_mp, bno + len, 0) - 1;
+	low = XFS_AGB_TO_AGINO(cur->bc_mp, bno);
+	high = XFS_AGB_TO_AGINO(cur->bc_mp, bno + len) - 1;
 
 	return xfs_ialloc_has_inode_record(cur, low, high, exists);
 }
diff --git a/fs/xfs/libxfs/xfs_types.c b/fs/xfs/libxfs/xfs_types.c
index 33a5ca346baf..895c232d63b7 100644
--- a/fs/xfs/libxfs/xfs_types.c
+++ b/fs/xfs/libxfs/xfs_types.c
@@ -89,14 +89,14 @@ xfs_agino_range(
 	 */
 	bno = round_up(XFS_AGFL_BLOCK(mp) + 1,
 			xfs_ialloc_cluster_alignment(mp));
-	*first = XFS_OFFBNO_TO_AGINO(mp, bno, 0);
+	*first = XFS_AGB_TO_AGINO(mp, bno);
 
 	/*
 	 * Calculate the last inode, which will be at the end of the
 	 * last (aligned) cluster that can be allocated in the AG.
 	 */
 	bno = round_down(eoag, xfs_ialloc_cluster_alignment(mp));
-	*last = XFS_OFFBNO_TO_AGINO(mp, bno, 0) - 1;
+	*last = XFS_AGB_TO_AGINO(mp, bno) - 1;
 }
 
 /*
diff --git a/fs/xfs/scrub/ialloc.c b/fs/xfs/scrub/ialloc.c
index 72f45b298fa5..426eb1a5503c 100644
--- a/fs/xfs/scrub/ialloc.c
+++ b/fs/xfs/scrub/ialloc.c
@@ -200,7 +200,7 @@ xchk_iallocbt_check_freemask(
 
 	/* Make sure the freemask matches the inode records. */
 	blks_per_cluster = xfs_icluster_size_fsb(mp);
-	nr_inodes = XFS_OFFBNO_TO_AGINO(mp, blks_per_cluster, 0);
+	nr_inodes = XFS_FSB_TO_INO(mp, blks_per_cluster);
 
 	for (agino = irec->ir_startino;
 	     agino < irec->ir_startino + XFS_INODES_PER_CHUNK;
diff --git a/fs/xfs/xfs_fsops.c b/fs/xfs/xfs_fsops.c
index 093c2b8d7e20..ec2e63a7963b 100644
--- a/fs/xfs/xfs_fsops.c
+++ b/fs/xfs/xfs_fsops.c
@@ -252,7 +252,7 @@ xfs_growfs_data(
 	if (mp->m_sb.sb_imax_pct) {
 		uint64_t icount = mp->m_sb.sb_dblocks * mp->m_sb.sb_imax_pct;
 		do_div(icount, 100);
-		mp->m_maxicount = icount << mp->m_sb.sb_inopblog;
+		mp->m_maxicount = XFS_FSB_TO_INO(mp, icount);
 	} else
 		mp->m_maxicount = 0;
 
diff --git a/fs/xfs/xfs_inode.c b/fs/xfs/xfs_inode.c
index f21756751540..801eb891d0fd 100644
--- a/fs/xfs/xfs_inode.c
+++ b/fs/xfs/xfs_inode.c
@@ -2200,7 +2200,7 @@ xfs_ifree_cluster(
 	inum = xic->first_ino;
 	pag = xfs_perag_get(mp, XFS_INO_TO_AGNO(mp, inum));
 	blks_per_cluster = xfs_icluster_size_fsb(mp);
-	inodes_per_cluster = blks_per_cluster << mp->m_sb.sb_inopblog;
+	inodes_per_cluster = XFS_FSB_TO_INO(mp, blks_per_cluster);
 	nbufs = mp->m_ialloc_blks / blks_per_cluster;
 
 	for (j = 0; j < nbufs; j++, inum += inodes_per_cluster) {
diff --git a/fs/xfs/xfs_itable.c b/fs/xfs/xfs_itable.c
index e9508ba01ed1..18d8d3b812a7 100644
--- a/fs/xfs/xfs_itable.c
+++ b/fs/xfs/xfs_itable.c
@@ -173,7 +173,7 @@ xfs_bulkstat_ichunk_ra(
 
 	agbno = XFS_AGINO_TO_AGBNO(mp, irec->ir_startino);
 	blks_per_cluster = xfs_icluster_size_fsb(mp);
-	inodes_per_cluster = blks_per_cluster << mp->m_sb.sb_inopblog;
+	inodes_per_cluster = XFS_FSB_TO_INO(mp, blks_per_cluster);
 
 	blk_start_plug(&plug);
 	for (i = 0; i < XFS_INODES_PER_CHUNK;
diff --git a/fs/xfs/xfs_super.c b/fs/xfs/xfs_super.c
index a2e944b80d2a..c9097cb0b955 100644
--- a/fs/xfs/xfs_super.c
+++ b/fs/xfs/xfs_super.c
@@ -608,7 +608,7 @@ xfs_set_inode_alloc(
 	}
 
 	/* Get the last possible inode in the filesystem */
-	agino =	XFS_OFFBNO_TO_AGINO(mp, sbp->sb_agblocks - 1, 0);
+	agino =	XFS_AGB_TO_AGINO(mp, sbp->sb_agblocks - 1);
 	ino = XFS_AGINO_TO_INO(mp, agcount - 1, agino);
 
 	/*
@@ -1150,7 +1150,7 @@ xfs_fs_statfs(
 	statp->f_bfree = fdblocks - mp->m_alloc_set_aside;
 	statp->f_bavail = statp->f_bfree;
 
-	fakeinos = statp->f_bfree << sbp->sb_inopblog;
+	fakeinos = XFS_FSB_TO_INO(mp, statp->f_bfree);
 	statp->f_files = min(icount + fakeinos, (uint64_t)XFS_MAXINUMBER);
 	if (mp->m_maxicount)
 		statp->f_files = min_t(typeof(statp->f_files),

^ permalink raw reply related	[flat|nested] 7+ messages in thread

* [PATCH 3/4] xfs: precalculate inodes and blocks per inode cluster
  2018-11-28 23:26 [PATCH 0/4] xfs-5.0: cleanups Darrick J. Wong
  2018-11-28 23:26 ` [PATCH 1/4] xfs: remove xfs_rmap_ag_owner and friends Darrick J. Wong
  2018-11-28 23:26 ` [PATCH 2/4] xfs: add a block to inode count converter Darrick J. Wong
@ 2018-11-28 23:26 ` Darrick J. Wong
  2018-11-29 15:00   ` Brian Foster
  2018-11-28 23:26 ` [PATCH 4/4] xfs: precalculate cluster alignment in inodes and blocks Darrick J. Wong
  3 siblings, 1 reply; 7+ messages in thread
From: Darrick J. Wong @ 2018-11-28 23:26 UTC (permalink / raw)
  To: darrick.wong; +Cc: linux-xfs

From: Darrick J. Wong <darrick.wong@oracle.com>

Store the number of inodes and blocks per inode cluster in the mount
data so that we don't have to keep recalculating them.

Signed-off-by: Darrick J. Wong <darrick.wong@oracle.com>
---
 fs/xfs/libxfs/xfs_ialloc.c |   23 ++++++++++-------------
 fs/xfs/scrub/ialloc.c      |   14 ++++++--------
 fs/xfs/xfs_inode.c         |   14 +++++---------
 fs/xfs/xfs_itable.c        |   14 ++++++--------
 fs/xfs/xfs_log_recover.c   |    8 +++-----
 fs/xfs/xfs_mount.c         |    2 ++
 fs/xfs/xfs_mount.h         |    2 ++
 7 files changed, 34 insertions(+), 43 deletions(-)


diff --git a/fs/xfs/libxfs/xfs_ialloc.c b/fs/xfs/libxfs/xfs_ialloc.c
index 3ac4a836428d..c7b2579a8e73 100644
--- a/fs/xfs/libxfs/xfs_ialloc.c
+++ b/fs/xfs/libxfs/xfs_ialloc.c
@@ -288,7 +288,7 @@ xfs_ialloc_inode_init(
 {
 	struct xfs_buf		*fbuf;
 	struct xfs_dinode	*free;
-	int			nbufs, blks_per_cluster, inodes_per_cluster;
+	int			nbufs;
 	int			version;
 	int			i, j;
 	xfs_daddr_t		d;
@@ -299,9 +299,7 @@ xfs_ialloc_inode_init(
 	 * sizes, manipulate the inodes in buffers  which are multiples of the
 	 * blocks size.
 	 */
-	blks_per_cluster = xfs_icluster_size_fsb(mp);
-	inodes_per_cluster = XFS_FSB_TO_INO(mp, blks_per_cluster);
-	nbufs = length / blks_per_cluster;
+	nbufs = length / mp->m_blocks_per_cluster;
 
 	/*
 	 * Figure out what version number to use in the inodes we create.  If
@@ -344,9 +342,10 @@ xfs_ialloc_inode_init(
 		/*
 		 * Get the block.
 		 */
-		d = XFS_AGB_TO_DADDR(mp, agno, agbno + (j * blks_per_cluster));
+		d = XFS_AGB_TO_DADDR(mp, agno, agbno +
+				(j * mp->m_blocks_per_cluster));
 		fbuf = xfs_trans_get_buf(tp, mp->m_ddev_targp, d,
-					 mp->m_bsize * blks_per_cluster,
+					 mp->m_bsize * mp->m_blocks_per_cluster,
 					 XBF_UNMAPPED);
 		if (!fbuf)
 			return -ENOMEM;
@@ -354,7 +353,7 @@ xfs_ialloc_inode_init(
 		/* Initialize the inode buffers and log them appropriately. */
 		fbuf->b_ops = &xfs_inode_buf_ops;
 		xfs_buf_zero(fbuf, 0, BBTOB(fbuf->b_length));
-		for (i = 0; i < inodes_per_cluster; i++) {
+		for (i = 0; i < mp->m_inodes_per_cluster; i++) {
 			int	ioffset = i << mp->m_sb.sb_inodelog;
 			uint	isize = xfs_dinode_size(version);
 
@@ -2289,7 +2288,6 @@ xfs_imap(
 	xfs_agblock_t	agbno;	/* block number of inode in the alloc group */
 	xfs_agino_t	agino;	/* inode number within alloc group */
 	xfs_agnumber_t	agno;	/* allocation group number */
-	int		blks_per_cluster; /* num blocks per inode cluster */
 	xfs_agblock_t	chunk_agbno;	/* first block in inode chunk */
 	xfs_agblock_t	cluster_agbno;	/* first block in inode cluster */
 	int		error;	/* error code */
@@ -2335,8 +2333,6 @@ xfs_imap(
 		return -EINVAL;
 	}
 
-	blks_per_cluster = xfs_icluster_size_fsb(mp);
-
 	/*
 	 * For bulkstat and handle lookups, we have an untrusted inode number
 	 * that we have to verify is valid. We cannot do this just by reading
@@ -2356,7 +2352,7 @@ xfs_imap(
 	 * If the inode cluster size is the same as the blocksize or
 	 * smaller we get to the buffer by simple arithmetics.
 	 */
-	if (blks_per_cluster == 1) {
+	if (mp->m_blocks_per_cluster == 1) {
 		offset = XFS_INO_TO_OFFSET(mp, ino);
 		ASSERT(offset < mp->m_sb.sb_inopblock);
 
@@ -2385,12 +2381,13 @@ xfs_imap(
 out_map:
 	ASSERT(agbno >= chunk_agbno);
 	cluster_agbno = chunk_agbno +
-		((offset_agbno / blks_per_cluster) * blks_per_cluster);
+		((offset_agbno / mp->m_blocks_per_cluster) *
+		 mp->m_blocks_per_cluster);
 	offset = ((agbno - cluster_agbno) * mp->m_sb.sb_inopblock) +
 		XFS_INO_TO_OFFSET(mp, ino);
 
 	imap->im_blkno = XFS_AGB_TO_DADDR(mp, agno, cluster_agbno);
-	imap->im_len = XFS_FSB_TO_BB(mp, blks_per_cluster);
+	imap->im_len = XFS_FSB_TO_BB(mp, mp->m_blocks_per_cluster);
 	imap->im_boffset = (unsigned short)(offset << mp->m_sb.sb_inodelog);
 
 	/*
diff --git a/fs/xfs/scrub/ialloc.c b/fs/xfs/scrub/ialloc.c
index 426eb1a5503c..596a02b8efdc 100644
--- a/fs/xfs/scrub/ialloc.c
+++ b/fs/xfs/scrub/ialloc.c
@@ -193,18 +193,16 @@ xchk_iallocbt_check_freemask(
 	xfs_agino_t			chunkino;
 	xfs_agino_t			clusterino;
 	xfs_agblock_t			agbno;
-	int				blks_per_cluster;
 	uint16_t			holemask;
 	uint16_t			ir_holemask;
 	int				error = 0;
 
 	/* Make sure the freemask matches the inode records. */
-	blks_per_cluster = xfs_icluster_size_fsb(mp);
-	nr_inodes = XFS_FSB_TO_INO(mp, blks_per_cluster);
+	nr_inodes = mp->m_inodes_per_cluster;
 
 	for (agino = irec->ir_startino;
 	     agino < irec->ir_startino + XFS_INODES_PER_CHUNK;
-	     agino += blks_per_cluster * mp->m_sb.sb_inopblock) {
+	     agino += mp->m_inodes_per_cluster) {
 		fsino = XFS_AGINO_TO_INO(mp, bs->cur->bc_private.a.agno, agino);
 		chunkino = agino - irec->ir_startino;
 		agbno = XFS_AGINO_TO_AGBNO(mp, agino);
@@ -225,18 +223,18 @@ xchk_iallocbt_check_freemask(
 		/* If any part of this is a hole, skip it. */
 		if (ir_holemask) {
 			xchk_xref_is_not_owned_by(bs->sc, agbno,
-					blks_per_cluster,
+					mp->m_blocks_per_cluster,
 					&XFS_RMAP_OINFO_INODES);
 			continue;
 		}
 
-		xchk_xref_is_owned_by(bs->sc, agbno, blks_per_cluster,
+		xchk_xref_is_owned_by(bs->sc, agbno, mp->m_blocks_per_cluster,
 				&XFS_RMAP_OINFO_INODES);
 
 		/* Grab the inode cluster buffer. */
 		imap.im_blkno = XFS_AGB_TO_DADDR(mp, bs->cur->bc_private.a.agno,
 				agbno);
-		imap.im_len = XFS_FSB_TO_BB(mp, blks_per_cluster);
+		imap.im_len = XFS_FSB_TO_BB(mp, mp->m_blocks_per_cluster);
 		imap.im_boffset = 0;
 
 		error = xfs_imap_to_bp(mp, bs->cur->bc_tp, &imap,
@@ -303,7 +301,7 @@ xchk_iallocbt_rec(
 	/* Make sure this record is aligned to cluster and inoalignmnt size. */
 	agbno = XFS_AGINO_TO_AGBNO(mp, irec.ir_startino);
 	if ((agbno & (xfs_ialloc_cluster_alignment(mp) - 1)) ||
-	    (agbno & (xfs_icluster_size_fsb(mp) - 1)))
+	    (agbno & (mp->m_blocks_per_cluster - 1)))
 		xchk_btree_set_corrupt(bs->sc, bs->cur, 0);
 
 	*inode_blocks += XFS_B_TO_FSB(mp,
diff --git a/fs/xfs/xfs_inode.c b/fs/xfs/xfs_inode.c
index 801eb891d0fd..ae667ba74a1c 100644
--- a/fs/xfs/xfs_inode.c
+++ b/fs/xfs/xfs_inode.c
@@ -2184,8 +2184,6 @@ xfs_ifree_cluster(
 	struct xfs_icluster	*xic)
 {
 	xfs_mount_t		*mp = free_ip->i_mount;
-	int			blks_per_cluster;
-	int			inodes_per_cluster;
 	int			nbufs;
 	int			i, j;
 	int			ioffset;
@@ -2199,11 +2197,9 @@ xfs_ifree_cluster(
 
 	inum = xic->first_ino;
 	pag = xfs_perag_get(mp, XFS_INO_TO_AGNO(mp, inum));
-	blks_per_cluster = xfs_icluster_size_fsb(mp);
-	inodes_per_cluster = XFS_FSB_TO_INO(mp, blks_per_cluster);
-	nbufs = mp->m_ialloc_blks / blks_per_cluster;
+	nbufs = mp->m_ialloc_blks / mp->m_blocks_per_cluster;
 
-	for (j = 0; j < nbufs; j++, inum += inodes_per_cluster) {
+	for (j = 0; j < nbufs; j++, inum += mp->m_inodes_per_cluster) {
 		/*
 		 * The allocation bitmap tells us which inodes of the chunk were
 		 * physically allocated. Skip the cluster if an inode falls into
@@ -2211,7 +2207,7 @@ xfs_ifree_cluster(
 		 */
 		ioffset = inum - xic->first_ino;
 		if ((xic->alloc & XFS_INOBT_MASK(ioffset)) == 0) {
-			ASSERT(ioffset % inodes_per_cluster == 0);
+			ASSERT(ioffset % mp->m_inodes_per_cluster == 0);
 			continue;
 		}
 
@@ -2227,7 +2223,7 @@ xfs_ifree_cluster(
 		 * to mark all the active inodes on the buffer stale.
 		 */
 		bp = xfs_trans_get_buf(tp, mp->m_ddev_targp, blkno,
-					mp->m_bsize * blks_per_cluster,
+					mp->m_bsize * mp->m_blocks_per_cluster,
 					XBF_UNMAPPED);
 
 		if (!bp)
@@ -2274,7 +2270,7 @@ xfs_ifree_cluster(
 		 * transaction stale above, which means there is no point in
 		 * even trying to lock them.
 		 */
-		for (i = 0; i < inodes_per_cluster; i++) {
+		for (i = 0; i < mp->m_inodes_per_cluster; i++) {
 retry:
 			rcu_read_lock();
 			ip = radix_tree_lookup(&pag->pag_ici_root,
diff --git a/fs/xfs/xfs_itable.c b/fs/xfs/xfs_itable.c
index 18d8d3b812a7..942e4aa5e729 100644
--- a/fs/xfs/xfs_itable.c
+++ b/fs/xfs/xfs_itable.c
@@ -167,20 +167,18 @@ xfs_bulkstat_ichunk_ra(
 {
 	xfs_agblock_t			agbno;
 	struct blk_plug			plug;
-	int				blks_per_cluster;
-	int				inodes_per_cluster;
 	int				i;	/* inode chunk index */
 
 	agbno = XFS_AGINO_TO_AGBNO(mp, irec->ir_startino);
-	blks_per_cluster = xfs_icluster_size_fsb(mp);
-	inodes_per_cluster = XFS_FSB_TO_INO(mp, blks_per_cluster);
 
 	blk_start_plug(&plug);
 	for (i = 0; i < XFS_INODES_PER_CHUNK;
-	     i += inodes_per_cluster, agbno += blks_per_cluster) {
-		if (xfs_inobt_maskn(i, inodes_per_cluster) & ~irec->ir_free) {
-			xfs_btree_reada_bufs(mp, agno, agbno, blks_per_cluster,
-					     &xfs_inode_buf_ops);
+	     i += mp->m_inodes_per_cluster, agbno += mp->m_blocks_per_cluster) {
+		if (xfs_inobt_maskn(i, mp->m_inodes_per_cluster) &
+		    ~irec->ir_free) {
+			xfs_btree_reada_bufs(mp, agno, agbno,
+					mp->m_blocks_per_cluster,
+					&xfs_inode_buf_ops);
 		}
 	}
 	blk_finish_plug(&plug);
diff --git a/fs/xfs/xfs_log_recover.c b/fs/xfs/xfs_log_recover.c
index 1fc9e9042e0e..9fe88d125f0a 100644
--- a/fs/xfs/xfs_log_recover.c
+++ b/fs/xfs/xfs_log_recover.c
@@ -3850,7 +3850,6 @@ xlog_recover_do_icreate_pass2(
 	unsigned int		count;
 	unsigned int		isize;
 	xfs_agblock_t		length;
-	int			blks_per_cluster;
 	int			bb_per_cluster;
 	int			cancel_count;
 	int			nbufs;
@@ -3918,14 +3917,13 @@ xlog_recover_do_icreate_pass2(
 	 * buffers for cancellation so we don't overwrite anything written after
 	 * a cancellation.
 	 */
-	blks_per_cluster = xfs_icluster_size_fsb(mp);
-	bb_per_cluster = XFS_FSB_TO_BB(mp, blks_per_cluster);
-	nbufs = length / blks_per_cluster;
+	bb_per_cluster = XFS_FSB_TO_BB(mp, mp->m_blocks_per_cluster);
+	nbufs = length / mp->m_blocks_per_cluster;
 	for (i = 0, cancel_count = 0; i < nbufs; i++) {
 		xfs_daddr_t	daddr;
 
 		daddr = XFS_AGB_TO_DADDR(mp, agno,
-					 agbno + i * blks_per_cluster);
+					 agbno + i * mp->m_blocks_per_cluster);
 		if (xlog_check_buffer_cancelled(log, daddr, bb_per_cluster, 0))
 			cancel_count++;
 	}
diff --git a/fs/xfs/xfs_mount.c b/fs/xfs/xfs_mount.c
index 02d15098dbee..56d374675fd5 100644
--- a/fs/xfs/xfs_mount.c
+++ b/fs/xfs/xfs_mount.c
@@ -798,6 +798,8 @@ xfs_mountfs(
 		if (mp->m_sb.sb_inoalignmt >= XFS_B_TO_FSBT(mp, new_size))
 			mp->m_inode_cluster_size = new_size;
 	}
+	mp->m_blocks_per_cluster = xfs_icluster_size_fsb(mp);
+	mp->m_inodes_per_cluster = XFS_FSB_TO_INO(mp, mp->m_blocks_per_cluster);
 
 	/*
 	 * If enabled, sparse inode chunk alignment is expected to match the
diff --git a/fs/xfs/xfs_mount.h b/fs/xfs/xfs_mount.h
index 7964513c3128..58a037bfac22 100644
--- a/fs/xfs/xfs_mount.h
+++ b/fs/xfs/xfs_mount.h
@@ -101,6 +101,8 @@ typedef struct xfs_mount {
 	uint8_t			m_agno_log;	/* log #ag's */
 	uint8_t			m_agino_log;	/* #bits for agino in inum */
 	uint			m_inode_cluster_size;/* min inode buf size */
+	unsigned int		m_inodes_per_cluster;
+	unsigned int		m_blocks_per_cluster;
 	uint			m_blockmask;	/* sb_blocksize-1 */
 	uint			m_blockwsize;	/* sb_blocksize in words */
 	uint			m_blockwmask;	/* blockwsize-1 */

^ permalink raw reply related	[flat|nested] 7+ messages in thread

* [PATCH 4/4] xfs: precalculate cluster alignment in inodes and blocks
  2018-11-28 23:26 [PATCH 0/4] xfs-5.0: cleanups Darrick J. Wong
                   ` (2 preceding siblings ...)
  2018-11-28 23:26 ` [PATCH 3/4] xfs: precalculate inodes and blocks per inode cluster Darrick J. Wong
@ 2018-11-28 23:26 ` Darrick J. Wong
  3 siblings, 0 replies; 7+ messages in thread
From: Darrick J. Wong @ 2018-11-28 23:26 UTC (permalink / raw)
  To: darrick.wong; +Cc: linux-xfs, Brian Foster

From: Darrick J. Wong <darrick.wong@oracle.com>

Store the inode cluster alignment information in units of inodes and
blocks in the mount data so that we don't have to keep recalculating
them.

Signed-off-by: Darrick J. Wong <darrick.wong@oracle.com>
Reviewed-by: Brian Foster <bfoster@redhat.com>
---
 fs/xfs/libxfs/xfs_ialloc.c |    8 ++++----
 fs/xfs/libxfs/xfs_types.c  |    5 ++---
 fs/xfs/scrub/ialloc.c      |    2 +-
 fs/xfs/xfs_mount.c         |    2 ++
 fs/xfs/xfs_mount.h         |    2 ++
 5 files changed, 11 insertions(+), 8 deletions(-)


diff --git a/fs/xfs/libxfs/xfs_ialloc.c b/fs/xfs/libxfs/xfs_ialloc.c
index c7b2579a8e73..d32152fc8a6c 100644
--- a/fs/xfs/libxfs/xfs_ialloc.c
+++ b/fs/xfs/libxfs/xfs_ialloc.c
@@ -690,7 +690,7 @@ xfs_ialloc_ag_alloc(
 		 * but not to use them in the actual exact allocation.
 		 */
 		args.alignment = 1;
-		args.minalignslop = xfs_ialloc_cluster_alignment(args.mp) - 1;
+		args.minalignslop = args.mp->m_cluster_align - 1;
 
 		/* Allow space for the inode btree to split. */
 		args.minleft = args.mp->m_in_maxlevels - 1;
@@ -725,7 +725,7 @@ xfs_ialloc_ag_alloc(
 			args.alignment = args.mp->m_dalign;
 			isaligned = 1;
 		} else
-			args.alignment = xfs_ialloc_cluster_alignment(args.mp);
+			args.alignment = args.mp->m_cluster_align;
 		/*
 		 * Need to figure out where to allocate the inode blocks.
 		 * Ideally they should be spaced out through the a.g.
@@ -754,7 +754,7 @@ xfs_ialloc_ag_alloc(
 		args.type = XFS_ALLOCTYPE_NEAR_BNO;
 		args.agbno = be32_to_cpu(agi->agi_root);
 		args.fsbno = XFS_AGB_TO_FSB(args.mp, agno, args.agbno);
-		args.alignment = xfs_ialloc_cluster_alignment(args.mp);
+		args.alignment = args.mp->m_cluster_align;
 		if ((error = xfs_alloc_vextent(&args)))
 			return error;
 	}
@@ -1017,7 +1017,7 @@ xfs_ialloc_ag_select(
 		 */
 		ineed = mp->m_ialloc_min_blks;
 		if (flags && ineed > 1)
-			ineed += xfs_ialloc_cluster_alignment(mp);
+			ineed += mp->m_cluster_align;
 		longest = pag->pagf_longest;
 		if (!longest)
 			longest = pag->pagf_flcount > 0;
diff --git a/fs/xfs/libxfs/xfs_types.c b/fs/xfs/libxfs/xfs_types.c
index 895c232d63b7..3306fc42cfad 100644
--- a/fs/xfs/libxfs/xfs_types.c
+++ b/fs/xfs/libxfs/xfs_types.c
@@ -87,15 +87,14 @@ xfs_agino_range(
 	 * Calculate the first inode, which will be in the first
 	 * cluster-aligned block after the AGFL.
 	 */
-	bno = round_up(XFS_AGFL_BLOCK(mp) + 1,
-			xfs_ialloc_cluster_alignment(mp));
+	bno = round_up(XFS_AGFL_BLOCK(mp) + 1, mp->m_cluster_align);
 	*first = XFS_AGB_TO_AGINO(mp, bno);
 
 	/*
 	 * Calculate the last inode, which will be at the end of the
 	 * last (aligned) cluster that can be allocated in the AG.
 	 */
-	bno = round_down(eoag, xfs_ialloc_cluster_alignment(mp));
+	bno = round_down(eoag, mp->m_cluster_align);
 	*last = XFS_AGB_TO_AGINO(mp, bno) - 1;
 }
 
diff --git a/fs/xfs/scrub/ialloc.c b/fs/xfs/scrub/ialloc.c
index 596a02b8efdc..9b5287a0e8ba 100644
--- a/fs/xfs/scrub/ialloc.c
+++ b/fs/xfs/scrub/ialloc.c
@@ -300,7 +300,7 @@ xchk_iallocbt_rec(
 
 	/* Make sure this record is aligned to cluster and inoalignmnt size. */
 	agbno = XFS_AGINO_TO_AGBNO(mp, irec.ir_startino);
-	if ((agbno & (xfs_ialloc_cluster_alignment(mp) - 1)) ||
+	if ((agbno & (mp->m_cluster_align - 1)) ||
 	    (agbno & (mp->m_blocks_per_cluster - 1)))
 		xchk_btree_set_corrupt(bs->sc, bs->cur, 0);
 
diff --git a/fs/xfs/xfs_mount.c b/fs/xfs/xfs_mount.c
index 56d374675fd5..b4d8c318be3c 100644
--- a/fs/xfs/xfs_mount.c
+++ b/fs/xfs/xfs_mount.c
@@ -800,6 +800,8 @@ xfs_mountfs(
 	}
 	mp->m_blocks_per_cluster = xfs_icluster_size_fsb(mp);
 	mp->m_inodes_per_cluster = XFS_FSB_TO_INO(mp, mp->m_blocks_per_cluster);
+	mp->m_cluster_align = xfs_ialloc_cluster_alignment(mp);
+	mp->m_cluster_align_inodes = XFS_FSB_TO_INO(mp, mp->m_cluster_align);
 
 	/*
 	 * If enabled, sparse inode chunk alignment is expected to match the
diff --git a/fs/xfs/xfs_mount.h b/fs/xfs/xfs_mount.h
index 58a037bfac22..0ad025e7f3cf 100644
--- a/fs/xfs/xfs_mount.h
+++ b/fs/xfs/xfs_mount.h
@@ -103,6 +103,8 @@ typedef struct xfs_mount {
 	uint			m_inode_cluster_size;/* min inode buf size */
 	unsigned int		m_inodes_per_cluster;
 	unsigned int		m_blocks_per_cluster;
+	unsigned int		m_cluster_align;
+	unsigned int		m_cluster_align_inodes;
 	uint			m_blockmask;	/* sb_blocksize-1 */
 	uint			m_blockwsize;	/* sb_blocksize in words */
 	uint			m_blockwmask;	/* blockwsize-1 */

^ permalink raw reply related	[flat|nested] 7+ messages in thread

* Re: [PATCH 1/4] xfs: remove xfs_rmap_ag_owner and friends
  2018-11-28 23:26 ` [PATCH 1/4] xfs: remove xfs_rmap_ag_owner and friends Darrick J. Wong
@ 2018-11-29 15:00   ` Brian Foster
  0 siblings, 0 replies; 7+ messages in thread
From: Brian Foster @ 2018-11-29 15:00 UTC (permalink / raw)
  To: Darrick J. Wong; +Cc: linux-xfs

On Wed, Nov 28, 2018 at 03:26:18PM -0800, Darrick J. Wong wrote:
> From: Darrick J. Wong <darrick.wong@oracle.com>
> 
> Owner information for static fs metadata can be defined readonly at
> build time because it never changes across filesystems.  This enables us
> to reduce stack usage (particularly in scrub) because we can use the
> statically defined oinfo structures.
> 
> Signed-off-by: Darrick J. Wong <darrick.wong@oracle.com>
> ---

Looks fine to me:

Reviewed-by: Brian Foster <bfoster@redhat.com>

>  fs/xfs/libxfs/xfs_ag.c             |    9 ++++-----
>  fs/xfs/libxfs/xfs_alloc.c          |    9 ++++-----
>  fs/xfs/libxfs/xfs_bmap.c           |    4 ++--
>  fs/xfs/libxfs/xfs_ialloc.c         |    8 +++-----
>  fs/xfs/libxfs/xfs_ialloc_btree.c   |    7 ++-----
>  fs/xfs/libxfs/xfs_refcount_btree.c |    6 ++----
>  fs/xfs/libxfs/xfs_rmap.c           |   28 ++++++++++++++++++++++++++++
>  fs/xfs/libxfs/xfs_rmap.h           |   34 ++++++++++------------------------
>  fs/xfs/scrub/agheader.c            |   25 +++++++------------------
>  fs/xfs/scrub/agheader_repair.c     |    5 ++---
>  fs/xfs/scrub/alloc.c               |    4 +---
>  fs/xfs/scrub/ialloc.c              |   28 +++++++++-------------------
>  fs/xfs/scrub/inode.c               |    4 +---
>  fs/xfs/scrub/refcount.c            |   15 +++++----------
>  fs/xfs/scrub/repair.c              |    4 +---
>  fs/xfs/scrub/rmap.c                |    5 +----
>  fs/xfs/xfs_extfree_item.c          |    5 ++---
>  17 files changed, 84 insertions(+), 116 deletions(-)
> 
> 
> diff --git a/fs/xfs/libxfs/xfs_ag.c b/fs/xfs/libxfs/xfs_ag.c
> index 9345802c99f7..999ad8d00d43 100644
> --- a/fs/xfs/libxfs/xfs_ag.c
> +++ b/fs/xfs/libxfs/xfs_ag.c
> @@ -414,7 +414,6 @@ xfs_ag_extend_space(
>  	struct aghdr_init_data	*id,
>  	xfs_extlen_t		len)
>  {
> -	struct xfs_owner_info	oinfo;
>  	struct xfs_buf		*bp;
>  	struct xfs_agi		*agi;
>  	struct xfs_agf		*agf;
> @@ -448,17 +447,17 @@ xfs_ag_extend_space(
>  	/*
>  	 * Free the new space.
>  	 *
> -	 * XFS_RMAP_OWN_NULL is used here to tell the rmap btree that
> +	 * XFS_RMAP_OINFO_SKIP_UPDATE is used here to tell the rmap btree that
>  	 * this doesn't actually exist in the rmap btree.
>  	 */
> -	xfs_rmap_ag_owner(&oinfo, XFS_RMAP_OWN_NULL);
>  	error = xfs_rmap_free(tp, bp, id->agno,
>  				be32_to_cpu(agf->agf_length) - len,
> -				len, &oinfo);
> +				len, &XFS_RMAP_OINFO_SKIP_UPDATE);
>  	if (error)
>  		return error;
>  
>  	return  xfs_free_extent(tp, XFS_AGB_TO_FSB(mp, id->agno,
>  					be32_to_cpu(agf->agf_length) - len),
> -				len, &oinfo, XFS_AG_RESV_NONE);
> +				len, &XFS_RMAP_OINFO_SKIP_UPDATE,
> +				XFS_AG_RESV_NONE);
>  }
> diff --git a/fs/xfs/libxfs/xfs_alloc.c b/fs/xfs/libxfs/xfs_alloc.c
> index ef039777f314..2b900eb2aec2 100644
> --- a/fs/xfs/libxfs/xfs_alloc.c
> +++ b/fs/xfs/libxfs/xfs_alloc.c
> @@ -1594,7 +1594,6 @@ xfs_alloc_ag_vextent_small(
>  	xfs_extlen_t	*flenp,	/* result length */
>  	int		*stat)	/* status: 0-freelist, 1-normal/none */
>  {
> -	struct xfs_owner_info	oinfo;
>  	int		error;
>  	xfs_agblock_t	fbno;
>  	xfs_extlen_t	flen;
> @@ -1648,9 +1647,8 @@ xfs_alloc_ag_vextent_small(
>  			 * doesn't live in the free space, we need to clear
>  			 * out the OWN_AG rmap.
>  			 */
> -			xfs_rmap_ag_owner(&oinfo, XFS_RMAP_OWN_AG);
>  			error = xfs_rmap_free(args->tp, args->agbp, args->agno,
> -					fbno, 1, &oinfo);
> +					fbno, 1, &XFS_RMAP_OINFO_AG);
>  			if (error)
>  				goto error0;
>  
> @@ -2314,10 +2312,11 @@ xfs_alloc_fix_freelist(
>  	 * repair/rmap.c in xfsprogs for details.
>  	 */
>  	memset(&targs, 0, sizeof(targs));
> +	/* struct copy below */
>  	if (flags & XFS_ALLOC_FLAG_NORMAP)
> -		xfs_rmap_skip_owner_update(&targs.oinfo);
> +		targs.oinfo = XFS_RMAP_OINFO_SKIP_UPDATE;
>  	else
> -		xfs_rmap_ag_owner(&targs.oinfo, XFS_RMAP_OWN_AG);
> +		targs.oinfo = XFS_RMAP_OINFO_AG;
>  	while (!(flags & XFS_ALLOC_FLAG_NOSHRINK) && pag->pagf_flcount > need) {
>  		error = xfs_alloc_get_freelist(tp, agbp, &bno, 0);
>  		if (error)
> diff --git a/fs/xfs/libxfs/xfs_bmap.c b/fs/xfs/libxfs/xfs_bmap.c
> index d5672ab58b1f..332eefa2700b 100644
> --- a/fs/xfs/libxfs/xfs_bmap.c
> +++ b/fs/xfs/libxfs/xfs_bmap.c
> @@ -564,7 +564,7 @@ __xfs_bmap_add_free(
>  	if (oinfo)
>  		new->xefi_oinfo = *oinfo;
>  	else
> -		xfs_rmap_skip_owner_update(&new->xefi_oinfo);
> +		new->xefi_oinfo = XFS_RMAP_OINFO_SKIP_UPDATE;
>  	new->xefi_skip_discard = skip_discard;
>  	trace_xfs_bmap_free_defer(tp->t_mountp,
>  			XFS_FSB_TO_AGNO(tp->t_mountp, bno), 0,
> @@ -3453,7 +3453,7 @@ xfs_bmap_btalloc(
>  	args.tp = ap->tp;
>  	args.mp = mp;
>  	args.fsbno = ap->blkno;
> -	xfs_rmap_skip_owner_update(&args.oinfo);
> +	args.oinfo = XFS_RMAP_OINFO_SKIP_UPDATE;
>  
>  	/* Trim the allocation back to the maximum an AG can fit. */
>  	args.maxlen = min(ap->length, mp->m_ag_max_usable);
> diff --git a/fs/xfs/libxfs/xfs_ialloc.c b/fs/xfs/libxfs/xfs_ialloc.c
> index a8f6db735d5d..fcf0d17405d8 100644
> --- a/fs/xfs/libxfs/xfs_ialloc.c
> +++ b/fs/xfs/libxfs/xfs_ialloc.c
> @@ -641,7 +641,7 @@ xfs_ialloc_ag_alloc(
>  	args.tp = tp;
>  	args.mp = tp->t_mountp;
>  	args.fsbno = NULLFSBLOCK;
> -	xfs_rmap_ag_owner(&args.oinfo, XFS_RMAP_OWN_INODES);
> +	args.oinfo = XFS_RMAP_OINFO_INODES;
>  
>  #ifdef DEBUG
>  	/* randomly do sparse inode allocations */
> @@ -1849,14 +1849,12 @@ xfs_difree_inode_chunk(
>  	int				nextbit;
>  	xfs_agblock_t			agbno;
>  	int				contigblk;
> -	struct xfs_owner_info		oinfo;
>  	DECLARE_BITMAP(holemask, XFS_INOBT_HOLEMASK_BITS);
> -	xfs_rmap_ag_owner(&oinfo, XFS_RMAP_OWN_INODES);
>  
>  	if (!xfs_inobt_issparse(rec->ir_holemask)) {
>  		/* not sparse, calculate extent info directly */
>  		xfs_bmap_add_free(tp, XFS_AGB_TO_FSB(mp, agno, sagbno),
> -				  mp->m_ialloc_blks, &oinfo);
> +				  mp->m_ialloc_blks, &XFS_RMAP_OINFO_INODES);
>  		return;
>  	}
>  
> @@ -1900,7 +1898,7 @@ xfs_difree_inode_chunk(
>  		ASSERT(agbno % mp->m_sb.sb_spino_align == 0);
>  		ASSERT(contigblk % mp->m_sb.sb_spino_align == 0);
>  		xfs_bmap_add_free(tp, XFS_AGB_TO_FSB(mp, agno, agbno),
> -				  contigblk, &oinfo);
> +				  contigblk, &XFS_RMAP_OINFO_INODES);
>  
>  		/* reset range to current bit and carry on... */
>  		startidx = endidx = nextbit;
> diff --git a/fs/xfs/libxfs/xfs_ialloc_btree.c b/fs/xfs/libxfs/xfs_ialloc_btree.c
> index 7fbf8af0b159..9b25e7a0df47 100644
> --- a/fs/xfs/libxfs/xfs_ialloc_btree.c
> +++ b/fs/xfs/libxfs/xfs_ialloc_btree.c
> @@ -84,7 +84,7 @@ __xfs_inobt_alloc_block(
>  	memset(&args, 0, sizeof(args));
>  	args.tp = cur->bc_tp;
>  	args.mp = cur->bc_mp;
> -	xfs_rmap_ag_owner(&args.oinfo, XFS_RMAP_OWN_INOBT);
> +	args.oinfo = XFS_RMAP_OINFO_INOBT;
>  	args.fsbno = XFS_AGB_TO_FSB(args.mp, cur->bc_private.a.agno, sbno);
>  	args.minlen = 1;
>  	args.maxlen = 1;
> @@ -136,12 +136,9 @@ __xfs_inobt_free_block(
>  	struct xfs_buf		*bp,
>  	enum xfs_ag_resv_type	resv)
>  {
> -	struct xfs_owner_info	oinfo;
> -
> -	xfs_rmap_ag_owner(&oinfo, XFS_RMAP_OWN_INOBT);
>  	return xfs_free_extent(cur->bc_tp,
>  			XFS_DADDR_TO_FSB(cur->bc_mp, XFS_BUF_ADDR(bp)), 1,
> -			&oinfo, resv);
> +			&XFS_RMAP_OINFO_INOBT, resv);
>  }
>  
>  STATIC int
> diff --git a/fs/xfs/libxfs/xfs_refcount_btree.c b/fs/xfs/libxfs/xfs_refcount_btree.c
> index 1aaa01c97517..d9eab657b63e 100644
> --- a/fs/xfs/libxfs/xfs_refcount_btree.c
> +++ b/fs/xfs/libxfs/xfs_refcount_btree.c
> @@ -70,7 +70,7 @@ xfs_refcountbt_alloc_block(
>  	args.type = XFS_ALLOCTYPE_NEAR_BNO;
>  	args.fsbno = XFS_AGB_TO_FSB(cur->bc_mp, cur->bc_private.a.agno,
>  			xfs_refc_block(args.mp));
> -	xfs_rmap_ag_owner(&args.oinfo, XFS_RMAP_OWN_REFC);
> +	args.oinfo = XFS_RMAP_OINFO_REFC;
>  	args.minlen = args.maxlen = args.prod = 1;
>  	args.resv = XFS_AG_RESV_METADATA;
>  
> @@ -106,15 +106,13 @@ xfs_refcountbt_free_block(
>  	struct xfs_buf		*agbp = cur->bc_private.a.agbp;
>  	struct xfs_agf		*agf = XFS_BUF_TO_AGF(agbp);
>  	xfs_fsblock_t		fsbno = XFS_DADDR_TO_FSB(mp, XFS_BUF_ADDR(bp));
> -	struct xfs_owner_info	oinfo;
>  	int			error;
>  
>  	trace_xfs_refcountbt_free_block(cur->bc_mp, cur->bc_private.a.agno,
>  			XFS_FSB_TO_AGBNO(cur->bc_mp, fsbno), 1);
> -	xfs_rmap_ag_owner(&oinfo, XFS_RMAP_OWN_REFC);
>  	be32_add_cpu(&agf->agf_refcount_blocks, -1);
>  	xfs_alloc_log_agf(cur->bc_tp, agbp, XFS_AGF_REFCOUNT_BLOCKS);
> -	error = xfs_free_extent(cur->bc_tp, fsbno, 1, &oinfo,
> +	error = xfs_free_extent(cur->bc_tp, fsbno, 1, &XFS_RMAP_OINFO_REFC,
>  			XFS_AG_RESV_METADATA);
>  	if (error)
>  		return error;
> diff --git a/fs/xfs/libxfs/xfs_rmap.c b/fs/xfs/libxfs/xfs_rmap.c
> index e7d06295338d..8ed885507dd8 100644
> --- a/fs/xfs/libxfs/xfs_rmap.c
> +++ b/fs/xfs/libxfs/xfs_rmap.c
> @@ -2550,3 +2550,31 @@ xfs_rmap_has_other_keys(
>  	*has_rmap = rks.has_rmap;
>  	return error;
>  }
> +
> +const struct xfs_owner_info XFS_RMAP_OINFO_SKIP_UPDATE = {
> +	.oi_owner = XFS_RMAP_OWN_NULL,
> +};
> +const struct xfs_owner_info XFS_RMAP_OINFO_ANY_OWNER = {
> +	.oi_owner = XFS_RMAP_OWN_UNKNOWN,
> +};
> +const struct xfs_owner_info XFS_RMAP_OINFO_FS = {
> +	.oi_owner = XFS_RMAP_OWN_FS,
> +};
> +const struct xfs_owner_info XFS_RMAP_OINFO_LOG = {
> +	.oi_owner = XFS_RMAP_OWN_LOG,
> +};
> +const struct xfs_owner_info XFS_RMAP_OINFO_AG = {
> +	.oi_owner = XFS_RMAP_OWN_AG,
> +};
> +const struct xfs_owner_info XFS_RMAP_OINFO_INOBT = {
> +	.oi_owner = XFS_RMAP_OWN_INOBT,
> +};
> +const struct xfs_owner_info XFS_RMAP_OINFO_INODES = {
> +	.oi_owner = XFS_RMAP_OWN_INODES,
> +};
> +const struct xfs_owner_info XFS_RMAP_OINFO_REFC = {
> +	.oi_owner = XFS_RMAP_OWN_REFC,
> +};
> +const struct xfs_owner_info XFS_RMAP_OINFO_COW = {
> +	.oi_owner = XFS_RMAP_OWN_COW,
> +};
> diff --git a/fs/xfs/libxfs/xfs_rmap.h b/fs/xfs/libxfs/xfs_rmap.h
> index 6d32838aa184..e21ed0294e5c 100644
> --- a/fs/xfs/libxfs/xfs_rmap.h
> +++ b/fs/xfs/libxfs/xfs_rmap.h
> @@ -6,16 +6,6 @@
>  #ifndef __XFS_RMAP_H__
>  #define __XFS_RMAP_H__
>  
> -static inline void
> -xfs_rmap_ag_owner(
> -	struct xfs_owner_info	*oi,
> -	uint64_t		owner)
> -{
> -	oi->oi_owner = owner;
> -	oi->oi_offset = 0;
> -	oi->oi_flags = 0;
> -}
> -
>  static inline void
>  xfs_rmap_ino_bmbt_owner(
>  	struct xfs_owner_info	*oi,
> @@ -43,13 +33,6 @@ xfs_rmap_ino_owner(
>  		oi->oi_flags |= XFS_OWNER_INFO_ATTR_FORK;
>  }
>  
> -static inline void
> -xfs_rmap_skip_owner_update(
> -	struct xfs_owner_info	*oi)
> -{
> -	xfs_rmap_ag_owner(oi, XFS_RMAP_OWN_NULL);
> -}
> -
>  static inline bool
>  xfs_rmap_should_skip_owner_update(
>  	const struct xfs_owner_info	*oi)
> @@ -57,13 +40,6 @@ xfs_rmap_should_skip_owner_update(
>  	return oi->oi_owner == XFS_RMAP_OWN_NULL;
>  }
>  
> -static inline void
> -xfs_rmap_any_owner_update(
> -	struct xfs_owner_info	*oi)
> -{
> -	xfs_rmap_ag_owner(oi, XFS_RMAP_OWN_UNKNOWN);
> -}
> -
>  /* Reverse mapping functions. */
>  
>  struct xfs_buf;
> @@ -225,4 +201,14 @@ int xfs_rmap_has_other_keys(struct xfs_btree_cur *cur, xfs_agblock_t bno,
>  		bool *has_rmap);
>  int xfs_rmap_map_raw(struct xfs_btree_cur *cur, struct xfs_rmap_irec *rmap);
>  
> +extern const struct xfs_owner_info XFS_RMAP_OINFO_SKIP_UPDATE;
> +extern const struct xfs_owner_info XFS_RMAP_OINFO_ANY_OWNER;
> +extern const struct xfs_owner_info XFS_RMAP_OINFO_FS;
> +extern const struct xfs_owner_info XFS_RMAP_OINFO_LOG;
> +extern const struct xfs_owner_info XFS_RMAP_OINFO_AG;
> +extern const struct xfs_owner_info XFS_RMAP_OINFO_INOBT;
> +extern const struct xfs_owner_info XFS_RMAP_OINFO_INODES;
> +extern const struct xfs_owner_info XFS_RMAP_OINFO_REFC;
> +extern const struct xfs_owner_info XFS_RMAP_OINFO_COW;
> +
>  #endif	/* __XFS_RMAP_H__ */
> diff --git a/fs/xfs/scrub/agheader.c b/fs/xfs/scrub/agheader.c
> index 3068a9382feb..90955ab1e895 100644
> --- a/fs/xfs/scrub/agheader.c
> +++ b/fs/xfs/scrub/agheader.c
> @@ -32,7 +32,6 @@ xchk_superblock_xref(
>  	struct xfs_scrub	*sc,
>  	struct xfs_buf		*bp)
>  {
> -	struct xfs_owner_info	oinfo;
>  	struct xfs_mount	*mp = sc->mp;
>  	xfs_agnumber_t		agno = sc->sm->sm_agno;
>  	xfs_agblock_t		agbno;
> @@ -49,8 +48,7 @@ xchk_superblock_xref(
>  
>  	xchk_xref_is_used_space(sc, agbno, 1);
>  	xchk_xref_is_not_inode_chunk(sc, agbno, 1);
> -	xfs_rmap_ag_owner(&oinfo, XFS_RMAP_OWN_FS);
> -	xchk_xref_is_owned_by(sc, agbno, 1, &oinfo);
> +	xchk_xref_is_owned_by(sc, agbno, 1, &XFS_RMAP_OINFO_FS);
>  	xchk_xref_is_not_shared(sc, agbno, 1);
>  
>  	/* scrub teardown will take care of sc->sa for us */
> @@ -484,7 +482,6 @@ STATIC void
>  xchk_agf_xref(
>  	struct xfs_scrub	*sc)
>  {
> -	struct xfs_owner_info	oinfo;
>  	struct xfs_mount	*mp = sc->mp;
>  	xfs_agblock_t		agbno;
>  	int			error;
> @@ -502,8 +499,7 @@ xchk_agf_xref(
>  	xchk_agf_xref_freeblks(sc);
>  	xchk_agf_xref_cntbt(sc);
>  	xchk_xref_is_not_inode_chunk(sc, agbno, 1);
> -	xfs_rmap_ag_owner(&oinfo, XFS_RMAP_OWN_FS);
> -	xchk_xref_is_owned_by(sc, agbno, 1, &oinfo);
> +	xchk_xref_is_owned_by(sc, agbno, 1, &XFS_RMAP_OINFO_FS);
>  	xchk_agf_xref_btreeblks(sc);
>  	xchk_xref_is_not_shared(sc, agbno, 1);
>  	xchk_agf_xref_refcblks(sc);
> @@ -598,7 +594,6 @@ xchk_agf(
>  /* AGFL */
>  
>  struct xchk_agfl_info {
> -	struct xfs_owner_info	oinfo;
>  	unsigned int		sz_entries;
>  	unsigned int		nr_entries;
>  	xfs_agblock_t		*entries;
> @@ -609,15 +604,14 @@ struct xchk_agfl_info {
>  STATIC void
>  xchk_agfl_block_xref(
>  	struct xfs_scrub	*sc,
> -	xfs_agblock_t		agbno,
> -	struct xfs_owner_info	*oinfo)
> +	xfs_agblock_t		agbno)
>  {
>  	if (sc->sm->sm_flags & XFS_SCRUB_OFLAG_CORRUPT)
>  		return;
>  
>  	xchk_xref_is_used_space(sc, agbno, 1);
>  	xchk_xref_is_not_inode_chunk(sc, agbno, 1);
> -	xchk_xref_is_owned_by(sc, agbno, 1, oinfo);
> +	xchk_xref_is_owned_by(sc, agbno, 1, &XFS_RMAP_OINFO_AG);
>  	xchk_xref_is_not_shared(sc, agbno, 1);
>  }
>  
> @@ -638,7 +632,7 @@ xchk_agfl_block(
>  	else
>  		xchk_block_set_corrupt(sc, sc->sa.agfl_bp);
>  
> -	xchk_agfl_block_xref(sc, agbno, priv);
> +	xchk_agfl_block_xref(sc, agbno);
>  
>  	if (sc->sm->sm_flags & XFS_SCRUB_OFLAG_CORRUPT)
>  		return XFS_BTREE_QUERY_RANGE_ABORT;
> @@ -662,7 +656,6 @@ STATIC void
>  xchk_agfl_xref(
>  	struct xfs_scrub	*sc)
>  {
> -	struct xfs_owner_info	oinfo;
>  	struct xfs_mount	*mp = sc->mp;
>  	xfs_agblock_t		agbno;
>  	int			error;
> @@ -678,8 +671,7 @@ xchk_agfl_xref(
>  
>  	xchk_xref_is_used_space(sc, agbno, 1);
>  	xchk_xref_is_not_inode_chunk(sc, agbno, 1);
> -	xfs_rmap_ag_owner(&oinfo, XFS_RMAP_OWN_FS);
> -	xchk_xref_is_owned_by(sc, agbno, 1, &oinfo);
> +	xchk_xref_is_owned_by(sc, agbno, 1, &XFS_RMAP_OINFO_FS);
>  	xchk_xref_is_not_shared(sc, agbno, 1);
>  
>  	/*
> @@ -732,7 +724,6 @@ xchk_agfl(
>  	}
>  
>  	/* Check the blocks in the AGFL. */
> -	xfs_rmap_ag_owner(&sai.oinfo, XFS_RMAP_OWN_AG);
>  	error = xfs_agfl_walk(sc->mp, XFS_BUF_TO_AGF(sc->sa.agf_bp),
>  			sc->sa.agfl_bp, xchk_agfl_block, &sai);
>  	if (error == XFS_BTREE_QUERY_RANGE_ABORT) {
> @@ -791,7 +782,6 @@ STATIC void
>  xchk_agi_xref(
>  	struct xfs_scrub	*sc)
>  {
> -	struct xfs_owner_info	oinfo;
>  	struct xfs_mount	*mp = sc->mp;
>  	xfs_agblock_t		agbno;
>  	int			error;
> @@ -808,8 +798,7 @@ xchk_agi_xref(
>  	xchk_xref_is_used_space(sc, agbno, 1);
>  	xchk_xref_is_not_inode_chunk(sc, agbno, 1);
>  	xchk_agi_xref_icounts(sc);
> -	xfs_rmap_ag_owner(&oinfo, XFS_RMAP_OWN_FS);
> -	xchk_xref_is_owned_by(sc, agbno, 1, &oinfo);
> +	xchk_xref_is_owned_by(sc, agbno, 1, &XFS_RMAP_OINFO_FS);
>  	xchk_xref_is_not_shared(sc, agbno, 1);
>  
>  	/* scrub teardown will take care of sc->sa for us */
> diff --git a/fs/xfs/scrub/agheader_repair.c b/fs/xfs/scrub/agheader_repair.c
> index f7568a4b5fe5..03d1e15cceba 100644
> --- a/fs/xfs/scrub/agheader_repair.c
> +++ b/fs/xfs/scrub/agheader_repair.c
> @@ -646,7 +646,6 @@ int
>  xrep_agfl(
>  	struct xfs_scrub	*sc)
>  {
> -	struct xfs_owner_info	oinfo;
>  	struct xfs_bitmap	agfl_extents;
>  	struct xfs_mount	*mp = sc->mp;
>  	struct xfs_buf		*agf_bp;
> @@ -708,8 +707,8 @@ xrep_agfl(
>  		goto err;
>  
>  	/* Dump any AGFL overflow. */
> -	xfs_rmap_ag_owner(&oinfo, XFS_RMAP_OWN_AG);
> -	return xrep_reap_extents(sc, &agfl_extents, &oinfo, XFS_AG_RESV_AGFL);
> +	return xrep_reap_extents(sc, &agfl_extents, &XFS_RMAP_OINFO_AG,
> +			XFS_AG_RESV_AGFL);
>  err:
>  	xfs_bitmap_destroy(&agfl_extents);
>  	return error;
> diff --git a/fs/xfs/scrub/alloc.c b/fs/xfs/scrub/alloc.c
> index 376bcb585ae6..44883e9112ad 100644
> --- a/fs/xfs/scrub/alloc.c
> +++ b/fs/xfs/scrub/alloc.c
> @@ -125,12 +125,10 @@ xchk_allocbt(
>  	struct xfs_scrub	*sc,
>  	xfs_btnum_t		which)
>  {
> -	struct xfs_owner_info	oinfo;
>  	struct xfs_btree_cur	*cur;
>  
> -	xfs_rmap_ag_owner(&oinfo, XFS_RMAP_OWN_AG);
>  	cur = which == XFS_BTNUM_BNO ? sc->sa.bno_cur : sc->sa.cnt_cur;
> -	return xchk_btree(sc, cur, xchk_allocbt_rec, &oinfo, NULL);
> +	return xchk_btree(sc, cur, xchk_allocbt_rec, &XFS_RMAP_OINFO_AG, NULL);
>  }
>  
>  int
> diff --git a/fs/xfs/scrub/ialloc.c b/fs/xfs/scrub/ialloc.c
> index 224dba937492..72f45b298fa5 100644
> --- a/fs/xfs/scrub/ialloc.c
> +++ b/fs/xfs/scrub/ialloc.c
> @@ -82,15 +82,12 @@ xchk_iallocbt_chunk_xref(
>  	xfs_agblock_t			agbno,
>  	xfs_extlen_t			len)
>  {
> -	struct xfs_owner_info		oinfo;
> -
>  	if (sc->sm->sm_flags & XFS_SCRUB_OFLAG_CORRUPT)
>  		return;
>  
>  	xchk_xref_is_used_space(sc, agbno, len);
>  	xchk_iallocbt_chunk_xref_other(sc, irec, agino);
> -	xfs_rmap_ag_owner(&oinfo, XFS_RMAP_OWN_INODES);
> -	xchk_xref_is_owned_by(sc, agbno, len, &oinfo);
> +	xchk_xref_is_owned_by(sc, agbno, len, &XFS_RMAP_OINFO_INODES);
>  	xchk_xref_is_not_shared(sc, agbno, len);
>  }
>  
> @@ -186,7 +183,6 @@ xchk_iallocbt_check_freemask(
>  	struct xchk_btree		*bs,
>  	struct xfs_inobt_rec_incore	*irec)
>  {
> -	struct xfs_owner_info		oinfo;
>  	struct xfs_imap			imap;
>  	struct xfs_mount		*mp = bs->cur->bc_mp;
>  	struct xfs_dinode		*dip;
> @@ -205,7 +201,6 @@ xchk_iallocbt_check_freemask(
>  	/* Make sure the freemask matches the inode records. */
>  	blks_per_cluster = xfs_icluster_size_fsb(mp);
>  	nr_inodes = XFS_OFFBNO_TO_AGINO(mp, blks_per_cluster, 0);
> -	xfs_rmap_ag_owner(&oinfo, XFS_RMAP_OWN_INODES);
>  
>  	for (agino = irec->ir_startino;
>  	     agino < irec->ir_startino + XFS_INODES_PER_CHUNK;
> @@ -230,12 +225,13 @@ xchk_iallocbt_check_freemask(
>  		/* If any part of this is a hole, skip it. */
>  		if (ir_holemask) {
>  			xchk_xref_is_not_owned_by(bs->sc, agbno,
> -					blks_per_cluster, &oinfo);
> +					blks_per_cluster,
> +					&XFS_RMAP_OINFO_INODES);
>  			continue;
>  		}
>  
>  		xchk_xref_is_owned_by(bs->sc, agbno, blks_per_cluster,
> -				&oinfo);
> +				&XFS_RMAP_OINFO_INODES);
>  
>  		/* Grab the inode cluster buffer. */
>  		imap.im_blkno = XFS_AGB_TO_DADDR(mp, bs->cur->bc_private.a.agno,
> @@ -366,7 +362,6 @@ xchk_iallocbt_xref_rmap_btreeblks(
>  	struct xfs_scrub	*sc,
>  	int			which)
>  {
> -	struct xfs_owner_info	oinfo;
>  	xfs_filblks_t		blocks;
>  	xfs_extlen_t		inobt_blocks = 0;
>  	xfs_extlen_t		finobt_blocks = 0;
> @@ -388,9 +383,8 @@ xchk_iallocbt_xref_rmap_btreeblks(
>  			return;
>  	}
>  
> -	xfs_rmap_ag_owner(&oinfo, XFS_RMAP_OWN_INOBT);
> -	error = xchk_count_rmap_ownedby_ag(sc, sc->sa.rmap_cur, &oinfo,
> -			&blocks);
> +	error = xchk_count_rmap_ownedby_ag(sc, sc->sa.rmap_cur,
> +			&XFS_RMAP_OINFO_INOBT, &blocks);
>  	if (!xchk_should_check_xref(sc, &error, &sc->sa.rmap_cur))
>  		return;
>  	if (blocks != inobt_blocks + finobt_blocks)
> @@ -407,7 +401,6 @@ xchk_iallocbt_xref_rmap_inodes(
>  	int			which,
>  	xfs_filblks_t		inode_blocks)
>  {
> -	struct xfs_owner_info	oinfo;
>  	xfs_filblks_t		blocks;
>  	int			error;
>  
> @@ -415,9 +408,8 @@ xchk_iallocbt_xref_rmap_inodes(
>  		return;
>  
>  	/* Check that we saw as many inode blocks as the rmap knows about. */
> -	xfs_rmap_ag_owner(&oinfo, XFS_RMAP_OWN_INODES);
> -	error = xchk_count_rmap_ownedby_ag(sc, sc->sa.rmap_cur, &oinfo,
> -			&blocks);
> +	error = xchk_count_rmap_ownedby_ag(sc, sc->sa.rmap_cur,
> +			&XFS_RMAP_OINFO_INODES, &blocks);
>  	if (!xchk_should_check_xref(sc, &error, &sc->sa.rmap_cur))
>  		return;
>  	if (blocks != inode_blocks)
> @@ -431,13 +423,11 @@ xchk_iallocbt(
>  	xfs_btnum_t		which)
>  {
>  	struct xfs_btree_cur	*cur;
> -	struct xfs_owner_info	oinfo;
>  	xfs_filblks_t		inode_blocks = 0;
>  	int			error;
>  
> -	xfs_rmap_ag_owner(&oinfo, XFS_RMAP_OWN_INOBT);
>  	cur = which == XFS_BTNUM_INO ? sc->sa.ino_cur : sc->sa.fino_cur;
> -	error = xchk_btree(sc, cur, xchk_iallocbt_rec, &oinfo,
> +	error = xchk_btree(sc, cur, xchk_iallocbt_rec, &XFS_RMAP_OINFO_INOBT,
>  			&inode_blocks);
>  	if (error)
>  		return error;
> diff --git a/fs/xfs/scrub/inode.c b/fs/xfs/scrub/inode.c
> index e386c9b0b4ab..e213efc194a1 100644
> --- a/fs/xfs/scrub/inode.c
> +++ b/fs/xfs/scrub/inode.c
> @@ -509,7 +509,6 @@ xchk_inode_xref(
>  	xfs_ino_t		ino,
>  	struct xfs_dinode	*dip)
>  {
> -	struct xfs_owner_info	oinfo;
>  	xfs_agnumber_t		agno;
>  	xfs_agblock_t		agbno;
>  	int			error;
> @@ -526,8 +525,7 @@ xchk_inode_xref(
>  
>  	xchk_xref_is_used_space(sc, agbno, 1);
>  	xchk_inode_xref_finobt(sc, ino);
> -	xfs_rmap_ag_owner(&oinfo, XFS_RMAP_OWN_INODES);
> -	xchk_xref_is_owned_by(sc, agbno, 1, &oinfo);
> +	xchk_xref_is_owned_by(sc, agbno, 1, &XFS_RMAP_OINFO_INODES);
>  	xchk_xref_is_not_shared(sc, agbno, 1);
>  	xchk_inode_xref_bmap(sc, dip);
>  
> diff --git a/fs/xfs/scrub/refcount.c b/fs/xfs/scrub/refcount.c
> index b7ade620acee..708b4158eb90 100644
> --- a/fs/xfs/scrub/refcount.c
> +++ b/fs/xfs/scrub/refcount.c
> @@ -385,7 +385,6 @@ xchk_refcount_xref_rmap(
>  	struct xfs_scrub	*sc,
>  	xfs_filblks_t		cow_blocks)
>  {
> -	struct xfs_owner_info	oinfo;
>  	xfs_extlen_t		refcbt_blocks = 0;
>  	xfs_filblks_t		blocks;
>  	int			error;
> @@ -394,21 +393,19 @@ xchk_refcount_xref_rmap(
>  		return;
>  
>  	/* Check that we saw as many refcbt blocks as the rmap knows about. */
> -	xfs_rmap_ag_owner(&oinfo, XFS_RMAP_OWN_REFC);
>  	error = xfs_btree_count_blocks(sc->sa.refc_cur, &refcbt_blocks);
>  	if (!xchk_btree_process_error(sc, sc->sa.refc_cur, 0, &error))
>  		return;
> -	error = xchk_count_rmap_ownedby_ag(sc, sc->sa.rmap_cur, &oinfo,
> -			&blocks);
> +	error = xchk_count_rmap_ownedby_ag(sc, sc->sa.rmap_cur,
> +			&XFS_RMAP_OINFO_REFC, &blocks);
>  	if (!xchk_should_check_xref(sc, &error, &sc->sa.rmap_cur))
>  		return;
>  	if (blocks != refcbt_blocks)
>  		xchk_btree_xref_set_corrupt(sc, sc->sa.rmap_cur, 0);
>  
>  	/* Check that we saw as many cow blocks as the rmap knows about. */
> -	xfs_rmap_ag_owner(&oinfo, XFS_RMAP_OWN_COW);
> -	error = xchk_count_rmap_ownedby_ag(sc, sc->sa.rmap_cur, &oinfo,
> -			&blocks);
> +	error = xchk_count_rmap_ownedby_ag(sc, sc->sa.rmap_cur,
> +			&XFS_RMAP_OINFO_COW, &blocks);
>  	if (!xchk_should_check_xref(sc, &error, &sc->sa.rmap_cur))
>  		return;
>  	if (blocks != cow_blocks)
> @@ -420,13 +417,11 @@ int
>  xchk_refcountbt(
>  	struct xfs_scrub	*sc)
>  {
> -	struct xfs_owner_info	oinfo;
>  	xfs_agblock_t		cow_blocks = 0;
>  	int			error;
>  
> -	xfs_rmap_ag_owner(&oinfo, XFS_RMAP_OWN_REFC);
>  	error = xchk_btree(sc, sc->sa.refc_cur, xchk_refcountbt_rec,
> -			&oinfo, &cow_blocks);
> +			&XFS_RMAP_OINFO_REFC, &cow_blocks);
>  	if (error)
>  		return error;
>  
> diff --git a/fs/xfs/scrub/repair.c b/fs/xfs/scrub/repair.c
> index 90ae9e173de7..1c8eecfe52b8 100644
> --- a/fs/xfs/scrub/repair.c
> +++ b/fs/xfs/scrub/repair.c
> @@ -505,7 +505,6 @@ xrep_put_freelist(
>  	struct xfs_scrub	*sc,
>  	xfs_agblock_t		agbno)
>  {
> -	struct xfs_owner_info	oinfo;
>  	int			error;
>  
>  	/* Make sure there's space on the freelist. */
> @@ -518,9 +517,8 @@ xrep_put_freelist(
>  	 * create an rmap for the block prior to merging it or else other
>  	 * parts will break.
>  	 */
> -	xfs_rmap_ag_owner(&oinfo, XFS_RMAP_OWN_AG);
>  	error = xfs_rmap_alloc(sc->tp, sc->sa.agf_bp, sc->sa.agno, agbno, 1,
> -			&oinfo);
> +			&XFS_RMAP_OINFO_AG);
>  	if (error)
>  		return error;
>  
> diff --git a/fs/xfs/scrub/rmap.c b/fs/xfs/scrub/rmap.c
> index 8a5bf15d544d..92a140c5b55e 100644
> --- a/fs/xfs/scrub/rmap.c
> +++ b/fs/xfs/scrub/rmap.c
> @@ -174,11 +174,8 @@ int
>  xchk_rmapbt(
>  	struct xfs_scrub	*sc)
>  {
> -	struct xfs_owner_info	oinfo;
> -
> -	xfs_rmap_ag_owner(&oinfo, XFS_RMAP_OWN_AG);
>  	return xchk_btree(sc, sc->sa.rmap_cur, xchk_rmapbt_rec,
> -			&oinfo, NULL);
> +			&XFS_RMAP_OINFO_AG, NULL);
>  }
>  
>  /* xref check that the extent is owned by a given owner */
> diff --git a/fs/xfs/xfs_extfree_item.c b/fs/xfs/xfs_extfree_item.c
> index d9da66c718bb..74ddf66f4cfe 100644
> --- a/fs/xfs/xfs_extfree_item.c
> +++ b/fs/xfs/xfs_extfree_item.c
> @@ -494,7 +494,6 @@ xfs_efi_recover(
>  	int			error = 0;
>  	xfs_extent_t		*extp;
>  	xfs_fsblock_t		startblock_fsb;
> -	struct xfs_owner_info	oinfo;
>  
>  	ASSERT(!test_bit(XFS_EFI_RECOVERED, &efip->efi_flags));
>  
> @@ -526,11 +525,11 @@ xfs_efi_recover(
>  		return error;
>  	efdp = xfs_trans_get_efd(tp, efip, efip->efi_format.efi_nextents);
>  
> -	xfs_rmap_any_owner_update(&oinfo);
>  	for (i = 0; i < efip->efi_format.efi_nextents; i++) {
>  		extp = &efip->efi_format.efi_extents[i];
>  		error = xfs_trans_free_extent(tp, efdp, extp->ext_start,
> -					      extp->ext_len, &oinfo, false);
> +					      extp->ext_len,
> +					      &XFS_RMAP_OINFO_ANY_OWNER, false);
>  		if (error)
>  			goto abort_error;
>  
> 

^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: [PATCH 3/4] xfs: precalculate inodes and blocks per inode cluster
  2018-11-28 23:26 ` [PATCH 3/4] xfs: precalculate inodes and blocks per inode cluster Darrick J. Wong
@ 2018-11-29 15:00   ` Brian Foster
  0 siblings, 0 replies; 7+ messages in thread
From: Brian Foster @ 2018-11-29 15:00 UTC (permalink / raw)
  To: Darrick J. Wong; +Cc: linux-xfs

On Wed, Nov 28, 2018 at 03:26:31PM -0800, Darrick J. Wong wrote:
> From: Darrick J. Wong <darrick.wong@oracle.com>
> 
> Store the number of inodes and blocks per inode cluster in the mount
> data so that we don't have to keep recalculating them.
> 
> Signed-off-by: Darrick J. Wong <darrick.wong@oracle.com>
> ---

Reviewed-by: Brian Foster <bfoster@redhat.com>

>  fs/xfs/libxfs/xfs_ialloc.c |   23 ++++++++++-------------
>  fs/xfs/scrub/ialloc.c      |   14 ++++++--------
>  fs/xfs/xfs_inode.c         |   14 +++++---------
>  fs/xfs/xfs_itable.c        |   14 ++++++--------
>  fs/xfs/xfs_log_recover.c   |    8 +++-----
>  fs/xfs/xfs_mount.c         |    2 ++
>  fs/xfs/xfs_mount.h         |    2 ++
>  7 files changed, 34 insertions(+), 43 deletions(-)
> 
> 
> diff --git a/fs/xfs/libxfs/xfs_ialloc.c b/fs/xfs/libxfs/xfs_ialloc.c
> index 3ac4a836428d..c7b2579a8e73 100644
> --- a/fs/xfs/libxfs/xfs_ialloc.c
> +++ b/fs/xfs/libxfs/xfs_ialloc.c
> @@ -288,7 +288,7 @@ xfs_ialloc_inode_init(
>  {
>  	struct xfs_buf		*fbuf;
>  	struct xfs_dinode	*free;
> -	int			nbufs, blks_per_cluster, inodes_per_cluster;
> +	int			nbufs;
>  	int			version;
>  	int			i, j;
>  	xfs_daddr_t		d;
> @@ -299,9 +299,7 @@ xfs_ialloc_inode_init(
>  	 * sizes, manipulate the inodes in buffers  which are multiples of the
>  	 * blocks size.
>  	 */
> -	blks_per_cluster = xfs_icluster_size_fsb(mp);
> -	inodes_per_cluster = XFS_FSB_TO_INO(mp, blks_per_cluster);
> -	nbufs = length / blks_per_cluster;
> +	nbufs = length / mp->m_blocks_per_cluster;
>  
>  	/*
>  	 * Figure out what version number to use in the inodes we create.  If
> @@ -344,9 +342,10 @@ xfs_ialloc_inode_init(
>  		/*
>  		 * Get the block.
>  		 */
> -		d = XFS_AGB_TO_DADDR(mp, agno, agbno + (j * blks_per_cluster));
> +		d = XFS_AGB_TO_DADDR(mp, agno, agbno +
> +				(j * mp->m_blocks_per_cluster));
>  		fbuf = xfs_trans_get_buf(tp, mp->m_ddev_targp, d,
> -					 mp->m_bsize * blks_per_cluster,
> +					 mp->m_bsize * mp->m_blocks_per_cluster,
>  					 XBF_UNMAPPED);
>  		if (!fbuf)
>  			return -ENOMEM;
> @@ -354,7 +353,7 @@ xfs_ialloc_inode_init(
>  		/* Initialize the inode buffers and log them appropriately. */
>  		fbuf->b_ops = &xfs_inode_buf_ops;
>  		xfs_buf_zero(fbuf, 0, BBTOB(fbuf->b_length));
> -		for (i = 0; i < inodes_per_cluster; i++) {
> +		for (i = 0; i < mp->m_inodes_per_cluster; i++) {
>  			int	ioffset = i << mp->m_sb.sb_inodelog;
>  			uint	isize = xfs_dinode_size(version);
>  
> @@ -2289,7 +2288,6 @@ xfs_imap(
>  	xfs_agblock_t	agbno;	/* block number of inode in the alloc group */
>  	xfs_agino_t	agino;	/* inode number within alloc group */
>  	xfs_agnumber_t	agno;	/* allocation group number */
> -	int		blks_per_cluster; /* num blocks per inode cluster */
>  	xfs_agblock_t	chunk_agbno;	/* first block in inode chunk */
>  	xfs_agblock_t	cluster_agbno;	/* first block in inode cluster */
>  	int		error;	/* error code */
> @@ -2335,8 +2333,6 @@ xfs_imap(
>  		return -EINVAL;
>  	}
>  
> -	blks_per_cluster = xfs_icluster_size_fsb(mp);
> -
>  	/*
>  	 * For bulkstat and handle lookups, we have an untrusted inode number
>  	 * that we have to verify is valid. We cannot do this just by reading
> @@ -2356,7 +2352,7 @@ xfs_imap(
>  	 * If the inode cluster size is the same as the blocksize or
>  	 * smaller we get to the buffer by simple arithmetics.
>  	 */
> -	if (blks_per_cluster == 1) {
> +	if (mp->m_blocks_per_cluster == 1) {
>  		offset = XFS_INO_TO_OFFSET(mp, ino);
>  		ASSERT(offset < mp->m_sb.sb_inopblock);
>  
> @@ -2385,12 +2381,13 @@ xfs_imap(
>  out_map:
>  	ASSERT(agbno >= chunk_agbno);
>  	cluster_agbno = chunk_agbno +
> -		((offset_agbno / blks_per_cluster) * blks_per_cluster);
> +		((offset_agbno / mp->m_blocks_per_cluster) *
> +		 mp->m_blocks_per_cluster);
>  	offset = ((agbno - cluster_agbno) * mp->m_sb.sb_inopblock) +
>  		XFS_INO_TO_OFFSET(mp, ino);
>  
>  	imap->im_blkno = XFS_AGB_TO_DADDR(mp, agno, cluster_agbno);
> -	imap->im_len = XFS_FSB_TO_BB(mp, blks_per_cluster);
> +	imap->im_len = XFS_FSB_TO_BB(mp, mp->m_blocks_per_cluster);
>  	imap->im_boffset = (unsigned short)(offset << mp->m_sb.sb_inodelog);
>  
>  	/*
> diff --git a/fs/xfs/scrub/ialloc.c b/fs/xfs/scrub/ialloc.c
> index 426eb1a5503c..596a02b8efdc 100644
> --- a/fs/xfs/scrub/ialloc.c
> +++ b/fs/xfs/scrub/ialloc.c
> @@ -193,18 +193,16 @@ xchk_iallocbt_check_freemask(
>  	xfs_agino_t			chunkino;
>  	xfs_agino_t			clusterino;
>  	xfs_agblock_t			agbno;
> -	int				blks_per_cluster;
>  	uint16_t			holemask;
>  	uint16_t			ir_holemask;
>  	int				error = 0;
>  
>  	/* Make sure the freemask matches the inode records. */
> -	blks_per_cluster = xfs_icluster_size_fsb(mp);
> -	nr_inodes = XFS_FSB_TO_INO(mp, blks_per_cluster);
> +	nr_inodes = mp->m_inodes_per_cluster;
>  
>  	for (agino = irec->ir_startino;
>  	     agino < irec->ir_startino + XFS_INODES_PER_CHUNK;
> -	     agino += blks_per_cluster * mp->m_sb.sb_inopblock) {
> +	     agino += mp->m_inodes_per_cluster) {
>  		fsino = XFS_AGINO_TO_INO(mp, bs->cur->bc_private.a.agno, agino);
>  		chunkino = agino - irec->ir_startino;
>  		agbno = XFS_AGINO_TO_AGBNO(mp, agino);
> @@ -225,18 +223,18 @@ xchk_iallocbt_check_freemask(
>  		/* If any part of this is a hole, skip it. */
>  		if (ir_holemask) {
>  			xchk_xref_is_not_owned_by(bs->sc, agbno,
> -					blks_per_cluster,
> +					mp->m_blocks_per_cluster,
>  					&XFS_RMAP_OINFO_INODES);
>  			continue;
>  		}
>  
> -		xchk_xref_is_owned_by(bs->sc, agbno, blks_per_cluster,
> +		xchk_xref_is_owned_by(bs->sc, agbno, mp->m_blocks_per_cluster,
>  				&XFS_RMAP_OINFO_INODES);
>  
>  		/* Grab the inode cluster buffer. */
>  		imap.im_blkno = XFS_AGB_TO_DADDR(mp, bs->cur->bc_private.a.agno,
>  				agbno);
> -		imap.im_len = XFS_FSB_TO_BB(mp, blks_per_cluster);
> +		imap.im_len = XFS_FSB_TO_BB(mp, mp->m_blocks_per_cluster);
>  		imap.im_boffset = 0;
>  
>  		error = xfs_imap_to_bp(mp, bs->cur->bc_tp, &imap,
> @@ -303,7 +301,7 @@ xchk_iallocbt_rec(
>  	/* Make sure this record is aligned to cluster and inoalignmnt size. */
>  	agbno = XFS_AGINO_TO_AGBNO(mp, irec.ir_startino);
>  	if ((agbno & (xfs_ialloc_cluster_alignment(mp) - 1)) ||
> -	    (agbno & (xfs_icluster_size_fsb(mp) - 1)))
> +	    (agbno & (mp->m_blocks_per_cluster - 1)))
>  		xchk_btree_set_corrupt(bs->sc, bs->cur, 0);
>  
>  	*inode_blocks += XFS_B_TO_FSB(mp,
> diff --git a/fs/xfs/xfs_inode.c b/fs/xfs/xfs_inode.c
> index 801eb891d0fd..ae667ba74a1c 100644
> --- a/fs/xfs/xfs_inode.c
> +++ b/fs/xfs/xfs_inode.c
> @@ -2184,8 +2184,6 @@ xfs_ifree_cluster(
>  	struct xfs_icluster	*xic)
>  {
>  	xfs_mount_t		*mp = free_ip->i_mount;
> -	int			blks_per_cluster;
> -	int			inodes_per_cluster;
>  	int			nbufs;
>  	int			i, j;
>  	int			ioffset;
> @@ -2199,11 +2197,9 @@ xfs_ifree_cluster(
>  
>  	inum = xic->first_ino;
>  	pag = xfs_perag_get(mp, XFS_INO_TO_AGNO(mp, inum));
> -	blks_per_cluster = xfs_icluster_size_fsb(mp);
> -	inodes_per_cluster = XFS_FSB_TO_INO(mp, blks_per_cluster);
> -	nbufs = mp->m_ialloc_blks / blks_per_cluster;
> +	nbufs = mp->m_ialloc_blks / mp->m_blocks_per_cluster;
>  
> -	for (j = 0; j < nbufs; j++, inum += inodes_per_cluster) {
> +	for (j = 0; j < nbufs; j++, inum += mp->m_inodes_per_cluster) {
>  		/*
>  		 * The allocation bitmap tells us which inodes of the chunk were
>  		 * physically allocated. Skip the cluster if an inode falls into
> @@ -2211,7 +2207,7 @@ xfs_ifree_cluster(
>  		 */
>  		ioffset = inum - xic->first_ino;
>  		if ((xic->alloc & XFS_INOBT_MASK(ioffset)) == 0) {
> -			ASSERT(ioffset % inodes_per_cluster == 0);
> +			ASSERT(ioffset % mp->m_inodes_per_cluster == 0);
>  			continue;
>  		}
>  
> @@ -2227,7 +2223,7 @@ xfs_ifree_cluster(
>  		 * to mark all the active inodes on the buffer stale.
>  		 */
>  		bp = xfs_trans_get_buf(tp, mp->m_ddev_targp, blkno,
> -					mp->m_bsize * blks_per_cluster,
> +					mp->m_bsize * mp->m_blocks_per_cluster,
>  					XBF_UNMAPPED);
>  
>  		if (!bp)
> @@ -2274,7 +2270,7 @@ xfs_ifree_cluster(
>  		 * transaction stale above, which means there is no point in
>  		 * even trying to lock them.
>  		 */
> -		for (i = 0; i < inodes_per_cluster; i++) {
> +		for (i = 0; i < mp->m_inodes_per_cluster; i++) {
>  retry:
>  			rcu_read_lock();
>  			ip = radix_tree_lookup(&pag->pag_ici_root,
> diff --git a/fs/xfs/xfs_itable.c b/fs/xfs/xfs_itable.c
> index 18d8d3b812a7..942e4aa5e729 100644
> --- a/fs/xfs/xfs_itable.c
> +++ b/fs/xfs/xfs_itable.c
> @@ -167,20 +167,18 @@ xfs_bulkstat_ichunk_ra(
>  {
>  	xfs_agblock_t			agbno;
>  	struct blk_plug			plug;
> -	int				blks_per_cluster;
> -	int				inodes_per_cluster;
>  	int				i;	/* inode chunk index */
>  
>  	agbno = XFS_AGINO_TO_AGBNO(mp, irec->ir_startino);
> -	blks_per_cluster = xfs_icluster_size_fsb(mp);
> -	inodes_per_cluster = XFS_FSB_TO_INO(mp, blks_per_cluster);
>  
>  	blk_start_plug(&plug);
>  	for (i = 0; i < XFS_INODES_PER_CHUNK;
> -	     i += inodes_per_cluster, agbno += blks_per_cluster) {
> -		if (xfs_inobt_maskn(i, inodes_per_cluster) & ~irec->ir_free) {
> -			xfs_btree_reada_bufs(mp, agno, agbno, blks_per_cluster,
> -					     &xfs_inode_buf_ops);
> +	     i += mp->m_inodes_per_cluster, agbno += mp->m_blocks_per_cluster) {
> +		if (xfs_inobt_maskn(i, mp->m_inodes_per_cluster) &
> +		    ~irec->ir_free) {
> +			xfs_btree_reada_bufs(mp, agno, agbno,
> +					mp->m_blocks_per_cluster,
> +					&xfs_inode_buf_ops);
>  		}
>  	}
>  	blk_finish_plug(&plug);
> diff --git a/fs/xfs/xfs_log_recover.c b/fs/xfs/xfs_log_recover.c
> index 1fc9e9042e0e..9fe88d125f0a 100644
> --- a/fs/xfs/xfs_log_recover.c
> +++ b/fs/xfs/xfs_log_recover.c
> @@ -3850,7 +3850,6 @@ xlog_recover_do_icreate_pass2(
>  	unsigned int		count;
>  	unsigned int		isize;
>  	xfs_agblock_t		length;
> -	int			blks_per_cluster;
>  	int			bb_per_cluster;
>  	int			cancel_count;
>  	int			nbufs;
> @@ -3918,14 +3917,13 @@ xlog_recover_do_icreate_pass2(
>  	 * buffers for cancellation so we don't overwrite anything written after
>  	 * a cancellation.
>  	 */
> -	blks_per_cluster = xfs_icluster_size_fsb(mp);
> -	bb_per_cluster = XFS_FSB_TO_BB(mp, blks_per_cluster);
> -	nbufs = length / blks_per_cluster;
> +	bb_per_cluster = XFS_FSB_TO_BB(mp, mp->m_blocks_per_cluster);
> +	nbufs = length / mp->m_blocks_per_cluster;
>  	for (i = 0, cancel_count = 0; i < nbufs; i++) {
>  		xfs_daddr_t	daddr;
>  
>  		daddr = XFS_AGB_TO_DADDR(mp, agno,
> -					 agbno + i * blks_per_cluster);
> +					 agbno + i * mp->m_blocks_per_cluster);
>  		if (xlog_check_buffer_cancelled(log, daddr, bb_per_cluster, 0))
>  			cancel_count++;
>  	}
> diff --git a/fs/xfs/xfs_mount.c b/fs/xfs/xfs_mount.c
> index 02d15098dbee..56d374675fd5 100644
> --- a/fs/xfs/xfs_mount.c
> +++ b/fs/xfs/xfs_mount.c
> @@ -798,6 +798,8 @@ xfs_mountfs(
>  		if (mp->m_sb.sb_inoalignmt >= XFS_B_TO_FSBT(mp, new_size))
>  			mp->m_inode_cluster_size = new_size;
>  	}
> +	mp->m_blocks_per_cluster = xfs_icluster_size_fsb(mp);
> +	mp->m_inodes_per_cluster = XFS_FSB_TO_INO(mp, mp->m_blocks_per_cluster);
>  
>  	/*
>  	 * If enabled, sparse inode chunk alignment is expected to match the
> diff --git a/fs/xfs/xfs_mount.h b/fs/xfs/xfs_mount.h
> index 7964513c3128..58a037bfac22 100644
> --- a/fs/xfs/xfs_mount.h
> +++ b/fs/xfs/xfs_mount.h
> @@ -101,6 +101,8 @@ typedef struct xfs_mount {
>  	uint8_t			m_agno_log;	/* log #ag's */
>  	uint8_t			m_agino_log;	/* #bits for agino in inum */
>  	uint			m_inode_cluster_size;/* min inode buf size */
> +	unsigned int		m_inodes_per_cluster;
> +	unsigned int		m_blocks_per_cluster;
>  	uint			m_blockmask;	/* sb_blocksize-1 */
>  	uint			m_blockwsize;	/* sb_blocksize in words */
>  	uint			m_blockwmask;	/* blockwsize-1 */
> 

^ permalink raw reply	[flat|nested] 7+ messages in thread

end of thread, other threads:[~2018-11-30  2:06 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2018-11-28 23:26 [PATCH 0/4] xfs-5.0: cleanups Darrick J. Wong
2018-11-28 23:26 ` [PATCH 1/4] xfs: remove xfs_rmap_ag_owner and friends Darrick J. Wong
2018-11-29 15:00   ` Brian Foster
2018-11-28 23:26 ` [PATCH 2/4] xfs: add a block to inode count converter Darrick J. Wong
2018-11-28 23:26 ` [PATCH 3/4] xfs: precalculate inodes and blocks per inode cluster Darrick J. Wong
2018-11-29 15:00   ` Brian Foster
2018-11-28 23:26 ` [PATCH 4/4] xfs: precalculate cluster alignment in inodes and blocks Darrick J. Wong

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.