All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCHBOMB RFC]: xfs: realtime units cleanups
@ 2023-10-11 17:57 Darrick J. Wong
  2023-10-11 18:01 ` [PATCHSET RFC v1.0 0/3] xfs: minor bugfixes for rt stuff Darrick J. Wong
                   ` (3 more replies)
  0 siblings, 4 replies; 83+ messages in thread
From: Darrick J. Wong @ 2023-10-11 17:57 UTC (permalink / raw)
  To: osandov, linux-xfs, hch

Hi everyone,

Christoph asked if I could resend the realtime space units cleanups that
I mentioned earlier in [1].  The realtime modernization project is stuck
deep in my dev branch behind the online repair series.  For my own
sanity I'm leaving them coupled together in djwong-dev instead of
splitting them and trying to keep the two branches in sync.

Anyway, here's an RFC of the rt cleanups; if this somehow gets merged
before online repair, I'll separate the fs/xfs/scrub/ diffs.

(Please please let's all help dchinner and cem have time and brainpower
to review the online repair patchsets.)

--D

[1] https://lore.kernel.org/linux-xfs/20230918153848.GA348018@frogsfrogsfrogs/

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

* [PATCHSET RFC v1.0 0/3] xfs: minor bugfixes for rt stuff
  2023-10-11 17:57 [PATCHBOMB RFC]: xfs: realtime units cleanups Darrick J. Wong
@ 2023-10-11 18:01 ` Darrick J. Wong
  2023-10-11 18:02   ` [PATCH 1/3] xfs: bump max fsgeom struct version Darrick J. Wong
                     ` (2 more replies)
  2023-10-11 18:01 ` [PATCHSET RFC v1.0 0/7] xfs: clean up realtime type usage Darrick J. Wong
                   ` (2 subsequent siblings)
  3 siblings, 3 replies; 83+ messages in thread
From: Darrick J. Wong @ 2023-10-11 18:01 UTC (permalink / raw)
  To: djwong; +Cc: linux-xfs, osandov, hch

Hi all,

This is a preparatory patchset that fixes a few miscellaneous bugs
before we start in on larger cleanups of realtime units usage.

If you're going to start using this code, I strongly recommend pulling
from my git trees, which are linked below.

This has been running on the djcloud for months with no problems.  Enjoy!
Comments and questions are, as always, welcome.

--D

kernel git tree:
https://git.kernel.org/cgit/linux/kernel/git/djwong/xfs-linux.git/log/?h=realtime-fixes

fstests git tree:
https://git.kernel.org/cgit/linux/kernel/git/djwong/xfstests-dev.git/log/?h=realtime-fixes
---
 fs/xfs/libxfs/xfs_sb.h |    2 +-
 fs/xfs/xfs_rtalloc.c   |    2 +-
 fs/xfs/xfs_rtalloc.h   |   24 ++++++++++++------------
 3 files changed, 14 insertions(+), 14 deletions(-)


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

* [PATCHSET RFC v1.0 0/7] xfs: clean up realtime type usage
  2023-10-11 17:57 [PATCHBOMB RFC]: xfs: realtime units cleanups Darrick J. Wong
  2023-10-11 18:01 ` [PATCHSET RFC v1.0 0/3] xfs: minor bugfixes for rt stuff Darrick J. Wong
@ 2023-10-11 18:01 ` Darrick J. Wong
  2023-10-11 18:02   ` [PATCH 1/7] xfs: make sure maxlen is still congruent with prod when rounding down Darrick J. Wong
                     ` (7 more replies)
  2023-10-11 18:01 ` [PATCHSET RFC v1.0 0/7] xfs: refactor rt extent unit conversions Darrick J. Wong
  2023-10-11 18:01 ` [PATCHSET RFC v1.0 0/8] xfs: refactor rtbitmap/summary macros Darrick J. Wong
  3 siblings, 8 replies; 83+ messages in thread
From: Darrick J. Wong @ 2023-10-11 18:01 UTC (permalink / raw)
  To: djwong; +Cc: linux-xfs, osandov, hch

Hi all,

The realtime code uses xfs_rtblock_t and xfs_fsblock_t in a lot of
places, and it's very confusing.  Clean up all the type usage so that an
xfs_rtblock_t is always a block within the realtime volume, an
xfs_fileoff_t is always a file offset within a realtime metadata file,
and an xfs_rtxnumber_t is always a rt extent within the realtime volume.

If you're going to start using this code, I strongly recommend pulling
from my git trees, which are linked below.

This has been running on the djcloud for months with no problems.  Enjoy!
Comments and questions are, as always, welcome.

--D

kernel git tree:
https://git.kernel.org/cgit/linux/kernel/git/djwong/xfs-linux.git/log/?h=clean-up-realtime-units

xfsprogs git tree:
https://git.kernel.org/cgit/linux/kernel/git/djwong/xfsprogs-dev.git/log/?h=clean-up-realtime-units
---
 fs/xfs/libxfs/xfs_bmap.c     |    4 -
 fs/xfs/libxfs/xfs_format.h   |    2 
 fs/xfs/libxfs/xfs_rtbitmap.c |  121 +++++++++++----------
 fs/xfs/libxfs/xfs_rtbitmap.h |   79 ++++++++++++++
 fs/xfs/libxfs/xfs_types.c    |    4 -
 fs/xfs/libxfs/xfs_types.h    |    8 +
 fs/xfs/scrub/bmap.c          |    2 
 fs/xfs/scrub/fscounters.c    |    2 
 fs/xfs/scrub/rtbitmap.c      |   16 +--
 fs/xfs/scrub/rtsummary.c     |    6 +
 fs/xfs/scrub/trace.h         |    7 +
 fs/xfs/xfs_bmap_item.c       |    2 
 fs/xfs/xfs_bmap_util.c       |   18 +--
 fs/xfs/xfs_fsmap.c           |    2 
 fs/xfs/xfs_rtalloc.c         |  243 ++++++++++++++++++++++--------------------
 fs/xfs/xfs_rtalloc.h         |   89 +--------------
 16 files changed, 315 insertions(+), 290 deletions(-)
 create mode 100644 fs/xfs/libxfs/xfs_rtbitmap.h


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

* [PATCHSET RFC v1.0 0/7] xfs: refactor rt extent unit conversions
  2023-10-11 17:57 [PATCHBOMB RFC]: xfs: realtime units cleanups Darrick J. Wong
  2023-10-11 18:01 ` [PATCHSET RFC v1.0 0/3] xfs: minor bugfixes for rt stuff Darrick J. Wong
  2023-10-11 18:01 ` [PATCHSET RFC v1.0 0/7] xfs: clean up realtime type usage Darrick J. Wong
@ 2023-10-11 18:01 ` Darrick J. Wong
  2023-10-11 18:04   ` [PATCH 1/7] xfs: create a helper to convert rtextents to rtblocks Darrick J. Wong
                     ` (6 more replies)
  2023-10-11 18:01 ` [PATCHSET RFC v1.0 0/8] xfs: refactor rtbitmap/summary macros Darrick J. Wong
  3 siblings, 7 replies; 83+ messages in thread
From: Darrick J. Wong @ 2023-10-11 18:01 UTC (permalink / raw)
  To: djwong; +Cc: linux-xfs, osandov, hch

Hi all,

This series replaces all the open-coded integer division and
multiplication conversions between rt blocks and rt extents with calls
to static inline helpers.  Having cleaned all that up, the helpers are
augmented to skip the expensive operations in favor of bit shifts and
masking if the rt extent size is a power of two.

If you're going to start using this code, I strongly recommend pulling
from my git trees, which are linked below.

This has been running on the djcloud for months with no problems.  Enjoy!
Comments and questions are, as always, welcome.

--D

kernel git tree:
https://git.kernel.org/cgit/linux/kernel/git/djwong/xfs-linux.git/log/?h=refactor-rt-unit-conversions

xfsprogs git tree:
https://git.kernel.org/cgit/linux/kernel/git/djwong/xfsprogs-dev.git/log/?h=refactor-rt-unit-conversions
---
 fs/xfs/libxfs/xfs_bmap.c        |   19 +++-----
 fs/xfs/libxfs/xfs_rtbitmap.c    |    4 +-
 fs/xfs/libxfs/xfs_rtbitmap.h    |   88 +++++++++++++++++++++++++++++++++++++++
 fs/xfs/libxfs/xfs_sb.c          |    2 +
 fs/xfs/libxfs/xfs_swapext.c     |    7 ++-
 fs/xfs/libxfs/xfs_trans_inode.c |    1 
 fs/xfs/libxfs/xfs_trans_resv.c  |    3 +
 fs/xfs/scrub/inode.c            |    3 +
 fs/xfs/scrub/inode_repair.c     |    3 +
 fs/xfs/scrub/rtbitmap.c         |   18 +++-----
 fs/xfs/scrub/rtsummary.c        |    4 +-
 fs/xfs/xfs_bmap_util.c          |   38 +++++++----------
 fs/xfs/xfs_fsmap.c              |   14 +++---
 fs/xfs/xfs_inode_item.c         |    3 +
 fs/xfs/xfs_ioctl.c              |    5 +-
 fs/xfs/xfs_linux.h              |   12 +++++
 fs/xfs/xfs_mount.h              |    2 +
 fs/xfs/xfs_rtalloc.c            |   16 ++++---
 fs/xfs/xfs_super.c              |    3 +
 fs/xfs/xfs_trans.c              |    9 +++-
 fs/xfs/xfs_xchgrange.c          |    4 +-
 21 files changed, 180 insertions(+), 78 deletions(-)


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

* [PATCHSET RFC v1.0 0/8] xfs: refactor rtbitmap/summary macros
  2023-10-11 17:57 [PATCHBOMB RFC]: xfs: realtime units cleanups Darrick J. Wong
                   ` (2 preceding siblings ...)
  2023-10-11 18:01 ` [PATCHSET RFC v1.0 0/7] xfs: refactor rt extent unit conversions Darrick J. Wong
@ 2023-10-11 18:01 ` Darrick J. Wong
  2023-10-11 18:06   ` [PATCH 1/8] xfs: convert the rtbitmap block and bit macros to static inline functions Darrick J. Wong
                     ` (7 more replies)
  3 siblings, 8 replies; 83+ messages in thread
From: Darrick J. Wong @ 2023-10-11 18:01 UTC (permalink / raw)
  To: djwong; +Cc: linux-xfs, osandov, hch

Hi all,

In preparation for adding block headers and enforcing endian order in
rtbitmap and rtsummary blocks, replace open-coded geometry computations
and fugly macros with proper helper functions that can be typechecked.
Soon we'll be needing to add more complex logic to the helpers.

If you're going to start using this code, I strongly recommend pulling
from my git trees, which are linked below.

This has been running on the djcloud for months with no problems.  Enjoy!
Comments and questions are, as always, welcome.

--D

kernel git tree:
https://git.kernel.org/cgit/linux/kernel/git/djwong/xfs-linux.git/log/?h=refactor-rtbitmap-macros

xfsprogs git tree:
https://git.kernel.org/cgit/linux/kernel/git/djwong/xfsprogs-dev.git/log/?h=refactor-rtbitmap-macros
---
 fs/xfs/libxfs/xfs_format.h      |   32 ++---
 fs/xfs/libxfs/xfs_rtbitmap.c    |  268 ++++++++++++++++++++++++++++-----------
 fs/xfs/libxfs/xfs_rtbitmap.h    |  133 +++++++++++++++++++
 fs/xfs/libxfs/xfs_trans_resv.c  |    9 +
 fs/xfs/libxfs/xfs_types.h       |    2 
 fs/xfs/scrub/rtsummary.c        |   50 ++++---
 fs/xfs/scrub/rtsummary.h        |    6 -
 fs/xfs/scrub/rtsummary_repair.c |    7 +
 fs/xfs/scrub/trace.c            |    1 
 fs/xfs/scrub/trace.h            |    4 -
 fs/xfs/xfs_ondisk.h             |    4 +
 fs/xfs/xfs_rtalloc.c            |   39 +++---
 12 files changed, 408 insertions(+), 147 deletions(-)


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

* [PATCH 1/3] xfs: bump max fsgeom struct version
  2023-10-11 18:01 ` [PATCHSET RFC v1.0 0/3] xfs: minor bugfixes for rt stuff Darrick J. Wong
@ 2023-10-11 18:02   ` Darrick J. Wong
  2023-10-12  4:51     ` Christoph Hellwig
  2023-10-11 18:02   ` [PATCH 2/3] xfs: prevent rt growfs when quota is enabled Darrick J. Wong
  2023-10-11 18:02   ` [PATCH 3/3] xfs: rt stubs should return negative errnos when rt disabled Darrick J. Wong
  2 siblings, 1 reply; 83+ messages in thread
From: Darrick J. Wong @ 2023-10-11 18:02 UTC (permalink / raw)
  To: djwong; +Cc: linux-xfs, osandov, hch

From: Darrick J. Wong <djwong@kernel.org>

The latest version of the fs geometry structure is v5.

Signed-off-by: Darrick J. Wong <djwong@kernel.org>
---
 fs/xfs/libxfs/xfs_sb.h |    2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)


diff --git a/fs/xfs/libxfs/xfs_sb.h b/fs/xfs/libxfs/xfs_sb.h
index a5e14740ec9ac..19134b23c10be 100644
--- a/fs/xfs/libxfs/xfs_sb.h
+++ b/fs/xfs/libxfs/xfs_sb.h
@@ -25,7 +25,7 @@ extern uint64_t	xfs_sb_version_to_features(struct xfs_sb *sbp);
 
 extern int	xfs_update_secondary_sbs(struct xfs_mount *mp);
 
-#define XFS_FS_GEOM_MAX_STRUCT_VER	(4)
+#define XFS_FS_GEOM_MAX_STRUCT_VER	(5)
 extern void	xfs_fs_geometry(struct xfs_mount *mp, struct xfs_fsop_geom *geo,
 				int struct_version);
 extern int	xfs_sb_read_secondary(struct xfs_mount *mp,


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

* [PATCH 2/3] xfs: prevent rt growfs when quota is enabled
  2023-10-11 18:01 ` [PATCHSET RFC v1.0 0/3] xfs: minor bugfixes for rt stuff Darrick J. Wong
  2023-10-11 18:02   ` [PATCH 1/3] xfs: bump max fsgeom struct version Darrick J. Wong
@ 2023-10-11 18:02   ` Darrick J. Wong
  2023-10-12  4:51     ` Christoph Hellwig
  2023-10-11 18:02   ` [PATCH 3/3] xfs: rt stubs should return negative errnos when rt disabled Darrick J. Wong
  2 siblings, 1 reply; 83+ messages in thread
From: Darrick J. Wong @ 2023-10-11 18:02 UTC (permalink / raw)
  To: djwong; +Cc: linux-xfs, osandov, hch

From: Darrick J. Wong <djwong@kernel.org>

Quotas aren't (yet) supported with realtime, so we shouldn't allow
userspace to set up a realtime section when quotas are enabled, even if
they attached one via mount options.  IOWS, you shouldn't be able to do:

# mkfs.xfs -f /dev/sda
# mount /dev/sda /mnt -o rtdev=/dev/sdb
# xfs_growfs -r /mnt

Signed-off-by: Darrick J. Wong <djwong@kernel.org>
---
 fs/xfs/xfs_rtalloc.c |    2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)


diff --git a/fs/xfs/xfs_rtalloc.c b/fs/xfs/xfs_rtalloc.c
index dbc81ea0f4ff6..5429a019159a6 100644
--- a/fs/xfs/xfs_rtalloc.c
+++ b/fs/xfs/xfs_rtalloc.c
@@ -959,7 +959,7 @@ xfs_growfs_rt(
 		return -EINVAL;
 
 	/* Unsupported realtime features. */
-	if (xfs_has_rmapbt(mp) || xfs_has_reflink(mp))
+	if (xfs_has_rmapbt(mp) || xfs_has_reflink(mp) || xfs_has_quota(mp))
 		return -EOPNOTSUPP;
 
 	nrblocks = in->newblocks;


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

* [PATCH 3/3] xfs: rt stubs should return negative errnos when rt disabled
  2023-10-11 18:01 ` [PATCHSET RFC v1.0 0/3] xfs: minor bugfixes for rt stuff Darrick J. Wong
  2023-10-11 18:02   ` [PATCH 1/3] xfs: bump max fsgeom struct version Darrick J. Wong
  2023-10-11 18:02   ` [PATCH 2/3] xfs: prevent rt growfs when quota is enabled Darrick J. Wong
@ 2023-10-11 18:02   ` Darrick J. Wong
  2023-10-12  4:52     ` Christoph Hellwig
  2 siblings, 1 reply; 83+ messages in thread
From: Darrick J. Wong @ 2023-10-11 18:02 UTC (permalink / raw)
  To: djwong; +Cc: linux-xfs, osandov, hch

From: Darrick J. Wong <djwong@kernel.org>

When realtime support is not compiled into the kernel, these functions
should return negative errnos, not positive errnos.  While we're at it,
fix a broken macro declaration.

Signed-off-by: Darrick J. Wong <djwong@kernel.org>
---
 fs/xfs/xfs_rtalloc.h |   24 ++++++++++++------------
 1 file changed, 12 insertions(+), 12 deletions(-)


diff --git a/fs/xfs/xfs_rtalloc.h b/fs/xfs/xfs_rtalloc.h
index e440f793dd98f..e53bc52d81fd6 100644
--- a/fs/xfs/xfs_rtalloc.h
+++ b/fs/xfs/xfs_rtalloc.h
@@ -143,17 +143,17 @@ int xfs_rtalloc_reinit_frextents(struct xfs_mount *mp);
 int xfs_rtfile_convert_unwritten(struct xfs_inode *ip, loff_t pos,
 		uint64_t len);
 #else
-# define xfs_rtallocate_extent(t,b,min,max,l,f,p,rb)    (ENOSYS)
-# define xfs_rtfree_extent(t,b,l)                       (ENOSYS)
-# define xfs_rtfree_blocks(t,rb,rl)			(ENOSYS)
-# define xfs_rtpick_extent(m,t,l,rb)                    (ENOSYS)
-# define xfs_growfs_rt(mp,in)                           (ENOSYS)
-# define xfs_rtalloc_query_range(t,l,h,f,p)             (ENOSYS)
-# define xfs_rtalloc_query_all(m,t,f,p)                 (ENOSYS)
-# define xfs_rtbuf_get(m,t,b,i,p)                       (ENOSYS)
-# define xfs_verify_rtbno(m, r)			(false)
-# define xfs_rtalloc_extent_is_free(m,t,s,l,i)          (ENOSYS)
-# define xfs_rtalloc_reinit_frextents(m)                (0)
+# define xfs_rtallocate_extent(t,b,min,max,l,f,p,rb)	(-ENOSYS)
+# define xfs_rtfree_extent(t,b,l)			(-ENOSYS)
+# define xfs_rtfree_blocks(t,rb,rl)			(-ENOSYS)
+# define xfs_rtpick_extent(m,t,l,rb)			(-ENOSYS)
+# define xfs_growfs_rt(mp,in)				(-ENOSYS)
+# define xfs_rtalloc_query_range(m,t,l,h,f,p)		(-ENOSYS)
+# define xfs_rtalloc_query_all(m,t,f,p)			(-ENOSYS)
+# define xfs_rtbuf_get(m,t,b,i,p)			(-ENOSYS)
+# define xfs_verify_rtbno(m, r)				(false)
+# define xfs_rtalloc_extent_is_free(m,t,s,l,i)		(-ENOSYS)
+# define xfs_rtalloc_reinit_frextents(m)		(0)
 static inline int		/* error */
 xfs_rtmount_init(
 	xfs_mount_t	*mp)	/* file system mount structure */
@@ -164,7 +164,7 @@ xfs_rtmount_init(
 	xfs_warn(mp, "Not built with CONFIG_XFS_RT");
 	return -ENOSYS;
 }
-# define xfs_rtmount_inodes(m)  (((mp)->m_sb.sb_rblocks == 0)? 0 : (ENOSYS))
+# define xfs_rtmount_inodes(m)  (((mp)->m_sb.sb_rblocks == 0)? 0 : (-ENOSYS))
 # define xfs_rtunmount_inodes(m)
 # define xfs_rtfile_convert_unwritten(ip, pos, len)	(0)
 #endif	/* CONFIG_XFS_RT */


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

* [PATCH 1/7] xfs: make sure maxlen is still congruent with prod when rounding down
  2023-10-11 18:01 ` [PATCHSET RFC v1.0 0/7] xfs: clean up realtime type usage Darrick J. Wong
@ 2023-10-11 18:02   ` Darrick J. Wong
  2023-10-12  4:59     ` Christoph Hellwig
  2023-10-11 18:03   ` [PATCH 2/7] xfs: move the xfs_rtbitmap.c declarations to xfs_rtbitmap.h Darrick J. Wong
                     ` (6 subsequent siblings)
  7 siblings, 1 reply; 83+ messages in thread
From: Darrick J. Wong @ 2023-10-11 18:02 UTC (permalink / raw)
  To: djwong; +Cc: linux-xfs, osandov, hch

From: Darrick J. Wong <djwong@kernel.org>

In commit 2a6ca4baed62, we tried to fix an overflow problem in the
realtime allocator that was caused by an overly large maxlen value
causing xfs_rtcheck_range to run off the end of the realtime bitmap.
Unfortunately, there is a subtle bug here -- maxlen (and minlen) both
have to be aligned with @prod, but @prod can be larger than 1 if the
user has set an extent size hint on the file, and that extent size hint
is larger than the realtime extent size.

If the rt free space extents are not aligned to this file's extszhint
because other files without extent size hints allocated space (or the
number of rt extents is similarly not aligned), then it's possible that
maxlen after clamping to sb_rextents will no longer be aligned to prod.
The allocation will succeed just fine, but we still trip the assertion.

Fix the problem by reducing maxlen by any misalignment with prod.  While
we're at it, split the assertions into two so that we can tell which
value had the bad alignment.

Fixes: 2a6ca4baed62 ("xfs: make sure the rt allocator doesn't run off the end")
Signed-off-by: Darrick J. Wong <djwong@kernel.org>
---
 fs/xfs/xfs_rtalloc.c |   24 +++++++++++++++++++-----
 1 file changed, 19 insertions(+), 5 deletions(-)


diff --git a/fs/xfs/xfs_rtalloc.c b/fs/xfs/xfs_rtalloc.c
index 5429a019159a6..309ed109d80fc 100644
--- a/fs/xfs/xfs_rtalloc.c
+++ b/fs/xfs/xfs_rtalloc.c
@@ -252,8 +252,13 @@ xfs_rtallocate_extent_block(
 		end = XFS_BLOCKTOBIT(mp, bbno + 1) - 1;
 	     i <= end;
 	     i++) {
-		/* Make sure we don't scan off the end of the rt volume. */
+		/*
+		 * Make sure we don't run off the end of the rt volume.  Be
+		 * careful that adjusting maxlen downwards doesn't cause us to
+		 * fail the alignment checks.
+		 */
 		maxlen = min(mp->m_sb.sb_rextents, i + maxlen) - i;
+		maxlen -= maxlen % prod;
 
 		/*
 		 * See if there's a free extent of maxlen starting at i.
@@ -360,7 +365,8 @@ xfs_rtallocate_extent_exact(
 	int		isfree;		/* extent is free */
 	xfs_rtblock_t	next;		/* next block to try (dummy) */
 
-	ASSERT(minlen % prod == 0 && maxlen % prod == 0);
+	ASSERT(minlen % prod == 0);
+	ASSERT(maxlen % prod == 0);
 	/*
 	 * Check if the range in question (for maxlen) is free.
 	 */
@@ -443,7 +449,9 @@ xfs_rtallocate_extent_near(
 	xfs_rtblock_t	n;		/* next block to try */
 	xfs_rtblock_t	r;		/* result block */
 
-	ASSERT(minlen % prod == 0 && maxlen % prod == 0);
+	ASSERT(minlen % prod == 0);
+	ASSERT(maxlen % prod == 0);
+
 	/*
 	 * If the block number given is off the end, silently set it to
 	 * the last block.
@@ -451,8 +459,13 @@ xfs_rtallocate_extent_near(
 	if (bno >= mp->m_sb.sb_rextents)
 		bno = mp->m_sb.sb_rextents - 1;
 
-	/* Make sure we don't run off the end of the rt volume. */
+	/*
+	 * Make sure we don't run off the end of the rt volume.  Be careful
+	 * that adjusting maxlen downwards doesn't cause us to fail the
+	 * alignment checks.
+	 */
 	maxlen = min(mp->m_sb.sb_rextents, bno + maxlen) - bno;
+	maxlen -= maxlen % prod;
 	if (maxlen < minlen) {
 		*rtblock = NULLRTBLOCK;
 		return 0;
@@ -643,7 +656,8 @@ xfs_rtallocate_extent_size(
 	xfs_rtblock_t	r;		/* result block number */
 	xfs_suminfo_t	sum;		/* summary information for extents */
 
-	ASSERT(minlen % prod == 0 && maxlen % prod == 0);
+	ASSERT(minlen % prod == 0);
+	ASSERT(maxlen % prod == 0);
 	ASSERT(maxlen != 0);
 
 	/*


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

* [PATCH 2/7] xfs: move the xfs_rtbitmap.c declarations to xfs_rtbitmap.h
  2023-10-11 18:01 ` [PATCHSET RFC v1.0 0/7] xfs: clean up realtime type usage Darrick J. Wong
  2023-10-11 18:02   ` [PATCH 1/7] xfs: make sure maxlen is still congruent with prod when rounding down Darrick J. Wong
@ 2023-10-11 18:03   ` Darrick J. Wong
  2023-10-12  6:33     ` Christoph Hellwig
  2023-10-11 18:03   ` [PATCH 3/7] xfs: convert xfs_extlen_t to xfs_rtxlen_t in the rt allocator Darrick J. Wong
                     ` (5 subsequent siblings)
  7 siblings, 1 reply; 83+ messages in thread
From: Darrick J. Wong @ 2023-10-11 18:03 UTC (permalink / raw)
  To: djwong; +Cc: linux-xfs, osandov, hch

From: Darrick J. Wong <djwong@kernel.org>

Move all the declarations for functionality in xfs_rtbitmap.c into a
separate xfs_rtbitmap.h header file.

Signed-off-by: Darrick J. Wong <djwong@kernel.org>
---
 fs/xfs/libxfs/xfs_bmap.c     |    2 +
 fs/xfs/libxfs/xfs_rtbitmap.c |    1 +
 fs/xfs/libxfs/xfs_rtbitmap.h |   82 ++++++++++++++++++++++++++++++++++++++++++
 fs/xfs/scrub/fscounters.c    |    2 +
 fs/xfs/scrub/rtbitmap.c      |    2 +
 fs/xfs/scrub/rtsummary.c     |    2 +
 fs/xfs/xfs_fsmap.c           |    2 +
 fs/xfs/xfs_rtalloc.c         |    1 +
 fs/xfs/xfs_rtalloc.h         |   73 -------------------------------------
 9 files changed, 89 insertions(+), 78 deletions(-)
 create mode 100644 fs/xfs/libxfs/xfs_rtbitmap.h


diff --git a/fs/xfs/libxfs/xfs_bmap.c b/fs/xfs/libxfs/xfs_bmap.c
index 7fc0c40bcba65..6aa7fd05ee30b 100644
--- a/fs/xfs/libxfs/xfs_bmap.c
+++ b/fs/xfs/libxfs/xfs_bmap.c
@@ -21,7 +21,7 @@
 #include "xfs_bmap.h"
 #include "xfs_bmap_util.h"
 #include "xfs_bmap_btree.h"
-#include "xfs_rtalloc.h"
+#include "xfs_rtbitmap.h"
 #include "xfs_errortag.h"
 #include "xfs_error.h"
 #include "xfs_quota.h"
diff --git a/fs/xfs/libxfs/xfs_rtbitmap.c b/fs/xfs/libxfs/xfs_rtbitmap.c
index c0bd7c44a6b88..196cad3ef85c9 100644
--- a/fs/xfs/libxfs/xfs_rtbitmap.c
+++ b/fs/xfs/libxfs/xfs_rtbitmap.c
@@ -17,6 +17,7 @@
 #include "xfs_rtalloc.h"
 #include "xfs_error.h"
 #include "xfs_health.h"
+#include "xfs_rtbitmap.h"
 
 /*
  * Realtime allocator bitmap functions shared with userspace.
diff --git a/fs/xfs/libxfs/xfs_rtbitmap.h b/fs/xfs/libxfs/xfs_rtbitmap.h
new file mode 100644
index 0000000000000..546dea34bb37c
--- /dev/null
+++ b/fs/xfs/libxfs/xfs_rtbitmap.h
@@ -0,0 +1,82 @@
+// SPDX-License-Identifier: GPL-2.0
+/*
+ * Copyright (c) 2000-2003,2005 Silicon Graphics, Inc.
+ * All Rights Reserved.
+ */
+#ifndef __XFS_RTBITMAP_H__
+#define	__XFS_RTBITMAP_H__
+
+/*
+ * XXX: Most of the realtime allocation functions deal in units of realtime
+ * extents, not realtime blocks.  This looks funny when paired with the type
+ * name and screams for a larger cleanup.
+ */
+struct xfs_rtalloc_rec {
+	xfs_rtblock_t		ar_startext;
+	xfs_rtblock_t		ar_extcount;
+};
+
+typedef int (*xfs_rtalloc_query_range_fn)(
+	struct xfs_mount		*mp,
+	struct xfs_trans		*tp,
+	const struct xfs_rtalloc_rec	*rec,
+	void				*priv);
+
+#ifdef CONFIG_XFS_RT
+int xfs_rtbuf_get(struct xfs_mount *mp, struct xfs_trans *tp,
+		  xfs_rtblock_t block, int issum, struct xfs_buf **bpp);
+int xfs_rtcheck_range(struct xfs_mount *mp, struct xfs_trans *tp,
+		      xfs_rtblock_t start, xfs_extlen_t len, int val,
+		      xfs_rtblock_t *new, int *stat);
+int xfs_rtfind_back(struct xfs_mount *mp, struct xfs_trans *tp,
+		    xfs_rtblock_t start, xfs_rtblock_t limit,
+		    xfs_rtblock_t *rtblock);
+int xfs_rtfind_forw(struct xfs_mount *mp, struct xfs_trans *tp,
+		    xfs_rtblock_t start, xfs_rtblock_t limit,
+		    xfs_rtblock_t *rtblock);
+int xfs_rtmodify_range(struct xfs_mount *mp, struct xfs_trans *tp,
+		       xfs_rtblock_t start, xfs_extlen_t len, int val);
+int xfs_rtmodify_summary_int(struct xfs_mount *mp, struct xfs_trans *tp,
+			     int log, xfs_rtblock_t bbno, int delta,
+			     struct xfs_buf **rbpp, xfs_fsblock_t *rsb,
+			     xfs_suminfo_t *sum);
+int xfs_rtmodify_summary(struct xfs_mount *mp, struct xfs_trans *tp, int log,
+			 xfs_rtblock_t bbno, int delta, struct xfs_buf **rbpp,
+			 xfs_fsblock_t *rsb);
+int xfs_rtfree_range(struct xfs_mount *mp, struct xfs_trans *tp,
+		     xfs_rtblock_t start, xfs_extlen_t len,
+		     struct xfs_buf **rbpp, xfs_fsblock_t *rsb);
+int xfs_rtalloc_query_range(struct xfs_mount *mp, struct xfs_trans *tp,
+		const struct xfs_rtalloc_rec *low_rec,
+		const struct xfs_rtalloc_rec *high_rec,
+		xfs_rtalloc_query_range_fn fn, void *priv);
+int xfs_rtalloc_query_all(struct xfs_mount *mp, struct xfs_trans *tp,
+			  xfs_rtalloc_query_range_fn fn,
+			  void *priv);
+bool xfs_verify_rtbno(struct xfs_mount *mp, xfs_rtblock_t rtbno);
+int xfs_rtalloc_extent_is_free(struct xfs_mount *mp, struct xfs_trans *tp,
+			       xfs_rtblock_t start, xfs_extlen_t len,
+			       bool *is_free);
+/*
+ * Free an extent in the realtime subvolume.  Length is expressed in
+ * realtime extents, as is the block number.
+ */
+int					/* error */
+xfs_rtfree_extent(
+	struct xfs_trans	*tp,	/* transaction pointer */
+	xfs_rtblock_t		bno,	/* starting block number to free */
+	xfs_extlen_t		len);	/* length of extent freed */
+
+/* Same as above, but in units of rt blocks. */
+int xfs_rtfree_blocks(struct xfs_trans *tp, xfs_fsblock_t rtbno,
+		xfs_filblks_t rtlen);
+#else /* CONFIG_XFS_RT */
+# define xfs_rtfree_extent(t,b,l)			(-ENOSYS)
+# define xfs_rtfree_blocks(t,rb,rl)			(-ENOSYS)
+# define xfs_rtalloc_query_range(m,t,l,h,f,p)		(-ENOSYS)
+# define xfs_rtalloc_query_all(m,t,f,p)			(-ENOSYS)
+# define xfs_rtbuf_get(m,t,b,i,p)			(-ENOSYS)
+# define xfs_rtalloc_extent_is_free(m,t,s,l,i)		(-ENOSYS)
+#endif /* CONFIG_XFS_RT */
+
+#endif /* __XFS_RTBITMAP_H__ */
diff --git a/fs/xfs/scrub/fscounters.c b/fs/xfs/scrub/fscounters.c
index 70b7e94c426ca..d310737c88236 100644
--- a/fs/xfs/scrub/fscounters.c
+++ b/fs/xfs/scrub/fscounters.c
@@ -16,7 +16,7 @@
 #include "xfs_health.h"
 #include "xfs_btree.h"
 #include "xfs_ag.h"
-#include "xfs_rtalloc.h"
+#include "xfs_rtbitmap.h"
 #include "xfs_inode.h"
 #include "xfs_icache.h"
 #include "scrub/scrub.h"
diff --git a/fs/xfs/scrub/rtbitmap.c b/fs/xfs/scrub/rtbitmap.c
index 19808f1f5872d..5561de4278162 100644
--- a/fs/xfs/scrub/rtbitmap.c
+++ b/fs/xfs/scrub/rtbitmap.c
@@ -11,7 +11,7 @@
 #include "xfs_mount.h"
 #include "xfs_log_format.h"
 #include "xfs_trans.h"
-#include "xfs_rtalloc.h"
+#include "xfs_rtbitmap.h"
 #include "xfs_inode.h"
 #include "xfs_bmap.h"
 #include "scrub/scrub.h"
diff --git a/fs/xfs/scrub/rtsummary.c b/fs/xfs/scrub/rtsummary.c
index acc1f1153c079..ccf07a63da70e 100644
--- a/fs/xfs/scrub/rtsummary.c
+++ b/fs/xfs/scrub/rtsummary.c
@@ -13,7 +13,7 @@
 #include "xfs_inode.h"
 #include "xfs_log_format.h"
 #include "xfs_trans.h"
-#include "xfs_rtalloc.h"
+#include "xfs_rtbitmap.h"
 #include "xfs_bit.h"
 #include "xfs_bmap.h"
 #include "scrub/scrub.h"
diff --git a/fs/xfs/xfs_fsmap.c b/fs/xfs/xfs_fsmap.c
index 736e5545f5840..8982c5d6cbd06 100644
--- a/fs/xfs/xfs_fsmap.c
+++ b/fs/xfs/xfs_fsmap.c
@@ -23,7 +23,7 @@
 #include "xfs_refcount.h"
 #include "xfs_refcount_btree.h"
 #include "xfs_alloc_btree.h"
-#include "xfs_rtalloc.h"
+#include "xfs_rtbitmap.h"
 #include "xfs_ag.h"
 
 /* Convert an xfs_fsmap to an fsmap. */
diff --git a/fs/xfs/xfs_rtalloc.c b/fs/xfs/xfs_rtalloc.c
index 309ed109d80fc..89b6e70165ece 100644
--- a/fs/xfs/xfs_rtalloc.c
+++ b/fs/xfs/xfs_rtalloc.c
@@ -24,6 +24,7 @@
 #include "xfs_trace.h"
 #include "xfs_da_format.h"
 #include "xfs_imeta.h"
+#include "xfs_rtbitmap.h"
 
 /*
  * Read and return the summary information for a given extent size,
diff --git a/fs/xfs/xfs_rtalloc.h b/fs/xfs/xfs_rtalloc.h
index e53bc52d81fd6..f14da84206d98 100644
--- a/fs/xfs/xfs_rtalloc.h
+++ b/fs/xfs/xfs_rtalloc.h
@@ -11,22 +11,6 @@
 struct xfs_mount;
 struct xfs_trans;
 
-/*
- * XXX: Most of the realtime allocation functions deal in units of realtime
- * extents, not realtime blocks.  This looks funny when paired with the type
- * name and screams for a larger cleanup.
- */
-struct xfs_rtalloc_rec {
-	xfs_rtblock_t		ar_startext;
-	xfs_rtblock_t		ar_extcount;
-};
-
-typedef int (*xfs_rtalloc_query_range_fn)(
-	struct xfs_mount		*mp,
-	struct xfs_trans		*tp,
-	const struct xfs_rtalloc_rec	*rec,
-	void				*priv);
-
 #ifdef CONFIG_XFS_RT
 /*
  * Function prototypes for exported functions.
@@ -48,19 +32,6 @@ xfs_rtallocate_extent(
 	xfs_extlen_t		prod,	/* extent product factor */
 	xfs_rtblock_t		*rtblock); /* out: start block allocated */
 
-/*
- * Free an extent in the realtime subvolume.  Length is expressed in
- * realtime extents, as is the block number.
- */
-int					/* error */
-xfs_rtfree_extent(
-	struct xfs_trans	*tp,	/* transaction pointer */
-	xfs_rtblock_t		bno,	/* starting block number to free */
-	xfs_extlen_t		len);	/* length of extent freed */
-
-/* Same as above, but in units of rt blocks. */
-int xfs_rtfree_blocks(struct xfs_trans *tp, xfs_fsblock_t rtbno,
-		xfs_filblks_t rtlen);
 
 /*
  * Initialize realtime fields in the mount structure.
@@ -102,57 +73,13 @@ xfs_growfs_rt(
 	struct xfs_mount	*mp,	/* file system mount structure */
 	xfs_growfs_rt_t		*in);	/* user supplied growfs struct */
 
-/*
- * From xfs_rtbitmap.c
- */
-int xfs_rtbuf_get(struct xfs_mount *mp, struct xfs_trans *tp,
-		  xfs_rtblock_t block, int issum, struct xfs_buf **bpp);
-int xfs_rtcheck_range(struct xfs_mount *mp, struct xfs_trans *tp,
-		      xfs_rtblock_t start, xfs_extlen_t len, int val,
-		      xfs_rtblock_t *new, int *stat);
-int xfs_rtfind_back(struct xfs_mount *mp, struct xfs_trans *tp,
-		    xfs_rtblock_t start, xfs_rtblock_t limit,
-		    xfs_rtblock_t *rtblock);
-int xfs_rtfind_forw(struct xfs_mount *mp, struct xfs_trans *tp,
-		    xfs_rtblock_t start, xfs_rtblock_t limit,
-		    xfs_rtblock_t *rtblock);
-int xfs_rtmodify_range(struct xfs_mount *mp, struct xfs_trans *tp,
-		       xfs_rtblock_t start, xfs_extlen_t len, int val);
-int xfs_rtmodify_summary_int(struct xfs_mount *mp, struct xfs_trans *tp,
-			     int log, xfs_rtblock_t bbno, int delta,
-			     struct xfs_buf **rbpp, xfs_fsblock_t *rsb,
-			     xfs_suminfo_t *sum);
-int xfs_rtmodify_summary(struct xfs_mount *mp, struct xfs_trans *tp, int log,
-			 xfs_rtblock_t bbno, int delta, struct xfs_buf **rbpp,
-			 xfs_fsblock_t *rsb);
-int xfs_rtfree_range(struct xfs_mount *mp, struct xfs_trans *tp,
-		     xfs_rtblock_t start, xfs_extlen_t len,
-		     struct xfs_buf **rbpp, xfs_fsblock_t *rsb);
-int xfs_rtalloc_query_range(struct xfs_mount *mp, struct xfs_trans *tp,
-		const struct xfs_rtalloc_rec *low_rec,
-		const struct xfs_rtalloc_rec *high_rec,
-		xfs_rtalloc_query_range_fn fn, void *priv);
-int xfs_rtalloc_query_all(struct xfs_mount *mp, struct xfs_trans *tp,
-			  xfs_rtalloc_query_range_fn fn,
-			  void *priv);
-bool xfs_verify_rtbno(struct xfs_mount *mp, xfs_rtblock_t rtbno);
-int xfs_rtalloc_extent_is_free(struct xfs_mount *mp, struct xfs_trans *tp,
-			       xfs_rtblock_t start, xfs_extlen_t len,
-			       bool *is_free);
 int xfs_rtalloc_reinit_frextents(struct xfs_mount *mp);
 int xfs_rtfile_convert_unwritten(struct xfs_inode *ip, loff_t pos,
 		uint64_t len);
 #else
 # define xfs_rtallocate_extent(t,b,min,max,l,f,p,rb)	(-ENOSYS)
-# define xfs_rtfree_extent(t,b,l)			(-ENOSYS)
-# define xfs_rtfree_blocks(t,rb,rl)			(-ENOSYS)
 # define xfs_rtpick_extent(m,t,l,rb)			(-ENOSYS)
 # define xfs_growfs_rt(mp,in)				(-ENOSYS)
-# define xfs_rtalloc_query_range(m,t,l,h,f,p)		(-ENOSYS)
-# define xfs_rtalloc_query_all(m,t,f,p)			(-ENOSYS)
-# define xfs_rtbuf_get(m,t,b,i,p)			(-ENOSYS)
-# define xfs_verify_rtbno(m, r)				(false)
-# define xfs_rtalloc_extent_is_free(m,t,s,l,i)		(-ENOSYS)
 # define xfs_rtalloc_reinit_frextents(m)		(0)
 static inline int		/* error */
 xfs_rtmount_init(


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

* [PATCH 3/7] xfs: convert xfs_extlen_t to xfs_rtxlen_t in the rt allocator
  2023-10-11 18:01 ` [PATCHSET RFC v1.0 0/7] xfs: clean up realtime type usage Darrick J. Wong
  2023-10-11 18:02   ` [PATCH 1/7] xfs: make sure maxlen is still congruent with prod when rounding down Darrick J. Wong
  2023-10-11 18:03   ` [PATCH 2/7] xfs: move the xfs_rtbitmap.c declarations to xfs_rtbitmap.h Darrick J. Wong
@ 2023-10-11 18:03   ` Darrick J. Wong
  2023-10-12  5:00     ` Christoph Hellwig
  2023-10-11 18:03   ` [PATCH 4/7] xfs: convert rt bitmap/summary block numbers to xfs_fileoff_t Darrick J. Wong
                     ` (4 subsequent siblings)
  7 siblings, 1 reply; 83+ messages in thread
From: Darrick J. Wong @ 2023-10-11 18:03 UTC (permalink / raw)
  To: djwong; +Cc: linux-xfs, osandov, hch

From: Darrick J. Wong <djwong@kernel.org>

In most of the filesystem, we use xfs_extlen_t to store the length of a
file (or AG) space mapping in units of fs blocks.  Unfortunately, the
realtime allocator also uses it to store the length of a rt space
mapping in units of rt extents.  This is confusing, since one rt extent
can consist of many fs blocks.

Separate the two by introducing a new type (xfs_rtxlen_t) to store the
length of a space mapping (in units of realtime extents) that would be
found in a file.

Signed-off-by: Darrick J. Wong <djwong@kernel.org>
---
 fs/xfs/libxfs/xfs_rtbitmap.c |   12 +++++-----
 fs/xfs/libxfs/xfs_rtbitmap.h |   11 ++++-----
 fs/xfs/libxfs/xfs_types.h    |    1 +
 fs/xfs/scrub/rtbitmap.c      |    2 +-
 fs/xfs/xfs_bmap_util.c       |    6 +++--
 fs/xfs/xfs_rtalloc.c         |   50 +++++++++++++++++++++---------------------
 fs/xfs/xfs_rtalloc.h         |   10 ++++----
 7 files changed, 46 insertions(+), 46 deletions(-)


diff --git a/fs/xfs/libxfs/xfs_rtbitmap.c b/fs/xfs/libxfs/xfs_rtbitmap.c
index 196cad3ef85c9..b90d2f2d5bdec 100644
--- a/fs/xfs/libxfs/xfs_rtbitmap.c
+++ b/fs/xfs/libxfs/xfs_rtbitmap.c
@@ -541,7 +541,7 @@ xfs_rtmodify_range(
 	xfs_mount_t	*mp,		/* file system mount point */
 	xfs_trans_t	*tp,		/* transaction pointer */
 	xfs_rtblock_t	start,		/* starting block to modify */
-	xfs_extlen_t	len,		/* length of extent to modify */
+	xfs_rtxlen_t	len,		/* length of extent to modify */
 	int		val)		/* 1 for free, 0 for allocated */
 {
 	xfs_rtword_t	*b;		/* current word in buffer */
@@ -697,7 +697,7 @@ xfs_rtfree_range(
 	xfs_mount_t	*mp,		/* file system mount point */
 	xfs_trans_t	*tp,		/* transaction pointer */
 	xfs_rtblock_t	start,		/* starting block to free */
-	xfs_extlen_t	len,		/* length to free */
+	xfs_rtxlen_t	len,		/* length to free */
 	struct xfs_buf	**rbpp,		/* in/out: summary block buffer */
 	xfs_fsblock_t	*rsb)		/* in/out: summary block number */
 {
@@ -773,7 +773,7 @@ xfs_rtcheck_range(
 	xfs_mount_t	*mp,		/* file system mount point */
 	xfs_trans_t	*tp,		/* transaction pointer */
 	xfs_rtblock_t	start,		/* starting block number of extent */
-	xfs_extlen_t	len,		/* length of extent */
+	xfs_rtxlen_t	len,		/* length of extent */
 	int		val,		/* 1 for free, 0 for allocated */
 	xfs_rtblock_t	*new,		/* out: first block not matching */
 	int		*stat)		/* out: 1 for matches, 0 for not */
@@ -949,7 +949,7 @@ xfs_rtcheck_alloc_range(
 	xfs_mount_t	*mp,		/* file system mount point */
 	xfs_trans_t	*tp,		/* transaction pointer */
 	xfs_rtblock_t	bno,		/* starting block number of extent */
-	xfs_extlen_t	len)		/* length of extent */
+	xfs_rtxlen_t	len)		/* length of extent */
 {
 	xfs_rtblock_t	new;		/* dummy for xfs_rtcheck_range */
 	int		stat;
@@ -972,7 +972,7 @@ int					/* error */
 xfs_rtfree_extent(
 	xfs_trans_t	*tp,		/* transaction pointer */
 	xfs_rtblock_t	bno,		/* starting block number to free */
-	xfs_extlen_t	len)		/* length of extent freed */
+	xfs_rtxlen_t	len)		/* length of extent freed */
 {
 	int		error;		/* error value */
 	xfs_mount_t	*mp;		/* file system mount structure */
@@ -1123,7 +1123,7 @@ xfs_rtalloc_extent_is_free(
 	struct xfs_mount		*mp,
 	struct xfs_trans		*tp,
 	xfs_rtblock_t			start,
-	xfs_extlen_t			len,
+	xfs_rtxlen_t			len,
 	bool				*is_free)
 {
 	xfs_rtblock_t			end;
diff --git a/fs/xfs/libxfs/xfs_rtbitmap.h b/fs/xfs/libxfs/xfs_rtbitmap.h
index 546dea34bb37c..d4449610154a8 100644
--- a/fs/xfs/libxfs/xfs_rtbitmap.h
+++ b/fs/xfs/libxfs/xfs_rtbitmap.h
@@ -26,7 +26,7 @@ typedef int (*xfs_rtalloc_query_range_fn)(
 int xfs_rtbuf_get(struct xfs_mount *mp, struct xfs_trans *tp,
 		  xfs_rtblock_t block, int issum, struct xfs_buf **bpp);
 int xfs_rtcheck_range(struct xfs_mount *mp, struct xfs_trans *tp,
-		      xfs_rtblock_t start, xfs_extlen_t len, int val,
+		      xfs_rtblock_t start, xfs_rtxlen_t len, int val,
 		      xfs_rtblock_t *new, int *stat);
 int xfs_rtfind_back(struct xfs_mount *mp, struct xfs_trans *tp,
 		    xfs_rtblock_t start, xfs_rtblock_t limit,
@@ -35,7 +35,7 @@ int xfs_rtfind_forw(struct xfs_mount *mp, struct xfs_trans *tp,
 		    xfs_rtblock_t start, xfs_rtblock_t limit,
 		    xfs_rtblock_t *rtblock);
 int xfs_rtmodify_range(struct xfs_mount *mp, struct xfs_trans *tp,
-		       xfs_rtblock_t start, xfs_extlen_t len, int val);
+		       xfs_rtblock_t start, xfs_rtxlen_t len, int val);
 int xfs_rtmodify_summary_int(struct xfs_mount *mp, struct xfs_trans *tp,
 			     int log, xfs_rtblock_t bbno, int delta,
 			     struct xfs_buf **rbpp, xfs_fsblock_t *rsb,
@@ -44,7 +44,7 @@ int xfs_rtmodify_summary(struct xfs_mount *mp, struct xfs_trans *tp, int log,
 			 xfs_rtblock_t bbno, int delta, struct xfs_buf **rbpp,
 			 xfs_fsblock_t *rsb);
 int xfs_rtfree_range(struct xfs_mount *mp, struct xfs_trans *tp,
-		     xfs_rtblock_t start, xfs_extlen_t len,
+		     xfs_rtblock_t start, xfs_rtxlen_t len,
 		     struct xfs_buf **rbpp, xfs_fsblock_t *rsb);
 int xfs_rtalloc_query_range(struct xfs_mount *mp, struct xfs_trans *tp,
 		const struct xfs_rtalloc_rec *low_rec,
@@ -53,9 +53,8 @@ int xfs_rtalloc_query_range(struct xfs_mount *mp, struct xfs_trans *tp,
 int xfs_rtalloc_query_all(struct xfs_mount *mp, struct xfs_trans *tp,
 			  xfs_rtalloc_query_range_fn fn,
 			  void *priv);
-bool xfs_verify_rtbno(struct xfs_mount *mp, xfs_rtblock_t rtbno);
 int xfs_rtalloc_extent_is_free(struct xfs_mount *mp, struct xfs_trans *tp,
-			       xfs_rtblock_t start, xfs_extlen_t len,
+			       xfs_rtblock_t start, xfs_rtxlen_t len,
 			       bool *is_free);
 /*
  * Free an extent in the realtime subvolume.  Length is expressed in
@@ -65,7 +64,7 @@ int					/* error */
 xfs_rtfree_extent(
 	struct xfs_trans	*tp,	/* transaction pointer */
 	xfs_rtblock_t		bno,	/* starting block number to free */
-	xfs_extlen_t		len);	/* length of extent freed */
+	xfs_rtxlen_t		len);	/* length of extent freed */
 
 /* Same as above, but in units of rt blocks. */
 int xfs_rtfree_blocks(struct xfs_trans *tp, xfs_fsblock_t rtbno,
diff --git a/fs/xfs/libxfs/xfs_types.h b/fs/xfs/libxfs/xfs_types.h
index 9a4019f23dd51..0856997f84d6d 100644
--- a/fs/xfs/libxfs/xfs_types.h
+++ b/fs/xfs/libxfs/xfs_types.h
@@ -11,6 +11,7 @@ typedef uint32_t	prid_t;		/* project ID */
 typedef uint32_t	xfs_agblock_t;	/* blockno in alloc. group */
 typedef uint32_t	xfs_agino_t;	/* inode # within allocation grp */
 typedef uint32_t	xfs_extlen_t;	/* extent length in blocks */
+typedef uint32_t	xfs_rtxlen_t;	/* file extent length in rtextents */
 typedef uint32_t	xfs_agnumber_t;	/* allocation group number */
 typedef uint64_t	xfs_extnum_t;	/* # of extents in a file */
 typedef uint32_t	xfs_aextnum_t;	/* # extents in an attribute fork */
diff --git a/fs/xfs/scrub/rtbitmap.c b/fs/xfs/scrub/rtbitmap.c
index 5561de4278162..b4f132176aabc 100644
--- a/fs/xfs/scrub/rtbitmap.c
+++ b/fs/xfs/scrub/rtbitmap.c
@@ -145,7 +145,7 @@ xchk_xref_is_used_rt_space(
 {
 	xfs_rtblock_t		startext;
 	xfs_rtblock_t		endext;
-	xfs_rtblock_t		extcount;
+	xfs_rtxlen_t		extcount;
 	bool			is_free;
 	int			error;
 
diff --git a/fs/xfs/xfs_bmap_util.c b/fs/xfs/xfs_bmap_util.c
index 9782c950f252e..f2efa508200b3 100644
--- a/fs/xfs/xfs_bmap_util.c
+++ b/fs/xfs/xfs_bmap_util.c
@@ -77,13 +77,13 @@ xfs_bmap_rtalloc(
 	struct xfs_mount	*mp = ap->ip->i_mount;
 	xfs_fileoff_t		orig_offset = ap->offset;
 	xfs_rtblock_t		rtb;
-	xfs_extlen_t		prod = 0;  /* product factor for allocators */
+	xfs_rtxlen_t		prod = 0;  /* product factor for allocators */
 	xfs_extlen_t		mod = 0;   /* product factor for allocators */
-	xfs_extlen_t		ralen = 0; /* realtime allocation length */
+	xfs_rtxlen_t		ralen = 0; /* realtime allocation length */
 	xfs_extlen_t		align;     /* minimum allocation alignment */
 	xfs_extlen_t		orig_length = ap->length;
 	xfs_extlen_t		minlen = mp->m_sb.sb_rextsize;
-	xfs_extlen_t		raminlen;
+	xfs_rtxlen_t		raminlen;
 	bool			rtlocked = false;
 	bool			ignore_locality = false;
 	int			error;
diff --git a/fs/xfs/xfs_rtalloc.c b/fs/xfs/xfs_rtalloc.c
index 89b6e70165ece..3ae0070d14d8f 100644
--- a/fs/xfs/xfs_rtalloc.c
+++ b/fs/xfs/xfs_rtalloc.c
@@ -149,7 +149,7 @@ xfs_rtallocate_range(
 	xfs_mount_t	*mp,		/* file system mount point */
 	xfs_trans_t	*tp,		/* transaction pointer */
 	xfs_rtblock_t	start,		/* start block to allocate */
-	xfs_extlen_t	len,		/* length to allocate */
+	xfs_rtxlen_t	len,		/* length to allocate */
 	struct xfs_buf	**rbpp,		/* in/out: summary block buffer */
 	xfs_fsblock_t	*rsb)		/* in/out: summary block number */
 {
@@ -228,13 +228,13 @@ xfs_rtallocate_extent_block(
 	xfs_mount_t	*mp,		/* file system mount point */
 	xfs_trans_t	*tp,		/* transaction pointer */
 	xfs_rtblock_t	bbno,		/* bitmap block number */
-	xfs_extlen_t	minlen,		/* minimum length to allocate */
-	xfs_extlen_t	maxlen,		/* maximum length to allocate */
-	xfs_extlen_t	*len,		/* out: actual length allocated */
+	xfs_rtxlen_t	minlen,		/* minimum length to allocate */
+	xfs_rtxlen_t	maxlen,		/* maximum length to allocate */
+	xfs_rtxlen_t	*len,		/* out: actual length allocated */
 	xfs_rtblock_t	*nextp,		/* out: next block to try */
 	struct xfs_buf	**rbpp,		/* in/out: summary block buffer */
 	xfs_fsblock_t	*rsb,		/* in/out: summary block number */
-	xfs_extlen_t	prod,		/* extent product factor */
+	xfs_rtxlen_t	prod,		/* extent product factor */
 	xfs_rtblock_t	*rtblock)	/* out: start block allocated */
 {
 	xfs_rtblock_t	besti;		/* best rtblock found so far */
@@ -312,7 +312,7 @@ xfs_rtallocate_extent_block(
 	 * Searched the whole thing & didn't find a maxlen free extent.
 	 */
 	if (minlen < maxlen && besti != -1) {
-		xfs_extlen_t	p;	/* amount to trim length by */
+		xfs_rtxlen_t	p;	/* amount to trim length by */
 
 		/*
 		 * If size should be a multiple of prod, make that so.
@@ -353,16 +353,16 @@ xfs_rtallocate_extent_exact(
 	xfs_mount_t	*mp,		/* file system mount point */
 	xfs_trans_t	*tp,		/* transaction pointer */
 	xfs_rtblock_t	bno,		/* starting block number to allocate */
-	xfs_extlen_t	minlen,		/* minimum length to allocate */
-	xfs_extlen_t	maxlen,		/* maximum length to allocate */
-	xfs_extlen_t	*len,		/* out: actual length allocated */
+	xfs_rtxlen_t	minlen,		/* minimum length to allocate */
+	xfs_rtxlen_t	maxlen,		/* maximum length to allocate */
+	xfs_rtxlen_t	*len,		/* out: actual length allocated */
 	struct xfs_buf	**rbpp,		/* in/out: summary block buffer */
 	xfs_fsblock_t	*rsb,		/* in/out: summary block number */
-	xfs_extlen_t	prod,		/* extent product factor */
+	xfs_rtxlen_t	prod,		/* extent product factor */
 	xfs_rtblock_t	*rtblock)	/* out: start block allocated */
 {
 	int		error;		/* error value */
-	xfs_extlen_t	i;		/* extent length trimmed due to prod */
+	xfs_rtxlen_t	i;		/* extent length trimmed due to prod */
 	int		isfree;		/* extent is free */
 	xfs_rtblock_t	next;		/* next block to try (dummy) */
 
@@ -433,12 +433,12 @@ xfs_rtallocate_extent_near(
 	xfs_mount_t	*mp,		/* file system mount point */
 	xfs_trans_t	*tp,		/* transaction pointer */
 	xfs_rtblock_t	bno,		/* starting block number to allocate */
-	xfs_extlen_t	minlen,		/* minimum length to allocate */
-	xfs_extlen_t	maxlen,		/* maximum length to allocate */
-	xfs_extlen_t	*len,		/* out: actual length allocated */
+	xfs_rtxlen_t	minlen,		/* minimum length to allocate */
+	xfs_rtxlen_t	maxlen,		/* maximum length to allocate */
+	xfs_rtxlen_t	*len,		/* out: actual length allocated */
 	struct xfs_buf	**rbpp,		/* in/out: summary block buffer */
 	xfs_fsblock_t	*rsb,		/* in/out: summary block number */
-	xfs_extlen_t	prod,		/* extent product factor */
+	xfs_rtxlen_t	prod,		/* extent product factor */
 	xfs_rtblock_t	*rtblock)	/* out: start block allocated */
 {
 	int		any;		/* any useful extents from summary */
@@ -642,12 +642,12 @@ STATIC int				/* error */
 xfs_rtallocate_extent_size(
 	xfs_mount_t	*mp,		/* file system mount point */
 	xfs_trans_t	*tp,		/* transaction pointer */
-	xfs_extlen_t	minlen,		/* minimum length to allocate */
-	xfs_extlen_t	maxlen,		/* maximum length to allocate */
-	xfs_extlen_t	*len,		/* out: actual length allocated */
+	xfs_rtxlen_t	minlen,		/* minimum length to allocate */
+	xfs_rtxlen_t	maxlen,		/* maximum length to allocate */
+	xfs_rtxlen_t	*len,		/* out: actual length allocated */
 	struct xfs_buf	**rbpp,		/* in/out: summary block buffer */
 	xfs_fsblock_t	*rsb,		/* in/out: summary block number */
-	xfs_extlen_t	prod,		/* extent product factor */
+	xfs_rtxlen_t	prod,		/* extent product factor */
 	xfs_rtblock_t	*rtblock)	/* out: start block allocated */
 {
 	int		error;		/* error value */
@@ -1195,11 +1195,11 @@ int					/* error */
 xfs_rtallocate_extent(
 	xfs_trans_t	*tp,		/* transaction pointer */
 	xfs_rtblock_t	bno,		/* starting block number to allocate */
-	xfs_extlen_t	minlen,		/* minimum length to allocate */
-	xfs_extlen_t	maxlen,		/* maximum length to allocate */
-	xfs_extlen_t	*len,		/* out: actual length allocated */
+	xfs_rtxlen_t	minlen,		/* minimum length to allocate */
+	xfs_rtxlen_t	maxlen,		/* maximum length to allocate */
+	xfs_rtxlen_t	*len,		/* out: actual length allocated */
 	int		wasdel,		/* was a delayed allocation extent */
-	xfs_extlen_t	prod,		/* extent product factor */
+	xfs_rtxlen_t	prod,		/* extent product factor */
 	xfs_rtblock_t	*rtblock)	/* out: start block allocated */
 {
 	xfs_mount_t	*mp = tp->t_mountp;
@@ -1215,7 +1215,7 @@ xfs_rtallocate_extent(
 	 * If prod is set then figure out what to do to minlen and maxlen.
 	 */
 	if (prod > 1) {
-		xfs_extlen_t	i;
+		xfs_rtxlen_t	i;
 
 		if ((i = maxlen % prod))
 			maxlen -= i;
@@ -1450,7 +1450,7 @@ int					/* error */
 xfs_rtpick_extent(
 	xfs_mount_t	*mp,		/* file system mount point */
 	xfs_trans_t	*tp,		/* transaction pointer */
-	xfs_extlen_t	len,		/* allocation length (rtextents) */
+	xfs_rtxlen_t	len,		/* allocation length (rtextents) */
 	xfs_rtblock_t	*pick)		/* result rt extent */
 {
 	xfs_rtblock_t	b;		/* result block */
diff --git a/fs/xfs/xfs_rtalloc.h b/fs/xfs/xfs_rtalloc.h
index f14da84206d98..ec03cc566bec8 100644
--- a/fs/xfs/xfs_rtalloc.h
+++ b/fs/xfs/xfs_rtalloc.h
@@ -25,11 +25,11 @@ int					/* error */
 xfs_rtallocate_extent(
 	struct xfs_trans	*tp,	/* transaction pointer */
 	xfs_rtblock_t		bno,	/* starting block number to allocate */
-	xfs_extlen_t		minlen,	/* minimum length to allocate */
-	xfs_extlen_t		maxlen,	/* maximum length to allocate */
-	xfs_extlen_t		*len,	/* out: actual length allocated */
+	xfs_rtxlen_t		minlen,	/* minimum length to allocate */
+	xfs_rtxlen_t		maxlen,	/* maximum length to allocate */
+	xfs_rtxlen_t		*len,	/* out: actual length allocated */
 	int			wasdel,	/* was a delayed allocation extent */
-	xfs_extlen_t		prod,	/* extent product factor */
+	xfs_rtxlen_t		prod,	/* extent product factor */
 	xfs_rtblock_t		*rtblock); /* out: start block allocated */
 
 
@@ -62,7 +62,7 @@ int					/* error */
 xfs_rtpick_extent(
 	struct xfs_mount	*mp,	/* file system mount point */
 	struct xfs_trans	*tp,	/* transaction pointer */
-	xfs_extlen_t		len,	/* allocation length (rtextents) */
+	xfs_rtxlen_t		len,	/* allocation length (rtextents) */
 	xfs_rtblock_t		*pick);	/* result rt extent */
 
 /*


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

* [PATCH 4/7] xfs: convert rt bitmap/summary block numbers to xfs_fileoff_t
  2023-10-11 18:01 ` [PATCHSET RFC v1.0 0/7] xfs: clean up realtime type usage Darrick J. Wong
                     ` (2 preceding siblings ...)
  2023-10-11 18:03   ` [PATCH 3/7] xfs: convert xfs_extlen_t to xfs_rtxlen_t in the rt allocator Darrick J. Wong
@ 2023-10-11 18:03   ` Darrick J. Wong
  2023-10-12  5:01     ` Christoph Hellwig
  2023-10-11 18:03   ` [PATCH 5/7] xfs: convert rt bitmap extent lengths to xfs_rtbxlen_t Darrick J. Wong
                     ` (3 subsequent siblings)
  7 siblings, 1 reply; 83+ messages in thread
From: Darrick J. Wong @ 2023-10-11 18:03 UTC (permalink / raw)
  To: djwong; +Cc: linux-xfs, osandov, hch

From: Darrick J. Wong <djwong@kernel.org>

We should use xfs_fileoff_t to store the file block offset of any
location within the realtime bitmap or summary files.

Signed-off-by: Darrick J. Wong <djwong@kernel.org>
---
 fs/xfs/libxfs/xfs_rtbitmap.c |   22 +++++++++++-----------
 fs/xfs/libxfs/xfs_rtbitmap.h |   12 ++++++------
 fs/xfs/scrub/rtbitmap.c      |    2 +-
 fs/xfs/xfs_rtalloc.c         |   34 +++++++++++++++++-----------------
 4 files changed, 35 insertions(+), 35 deletions(-)


diff --git a/fs/xfs/libxfs/xfs_rtbitmap.c b/fs/xfs/libxfs/xfs_rtbitmap.c
index b90d2f2d5bdec..50a9d23c00c6d 100644
--- a/fs/xfs/libxfs/xfs_rtbitmap.c
+++ b/fs/xfs/libxfs/xfs_rtbitmap.c
@@ -56,7 +56,7 @@ int
 xfs_rtbuf_get(
 	xfs_mount_t	*mp,		/* file system mount structure */
 	xfs_trans_t	*tp,		/* transaction pointer */
-	xfs_rtblock_t	block,		/* block number in bitmap or summary */
+	xfs_fileoff_t	block,		/* block number in bitmap or summary */
 	int		issum,		/* is summary not bitmap */
 	struct xfs_buf	**bpp)		/* output: buffer for the block */
 {
@@ -108,7 +108,7 @@ xfs_rtfind_back(
 {
 	xfs_rtword_t	*b;		/* current word in buffer */
 	int		bit;		/* bit number in the word */
-	xfs_rtblock_t	block;		/* bitmap block number */
+	xfs_fileoff_t	block;		/* bitmap block number */
 	struct xfs_buf	*bp;		/* buf for the block */
 	xfs_rtword_t	*bufp;		/* starting word in buffer */
 	int		error;		/* error value */
@@ -283,7 +283,7 @@ xfs_rtfind_forw(
 {
 	xfs_rtword_t	*b;		/* current word in buffer */
 	int		bit;		/* bit number in the word */
-	xfs_rtblock_t	block;		/* bitmap block number */
+	xfs_fileoff_t	block;		/* bitmap block number */
 	struct xfs_buf	*bp;		/* buf for the block */
 	xfs_rtword_t	*bufp;		/* starting word in buffer */
 	int		error;		/* error value */
@@ -453,15 +453,15 @@ xfs_rtmodify_summary_int(
 	xfs_mount_t	*mp,		/* file system mount structure */
 	xfs_trans_t	*tp,		/* transaction pointer */
 	int		log,		/* log2 of extent size */
-	xfs_rtblock_t	bbno,		/* bitmap block number */
+	xfs_fileoff_t	bbno,		/* bitmap block number */
 	int		delta,		/* change to make to summary info */
 	struct xfs_buf	**rbpp,		/* in/out: summary block buffer */
-	xfs_fsblock_t	*rsb,		/* in/out: summary block number */
+	xfs_fileoff_t	*rsb,		/* in/out: summary block number */
 	xfs_suminfo_t	*sum)		/* out: summary info for this block */
 {
 	struct xfs_buf	*bp;		/* buffer for the summary block */
 	int		error;		/* error value */
-	xfs_fsblock_t	sb;		/* summary fsblock */
+	xfs_fileoff_t	sb;		/* summary fsblock */
 	int		so;		/* index into the summary file */
 	xfs_suminfo_t	*sp;		/* pointer to returned data */
 
@@ -523,10 +523,10 @@ xfs_rtmodify_summary(
 	xfs_mount_t	*mp,		/* file system mount structure */
 	xfs_trans_t	*tp,		/* transaction pointer */
 	int		log,		/* log2 of extent size */
-	xfs_rtblock_t	bbno,		/* bitmap block number */
+	xfs_fileoff_t	bbno,		/* bitmap block number */
 	int		delta,		/* change to make to summary info */
 	struct xfs_buf	**rbpp,		/* in/out: summary block buffer */
-	xfs_fsblock_t	*rsb)		/* in/out: summary block number */
+	xfs_fileoff_t	*rsb)		/* in/out: summary block number */
 {
 	return xfs_rtmodify_summary_int(mp, tp, log, bbno,
 					delta, rbpp, rsb, NULL);
@@ -546,7 +546,7 @@ xfs_rtmodify_range(
 {
 	xfs_rtword_t	*b;		/* current word in buffer */
 	int		bit;		/* bit number in the word */
-	xfs_rtblock_t	block;		/* bitmap block number */
+	xfs_fileoff_t	block;		/* bitmap block number */
 	struct xfs_buf	*bp;		/* buf for the block */
 	xfs_rtword_t	*bufp;		/* starting word in buffer */
 	int		error;		/* error value */
@@ -699,7 +699,7 @@ xfs_rtfree_range(
 	xfs_rtblock_t	start,		/* starting block to free */
 	xfs_rtxlen_t	len,		/* length to free */
 	struct xfs_buf	**rbpp,		/* in/out: summary block buffer */
-	xfs_fsblock_t	*rsb)		/* in/out: summary block number */
+	xfs_fileoff_t	*rsb)		/* in/out: summary block number */
 {
 	xfs_rtblock_t	end;		/* end of the freed extent */
 	int		error;		/* error value */
@@ -780,7 +780,7 @@ xfs_rtcheck_range(
 {
 	xfs_rtword_t	*b;		/* current word in buffer */
 	int		bit;		/* bit number in the word */
-	xfs_rtblock_t	block;		/* bitmap block number */
+	xfs_fileoff_t	block;		/* bitmap block number */
 	struct xfs_buf	*bp;		/* buf for the block */
 	xfs_rtword_t	*bufp;		/* starting word in buffer */
 	int		error;		/* error value */
diff --git a/fs/xfs/libxfs/xfs_rtbitmap.h b/fs/xfs/libxfs/xfs_rtbitmap.h
index d4449610154a8..e2ea6d31c38b1 100644
--- a/fs/xfs/libxfs/xfs_rtbitmap.h
+++ b/fs/xfs/libxfs/xfs_rtbitmap.h
@@ -24,7 +24,7 @@ typedef int (*xfs_rtalloc_query_range_fn)(
 
 #ifdef CONFIG_XFS_RT
 int xfs_rtbuf_get(struct xfs_mount *mp, struct xfs_trans *tp,
-		  xfs_rtblock_t block, int issum, struct xfs_buf **bpp);
+		  xfs_fileoff_t block, int issum, struct xfs_buf **bpp);
 int xfs_rtcheck_range(struct xfs_mount *mp, struct xfs_trans *tp,
 		      xfs_rtblock_t start, xfs_rtxlen_t len, int val,
 		      xfs_rtblock_t *new, int *stat);
@@ -37,15 +37,15 @@ int xfs_rtfind_forw(struct xfs_mount *mp, struct xfs_trans *tp,
 int xfs_rtmodify_range(struct xfs_mount *mp, struct xfs_trans *tp,
 		       xfs_rtblock_t start, xfs_rtxlen_t len, int val);
 int xfs_rtmodify_summary_int(struct xfs_mount *mp, struct xfs_trans *tp,
-			     int log, xfs_rtblock_t bbno, int delta,
-			     struct xfs_buf **rbpp, xfs_fsblock_t *rsb,
+			     int log, xfs_fileoff_t bbno, int delta,
+			     struct xfs_buf **rbpp, xfs_fileoff_t *rsb,
 			     xfs_suminfo_t *sum);
 int xfs_rtmodify_summary(struct xfs_mount *mp, struct xfs_trans *tp, int log,
-			 xfs_rtblock_t bbno, int delta, struct xfs_buf **rbpp,
-			 xfs_fsblock_t *rsb);
+			 xfs_fileoff_t bbno, int delta, struct xfs_buf **rbpp,
+			 xfs_fileoff_t *rsb);
 int xfs_rtfree_range(struct xfs_mount *mp, struct xfs_trans *tp,
 		     xfs_rtblock_t start, xfs_rtxlen_t len,
-		     struct xfs_buf **rbpp, xfs_fsblock_t *rsb);
+		     struct xfs_buf **rbpp, xfs_fileoff_t *rsb);
 int xfs_rtalloc_query_range(struct xfs_mount *mp, struct xfs_trans *tp,
 		const struct xfs_rtalloc_rec *low_rec,
 		const struct xfs_rtalloc_rec *high_rec,
diff --git a/fs/xfs/scrub/rtbitmap.c b/fs/xfs/scrub/rtbitmap.c
index b4f132176aabc..c32249a1969aa 100644
--- a/fs/xfs/scrub/rtbitmap.c
+++ b/fs/xfs/scrub/rtbitmap.c
@@ -77,7 +77,7 @@ xchk_rtbitmap_check_extents(
 {
 	struct xfs_mount	*mp = sc->mp;
 	struct xfs_bmbt_irec	map;
-	xfs_rtblock_t		off;
+	xfs_fileoff_t		off;
 	int			nmap;
 	int			error = 0;
 
diff --git a/fs/xfs/xfs_rtalloc.c b/fs/xfs/xfs_rtalloc.c
index 3ae0070d14d8f..5eb23cff281d1 100644
--- a/fs/xfs/xfs_rtalloc.c
+++ b/fs/xfs/xfs_rtalloc.c
@@ -37,9 +37,9 @@ xfs_rtget_summary(
 	xfs_mount_t	*mp,		/* file system mount structure */
 	xfs_trans_t	*tp,		/* transaction pointer */
 	int		log,		/* log2 of extent size */
-	xfs_rtblock_t	bbno,		/* bitmap block number */
+	xfs_fileoff_t	bbno,		/* bitmap block number */
 	struct xfs_buf	**rbpp,		/* in/out: summary block buffer */
-	xfs_fsblock_t	*rsb,		/* in/out: summary block number */
+	xfs_fileoff_t	*rsb,		/* in/out: summary block number */
 	xfs_suminfo_t	*sum)		/* out: summary info for this block */
 {
 	return xfs_rtmodify_summary_int(mp, tp, log, bbno, 0, rbpp, rsb, sum);
@@ -55,9 +55,9 @@ xfs_rtany_summary(
 	xfs_trans_t	*tp,		/* transaction pointer */
 	int		low,		/* low log2 extent size */
 	int		high,		/* high log2 extent size */
-	xfs_rtblock_t	bbno,		/* bitmap block number */
+	xfs_fileoff_t	bbno,		/* bitmap block number */
 	struct xfs_buf	**rbpp,		/* in/out: summary block buffer */
-	xfs_fsblock_t	*rsb,		/* in/out: summary block number */
+	xfs_fileoff_t	*rsb,		/* in/out: summary block number */
 	int		*stat)		/* out: any good extents here? */
 {
 	int		error;		/* error value */
@@ -109,12 +109,12 @@ xfs_rtcopy_summary(
 	xfs_mount_t	*nmp,		/* new file system mount point */
 	xfs_trans_t	*tp)		/* transaction pointer */
 {
-	xfs_rtblock_t	bbno;		/* bitmap block number */
+	xfs_fileoff_t	bbno;		/* bitmap block number */
 	struct xfs_buf	*bp;		/* summary buffer */
 	int		error;		/* error return value */
 	int		log;		/* summary level number (log length) */
 	xfs_suminfo_t	sum;		/* summary data */
-	xfs_fsblock_t	sumbno;		/* summary block number */
+	xfs_fileoff_t	sumbno;		/* summary block number */
 
 	bp = NULL;
 	for (log = omp->m_rsumlevels - 1; log >= 0; log--) {
@@ -151,7 +151,7 @@ xfs_rtallocate_range(
 	xfs_rtblock_t	start,		/* start block to allocate */
 	xfs_rtxlen_t	len,		/* length to allocate */
 	struct xfs_buf	**rbpp,		/* in/out: summary block buffer */
-	xfs_fsblock_t	*rsb)		/* in/out: summary block number */
+	xfs_fileoff_t	*rsb)		/* in/out: summary block number */
 {
 	xfs_rtblock_t	end;		/* end of the allocated extent */
 	int		error;		/* error value */
@@ -227,13 +227,13 @@ STATIC int				/* error */
 xfs_rtallocate_extent_block(
 	xfs_mount_t	*mp,		/* file system mount point */
 	xfs_trans_t	*tp,		/* transaction pointer */
-	xfs_rtblock_t	bbno,		/* bitmap block number */
+	xfs_fileoff_t	bbno,		/* bitmap block number */
 	xfs_rtxlen_t	minlen,		/* minimum length to allocate */
 	xfs_rtxlen_t	maxlen,		/* maximum length to allocate */
 	xfs_rtxlen_t	*len,		/* out: actual length allocated */
 	xfs_rtblock_t	*nextp,		/* out: next block to try */
 	struct xfs_buf	**rbpp,		/* in/out: summary block buffer */
-	xfs_fsblock_t	*rsb,		/* in/out: summary block number */
+	xfs_fileoff_t	*rsb,		/* in/out: summary block number */
 	xfs_rtxlen_t	prod,		/* extent product factor */
 	xfs_rtblock_t	*rtblock)	/* out: start block allocated */
 {
@@ -357,7 +357,7 @@ xfs_rtallocate_extent_exact(
 	xfs_rtxlen_t	maxlen,		/* maximum length to allocate */
 	xfs_rtxlen_t	*len,		/* out: actual length allocated */
 	struct xfs_buf	**rbpp,		/* in/out: summary block buffer */
-	xfs_fsblock_t	*rsb,		/* in/out: summary block number */
+	xfs_fileoff_t	*rsb,		/* in/out: summary block number */
 	xfs_rtxlen_t	prod,		/* extent product factor */
 	xfs_rtblock_t	*rtblock)	/* out: start block allocated */
 {
@@ -437,12 +437,12 @@ xfs_rtallocate_extent_near(
 	xfs_rtxlen_t	maxlen,		/* maximum length to allocate */
 	xfs_rtxlen_t	*len,		/* out: actual length allocated */
 	struct xfs_buf	**rbpp,		/* in/out: summary block buffer */
-	xfs_fsblock_t	*rsb,		/* in/out: summary block number */
+	xfs_fileoff_t	*rsb,		/* in/out: summary block number */
 	xfs_rtxlen_t	prod,		/* extent product factor */
 	xfs_rtblock_t	*rtblock)	/* out: start block allocated */
 {
 	int		any;		/* any useful extents from summary */
-	xfs_rtblock_t	bbno;		/* bitmap block number */
+	xfs_fileoff_t	bbno;		/* bitmap block number */
 	int		error;		/* error value */
 	int		i;		/* bitmap block offset (loop control) */
 	int		j;		/* secondary loop control */
@@ -646,12 +646,12 @@ xfs_rtallocate_extent_size(
 	xfs_rtxlen_t	maxlen,		/* maximum length to allocate */
 	xfs_rtxlen_t	*len,		/* out: actual length allocated */
 	struct xfs_buf	**rbpp,		/* in/out: summary block buffer */
-	xfs_fsblock_t	*rsb,		/* in/out: summary block number */
+	xfs_fileoff_t	*rsb,		/* in/out: summary block number */
 	xfs_rtxlen_t	prod,		/* extent product factor */
 	xfs_rtblock_t	*rtblock)	/* out: start block allocated */
 {
 	int		error;		/* error value */
-	int		i;		/* bitmap block number */
+	xfs_fileoff_t	i;		/* bitmap block number */
 	int		l;		/* level number (loop control) */
 	xfs_rtblock_t	n;		/* next block to be tried */
 	xfs_rtblock_t	r;		/* result block number */
@@ -927,7 +927,7 @@ xfs_growfs_rt(
 	xfs_mount_t	*mp,		/* mount point for filesystem */
 	xfs_growfs_rt_t	*in)		/* growfs rt input struct */
 {
-	xfs_rtblock_t	bmbno;		/* bitmap block number */
+	xfs_fileoff_t	bmbno;		/* bitmap block number */
 	struct xfs_buf	*bp;		/* temporary buffer */
 	int		error;		/* error return value */
 	xfs_mount_t	*nmp;		/* new (fake) mount structure */
@@ -942,7 +942,7 @@ xfs_growfs_rt(
 	xfs_extlen_t	rbmblocks;	/* current number of rt bitmap blocks */
 	xfs_extlen_t	rsumblocks;	/* current number of rt summary blks */
 	xfs_sb_t	*sbp;		/* old superblock */
-	xfs_fsblock_t	sumbno;		/* summary block number */
+	xfs_fileoff_t	sumbno;		/* summary block number */
 	uint8_t		*rsum_cache;	/* old summary cache */
 
 	sbp = &mp->m_sb;
@@ -1205,7 +1205,7 @@ xfs_rtallocate_extent(
 	xfs_mount_t	*mp = tp->t_mountp;
 	int		error;		/* error value */
 	xfs_rtblock_t	r;		/* result allocated block */
-	xfs_fsblock_t	sb;		/* summary file block number */
+	xfs_fileoff_t	sb;		/* summary file block number */
 	struct xfs_buf	*sumbp;		/* summary file block buffer */
 
 	ASSERT(xfs_isilocked(mp->m_rbmip, XFS_ILOCK_EXCL));


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

* [PATCH 5/7] xfs: convert rt bitmap extent lengths to xfs_rtbxlen_t
  2023-10-11 18:01 ` [PATCHSET RFC v1.0 0/7] xfs: clean up realtime type usage Darrick J. Wong
                     ` (3 preceding siblings ...)
  2023-10-11 18:03   ` [PATCH 4/7] xfs: convert rt bitmap/summary block numbers to xfs_fileoff_t Darrick J. Wong
@ 2023-10-11 18:03   ` Darrick J. Wong
  2023-10-12  5:01     ` Christoph Hellwig
  2023-10-11 18:04   ` [PATCH 6/7] xfs: rename xfs_verify_rtext to xfs_verify_rtbext Darrick J. Wong
                     ` (2 subsequent siblings)
  7 siblings, 1 reply; 83+ messages in thread
From: Darrick J. Wong @ 2023-10-11 18:03 UTC (permalink / raw)
  To: djwong; +Cc: linux-xfs, osandov, hch

From: Darrick J. Wong <djwong@kernel.org>

XFS uses xfs_rtblock_t for many different uses, which makes it much more
difficult to perform a unit analysis on the codebase.  One of these
(ab)uses is when we need to store the length of a free space extent as
stored in the realtime bitmap.  Because there can be up to 2^64 realtime
extents in a filesystem, we need a new type that is larger than
xfs_rtxlen_t for callers that are querying the bitmap directly.  This
means scrub and growfs.

Create this type as "xfs_rtbxlen_t" and use it to store 64-bit rtx
lengths.  'b' stands for 'bitmap' or 'big'; reader's choice.

Signed-off-by: Darrick J. Wong <djwong@kernel.org>
---
 fs/xfs/libxfs/xfs_format.h   |    2 +-
 fs/xfs/libxfs/xfs_rtbitmap.h |    2 +-
 fs/xfs/libxfs/xfs_types.h    |    1 +
 fs/xfs/scrub/trace.h         |    3 ++-
 4 files changed, 5 insertions(+), 3 deletions(-)


diff --git a/fs/xfs/libxfs/xfs_format.h b/fs/xfs/libxfs/xfs_format.h
index 4c784bccb1e43..9ce2ebf96667a 100644
--- a/fs/xfs/libxfs/xfs_format.h
+++ b/fs/xfs/libxfs/xfs_format.h
@@ -97,7 +97,7 @@ typedef struct xfs_sb {
 	uint32_t	sb_blocksize;	/* logical block size, bytes */
 	xfs_rfsblock_t	sb_dblocks;	/* number of data blocks */
 	xfs_rfsblock_t	sb_rblocks;	/* number of realtime blocks */
-	xfs_rtblock_t	sb_rextents;	/* number of realtime extents */
+	xfs_rtbxlen_t	sb_rextents;	/* number of realtime extents */
 	uuid_t		sb_uuid;	/* user-visible file system unique id */
 	xfs_fsblock_t	sb_logstart;	/* starting block of log if internal */
 	xfs_ino_t	sb_rootino;	/* root inode number */
diff --git a/fs/xfs/libxfs/xfs_rtbitmap.h b/fs/xfs/libxfs/xfs_rtbitmap.h
index e2ea6d31c38b1..b0a81fb8dbda2 100644
--- a/fs/xfs/libxfs/xfs_rtbitmap.h
+++ b/fs/xfs/libxfs/xfs_rtbitmap.h
@@ -13,7 +13,7 @@
  */
 struct xfs_rtalloc_rec {
 	xfs_rtblock_t		ar_startext;
-	xfs_rtblock_t		ar_extcount;
+	xfs_rtbxlen_t		ar_extcount;
 };
 
 typedef int (*xfs_rtalloc_query_range_fn)(
diff --git a/fs/xfs/libxfs/xfs_types.h b/fs/xfs/libxfs/xfs_types.h
index 0856997f84d6d..a2fb880433b56 100644
--- a/fs/xfs/libxfs/xfs_types.h
+++ b/fs/xfs/libxfs/xfs_types.h
@@ -32,6 +32,7 @@ typedef uint64_t	xfs_rfsblock_t;	/* blockno in filesystem (raw) */
 typedef uint64_t	xfs_rtblock_t;	/* extent (block) in realtime area */
 typedef uint64_t	xfs_fileoff_t;	/* block number in a file */
 typedef uint64_t	xfs_filblks_t;	/* number of blocks in a file */
+typedef uint64_t	xfs_rtbxlen_t;	/* rtbitmap extent length in rtextents */
 
 typedef int64_t		xfs_srtblock_t;	/* signed version of xfs_rtblock_t */
 
diff --git a/fs/xfs/scrub/trace.h b/fs/xfs/scrub/trace.h
index b0c4acc6f5d22..70cb27e8c292e 100644
--- a/fs/xfs/scrub/trace.h
+++ b/fs/xfs/scrub/trace.h
@@ -1261,7 +1261,8 @@ TRACE_EVENT(xfarray_sort_stats,
 #ifdef CONFIG_XFS_RT
 TRACE_EVENT(xchk_rtsum_record_free,
 	TP_PROTO(struct xfs_mount *mp, xfs_rtblock_t start,
-		 uint64_t len, unsigned int log, loff_t pos, xfs_suminfo_t v),
+		 xfs_rtbxlen_t len, unsigned int log, loff_t pos,
+		 xfs_suminfo_t v),
 	TP_ARGS(mp, start, len, log, pos, v),
 	TP_STRUCT__entry(
 		__field(dev_t, dev)


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

* [PATCH 6/7] xfs: rename xfs_verify_rtext to xfs_verify_rtbext
  2023-10-11 18:01 ` [PATCHSET RFC v1.0 0/7] xfs: clean up realtime type usage Darrick J. Wong
                     ` (4 preceding siblings ...)
  2023-10-11 18:03   ` [PATCH 5/7] xfs: convert rt bitmap extent lengths to xfs_rtbxlen_t Darrick J. Wong
@ 2023-10-11 18:04   ` Darrick J. Wong
  2023-10-12  5:02     ` Christoph Hellwig
  2023-10-11 18:04   ` [PATCH 7/7] xfs: convert rt extent numbers to xfs_rtxnum_t Darrick J. Wong
  2023-10-12  5:05   ` [PATCHSET RFC v1.0 0/7] xfs: clean up realtime type usage Christoph Hellwig
  7 siblings, 1 reply; 83+ messages in thread
From: Darrick J. Wong @ 2023-10-11 18:04 UTC (permalink / raw)
  To: djwong; +Cc: linux-xfs, osandov, hch

From: Darrick J. Wong <djwong@kernel.org>

This helper function validates that a range of *blocks* in the
realtime section is completely contained within the realtime section.
It does /not/ validate ranges of *rtextents*.  Rename the function to
avoid suggesting that it does, and change the type of the @len parameter
since xfs_rtblock_t is a position unit, not a length unit.

Signed-off-by: Darrick J. Wong <djwong@kernel.org>
---
 fs/xfs/libxfs/xfs_bmap.c  |    2 +-
 fs/xfs/libxfs/xfs_types.c |    4 ++--
 fs/xfs/libxfs/xfs_types.h |    4 ++--
 fs/xfs/scrub/bmap.c       |    2 +-
 fs/xfs/scrub/rtbitmap.c   |    4 ++--
 fs/xfs/scrub/rtsummary.c  |    2 +-
 fs/xfs/xfs_bmap_item.c    |    2 +-
 7 files changed, 10 insertions(+), 10 deletions(-)


diff --git a/fs/xfs/libxfs/xfs_bmap.c b/fs/xfs/libxfs/xfs_bmap.c
index 6aa7fd05ee30b..fd083a3c554e0 100644
--- a/fs/xfs/libxfs/xfs_bmap.c
+++ b/fs/xfs/libxfs/xfs_bmap.c
@@ -6257,7 +6257,7 @@ xfs_bmap_validate_extent_raw(
 		return __this_address;
 
 	if (rtfile && whichfork == XFS_DATA_FORK) {
-		if (!xfs_verify_rtext(mp, irec->br_startblock,
+		if (!xfs_verify_rtbext(mp, irec->br_startblock,
 					  irec->br_blockcount))
 			return __this_address;
 	} else {
diff --git a/fs/xfs/libxfs/xfs_types.c b/fs/xfs/libxfs/xfs_types.c
index dfcc1889c2033..b1fa715e5f398 100644
--- a/fs/xfs/libxfs/xfs_types.c
+++ b/fs/xfs/libxfs/xfs_types.c
@@ -147,10 +147,10 @@ xfs_verify_rtbno(
 
 /* Verify that a realtime device extent is fully contained inside the volume. */
 bool
-xfs_verify_rtext(
+xfs_verify_rtbext(
 	struct xfs_mount	*mp,
 	xfs_rtblock_t		rtbno,
-	xfs_rtblock_t		len)
+	xfs_filblks_t		len)
 {
 	if (rtbno + len <= rtbno)
 		return false;
diff --git a/fs/xfs/libxfs/xfs_types.h b/fs/xfs/libxfs/xfs_types.h
index a2fb880433b56..532447a357321 100644
--- a/fs/xfs/libxfs/xfs_types.h
+++ b/fs/xfs/libxfs/xfs_types.h
@@ -240,8 +240,8 @@ bool xfs_verify_ino(struct xfs_mount *mp, xfs_ino_t ino);
 bool xfs_internal_inum(struct xfs_mount *mp, xfs_ino_t ino);
 bool xfs_verify_dir_ino(struct xfs_mount *mp, xfs_ino_t ino);
 bool xfs_verify_rtbno(struct xfs_mount *mp, xfs_rtblock_t rtbno);
-bool xfs_verify_rtext(struct xfs_mount *mp, xfs_rtblock_t rtbno,
-		xfs_rtblock_t len);
+bool xfs_verify_rtbext(struct xfs_mount *mp, xfs_rtblock_t rtbno,
+		xfs_filblks_t len);
 bool xfs_verify_icount(struct xfs_mount *mp, unsigned long long icount);
 bool xfs_verify_dablk(struct xfs_mount *mp, xfs_fileoff_t off);
 void xfs_icount_range(struct xfs_mount *mp, unsigned long long *min,
diff --git a/fs/xfs/scrub/bmap.c b/fs/xfs/scrub/bmap.c
index 256ee322cb4af..21fd685415137 100644
--- a/fs/xfs/scrub/bmap.c
+++ b/fs/xfs/scrub/bmap.c
@@ -432,7 +432,7 @@ xchk_bmap_iextent(
 
 	/* Make sure the extent points to a valid place. */
 	if (info->is_rt &&
-	    !xfs_verify_rtext(mp, irec->br_startblock, irec->br_blockcount))
+	    !xfs_verify_rtbext(mp, irec->br_startblock, irec->br_blockcount))
 		xchk_fblock_set_corrupt(info->sc, info->whichfork,
 				irec->br_startoff);
 	if (!info->is_rt &&
diff --git a/fs/xfs/scrub/rtbitmap.c b/fs/xfs/scrub/rtbitmap.c
index c32249a1969aa..0d4bed1e6b8ce 100644
--- a/fs/xfs/scrub/rtbitmap.c
+++ b/fs/xfs/scrub/rtbitmap.c
@@ -60,12 +60,12 @@ xchk_rtbitmap_rec(
 {
 	struct xfs_scrub	*sc = priv;
 	xfs_rtblock_t		startblock;
-	xfs_rtblock_t		blockcount;
+	xfs_filblks_t		blockcount;
 
 	startblock = rec->ar_startext * mp->m_sb.sb_rextsize;
 	blockcount = rec->ar_extcount * mp->m_sb.sb_rextsize;
 
-	if (!xfs_verify_rtext(mp, startblock, blockcount))
+	if (!xfs_verify_rtbext(mp, startblock, blockcount))
 		xchk_fblock_set_corrupt(sc, XFS_DATA_FORK, 0);
 	return 0;
 }
diff --git a/fs/xfs/scrub/rtsummary.c b/fs/xfs/scrub/rtsummary.c
index ccf07a63da70e..b96a464ca3e85 100644
--- a/fs/xfs/scrub/rtsummary.c
+++ b/fs/xfs/scrub/rtsummary.c
@@ -149,7 +149,7 @@ xchk_rtsum_record_free(
 	rtbno = rec->ar_startext * mp->m_sb.sb_rextsize;
 	rtlen = rec->ar_extcount * mp->m_sb.sb_rextsize;
 
-	if (!xfs_verify_rtext(mp, rtbno, rtlen)) {
+	if (!xfs_verify_rtbext(mp, rtbno, rtlen)) {
 		xchk_ino_xref_set_corrupt(sc, mp->m_rbmip->i_ino);
 		return -EFSCORRUPTED;
 	}
diff --git a/fs/xfs/xfs_bmap_item.c b/fs/xfs/xfs_bmap_item.c
index e1f54cf8f0442..5dbe4a79e36c5 100644
--- a/fs/xfs/xfs_bmap_item.c
+++ b/fs/xfs/xfs_bmap_item.c
@@ -474,7 +474,7 @@ xfs_bui_validate(
 		return false;
 
 	if (map->me_flags & XFS_BMAP_EXTENT_REALTIME)
-		return xfs_verify_rtext(mp, map->me_startblock, map->me_len);
+		return xfs_verify_rtbext(mp, map->me_startblock, map->me_len);
 
 	return xfs_verify_fsbext(mp, map->me_startblock, map->me_len);
 }


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

* [PATCH 7/7] xfs: convert rt extent numbers to xfs_rtxnum_t
  2023-10-11 18:01 ` [PATCHSET RFC v1.0 0/7] xfs: clean up realtime type usage Darrick J. Wong
                     ` (5 preceding siblings ...)
  2023-10-11 18:04   ` [PATCH 6/7] xfs: rename xfs_verify_rtext to xfs_verify_rtbext Darrick J. Wong
@ 2023-10-11 18:04   ` Darrick J. Wong
  2023-10-12  5:03     ` Christoph Hellwig
  2023-10-12  5:05   ` [PATCHSET RFC v1.0 0/7] xfs: clean up realtime type usage Christoph Hellwig
  7 siblings, 1 reply; 83+ messages in thread
From: Darrick J. Wong @ 2023-10-11 18:04 UTC (permalink / raw)
  To: djwong; +Cc: linux-xfs, osandov, hch

From: Darrick J. Wong <djwong@kernel.org>

Further disambiguate the xfs_rtblock_t uses by creating a new type,
xfs_rtxnum_t, to store the position of an extent within the realtime
section, in units of rtextents.

Signed-off-by: Darrick J. Wong <djwong@kernel.org>
---
 fs/xfs/libxfs/xfs_rtbitmap.c |   86 +++++++++++++--------------
 fs/xfs/libxfs/xfs_rtbitmap.h |   26 ++++----
 fs/xfs/libxfs/xfs_types.h    |    2 +
 fs/xfs/scrub/rtbitmap.c      |    6 +-
 fs/xfs/scrub/rtsummary.c     |    2 -
 fs/xfs/scrub/trace.h         |    4 +
 fs/xfs/xfs_bmap_util.c       |   12 ++--
 fs/xfs/xfs_rtalloc.c         |  134 +++++++++++++++++++++---------------------
 fs/xfs/xfs_rtalloc.h         |    6 +-
 9 files changed, 138 insertions(+), 140 deletions(-)


diff --git a/fs/xfs/libxfs/xfs_rtbitmap.c b/fs/xfs/libxfs/xfs_rtbitmap.c
index 50a9d23c00c6d..ce14436811319 100644
--- a/fs/xfs/libxfs/xfs_rtbitmap.c
+++ b/fs/xfs/libxfs/xfs_rtbitmap.c
@@ -102,9 +102,9 @@ int
 xfs_rtfind_back(
 	xfs_mount_t	*mp,		/* file system mount point */
 	xfs_trans_t	*tp,		/* transaction pointer */
-	xfs_rtblock_t	start,		/* starting block to look at */
-	xfs_rtblock_t	limit,		/* last block to look at */
-	xfs_rtblock_t	*rtblock)	/* out: start block found */
+	xfs_rtxnum_t	start,		/* starting rtext to look at */
+	xfs_rtxnum_t	limit,		/* last rtext to look at */
+	xfs_rtxnum_t	*rtx)		/* out: start rtext found */
 {
 	xfs_rtword_t	*b;		/* current word in buffer */
 	int		bit;		/* bit number in the word */
@@ -112,9 +112,9 @@ xfs_rtfind_back(
 	struct xfs_buf	*bp;		/* buf for the block */
 	xfs_rtword_t	*bufp;		/* starting word in buffer */
 	int		error;		/* error value */
-	xfs_rtblock_t	firstbit;	/* first useful bit in the word */
-	xfs_rtblock_t	i;		/* current bit number rel. to start */
-	xfs_rtblock_t	len;		/* length of inspected area */
+	xfs_rtxnum_t	firstbit;	/* first useful bit in the word */
+	xfs_rtxnum_t	i;		/* current bit number rel. to start */
+	xfs_rtxnum_t	len;		/* length of inspected area */
 	xfs_rtword_t	mask;		/* mask of relevant bits for value */
 	xfs_rtword_t	want;		/* mask for "good" values */
 	xfs_rtword_t	wdiff;		/* difference from wanted value */
@@ -163,7 +163,7 @@ xfs_rtfind_back(
 			 */
 			xfs_trans_brelse(tp, bp);
 			i = bit - XFS_RTHIBIT(wdiff);
-			*rtblock = start - i + 1;
+			*rtx = start - i + 1;
 			return 0;
 		}
 		i = bit - firstbit + 1;
@@ -209,7 +209,7 @@ xfs_rtfind_back(
 			 */
 			xfs_trans_brelse(tp, bp);
 			i += XFS_NBWORD - 1 - XFS_RTHIBIT(wdiff);
-			*rtblock = start - i + 1;
+			*rtx = start - i + 1;
 			return 0;
 		}
 		i += XFS_NBWORD;
@@ -256,7 +256,7 @@ xfs_rtfind_back(
 			 */
 			xfs_trans_brelse(tp, bp);
 			i += XFS_NBWORD - 1 - XFS_RTHIBIT(wdiff);
-			*rtblock = start - i + 1;
+			*rtx = start - i + 1;
 			return 0;
 		} else
 			i = len;
@@ -265,7 +265,7 @@ xfs_rtfind_back(
 	 * No match, return that we scanned the whole area.
 	 */
 	xfs_trans_brelse(tp, bp);
-	*rtblock = start - i + 1;
+	*rtx = start - i + 1;
 	return 0;
 }
 
@@ -277,9 +277,9 @@ int
 xfs_rtfind_forw(
 	xfs_mount_t	*mp,		/* file system mount point */
 	xfs_trans_t	*tp,		/* transaction pointer */
-	xfs_rtblock_t	start,		/* starting block to look at */
-	xfs_rtblock_t	limit,		/* last block to look at */
-	xfs_rtblock_t	*rtblock)	/* out: start block found */
+	xfs_rtxnum_t	start,		/* starting rtext to look at */
+	xfs_rtxnum_t	limit,		/* last rtext to look at */
+	xfs_rtxnum_t	*rtx)		/* out: start rtext found */
 {
 	xfs_rtword_t	*b;		/* current word in buffer */
 	int		bit;		/* bit number in the word */
@@ -287,9 +287,9 @@ xfs_rtfind_forw(
 	struct xfs_buf	*bp;		/* buf for the block */
 	xfs_rtword_t	*bufp;		/* starting word in buffer */
 	int		error;		/* error value */
-	xfs_rtblock_t	i;		/* current bit number rel. to start */
-	xfs_rtblock_t	lastbit;	/* last useful bit in the word */
-	xfs_rtblock_t	len;		/* length of inspected area */
+	xfs_rtxnum_t	i;		/* current bit number rel. to start */
+	xfs_rtxnum_t	lastbit;	/* last useful bit in the word */
+	xfs_rtxnum_t	len;		/* length of inspected area */
 	xfs_rtword_t	mask;		/* mask of relevant bits for value */
 	xfs_rtword_t	want;		/* mask for "good" values */
 	xfs_rtword_t	wdiff;		/* difference from wanted value */
@@ -337,7 +337,7 @@ xfs_rtfind_forw(
 			 */
 			xfs_trans_brelse(tp, bp);
 			i = XFS_RTLOBIT(wdiff) - bit;
-			*rtblock = start + i - 1;
+			*rtx = start + i - 1;
 			return 0;
 		}
 		i = lastbit - bit;
@@ -382,7 +382,7 @@ xfs_rtfind_forw(
 			 */
 			xfs_trans_brelse(tp, bp);
 			i += XFS_RTLOBIT(wdiff);
-			*rtblock = start + i - 1;
+			*rtx = start + i - 1;
 			return 0;
 		}
 		i += XFS_NBWORD;
@@ -426,7 +426,7 @@ xfs_rtfind_forw(
 			 */
 			xfs_trans_brelse(tp, bp);
 			i += XFS_RTLOBIT(wdiff);
-			*rtblock = start + i - 1;
+			*rtx = start + i - 1;
 			return 0;
 		} else
 			i = len;
@@ -435,7 +435,7 @@ xfs_rtfind_forw(
 	 * No match, return that we scanned the whole area.
 	 */
 	xfs_trans_brelse(tp, bp);
-	*rtblock = start + i - 1;
+	*rtx = start + i - 1;
 	return 0;
 }
 
@@ -540,7 +540,7 @@ int
 xfs_rtmodify_range(
 	xfs_mount_t	*mp,		/* file system mount point */
 	xfs_trans_t	*tp,		/* transaction pointer */
-	xfs_rtblock_t	start,		/* starting block to modify */
+	xfs_rtxnum_t	start,		/* starting rtext to modify */
 	xfs_rtxlen_t	len,		/* length of extent to modify */
 	int		val)		/* 1 for free, 0 for allocated */
 {
@@ -696,15 +696,15 @@ int
 xfs_rtfree_range(
 	xfs_mount_t	*mp,		/* file system mount point */
 	xfs_trans_t	*tp,		/* transaction pointer */
-	xfs_rtblock_t	start,		/* starting block to free */
+	xfs_rtxnum_t	start,		/* starting rtext to free */
 	xfs_rtxlen_t	len,		/* length to free */
 	struct xfs_buf	**rbpp,		/* in/out: summary block buffer */
 	xfs_fileoff_t	*rsb)		/* in/out: summary block number */
 {
-	xfs_rtblock_t	end;		/* end of the freed extent */
+	xfs_rtxnum_t	end;		/* end of the freed extent */
 	int		error;		/* error value */
-	xfs_rtblock_t	postblock;	/* first block freed > end */
-	xfs_rtblock_t	preblock;	/* first block freed < start */
+	xfs_rtxnum_t	postblock;	/* first rtext freed > end */
+	xfs_rtxnum_t	preblock;	/* first rtext freed < start */
 
 	end = start + len - 1;
 	/*
@@ -772,10 +772,10 @@ int
 xfs_rtcheck_range(
 	xfs_mount_t	*mp,		/* file system mount point */
 	xfs_trans_t	*tp,		/* transaction pointer */
-	xfs_rtblock_t	start,		/* starting block number of extent */
+	xfs_rtxnum_t	start,		/* starting rtext number of extent */
 	xfs_rtxlen_t	len,		/* length of extent */
 	int		val,		/* 1 for free, 0 for allocated */
-	xfs_rtblock_t	*new,		/* out: first block not matching */
+	xfs_rtxnum_t	*new,		/* out: first rtext not matching */
 	int		*stat)		/* out: 1 for matches, 0 for not */
 {
 	xfs_rtword_t	*b;		/* current word in buffer */
@@ -784,8 +784,8 @@ xfs_rtcheck_range(
 	struct xfs_buf	*bp;		/* buf for the block */
 	xfs_rtword_t	*bufp;		/* starting word in buffer */
 	int		error;		/* error value */
-	xfs_rtblock_t	i;		/* current bit number rel. to start */
-	xfs_rtblock_t	lastbit;	/* last useful bit in word */
+	xfs_rtxnum_t	i;		/* current bit number rel. to start */
+	xfs_rtxnum_t	lastbit;	/* last useful bit in word */
 	xfs_rtword_t	mask;		/* mask of relevant bits for value */
 	xfs_rtword_t	wdiff;		/* difference from wanted value */
 	int		word;		/* word number in the buffer */
@@ -948,14 +948,14 @@ STATIC int				/* error */
 xfs_rtcheck_alloc_range(
 	xfs_mount_t	*mp,		/* file system mount point */
 	xfs_trans_t	*tp,		/* transaction pointer */
-	xfs_rtblock_t	bno,		/* starting block number of extent */
+	xfs_rtxnum_t	start,		/* starting rtext number of extent */
 	xfs_rtxlen_t	len)		/* length of extent */
 {
-	xfs_rtblock_t	new;		/* dummy for xfs_rtcheck_range */
+	xfs_rtxnum_t	new;		/* dummy for xfs_rtcheck_range */
 	int		stat;
 	int		error;
 
-	error = xfs_rtcheck_range(mp, tp, bno, len, 0, &new, &stat);
+	error = xfs_rtcheck_range(mp, tp, start, len, 0, &new, &stat);
 	if (error)
 		return error;
 	ASSERT(stat);
@@ -971,7 +971,7 @@ xfs_rtcheck_alloc_range(
 int					/* error */
 xfs_rtfree_extent(
 	xfs_trans_t	*tp,		/* transaction pointer */
-	xfs_rtblock_t	bno,		/* starting block number to free */
+	xfs_rtxnum_t	start,		/* starting rtext number to free */
 	xfs_rtxlen_t	len)		/* length of extent freed */
 {
 	int		error;		/* error value */
@@ -984,14 +984,14 @@ xfs_rtfree_extent(
 	ASSERT(mp->m_rbmip->i_itemp != NULL);
 	ASSERT(xfs_isilocked(mp->m_rbmip, XFS_ILOCK_EXCL));
 
-	error = xfs_rtcheck_alloc_range(mp, tp, bno, len);
+	error = xfs_rtcheck_alloc_range(mp, tp, start, len);
 	if (error)
 		return error;
 
 	/*
 	 * Free the range of realtime blocks.
 	 */
-	error = xfs_rtfree_range(mp, tp, bno, len, &sumbp, &sb);
+	error = xfs_rtfree_range(mp, tp, start, len, &sumbp, &sb);
 	if (error) {
 		return error;
 	}
@@ -1025,7 +1025,7 @@ xfs_rtfree_blocks(
 	xfs_filblks_t		rtlen)
 {
 	struct xfs_mount	*mp = tp->t_mountp;
-	xfs_rtblock_t		bno;
+	xfs_rtxnum_t		start;
 	xfs_filblks_t		len;
 	xfs_extlen_t		mod;
 
@@ -1037,13 +1037,13 @@ xfs_rtfree_blocks(
 		return -EIO;
 	}
 
-	bno = div_u64_rem(rtbno, mp->m_sb.sb_rextsize, &mod);
+	start = div_u64_rem(rtbno, mp->m_sb.sb_rextsize, &mod);
 	if (mod) {
 		ASSERT(mod == 0);
 		return -EIO;
 	}
 
-	return xfs_rtfree_extent(tp, bno, len);
+	return xfs_rtfree_extent(tp, start, len);
 }
 
 /* Find all the free records within a given range. */
@@ -1057,9 +1057,9 @@ xfs_rtalloc_query_range(
 	void				*priv)
 {
 	struct xfs_rtalloc_rec		rec;
-	xfs_rtblock_t			rtstart;
-	xfs_rtblock_t			rtend;
-	xfs_rtblock_t			high_key;
+	xfs_rtxnum_t			rtstart;
+	xfs_rtxnum_t			rtend;
+	xfs_rtxnum_t			high_key;
 	int				is_free;
 	int				error = 0;
 
@@ -1122,11 +1122,11 @@ int
 xfs_rtalloc_extent_is_free(
 	struct xfs_mount		*mp,
 	struct xfs_trans		*tp,
-	xfs_rtblock_t			start,
+	xfs_rtxnum_t			start,
 	xfs_rtxlen_t			len,
 	bool				*is_free)
 {
-	xfs_rtblock_t			end;
+	xfs_rtxnum_t			end;
 	int				matches;
 	int				error;
 
diff --git a/fs/xfs/libxfs/xfs_rtbitmap.h b/fs/xfs/libxfs/xfs_rtbitmap.h
index b0a81fb8dbda2..5e2afb7fea0e7 100644
--- a/fs/xfs/libxfs/xfs_rtbitmap.h
+++ b/fs/xfs/libxfs/xfs_rtbitmap.h
@@ -7,12 +7,10 @@
 #define	__XFS_RTBITMAP_H__
 
 /*
- * XXX: Most of the realtime allocation functions deal in units of realtime
- * extents, not realtime blocks.  This looks funny when paired with the type
- * name and screams for a larger cleanup.
+ * Functions for walking free space rtextents in the realtime bitmap.
  */
 struct xfs_rtalloc_rec {
-	xfs_rtblock_t		ar_startext;
+	xfs_rtxnum_t		ar_startext;
 	xfs_rtbxlen_t		ar_extcount;
 };
 
@@ -26,16 +24,16 @@ typedef int (*xfs_rtalloc_query_range_fn)(
 int xfs_rtbuf_get(struct xfs_mount *mp, struct xfs_trans *tp,
 		  xfs_fileoff_t block, int issum, struct xfs_buf **bpp);
 int xfs_rtcheck_range(struct xfs_mount *mp, struct xfs_trans *tp,
-		      xfs_rtblock_t start, xfs_rtxlen_t len, int val,
-		      xfs_rtblock_t *new, int *stat);
+		      xfs_rtxnum_t start, xfs_rtxlen_t len, int val,
+		      xfs_rtxnum_t *new, int *stat);
 int xfs_rtfind_back(struct xfs_mount *mp, struct xfs_trans *tp,
-		    xfs_rtblock_t start, xfs_rtblock_t limit,
-		    xfs_rtblock_t *rtblock);
+		    xfs_rtxnum_t start, xfs_rtxnum_t limit,
+		    xfs_rtxnum_t *rtblock);
 int xfs_rtfind_forw(struct xfs_mount *mp, struct xfs_trans *tp,
-		    xfs_rtblock_t start, xfs_rtblock_t limit,
-		    xfs_rtblock_t *rtblock);
+		    xfs_rtxnum_t start, xfs_rtxnum_t limit,
+		    xfs_rtxnum_t *rtblock);
 int xfs_rtmodify_range(struct xfs_mount *mp, struct xfs_trans *tp,
-		       xfs_rtblock_t start, xfs_rtxlen_t len, int val);
+		       xfs_rtxnum_t start, xfs_rtxlen_t len, int val);
 int xfs_rtmodify_summary_int(struct xfs_mount *mp, struct xfs_trans *tp,
 			     int log, xfs_fileoff_t bbno, int delta,
 			     struct xfs_buf **rbpp, xfs_fileoff_t *rsb,
@@ -44,7 +42,7 @@ int xfs_rtmodify_summary(struct xfs_mount *mp, struct xfs_trans *tp, int log,
 			 xfs_fileoff_t bbno, int delta, struct xfs_buf **rbpp,
 			 xfs_fileoff_t *rsb);
 int xfs_rtfree_range(struct xfs_mount *mp, struct xfs_trans *tp,
-		     xfs_rtblock_t start, xfs_rtxlen_t len,
+		     xfs_rtxnum_t start, xfs_rtxlen_t len,
 		     struct xfs_buf **rbpp, xfs_fileoff_t *rsb);
 int xfs_rtalloc_query_range(struct xfs_mount *mp, struct xfs_trans *tp,
 		const struct xfs_rtalloc_rec *low_rec,
@@ -54,7 +52,7 @@ int xfs_rtalloc_query_all(struct xfs_mount *mp, struct xfs_trans *tp,
 			  xfs_rtalloc_query_range_fn fn,
 			  void *priv);
 int xfs_rtalloc_extent_is_free(struct xfs_mount *mp, struct xfs_trans *tp,
-			       xfs_rtblock_t start, xfs_rtxlen_t len,
+			       xfs_rtxnum_t start, xfs_rtxlen_t len,
 			       bool *is_free);
 /*
  * Free an extent in the realtime subvolume.  Length is expressed in
@@ -63,7 +61,7 @@ int xfs_rtalloc_extent_is_free(struct xfs_mount *mp, struct xfs_trans *tp,
 int					/* error */
 xfs_rtfree_extent(
 	struct xfs_trans	*tp,	/* transaction pointer */
-	xfs_rtblock_t		bno,	/* starting block number to free */
+	xfs_rtxnum_t		start,	/* starting rtext number to free */
 	xfs_rtxlen_t		len);	/* length of extent freed */
 
 /* Same as above, but in units of rt blocks. */
diff --git a/fs/xfs/libxfs/xfs_types.h b/fs/xfs/libxfs/xfs_types.h
index 532447a357321..abb07a1c7b0b4 100644
--- a/fs/xfs/libxfs/xfs_types.h
+++ b/fs/xfs/libxfs/xfs_types.h
@@ -32,6 +32,7 @@ typedef uint64_t	xfs_rfsblock_t;	/* blockno in filesystem (raw) */
 typedef uint64_t	xfs_rtblock_t;	/* extent (block) in realtime area */
 typedef uint64_t	xfs_fileoff_t;	/* block number in a file */
 typedef uint64_t	xfs_filblks_t;	/* number of blocks in a file */
+typedef uint64_t	xfs_rtxnum_t;	/* rtextent number */
 typedef uint64_t	xfs_rtbxlen_t;	/* rtbitmap extent length in rtextents */
 
 typedef int64_t		xfs_srtblock_t;	/* signed version of xfs_rtblock_t */
@@ -49,6 +50,7 @@ typedef void *		xfs_failaddr_t;
 #define	NULLRFSBLOCK	((xfs_rfsblock_t)-1)
 #define	NULLRTBLOCK	((xfs_rtblock_t)-1)
 #define	NULLFILEOFF	((xfs_fileoff_t)-1)
+#define NULLRTEXTNO	((xfs_rtxnum_t)-1)
 
 #define	NULLAGBLOCK	((xfs_agblock_t)-1)
 #define	NULLAGNUMBER	((xfs_agnumber_t)-1)
diff --git a/fs/xfs/scrub/rtbitmap.c b/fs/xfs/scrub/rtbitmap.c
index 0d4bed1e6b8ce..fe871ce224c89 100644
--- a/fs/xfs/scrub/rtbitmap.c
+++ b/fs/xfs/scrub/rtbitmap.c
@@ -59,7 +59,7 @@ xchk_rtbitmap_rec(
 	void			*priv)
 {
 	struct xfs_scrub	*sc = priv;
-	xfs_rtblock_t		startblock;
+	xfs_rtxnum_t		startblock;
 	xfs_filblks_t		blockcount;
 
 	startblock = rec->ar_startext * mp->m_sb.sb_rextsize;
@@ -143,8 +143,8 @@ xchk_xref_is_used_rt_space(
 	xfs_rtblock_t		fsbno,
 	xfs_extlen_t		len)
 {
-	xfs_rtblock_t		startext;
-	xfs_rtblock_t		endext;
+	xfs_rtxnum_t		startext;
+	xfs_rtxnum_t		endext;
 	xfs_rtxlen_t		extcount;
 	bool			is_free;
 	int			error;
diff --git a/fs/xfs/scrub/rtsummary.c b/fs/xfs/scrub/rtsummary.c
index b96a464ca3e85..c03f6e0074d4d 100644
--- a/fs/xfs/scrub/rtsummary.c
+++ b/fs/xfs/scrub/rtsummary.c
@@ -131,7 +131,7 @@ xchk_rtsum_record_free(
 {
 	struct xfs_scrub		*sc = priv;
 	xfs_fileoff_t			rbmoff;
-	xfs_rtblock_t			rtbno;
+	xfs_rtxnum_t			rtbno;
 	xfs_filblks_t			rtlen;
 	xchk_rtsumoff_t			offs;
 	unsigned int			lenlog;
diff --git a/fs/xfs/scrub/trace.h b/fs/xfs/scrub/trace.h
index 70cb27e8c292e..5fc3e07d85ebd 100644
--- a/fs/xfs/scrub/trace.h
+++ b/fs/xfs/scrub/trace.h
@@ -1260,14 +1260,14 @@ TRACE_EVENT(xfarray_sort_stats,
 
 #ifdef CONFIG_XFS_RT
 TRACE_EVENT(xchk_rtsum_record_free,
-	TP_PROTO(struct xfs_mount *mp, xfs_rtblock_t start,
+	TP_PROTO(struct xfs_mount *mp, xfs_rtxnum_t start,
 		 xfs_rtbxlen_t len, unsigned int log, loff_t pos,
 		 xfs_suminfo_t v),
 	TP_ARGS(mp, start, len, log, pos, v),
 	TP_STRUCT__entry(
 		__field(dev_t, dev)
 		__field(dev_t, rtdev)
-		__field(xfs_rtblock_t, start)
+		__field(xfs_rtxnum_t, start)
 		__field(unsigned long long, len)
 		__field(unsigned int, log)
 		__field(loff_t, pos)
diff --git a/fs/xfs/xfs_bmap_util.c b/fs/xfs/xfs_bmap_util.c
index f2efa508200b3..285e9cafe29ef 100644
--- a/fs/xfs/xfs_bmap_util.c
+++ b/fs/xfs/xfs_bmap_util.c
@@ -76,7 +76,7 @@ xfs_bmap_rtalloc(
 {
 	struct xfs_mount	*mp = ap->ip->i_mount;
 	xfs_fileoff_t		orig_offset = ap->offset;
-	xfs_rtblock_t		rtb;
+	xfs_rtxnum_t		rtx;
 	xfs_rtxlen_t		prod = 0;  /* product factor for allocators */
 	xfs_extlen_t		mod = 0;   /* product factor for allocators */
 	xfs_rtxlen_t		ralen = 0; /* realtime allocation length */
@@ -145,8 +145,6 @@ xfs_bmap_rtalloc(
 	 * pick an extent that will space things out in the rt area.
 	 */
 	if (ap->eof && ap->offset == 0) {
-		xfs_rtblock_t rtx; /* realtime extent no */
-
 		error = xfs_rtpick_extent(mp, ap->tp, ralen, &rtx);
 		if (error)
 			return error;
@@ -164,16 +162,16 @@ xfs_bmap_rtalloc(
 		ap->blkno = 0;
 	else
 		do_div(ap->blkno, mp->m_sb.sb_rextsize);
-	rtb = ap->blkno;
+	rtx = ap->blkno;
 	ap->length = ralen;
 	raminlen = max_t(xfs_extlen_t, 1, minlen / mp->m_sb.sb_rextsize);
 	error = xfs_rtallocate_extent(ap->tp, ap->blkno, raminlen, ap->length,
-			&ralen, ap->wasdel, prod, &rtb);
+			&ralen, ap->wasdel, prod, &rtx);
 	if (error)
 		return error;
 
-	if (rtb != NULLRTBLOCK) {
-		ap->blkno = rtb * mp->m_sb.sb_rextsize;
+	if (rtx != NULLRTEXTNO) {
+		ap->blkno = rtx * mp->m_sb.sb_rextsize;
 		ap->length = ralen * mp->m_sb.sb_rextsize;
 		ap->ip->i_nblocks += ap->length;
 		xfs_trans_log_inode(ap->tp, ap->ip, XFS_ILOG_CORE);
diff --git a/fs/xfs/xfs_rtalloc.c b/fs/xfs/xfs_rtalloc.c
index 5eb23cff281d1..4bb776911a4fb 100644
--- a/fs/xfs/xfs_rtalloc.c
+++ b/fs/xfs/xfs_rtalloc.c
@@ -148,15 +148,15 @@ STATIC int				/* error */
 xfs_rtallocate_range(
 	xfs_mount_t	*mp,		/* file system mount point */
 	xfs_trans_t	*tp,		/* transaction pointer */
-	xfs_rtblock_t	start,		/* start block to allocate */
+	xfs_rtxnum_t	start,		/* start rtext to allocate */
 	xfs_rtxlen_t	len,		/* length to allocate */
 	struct xfs_buf	**rbpp,		/* in/out: summary block buffer */
 	xfs_fileoff_t	*rsb)		/* in/out: summary block number */
 {
-	xfs_rtblock_t	end;		/* end of the allocated extent */
+	xfs_rtxnum_t	end;		/* end of the allocated rtext */
 	int		error;		/* error value */
-	xfs_rtblock_t	postblock = 0;	/* first block allocated > end */
-	xfs_rtblock_t	preblock = 0;	/* first block allocated < start */
+	xfs_rtxnum_t	postblock = 0;	/* first rtext allocated > end */
+	xfs_rtxnum_t	preblock = 0;	/* first rtext allocated < start */
 
 	end = start + len - 1;
 	/*
@@ -220,7 +220,7 @@ xfs_rtallocate_range(
 /*
  * Attempt to allocate an extent minlen<=len<=maxlen starting from
  * bitmap block bbno.  If we don't get maxlen then use prod to trim
- * the length, if given.  Returns error; returns starting block in *rtblock.
+ * the length, if given.  Returns error; returns starting block in *rtx.
  * The lengths are all in rtextents.
  */
 STATIC int				/* error */
@@ -231,18 +231,18 @@ xfs_rtallocate_extent_block(
 	xfs_rtxlen_t	minlen,		/* minimum length to allocate */
 	xfs_rtxlen_t	maxlen,		/* maximum length to allocate */
 	xfs_rtxlen_t	*len,		/* out: actual length allocated */
-	xfs_rtblock_t	*nextp,		/* out: next block to try */
+	xfs_rtxnum_t	*nextp,		/* out: next rtext to try */
 	struct xfs_buf	**rbpp,		/* in/out: summary block buffer */
 	xfs_fileoff_t	*rsb,		/* in/out: summary block number */
 	xfs_rtxlen_t	prod,		/* extent product factor */
-	xfs_rtblock_t	*rtblock)	/* out: start block allocated */
+	xfs_rtxnum_t	*rtx)		/* out: start rtext allocated */
 {
-	xfs_rtblock_t	besti;		/* best rtblock found so far */
-	xfs_rtblock_t	bestlen;	/* best length found so far */
-	xfs_rtblock_t	end;		/* last rtblock in chunk */
+	xfs_rtxnum_t	besti;		/* best rtext found so far */
+	xfs_rtxnum_t	bestlen;	/* best length found so far */
+	xfs_rtxnum_t	end;		/* last rtext in chunk */
 	int		error;		/* error value */
-	xfs_rtblock_t	i;		/* current rtblock trying */
-	xfs_rtblock_t	next;		/* next rtblock to try */
+	xfs_rtxnum_t	i;		/* current rtext trying */
+	xfs_rtxnum_t	next;		/* next rtext to try */
 	int		stat;		/* status from internal calls */
 
 	/*
@@ -279,7 +279,7 @@ xfs_rtallocate_extent_block(
 				return error;
 			}
 			*len = maxlen;
-			*rtblock = i;
+			*rtx = i;
 			return 0;
 		}
 		/*
@@ -289,7 +289,7 @@ xfs_rtallocate_extent_block(
 		 * so far, remember it.
 		 */
 		if (minlen < maxlen) {
-			xfs_rtblock_t	thislen;	/* this extent size */
+			xfs_rtxnum_t	thislen;	/* this extent size */
 
 			thislen = next - i;
 			if (thislen >= minlen && thislen > bestlen) {
@@ -331,47 +331,47 @@ xfs_rtallocate_extent_block(
 			return error;
 		}
 		*len = bestlen;
-		*rtblock = besti;
+		*rtx = besti;
 		return 0;
 	}
 	/*
 	 * Allocation failed.  Set *nextp to the next block to try.
 	 */
 	*nextp = next;
-	*rtblock = NULLRTBLOCK;
+	*rtx = NULLRTEXTNO;
 	return 0;
 }
 
 /*
  * Allocate an extent of length minlen<=len<=maxlen, starting at block
  * bno.  If we don't get maxlen then use prod to trim the length, if given.
- * Returns error; returns starting block in *rtblock.
+ * Returns error; returns starting block in *rtx.
  * The lengths are all in rtextents.
  */
 STATIC int				/* error */
 xfs_rtallocate_extent_exact(
 	xfs_mount_t	*mp,		/* file system mount point */
 	xfs_trans_t	*tp,		/* transaction pointer */
-	xfs_rtblock_t	bno,		/* starting block number to allocate */
+	xfs_rtxnum_t	start,		/* starting rtext number to allocate */
 	xfs_rtxlen_t	minlen,		/* minimum length to allocate */
 	xfs_rtxlen_t	maxlen,		/* maximum length to allocate */
 	xfs_rtxlen_t	*len,		/* out: actual length allocated */
 	struct xfs_buf	**rbpp,		/* in/out: summary block buffer */
 	xfs_fileoff_t	*rsb,		/* in/out: summary block number */
 	xfs_rtxlen_t	prod,		/* extent product factor */
-	xfs_rtblock_t	*rtblock)	/* out: start block allocated */
+	xfs_rtxnum_t	*rtx)		/* out: start rtext allocated */
 {
 	int		error;		/* error value */
 	xfs_rtxlen_t	i;		/* extent length trimmed due to prod */
 	int		isfree;		/* extent is free */
-	xfs_rtblock_t	next;		/* next block to try (dummy) */
+	xfs_rtxnum_t	next;		/* next rtext to try (dummy) */
 
 	ASSERT(minlen % prod == 0);
 	ASSERT(maxlen % prod == 0);
 	/*
 	 * Check if the range in question (for maxlen) is free.
 	 */
-	error = xfs_rtcheck_range(mp, tp, bno, maxlen, 1, &next, &isfree);
+	error = xfs_rtcheck_range(mp, tp, start, maxlen, 1, &next, &isfree);
 	if (error) {
 		return error;
 	}
@@ -379,23 +379,23 @@ xfs_rtallocate_extent_exact(
 		/*
 		 * If it is, allocate it and return success.
 		 */
-		error = xfs_rtallocate_range(mp, tp, bno, maxlen, rbpp, rsb);
+		error = xfs_rtallocate_range(mp, tp, start, maxlen, rbpp, rsb);
 		if (error) {
 			return error;
 		}
 		*len = maxlen;
-		*rtblock = bno;
+		*rtx = start;
 		return 0;
 	}
 	/*
 	 * If not, allocate what there is, if it's at least minlen.
 	 */
-	maxlen = next - bno;
+	maxlen = next - start;
 	if (maxlen < minlen) {
 		/*
 		 * Failed, return failure status.
 		 */
-		*rtblock = NULLRTBLOCK;
+		*rtx = NULLRTEXTNO;
 		return 0;
 	}
 	/*
@@ -407,39 +407,39 @@ xfs_rtallocate_extent_exact(
 			/*
 			 * Now we can't do it, return failure status.
 			 */
-			*rtblock = NULLRTBLOCK;
+			*rtx = NULLRTEXTNO;
 			return 0;
 		}
 	}
 	/*
 	 * Allocate what we can and return it.
 	 */
-	error = xfs_rtallocate_range(mp, tp, bno, maxlen, rbpp, rsb);
+	error = xfs_rtallocate_range(mp, tp, start, maxlen, rbpp, rsb);
 	if (error) {
 		return error;
 	}
 	*len = maxlen;
-	*rtblock = bno;
+	*rtx = start;
 	return 0;
 }
 
 /*
  * Allocate an extent of length minlen<=len<=maxlen, starting as near
- * to bno as possible.  If we don't get maxlen then use prod to trim
+ * to start as possible.  If we don't get maxlen then use prod to trim
  * the length, if given.  The lengths are all in rtextents.
  */
 STATIC int				/* error */
 xfs_rtallocate_extent_near(
 	xfs_mount_t	*mp,		/* file system mount point */
 	xfs_trans_t	*tp,		/* transaction pointer */
-	xfs_rtblock_t	bno,		/* starting block number to allocate */
+	xfs_rtxnum_t	start,		/* starting rtext number to allocate */
 	xfs_rtxlen_t	minlen,		/* minimum length to allocate */
 	xfs_rtxlen_t	maxlen,		/* maximum length to allocate */
 	xfs_rtxlen_t	*len,		/* out: actual length allocated */
 	struct xfs_buf	**rbpp,		/* in/out: summary block buffer */
 	xfs_fileoff_t	*rsb,		/* in/out: summary block number */
 	xfs_rtxlen_t	prod,		/* extent product factor */
-	xfs_rtblock_t	*rtblock)	/* out: start block allocated */
+	xfs_rtxnum_t	*rtx)		/* out: start rtext allocated */
 {
 	int		any;		/* any useful extents from summary */
 	xfs_fileoff_t	bbno;		/* bitmap block number */
@@ -447,8 +447,8 @@ xfs_rtallocate_extent_near(
 	int		i;		/* bitmap block offset (loop control) */
 	int		j;		/* secondary loop control */
 	int		log2len;	/* log2 of minlen */
-	xfs_rtblock_t	n;		/* next block to try */
-	xfs_rtblock_t	r;		/* result block */
+	xfs_rtxnum_t	n;		/* next rtext to try */
+	xfs_rtxnum_t	r;		/* result rtext */
 
 	ASSERT(minlen % prod == 0);
 	ASSERT(maxlen % prod == 0);
@@ -457,25 +457,25 @@ xfs_rtallocate_extent_near(
 	 * If the block number given is off the end, silently set it to
 	 * the last block.
 	 */
-	if (bno >= mp->m_sb.sb_rextents)
-		bno = mp->m_sb.sb_rextents - 1;
+	if (start >= mp->m_sb.sb_rextents)
+		start = mp->m_sb.sb_rextents - 1;
 
 	/*
 	 * Make sure we don't run off the end of the rt volume.  Be careful
 	 * that adjusting maxlen downwards doesn't cause us to fail the
 	 * alignment checks.
 	 */
-	maxlen = min(mp->m_sb.sb_rextents, bno + maxlen) - bno;
+	maxlen = min(mp->m_sb.sb_rextents, start + maxlen) - start;
 	maxlen -= maxlen % prod;
 	if (maxlen < minlen) {
-		*rtblock = NULLRTBLOCK;
+		*rtx = NULLRTEXTNO;
 		return 0;
 	}
 
 	/*
 	 * Try the exact allocation first.
 	 */
-	error = xfs_rtallocate_extent_exact(mp, tp, bno, minlen, maxlen, len,
+	error = xfs_rtallocate_extent_exact(mp, tp, start, minlen, maxlen, len,
 		rbpp, rsb, prod, &r);
 	if (error) {
 		return error;
@@ -483,11 +483,11 @@ xfs_rtallocate_extent_near(
 	/*
 	 * If the exact allocation worked, return that.
 	 */
-	if (r != NULLRTBLOCK) {
-		*rtblock = r;
+	if (r != NULLRTEXTNO) {
+		*rtx = r;
 		return 0;
 	}
-	bbno = XFS_BITTOBLOCK(mp, bno);
+	bbno = XFS_BITTOBLOCK(mp, start);
 	i = 0;
 	ASSERT(minlen != 0);
 	log2len = xfs_highbit32(minlen);
@@ -526,8 +526,8 @@ xfs_rtallocate_extent_near(
 				/*
 				 * If it worked, return it.
 				 */
-				if (r != NULLRTBLOCK) {
-					*rtblock = r;
+				if (r != NULLRTEXTNO) {
+					*rtx = r;
 					return 0;
 				}
 			}
@@ -571,8 +571,8 @@ xfs_rtallocate_extent_near(
 					/*
 					 * If it works, return the extent.
 					 */
-					if (r != NULLRTBLOCK) {
-						*rtblock = r;
+					if (r != NULLRTEXTNO) {
+						*rtx = r;
 						return 0;
 					}
 				}
@@ -593,8 +593,8 @@ xfs_rtallocate_extent_near(
 				/*
 				 * If it works, return the extent.
 				 */
-				if (r != NULLRTBLOCK) {
-					*rtblock = r;
+				if (r != NULLRTEXTNO) {
+					*rtx = r;
 					return 0;
 				}
 			}
@@ -629,7 +629,7 @@ xfs_rtallocate_extent_near(
 		else
 			break;
 	}
-	*rtblock = NULLRTBLOCK;
+	*rtx = NULLRTEXTNO;
 	return 0;
 }
 
@@ -648,13 +648,13 @@ xfs_rtallocate_extent_size(
 	struct xfs_buf	**rbpp,		/* in/out: summary block buffer */
 	xfs_fileoff_t	*rsb,		/* in/out: summary block number */
 	xfs_rtxlen_t	prod,		/* extent product factor */
-	xfs_rtblock_t	*rtblock)	/* out: start block allocated */
+	xfs_rtxnum_t	*rtx)		/* out: start rtext allocated */
 {
 	int		error;		/* error value */
 	xfs_fileoff_t	i;		/* bitmap block number */
 	int		l;		/* level number (loop control) */
-	xfs_rtblock_t	n;		/* next block to be tried */
-	xfs_rtblock_t	r;		/* result block number */
+	xfs_rtxnum_t	n;		/* next rtext to be tried */
+	xfs_rtxnum_t	r;		/* result rtext number */
 	xfs_suminfo_t	sum;		/* summary information for extents */
 
 	ASSERT(minlen % prod == 0);
@@ -697,8 +697,8 @@ xfs_rtallocate_extent_size(
 			/*
 			 * If it worked, return that.
 			 */
-			if (r != NULLRTBLOCK) {
-				*rtblock = r;
+			if (r != NULLRTEXTNO) {
+				*rtx = r;
 				return 0;
 			}
 			/*
@@ -715,7 +715,7 @@ xfs_rtallocate_extent_size(
 	 * we're asking for a fixed size extent.
 	 */
 	if (minlen > --maxlen) {
-		*rtblock = NULLRTBLOCK;
+		*rtx = NULLRTEXTNO;
 		return 0;
 	}
 	ASSERT(minlen != 0);
@@ -760,8 +760,8 @@ xfs_rtallocate_extent_size(
 			/*
 			 * If it worked, return that extent.
 			 */
-			if (r != NULLRTBLOCK) {
-				*rtblock = r;
+			if (r != NULLRTEXTNO) {
+				*rtx = r;
 				return 0;
 			}
 			/*
@@ -776,7 +776,7 @@ xfs_rtallocate_extent_size(
 	/*
 	 * Got nothing, return failure.
 	 */
-	*rtblock = NULLRTBLOCK;
+	*rtx = NULLRTEXTNO;
 	return 0;
 }
 
@@ -933,7 +933,7 @@ xfs_growfs_rt(
 	xfs_mount_t	*nmp;		/* new (fake) mount structure */
 	xfs_rfsblock_t	nrblocks;	/* new number of realtime blocks */
 	xfs_extlen_t	nrbmblocks;	/* new number of rt bitmap blocks */
-	xfs_rtblock_t	nrextents;	/* new number of realtime extents */
+	xfs_rtxnum_t	nrextents;	/* new number of realtime extents */
 	uint8_t		nrextslog;	/* new log2 of sb_rextents */
 	xfs_extlen_t	nrsumblocks;	/* new number of summary blocks */
 	uint		nrsumlevels;	/* new rt summary levels */
@@ -1194,17 +1194,17 @@ xfs_growfs_rt(
 int					/* error */
 xfs_rtallocate_extent(
 	xfs_trans_t	*tp,		/* transaction pointer */
-	xfs_rtblock_t	bno,		/* starting block number to allocate */
+	xfs_rtxnum_t	start,		/* starting rtext number to allocate */
 	xfs_rtxlen_t	minlen,		/* minimum length to allocate */
 	xfs_rtxlen_t	maxlen,		/* maximum length to allocate */
 	xfs_rtxlen_t	*len,		/* out: actual length allocated */
 	int		wasdel,		/* was a delayed allocation extent */
 	xfs_rtxlen_t	prod,		/* extent product factor */
-	xfs_rtblock_t	*rtblock)	/* out: start block allocated */
+	xfs_rtxnum_t	*rtblock)	/* out: start rtext allocated */
 {
 	xfs_mount_t	*mp = tp->t_mountp;
 	int		error;		/* error value */
-	xfs_rtblock_t	r;		/* result allocated block */
+	xfs_rtxnum_t	r;		/* result allocated rtext */
 	xfs_fileoff_t	sb;		/* summary file block number */
 	struct xfs_buf	*sumbp;		/* summary file block buffer */
 
@@ -1222,18 +1222,18 @@ xfs_rtallocate_extent(
 		if ((i = minlen % prod))
 			minlen += prod - i;
 		if (maxlen < minlen) {
-			*rtblock = NULLRTBLOCK;
+			*rtblock = NULLRTEXTNO;
 			return 0;
 		}
 	}
 
 retry:
 	sumbp = NULL;
-	if (bno == 0) {
+	if (start == 0) {
 		error = xfs_rtallocate_extent_size(mp, tp, minlen, maxlen, len,
 				&sumbp,	&sb, prod, &r);
 	} else {
-		error = xfs_rtallocate_extent_near(mp, tp, bno, minlen, maxlen,
+		error = xfs_rtallocate_extent_near(mp, tp, start, minlen, maxlen,
 				len, &sumbp, &sb, prod, &r);
 	}
 
@@ -1243,7 +1243,7 @@ xfs_rtallocate_extent(
 	/*
 	 * If it worked, update the superblock.
 	 */
-	if (r != NULLRTBLOCK) {
+	if (r != NULLRTEXTNO) {
 		long	slen = (long)*len;
 
 		ASSERT(*len >= minlen && *len <= maxlen);
@@ -1451,9 +1451,9 @@ xfs_rtpick_extent(
 	xfs_mount_t	*mp,		/* file system mount point */
 	xfs_trans_t	*tp,		/* transaction pointer */
 	xfs_rtxlen_t	len,		/* allocation length (rtextents) */
-	xfs_rtblock_t	*pick)		/* result rt extent */
+	xfs_rtxnum_t	*pick)		/* result rt extent */
 {
-	xfs_rtblock_t	b;		/* result block */
+	xfs_rtxnum_t	b;		/* result rtext */
 	int		log2;		/* log of sequence number */
 	uint64_t	resid;		/* residual after log removed */
 	uint64_t	seq;		/* sequence number of file creation */
diff --git a/fs/xfs/xfs_rtalloc.h b/fs/xfs/xfs_rtalloc.h
index ec03cc566bec8..5ac9c15948c82 100644
--- a/fs/xfs/xfs_rtalloc.h
+++ b/fs/xfs/xfs_rtalloc.h
@@ -24,13 +24,13 @@ struct xfs_trans;
 int					/* error */
 xfs_rtallocate_extent(
 	struct xfs_trans	*tp,	/* transaction pointer */
-	xfs_rtblock_t		bno,	/* starting block number to allocate */
+	xfs_rtxnum_t		start,	/* starting rtext number to allocate */
 	xfs_rtxlen_t		minlen,	/* minimum length to allocate */
 	xfs_rtxlen_t		maxlen,	/* maximum length to allocate */
 	xfs_rtxlen_t		*len,	/* out: actual length allocated */
 	int			wasdel,	/* was a delayed allocation extent */
 	xfs_rtxlen_t		prod,	/* extent product factor */
-	xfs_rtblock_t		*rtblock); /* out: start block allocated */
+	xfs_rtxnum_t		*rtblock); /* out: start rtext allocated */
 
 
 /*
@@ -63,7 +63,7 @@ xfs_rtpick_extent(
 	struct xfs_mount	*mp,	/* file system mount point */
 	struct xfs_trans	*tp,	/* transaction pointer */
 	xfs_rtxlen_t		len,	/* allocation length (rtextents) */
-	xfs_rtblock_t		*pick);	/* result rt extent */
+	xfs_rtxnum_t		*pick);	/* result rt extent */
 
 /*
  * Grow the realtime area of the filesystem.


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

* [PATCH 1/7] xfs: create a helper to convert rtextents to rtblocks
  2023-10-11 18:01 ` [PATCHSET RFC v1.0 0/7] xfs: refactor rt extent unit conversions Darrick J. Wong
@ 2023-10-11 18:04   ` Darrick J. Wong
  2023-10-12  5:10     ` Christoph Hellwig
  2023-10-11 18:04   ` [PATCH 2/7] xfs: create a helper to compute leftovers of realtime extents Darrick J. Wong
                     ` (5 subsequent siblings)
  6 siblings, 1 reply; 83+ messages in thread
From: Darrick J. Wong @ 2023-10-11 18:04 UTC (permalink / raw)
  To: djwong; +Cc: linux-xfs, osandov, hch

From: Darrick J. Wong <djwong@kernel.org>

Create a helper to convert a realtime extent to a realtime block.  Later
on we'll change the helper to use bit shifts when possible.

Signed-off-by: Darrick J. Wong <djwong@kernel.org>
---
 fs/xfs/libxfs/xfs_rtbitmap.h |   16 ++++++++++++++++
 fs/xfs/scrub/rtbitmap.c      |    4 ++--
 fs/xfs/scrub/rtsummary.c     |    4 ++--
 fs/xfs/xfs_bmap_util.c       |    9 +++++----
 fs/xfs/xfs_fsmap.c           |    6 +++---
 fs/xfs/xfs_super.c           |    3 ++-
 6 files changed, 30 insertions(+), 12 deletions(-)


diff --git a/fs/xfs/libxfs/xfs_rtbitmap.h b/fs/xfs/libxfs/xfs_rtbitmap.h
index 5e2afb7fea0e7..099ea8902aaaf 100644
--- a/fs/xfs/libxfs/xfs_rtbitmap.h
+++ b/fs/xfs/libxfs/xfs_rtbitmap.h
@@ -6,6 +6,22 @@
 #ifndef __XFS_RTBITMAP_H__
 #define	__XFS_RTBITMAP_H__
 
+static inline xfs_rtblock_t
+xfs_rtx_to_rtb(
+	struct xfs_mount	*mp,
+	xfs_rtxnum_t		rtx)
+{
+	return rtx * mp->m_sb.sb_rextsize;
+}
+
+static inline xfs_extlen_t
+xfs_rtxlen_to_extlen(
+	struct xfs_mount	*mp,
+	xfs_rtxlen_t		rtxlen)
+{
+	return rtxlen * mp->m_sb.sb_rextsize;
+}
+
 /*
  * Functions for walking free space rtextents in the realtime bitmap.
  */
diff --git a/fs/xfs/scrub/rtbitmap.c b/fs/xfs/scrub/rtbitmap.c
index fe871ce224c89..01bc5119d612c 100644
--- a/fs/xfs/scrub/rtbitmap.c
+++ b/fs/xfs/scrub/rtbitmap.c
@@ -62,8 +62,8 @@ xchk_rtbitmap_rec(
 	xfs_rtxnum_t		startblock;
 	xfs_filblks_t		blockcount;
 
-	startblock = rec->ar_startext * mp->m_sb.sb_rextsize;
-	blockcount = rec->ar_extcount * mp->m_sb.sb_rextsize;
+	startblock = xfs_rtx_to_rtb(mp, rec->ar_startext);
+	blockcount = xfs_rtx_to_rtb(mp, rec->ar_extcount);
 
 	if (!xfs_verify_rtbext(mp, startblock, blockcount))
 		xchk_fblock_set_corrupt(sc, XFS_DATA_FORK, 0);
diff --git a/fs/xfs/scrub/rtsummary.c b/fs/xfs/scrub/rtsummary.c
index c03f6e0074d4d..a329470bade8d 100644
--- a/fs/xfs/scrub/rtsummary.c
+++ b/fs/xfs/scrub/rtsummary.c
@@ -146,8 +146,8 @@ xchk_rtsum_record_free(
 	lenlog = XFS_RTBLOCKLOG(rec->ar_extcount);
 	offs = XFS_SUMOFFS(mp, lenlog, rbmoff);
 
-	rtbno = rec->ar_startext * mp->m_sb.sb_rextsize;
-	rtlen = rec->ar_extcount * mp->m_sb.sb_rextsize;
+	rtbno = xfs_rtx_to_rtb(mp, rec->ar_startext);
+	rtlen = xfs_rtx_to_rtb(mp, rec->ar_extcount);
 
 	if (!xfs_verify_rtbext(mp, rtbno, rtlen)) {
 		xchk_ino_xref_set_corrupt(sc, mp->m_rbmip->i_ino);
diff --git a/fs/xfs/xfs_bmap_util.c b/fs/xfs/xfs_bmap_util.c
index 285e9cafe29ef..cd4136b2b39c4 100644
--- a/fs/xfs/xfs_bmap_util.c
+++ b/fs/xfs/xfs_bmap_util.c
@@ -29,6 +29,7 @@
 #include "xfs_iomap.h"
 #include "xfs_reflink.h"
 #include "xfs_swapext.h"
+#include "xfs_rtbitmap.h"
 
 /* Kernel only BMAP related definitions and functions */
 
@@ -126,7 +127,7 @@ xfs_bmap_rtalloc(
 	 * XFS_BMBT_MAX_EXTLEN), we don't hear about that number, and can't
 	 * adjust the starting point to match it.
 	 */
-	if (ralen * mp->m_sb.sb_rextsize >= XFS_MAX_BMBT_EXTLEN)
+	if (xfs_rtxlen_to_extlen(mp, ralen) >= XFS_MAX_BMBT_EXTLEN)
 		ralen = XFS_MAX_BMBT_EXTLEN / mp->m_sb.sb_rextsize;
 
 	/*
@@ -148,7 +149,7 @@ xfs_bmap_rtalloc(
 		error = xfs_rtpick_extent(mp, ap->tp, ralen, &rtx);
 		if (error)
 			return error;
-		ap->blkno = rtx * mp->m_sb.sb_rextsize;
+		ap->blkno = xfs_rtx_to_rtb(mp, rtx);
 	} else {
 		ap->blkno = 0;
 	}
@@ -171,8 +172,8 @@ xfs_bmap_rtalloc(
 		return error;
 
 	if (rtx != NULLRTEXTNO) {
-		ap->blkno = rtx * mp->m_sb.sb_rextsize;
-		ap->length = ralen * mp->m_sb.sb_rextsize;
+		ap->blkno = xfs_rtx_to_rtb(mp, rtx);
+		ap->length = xfs_rtxlen_to_extlen(mp, ralen);
 		ap->ip->i_nblocks += ap->length;
 		xfs_trans_log_inode(ap->tp, ap->ip, XFS_ILOG_CORE);
 		if (ap->wasdel)
diff --git a/fs/xfs/xfs_fsmap.c b/fs/xfs/xfs_fsmap.c
index 8982c5d6cbd06..1a187bc9da3de 100644
--- a/fs/xfs/xfs_fsmap.c
+++ b/fs/xfs/xfs_fsmap.c
@@ -483,11 +483,11 @@ xfs_getfsmap_rtdev_rtbitmap_helper(
 	xfs_rtblock_t			rtbno;
 	xfs_daddr_t			rec_daddr, len_daddr;
 
-	rtbno = rec->ar_startext * mp->m_sb.sb_rextsize;
+	rtbno = xfs_rtx_to_rtb(mp, rec->ar_startext);
 	rec_daddr = XFS_FSB_TO_BB(mp, rtbno);
 	irec.rm_startblock = rtbno;
 
-	rtbno = rec->ar_extcount * mp->m_sb.sb_rextsize;
+	rtbno = xfs_rtx_to_rtb(mp, rec->ar_extcount);
 	len_daddr = XFS_FSB_TO_BB(mp, rtbno);
 	irec.rm_blockcount = rtbno;
 
@@ -514,7 +514,7 @@ xfs_getfsmap_rtdev_rtbitmap(
 	uint64_t			eofs;
 	int				error;
 
-	eofs = XFS_FSB_TO_BB(mp, mp->m_sb.sb_rextents * mp->m_sb.sb_rextsize);
+	eofs = XFS_FSB_TO_BB(mp, xfs_rtx_to_rtb(mp, mp->m_sb.sb_rextents));
 	if (keys[0].fmr_physical >= eofs)
 		return 0;
 	start_rtb = XFS_BB_TO_FSBT(mp,
diff --git a/fs/xfs/xfs_super.c b/fs/xfs/xfs_super.c
index e352c78059e7f..f19117f76b9f4 100644
--- a/fs/xfs/xfs_super.c
+++ b/fs/xfs/xfs_super.c
@@ -44,6 +44,7 @@
 #include "xfs_dahash_test.h"
 #include "xfs_swapext_item.h"
 #include "xfs_parent.h"
+#include "xfs_rtbitmap.h"
 #include "scrub/stats.h"
 #include "scrub/rcbag_btree.h"
 
@@ -893,7 +894,7 @@ xfs_fs_statfs(
 
 		statp->f_blocks = sbp->sb_rblocks;
 		freertx = percpu_counter_sum_positive(&mp->m_frextents);
-		statp->f_bavail = statp->f_bfree = freertx * sbp->sb_rextsize;
+		statp->f_bavail = statp->f_bfree = xfs_rtx_to_rtb(mp, freertx);
 	}
 
 	return 0;


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

* [PATCH 2/7] xfs: create a helper to compute leftovers of realtime extents
  2023-10-11 18:01 ` [PATCHSET RFC v1.0 0/7] xfs: refactor rt extent unit conversions Darrick J. Wong
  2023-10-11 18:04   ` [PATCH 1/7] xfs: create a helper to convert rtextents to rtblocks Darrick J. Wong
@ 2023-10-11 18:04   ` Darrick J. Wong
  2023-10-12  5:11     ` Christoph Hellwig
  2023-10-11 18:05   ` [PATCH 3/7] " Darrick J. Wong
                     ` (4 subsequent siblings)
  6 siblings, 1 reply; 83+ messages in thread
From: Darrick J. Wong @ 2023-10-11 18:04 UTC (permalink / raw)
  To: djwong; +Cc: linux-xfs, osandov, hch

From: Darrick J. Wong <djwong@kernel.org>

Create a helper to compute the misalignment between a file extent
(xfs_extlen_t) and a realtime extent.

Signed-off-by: Darrick J. Wong <djwong@kernel.org>
---
 fs/xfs/libxfs/xfs_bmap.c        |    4 ++--
 fs/xfs/libxfs/xfs_rtbitmap.h    |    9 +++++++++
 fs/xfs/libxfs/xfs_trans_inode.c |    1 +
 fs/xfs/scrub/inode.c            |    3 ++-
 fs/xfs/scrub/inode_repair.c     |    3 ++-
 fs/xfs/xfs_bmap_util.c          |    2 +-
 fs/xfs/xfs_inode_item.c         |    3 ++-
 fs/xfs/xfs_ioctl.c              |    5 +++--
 8 files changed, 22 insertions(+), 8 deletions(-)


diff --git a/fs/xfs/libxfs/xfs_bmap.c b/fs/xfs/libxfs/xfs_bmap.c
index fd083a3c554e0..82dc95944374e 100644
--- a/fs/xfs/libxfs/xfs_bmap.c
+++ b/fs/xfs/libxfs/xfs_bmap.c
@@ -3038,7 +3038,7 @@ xfs_bmap_extsize_align(
 	 * If realtime, and the result isn't a multiple of the realtime
 	 * extent size we need to remove blocks until it is.
 	 */
-	if (rt && (temp = (align_alen % mp->m_sb.sb_rextsize))) {
+	if (rt && (temp = xfs_extlen_to_rtxmod(mp, align_alen))) {
 		/*
 		 * We're not covering the original request, or
 		 * we won't be able to once we fix the length.
@@ -3065,7 +3065,7 @@ xfs_bmap_extsize_align(
 		else {
 			align_alen -= orig_off - align_off;
 			align_off = orig_off;
-			align_alen -= align_alen % mp->m_sb.sb_rextsize;
+			align_alen -= xfs_extlen_to_rtxmod(mp, align_alen);
 		}
 		/*
 		 * Result doesn't cover the request, fail it.
diff --git a/fs/xfs/libxfs/xfs_rtbitmap.h b/fs/xfs/libxfs/xfs_rtbitmap.h
index 099ea8902aaaf..b6a4c46bddc0a 100644
--- a/fs/xfs/libxfs/xfs_rtbitmap.h
+++ b/fs/xfs/libxfs/xfs_rtbitmap.h
@@ -22,6 +22,15 @@ xfs_rtxlen_to_extlen(
 	return rtxlen * mp->m_sb.sb_rextsize;
 }
 
+/* Compute the misalignment between an extent length and a realtime extent .*/
+static inline unsigned int
+xfs_extlen_to_rtxmod(
+	struct xfs_mount	*mp,
+	xfs_extlen_t		len)
+{
+	return len % mp->m_sb.sb_rextsize;
+}
+
 /*
  * Functions for walking free space rtextents in the realtime bitmap.
  */
diff --git a/fs/xfs/libxfs/xfs_trans_inode.c b/fs/xfs/libxfs/xfs_trans_inode.c
index 3e07e7c6a5d53..29f1aa290ce6d 100644
--- a/fs/xfs/libxfs/xfs_trans_inode.c
+++ b/fs/xfs/libxfs/xfs_trans_inode.c
@@ -14,6 +14,7 @@
 #include "xfs_trans.h"
 #include "xfs_trans_priv.h"
 #include "xfs_inode_item.h"
+#include "xfs_rtbitmap.h"
 
 #include <linux/iversion.h>
 
diff --git a/fs/xfs/scrub/inode.c b/fs/xfs/scrub/inode.c
index 3cb75c559a32f..e8da1ae3c5c01 100644
--- a/fs/xfs/scrub/inode.c
+++ b/fs/xfs/scrub/inode.c
@@ -20,6 +20,7 @@
 #include "xfs_reflink.h"
 #include "xfs_rmap.h"
 #include "xfs_bmap_util.h"
+#include "xfs_rtbitmap.h"
 #include "scrub/scrub.h"
 #include "scrub/common.h"
 #include "scrub/btree.h"
@@ -254,7 +255,7 @@ xchk_inode_extsize(
 	 */
 	if ((flags & XFS_DIFLAG_RTINHERIT) &&
 	    (flags & XFS_DIFLAG_EXTSZINHERIT) &&
-	    value % sc->mp->m_sb.sb_rextsize > 0)
+	    xfs_extlen_to_rtxmod(sc->mp, value) > 0)
 		xchk_ino_set_warning(sc, ino);
 }
 
diff --git a/fs/xfs/scrub/inode_repair.c b/fs/xfs/scrub/inode_repair.c
index 6787abbc6d6ff..7f1f7cec822a2 100644
--- a/fs/xfs/scrub/inode_repair.c
+++ b/fs/xfs/scrub/inode_repair.c
@@ -36,6 +36,7 @@
 #include "xfs_attr_leaf.h"
 #include "xfs_log_priv.h"
 #include "xfs_symlink_remote.h"
+#include "xfs_rtbitmap.h"
 #include "scrub/xfs_scrub.h"
 #include "scrub/scrub.h"
 #include "scrub/common.h"
@@ -1599,7 +1600,7 @@ xrep_inode_extsize(
 	/* Fix misaligned extent size hints on a directory. */
 	if ((sc->ip->i_diflags & XFS_DIFLAG_RTINHERIT) &&
 	    (sc->ip->i_diflags & XFS_DIFLAG_EXTSZINHERIT) &&
-	    sc->ip->i_extsize % sc->mp->m_sb.sb_rextsize > 0) {
+	    xfs_extlen_to_rtxmod(sc->mp, sc->ip->i_extsize) > 0) {
 		sc->ip->i_extsize = 0;
 		sc->ip->i_diflags &= ~XFS_DIFLAG_EXTSZINHERIT;
 	}
diff --git a/fs/xfs/xfs_bmap_util.c b/fs/xfs/xfs_bmap_util.c
index cd4136b2b39c4..0590d55cd88f6 100644
--- a/fs/xfs/xfs_bmap_util.c
+++ b/fs/xfs/xfs_bmap_util.c
@@ -98,7 +98,7 @@ xfs_bmap_rtalloc(
 	if (error)
 		return error;
 	ASSERT(ap->length);
-	ASSERT(ap->length % mp->m_sb.sb_rextsize == 0);
+	ASSERT(xfs_extlen_to_rtxmod(mp, ap->length) == 0);
 
 	/*
 	 * If we shifted the file offset downward to satisfy an extent size
diff --git a/fs/xfs/xfs_inode_item.c b/fs/xfs/xfs_inode_item.c
index 127b2410eb206..3183d0b03e0bc 100644
--- a/fs/xfs/xfs_inode_item.c
+++ b/fs/xfs/xfs_inode_item.c
@@ -19,6 +19,7 @@
 #include "xfs_log.h"
 #include "xfs_log_priv.h"
 #include "xfs_error.h"
+#include "xfs_rtbitmap.h"
 
 #include <linux/iversion.h>
 
@@ -107,7 +108,7 @@ xfs_inode_item_precommit(
 	 */
 	if ((ip->i_diflags & XFS_DIFLAG_RTINHERIT) &&
 	    (ip->i_diflags & XFS_DIFLAG_EXTSZINHERIT) &&
-	    (ip->i_extsize % ip->i_mount->m_sb.sb_rextsize) > 0) {
+	    xfs_extlen_to_rtxmod(ip->i_mount, ip->i_extsize) > 0) {
 		ip->i_diflags &= ~(XFS_DIFLAG_EXTSIZE |
 				   XFS_DIFLAG_EXTSZINHERIT);
 		ip->i_extsize = 0;
diff --git a/fs/xfs/xfs_ioctl.c b/fs/xfs/xfs_ioctl.c
index a2c7508527f8c..cbfa8500e2354 100644
--- a/fs/xfs/xfs_ioctl.c
+++ b/fs/xfs/xfs_ioctl.c
@@ -41,6 +41,7 @@
 #include "xfs_xattr.h"
 #include "xfs_xchgrange.h"
 #include "xfs_file.h"
+#include "xfs_rtbitmap.h"
 
 #include <linux/mount.h>
 #include <linux/namei.h>
@@ -1017,7 +1018,7 @@ xfs_fill_fsxattr(
 		 * later.
 		 */
 		if ((ip->i_diflags & XFS_DIFLAG_RTINHERIT) &&
-		    ip->i_extsize % mp->m_sb.sb_rextsize > 0) {
+		    xfs_extlen_to_rtxmod(mp, ip->i_extsize) > 0) {
 			fa->fsx_xflags &= ~(FS_XFLAG_EXTSIZE |
 					    FS_XFLAG_EXTSZINHERIT);
 			fa->fsx_extsize = 0;
@@ -1083,7 +1084,7 @@ xfs_ioctl_setattr_xflags(
 	/* If realtime flag is set then must have realtime device */
 	if (fa->fsx_xflags & FS_XFLAG_REALTIME) {
 		if (mp->m_sb.sb_rblocks == 0 || mp->m_sb.sb_rextsize == 0 ||
-		    (ip->i_extsize % mp->m_sb.sb_rextsize))
+		    xfs_extlen_to_rtxmod(mp, ip->i_extsize))
 			return -EINVAL;
 	}
 


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

* [PATCH 3/7] xfs: create a helper to compute leftovers of realtime extents
  2023-10-11 18:01 ` [PATCHSET RFC v1.0 0/7] xfs: refactor rt extent unit conversions Darrick J. Wong
  2023-10-11 18:04   ` [PATCH 1/7] xfs: create a helper to convert rtextents to rtblocks Darrick J. Wong
  2023-10-11 18:04   ` [PATCH 2/7] xfs: create a helper to compute leftovers of realtime extents Darrick J. Wong
@ 2023-10-11 18:05   ` Darrick J. Wong
  2023-10-12  6:34     ` Christoph Hellwig
  2023-10-11 18:05   ` [PATCH 4/7] xfs: create helpers to convert rt block numbers to rt extent numbers Darrick J. Wong
                     ` (3 subsequent siblings)
  6 siblings, 1 reply; 83+ messages in thread
From: Darrick J. Wong @ 2023-10-11 18:05 UTC (permalink / raw)
  To: djwong; +Cc: linux-xfs, osandov, hch

From: Darrick J. Wong <djwong@kernel.org>

Create a helper to compute the realtime extent (xfs_rtxlen_t) from an
extent length (xfs_extlen_t) value.

Signed-off-by: Darrick J. Wong <djwong@kernel.org>
---
 fs/xfs/libxfs/xfs_rtbitmap.h   |    8 ++++++++
 fs/xfs/libxfs/xfs_trans_resv.c |    3 ++-
 fs/xfs/xfs_bmap_util.c         |   11 ++++-------
 fs/xfs/xfs_trans.c             |    5 +++--
 4 files changed, 17 insertions(+), 10 deletions(-)


diff --git a/fs/xfs/libxfs/xfs_rtbitmap.h b/fs/xfs/libxfs/xfs_rtbitmap.h
index b6a4c46bddc0a..e2a36fc157c4c 100644
--- a/fs/xfs/libxfs/xfs_rtbitmap.h
+++ b/fs/xfs/libxfs/xfs_rtbitmap.h
@@ -31,6 +31,14 @@ xfs_extlen_to_rtxmod(
 	return len % mp->m_sb.sb_rextsize;
 }
 
+static inline xfs_rtxlen_t
+xfs_extlen_to_rtxlen(
+	struct xfs_mount	*mp,
+	xfs_extlen_t		len)
+{
+	return len / mp->m_sb.sb_rextsize;
+}
+
 /*
  * Functions for walking free space rtextents in the realtime bitmap.
  */
diff --git a/fs/xfs/libxfs/xfs_trans_resv.c b/fs/xfs/libxfs/xfs_trans_resv.c
index 328c569c20a35..9c3dbcbe05358 100644
--- a/fs/xfs/libxfs/xfs_trans_resv.c
+++ b/fs/xfs/libxfs/xfs_trans_resv.c
@@ -22,6 +22,7 @@
 #include "xfs_attr_item.h"
 #include "xfs_log.h"
 #include "xfs_da_format.h"
+#include "xfs_rtbitmap.h"
 
 #define _ALLOC	true
 #define _FREE	false
@@ -223,7 +224,7 @@ xfs_rtalloc_block_count(
 	unsigned int		blksz = XFS_FSB_TO_B(mp, 1);
 	unsigned int		rtbmp_bytes;
 
-	rtbmp_bytes = (XFS_MAX_BMBT_EXTLEN / mp->m_sb.sb_rextsize) / NBBY;
+	rtbmp_bytes = xfs_extlen_to_rtxlen(mp, XFS_MAX_BMBT_EXTLEN) / NBBY;
 	return (howmany(rtbmp_bytes, blksz) + 1) * num_ops;
 }
 
diff --git a/fs/xfs/xfs_bmap_util.c b/fs/xfs/xfs_bmap_util.c
index 0590d55cd88f6..c246f25aaad55 100644
--- a/fs/xfs/xfs_bmap_util.c
+++ b/fs/xfs/xfs_bmap_util.c
@@ -91,7 +91,7 @@ xfs_bmap_rtalloc(
 
 	align = xfs_get_extsz_hint(ap->ip);
 retry:
-	prod = align / mp->m_sb.sb_rextsize;
+	prod = xfs_extlen_to_rtxlen(mp, align);
 	error = xfs_bmap_extsize_align(mp, &ap->got, &ap->prev,
 					align, 1, ap->eof, 0,
 					ap->conv, &ap->offset, &ap->length);
@@ -118,17 +118,14 @@ xfs_bmap_rtalloc(
 		prod = 1;
 	/*
 	 * Set ralen to be the actual requested length in rtextents.
-	 */
-	ralen = ap->length / mp->m_sb.sb_rextsize;
-	/*
+	 *
 	 * If the old value was close enough to XFS_BMBT_MAX_EXTLEN that
 	 * we rounded up to it, cut it back so it's valid again.
 	 * Note that if it's a really large request (bigger than
 	 * XFS_BMBT_MAX_EXTLEN), we don't hear about that number, and can't
 	 * adjust the starting point to match it.
 	 */
-	if (xfs_rtxlen_to_extlen(mp, ralen) >= XFS_MAX_BMBT_EXTLEN)
-		ralen = XFS_MAX_BMBT_EXTLEN / mp->m_sb.sb_rextsize;
+	ralen = xfs_extlen_to_rtxlen(mp, min(ap->length, XFS_MAX_BMBT_EXTLEN));
 
 	/*
 	 * Lock out modifications to both the RT bitmap and summary inodes
@@ -165,7 +162,7 @@ xfs_bmap_rtalloc(
 		do_div(ap->blkno, mp->m_sb.sb_rextsize);
 	rtx = ap->blkno;
 	ap->length = ralen;
-	raminlen = max_t(xfs_extlen_t, 1, minlen / mp->m_sb.sb_rextsize);
+	raminlen = max_t(xfs_rtxlen_t, 1, xfs_extlen_to_rtxlen(mp, minlen));
 	error = xfs_rtallocate_extent(ap->tp, ap->blkno, raminlen, ap->length,
 			&ralen, ap->wasdel, prod, &rtx);
 	if (error)
diff --git a/fs/xfs/xfs_trans.c b/fs/xfs/xfs_trans.c
index ea045af01f5e8..22aa2111b6cab 100644
--- a/fs/xfs/xfs_trans.c
+++ b/fs/xfs/xfs_trans.c
@@ -24,6 +24,7 @@
 #include "xfs_dquot_item.h"
 #include "xfs_dquot.h"
 #include "xfs_icache.h"
+#include "xfs_rtbitmap.h"
 
 struct kmem_cache	*xfs_trans_cache;
 
@@ -1252,7 +1253,7 @@ xfs_trans_alloc_inode(
 
 retry:
 	error = xfs_trans_alloc(mp, resv, dblocks,
-			rblocks / mp->m_sb.sb_rextsize,
+			xfs_extlen_to_rtxlen(mp, rblocks),
 			force ? XFS_TRANS_RESERVE : 0, &tp);
 	if (error)
 		return error;
@@ -1298,7 +1299,7 @@ xfs_trans_reserve_more_inode(
 	bool			force_quota)
 {
 	struct xfs_mount	*mp = ip->i_mount;
-	unsigned int		rtx = rblocks / mp->m_sb.sb_rextsize;
+	unsigned int		rtx = xfs_extlen_to_rtxlen(mp, rblocks);
 	int			error;
 
 	ASSERT(xfs_isilocked(ip, XFS_ILOCK_EXCL));


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

* [PATCH 4/7] xfs: create helpers to convert rt block numbers to rt extent numbers
  2023-10-11 18:01 ` [PATCHSET RFC v1.0 0/7] xfs: refactor rt extent unit conversions Darrick J. Wong
                     ` (2 preceding siblings ...)
  2023-10-11 18:05   ` [PATCH 3/7] " Darrick J. Wong
@ 2023-10-11 18:05   ` Darrick J. Wong
  2023-10-12  5:17     ` Christoph Hellwig
  2023-10-11 18:05   ` [PATCH 5/7] xfs: convert do_div calls to xfs_rtb_to_rtx helper calls Darrick J. Wong
                     ` (2 subsequent siblings)
  6 siblings, 1 reply; 83+ messages in thread
From: Darrick J. Wong @ 2023-10-11 18:05 UTC (permalink / raw)
  To: djwong; +Cc: linux-xfs, osandov, hch

From: Darrick J. Wong <djwong@kernel.org>

Create helpers to do unit conversions of rt block numbers to rt extent
numbers.  There are two variations -- the suffix "t" denotes the one
that returns only the truncated extent number; the other one also
returns the misalignment.  Convert all the div_u64_rem users; we'll do
the do_div users in the next patch.

Signed-off-by: Darrick J. Wong <djwong@kernel.org>
---
 fs/xfs/libxfs/xfs_bmap.c     |    7 +++----
 fs/xfs/libxfs/xfs_rtbitmap.c |    4 ++--
 fs/xfs/libxfs/xfs_rtbitmap.h |   17 +++++++++++++++++
 fs/xfs/libxfs/xfs_swapext.c  |    7 ++++---
 fs/xfs/xfs_rtalloc.c         |    8 ++++----
 5 files changed, 30 insertions(+), 13 deletions(-)


diff --git a/fs/xfs/libxfs/xfs_bmap.c b/fs/xfs/libxfs/xfs_bmap.c
index 82dc95944374e..463174af94333 100644
--- a/fs/xfs/libxfs/xfs_bmap.c
+++ b/fs/xfs/libxfs/xfs_bmap.c
@@ -5336,7 +5336,6 @@ __xfs_bunmapi(
 	int			tmp_logflags;	/* partial logging flags */
 	int			wasdel;		/* was a delayed alloc extent */
 	int			whichfork;	/* data or attribute fork */
-	xfs_fsblock_t		sum;
 	xfs_filblks_t		len = *rlen;	/* length to unmap in file */
 	xfs_fileoff_t		end;
 	struct xfs_iext_cursor	icur;
@@ -5433,8 +5432,7 @@ __xfs_bunmapi(
 		if (!isrt || (flags & XFS_BMAPI_REMAP))
 			goto delete;
 
-		sum = del.br_startblock + del.br_blockcount;
-		div_u64_rem(sum, mp->m_sb.sb_rextsize, &mod);
+		xfs_rtb_to_rtx(mp, del.br_startblock + del.br_blockcount, &mod);
 		if (mod) {
 			/*
 			 * Realtime extent not lined up at the end.
@@ -5481,7 +5479,8 @@ __xfs_bunmapi(
 				goto error0;
 			goto nodelete;
 		}
-		div_u64_rem(del.br_startblock, mp->m_sb.sb_rextsize, &mod);
+
+		xfs_rtb_to_rtx(mp, del.br_startblock, &mod);
 		if (mod) {
 			xfs_extlen_t off = mp->m_sb.sb_rextsize - mod;
 
diff --git a/fs/xfs/libxfs/xfs_rtbitmap.c b/fs/xfs/libxfs/xfs_rtbitmap.c
index ce14436811319..de54386cf52f3 100644
--- a/fs/xfs/libxfs/xfs_rtbitmap.c
+++ b/fs/xfs/libxfs/xfs_rtbitmap.c
@@ -1031,13 +1031,13 @@ xfs_rtfree_blocks(
 
 	ASSERT(rtlen <= XFS_MAX_BMBT_EXTLEN);
 
-	len = div_u64_rem(rtlen, mp->m_sb.sb_rextsize, &mod);
+	len = xfs_rtb_to_rtx(mp, rtlen, &mod);
 	if (mod) {
 		ASSERT(mod == 0);
 		return -EIO;
 	}
 
-	start = div_u64_rem(rtbno, mp->m_sb.sb_rextsize, &mod);
+	start = xfs_rtb_to_rtx(mp, rtbno, &mod);
 	if (mod) {
 		ASSERT(mod == 0);
 		return -EIO;
diff --git a/fs/xfs/libxfs/xfs_rtbitmap.h b/fs/xfs/libxfs/xfs_rtbitmap.h
index e2a36fc157c4c..bdd4858a794c2 100644
--- a/fs/xfs/libxfs/xfs_rtbitmap.h
+++ b/fs/xfs/libxfs/xfs_rtbitmap.h
@@ -39,6 +39,23 @@ xfs_extlen_to_rtxlen(
 	return len / mp->m_sb.sb_rextsize;
 }
 
+static inline xfs_rtxnum_t
+xfs_rtb_to_rtx(
+	struct xfs_mount	*mp,
+	xfs_rtblock_t		rtbno,
+	xfs_extlen_t		*mod)
+{
+	return div_u64_rem(rtbno, mp->m_sb.sb_rextsize, mod);
+}
+
+static inline xfs_rtxnum_t
+xfs_rtb_to_rtxt(
+	struct xfs_mount	*mp,
+	xfs_rtblock_t		rtbno)
+{
+	return div_u64(rtbno, mp->m_sb.sb_rextsize);
+}
+
 /*
  * Functions for walking free space rtextents in the realtime bitmap.
  */
diff --git a/fs/xfs/libxfs/xfs_swapext.c b/fs/xfs/libxfs/xfs_swapext.c
index b1d66e0cfac91..6107ec7d8d568 100644
--- a/fs/xfs/libxfs/xfs_swapext.c
+++ b/fs/xfs/libxfs/xfs_swapext.c
@@ -30,6 +30,7 @@
 #include "xfs_dir2_priv.h"
 #include "xfs_dir2.h"
 #include "xfs_symlink_remote.h"
+#include "xfs_rtbitmap.h"
 
 struct kmem_cache	*xfs_swapext_intent_cache;
 
@@ -202,19 +203,19 @@ xfs_swapext_check_rt_extents(
 					  irec2.br_blockcount);
 
 		/* Both mappings must be aligned to the realtime extent size. */
-		div_u64_rem(irec1.br_startoff, mp->m_sb.sb_rextsize, &mod);
+		xfs_rtb_to_rtx(mp, irec1.br_startoff, &mod);
 		if (mod) {
 			ASSERT(mod == 0);
 			return -EINVAL;
 		}
 
-		div_u64_rem(irec2.br_startoff, mp->m_sb.sb_rextsize, &mod);
+		xfs_rtb_to_rtx(mp, irec1.br_startoff, &mod);
 		if (mod) {
 			ASSERT(mod == 0);
 			return -EINVAL;
 		}
 
-		div_u64_rem(irec1.br_blockcount, mp->m_sb.sb_rextsize, &mod);
+		xfs_rtb_to_rtx(mp, irec1.br_blockcount, &mod);
 		if (mod) {
 			ASSERT(mod == 0);
 			return -EINVAL;
diff --git a/fs/xfs/xfs_rtalloc.c b/fs/xfs/xfs_rtalloc.c
index 4bb776911a4fb..d3a5112f21156 100644
--- a/fs/xfs/xfs_rtalloc.c
+++ b/fs/xfs/xfs_rtalloc.c
@@ -1496,16 +1496,16 @@ xfs_rtfile_want_conversion(
 	struct xfs_bmbt_irec	*irec)
 {
 	xfs_fileoff_t		rext_next;
-	uint32_t		modoff, modcnt;
+	xfs_extlen_t		modoff, modcnt;
 
 	if (irec->br_state != XFS_EXT_UNWRITTEN)
 		return false;
 
-	div_u64_rem(irec->br_startoff, mp->m_sb.sb_rextsize, &modoff);
+	xfs_rtb_to_rtx(mp, irec->br_startoff, &modoff);
 	if (modoff == 0) {
-		uint64_t	rexts = div_u64_rem(irec->br_blockcount,
-						mp->m_sb.sb_rextsize, &modcnt);
+		xfs_rtbxlen_t	rexts;
 
+		rexts = xfs_rtb_to_rtx(mp, irec->br_blockcount, &modcnt);
 		if (rexts > 0) {
 			/*
 			 * Unwritten mapping starts at an rt extent boundary


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

* [PATCH 5/7] xfs: convert do_div calls to xfs_rtb_to_rtx helper calls
  2023-10-11 18:01 ` [PATCHSET RFC v1.0 0/7] xfs: refactor rt extent unit conversions Darrick J. Wong
                     ` (3 preceding siblings ...)
  2023-10-11 18:05   ` [PATCH 4/7] xfs: create helpers to convert rt block numbers to rt extent numbers Darrick J. Wong
@ 2023-10-11 18:05   ` Darrick J. Wong
  2023-10-12  5:22     ` Christoph Hellwig
  2023-10-11 18:05   ` [PATCH 6/7] xfs: create rt extent rounding helpers for realtime extent blocks Darrick J. Wong
  2023-10-11 18:06   ` [PATCH 7/7] xfs: use shifting and masking when converting rt extents, if possible Darrick J. Wong
  6 siblings, 1 reply; 83+ messages in thread
From: Darrick J. Wong @ 2023-10-11 18:05 UTC (permalink / raw)
  To: djwong; +Cc: linux-xfs, osandov, hch

From: Darrick J. Wong <djwong@kernel.org>

Convert these calls to use the helpers, and clean up all these places
where the same variable can have different units depending on where it
is in the function.

Signed-off-by: Darrick J. Wong <djwong@kernel.org>
---
 fs/xfs/libxfs/xfs_bmap.c |    8 ++------
 fs/xfs/scrub/rtbitmap.c  |   14 +++++---------
 fs/xfs/xfs_bmap_util.c   |   10 ++++------
 fs/xfs/xfs_fsmap.c       |    8 ++++----
 fs/xfs/xfs_rtalloc.c     |    3 +--
 5 files changed, 16 insertions(+), 27 deletions(-)


diff --git a/fs/xfs/libxfs/xfs_bmap.c b/fs/xfs/libxfs/xfs_bmap.c
index 463174af94333..d322fd5116179 100644
--- a/fs/xfs/libxfs/xfs_bmap.c
+++ b/fs/xfs/libxfs/xfs_bmap.c
@@ -4883,12 +4883,8 @@ xfs_bmap_del_extent_delay(
 	ASSERT(got->br_startoff <= del->br_startoff);
 	ASSERT(got_endoff >= del_endoff);
 
-	if (isrt) {
-		uint64_t rtexts = XFS_FSB_TO_B(mp, del->br_blockcount);
-
-		do_div(rtexts, mp->m_sb.sb_rextsize);
-		xfs_mod_frextents(mp, rtexts);
-	}
+	if (isrt)
+		xfs_mod_frextents(mp, xfs_rtb_to_rtxt(mp, del->br_blockcount));
 
 	/*
 	 * Update the inode delalloc counter now and wait to update the
diff --git a/fs/xfs/scrub/rtbitmap.c b/fs/xfs/scrub/rtbitmap.c
index 01bc5119d612c..a785fb5f317dd 100644
--- a/fs/xfs/scrub/rtbitmap.c
+++ b/fs/xfs/scrub/rtbitmap.c
@@ -140,26 +140,22 @@ xchk_rtbitmap(
 void
 xchk_xref_is_used_rt_space(
 	struct xfs_scrub	*sc,
-	xfs_rtblock_t		fsbno,
+	xfs_rtblock_t		rtbno,
 	xfs_extlen_t		len)
 {
 	xfs_rtxnum_t		startext;
 	xfs_rtxnum_t		endext;
-	xfs_rtxlen_t		extcount;
 	bool			is_free;
 	int			error;
 
 	if (xchk_skip_xref(sc->sm))
 		return;
 
-	startext = fsbno;
-	endext = fsbno + len - 1;
-	do_div(startext, sc->mp->m_sb.sb_rextsize);
-	do_div(endext, sc->mp->m_sb.sb_rextsize);
-	extcount = endext - startext + 1;
+	startext = xfs_rtb_to_rtxt(sc->mp, rtbno);
+	endext = xfs_rtb_to_rtxt(sc->mp, rtbno + len - 1);
 	xfs_ilock(sc->mp->m_rbmip, XFS_ILOCK_SHARED | XFS_ILOCK_RTBITMAP);
-	error = xfs_rtalloc_extent_is_free(sc->mp, sc->tp, startext, extcount,
-			&is_free);
+	error = xfs_rtalloc_extent_is_free(sc->mp, sc->tp, startext,
+			endext - startext + 1, &is_free);
 	if (!xchk_should_check_xref(sc, &error, NULL))
 		goto out_unlock;
 	if (is_free)
diff --git a/fs/xfs/xfs_bmap_util.c b/fs/xfs/xfs_bmap_util.c
index c246f25aaad55..8f1e16e49dab2 100644
--- a/fs/xfs/xfs_bmap_util.c
+++ b/fs/xfs/xfs_bmap_util.c
@@ -157,14 +157,12 @@ xfs_bmap_rtalloc(
 	 * Realtime allocation, done through xfs_rtallocate_extent.
 	 */
 	if (ignore_locality)
-		ap->blkno = 0;
+		rtx = 0;
 	else
-		do_div(ap->blkno, mp->m_sb.sb_rextsize);
-	rtx = ap->blkno;
-	ap->length = ralen;
+		rtx = xfs_rtb_to_rtxt(mp, ap->blkno);
 	raminlen = max_t(xfs_rtxlen_t, 1, xfs_extlen_to_rtxlen(mp, minlen));
-	error = xfs_rtallocate_extent(ap->tp, ap->blkno, raminlen, ap->length,
-			&ralen, ap->wasdel, prod, &rtx);
+	error = xfs_rtallocate_extent(ap->tp, rtx, raminlen, ralen, &ralen,
+			ap->wasdel, prod, &rtx);
 	if (error)
 		return error;
 
diff --git a/fs/xfs/xfs_fsmap.c b/fs/xfs/xfs_fsmap.c
index 1a187bc9da3de..32aefaf7d6684 100644
--- a/fs/xfs/xfs_fsmap.c
+++ b/fs/xfs/xfs_fsmap.c
@@ -512,6 +512,7 @@ xfs_getfsmap_rtdev_rtbitmap(
 	xfs_rtblock_t			start_rtb;
 	xfs_rtblock_t			end_rtb;
 	uint64_t			eofs;
+	xfs_extlen_t			mod;
 	int				error;
 
 	eofs = XFS_FSB_TO_BB(mp, xfs_rtx_to_rtb(mp, mp->m_sb.sb_rextents));
@@ -539,10 +540,9 @@ xfs_getfsmap_rtdev_rtbitmap(
 	 * Set up query parameters to return free rtextents covering the range
 	 * we want.
 	 */
-	alow.ar_startext = start_rtb;
-	ahigh.ar_startext = end_rtb;
-	do_div(alow.ar_startext, mp->m_sb.sb_rextsize);
-	if (do_div(ahigh.ar_startext, mp->m_sb.sb_rextsize))
+	alow.ar_startext = xfs_rtb_to_rtxt(mp, start_rtb);
+	ahigh.ar_startext = xfs_rtb_to_rtx(mp, end_rtb, &mod);
+	if (mod)
 		ahigh.ar_startext++;
 	error = xfs_rtalloc_query_range(mp, tp, &alow, &ahigh,
 			xfs_getfsmap_rtdev_rtbitmap_helper, info);
diff --git a/fs/xfs/xfs_rtalloc.c b/fs/xfs/xfs_rtalloc.c
index d3a5112f21156..8db8f957a683b 100644
--- a/fs/xfs/xfs_rtalloc.c
+++ b/fs/xfs/xfs_rtalloc.c
@@ -1056,8 +1056,7 @@ xfs_growfs_rt(
 		nrblocks_step = (bmbno + 1) * NBBY * nsbp->sb_blocksize *
 				nsbp->sb_rextsize;
 		nsbp->sb_rblocks = min(nrblocks, nrblocks_step);
-		nsbp->sb_rextents = nsbp->sb_rblocks;
-		do_div(nsbp->sb_rextents, nsbp->sb_rextsize);
+		nsbp->sb_rextents = xfs_rtb_to_rtxt(nmp, nsbp->sb_rblocks);
 		ASSERT(nsbp->sb_rextents != 0);
 		nsbp->sb_rextslog = xfs_highbit32(nsbp->sb_rextents);
 		nrsumlevels = nmp->m_rsumlevels = nsbp->sb_rextslog + 1;


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

* [PATCH 6/7] xfs: create rt extent rounding helpers for realtime extent blocks
  2023-10-11 18:01 ` [PATCHSET RFC v1.0 0/7] xfs: refactor rt extent unit conversions Darrick J. Wong
                     ` (4 preceding siblings ...)
  2023-10-11 18:05   ` [PATCH 5/7] xfs: convert do_div calls to xfs_rtb_to_rtx helper calls Darrick J. Wong
@ 2023-10-11 18:05   ` Darrick J. Wong
  2023-10-12  5:22     ` Christoph Hellwig
  2023-10-11 18:06   ` [PATCH 7/7] xfs: use shifting and masking when converting rt extents, if possible Darrick J. Wong
  6 siblings, 1 reply; 83+ messages in thread
From: Darrick J. Wong @ 2023-10-11 18:05 UTC (permalink / raw)
  To: djwong; +Cc: linux-xfs, osandov, hch

From: Darrick J. Wong <djwong@kernel.org>

Create a pair of functions to round rtblock numbers up or down to the
nearest rt extent.

Signed-off-by: Darrick J. Wong <djwong@kernel.org>
---
 fs/xfs/libxfs/xfs_rtbitmap.h |   18 ++++++++++++++++++
 fs/xfs/xfs_bmap_util.c       |    8 +++-----
 fs/xfs/xfs_rtalloc.c         |    4 ++--
 fs/xfs/xfs_xchgrange.c       |    4 ++--
 4 files changed, 25 insertions(+), 9 deletions(-)


diff --git a/fs/xfs/libxfs/xfs_rtbitmap.h b/fs/xfs/libxfs/xfs_rtbitmap.h
index bdd4858a794c2..bc51d3bfc7c45 100644
--- a/fs/xfs/libxfs/xfs_rtbitmap.h
+++ b/fs/xfs/libxfs/xfs_rtbitmap.h
@@ -56,6 +56,24 @@ xfs_rtb_to_rtxt(
 	return div_u64(rtbno, mp->m_sb.sb_rextsize);
 }
 
+/* Round this rtblock up to the nearest rt extent size. */
+static inline xfs_rtblock_t
+xfs_rtb_roundup_rtx(
+	struct xfs_mount	*mp,
+	xfs_rtblock_t		rtbno)
+{
+	return roundup_64(rtbno, mp->m_sb.sb_rextsize);
+}
+
+/* Round this rtblock down to the nearest rt extent size. */
+static inline xfs_rtblock_t
+xfs_rtb_rounddown_rtx(
+	struct xfs_mount	*mp,
+	xfs_rtblock_t		rtbno)
+{
+	return rounddown_64(rtbno, mp->m_sb.sb_rextsize);
+}
+
 /*
  * Functions for walking free space rtextents in the realtime bitmap.
  */
diff --git a/fs/xfs/xfs_bmap_util.c b/fs/xfs/xfs_bmap_util.c
index 8f1e16e49dab2..b17332b84812e 100644
--- a/fs/xfs/xfs_bmap_util.c
+++ b/fs/xfs/xfs_bmap_util.c
@@ -685,7 +685,7 @@ xfs_can_free_eofblocks(
 	 */
 	end_fsb = XFS_B_TO_FSB(mp, (xfs_ufsize_t)XFS_ISIZE(ip));
 	if (XFS_IS_REALTIME_INODE(ip) && mp->m_sb.sb_rextsize > 1)
-		end_fsb = roundup_64(end_fsb, mp->m_sb.sb_rextsize);
+		end_fsb = xfs_rtb_roundup_rtx(mp, end_fsb);
 	last_fsb = XFS_B_TO_FSB(mp, mp->m_super->s_maxbytes);
 	if (last_fsb <= end_fsb)
 		return false;
@@ -984,10 +984,8 @@ xfs_free_file_space(
 
 	/* We can only free complete realtime extents. */
 	if (xfs_inode_has_bigrtextents(ip)) {
-		startoffset_fsb = roundup_64(startoffset_fsb,
-					     mp->m_sb.sb_rextsize);
-		endoffset_fsb = rounddown_64(endoffset_fsb,
-					     mp->m_sb.sb_rextsize);
+		startoffset_fsb = xfs_rtb_roundup_rtx(mp, startoffset_fsb);
+		endoffset_fsb = xfs_rtb_rounddown_rtx(mp, endoffset_fsb);
 	}
 
 	/*
diff --git a/fs/xfs/xfs_rtalloc.c b/fs/xfs/xfs_rtalloc.c
index 8db8f957a683b..e62ca51b995ba 100644
--- a/fs/xfs/xfs_rtalloc.c
+++ b/fs/xfs/xfs_rtalloc.c
@@ -1633,8 +1633,8 @@ xfs_rtfile_convert_unwritten(
 	if (mp->m_sb.sb_rextsize == 1)
 		return 0;
 
-	off = rounddown_64(XFS_B_TO_FSBT(mp, pos), mp->m_sb.sb_rextsize);
-	endoff = roundup_64(XFS_B_TO_FSB(mp, pos + len), mp->m_sb.sb_rextsize);
+	off = xfs_rtb_rounddown_rtx(mp, XFS_B_TO_FSBT(mp, pos));
+	endoff = xfs_rtb_roundup_rtx(mp, XFS_B_TO_FSB(mp, pos + len));
 
 	trace_xfs_rtfile_convert_unwritten(ip, pos, len);
 
diff --git a/fs/xfs/xfs_xchgrange.c b/fs/xfs/xfs_xchgrange.c
index befa915089ce6..a4a352e027c97 100644
--- a/fs/xfs/xfs_xchgrange.c
+++ b/fs/xfs/xfs_xchgrange.c
@@ -28,6 +28,7 @@
 #include "xfs_icache.h"
 #include "xfs_log.h"
 #include "xfs_rtalloc.h"
+#include "xfs_rtbitmap.h"
 #include <linux/fsnotify.h>
 
 /*
@@ -1236,8 +1237,7 @@ xfs_xchg_range(
 	 * offsets and length in @fxr are safe to round up.
 	 */
 	if (XFS_IS_REALTIME_INODE(ip2))
-		req.blockcount = roundup_64(req.blockcount,
-					    mp->m_sb.sb_rextsize);
+		req.blockcount = xfs_rtb_roundup_rtx(mp, req.blockcount);
 
 	error = xfs_xchg_range_estimate(&req);
 	if (error)


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

* [PATCH 7/7] xfs: use shifting and masking when converting rt extents, if possible
  2023-10-11 18:01 ` [PATCHSET RFC v1.0 0/7] xfs: refactor rt extent unit conversions Darrick J. Wong
                     ` (5 preceding siblings ...)
  2023-10-11 18:05   ` [PATCH 6/7] xfs: create rt extent rounding helpers for realtime extent blocks Darrick J. Wong
@ 2023-10-11 18:06   ` Darrick J. Wong
  2023-10-12  5:25     ` Christoph Hellwig
  6 siblings, 1 reply; 83+ messages in thread
From: Darrick J. Wong @ 2023-10-11 18:06 UTC (permalink / raw)
  To: djwong; +Cc: linux-xfs, osandov, hch

From: Darrick J. Wong <djwong@kernel.org>

Avoid the costs of integer division (32-bit and 64-bit) if the realtime
extent size is a power of two.

Signed-off-by: Darrick J. Wong <djwong@kernel.org>
---
 fs/xfs/libxfs/xfs_rtbitmap.h |   20 ++++++++++++++++++++
 fs/xfs/libxfs/xfs_sb.c       |    2 ++
 fs/xfs/xfs_linux.h           |   12 ++++++++++++
 fs/xfs/xfs_mount.h           |    2 ++
 fs/xfs/xfs_rtalloc.c         |    1 +
 fs/xfs/xfs_trans.c           |    4 ++++
 6 files changed, 41 insertions(+)


diff --git a/fs/xfs/libxfs/xfs_rtbitmap.h b/fs/xfs/libxfs/xfs_rtbitmap.h
index bc51d3bfc7c45..9dd791181ca2b 100644
--- a/fs/xfs/libxfs/xfs_rtbitmap.h
+++ b/fs/xfs/libxfs/xfs_rtbitmap.h
@@ -11,6 +11,9 @@ xfs_rtx_to_rtb(
 	struct xfs_mount	*mp,
 	xfs_rtxnum_t		rtx)
 {
+	if (mp->m_rtxblklog >= 0)
+		return rtx << mp->m_rtxblklog;
+
 	return rtx * mp->m_sb.sb_rextsize;
 }
 
@@ -19,6 +22,9 @@ xfs_rtxlen_to_extlen(
 	struct xfs_mount	*mp,
 	xfs_rtxlen_t		rtxlen)
 {
+	if (mp->m_rtxblklog >= 0)
+		return rtxlen << mp->m_rtxblklog;
+
 	return rtxlen * mp->m_sb.sb_rextsize;
 }
 
@@ -28,6 +34,9 @@ xfs_extlen_to_rtxmod(
 	struct xfs_mount	*mp,
 	xfs_extlen_t		len)
 {
+	if (mp->m_rtxblklog >= 0)
+		return len & mp->m_rtxblkmask;
+
 	return len % mp->m_sb.sb_rextsize;
 }
 
@@ -36,6 +45,9 @@ xfs_extlen_to_rtxlen(
 	struct xfs_mount	*mp,
 	xfs_extlen_t		len)
 {
+	if (mp->m_rtxblklog >= 0)
+		return len >> mp->m_rtxblklog;
+
 	return len / mp->m_sb.sb_rextsize;
 }
 
@@ -45,6 +57,11 @@ xfs_rtb_to_rtx(
 	xfs_rtblock_t		rtbno,
 	xfs_extlen_t		*mod)
 {
+	if (mp->m_rtxblklog >= 0) {
+		*mod = rtbno & mp->m_rtxblkmask;
+		return rtbno >> mp->m_rtxblklog;
+	}
+
 	return div_u64_rem(rtbno, mp->m_sb.sb_rextsize, mod);
 }
 
@@ -53,6 +70,9 @@ xfs_rtb_to_rtxt(
 	struct xfs_mount	*mp,
 	xfs_rtblock_t		rtbno)
 {
+	if (mp->m_rtxblklog >= 0)
+		return rtbno >> mp->m_rtxblklog;
+
 	return div_u64(rtbno, mp->m_sb.sb_rextsize);
 }
 
diff --git a/fs/xfs/libxfs/xfs_sb.c b/fs/xfs/libxfs/xfs_sb.c
index 5fb142b8e3d92..db04378f287a6 100644
--- a/fs/xfs/libxfs/xfs_sb.c
+++ b/fs/xfs/libxfs/xfs_sb.c
@@ -1011,6 +1011,8 @@ xfs_sb_mount_common(
 	mp->m_blockmask = sbp->sb_blocksize - 1;
 	mp->m_blockwsize = sbp->sb_blocksize >> XFS_WORDLOG;
 	mp->m_blockwmask = mp->m_blockwsize - 1;
+	mp->m_rtxblklog = log2_if_power2(sbp->sb_rextsize);
+	mp->m_rtxblkmask = mask64_if_power2(sbp->sb_rextsize);
 
 	mp->m_alloc_mxr[0] = xfs_allocbt_maxrecs(mp, sbp->sb_blocksize, 1);
 	mp->m_alloc_mxr[1] = xfs_allocbt_maxrecs(mp, sbp->sb_blocksize, 0);
diff --git a/fs/xfs/xfs_linux.h b/fs/xfs/xfs_linux.h
index dfde4021905b7..953466922ddf7 100644
--- a/fs/xfs/xfs_linux.h
+++ b/fs/xfs/xfs_linux.h
@@ -203,6 +203,18 @@ static inline bool isaligned_64(uint64_t x, uint32_t y)
 	return do_div(x, y) == 0;
 }
 
+/* If @b is a power of 2, return log2(b).  Else return -1. */
+static inline int8_t log2_if_power2(unsigned long b)
+{
+	return is_power_of_2(b) ? ilog2(b) : -1;
+}
+
+/* If @b is a power of 2, return a mask of the lower bits, else return zero. */
+static inline unsigned long long mask64_if_power2(unsigned long b)
+{
+	return is_power_of_2(b) ? b - 1 : 0;
+}
+
 int xfs_rw_bdev(struct block_device *bdev, sector_t sector, unsigned int count,
 		char *data, enum req_op op);
 
diff --git a/fs/xfs/xfs_mount.h b/fs/xfs/xfs_mount.h
index f42679a6569ff..3c5b0327164bc 100644
--- a/fs/xfs/xfs_mount.h
+++ b/fs/xfs/xfs_mount.h
@@ -120,6 +120,7 @@ typedef struct xfs_mount {
 	uint8_t			m_blkbb_log;	/* blocklog - BBSHIFT */
 	uint8_t			m_agno_log;	/* log #ag's */
 	uint8_t			m_sectbb_log;	/* sectlog - BBSHIFT */
+	int8_t			m_rtxblklog;	/* log2 of rextsize, if possible */
 	uint			m_blockmask;	/* sb_blocksize-1 */
 	uint			m_blockwsize;	/* sb_blocksize in words */
 	uint			m_blockwmask;	/* blockwsize-1 */
@@ -153,6 +154,7 @@ typedef struct xfs_mount {
 	uint64_t		m_features;	/* active filesystem features */
 	uint64_t		m_low_space[XFS_LOWSP_MAX];
 	uint64_t		m_low_rtexts[XFS_LOWSP_MAX];
+	uint64_t		m_rtxblkmask;	/* rt extent block mask */
 	struct xfs_ino_geometry	m_ino_geo;	/* inode geometry */
 	struct xfs_trans_resv	m_resv;		/* precomputed res values */
 						/* low free space thresholds */
diff --git a/fs/xfs/xfs_rtalloc.c b/fs/xfs/xfs_rtalloc.c
index e62ca51b995ba..dc4874776c2cb 100644
--- a/fs/xfs/xfs_rtalloc.c
+++ b/fs/xfs/xfs_rtalloc.c
@@ -1052,6 +1052,7 @@ xfs_growfs_rt(
 		 * Calculate new sb and mount fields for this round.
 		 */
 		nsbp->sb_rextsize = in->extsize;
+		nmp->m_rtxblklog = -1; /* don't use shift or masking */
 		nsbp->sb_rbmblocks = bmbno + 1;
 		nrblocks_step = (bmbno + 1) * NBBY * nsbp->sb_blocksize *
 				nsbp->sb_rextsize;
diff --git a/fs/xfs/xfs_trans.c b/fs/xfs/xfs_trans.c
index 22aa2111b6cab..35161074c4e7d 100644
--- a/fs/xfs/xfs_trans.c
+++ b/fs/xfs/xfs_trans.c
@@ -712,6 +712,10 @@ xfs_trans_unreserve_and_mod_sb(
 	mp->m_sb.sb_agcount += tp->t_agcount_delta;
 	mp->m_sb.sb_imax_pct += tp->t_imaxpct_delta;
 	mp->m_sb.sb_rextsize += tp->t_rextsize_delta;
+	if (tp->t_rextsize_delta) {
+		mp->m_rtxblklog = log2_if_power2(mp->m_sb.sb_rextsize);
+		mp->m_rtxblkmask = mask64_if_power2(mp->m_sb.sb_rextsize);
+	}
 	mp->m_sb.sb_rbmblocks += tp->t_rbmblocks_delta;
 	mp->m_sb.sb_rblocks += tp->t_rblocks_delta;
 	mp->m_sb.sb_rextents += tp->t_rextents_delta;


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

* [PATCH 1/8] xfs: convert the rtbitmap block and bit macros to static inline functions
  2023-10-11 18:01 ` [PATCHSET RFC v1.0 0/8] xfs: refactor rtbitmap/summary macros Darrick J. Wong
@ 2023-10-11 18:06   ` Darrick J. Wong
  2023-10-12  6:34     ` Christoph Hellwig
  2023-10-11 18:06   ` [PATCH 2/8] xfs: remove XFS_BLOCKWSIZE and XFS_BLOCKWMASK macros Darrick J. Wong
                     ` (6 subsequent siblings)
  7 siblings, 1 reply; 83+ messages in thread
From: Darrick J. Wong @ 2023-10-11 18:06 UTC (permalink / raw)
  To: djwong; +Cc: linux-xfs, osandov, hch

From: Darrick J. Wong <djwong@kernel.org>

Replace these macros with typechecked helper functions.  Eventually
we're going to add more logic to the helpers and it'll be easier if we
don't have to macro it up.

Signed-off-by: Darrick J. Wong <djwong@kernel.org>
---
 fs/xfs/libxfs/xfs_format.h   |    5 -----
 fs/xfs/libxfs/xfs_rtbitmap.c |   22 +++++++++++-----------
 fs/xfs/libxfs/xfs_rtbitmap.h |   27 +++++++++++++++++++++++++++
 fs/xfs/scrub/rtsummary.c     |    2 +-
 fs/xfs/xfs_rtalloc.c         |   20 ++++++++++----------
 5 files changed, 49 insertions(+), 27 deletions(-)


diff --git a/fs/xfs/libxfs/xfs_format.h b/fs/xfs/libxfs/xfs_format.h
index 9ce2ebf96667a..932e22e024d5b 100644
--- a/fs/xfs/libxfs/xfs_format.h
+++ b/fs/xfs/libxfs/xfs_format.h
@@ -1226,11 +1226,6 @@ static inline bool xfs_dinode_has_large_extent_counts(
 	((xfs_suminfo_t *)((bp)->b_addr + \
 		(((so) * (uint)sizeof(xfs_suminfo_t)) & XFS_BLOCKMASK(mp))))
 
-#define	XFS_BITTOBLOCK(mp,bi)	((bi) >> (mp)->m_blkbit_log)
-#define	XFS_BLOCKTOBIT(mp,bb)	((bb) << (mp)->m_blkbit_log)
-#define	XFS_BITTOWORD(mp,bi)	\
-	((int)(((bi) >> XFS_NBWORDLOG) & XFS_BLOCKWMASK(mp)))
-
 #define	XFS_RTMIN(a,b)	((a) < (b) ? (a) : (b))
 #define	XFS_RTMAX(a,b)	((a) > (b) ? (a) : (b))
 
diff --git a/fs/xfs/libxfs/xfs_rtbitmap.c b/fs/xfs/libxfs/xfs_rtbitmap.c
index de54386cf52f3..ce8736666a1ef 100644
--- a/fs/xfs/libxfs/xfs_rtbitmap.c
+++ b/fs/xfs/libxfs/xfs_rtbitmap.c
@@ -123,7 +123,7 @@ xfs_rtfind_back(
 	/*
 	 * Compute and read in starting bitmap block for starting block.
 	 */
-	block = XFS_BITTOBLOCK(mp, start);
+	block = xfs_rtx_to_rbmblock(mp, start);
 	error = xfs_rtbuf_get(mp, tp, block, 0, &bp);
 	if (error) {
 		return error;
@@ -132,7 +132,7 @@ xfs_rtfind_back(
 	/*
 	 * Get the first word's index & point to it.
 	 */
-	word = XFS_BITTOWORD(mp, start);
+	word = xfs_rtx_to_rbmword(mp, start);
 	b = &bufp[word];
 	bit = (int)(start & (XFS_NBWORD - 1));
 	len = start - limit + 1;
@@ -298,7 +298,7 @@ xfs_rtfind_forw(
 	/*
 	 * Compute and read in starting bitmap block for starting block.
 	 */
-	block = XFS_BITTOBLOCK(mp, start);
+	block = xfs_rtx_to_rbmblock(mp, start);
 	error = xfs_rtbuf_get(mp, tp, block, 0, &bp);
 	if (error) {
 		return error;
@@ -307,7 +307,7 @@ xfs_rtfind_forw(
 	/*
 	 * Get the first word's index & point to it.
 	 */
-	word = XFS_BITTOWORD(mp, start);
+	word = xfs_rtx_to_rbmword(mp, start);
 	b = &bufp[word];
 	bit = (int)(start & (XFS_NBWORD - 1));
 	len = limit - start + 1;
@@ -559,7 +559,7 @@ xfs_rtmodify_range(
 	/*
 	 * Compute starting bitmap block number.
 	 */
-	block = XFS_BITTOBLOCK(mp, start);
+	block = xfs_rtx_to_rbmblock(mp, start);
 	/*
 	 * Read the bitmap block, and point to its data.
 	 */
@@ -571,7 +571,7 @@ xfs_rtmodify_range(
 	/*
 	 * Compute the starting word's address, and starting bit.
 	 */
-	word = XFS_BITTOWORD(mp, start);
+	word = xfs_rtx_to_rbmword(mp, start);
 	first = b = &bufp[word];
 	bit = (int)(start & (XFS_NBWORD - 1));
 	/*
@@ -737,7 +737,7 @@ xfs_rtfree_range(
 	if (preblock < start) {
 		error = xfs_rtmodify_summary(mp, tp,
 			XFS_RTBLOCKLOG(start - preblock),
-			XFS_BITTOBLOCK(mp, preblock), -1, rbpp, rsb);
+			xfs_rtx_to_rbmblock(mp, preblock), -1, rbpp, rsb);
 		if (error) {
 			return error;
 		}
@@ -749,7 +749,7 @@ xfs_rtfree_range(
 	if (postblock > end) {
 		error = xfs_rtmodify_summary(mp, tp,
 			XFS_RTBLOCKLOG(postblock - end),
-			XFS_BITTOBLOCK(mp, end + 1), -1, rbpp, rsb);
+			xfs_rtx_to_rbmblock(mp, end + 1), -1, rbpp, rsb);
 		if (error) {
 			return error;
 		}
@@ -760,7 +760,7 @@ xfs_rtfree_range(
 	 */
 	error = xfs_rtmodify_summary(mp, tp,
 		XFS_RTBLOCKLOG(postblock + 1 - preblock),
-		XFS_BITTOBLOCK(mp, preblock), 1, rbpp, rsb);
+		xfs_rtx_to_rbmblock(mp, preblock), 1, rbpp, rsb);
 	return error;
 }
 
@@ -793,7 +793,7 @@ xfs_rtcheck_range(
 	/*
 	 * Compute starting bitmap block number
 	 */
-	block = XFS_BITTOBLOCK(mp, start);
+	block = xfs_rtx_to_rbmblock(mp, start);
 	/*
 	 * Read the bitmap block.
 	 */
@@ -805,7 +805,7 @@ xfs_rtcheck_range(
 	/*
 	 * Compute the starting word's address, and starting bit.
 	 */
-	word = XFS_BITTOWORD(mp, start);
+	word = xfs_rtx_to_rbmword(mp, start);
 	b = &bufp[word];
 	bit = (int)(start & (XFS_NBWORD - 1));
 	/*
diff --git a/fs/xfs/libxfs/xfs_rtbitmap.h b/fs/xfs/libxfs/xfs_rtbitmap.h
index 9dd791181ca2b..e53011bc638d6 100644
--- a/fs/xfs/libxfs/xfs_rtbitmap.h
+++ b/fs/xfs/libxfs/xfs_rtbitmap.h
@@ -94,6 +94,33 @@ xfs_rtb_rounddown_rtx(
 	return rounddown_64(rtbno, mp->m_sb.sb_rextsize);
 }
 
+/* Convert an rt extent number to a file block offset in the rt bitmap file. */
+static inline xfs_fileoff_t
+xfs_rtx_to_rbmblock(
+	struct xfs_mount	*mp,
+	xfs_rtxnum_t		rtx)
+{
+	return rtx >> mp->m_blkbit_log;
+}
+
+/* Convert an rt extent number to a word offset within an rt bitmap block. */
+static inline unsigned int
+xfs_rtx_to_rbmword(
+	struct xfs_mount	*mp,
+	xfs_rtxnum_t		rtx)
+{
+	return (rtx >> XFS_NBWORDLOG) & XFS_BLOCKWMASK(mp);
+}
+
+/* Convert a file block offset in the rt bitmap file to an rt extent number. */
+static inline xfs_rtxnum_t
+xfs_rbmblock_to_rtx(
+	struct xfs_mount	*mp,
+	xfs_fileoff_t		rbmoff)
+{
+	return rbmoff << mp->m_blkbit_log;
+}
+
 /*
  * Functions for walking free space rtextents in the realtime bitmap.
  */
diff --git a/fs/xfs/scrub/rtsummary.c b/fs/xfs/scrub/rtsummary.c
index a329470bade8d..5d0b9980ea810 100644
--- a/fs/xfs/scrub/rtsummary.c
+++ b/fs/xfs/scrub/rtsummary.c
@@ -142,7 +142,7 @@ xchk_rtsum_record_free(
 		return error;
 
 	/* Compute the relevant location in the rtsum file. */
-	rbmoff = XFS_BITTOBLOCK(mp, rec->ar_startext);
+	rbmoff = xfs_rtx_to_rbmblock(mp, rec->ar_startext);
 	lenlog = XFS_RTBLOCKLOG(rec->ar_extcount);
 	offs = XFS_SUMOFFS(mp, lenlog, rbmoff);
 
diff --git a/fs/xfs/xfs_rtalloc.c b/fs/xfs/xfs_rtalloc.c
index dc4874776c2cb..14d01b97b892d 100644
--- a/fs/xfs/xfs_rtalloc.c
+++ b/fs/xfs/xfs_rtalloc.c
@@ -182,7 +182,7 @@ xfs_rtallocate_range(
 	 */
 	error = xfs_rtmodify_summary(mp, tp,
 		XFS_RTBLOCKLOG(postblock + 1 - preblock),
-		XFS_BITTOBLOCK(mp, preblock), -1, rbpp, rsb);
+		xfs_rtx_to_rbmblock(mp, preblock), -1, rbpp, rsb);
 	if (error) {
 		return error;
 	}
@@ -193,7 +193,7 @@ xfs_rtallocate_range(
 	if (preblock < start) {
 		error = xfs_rtmodify_summary(mp, tp,
 			XFS_RTBLOCKLOG(start - preblock),
-			XFS_BITTOBLOCK(mp, preblock), 1, rbpp, rsb);
+			xfs_rtx_to_rbmblock(mp, preblock), 1, rbpp, rsb);
 		if (error) {
 			return error;
 		}
@@ -205,7 +205,7 @@ xfs_rtallocate_range(
 	if (postblock > end) {
 		error = xfs_rtmodify_summary(mp, tp,
 			XFS_RTBLOCKLOG(postblock - end),
-			XFS_BITTOBLOCK(mp, end + 1), 1, rbpp, rsb);
+			xfs_rtx_to_rbmblock(mp, end + 1), 1, rbpp, rsb);
 		if (error) {
 			return error;
 		}
@@ -249,8 +249,8 @@ xfs_rtallocate_extent_block(
 	 * Loop over all the extents starting in this bitmap block,
 	 * looking for one that's long enough.
 	 */
-	for (i = XFS_BLOCKTOBIT(mp, bbno), besti = -1, bestlen = 0,
-		end = XFS_BLOCKTOBIT(mp, bbno + 1) - 1;
+	for (i = xfs_rbmblock_to_rtx(mp, bbno), besti = -1, bestlen = 0,
+		end = xfs_rbmblock_to_rtx(mp, bbno + 1) - 1;
 	     i <= end;
 	     i++) {
 		/*
@@ -487,7 +487,7 @@ xfs_rtallocate_extent_near(
 		*rtx = r;
 		return 0;
 	}
-	bbno = XFS_BITTOBLOCK(mp, start);
+	bbno = xfs_rtx_to_rbmblock(mp, start);
 	i = 0;
 	ASSERT(minlen != 0);
 	log2len = xfs_highbit32(minlen);
@@ -706,8 +706,8 @@ xfs_rtallocate_extent_size(
 			 * allocator is beyond the next bitmap block,
 			 * skip to that bitmap block.
 			 */
-			if (XFS_BITTOBLOCK(mp, n) > i + 1)
-				i = XFS_BITTOBLOCK(mp, n) - 1;
+			if (xfs_rtx_to_rbmblock(mp, n) > i + 1)
+				i = xfs_rtx_to_rbmblock(mp, n) - 1;
 		}
 	}
 	/*
@@ -769,8 +769,8 @@ xfs_rtallocate_extent_size(
 			 * allocator is beyond the next bitmap block,
 			 * skip to that bitmap block.
 			 */
-			if (XFS_BITTOBLOCK(mp, n) > i + 1)
-				i = XFS_BITTOBLOCK(mp, n) - 1;
+			if (xfs_rtx_to_rbmblock(mp, n) > i + 1)
+				i = xfs_rtx_to_rbmblock(mp, n) - 1;
 		}
 	}
 	/*


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

* [PATCH 2/8] xfs: remove XFS_BLOCKWSIZE and XFS_BLOCKWMASK macros
  2023-10-11 18:01 ` [PATCHSET RFC v1.0 0/8] xfs: refactor rtbitmap/summary macros Darrick J. Wong
  2023-10-11 18:06   ` [PATCH 1/8] xfs: convert the rtbitmap block and bit macros to static inline functions Darrick J. Wong
@ 2023-10-11 18:06   ` Darrick J. Wong
  2023-10-12  5:33     ` Christoph Hellwig
  2023-10-11 18:07   ` [PATCH 3/8] xfs: convert open-coded xfs_rtword_t pointer accesses to helper Darrick J. Wong
                     ` (5 subsequent siblings)
  7 siblings, 1 reply; 83+ messages in thread
From: Darrick J. Wong @ 2023-10-11 18:06 UTC (permalink / raw)
  To: djwong; +Cc: linux-xfs, osandov, hch

From: Darrick J. Wong <djwong@kernel.org>

Remove these trivial macros since they're not even part of the ondisk
format.

Signed-off-by: Darrick J. Wong <djwong@kernel.org>
---
 fs/xfs/libxfs/xfs_format.h   |    2 --
 fs/xfs/libxfs/xfs_rtbitmap.c |   16 ++++++++--------
 fs/xfs/libxfs/xfs_rtbitmap.h |    2 +-
 3 files changed, 9 insertions(+), 11 deletions(-)


diff --git a/fs/xfs/libxfs/xfs_format.h b/fs/xfs/libxfs/xfs_format.h
index 932e22e024d5b..dff9e654087b9 100644
--- a/fs/xfs/libxfs/xfs_format.h
+++ b/fs/xfs/libxfs/xfs_format.h
@@ -1213,8 +1213,6 @@ static inline bool xfs_dinode_has_large_extent_counts(
 
 #define	XFS_BLOCKSIZE(mp)	((mp)->m_sb.sb_blocksize)
 #define	XFS_BLOCKMASK(mp)	((mp)->m_blockmask)
-#define	XFS_BLOCKWSIZE(mp)	((mp)->m_blockwsize)
-#define	XFS_BLOCKWMASK(mp)	((mp)->m_blockwmask)
 
 /*
  * RT Summary and bit manipulation macros.
diff --git a/fs/xfs/libxfs/xfs_rtbitmap.c b/fs/xfs/libxfs/xfs_rtbitmap.c
index ce8736666a1ef..1f4886287aad0 100644
--- a/fs/xfs/libxfs/xfs_rtbitmap.c
+++ b/fs/xfs/libxfs/xfs_rtbitmap.c
@@ -181,7 +181,7 @@ xfs_rtfind_back(
 				return error;
 			}
 			bufp = bp->b_addr;
-			word = XFS_BLOCKWMASK(mp);
+			word = mp->m_blockwsize - 1;
 			b = &bufp[word];
 		} else {
 			/*
@@ -227,7 +227,7 @@ xfs_rtfind_back(
 				return error;
 			}
 			bufp = bp->b_addr;
-			word = XFS_BLOCKWMASK(mp);
+			word = mp->m_blockwsize - 1;
 			b = &bufp[word];
 		} else {
 			/*
@@ -345,7 +345,7 @@ xfs_rtfind_forw(
 		 * Go on to next block if that's where the next word is
 		 * and we need the next word.
 		 */
-		if (++word == XFS_BLOCKWSIZE(mp) && i < len) {
+		if (++word == mp->m_blockwsize && i < len) {
 			/*
 			 * If done with this block, get the previous one.
 			 */
@@ -390,7 +390,7 @@ xfs_rtfind_forw(
 		 * Go on to next block if that's where the next word is
 		 * and we need the next word.
 		 */
-		if (++word == XFS_BLOCKWSIZE(mp) && i < len) {
+		if (++word == mp->m_blockwsize && i < len) {
 			/*
 			 * If done with this block, get the next one.
 			 */
@@ -600,7 +600,7 @@ xfs_rtmodify_range(
 		 * Go on to the next block if that's where the next word is
 		 * and we need the next word.
 		 */
-		if (++word == XFS_BLOCKWSIZE(mp) && i < len) {
+		if (++word == mp->m_blockwsize && i < len) {
 			/*
 			 * Log the changed part of this block.
 			 * Get the next one.
@@ -640,7 +640,7 @@ xfs_rtmodify_range(
 		 * Go on to the next block if that's where the next word is
 		 * and we need the next word.
 		 */
-		if (++word == XFS_BLOCKWSIZE(mp) && i < len) {
+		if (++word == mp->m_blockwsize && i < len) {
 			/*
 			 * Log the changed part of this block.
 			 * Get the next one.
@@ -843,7 +843,7 @@ xfs_rtcheck_range(
 		 * Go on to next block if that's where the next word is
 		 * and we need the next word.
 		 */
-		if (++word == XFS_BLOCKWSIZE(mp) && i < len) {
+		if (++word == mp->m_blockwsize && i < len) {
 			/*
 			 * If done with this block, get the next one.
 			 */
@@ -889,7 +889,7 @@ xfs_rtcheck_range(
 		 * Go on to next block if that's where the next word is
 		 * and we need the next word.
 		 */
-		if (++word == XFS_BLOCKWSIZE(mp) && i < len) {
+		if (++word == mp->m_blockwsize && i < len) {
 			/*
 			 * If done with this block, get the next one.
 			 */
diff --git a/fs/xfs/libxfs/xfs_rtbitmap.h b/fs/xfs/libxfs/xfs_rtbitmap.h
index e53011bc638d6..5f4a453e29eb6 100644
--- a/fs/xfs/libxfs/xfs_rtbitmap.h
+++ b/fs/xfs/libxfs/xfs_rtbitmap.h
@@ -109,7 +109,7 @@ xfs_rtx_to_rbmword(
 	struct xfs_mount	*mp,
 	xfs_rtxnum_t		rtx)
 {
-	return (rtx >> XFS_NBWORDLOG) & XFS_BLOCKWMASK(mp);
+	return (rtx >> XFS_NBWORDLOG) & (mp->m_blockwsize - 1);
 }
 
 /* Convert a file block offset in the rt bitmap file to an rt extent number. */


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

* [PATCH 3/8] xfs: convert open-coded xfs_rtword_t pointer accesses to helper
  2023-10-11 18:01 ` [PATCHSET RFC v1.0 0/8] xfs: refactor rtbitmap/summary macros Darrick J. Wong
  2023-10-11 18:06   ` [PATCH 1/8] xfs: convert the rtbitmap block and bit macros to static inline functions Darrick J. Wong
  2023-10-11 18:06   ` [PATCH 2/8] xfs: remove XFS_BLOCKWSIZE and XFS_BLOCKWMASK macros Darrick J. Wong
@ 2023-10-11 18:07   ` Darrick J. Wong
  2023-10-12  5:39     ` Christoph Hellwig
  2023-10-11 18:07   ` [PATCH 4/8] xfs: convert rt summary macros to helpers Darrick J. Wong
                     ` (4 subsequent siblings)
  7 siblings, 1 reply; 83+ messages in thread
From: Darrick J. Wong @ 2023-10-11 18:07 UTC (permalink / raw)
  To: djwong; +Cc: linux-xfs, osandov, hch

From: Darrick J. Wong <djwong@kernel.org>

There are a bunch of places where we use open-coded logic to find a
pointer to an xfs_rtword_t within a rt bitmap buffer.  Convert all that
to helper functions for better type safety.

Signed-off-by: Darrick J. Wong <djwong@kernel.org>
---
 fs/xfs/libxfs/xfs_rtbitmap.c |   59 ++++++++++++++++++++++--------------------
 fs/xfs/libxfs/xfs_rtbitmap.h |   20 ++++++++++++++
 2 files changed, 51 insertions(+), 28 deletions(-)


diff --git a/fs/xfs/libxfs/xfs_rtbitmap.c b/fs/xfs/libxfs/xfs_rtbitmap.c
index 1f4886287aad0..231622a5ab681 100644
--- a/fs/xfs/libxfs/xfs_rtbitmap.c
+++ b/fs/xfs/libxfs/xfs_rtbitmap.c
@@ -110,7 +110,6 @@ xfs_rtfind_back(
 	int		bit;		/* bit number in the word */
 	xfs_fileoff_t	block;		/* bitmap block number */
 	struct xfs_buf	*bp;		/* buf for the block */
-	xfs_rtword_t	*bufp;		/* starting word in buffer */
 	int		error;		/* error value */
 	xfs_rtxnum_t	firstbit;	/* first useful bit in the word */
 	xfs_rtxnum_t	i;		/* current bit number rel. to start */
@@ -128,12 +127,12 @@ xfs_rtfind_back(
 	if (error) {
 		return error;
 	}
-	bufp = bp->b_addr;
+
 	/*
 	 * Get the first word's index & point to it.
 	 */
 	word = xfs_rtx_to_rbmword(mp, start);
-	b = &bufp[word];
+	b = xfs_rbmblock_wordptr(bp, word);
 	bit = (int)(start & (XFS_NBWORD - 1));
 	len = start - limit + 1;
 	/*
@@ -180,9 +179,9 @@ xfs_rtfind_back(
 			if (error) {
 				return error;
 			}
-			bufp = bp->b_addr;
+
 			word = mp->m_blockwsize - 1;
-			b = &bufp[word];
+			b = xfs_rbmblock_wordptr(bp, word);
 		} else {
 			/*
 			 * Go on to the previous word in the buffer.
@@ -226,9 +225,9 @@ xfs_rtfind_back(
 			if (error) {
 				return error;
 			}
-			bufp = bp->b_addr;
+
 			word = mp->m_blockwsize - 1;
-			b = &bufp[word];
+			b = xfs_rbmblock_wordptr(bp, word);
 		} else {
 			/*
 			 * Go on to the previous word in the buffer.
@@ -285,7 +284,6 @@ xfs_rtfind_forw(
 	int		bit;		/* bit number in the word */
 	xfs_fileoff_t	block;		/* bitmap block number */
 	struct xfs_buf	*bp;		/* buf for the block */
-	xfs_rtword_t	*bufp;		/* starting word in buffer */
 	int		error;		/* error value */
 	xfs_rtxnum_t	i;		/* current bit number rel. to start */
 	xfs_rtxnum_t	lastbit;	/* last useful bit in the word */
@@ -303,12 +301,12 @@ xfs_rtfind_forw(
 	if (error) {
 		return error;
 	}
-	bufp = bp->b_addr;
+
 	/*
 	 * Get the first word's index & point to it.
 	 */
 	word = xfs_rtx_to_rbmword(mp, start);
-	b = &bufp[word];
+	b = xfs_rbmblock_wordptr(bp, word);
 	bit = (int)(start & (XFS_NBWORD - 1));
 	len = limit - start + 1;
 	/*
@@ -354,8 +352,9 @@ xfs_rtfind_forw(
 			if (error) {
 				return error;
 			}
-			b = bufp = bp->b_addr;
+
 			word = 0;
+			b = xfs_rbmblock_wordptr(bp, word);
 		} else {
 			/*
 			 * Go on to the previous word in the buffer.
@@ -399,8 +398,9 @@ xfs_rtfind_forw(
 			if (error) {
 				return error;
 			}
-			b = bufp = bp->b_addr;
+
 			word = 0;
+			b = xfs_rbmblock_wordptr(bp, word);
 		} else {
 			/*
 			 * Go on to the next word in the buffer.
@@ -548,7 +548,6 @@ xfs_rtmodify_range(
 	int		bit;		/* bit number in the word */
 	xfs_fileoff_t	block;		/* bitmap block number */
 	struct xfs_buf	*bp;		/* buf for the block */
-	xfs_rtword_t	*bufp;		/* starting word in buffer */
 	int		error;		/* error value */
 	xfs_rtword_t	*first;		/* first used word in the buffer */
 	int		i;		/* current bit number rel. to start */
@@ -567,12 +566,12 @@ xfs_rtmodify_range(
 	if (error) {
 		return error;
 	}
-	bufp = bp->b_addr;
+
 	/*
 	 * Compute the starting word's address, and starting bit.
 	 */
 	word = xfs_rtx_to_rbmword(mp, start);
-	first = b = &bufp[word];
+	first = b = xfs_rbmblock_wordptr(bp, word);
 	bit = (int)(start & (XFS_NBWORD - 1));
 	/*
 	 * 0 (allocated) => all zeroes; 1 (free) => all ones.
@@ -606,14 +605,15 @@ xfs_rtmodify_range(
 			 * Get the next one.
 			 */
 			xfs_trans_log_buf(tp, bp,
-				(uint)((char *)first - (char *)bufp),
-				(uint)((char *)b - (char *)bufp));
+				(uint)((char *)first - (char *)bp->b_addr),
+				(uint)((char *)b - (char *)bp->b_addr));
 			error = xfs_rtbuf_get(mp, tp, ++block, 0, &bp);
 			if (error) {
 				return error;
 			}
-			first = b = bufp = bp->b_addr;
+
 			word = 0;
+			first = b = xfs_rbmblock_wordptr(bp, word);
 		} else {
 			/*
 			 * Go on to the next word in the buffer
@@ -646,14 +646,15 @@ xfs_rtmodify_range(
 			 * Get the next one.
 			 */
 			xfs_trans_log_buf(tp, bp,
-				(uint)((char *)first - (char *)bufp),
-				(uint)((char *)b - (char *)bufp));
+				(uint)((char *)first - (char *)bp->b_addr),
+				(uint)((char *)b - (char *)bp->b_addr));
 			error = xfs_rtbuf_get(mp, tp, ++block, 0, &bp);
 			if (error) {
 				return error;
 			}
-			first = b = bufp = bp->b_addr;
+
 			word = 0;
+			first = b = xfs_rbmblock_wordptr(bp, word);
 		} else {
 			/*
 			 * Go on to the next word in the buffer
@@ -683,8 +684,9 @@ xfs_rtmodify_range(
 	 * Log any remaining changed bytes.
 	 */
 	if (b > first)
-		xfs_trans_log_buf(tp, bp, (uint)((char *)first - (char *)bufp),
-			(uint)((char *)b - (char *)bufp - 1));
+		xfs_trans_log_buf(tp, bp,
+			(uint)((char *)first - (char *)bp->b_addr),
+			(uint)((char *)b - (char *)bp->b_addr - 1));
 	return 0;
 }
 
@@ -782,7 +784,6 @@ xfs_rtcheck_range(
 	int		bit;		/* bit number in the word */
 	xfs_fileoff_t	block;		/* bitmap block number */
 	struct xfs_buf	*bp;		/* buf for the block */
-	xfs_rtword_t	*bufp;		/* starting word in buffer */
 	int		error;		/* error value */
 	xfs_rtxnum_t	i;		/* current bit number rel. to start */
 	xfs_rtxnum_t	lastbit;	/* last useful bit in word */
@@ -801,12 +802,12 @@ xfs_rtcheck_range(
 	if (error) {
 		return error;
 	}
-	bufp = bp->b_addr;
+
 	/*
 	 * Compute the starting word's address, and starting bit.
 	 */
 	word = xfs_rtx_to_rbmword(mp, start);
-	b = &bufp[word];
+	b = xfs_rbmblock_wordptr(bp, word);
 	bit = (int)(start & (XFS_NBWORD - 1));
 	/*
 	 * 0 (allocated) => all zero's; 1 (free) => all one's.
@@ -852,8 +853,9 @@ xfs_rtcheck_range(
 			if (error) {
 				return error;
 			}
-			b = bufp = bp->b_addr;
+
 			word = 0;
+			b = xfs_rbmblock_wordptr(bp, word);
 		} else {
 			/*
 			 * Go on to the next word in the buffer.
@@ -898,8 +900,9 @@ xfs_rtcheck_range(
 			if (error) {
 				return error;
 			}
-			b = bufp = bp->b_addr;
+
 			word = 0;
+			b = xfs_rbmblock_wordptr(bp, word);
 		} else {
 			/*
 			 * Go on to the next word in the buffer.
diff --git a/fs/xfs/libxfs/xfs_rtbitmap.h b/fs/xfs/libxfs/xfs_rtbitmap.h
index 5f4a453e29eb6..af37afec2b010 100644
--- a/fs/xfs/libxfs/xfs_rtbitmap.h
+++ b/fs/xfs/libxfs/xfs_rtbitmap.h
@@ -121,6 +121,26 @@ xfs_rbmblock_to_rtx(
 	return rbmoff << mp->m_blkbit_log;
 }
 
+/* Return a pointer to a bitmap word within a rt bitmap block buffer. */
+static inline xfs_rtword_t *
+xfs_rbmbuf_wordptr(
+	void			*buf,
+	unsigned int		rbmword)
+{
+	xfs_rtword_t		*wordp = buf;
+
+	return &wordp[rbmword];
+}
+
+/* Return a pointer to a bitmap word within a rt bitmap block. */
+static inline xfs_rtword_t *
+xfs_rbmblock_wordptr(
+	struct xfs_buf		*bp,
+	unsigned int		rbmword)
+{
+	return xfs_rbmbuf_wordptr(bp->b_addr, rbmword);
+}
+
 /*
  * Functions for walking free space rtextents in the realtime bitmap.
  */


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

* [PATCH 4/8] xfs: convert rt summary macros to helpers
  2023-10-11 18:01 ` [PATCHSET RFC v1.0 0/8] xfs: refactor rtbitmap/summary macros Darrick J. Wong
                     ` (2 preceding siblings ...)
  2023-10-11 18:07   ` [PATCH 3/8] xfs: convert open-coded xfs_rtword_t pointer accesses to helper Darrick J. Wong
@ 2023-10-11 18:07   ` Darrick J. Wong
  2023-10-12  5:41     ` Christoph Hellwig
  2023-10-11 18:07   ` [PATCH 5/8] xfs: create helpers for rtbitmap block/wordcount computations Darrick J. Wong
                     ` (3 subsequent siblings)
  7 siblings, 1 reply; 83+ messages in thread
From: Darrick J. Wong @ 2023-10-11 18:07 UTC (permalink / raw)
  To: djwong; +Cc: linux-xfs, osandov, hch

From: Darrick J. Wong <djwong@kernel.org>

Convert the realtime summary file macros to helper functions so that we
can improve type checking.

Signed-off-by: Darrick J. Wong <djwong@kernel.org>
---
 fs/xfs/libxfs/xfs_format.h      |    9 +-----
 fs/xfs/libxfs/xfs_rtbitmap.c    |   10 ++++---
 fs/xfs/libxfs/xfs_rtbitmap.h    |   59 +++++++++++++++++++++++++++++++++++++++
 fs/xfs/libxfs/xfs_types.h       |    2 +
 fs/xfs/scrub/rtsummary.c        |   16 ++++++-----
 fs/xfs/scrub/rtsummary.h        |    4 +--
 fs/xfs/scrub/rtsummary_repair.c |    7 +++--
 7 files changed, 83 insertions(+), 24 deletions(-)


diff --git a/fs/xfs/libxfs/xfs_format.h b/fs/xfs/libxfs/xfs_format.h
index dff9e654087b9..1254834ab5c9e 100644
--- a/fs/xfs/libxfs/xfs_format.h
+++ b/fs/xfs/libxfs/xfs_format.h
@@ -1215,15 +1215,8 @@ static inline bool xfs_dinode_has_large_extent_counts(
 #define	XFS_BLOCKMASK(mp)	((mp)->m_blockmask)
 
 /*
- * RT Summary and bit manipulation macros.
+ * RT bit manipulation macros.
  */
-#define	XFS_SUMOFFS(mp,ls,bb)	((int)((ls) * (mp)->m_sb.sb_rbmblocks + (bb)))
-#define	XFS_SUMOFFSTOBLOCK(mp,s)	\
-	(((s) * (uint)sizeof(xfs_suminfo_t)) >> (mp)->m_sb.sb_blocklog)
-#define	XFS_SUMPTR(mp,bp,so)	\
-	((xfs_suminfo_t *)((bp)->b_addr + \
-		(((so) * (uint)sizeof(xfs_suminfo_t)) & XFS_BLOCKMASK(mp))))
-
 #define	XFS_RTMIN(a,b)	((a) < (b) ? (a) : (b))
 #define	XFS_RTMAX(a,b)	((a) > (b) ? (a) : (b))
 
diff --git a/fs/xfs/libxfs/xfs_rtbitmap.c b/fs/xfs/libxfs/xfs_rtbitmap.c
index 231622a5ab681..b6a1d240c5545 100644
--- a/fs/xfs/libxfs/xfs_rtbitmap.c
+++ b/fs/xfs/libxfs/xfs_rtbitmap.c
@@ -462,17 +462,18 @@ xfs_rtmodify_summary_int(
 	struct xfs_buf	*bp;		/* buffer for the summary block */
 	int		error;		/* error value */
 	xfs_fileoff_t	sb;		/* summary fsblock */
-	int		so;		/* index into the summary file */
+	xfs_rtsumoff_t	so;		/* index into the summary file */
 	xfs_suminfo_t	*sp;		/* pointer to returned data */
+	unsigned int	infoword;
 
 	/*
 	 * Compute entry number in the summary file.
 	 */
-	so = XFS_SUMOFFS(mp, log, bbno);
+	so = xfs_rtsumoffs(mp, log, bbno);
 	/*
 	 * Compute the block number in the summary file.
 	 */
-	sb = XFS_SUMOFFSTOBLOCK(mp, so);
+	sb = xfs_rtsumoffs_to_block(mp, so);
 	/*
 	 * If we have an old buffer, and the block number matches, use that.
 	 */
@@ -500,7 +501,8 @@ xfs_rtmodify_summary_int(
 	/*
 	 * Point to the summary information, modify/log it, and/or copy it out.
 	 */
-	sp = XFS_SUMPTR(mp, bp, so);
+	infoword = xfs_rtsumoffs_to_infoword(mp, so);
+	sp = xfs_rsumblock_infoptr(bp, infoword);
 	if (delta) {
 		uint first = (uint)((char *)sp - (char *)bp->b_addr);
 
diff --git a/fs/xfs/libxfs/xfs_rtbitmap.h b/fs/xfs/libxfs/xfs_rtbitmap.h
index af37afec2b010..f616956b28911 100644
--- a/fs/xfs/libxfs/xfs_rtbitmap.h
+++ b/fs/xfs/libxfs/xfs_rtbitmap.h
@@ -141,6 +141,65 @@ xfs_rbmblock_wordptr(
 	return xfs_rbmbuf_wordptr(bp->b_addr, rbmword);
 }
 
+/*
+ * Convert a rt extent length and rt bitmap block number to a xfs_suminfo_t
+ * offset within the rt summary file.
+ */
+static inline xfs_rtsumoff_t
+xfs_rtsumoffs(
+	struct xfs_mount	*mp,
+	int			log2_len,
+	xfs_fileoff_t		rbmoff)
+{
+	return log2_len * mp->m_sb.sb_rbmblocks + rbmoff;
+}
+
+/*
+ * Convert an xfs_suminfo_t offset to a file block offset within the rt summary
+ * file.
+ */
+static inline xfs_fileoff_t
+xfs_rtsumoffs_to_block(
+	struct xfs_mount	*mp,
+	xfs_rtsumoff_t		rsumoff)
+{
+	return XFS_B_TO_FSBT(mp, rsumoff * sizeof(xfs_suminfo_t));
+}
+
+/*
+ * Convert an xfs_suminfo_t offset to an info word offset within an rt summary
+ * block.
+ */
+static inline unsigned int
+xfs_rtsumoffs_to_infoword(
+	struct xfs_mount	*mp,
+	xfs_rtsumoff_t		rsumoff)
+{
+	unsigned int		mask = mp->m_blockmask >> XFS_SUMINFOLOG;
+
+	return rsumoff & mask;
+}
+
+/* Return a pointer to a summary info word within a rt summary block buffer. */
+static inline xfs_suminfo_t *
+xfs_rsumbuf_infoptr(
+	void			*buf,
+	unsigned int		infoword)
+{
+	xfs_suminfo_t		*infop = buf;
+
+	return &infop[infoword];
+}
+
+/* Return a pointer to a summary info word within a rt summary block. */
+static inline xfs_suminfo_t *
+xfs_rsumblock_infoptr(
+	struct xfs_buf		*bp,
+	unsigned int		infoword)
+{
+	return xfs_rsumbuf_infoptr(bp->b_addr, infoword);
+}
+
 /*
  * Functions for walking free space rtextents in the realtime bitmap.
  */
diff --git a/fs/xfs/libxfs/xfs_types.h b/fs/xfs/libxfs/xfs_types.h
index abb07a1c7b0b4..f4615c5be34f2 100644
--- a/fs/xfs/libxfs/xfs_types.h
+++ b/fs/xfs/libxfs/xfs_types.h
@@ -19,6 +19,7 @@ typedef int64_t		xfs_fsize_t;	/* bytes in a file */
 typedef uint64_t	xfs_ufsize_t;	/* unsigned bytes in a file */
 
 typedef int32_t		xfs_suminfo_t;	/* type of bitmap summary info */
+typedef uint32_t	xfs_rtsumoff_t;	/* offset of an rtsummary info word */
 typedef uint32_t	xfs_rtword_t;	/* word type for bitmap manipulations */
 
 typedef int64_t		xfs_lsn_t;	/* log sequence number */
@@ -151,6 +152,7 @@ typedef uint32_t	xfs_dqid_t;
  */
 #define	XFS_NBBYLOG	3		/* log2(NBBY) */
 #define	XFS_WORDLOG	2		/* log2(sizeof(xfs_rtword_t)) */
+#define	XFS_SUMINFOLOG	2		/* log2(sizeof(xfs_suminfo_t)) */
 #define	XFS_NBWORDLOG	(XFS_NBBYLOG + XFS_WORDLOG)
 #define	XFS_NBWORD	(1 << XFS_NBWORDLOG)
 #define	XFS_WORDMASK	((1 << XFS_WORDLOG) - 1)
diff --git a/fs/xfs/scrub/rtsummary.c b/fs/xfs/scrub/rtsummary.c
index 5d0b9980ea810..901696c593dc9 100644
--- a/fs/xfs/scrub/rtsummary.c
+++ b/fs/xfs/scrub/rtsummary.c
@@ -93,7 +93,7 @@ xchk_setup_rtsummary(
 static inline int
 xfsum_load(
 	struct xfs_scrub	*sc,
-	xchk_rtsumoff_t		sumoff,
+	xfs_rtsumoff_t		sumoff,
 	xfs_suminfo_t		*info)
 {
 	return xfile_obj_load(sc->xfile, info, sizeof(xfs_suminfo_t),
@@ -103,7 +103,7 @@ xfsum_load(
 static inline int
 xfsum_store(
 	struct xfs_scrub	*sc,
-	xchk_rtsumoff_t		sumoff,
+	xfs_rtsumoff_t		sumoff,
 	const xfs_suminfo_t	info)
 {
 	return xfile_obj_store(sc->xfile, &info, sizeof(xfs_suminfo_t),
@@ -113,7 +113,7 @@ xfsum_store(
 inline int
 xfsum_copyout(
 	struct xfs_scrub	*sc,
-	xchk_rtsumoff_t		sumoff,
+	xfs_rtsumoff_t		sumoff,
 	xfs_suminfo_t		*info,
 	unsigned int		nr_words)
 {
@@ -133,7 +133,7 @@ xchk_rtsum_record_free(
 	xfs_fileoff_t			rbmoff;
 	xfs_rtxnum_t			rtbno;
 	xfs_filblks_t			rtlen;
-	xchk_rtsumoff_t			offs;
+	xfs_rtsumoff_t			offs;
 	unsigned int			lenlog;
 	xfs_suminfo_t			v = 0;
 	int				error = 0;
@@ -144,7 +144,7 @@ xchk_rtsum_record_free(
 	/* Compute the relevant location in the rtsum file. */
 	rbmoff = xfs_rtx_to_rbmblock(mp, rec->ar_startext);
 	lenlog = XFS_RTBLOCKLOG(rec->ar_extcount);
-	offs = XFS_SUMOFFS(mp, lenlog, rbmoff);
+	offs = xfs_rtsumoffs(mp, lenlog, rbmoff);
 
 	rtbno = xfs_rtx_to_rtb(mp, rec->ar_startext);
 	rtlen = xfs_rtx_to_rtb(mp, rec->ar_extcount);
@@ -193,10 +193,11 @@ xchk_rtsum_compare(
 	struct xfs_buf		*bp;
 	struct xfs_bmbt_irec	map;
 	xfs_fileoff_t		off;
-	xchk_rtsumoff_t		sumoff = 0;
+	xfs_rtsumoff_t		sumoff = 0;
 	int			nmap;
 
 	for (off = 0; off < XFS_B_TO_FSB(mp, mp->m_rsumsize); off++) {
+		xfs_suminfo_t	*ondisk_info;
 		int		error = 0;
 
 		if (xchk_should_terminate(sc, &error))
@@ -228,7 +229,8 @@ xchk_rtsum_compare(
 			return error;
 		}
 
-		if (memcmp(bp->b_addr, sc->buf,
+		ondisk_info = xfs_rsumblock_infoptr(bp, 0);
+		if (memcmp(ondisk_info, sc->buf,
 					mp->m_blockwsize << XFS_WORDLOG) != 0)
 			xchk_fblock_set_corrupt(sc, XFS_DATA_FORK, off);
 
diff --git a/fs/xfs/scrub/rtsummary.h b/fs/xfs/scrub/rtsummary.h
index 8c61fda80830c..7a69474293bf1 100644
--- a/fs/xfs/scrub/rtsummary.h
+++ b/fs/xfs/scrub/rtsummary.h
@@ -6,9 +6,9 @@
 #ifndef __XFS_SCRUB_RTSUMMARY_H__
 #define __XFS_SCRUB_RTSUMMARY_H__
 
-typedef unsigned int xchk_rtsumoff_t;
+typedef unsigned int xfs_rtsumoff_t;
 
-int xfsum_copyout(struct xfs_scrub *sc, xchk_rtsumoff_t sumoff,
+int xfsum_copyout(struct xfs_scrub *sc, xfs_rtsumoff_t sumoff,
 		xfs_suminfo_t *info, unsigned int nr_words);
 
 #endif /* __XFS_SCRUB_RTSUMMARY_H__ */
diff --git a/fs/xfs/scrub/rtsummary_repair.c b/fs/xfs/scrub/rtsummary_repair.c
index 78cc18d82ebb3..57fbe10bf9842 100644
--- a/fs/xfs/scrub/rtsummary_repair.c
+++ b/fs/xfs/scrub/rtsummary_repair.c
@@ -18,6 +18,7 @@
 #include "xfs_bmap.h"
 #include "xfs_bmap_btree.h"
 #include "xfs_swapext.h"
+#include "xfs_rtbitmap.h"
 #include "scrub/scrub.h"
 #include "scrub/common.h"
 #include "scrub/trace.h"
@@ -30,7 +31,7 @@
 
 struct xrep_rtsummary {
 	/* suminfo position of xfile as we write buffers to disk. */
-	xchk_rtsumoff_t		prep_wordoff;
+	xfs_rtsumoff_t		prep_wordoff;
 };
 
 /* Set us up to repair the rtsummary file. */
@@ -89,8 +90,8 @@ xrep_rtsummary_prep_buf(
 
 	bp->b_ops = &xfs_rtbuf_ops;
 
-	error = xfsum_copyout(sc, rs->prep_wordoff, bp->b_addr,
-			mp->m_blockwsize);
+	error = xfsum_copyout(sc, rs->prep_wordoff,
+			xfs_rsumblock_infoptr(bp, 0), mp->m_blockwsize);
 	if (error)
 		return error;
 


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

* [PATCH 5/8] xfs: create helpers for rtbitmap block/wordcount computations
  2023-10-11 18:01 ` [PATCHSET RFC v1.0 0/8] xfs: refactor rtbitmap/summary macros Darrick J. Wong
                     ` (3 preceding siblings ...)
  2023-10-11 18:07   ` [PATCH 4/8] xfs: convert rt summary macros to helpers Darrick J. Wong
@ 2023-10-11 18:07   ` Darrick J. Wong
  2023-10-12  5:44     ` Christoph Hellwig
  2023-10-11 18:07   ` [PATCH 6/8] xfs: use accessor functions for bitmap words Darrick J. Wong
                     ` (2 subsequent siblings)
  7 siblings, 1 reply; 83+ messages in thread
From: Darrick J. Wong @ 2023-10-11 18:07 UTC (permalink / raw)
  To: djwong; +Cc: linux-xfs, osandov, hch

From: Darrick J. Wong <djwong@kernel.org>

Create helper functions that compute the number of blocks or words
necessary to store the rt bitmap.

Signed-off-by: Darrick J. Wong <djwong@kernel.org>
---
 fs/xfs/libxfs/xfs_rtbitmap.c   |   27 +++++++++++++++++++++++++++
 fs/xfs/libxfs/xfs_rtbitmap.h   |   12 ++++++++++++
 fs/xfs/libxfs/xfs_trans_resv.c |    9 +++++----
 fs/xfs/scrub/rtsummary.c       |    7 +++----
 fs/xfs/xfs_rtalloc.c           |    2 +-
 5 files changed, 48 insertions(+), 9 deletions(-)


diff --git a/fs/xfs/libxfs/xfs_rtbitmap.c b/fs/xfs/libxfs/xfs_rtbitmap.c
index b6a1d240c5545..2a453f0215ee0 100644
--- a/fs/xfs/libxfs/xfs_rtbitmap.c
+++ b/fs/xfs/libxfs/xfs_rtbitmap.c
@@ -1142,3 +1142,30 @@ xfs_rtalloc_extent_is_free(
 	*is_free = matches;
 	return 0;
 }
+
+/*
+ * Compute the number of rtbitmap blocks needed to track the given number of rt
+ * extents.
+ */
+xfs_filblks_t
+xfs_rtbitmap_blockcount(
+	struct xfs_mount	*mp,
+	xfs_rtbxlen_t		rtextents)
+{
+	return howmany_64(rtextents, NBBY * mp->m_sb.sb_blocksize);
+}
+
+/*
+ * Compute the number of rtbitmap words needed to populate every block of a
+ * bitmap that is large enough to track the given number of rt extents.
+ */
+unsigned long long
+xfs_rtbitmap_wordcount(
+	struct xfs_mount	*mp,
+	xfs_rtbxlen_t		rtextents)
+{
+	xfs_filblks_t		blocks;
+
+	blocks = xfs_rtbitmap_blockcount(mp, rtextents);
+	return XFS_FSB_TO_B(mp, blocks) >> XFS_WORDLOG;
+}
diff --git a/fs/xfs/libxfs/xfs_rtbitmap.h b/fs/xfs/libxfs/xfs_rtbitmap.h
index f616956b28911..308ce814a908a 100644
--- a/fs/xfs/libxfs/xfs_rtbitmap.h
+++ b/fs/xfs/libxfs/xfs_rtbitmap.h
@@ -261,6 +261,11 @@ xfs_rtfree_extent(
 /* Same as above, but in units of rt blocks. */
 int xfs_rtfree_blocks(struct xfs_trans *tp, xfs_fsblock_t rtbno,
 		xfs_filblks_t rtlen);
+
+xfs_filblks_t xfs_rtbitmap_blockcount(struct xfs_mount *mp, xfs_rtbxlen_t
+		rtextents);
+unsigned long long xfs_rtbitmap_wordcount(struct xfs_mount *mp,
+		xfs_rtbxlen_t rtextents);
 #else /* CONFIG_XFS_RT */
 # define xfs_rtfree_extent(t,b,l)			(-ENOSYS)
 # define xfs_rtfree_blocks(t,rb,rl)			(-ENOSYS)
@@ -268,6 +273,13 @@ int xfs_rtfree_blocks(struct xfs_trans *tp, xfs_fsblock_t rtbno,
 # define xfs_rtalloc_query_all(m,t,f,p)			(-ENOSYS)
 # define xfs_rtbuf_get(m,t,b,i,p)			(-ENOSYS)
 # define xfs_rtalloc_extent_is_free(m,t,s,l,i)		(-ENOSYS)
+static inline xfs_filblks_t
+xfs_rtbitmap_blockcount(struct xfs_mount *mp, xfs_rtbxlen_t rtextents)
+{
+	/* shut up gcc */
+	return 0;
+}
+# define xfs_rtbitmap_wordcount(mp, r)			(0)
 #endif /* CONFIG_XFS_RT */
 
 #endif /* __XFS_RTBITMAP_H__ */
diff --git a/fs/xfs/libxfs/xfs_trans_resv.c b/fs/xfs/libxfs/xfs_trans_resv.c
index 9c3dbcbe05358..01fccc4ade8a5 100644
--- a/fs/xfs/libxfs/xfs_trans_resv.c
+++ b/fs/xfs/libxfs/xfs_trans_resv.c
@@ -221,11 +221,12 @@ xfs_rtalloc_block_count(
 	struct xfs_mount	*mp,
 	unsigned int		num_ops)
 {
-	unsigned int		blksz = XFS_FSB_TO_B(mp, 1);
-	unsigned int		rtbmp_bytes;
+	unsigned int		rtbmp_blocks;
+	xfs_rtxlen_t		rtxlen;
 
-	rtbmp_bytes = xfs_extlen_to_rtxlen(mp, XFS_MAX_BMBT_EXTLEN) / NBBY;
-	return (howmany(rtbmp_bytes, blksz) + 1) * num_ops;
+	rtxlen = xfs_extlen_to_rtxlen(mp, XFS_MAX_BMBT_EXTLEN);
+	rtbmp_blocks = xfs_rtbitmap_blockcount(mp, rtxlen);
+	return (rtbmp_blocks + 1) * num_ops;
 }
 
 /*
diff --git a/fs/xfs/scrub/rtsummary.c b/fs/xfs/scrub/rtsummary.c
index 901696c593dc9..29cd26b7779d1 100644
--- a/fs/xfs/scrub/rtsummary.c
+++ b/fs/xfs/scrub/rtsummary.c
@@ -172,12 +172,11 @@ xchk_rtsum_compute(
 	struct xfs_scrub	*sc)
 {
 	struct xfs_mount	*mp = sc->mp;
-	unsigned long long	rtbmp_bytes;
+	unsigned long long	rtbmp_blocks;
 
 	/* If the bitmap size doesn't match the computed size, bail. */
-	rtbmp_bytes = howmany_64(mp->m_sb.sb_rextents, NBBY);
-	if (roundup_64(rtbmp_bytes, mp->m_sb.sb_blocksize) !=
-			mp->m_rbmip->i_disk_size)
+	rtbmp_blocks = xfs_rtbitmap_blockcount(mp, mp->m_sb.sb_rextents);
+	if (XFS_FSB_TO_B(mp, rtbmp_blocks) != mp->m_rbmip->i_disk_size)
 		return -EFSCORRUPTED;
 
 	return xfs_rtalloc_query_all(sc->mp, sc->tp, xchk_rtsum_record_free,
diff --git a/fs/xfs/xfs_rtalloc.c b/fs/xfs/xfs_rtalloc.c
index 14d01b97b892d..32e3ac40e28f7 100644
--- a/fs/xfs/xfs_rtalloc.c
+++ b/fs/xfs/xfs_rtalloc.c
@@ -996,7 +996,7 @@ xfs_growfs_rt(
 	 */
 	nrextents = nrblocks;
 	do_div(nrextents, in->extsize);
-	nrbmblocks = howmany_64(nrextents, NBBY * sbp->sb_blocksize);
+	nrbmblocks = xfs_rtbitmap_blockcount(mp, nrextents);
 	nrextslog = xfs_highbit32(nrextents);
 	nrsumlevels = nrextslog + 1;
 	nrsumsize = (uint)sizeof(xfs_suminfo_t) * nrsumlevels * nrbmblocks;


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

* [PATCH 6/8] xfs: use accessor functions for bitmap words
  2023-10-11 18:01 ` [PATCHSET RFC v1.0 0/8] xfs: refactor rtbitmap/summary macros Darrick J. Wong
                     ` (4 preceding siblings ...)
  2023-10-11 18:07   ` [PATCH 5/8] xfs: create helpers for rtbitmap block/wordcount computations Darrick J. Wong
@ 2023-10-11 18:07   ` Darrick J. Wong
  2023-10-12  6:19     ` Christoph Hellwig
  2023-10-11 18:08   ` [PATCH 7/8] xfs: create helpers for rtsummary block/wordcount computations Darrick J. Wong
  2023-10-11 18:08   ` [PATCH 8/8] xfs: use accessor functions for summary info words Darrick J. Wong
  7 siblings, 1 reply; 83+ messages in thread
From: Darrick J. Wong @ 2023-10-11 18:07 UTC (permalink / raw)
  To: djwong; +Cc: linux-xfs, osandov, hch

From: Darrick J. Wong <djwong@kernel.org>

Create get and set functions for rtbitmap words so that we can redefine
the ondisk format with a specific endianness.  Note that this requires
the definition of a distinct type for ondisk rtbitmap words so that the
compiler can perform proper typechecking as we go back and forth.

In the upcoming rtgroups feature, we're going to fix the problem that
rtwords are written in host endian order, which means we'll need the
distinct rtword/rtword_raw types.

Signed-off-by: Darrick J. Wong <djwong@kernel.org>
---
 fs/xfs/libxfs/xfs_format.h   |    8 ++++
 fs/xfs/libxfs/xfs_rtbitmap.c |   78 +++++++++++++++++++++++++++++++-----------
 fs/xfs/libxfs/xfs_rtbitmap.h |   10 ++++-
 fs/xfs/xfs_ondisk.h          |    3 ++
 4 files changed, 75 insertions(+), 24 deletions(-)


diff --git a/fs/xfs/libxfs/xfs_format.h b/fs/xfs/libxfs/xfs_format.h
index 1254834ab5c9e..8e880ec217396 100644
--- a/fs/xfs/libxfs/xfs_format.h
+++ b/fs/xfs/libxfs/xfs_format.h
@@ -728,6 +728,14 @@ struct xfs_agfl {
 	    ASSERT(xfs_daddr_to_agno(mp, d) == \
 		   xfs_daddr_to_agno(mp, (d) + (len) - 1)))
 
+/*
+ * Realtime bitmap information is accessed by the word, which is currently
+ * stored in host-endian format.
+ */
+union xfs_rtword_ondisk {
+	__u32		raw;
+};
+
 /*
  * XFS Timestamps
  * ==============
diff --git a/fs/xfs/libxfs/xfs_rtbitmap.c b/fs/xfs/libxfs/xfs_rtbitmap.c
index 2a453f0215ee0..b2b1a1aec3422 100644
--- a/fs/xfs/libxfs/xfs_rtbitmap.c
+++ b/fs/xfs/libxfs/xfs_rtbitmap.c
@@ -94,6 +94,25 @@ xfs_rtbuf_get(
 	return 0;
 }
 
+/* Convert an ondisk bitmap word to its incore representation. */
+inline xfs_rtword_t
+xfs_rtbitmap_getword(
+	struct xfs_mount	*mp,
+	union xfs_rtword_ondisk	*wordptr)
+{
+	return wordptr->raw;
+}
+
+/* Set an ondisk bitmap word from an incore representation. */
+inline void
+xfs_rtbitmap_setword(
+	struct xfs_mount	*mp,
+	union xfs_rtword_ondisk	*wordptr,
+	xfs_rtword_t		incore)
+{
+	wordptr->raw = incore;
+}
+
 /*
  * Searching backward from start to limit, find the first block whose
  * allocated/free state is different from start's.
@@ -106,7 +125,7 @@ xfs_rtfind_back(
 	xfs_rtxnum_t	limit,		/* last rtext to look at */
 	xfs_rtxnum_t	*rtx)		/* out: start rtext found */
 {
-	xfs_rtword_t	*b;		/* current word in buffer */
+	union xfs_rtword_ondisk *b;		/* current word in buffer */
 	int		bit;		/* bit number in the word */
 	xfs_fileoff_t	block;		/* bitmap block number */
 	struct xfs_buf	*bp;		/* buf for the block */
@@ -117,6 +136,7 @@ xfs_rtfind_back(
 	xfs_rtword_t	mask;		/* mask of relevant bits for value */
 	xfs_rtword_t	want;		/* mask for "good" values */
 	xfs_rtword_t	wdiff;		/* difference from wanted value */
+	xfs_rtword_t	incore;
 	int		word;		/* word number in the buffer */
 
 	/*
@@ -139,7 +159,8 @@ xfs_rtfind_back(
 	 * Compute match value, based on the bit at start: if 1 (free)
 	 * then all-ones, else all-zeroes.
 	 */
-	want = (*b & ((xfs_rtword_t)1 << bit)) ? -1 : 0;
+	incore = xfs_rtbitmap_getword(mp, b);
+	want = (incore & ((xfs_rtword_t)1 << bit)) ? -1 : 0;
 	/*
 	 * If the starting position is not word-aligned, deal with the
 	 * partial word.
@@ -156,7 +177,7 @@ xfs_rtfind_back(
 		 * Calculate the difference between the value there
 		 * and what we're looking for.
 		 */
-		if ((wdiff = (*b ^ want) & mask)) {
+		if ((wdiff = (incore ^ want) & mask)) {
 			/*
 			 * Different.  Mark where we are and return.
 			 */
@@ -202,7 +223,8 @@ xfs_rtfind_back(
 		/*
 		 * Compute difference between actual and desired value.
 		 */
-		if ((wdiff = *b ^ want)) {
+		incore = xfs_rtbitmap_getword(mp, b);
+		if ((wdiff = incore ^ want)) {
 			/*
 			 * Different, mark where we are and return.
 			 */
@@ -249,7 +271,8 @@ xfs_rtfind_back(
 		/*
 		 * Compute difference between actual and desired value.
 		 */
-		if ((wdiff = (*b ^ want) & mask)) {
+		incore = xfs_rtbitmap_getword(mp, b);
+		if ((wdiff = (incore ^ want) & mask)) {
 			/*
 			 * Different, mark where we are and return.
 			 */
@@ -280,7 +303,7 @@ xfs_rtfind_forw(
 	xfs_rtxnum_t	limit,		/* last rtext to look at */
 	xfs_rtxnum_t	*rtx)		/* out: start rtext found */
 {
-	xfs_rtword_t	*b;		/* current word in buffer */
+	union xfs_rtword_ondisk *b;		/* current word in buffer */
 	int		bit;		/* bit number in the word */
 	xfs_fileoff_t	block;		/* bitmap block number */
 	struct xfs_buf	*bp;		/* buf for the block */
@@ -291,6 +314,7 @@ xfs_rtfind_forw(
 	xfs_rtword_t	mask;		/* mask of relevant bits for value */
 	xfs_rtword_t	want;		/* mask for "good" values */
 	xfs_rtword_t	wdiff;		/* difference from wanted value */
+	xfs_rtword_t	incore;
 	int		word;		/* word number in the buffer */
 
 	/*
@@ -313,7 +337,8 @@ xfs_rtfind_forw(
 	 * Compute match value, based on the bit at start: if 1 (free)
 	 * then all-ones, else all-zeroes.
 	 */
-	want = (*b & ((xfs_rtword_t)1 << bit)) ? -1 : 0;
+	incore = xfs_rtbitmap_getword(mp, b);
+	want = (incore & ((xfs_rtword_t)1 << bit)) ? -1 : 0;
 	/*
 	 * If the starting position is not word-aligned, deal with the
 	 * partial word.
@@ -329,7 +354,7 @@ xfs_rtfind_forw(
 		 * Calculate the difference between the value there
 		 * and what we're looking for.
 		 */
-		if ((wdiff = (*b ^ want) & mask)) {
+		if ((wdiff = (incore ^ want) & mask)) {
 			/*
 			 * Different.  Mark where we are and return.
 			 */
@@ -375,7 +400,8 @@ xfs_rtfind_forw(
 		/*
 		 * Compute difference between actual and desired value.
 		 */
-		if ((wdiff = *b ^ want)) {
+		incore = xfs_rtbitmap_getword(mp, b);
+		if ((wdiff = incore ^ want)) {
 			/*
 			 * Different, mark where we are and return.
 			 */
@@ -420,7 +446,8 @@ xfs_rtfind_forw(
 		/*
 		 * Compute difference between actual and desired value.
 		 */
-		if ((wdiff = (*b ^ want) & mask)) {
+		incore = xfs_rtbitmap_getword(mp, b);
+		if ((wdiff = (incore ^ want) & mask)) {
 			/*
 			 * Different, mark where we are and return.
 			 */
@@ -546,15 +573,16 @@ xfs_rtmodify_range(
 	xfs_rtxlen_t	len,		/* length of extent to modify */
 	int		val)		/* 1 for free, 0 for allocated */
 {
-	xfs_rtword_t	*b;		/* current word in buffer */
+	union xfs_rtword_ondisk *b;		/* current word in buffer */
 	int		bit;		/* bit number in the word */
 	xfs_fileoff_t	block;		/* bitmap block number */
 	struct xfs_buf	*bp;		/* buf for the block */
 	int		error;		/* error value */
-	xfs_rtword_t	*first;		/* first used word in the buffer */
+	union xfs_rtword_ondisk *first;		/* first used word in the buffer */
 	int		i;		/* current bit number rel. to start */
 	int		lastbit;	/* last useful bit in word */
 	xfs_rtword_t	mask;		/* mask o frelevant bits for value */
+	xfs_rtword_t	incore;
 	int		word;		/* word number in the buffer */
 
 	/*
@@ -592,10 +620,12 @@ xfs_rtmodify_range(
 		/*
 		 * Set/clear the active bits.
 		 */
+		incore = xfs_rtbitmap_getword(mp, b);
 		if (val)
-			*b |= mask;
+			incore |= mask;
 		else
-			*b &= ~mask;
+			incore &= ~mask;
+		xfs_rtbitmap_setword(mp, b, incore);
 		i = lastbit - bit;
 		/*
 		 * Go on to the next block if that's where the next word is
@@ -636,7 +666,7 @@ xfs_rtmodify_range(
 		/*
 		 * Set the word value correctly.
 		 */
-		*b = val;
+		xfs_rtbitmap_setword(mp, b, val);
 		i += XFS_NBWORD;
 		/*
 		 * Go on to the next block if that's where the next word is
@@ -676,10 +706,12 @@ xfs_rtmodify_range(
 		/*
 		 * Set/clear the active bits.
 		 */
+		incore = xfs_rtbitmap_getword(mp, b);
 		if (val)
-			*b |= mask;
+			incore |= mask;
 		else
-			*b &= ~mask;
+			incore &= ~mask;
+		xfs_rtbitmap_setword(mp, b, incore);
 		b++;
 	}
 	/*
@@ -782,7 +814,7 @@ xfs_rtcheck_range(
 	xfs_rtxnum_t	*new,		/* out: first rtext not matching */
 	int		*stat)		/* out: 1 for matches, 0 for not */
 {
-	xfs_rtword_t	*b;		/* current word in buffer */
+	union xfs_rtword_ondisk *b;		/* current word in buffer */
 	int		bit;		/* bit number in the word */
 	xfs_fileoff_t	block;		/* bitmap block number */
 	struct xfs_buf	*bp;		/* buf for the block */
@@ -791,6 +823,7 @@ xfs_rtcheck_range(
 	xfs_rtxnum_t	lastbit;	/* last useful bit in word */
 	xfs_rtword_t	mask;		/* mask of relevant bits for value */
 	xfs_rtword_t	wdiff;		/* difference from wanted value */
+	xfs_rtword_t	incore;
 	int		word;		/* word number in the buffer */
 
 	/*
@@ -831,7 +864,8 @@ xfs_rtcheck_range(
 		/*
 		 * Compute difference between actual and desired value.
 		 */
-		if ((wdiff = (*b ^ val) & mask)) {
+		incore = xfs_rtbitmap_getword(mp, b);
+		if ((wdiff = (incore ^ val) & mask)) {
 			/*
 			 * Different, compute first wrong bit and return.
 			 */
@@ -878,7 +912,8 @@ xfs_rtcheck_range(
 		/*
 		 * Compute difference between actual and desired value.
 		 */
-		if ((wdiff = *b ^ val)) {
+		incore = xfs_rtbitmap_getword(mp, b);
+		if ((wdiff = incore ^ val)) {
 			/*
 			 * Different, compute first wrong bit and return.
 			 */
@@ -924,7 +959,8 @@ xfs_rtcheck_range(
 		/*
 		 * Compute difference between actual and desired value.
 		 */
-		if ((wdiff = (*b ^ val) & mask)) {
+		incore = xfs_rtbitmap_getword(mp, b);
+		if ((wdiff = (incore ^ val) & mask)) {
 			/*
 			 * Different, compute first wrong bit and return.
 			 */
diff --git a/fs/xfs/libxfs/xfs_rtbitmap.h b/fs/xfs/libxfs/xfs_rtbitmap.h
index 308ce814a908a..0a3c6299af8e2 100644
--- a/fs/xfs/libxfs/xfs_rtbitmap.h
+++ b/fs/xfs/libxfs/xfs_rtbitmap.h
@@ -122,18 +122,18 @@ xfs_rbmblock_to_rtx(
 }
 
 /* Return a pointer to a bitmap word within a rt bitmap block buffer. */
-static inline xfs_rtword_t *
+static inline union xfs_rtword_ondisk *
 xfs_rbmbuf_wordptr(
 	void			*buf,
 	unsigned int		rbmword)
 {
-	xfs_rtword_t		*wordp = buf;
+	union xfs_rtword_ondisk	*wordp = buf;
 
 	return &wordp[rbmword];
 }
 
 /* Return a pointer to a bitmap word within a rt bitmap block. */
-static inline xfs_rtword_t *
+static inline union xfs_rtword_ondisk *
 xfs_rbmblock_wordptr(
 	struct xfs_buf		*bp,
 	unsigned int		rbmword)
@@ -266,6 +266,10 @@ xfs_filblks_t xfs_rtbitmap_blockcount(struct xfs_mount *mp, xfs_rtbxlen_t
 		rtextents);
 unsigned long long xfs_rtbitmap_wordcount(struct xfs_mount *mp,
 		xfs_rtbxlen_t rtextents);
+xfs_rtword_t xfs_rtbitmap_getword(struct xfs_mount *mp,
+		union xfs_rtword_ondisk *wordptr);
+void xfs_rtbitmap_setword(struct xfs_mount *mp,
+		union xfs_rtword_ondisk *wordptr, xfs_rtword_t incore);
 #else /* CONFIG_XFS_RT */
 # define xfs_rtfree_extent(t,b,l)			(-ENOSYS)
 # define xfs_rtfree_blocks(t,rb,rl)			(-ENOSYS)
diff --git a/fs/xfs/xfs_ondisk.h b/fs/xfs/xfs_ondisk.h
index 2bbad8bfc6293..efdba05f90aed 100644
--- a/fs/xfs/xfs_ondisk.h
+++ b/fs/xfs/xfs_ondisk.h
@@ -72,6 +72,9 @@ xfs_check_ondisk_structs(void)
 	XFS_CHECK_STRUCT_SIZE(xfs_attr_leaf_map_t,		4);
 	XFS_CHECK_STRUCT_SIZE(xfs_attr_leaf_name_local_t,	4);
 
+	/* realtime structures */
+	XFS_CHECK_STRUCT_SIZE(union xfs_rtword_ondisk,		4);
+
 	/*
 	 * m68k has problems with xfs_attr_leaf_name_remote_t, but we pad it to
 	 * 4 bytes anyway so it's not obviously a problem.  Hence for the moment


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

* [PATCH 7/8] xfs: create helpers for rtsummary block/wordcount computations
  2023-10-11 18:01 ` [PATCHSET RFC v1.0 0/8] xfs: refactor rtbitmap/summary macros Darrick J. Wong
                     ` (5 preceding siblings ...)
  2023-10-11 18:07   ` [PATCH 6/8] xfs: use accessor functions for bitmap words Darrick J. Wong
@ 2023-10-11 18:08   ` Darrick J. Wong
  2023-10-12  6:25     ` Christoph Hellwig
  2023-10-11 18:08   ` [PATCH 8/8] xfs: use accessor functions for summary info words Darrick J. Wong
  7 siblings, 1 reply; 83+ messages in thread
From: Darrick J. Wong @ 2023-10-11 18:08 UTC (permalink / raw)
  To: djwong; +Cc: linux-xfs, osandov, hch

From: Darrick J. Wong <djwong@kernel.org>

Create helper functions that compute the number of blocks or words
necessary to store the rt summary file.

Signed-off-by: Darrick J. Wong <djwong@kernel.org>
---
 fs/xfs/libxfs/xfs_rtbitmap.c |   29 +++++++++++++++++++++++++++++
 fs/xfs/libxfs/xfs_rtbitmap.h |    7 +++++++
 fs/xfs/scrub/rtsummary.c     |    5 ++++-
 fs/xfs/xfs_rtalloc.c         |   17 +++++++----------
 4 files changed, 47 insertions(+), 11 deletions(-)


diff --git a/fs/xfs/libxfs/xfs_rtbitmap.c b/fs/xfs/libxfs/xfs_rtbitmap.c
index b2b1a1aec3422..be5c793da46c9 100644
--- a/fs/xfs/libxfs/xfs_rtbitmap.c
+++ b/fs/xfs/libxfs/xfs_rtbitmap.c
@@ -1205,3 +1205,32 @@ xfs_rtbitmap_wordcount(
 	blocks = xfs_rtbitmap_blockcount(mp, rtextents);
 	return XFS_FSB_TO_B(mp, blocks) >> XFS_WORDLOG;
 }
+
+/* Compute the number of rtsummary blocks needed to track the given rt space. */
+xfs_filblks_t
+xfs_rtsummary_blockcount(
+	struct xfs_mount	*mp,
+	unsigned int		rsumlevels,
+	xfs_extlen_t		rbmblocks)
+{
+	unsigned long long	rsumwords;
+
+	rsumwords = (unsigned long long)rsumlevels * rbmblocks;
+	return XFS_B_TO_FSB(mp, rsumwords << XFS_WORDLOG);
+}
+
+/*
+ * Compute the number of rtsummary info words needed to populate every block of
+ * a summary file that is large enough to track the given rt space.
+ */
+unsigned long long
+xfs_rtsummary_wordcount(
+	struct xfs_mount	*mp,
+	unsigned int		rsumlevels,
+	xfs_extlen_t		rbmblocks)
+{
+	xfs_filblks_t		blocks;
+
+	blocks = xfs_rtsummary_blockcount(mp, rsumlevels, rbmblocks);
+	return XFS_FSB_TO_B(mp, blocks) >> XFS_WORDLOG;
+}
diff --git a/fs/xfs/libxfs/xfs_rtbitmap.h b/fs/xfs/libxfs/xfs_rtbitmap.h
index 0a3c6299af8e2..a66357cf002be 100644
--- a/fs/xfs/libxfs/xfs_rtbitmap.h
+++ b/fs/xfs/libxfs/xfs_rtbitmap.h
@@ -270,6 +270,11 @@ xfs_rtword_t xfs_rtbitmap_getword(struct xfs_mount *mp,
 		union xfs_rtword_ondisk *wordptr);
 void xfs_rtbitmap_setword(struct xfs_mount *mp,
 		union xfs_rtword_ondisk *wordptr, xfs_rtword_t incore);
+
+xfs_filblks_t xfs_rtsummary_blockcount(struct xfs_mount *mp,
+		unsigned int rsumlevels, xfs_extlen_t rbmblocks);
+unsigned long long xfs_rtsummary_wordcount(struct xfs_mount *mp,
+		unsigned int rsumlevels, xfs_extlen_t rbmblocks);
 #else /* CONFIG_XFS_RT */
 # define xfs_rtfree_extent(t,b,l)			(-ENOSYS)
 # define xfs_rtfree_blocks(t,rb,rl)			(-ENOSYS)
@@ -284,6 +289,8 @@ xfs_rtbitmap_blockcount(struct xfs_mount *mp, xfs_rtbxlen_t rtextents)
 	return 0;
 }
 # define xfs_rtbitmap_wordcount(mp, r)			(0)
+# define xfs_rtsummary_blockcount(mp, l, b)		(0)
+# define xfs_rtsummary_wordcount(mp, l, b)		(0)
 #endif /* CONFIG_XFS_RT */
 
 #endif /* __XFS_RTBITMAP_H__ */
diff --git a/fs/xfs/scrub/rtsummary.c b/fs/xfs/scrub/rtsummary.c
index 29cd26b7779d1..3fcf7de9f685f 100644
--- a/fs/xfs/scrub/rtsummary.c
+++ b/fs/xfs/scrub/rtsummary.c
@@ -41,6 +41,7 @@ xchk_setup_rtsummary(
 	struct xfs_mount	*mp = sc->mp;
 	char			*descr;
 	size_t			bufsize = mp->m_sb.sb_blocksize;
+	unsigned int		wordcnt;
 	unsigned int		resblks = 0;
 	int			error;
 
@@ -54,8 +55,10 @@ xchk_setup_rtsummary(
 	 * Create an xfile to construct a new rtsummary file.  The xfile allows
 	 * us to avoid pinning kernel memory for this purpose.
 	 */
+	wordcnt = xfs_rtsummary_wordcount(mp, mp->m_rsumlevels,
+			mp->m_sb.sb_rbmblocks);
 	descr = xchk_xfile_descr(sc, "realtime summary file");
-	error = xfile_create(descr, mp->m_rsumsize, &sc->xfile);
+	error = xfile_create(descr, wordcnt << XFS_WORDLOG, &sc->xfile);
 	kfree(descr);
 	if (error)
 		return error;
diff --git a/fs/xfs/xfs_rtalloc.c b/fs/xfs/xfs_rtalloc.c
index 32e3ac40e28f7..2e7857a528408 100644
--- a/fs/xfs/xfs_rtalloc.c
+++ b/fs/xfs/xfs_rtalloc.c
@@ -999,8 +999,7 @@ xfs_growfs_rt(
 	nrbmblocks = xfs_rtbitmap_blockcount(mp, nrextents);
 	nrextslog = xfs_highbit32(nrextents);
 	nrsumlevels = nrextslog + 1;
-	nrsumsize = (uint)sizeof(xfs_suminfo_t) * nrsumlevels * nrbmblocks;
-	nrsumblocks = XFS_B_TO_FSB(mp, nrsumsize);
+	nrsumblocks = xfs_rtsummary_blockcount(mp, nrsumlevels, nrbmblocks);
 	nrsumsize = XFS_FSB_TO_B(mp, nrsumblocks);
 	/*
 	 * New summary size can't be more than half the size of
@@ -1061,10 +1060,8 @@ xfs_growfs_rt(
 		ASSERT(nsbp->sb_rextents != 0);
 		nsbp->sb_rextslog = xfs_highbit32(nsbp->sb_rextents);
 		nrsumlevels = nmp->m_rsumlevels = nsbp->sb_rextslog + 1;
-		nrsumsize =
-			(uint)sizeof(xfs_suminfo_t) * nrsumlevels *
-			nsbp->sb_rbmblocks;
-		nrsumblocks = XFS_B_TO_FSB(mp, nrsumsize);
+		nrsumblocks = xfs_rtsummary_blockcount(mp, nrsumlevels,
+				nsbp->sb_rbmblocks);
 		nmp->m_rsumsize = nrsumsize = XFS_FSB_TO_B(mp, nrsumblocks);
 		/*
 		 * Start a transaction, get the log reservation.
@@ -1270,6 +1267,7 @@ xfs_rtmount_init(
 	struct xfs_buf		*bp;	/* buffer for last block of subvolume */
 	struct xfs_sb		*sbp;	/* filesystem superblock copy in mount */
 	xfs_daddr_t		d;	/* address of last block of subvolume */
+	unsigned int		rsumblocks;
 	int			error;
 
 	sbp = &mp->m_sb;
@@ -1281,10 +1279,9 @@ xfs_rtmount_init(
 		return -ENODEV;
 	}
 	mp->m_rsumlevels = sbp->sb_rextslog + 1;
-	mp->m_rsumsize =
-		(uint)sizeof(xfs_suminfo_t) * mp->m_rsumlevels *
-		sbp->sb_rbmblocks;
-	mp->m_rsumsize = roundup(mp->m_rsumsize, sbp->sb_blocksize);
+	rsumblocks = xfs_rtsummary_blockcount(mp, mp->m_rsumlevels,
+			mp->m_sb.sb_rbmblocks);
+	mp->m_rsumsize = XFS_FSB_TO_B(mp, rsumblocks);
 	mp->m_rbmip = mp->m_rsumip = NULL;
 	/*
 	 * Check that the realtime section is an ok size.


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

* [PATCH 8/8] xfs: use accessor functions for summary info words
  2023-10-11 18:01 ` [PATCHSET RFC v1.0 0/8] xfs: refactor rtbitmap/summary macros Darrick J. Wong
                     ` (6 preceding siblings ...)
  2023-10-11 18:08   ` [PATCH 7/8] xfs: create helpers for rtsummary block/wordcount computations Darrick J. Wong
@ 2023-10-11 18:08   ` Darrick J. Wong
  2023-10-12  6:26     ` Christoph Hellwig
  7 siblings, 1 reply; 83+ messages in thread
From: Darrick J. Wong @ 2023-10-11 18:08 UTC (permalink / raw)
  To: djwong; +Cc: linux-xfs, osandov, hch

From: Darrick J. Wong <djwong@kernel.org>

Create get and set functions for rtsummary words so that we can redefine
the ondisk format with a specific endianness.  Note that this requires
the definition of a distinct type for ondisk summary info words so that
the compiler can perform proper typechecking.

Signed-off-by: Darrick J. Wong <djwong@kernel.org>
---
 fs/xfs/libxfs/xfs_format.h   |    8 ++++++++
 fs/xfs/libxfs/xfs_rtbitmap.c |   27 ++++++++++++++++++++++-----
 fs/xfs/libxfs/xfs_rtbitmap.h |   10 +++++++---
 fs/xfs/scrub/rtsummary.c     |   22 ++++++++++++----------
 fs/xfs/scrub/rtsummary.h     |    2 +-
 fs/xfs/scrub/trace.c         |    1 +
 fs/xfs/scrub/trace.h         |    4 ++--
 fs/xfs/xfs_ondisk.h          |    1 +
 8 files changed, 54 insertions(+), 21 deletions(-)


diff --git a/fs/xfs/libxfs/xfs_format.h b/fs/xfs/libxfs/xfs_format.h
index 8e880ec217396..a4ef175409ef3 100644
--- a/fs/xfs/libxfs/xfs_format.h
+++ b/fs/xfs/libxfs/xfs_format.h
@@ -736,6 +736,14 @@ union xfs_rtword_ondisk {
 	__u32		raw;
 };
 
+/*
+ * Realtime summary counts are accessed by the word, which is currently
+ * stored in host-endian format.
+ */
+union xfs_suminfo_ondisk {
+	__u32		raw;
+};
+
 /*
  * XFS Timestamps
  * ==============
diff --git a/fs/xfs/libxfs/xfs_rtbitmap.c b/fs/xfs/libxfs/xfs_rtbitmap.c
index be5c793da46c9..b74261abd2385 100644
--- a/fs/xfs/libxfs/xfs_rtbitmap.c
+++ b/fs/xfs/libxfs/xfs_rtbitmap.c
@@ -466,6 +466,23 @@ xfs_rtfind_forw(
 	return 0;
 }
 
+inline xfs_suminfo_t
+xfs_suminfo_get(
+	struct xfs_mount	*mp,
+	union xfs_suminfo_ondisk *infoptr)
+{
+	return infoptr->raw;
+}
+
+inline void
+xfs_suminfo_add(
+	struct xfs_mount	*mp,
+	union xfs_suminfo_ondisk *infoptr,
+	int			delta)
+{
+	infoptr->raw += delta;
+}
+
 /*
  * Read and/or modify the summary information for a given extent size,
  * bitmap block combination.
@@ -490,7 +507,7 @@ xfs_rtmodify_summary_int(
 	int		error;		/* error value */
 	xfs_fileoff_t	sb;		/* summary fsblock */
 	xfs_rtsumoff_t	so;		/* index into the summary file */
-	xfs_suminfo_t	*sp;		/* pointer to returned data */
+	union xfs_suminfo_ondisk *sp;		/* pointer to returned data */
 	unsigned int	infoword;
 
 	/*
@@ -533,17 +550,17 @@ xfs_rtmodify_summary_int(
 	if (delta) {
 		uint first = (uint)((char *)sp - (char *)bp->b_addr);
 
-		*sp += delta;
+		xfs_suminfo_add(mp, sp, delta);
 		if (mp->m_rsum_cache) {
-			if (*sp == 0 && log == mp->m_rsum_cache[bbno])
+			if (sp->raw == 0 && log == mp->m_rsum_cache[bbno])
 				mp->m_rsum_cache[bbno]++;
-			if (*sp != 0 && log < mp->m_rsum_cache[bbno])
+			if (sp->raw != 0 && log < mp->m_rsum_cache[bbno])
 				mp->m_rsum_cache[bbno] = log;
 		}
 		xfs_trans_log_buf(tp, bp, first, first + sizeof(*sp) - 1);
 	}
 	if (sum)
-		*sum = *sp;
+		*sum = xfs_suminfo_get(mp, sp);
 	return 0;
 }
 
diff --git a/fs/xfs/libxfs/xfs_rtbitmap.h b/fs/xfs/libxfs/xfs_rtbitmap.h
index a66357cf002be..749c8e3ec4cbb 100644
--- a/fs/xfs/libxfs/xfs_rtbitmap.h
+++ b/fs/xfs/libxfs/xfs_rtbitmap.h
@@ -181,18 +181,18 @@ xfs_rtsumoffs_to_infoword(
 }
 
 /* Return a pointer to a summary info word within a rt summary block buffer. */
-static inline xfs_suminfo_t *
+static inline union xfs_suminfo_ondisk *
 xfs_rsumbuf_infoptr(
 	void			*buf,
 	unsigned int		infoword)
 {
-	xfs_suminfo_t		*infop = buf;
+	union xfs_suminfo_ondisk *infop = buf;
 
 	return &infop[infoword];
 }
 
 /* Return a pointer to a summary info word within a rt summary block. */
-static inline xfs_suminfo_t *
+static inline union xfs_suminfo_ondisk *
 xfs_rsumblock_infoptr(
 	struct xfs_buf		*bp,
 	unsigned int		infoword)
@@ -275,6 +275,10 @@ xfs_filblks_t xfs_rtsummary_blockcount(struct xfs_mount *mp,
 		unsigned int rsumlevels, xfs_extlen_t rbmblocks);
 unsigned long long xfs_rtsummary_wordcount(struct xfs_mount *mp,
 		unsigned int rsumlevels, xfs_extlen_t rbmblocks);
+xfs_suminfo_t xfs_suminfo_get(struct xfs_mount *mp,
+		union xfs_suminfo_ondisk *infoptr);
+void xfs_suminfo_add(struct xfs_mount *mp, union xfs_suminfo_ondisk *infoptr,
+		int delta);
 #else /* CONFIG_XFS_RT */
 # define xfs_rtfree_extent(t,b,l)			(-ENOSYS)
 # define xfs_rtfree_blocks(t,rb,rl)			(-ENOSYS)
diff --git a/fs/xfs/scrub/rtsummary.c b/fs/xfs/scrub/rtsummary.c
index 3fcf7de9f685f..e8b0f57b9bb10 100644
--- a/fs/xfs/scrub/rtsummary.c
+++ b/fs/xfs/scrub/rtsummary.c
@@ -97,9 +97,10 @@ static inline int
 xfsum_load(
 	struct xfs_scrub	*sc,
 	xfs_rtsumoff_t		sumoff,
-	xfs_suminfo_t		*info)
+	union xfs_suminfo_ondisk *rawinfo)
 {
-	return xfile_obj_load(sc->xfile, info, sizeof(xfs_suminfo_t),
+	return xfile_obj_load(sc->xfile, rawinfo,
+			sizeof(union xfs_suminfo_ondisk),
 			sumoff << XFS_WORDLOG);
 }
 
@@ -107,9 +108,10 @@ static inline int
 xfsum_store(
 	struct xfs_scrub	*sc,
 	xfs_rtsumoff_t		sumoff,
-	const xfs_suminfo_t	info)
+	const union xfs_suminfo_ondisk rawinfo)
 {
-	return xfile_obj_store(sc->xfile, &info, sizeof(xfs_suminfo_t),
+	return xfile_obj_store(sc->xfile, &rawinfo,
+			sizeof(union xfs_suminfo_ondisk),
 			sumoff << XFS_WORDLOG);
 }
 
@@ -117,10 +119,10 @@ inline int
 xfsum_copyout(
 	struct xfs_scrub	*sc,
 	xfs_rtsumoff_t		sumoff,
-	xfs_suminfo_t		*info,
+	union xfs_suminfo_ondisk *rawinfo,
 	unsigned int		nr_words)
 {
-	return xfile_obj_load(sc->xfile, info, nr_words << XFS_WORDLOG,
+	return xfile_obj_load(sc->xfile, rawinfo, nr_words << XFS_WORDLOG,
 			sumoff << XFS_WORDLOG);
 }
 
@@ -138,7 +140,7 @@ xchk_rtsum_record_free(
 	xfs_filblks_t			rtlen;
 	xfs_rtsumoff_t			offs;
 	unsigned int			lenlog;
-	xfs_suminfo_t			v = 0;
+	union xfs_suminfo_ondisk	v;
 	int				error = 0;
 
 	if (xchk_should_terminate(sc, &error))
@@ -162,9 +164,9 @@ xchk_rtsum_record_free(
 	if (error)
 		return error;
 
-	v++;
+	xfs_suminfo_add(mp, &v, 1);
 	trace_xchk_rtsum_record_free(mp, rec->ar_startext, rec->ar_extcount,
-			lenlog, offs, v);
+			lenlog, offs, &v);
 
 	return xfsum_store(sc, offs, v);
 }
@@ -199,7 +201,7 @@ xchk_rtsum_compare(
 	int			nmap;
 
 	for (off = 0; off < XFS_B_TO_FSB(mp, mp->m_rsumsize); off++) {
-		xfs_suminfo_t	*ondisk_info;
+		union xfs_suminfo_ondisk *ondisk_info;
 		int		error = 0;
 
 		if (xchk_should_terminate(sc, &error))
diff --git a/fs/xfs/scrub/rtsummary.h b/fs/xfs/scrub/rtsummary.h
index 7a69474293bf1..f456bf952bc06 100644
--- a/fs/xfs/scrub/rtsummary.h
+++ b/fs/xfs/scrub/rtsummary.h
@@ -9,6 +9,6 @@
 typedef unsigned int xfs_rtsumoff_t;
 
 int xfsum_copyout(struct xfs_scrub *sc, xfs_rtsumoff_t sumoff,
-		xfs_suminfo_t *info, unsigned int nr_words);
+		union xfs_suminfo_ondisk *info, unsigned int nr_words);
 
 #endif /* __XFS_SCRUB_RTSUMMARY_H__ */
diff --git a/fs/xfs/scrub/trace.c b/fs/xfs/scrub/trace.c
index e4da5831c6a3c..0a7408699bc85 100644
--- a/fs/xfs/scrub/trace.c
+++ b/fs/xfs/scrub/trace.c
@@ -21,6 +21,7 @@
 #include "xfs_rmap.h"
 #include "xfs_parent.h"
 #include "xfs_imeta.h"
+#include "xfs_rtbitmap.h"
 #include "scrub/scrub.h"
 #include "scrub/xfile.h"
 #include "scrub/xfarray.h"
diff --git a/fs/xfs/scrub/trace.h b/fs/xfs/scrub/trace.h
index 5fc3e07d85ebd..0326f4138c8ca 100644
--- a/fs/xfs/scrub/trace.h
+++ b/fs/xfs/scrub/trace.h
@@ -1262,7 +1262,7 @@ TRACE_EVENT(xfarray_sort_stats,
 TRACE_EVENT(xchk_rtsum_record_free,
 	TP_PROTO(struct xfs_mount *mp, xfs_rtxnum_t start,
 		 xfs_rtbxlen_t len, unsigned int log, loff_t pos,
-		 xfs_suminfo_t v),
+		 union xfs_suminfo_ondisk *v),
 	TP_ARGS(mp, start, len, log, pos, v),
 	TP_STRUCT__entry(
 		__field(dev_t, dev)
@@ -1280,7 +1280,7 @@ TRACE_EVENT(xchk_rtsum_record_free,
 		__entry->len = len;
 		__entry->log = log;
 		__entry->pos = pos;
-		__entry->v = v;
+		__entry->v = xfs_suminfo_get(mp, v);
 	),
 	TP_printk("dev %d:%d rtdev %d:%d rtx 0x%llx rtxcount 0x%llx log %u rsumpos 0x%llx sumcount %u",
 		  MAJOR(__entry->dev), MINOR(__entry->dev),
diff --git a/fs/xfs/xfs_ondisk.h b/fs/xfs/xfs_ondisk.h
index efdba05f90aed..652b9b71a9052 100644
--- a/fs/xfs/xfs_ondisk.h
+++ b/fs/xfs/xfs_ondisk.h
@@ -74,6 +74,7 @@ xfs_check_ondisk_structs(void)
 
 	/* realtime structures */
 	XFS_CHECK_STRUCT_SIZE(union xfs_rtword_ondisk,		4);
+	XFS_CHECK_STRUCT_SIZE(union xfs_suminfo_ondisk,		4);
 
 	/*
 	 * m68k has problems with xfs_attr_leaf_name_remote_t, but we pad it to


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

* Re: [PATCH 1/3] xfs: bump max fsgeom struct version
  2023-10-11 18:02   ` [PATCH 1/3] xfs: bump max fsgeom struct version Darrick J. Wong
@ 2023-10-12  4:51     ` Christoph Hellwig
  2023-10-12 17:34       ` Darrick J. Wong
  0 siblings, 1 reply; 83+ messages in thread
From: Christoph Hellwig @ 2023-10-12  4:51 UTC (permalink / raw)
  To: Darrick J. Wong; +Cc: linux-xfs, osandov, hch

On Wed, Oct 11, 2023 at 11:02:03AM -0700, Darrick J. Wong wrote:
> From: Darrick J. Wong <djwong@kernel.org>
> 
> The latest version of the fs geometry structure is v5.

The commit log and change left me a little confused, having it in
a RT series even more.  So I went out and tried to understand it:

 - the fsgeom struct version is used by xfs_fs_geometry
 - XFS_FS_GEOM_MAX_STRUCT_VER is not used in the kernel at all,
   but libxfs uses it to always query all information in db and
   mkfs
 - commit 1b6d968de22bffd added the v5 structure, which mostly
   contains extra padding, but otherwise just reports the struct
   version for now

So this commit is a no-op for the kernel, and mostly a no-op for
userspace as nothing looks at the new field, but probably useful
for later changes.

Maybe capture this in the commit log.

With that:

Reviewed-by: Christoph Hellwig <hch@lst.de>

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

* Re: [PATCH 2/3] xfs: prevent rt growfs when quota is enabled
  2023-10-11 18:02   ` [PATCH 2/3] xfs: prevent rt growfs when quota is enabled Darrick J. Wong
@ 2023-10-12  4:51     ` Christoph Hellwig
  0 siblings, 0 replies; 83+ messages in thread
From: Christoph Hellwig @ 2023-10-12  4:51 UTC (permalink / raw)
  To: Darrick J. Wong; +Cc: linux-xfs, osandov, hch

Looks good:

Reviewed-by: Christoph Hellwig <hch@lst.de>

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

* Re: [PATCH 3/3] xfs: rt stubs should return negative errnos when rt disabled
  2023-10-11 18:02   ` [PATCH 3/3] xfs: rt stubs should return negative errnos when rt disabled Darrick J. Wong
@ 2023-10-12  4:52     ` Christoph Hellwig
  0 siblings, 0 replies; 83+ messages in thread
From: Christoph Hellwig @ 2023-10-12  4:52 UTC (permalink / raw)
  To: Darrick J. Wong; +Cc: linux-xfs, osandov, hch

On Wed, Oct 11, 2023 at 11:02:35AM -0700, Darrick J. Wong wrote:
> From: Darrick J. Wong <djwong@kernel.org>
> 
> When realtime support is not compiled into the kernel, these functions
> should return negative errnos, not positive errnos.  While we're at it,
> fix a broken macro declaration.

I would love to eventually see these as inline functions to also improve
error checking.  I'm not going to burden that on you now, though.

Reviewed-by: Christoph Hellwig <hch@lst.de>


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

* Re: [PATCH 1/7] xfs: make sure maxlen is still congruent with prod when rounding down
  2023-10-11 18:02   ` [PATCH 1/7] xfs: make sure maxlen is still congruent with prod when rounding down Darrick J. Wong
@ 2023-10-12  4:59     ` Christoph Hellwig
  2023-10-12 17:31       ` Darrick J. Wong
  0 siblings, 1 reply; 83+ messages in thread
From: Christoph Hellwig @ 2023-10-12  4:59 UTC (permalink / raw)
  To: Darrick J. Wong; +Cc: linux-xfs, osandov, hch

On Wed, Oct 11, 2023 at 11:02:50AM -0700, Darrick J. Wong wrote:
> Fix the problem by reducing maxlen by any misalignment with prod.  While
> we're at it, split the assertions into two so that we can tell which
> value had the bad alignment.

Yay, I always hate it when I trigger these compund asserts..

>  		maxlen = min(mp->m_sb.sb_rextents, i + maxlen) - i;
> +		maxlen -= maxlen % prod;

>  	maxlen = min(mp->m_sb.sb_rextents, bno + maxlen) - bno;
> +	maxlen -= maxlen % prod;

Not sure if that's bikeshedding, but this almost asks for a little
helper with a comment.

Otherwise looks good:

Reviewed-by: Christoph Hellwig <hch@lst.de>

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

* Re: [PATCH 3/7] xfs: convert xfs_extlen_t to xfs_rtxlen_t in the rt allocator
  2023-10-11 18:03   ` [PATCH 3/7] xfs: convert xfs_extlen_t to xfs_rtxlen_t in the rt allocator Darrick J. Wong
@ 2023-10-12  5:00     ` Christoph Hellwig
  0 siblings, 0 replies; 83+ messages in thread
From: Christoph Hellwig @ 2023-10-12  5:00 UTC (permalink / raw)
  To: Darrick J. Wong; +Cc: linux-xfs, osandov, hch

On Wed, Oct 11, 2023 at 11:03:21AM -0700, Darrick J. Wong wrote:
> From: Darrick J. Wong <djwong@kernel.org>
> 
> In most of the filesystem, we use xfs_extlen_t to store the length of a
> file (or AG) space mapping in units of fs blocks.  Unfortunately, the
> realtime allocator also uses it to store the length of a rt space
> mapping in units of rt extents.  This is confusing, since one rt extent
> can consist of many fs blocks.
> 
> Separate the two by introducing a new type (xfs_rtxlen_t) to store the
> length of a space mapping (in units of realtime extents) that would be
> found in a file.

Looks good:

Reviewed-by: Christoph Hellwig <hch@lst.de>

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

* Re: [PATCH 4/7] xfs: convert rt bitmap/summary block numbers to xfs_fileoff_t
  2023-10-11 18:03   ` [PATCH 4/7] xfs: convert rt bitmap/summary block numbers to xfs_fileoff_t Darrick J. Wong
@ 2023-10-12  5:01     ` Christoph Hellwig
  0 siblings, 0 replies; 83+ messages in thread
From: Christoph Hellwig @ 2023-10-12  5:01 UTC (permalink / raw)
  To: Darrick J. Wong; +Cc: linux-xfs, osandov, hch

Looks good:

Reviewed-by: Christoph Hellwig <hch@lst.de>

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

* Re: [PATCH 5/7] xfs: convert rt bitmap extent lengths to xfs_rtbxlen_t
  2023-10-11 18:03   ` [PATCH 5/7] xfs: convert rt bitmap extent lengths to xfs_rtbxlen_t Darrick J. Wong
@ 2023-10-12  5:01     ` Christoph Hellwig
  0 siblings, 0 replies; 83+ messages in thread
From: Christoph Hellwig @ 2023-10-12  5:01 UTC (permalink / raw)
  To: Darrick J. Wong; +Cc: linux-xfs, osandov, hch

Looks good:

Reviewed-by: Christoph Hellwig <hch@lst.de>

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

* Re: [PATCH 6/7] xfs: rename xfs_verify_rtext to xfs_verify_rtbext
  2023-10-11 18:04   ` [PATCH 6/7] xfs: rename xfs_verify_rtext to xfs_verify_rtbext Darrick J. Wong
@ 2023-10-12  5:02     ` Christoph Hellwig
  0 siblings, 0 replies; 83+ messages in thread
From: Christoph Hellwig @ 2023-10-12  5:02 UTC (permalink / raw)
  To: Darrick J. Wong; +Cc: linux-xfs, osandov, hch

On Wed, Oct 11, 2023 at 11:04:08AM -0700, Darrick J. Wong wrote:
> From: Darrick J. Wong <djwong@kernel.org>
> 
> This helper function validates that a range of *blocks* in the
> realtime section is completely contained within the realtime section.
> It does /not/ validate ranges of *rtextents*.  Rename the function to
> avoid suggesting that it does, and change the type of the @len parameter
> since xfs_rtblock_t is a position unit, not a length unit.

Looks good:

Reviewed-by: Christoph Hellwig <hch@lst.de>

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

* Re: [PATCH 7/7] xfs: convert rt extent numbers to xfs_rtxnum_t
  2023-10-11 18:04   ` [PATCH 7/7] xfs: convert rt extent numbers to xfs_rtxnum_t Darrick J. Wong
@ 2023-10-12  5:03     ` Christoph Hellwig
  0 siblings, 0 replies; 83+ messages in thread
From: Christoph Hellwig @ 2023-10-12  5:03 UTC (permalink / raw)
  To: Darrick J. Wong; +Cc: linux-xfs, osandov, hch

Looks good:

Reviewed-by: Christoph Hellwig <hch@lst.de>

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

* Re: [PATCHSET RFC v1.0 0/7] xfs: clean up realtime type usage
  2023-10-11 18:01 ` [PATCHSET RFC v1.0 0/7] xfs: clean up realtime type usage Darrick J. Wong
                     ` (6 preceding siblings ...)
  2023-10-11 18:04   ` [PATCH 7/7] xfs: convert rt extent numbers to xfs_rtxnum_t Darrick J. Wong
@ 2023-10-12  5:05   ` Christoph Hellwig
  2023-10-12 22:30     ` Darrick J. Wong
  7 siblings, 1 reply; 83+ messages in thread
From: Christoph Hellwig @ 2023-10-12  5:05 UTC (permalink / raw)
  To: Darrick J. Wong; +Cc: linux-xfs, osandov, hch

On Wed, Oct 11, 2023 at 11:01:16AM -0700, Darrick J. Wong wrote:
> Hi all,
> 
> The realtime code uses xfs_rtblock_t and xfs_fsblock_t in a lot of
> places, and it's very confusing.  Clean up all the type usage so that an
> xfs_rtblock_t is always a block within the realtime volume, an
> xfs_fileoff_t is always a file offset within a realtime metadata file,
> and an xfs_rtxnumber_t is always a rt extent within the realtime volume.

Question as a follow up:  now that we have proper types for all
the RT-specific units, what's the point of even keeping xfs_rtblock_t
around vs always using xfs_fsblock_t or xfs_rfsblock_t?


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

* Re: [PATCH 1/7] xfs: create a helper to convert rtextents to rtblocks
  2023-10-11 18:04   ` [PATCH 1/7] xfs: create a helper to convert rtextents to rtblocks Darrick J. Wong
@ 2023-10-12  5:10     ` Christoph Hellwig
  0 siblings, 0 replies; 83+ messages in thread
From: Christoph Hellwig @ 2023-10-12  5:10 UTC (permalink / raw)
  To: Darrick J. Wong; +Cc: linux-xfs, osandov, hch

On Wed, Oct 11, 2023 at 11:04:40AM -0700, Darrick J. Wong wrote:
> From: Darrick J. Wong <djwong@kernel.org>
> 
> Create a helper to convert a realtime extent to a realtime block.  Later
> on we'll change the helper to use bit shifts when possible.

Looks good:

Reviewed-by: Christoph Hellwig <hch@lst.de>

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

* Re: [PATCH 2/7] xfs: create a helper to compute leftovers of realtime extents
  2023-10-11 18:04   ` [PATCH 2/7] xfs: create a helper to compute leftovers of realtime extents Darrick J. Wong
@ 2023-10-12  5:11     ` Christoph Hellwig
  2023-10-12 17:40       ` Darrick J. Wong
  0 siblings, 1 reply; 83+ messages in thread
From: Christoph Hellwig @ 2023-10-12  5:11 UTC (permalink / raw)
  To: Darrick J. Wong; +Cc: linux-xfs, osandov, hch

> diff --git a/fs/xfs/libxfs/xfs_trans_inode.c b/fs/xfs/libxfs/xfs_trans_inode.c
> index 3e07e7c6a5d53..29f1aa290ce6d 100644
> --- a/fs/xfs/libxfs/xfs_trans_inode.c
> +++ b/fs/xfs/libxfs/xfs_trans_inode.c
> @@ -14,6 +14,7 @@
>  #include "xfs_trans.h"
>  #include "xfs_trans_priv.h"
>  #include "xfs_inode_item.h"
> +#include "xfs_rtbitmap.h"
>  
>  #include <linux/iversion.h>
>  

This seems to just have slipped in here?

Otherwise looks good:

Reviewed-by: Christoph Hellwig <hch@lst.de>

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

* Re: [PATCH 4/7] xfs: create helpers to convert rt block numbers to rt extent numbers
  2023-10-11 18:05   ` [PATCH 4/7] xfs: create helpers to convert rt block numbers to rt extent numbers Darrick J. Wong
@ 2023-10-12  5:17     ` Christoph Hellwig
  2023-10-12 17:58       ` Darrick J. Wong
  0 siblings, 1 reply; 83+ messages in thread
From: Christoph Hellwig @ 2023-10-12  5:17 UTC (permalink / raw)
  To: Darrick J. Wong; +Cc: linux-xfs, osandov, hch

On Wed, Oct 11, 2023 at 11:05:27AM -0700, Darrick J. Wong wrote:
> From: Darrick J. Wong <djwong@kernel.org>
> 
> Create helpers to do unit conversions of rt block numbers to rt extent
> numbers.  There are two variations -- the suffix "t" denotes the one
> that returns only the truncated extent number; the other one also
> returns the misalignment.  Convert all the div_u64_rem users; we'll do
> the do_div users in the next patch.

When trying to work with thee helpers I found the t prefix here a bit
weird, as it works different than the T in say XFS_B_TO_FSB
vs XFS_B_TO_FSBT which give you different results for the two versions.
Here we get the same returned result, just with the additional
return for the remainder.

Maybe have xfs_rtb_to_rtx and xfs_rtb_to_rtx_rem for the version with
the modulo?

We also have quite a few places that only care about the mod,
so an additƣonal xfs_rtb_rem/mod might be useful as well.


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

* Re: [PATCH 5/7] xfs: convert do_div calls to xfs_rtb_to_rtx helper calls
  2023-10-11 18:05   ` [PATCH 5/7] xfs: convert do_div calls to xfs_rtb_to_rtx helper calls Darrick J. Wong
@ 2023-10-12  5:22     ` Christoph Hellwig
  2023-10-12 18:10       ` Darrick J. Wong
  0 siblings, 1 reply; 83+ messages in thread
From: Christoph Hellwig @ 2023-10-12  5:22 UTC (permalink / raw)
  To: Darrick J. Wong; +Cc: linux-xfs, osandov, hch

On Wed, Oct 11, 2023 at 11:05:42AM -0700, Darrick J. Wong wrote:
> -	if (isrt) {
> -		uint64_t rtexts = XFS_FSB_TO_B(mp, del->br_blockcount);
> -
> -		do_div(rtexts, mp->m_sb.sb_rextsize);
> -		xfs_mod_frextents(mp, rtexts);
> -	}
> +	if (isrt)
> +		xfs_mod_frextents(mp, xfs_rtb_to_rtxt(mp, del->br_blockcount));

This is losing the XFS_FSB_TO_B conversion.  Now that conversion is
bogus and doesn't match the rest of the code, and only the fact that
we don't currently support delalloc on the RT device has saved our
ass since fa5c836ca8e.  Maybe split this into a little prep patch with
the a fixes tag?

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

* Re: [PATCH 6/7] xfs: create rt extent rounding helpers for realtime extent blocks
  2023-10-11 18:05   ` [PATCH 6/7] xfs: create rt extent rounding helpers for realtime extent blocks Darrick J. Wong
@ 2023-10-12  5:22     ` Christoph Hellwig
  0 siblings, 0 replies; 83+ messages in thread
From: Christoph Hellwig @ 2023-10-12  5:22 UTC (permalink / raw)
  To: Darrick J. Wong; +Cc: linux-xfs, osandov, hch

Looks good:

Reviewed-by: Christoph Hellwig <hch@lst.de>

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

* Re: [PATCH 7/7] xfs: use shifting and masking when converting rt extents, if possible
  2023-10-11 18:06   ` [PATCH 7/7] xfs: use shifting and masking when converting rt extents, if possible Darrick J. Wong
@ 2023-10-12  5:25     ` Christoph Hellwig
  2023-10-12 18:19       ` Darrick J. Wong
  0 siblings, 1 reply; 83+ messages in thread
From: Christoph Hellwig @ 2023-10-12  5:25 UTC (permalink / raw)
  To: Darrick J. Wong; +Cc: linux-xfs, osandov, hch

On Wed, Oct 11, 2023 at 11:06:14AM -0700, Darrick J. Wong wrote:
> From: Darrick J. Wong <djwong@kernel.org>
> 
> Avoid the costs of integer division (32-bit and 64-bit) if the realtime
> extent size is a power of two.

Looks good:

Reviewed-by: Christoph Hellwig <hch@lst.de>

Do you have any data on how common non-power of two rtext sizes are?
Might it be worth to add unlikely annotations?

> @@ -11,6 +11,9 @@ xfs_rtx_to_rtb(
>  	struct xfs_mount	*mp,
>  	xfs_rtxnum_t		rtx)
>  {
> +	if (mp->m_rtxblklog >= 0)
> +		return rtx << mp->m_rtxblklog;
> +
>  	return rtx * mp->m_sb.sb_rextsize;

i.e.

	if (unlikely(mp->m_rtxblklog == ‐1))
	  	return rtx * mp->m_sb.sb_rextsize;
	return rtx << mp->m_rtxblklog;


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

* Re: [PATCH 2/8] xfs: remove XFS_BLOCKWSIZE and XFS_BLOCKWMASK macros
  2023-10-11 18:06   ` [PATCH 2/8] xfs: remove XFS_BLOCKWSIZE and XFS_BLOCKWMASK macros Darrick J. Wong
@ 2023-10-12  5:33     ` Christoph Hellwig
  2023-10-12 18:20       ` Darrick J. Wong
  0 siblings, 1 reply; 83+ messages in thread
From: Christoph Hellwig @ 2023-10-12  5:33 UTC (permalink / raw)
  To: Darrick J. Wong; +Cc: linux-xfs, osandov, hch

On Wed, Oct 11, 2023 at 11:06:45AM -0700, Darrick J. Wong wrote:
> @@ -181,7 +181,7 @@ xfs_rtfind_back(
>  				return error;
>  			}
>  			bufp = bp->b_addr;
> -			word = XFS_BLOCKWMASK(mp);
> +			word = mp->m_blockwsize - 1;
>  			b = &bufp[word];
>  		} else {
>  			/*
> @@ -227,7 +227,7 @@ xfs_rtfind_back(
>  				return error;
>  			}
>  			bufp = bp->b_addr;
> -			word = XFS_BLOCKWMASK(mp);
> +			word = mp->m_blockwsize - 1;
>  			b = &bufp[word];
>  		} else {

Random rambling: there is a fairly large chunk of code duplicated
here.  Maybe the caching series and/or Dave's suggest args cleanup
would be good opportunity to refactor it.  Same for the next two
clusters of two chunks.

The patch itself looks good:

Reviewed-by: Christoph Hellwig <hch@lst.de>

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

* Re: [PATCH 3/8] xfs: convert open-coded xfs_rtword_t pointer accesses to helper
  2023-10-11 18:07   ` [PATCH 3/8] xfs: convert open-coded xfs_rtword_t pointer accesses to helper Darrick J. Wong
@ 2023-10-12  5:39     ` Christoph Hellwig
  2023-10-12 18:26       ` Darrick J. Wong
  0 siblings, 1 reply; 83+ messages in thread
From: Christoph Hellwig @ 2023-10-12  5:39 UTC (permalink / raw)
  To: Darrick J. Wong; +Cc: linux-xfs, osandov, hch

On Wed, Oct 11, 2023 at 11:07:01AM -0700, Darrick J. Wong wrote:
> +/* Return a pointer to a bitmap word within a rt bitmap block buffer. */
> +static inline xfs_rtword_t *
> +xfs_rbmbuf_wordptr(
> +	void			*buf,
> +	unsigned int		rbmword)
> +{
> +	xfs_rtword_t		*wordp = buf;
> +
> +	return &wordp[rbmword];

Superficial nitpick, I find the array dereference syntax here highly
confusing as the passed in pointer is not an array at all.

In fact I wonder what the xfs_rbmbuf_wordptr helper is for?  Even
looking at your full patch stack xfs_rbmblock_wordptr seems like
the only user.

> +/* Return a pointer to a bitmap word within a rt bitmap block. */
> +static inline xfs_rtword_t *
> +xfs_rbmblock_wordptr(
> +	struct xfs_buf		*bp,
> +	unsigned int		rbmword)
> +{
> +	return xfs_rbmbuf_wordptr(bp->b_addr, rbmword);

So I'd much rather just open code this as:

	xfs_rtword_t		*words = bp->b_addr;

	return words + rbmword;

and if I want to get really fancy I'd maybe rename rbmword to
something like index which feels more readable than rbmword.

That beeing said the xfs_rbmblock_wordptr abstraction is very welcome.

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

* Re: [PATCH 4/8] xfs: convert rt summary macros to helpers
  2023-10-11 18:07   ` [PATCH 4/8] xfs: convert rt summary macros to helpers Darrick J. Wong
@ 2023-10-12  5:41     ` Christoph Hellwig
  0 siblings, 0 replies; 83+ messages in thread
From: Christoph Hellwig @ 2023-10-12  5:41 UTC (permalink / raw)
  To: Darrick J. Wong; +Cc: linux-xfs, osandov, hch

Looks good:

Reviewed-by: Christoph Hellwig <hch@lst.de>

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

* Re: [PATCH 5/8] xfs: create helpers for rtbitmap block/wordcount computations
  2023-10-11 18:07   ` [PATCH 5/8] xfs: create helpers for rtbitmap block/wordcount computations Darrick J. Wong
@ 2023-10-12  5:44     ` Christoph Hellwig
  2023-10-12 21:55       ` Darrick J. Wong
  0 siblings, 1 reply; 83+ messages in thread
From: Christoph Hellwig @ 2023-10-12  5:44 UTC (permalink / raw)
  To: Darrick J. Wong; +Cc: linux-xfs, osandov, hch

On Wed, Oct 11, 2023 at 11:07:32AM -0700, Darrick J. Wong wrote:
> +/*
> + * Compute the number of rtbitmap blocks needed to track the given number of rt
> + * extents.
> + */
> +xfs_filblks_t
> +xfs_rtbitmap_blockcount(
> +	struct xfs_mount	*mp,
> +	xfs_rtbxlen_t		rtextents)
> +{
> +	return howmany_64(rtextents, NBBY * mp->m_sb.sb_blocksize);
> +}

Given that this only has a few users, the !RT stub is a pain, and
having a different result from before in the transaction reservation
is somewhat unexpected change (even if harmless), maybe just mark
this inline?

> +/*
> + * Compute the number of rtbitmap words needed to populate every block of a
> + * bitmap that is large enough to track the given number of rt extents.
> + */
> +unsigned long long
> +xfs_rtbitmap_wordcount(
> +	struct xfs_mount	*mp,
> +	xfs_rtbxlen_t		rtextents)
> +{
> +	xfs_filblks_t		blocks;
> +
> +	blocks = xfs_rtbitmap_blockcount(mp, rtextents);
> +	return XFS_FSB_TO_B(mp, blocks) >> XFS_WORDLOG;
> +}

This one isn't used in this patch or the rest of the series.  Maybe
move it to the patch (-series) that adds the caller in the repair
code?

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

* Re: [PATCH 6/8] xfs: use accessor functions for bitmap words
  2023-10-11 18:07   ` [PATCH 6/8] xfs: use accessor functions for bitmap words Darrick J. Wong
@ 2023-10-12  6:19     ` Christoph Hellwig
  2023-10-12 22:11       ` Darrick J. Wong
  0 siblings, 1 reply; 83+ messages in thread
From: Christoph Hellwig @ 2023-10-12  6:19 UTC (permalink / raw)
  To: Darrick J. Wong; +Cc: linux-xfs, osandov, hch

On Wed, Oct 11, 2023 at 11:07:48AM -0700, Darrick J. Wong wrote:
> From: Darrick J. Wong <djwong@kernel.org>
> 
> Create get and set functions for rtbitmap words so that we can redefine
> the ondisk format with a specific endianness.  Note that this requires
> the definition of a distinct type for ondisk rtbitmap words so that the
> compiler can perform proper typechecking as we go back and forth.
> 
> In the upcoming rtgroups feature, we're going to fix the problem that
> rtwords are written in host endian order, which means we'll need the
> distinct rtword/rtword_raw types.

I've been looking over this and I have to say I kinda hate the
abstraction level.

Having to deal with both the union xfs_rtword_ondisk, and the
normal in-memory rtword just feels cumbersome.

I'd go for an API that gets/sets the values based on [bp, word] indices
instead.  That would also need helpers for logging the buffer ranges
based on indices, which seems helpful for the code quality anyway.

I don't really want to burden that on you and would offer to do that
work myself after we work before this merged.


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

* Re: [PATCH 7/8] xfs: create helpers for rtsummary block/wordcount computations
  2023-10-11 18:08   ` [PATCH 7/8] xfs: create helpers for rtsummary block/wordcount computations Darrick J. Wong
@ 2023-10-12  6:25     ` Christoph Hellwig
  2023-10-12 22:18       ` Darrick J. Wong
  0 siblings, 1 reply; 83+ messages in thread
From: Christoph Hellwig @ 2023-10-12  6:25 UTC (permalink / raw)
  To: Darrick J. Wong; +Cc: linux-xfs, osandov, hch

On Wed, Oct 11, 2023 at 11:08:03AM -0700, Darrick J. Wong wrote:
> +/* Compute the number of rtsummary blocks needed to track the given rt space. */
> +xfs_filblks_t
> +xfs_rtsummary_blockcount(
> +	struct xfs_mount	*mp,
> +	unsigned int		rsumlevels,
> +	xfs_extlen_t		rbmblocks)
> +{
> +	unsigned long long	rsumwords;
> +
> +	rsumwords = (unsigned long long)rsumlevels * rbmblocks;
> +	return XFS_B_TO_FSB(mp, rsumwords << XFS_WORDLOG);
> +}

This helper and its users make complete sense to me and looks good:

Reviewed-by: Christoph Hellwig <hch@lst.de>

> +/*
> + * Compute the number of rtsummary info words needed to populate every block of
> + * a summary file that is large enough to track the given rt space.
> + */
> +unsigned long long
> +xfs_rtsummary_wordcount(
> +	struct xfs_mount	*mp,
> +	unsigned int		rsumlevels,
> +	xfs_extlen_t		rbmblocks)
> +{
> +	xfs_filblks_t		blocks;
> +
> +	blocks = xfs_rtsummary_blockcount(mp, rsumlevels, rbmblocks);
> +	return XFS_FSB_TO_B(mp, blocks) >> XFS_WORDLOG;
> +}

> @@ -54,8 +55,10 @@ xchk_setup_rtsummary(
>  	 * Create an xfile to construct a new rtsummary file.  The xfile allows
>  	 * us to avoid pinning kernel memory for this purpose.
>  	 */
> +	wordcnt = xfs_rtsummary_wordcount(mp, mp->m_rsumlevels,
> +			mp->m_sb.sb_rbmblocks);
>  	descr = xchk_xfile_descr(sc, "realtime summary file");
> -	error = xfile_create(descr, mp->m_rsumsize, &sc->xfile);
> +	error = xfile_create(descr, wordcnt << XFS_WORDLOG, &sc->xfile);
>  	kfree(descr);

But this confuses me.  What problem does it solve over just using
m_rsumsize?

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

* Re: [PATCH 8/8] xfs: use accessor functions for summary info words
  2023-10-11 18:08   ` [PATCH 8/8] xfs: use accessor functions for summary info words Darrick J. Wong
@ 2023-10-12  6:26     ` Christoph Hellwig
  2023-10-12 22:21       ` Darrick J. Wong
  0 siblings, 1 reply; 83+ messages in thread
From: Christoph Hellwig @ 2023-10-12  6:26 UTC (permalink / raw)
  To: Darrick J. Wong; +Cc: linux-xfs, osandov, hch

On Wed, Oct 11, 2023 at 11:08:19AM -0700, Darrick J. Wong wrote:
> From: Darrick J. Wong <djwong@kernel.org>
> 
> Create get and set functions for rtsummary words so that we can redefine
> the ondisk format with a specific endianness.  Note that this requires
> the definition of a distinct type for ondisk summary info words so that
> the compiler can perform proper typechecking.

Same comment as for the bitmap access, including the same offer.


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

* Re: [PATCH 2/7] xfs: move the xfs_rtbitmap.c declarations to xfs_rtbitmap.h
  2023-10-11 18:03   ` [PATCH 2/7] xfs: move the xfs_rtbitmap.c declarations to xfs_rtbitmap.h Darrick J. Wong
@ 2023-10-12  6:33     ` Christoph Hellwig
  0 siblings, 0 replies; 83+ messages in thread
From: Christoph Hellwig @ 2023-10-12  6:33 UTC (permalink / raw)
  To: Darrick J. Wong; +Cc: linux-xfs, osandov, hch

Looks good:

Reviewed-by: Christoph Hellwig <hch@lst.de>

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

* Re: [PATCH 3/7] xfs: create a helper to compute leftovers of realtime extents
  2023-10-11 18:05   ` [PATCH 3/7] " Darrick J. Wong
@ 2023-10-12  6:34     ` Christoph Hellwig
  0 siblings, 0 replies; 83+ messages in thread
From: Christoph Hellwig @ 2023-10-12  6:34 UTC (permalink / raw)
  To: Darrick J. Wong; +Cc: linux-xfs, osandov, hch

Looks good:

Reviewed-by: Christoph Hellwig <hch@lst.de>

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

* Re: [PATCH 1/8] xfs: convert the rtbitmap block and bit macros to static inline functions
  2023-10-11 18:06   ` [PATCH 1/8] xfs: convert the rtbitmap block and bit macros to static inline functions Darrick J. Wong
@ 2023-10-12  6:34     ` Christoph Hellwig
  0 siblings, 0 replies; 83+ messages in thread
From: Christoph Hellwig @ 2023-10-12  6:34 UTC (permalink / raw)
  To: Darrick J. Wong; +Cc: linux-xfs, osandov, hch

Looks good:

Reviewed-by: Christoph Hellwig <hch@lst.de>

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

* Re: [PATCH 1/7] xfs: make sure maxlen is still congruent with prod when rounding down
  2023-10-12  4:59     ` Christoph Hellwig
@ 2023-10-12 17:31       ` Darrick J. Wong
  2023-10-13  4:22         ` Christoph Hellwig
  0 siblings, 1 reply; 83+ messages in thread
From: Darrick J. Wong @ 2023-10-12 17:31 UTC (permalink / raw)
  To: Christoph Hellwig; +Cc: linux-xfs, osandov

On Thu, Oct 12, 2023 at 06:59:54AM +0200, Christoph Hellwig wrote:
> On Wed, Oct 11, 2023 at 11:02:50AM -0700, Darrick J. Wong wrote:
> > Fix the problem by reducing maxlen by any misalignment with prod.  While
> > we're at it, split the assertions into two so that we can tell which
> > value had the bad alignment.
> 
> Yay, I always hate it when I trigger these compund asserts..
> 
> >  		maxlen = min(mp->m_sb.sb_rextents, i + maxlen) - i;
> > +		maxlen -= maxlen % prod;
> 
> >  	maxlen = min(mp->m_sb.sb_rextents, bno + maxlen) - bno;
> > +	maxlen -= maxlen % prod;
> 
> Not sure if that's bikeshedding, but this almost asks for a little
> helper with a comment.

How about:

/*
 * Make sure we don't run off the end of the rt volume.  Be careful that
 * adjusting maxlen downwards doesn't cause us to fail the alignment checks.
 */
static inline xfs_extlen_t
xfs_rtallocate_clamp_len(
	struct xfs_mount	*mp,
	xfs_rtblock_t		startrtx,
	xfs_extlen_t		rtxlen,
	xfs_extlen_t		prod)
{
	xfs_extlen_t		ret;

	ret = min(mp->m_sb.sb_rextents, startrtx + rtxlen) - startrtx;
	return rounddown(ret, prod);
}

	minlen = xfs_rtallocate_clamp_len(mp, i, maxlen, prod);

and

	minlen = xfs_rtalloc_clamp_len(mp, bno, maxlen, prod);

--D

> Otherwise looks good:
> 
> Reviewed-by: Christoph Hellwig <hch@lst.de>

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

* Re: [PATCH 1/3] xfs: bump max fsgeom struct version
  2023-10-12  4:51     ` Christoph Hellwig
@ 2023-10-12 17:34       ` Darrick J. Wong
  0 siblings, 0 replies; 83+ messages in thread
From: Darrick J. Wong @ 2023-10-12 17:34 UTC (permalink / raw)
  To: Christoph Hellwig; +Cc: linux-xfs, osandov

On Thu, Oct 12, 2023 at 06:51:30AM +0200, Christoph Hellwig wrote:
> On Wed, Oct 11, 2023 at 11:02:03AM -0700, Darrick J. Wong wrote:
> > From: Darrick J. Wong <djwong@kernel.org>
> > 
> > The latest version of the fs geometry structure is v5.
> 
> The commit log and change left me a little confused, having it in
> a RT series even more.  So I went out and tried to understand it:
> 
>  - the fsgeom struct version is used by xfs_fs_geometry
>  - XFS_FS_GEOM_MAX_STRUCT_VER is not used in the kernel at all,
>    but libxfs uses it to always query all information in db and
>    mkfs
>  - commit 1b6d968de22bffd added the v5 structure, which mostly
>    contains extra padding, but otherwise just reports the struct
>    version for now
> 
> So this commit is a no-op for the kernel, and mostly a no-op for
> userspace as nothing looks at the new field, but probably useful
> for later changes.
> 
> Maybe capture this in the commit log.

I've changed the commit message to:

xfs: bump max fsgeom struct version

The latest version of the fs geometry structure is v5.  Bump this
constant so that xfs_db and mkfs calls to libxfs_fs_geometry will fill
out all the fields.

IOWs, this commit is a no-op for the kernel, but will be useful for
userspace reporting in later changes.

> With that:
> 
> Reviewed-by: Christoph Hellwig <hch@lst.de>

Thank you!

--D

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

* Re: [PATCH 2/7] xfs: create a helper to compute leftovers of realtime extents
  2023-10-12  5:11     ` Christoph Hellwig
@ 2023-10-12 17:40       ` Darrick J. Wong
  0 siblings, 0 replies; 83+ messages in thread
From: Darrick J. Wong @ 2023-10-12 17:40 UTC (permalink / raw)
  To: Christoph Hellwig; +Cc: linux-xfs, osandov

On Thu, Oct 12, 2023 at 07:11:40AM +0200, Christoph Hellwig wrote:
> > diff --git a/fs/xfs/libxfs/xfs_trans_inode.c b/fs/xfs/libxfs/xfs_trans_inode.c
> > index 3e07e7c6a5d53..29f1aa290ce6d 100644
> > --- a/fs/xfs/libxfs/xfs_trans_inode.c
> > +++ b/fs/xfs/libxfs/xfs_trans_inode.c
> > @@ -14,6 +14,7 @@
> >  #include "xfs_trans.h"
> >  #include "xfs_trans_priv.h"
> >  #include "xfs_inode_item.h"
> > +#include "xfs_rtbitmap.h"
> >  
> >  #include <linux/iversion.h>
> >  
> 
> This seems to just have slipped in here?

Oops, good catch.  I'll remove that.

> Otherwise looks good:
> 
> Reviewed-by: Christoph Hellwig <hch@lst.de>

Thanks!

--D

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

* Re: [PATCH 4/7] xfs: create helpers to convert rt block numbers to rt extent numbers
  2023-10-12  5:17     ` Christoph Hellwig
@ 2023-10-12 17:58       ` Darrick J. Wong
  2023-10-13  4:25         ` Christoph Hellwig
  0 siblings, 1 reply; 83+ messages in thread
From: Darrick J. Wong @ 2023-10-12 17:58 UTC (permalink / raw)
  To: Christoph Hellwig; +Cc: linux-xfs, osandov

On Thu, Oct 12, 2023 at 07:17:13AM +0200, Christoph Hellwig wrote:
> On Wed, Oct 11, 2023 at 11:05:27AM -0700, Darrick J. Wong wrote:
> > From: Darrick J. Wong <djwong@kernel.org>
> > 
> > Create helpers to do unit conversions of rt block numbers to rt extent
> > numbers.  There are two variations -- the suffix "t" denotes the one
> > that returns only the truncated extent number; the other one also
> > returns the misalignment.  Convert all the div_u64_rem users; we'll do
> > the do_div users in the next patch.
> 
> When trying to work with thee helpers I found the t prefix here a bit
> weird, as it works different than the T in say XFS_B_TO_FSB
> vs XFS_B_TO_FSBT which give you different results for the two versions.
> Here we get the same returned result, just with the additional
> return for the remainder.
> 
> Maybe have xfs_rtb_to_rtx and xfs_rtb_to_rtx_rem for the version with
> the modulo?

<nod> I've decided to go with:

/* Convert an rt block number into an rt extent number. */
static inline xfs_rtxnum_t
xfs_rtb_to_rtx(
	struct xfs_mount	*mp,
	xfs_rtblock_t		rtbno)
{
	return div_u64(rtbno, mp->m_sb.sb_rextsize);
}

/* Return the offset of an rt block number within an rt extent. */
static inline xfs_extlen_t
xfs_rtb_to_rtxoff(
	struct xfs_mount	*mp,
	xfs_rtblock_t		rtbno)
{
	return do_div(rtbno, mp->m_sb.sb_rextsize);
}

/*
 * Crack an rt block number into an rt extent number and an offset within that
 * rt extent.  Returns the rt extent number directly and the offset in @off.
 */
static inline xfs_rtxnum_t
xfs_rtb_to_rtxrem(
	struct xfs_mount	*mp,
	xfs_rtblock_t		rtbno,
	xfs_extlen_t		*off)
{
	return div_u64_rem(rtbno, mp->m_sb.sb_rextsize, off);
}

> We also have quite a few places that only care about the mod,
> so an additƣonal xfs_rtb_rem/mod might be useful as well.

Agreed, I had noticed that there were a fair number of places where
we're really only checking for rtx alignment.  xfs_rtb_to_rtxoff is
the new helper.

--D

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

* Re: [PATCH 5/7] xfs: convert do_div calls to xfs_rtb_to_rtx helper calls
  2023-10-12  5:22     ` Christoph Hellwig
@ 2023-10-12 18:10       ` Darrick J. Wong
  0 siblings, 0 replies; 83+ messages in thread
From: Darrick J. Wong @ 2023-10-12 18:10 UTC (permalink / raw)
  To: Christoph Hellwig; +Cc: linux-xfs, osandov

On Thu, Oct 12, 2023 at 07:22:18AM +0200, Christoph Hellwig wrote:
> On Wed, Oct 11, 2023 at 11:05:42AM -0700, Darrick J. Wong wrote:
> > -	if (isrt) {
> > -		uint64_t rtexts = XFS_FSB_TO_B(mp, del->br_blockcount);
> > -
> > -		do_div(rtexts, mp->m_sb.sb_rextsize);
> > -		xfs_mod_frextents(mp, rtexts);
> > -	}
> > +	if (isrt)
> > +		xfs_mod_frextents(mp, xfs_rtb_to_rtxt(mp, del->br_blockcount));
> 
> This is losing the XFS_FSB_TO_B conversion.  Now that conversion is
> bogus and doesn't match the rest of the code, and only the fact that
> we don't currently support delalloc on the RT device has saved our
> ass since fa5c836ca8e.  Maybe split this into a little prep patch with
> the a fixes tag?

Done.

--D

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

* Re: [PATCH 7/7] xfs: use shifting and masking when converting rt extents, if possible
  2023-10-12  5:25     ` Christoph Hellwig
@ 2023-10-12 18:19       ` Darrick J. Wong
  2023-10-16 17:19         ` Omar Sandoval
  0 siblings, 1 reply; 83+ messages in thread
From: Darrick J. Wong @ 2023-10-12 18:19 UTC (permalink / raw)
  To: Christoph Hellwig; +Cc: linux-xfs, osandov

On Thu, Oct 12, 2023 at 07:25:11AM +0200, Christoph Hellwig wrote:
> On Wed, Oct 11, 2023 at 11:06:14AM -0700, Darrick J. Wong wrote:
> > From: Darrick J. Wong <djwong@kernel.org>
> > 
> > Avoid the costs of integer division (32-bit and 64-bit) if the realtime
> > extent size is a power of two.
> 
> Looks good:
> 
> Reviewed-by: Christoph Hellwig <hch@lst.de>
> 
> Do you have any data on how common non-power of two rtext sizes are?
> Might it be worth to add unlikely annotations?

I don't really know about the historical uses.  There might be old
filesystems out there with a non-power-of-2 raid stripe size that are
set up for full stripe allocations for speed.

We (oracle) are interested in using rt for PMD allocations on pmem/cxl
devices and atomic writes on scsi/nvme devices.  Both of those cases
will only ever use powers of 2.

I'll add some if-test annotations and we'll see if anyone notices. ;)

--D

> > @@ -11,6 +11,9 @@ xfs_rtx_to_rtb(
> >  	struct xfs_mount	*mp,
> >  	xfs_rtxnum_t		rtx)
> >  {
> > +	if (mp->m_rtxblklog >= 0)
> > +		return rtx << mp->m_rtxblklog;
> > +
> >  	return rtx * mp->m_sb.sb_rextsize;
> 
> i.e.
> 
> 	if (unlikely(mp->m_rtxblklog == ‐1))
> 	  	return rtx * mp->m_sb.sb_rextsize;
> 	return rtx << mp->m_rtxblklog;
> 

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

* Re: [PATCH 2/8] xfs: remove XFS_BLOCKWSIZE and XFS_BLOCKWMASK macros
  2023-10-12  5:33     ` Christoph Hellwig
@ 2023-10-12 18:20       ` Darrick J. Wong
  2023-10-13  5:53         ` Christoph Hellwig
  0 siblings, 1 reply; 83+ messages in thread
From: Darrick J. Wong @ 2023-10-12 18:20 UTC (permalink / raw)
  To: Christoph Hellwig; +Cc: linux-xfs, osandov

On Thu, Oct 12, 2023 at 07:33:06AM +0200, Christoph Hellwig wrote:
> On Wed, Oct 11, 2023 at 11:06:45AM -0700, Darrick J. Wong wrote:
> > @@ -181,7 +181,7 @@ xfs_rtfind_back(
> >  				return error;
> >  			}
> >  			bufp = bp->b_addr;
> > -			word = XFS_BLOCKWMASK(mp);
> > +			word = mp->m_blockwsize - 1;
> >  			b = &bufp[word];
> >  		} else {
> >  			/*
> > @@ -227,7 +227,7 @@ xfs_rtfind_back(
> >  				return error;
> >  			}
> >  			bufp = bp->b_addr;
> > -			word = XFS_BLOCKWMASK(mp);
> > +			word = mp->m_blockwsize - 1;
> >  			b = &bufp[word];
> >  		} else {
> 
> Random rambling: there is a fairly large chunk of code duplicated
> here.  Maybe the caching series and/or Dave's suggest args cleanup
> would be good opportunity to refactor it.  Same for the next two
> clusters of two chunks.

Yeah, Dave and I will have to figure out how to integrate these two.
I might just pull in his rtalloc_args patch at the end of this series.

--D

> The patch itself looks good:
> 
> Reviewed-by: Christoph Hellwig <hch@lst.de>

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

* Re: [PATCH 3/8] xfs: convert open-coded xfs_rtword_t pointer accesses to helper
  2023-10-12  5:39     ` Christoph Hellwig
@ 2023-10-12 18:26       ` Darrick J. Wong
  0 siblings, 0 replies; 83+ messages in thread
From: Darrick J. Wong @ 2023-10-12 18:26 UTC (permalink / raw)
  To: Christoph Hellwig; +Cc: linux-xfs, osandov

On Thu, Oct 12, 2023 at 07:39:54AM +0200, Christoph Hellwig wrote:
> On Wed, Oct 11, 2023 at 11:07:01AM -0700, Darrick J. Wong wrote:
> > +/* Return a pointer to a bitmap word within a rt bitmap block buffer. */
> > +static inline xfs_rtword_t *
> > +xfs_rbmbuf_wordptr(
> > +	void			*buf,
> > +	unsigned int		rbmword)
> > +{
> > +	xfs_rtword_t		*wordp = buf;
> > +
> > +	return &wordp[rbmword];
> 
> Superficial nitpick, I find the array dereference syntax here highly
> confusing as the passed in pointer is not an array at all.
> 
> In fact I wonder what the xfs_rbmbuf_wordptr helper is for?  Even
> looking at your full patch stack xfs_rbmblock_wordptr seems like
> the only user.

IIRC an earlier version of this patchset actually tried to use
xfs_rbmbuf_wordptr in the online repair code when it was building the
new rtbitmap file contents.  At some point I must've decided that it was
easier to access the xfile directly.

So, yes, this helper can be deleted.

> > +/* Return a pointer to a bitmap word within a rt bitmap block. */
> > +static inline xfs_rtword_t *
> > +xfs_rbmblock_wordptr(
> > +	struct xfs_buf		*bp,
> > +	unsigned int		rbmword)
> > +{
> > +	return xfs_rbmbuf_wordptr(bp->b_addr, rbmword);
> 
> So I'd much rather just open code this as:
> 
> 	xfs_rtword_t		*words = bp->b_addr;
> 
> 	return words + rbmword;
> 
> and if I want to get really fancy I'd maybe rename rbmword to
> something like index which feels more readable than rbmword.

Done.

> That beeing said the xfs_rbmblock_wordptr abstraction is very welcome.

Thanks!

--D

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

* Re: [PATCH 5/8] xfs: create helpers for rtbitmap block/wordcount computations
  2023-10-12  5:44     ` Christoph Hellwig
@ 2023-10-12 21:55       ` Darrick J. Wong
  2023-10-13  4:26         ` Christoph Hellwig
  0 siblings, 1 reply; 83+ messages in thread
From: Darrick J. Wong @ 2023-10-12 21:55 UTC (permalink / raw)
  To: Christoph Hellwig; +Cc: linux-xfs, osandov

On Thu, Oct 12, 2023 at 07:44:33AM +0200, Christoph Hellwig wrote:
> On Wed, Oct 11, 2023 at 11:07:32AM -0700, Darrick J. Wong wrote:
> > +/*
> > + * Compute the number of rtbitmap blocks needed to track the given number of rt
> > + * extents.
> > + */
> > +xfs_filblks_t
> > +xfs_rtbitmap_blockcount(
> > +	struct xfs_mount	*mp,
> > +	xfs_rtbxlen_t		rtextents)
> > +{
> > +	return howmany_64(rtextents, NBBY * mp->m_sb.sb_blocksize);
> > +}
> 
> Given that this only has a few users, the !RT stub is a pain, and
> having a different result from before in the transaction reservation
> is somewhat unexpected change (even if harmless),

Ohh, right, I didn't even notice that the result changes slightly when
the we go from dividing by NBBY before howmany'ing with blocksize to
howmany'ing with (NBBY * blocksize).

> maybe just mark this inline?

I could make these inline functions at the bottom of xfs_rtbitmap.h, and
even put them outside of the #ifdef RT bits.  That'll get rid of two
stubs for now, but later the rtgroups patchset wants to add a header
to rtbitmap blocks.  Then we'll need a function to compute the number of
rtextents covered by a single bitmap block:

/* Compute the number of rt extents tracked by a single bitmap block. */
xfs_rtxnum_t
xfs_rtbitmap_rtx_per_rbmblock(
	struct xfs_mount	*mp)
{
	unsigned int		rbmblock_bytes = mp->m_sb.sb_blocksize;

	if (xfs_has_rtgroups(mp))
		rbmblock_bytes -= sizeof(struct xfs_rtbuf_blkinfo);

	return rbmblock_bytes * NBBY;
}

So then either this function will need to have a stub that returns a
garbage value.  Alternately, it could move out of xfs_rtbitmap.c.

Right now, xfs_rtbitmap_rtx_per_rbmblock isn't even a defined symbol for
!RT, and the stub version of _wordcount and _blockcount return 0, which
at least makes sense.

> > +/*
> > + * Compute the number of rtbitmap words needed to populate every block of a
> > + * bitmap that is large enough to track the given number of rt extents.
> > + */
> > +unsigned long long
> > +xfs_rtbitmap_wordcount(
> > +	struct xfs_mount	*mp,
> > +	xfs_rtbxlen_t		rtextents)
> > +{
> > +	xfs_filblks_t		blocks;
> > +
> > +	blocks = xfs_rtbitmap_blockcount(mp, rtextents);
> > +	return XFS_FSB_TO_B(mp, blocks) >> XFS_WORDLOG;
> > +}
> 
> This one isn't used in this patch or the rest of the series.  Maybe
> move it to the patch (-series) that adds the caller in the repair
> code?

<shrug> The xfsprogs version of this patch uses this helper to decrapify
the incore rtbitmap computation in xfs_repair:

diff --git a/repair/rt.c b/repair/rt.c
index 8f3b9082a9b..244b59f04ce 100644
--- a/repair/rt.c
+++ b/repair/rt.c
@@ -19,6 +19,8 @@
 void
 rtinit(xfs_mount_t *mp)
 {
+       unsigned long long      wordcnt;
+
        if (mp->m_sb.sb_rblocks == 0)
                return;
 
@@ -26,11 +28,9 @@ rtinit(xfs_mount_t *mp)
         * realtime init -- blockmap initialization is
         * handled by incore_init()
         */
-       /*
-       sumfile = calloc(mp->m_rsumsize, 1);
-       */
-       if ((btmcompute = calloc(mp->m_sb.sb_rbmblocks *
-                       mp->m_sb.sb_blocksize, 1)) == NULL)
+       wordcnt = libxfs_rtbitmap_wordcount(mp, mp->m_sb.sb_rextents);
+       btmcompute = calloc(wordcnt, sizeof(xfs_rtword_t));
+       if (!btmcompute)
                do_error(
        _("couldn't allocate memory for incore realtime bitmap.\n"));

So I'd rather leave these two helpers defined as they are.

--D

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

* Re: [PATCH 6/8] xfs: use accessor functions for bitmap words
  2023-10-12  6:19     ` Christoph Hellwig
@ 2023-10-12 22:11       ` Darrick J. Wong
  2023-10-13  4:28         ` Christoph Hellwig
  0 siblings, 1 reply; 83+ messages in thread
From: Darrick J. Wong @ 2023-10-12 22:11 UTC (permalink / raw)
  To: Christoph Hellwig; +Cc: linux-xfs, osandov

On Thu, Oct 12, 2023 at 08:19:16AM +0200, Christoph Hellwig wrote:
> On Wed, Oct 11, 2023 at 11:07:48AM -0700, Darrick J. Wong wrote:
> > From: Darrick J. Wong <djwong@kernel.org>
> > 
> > Create get and set functions for rtbitmap words so that we can redefine
> > the ondisk format with a specific endianness.  Note that this requires
> > the definition of a distinct type for ondisk rtbitmap words so that the
> > compiler can perform proper typechecking as we go back and forth.
> > 
> > In the upcoming rtgroups feature, we're going to fix the problem that
> > rtwords are written in host endian order, which means we'll need the
> > distinct rtword/rtword_raw types.
> 
> I've been looking over this and I have to say I kinda hate the
> abstraction level.
> 
> Having to deal with both the union xfs_rtword_ondisk, and the
> normal in-memory rtword just feels cumbersome.
> 
> I'd go for an API that gets/sets the values based on [bp, word] indices
> instead.  That would also need helpers for logging the buffer ranges
> based on indices, which seems helpful for the code quality anyway.
> 
> I don't really want to burden that on you and would offer to do that
> work myself after we work before this merged.

Hmm, so you want to go from:

	union xfs_rtword_ondisk *start, *end, *b;

	start = b = xfs_rbmblock_wordptr(bp, startword);
	end = xfs_rbmblock_wordptr(bp, endword);

	while (b < end) {
		somevalue = xfs_rtbitmap_getword(mp, b);
		somevalue |= somemask;
		xfs_rtbitmap_setword(mp, b, somevalue);
		b++;
	}

	xfs_trans_log_buf(tp, bp, start - bp->b_addr, b - bp->b_addr);

to something like:

	for (word = startword; word <= endword; word++) {
		somevalue = xfs_rtbitmap_getword(mp, b);
		somevalue |= somemask;
		xfs_rtbitmap_setword(mp, bp, word, somevalue);
	}
	xfs_rtbitmap_log_buf(tp, bp, startword, endword);

I think that could be done with relatively little churn, though it's
unfortunate that the second version does 2x(shift + addition) each time
it goes through the loop instead of the pointer increment that the first
version does.

--D

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

* Re: [PATCH 7/8] xfs: create helpers for rtsummary block/wordcount computations
  2023-10-12  6:25     ` Christoph Hellwig
@ 2023-10-12 22:18       ` Darrick J. Wong
  2023-10-13  4:29         ` Christoph Hellwig
  0 siblings, 1 reply; 83+ messages in thread
From: Darrick J. Wong @ 2023-10-12 22:18 UTC (permalink / raw)
  To: Christoph Hellwig; +Cc: linux-xfs, osandov

On Thu, Oct 12, 2023 at 08:25:51AM +0200, Christoph Hellwig wrote:
> On Wed, Oct 11, 2023 at 11:08:03AM -0700, Darrick J. Wong wrote:
> > +/* Compute the number of rtsummary blocks needed to track the given rt space. */
> > +xfs_filblks_t
> > +xfs_rtsummary_blockcount(
> > +	struct xfs_mount	*mp,
> > +	unsigned int		rsumlevels,
> > +	xfs_extlen_t		rbmblocks)
> > +{
> > +	unsigned long long	rsumwords;
> > +
> > +	rsumwords = (unsigned long long)rsumlevels * rbmblocks;
> > +	return XFS_B_TO_FSB(mp, rsumwords << XFS_WORDLOG);
> > +}
> 
> This helper and its users make complete sense to me and looks good:
> 
> Reviewed-by: Christoph Hellwig <hch@lst.de>
> 
> > +/*
> > + * Compute the number of rtsummary info words needed to populate every block of
> > + * a summary file that is large enough to track the given rt space.
> > + */
> > +unsigned long long
> > +xfs_rtsummary_wordcount(
> > +	struct xfs_mount	*mp,
> > +	unsigned int		rsumlevels,
> > +	xfs_extlen_t		rbmblocks)
> > +{
> > +	xfs_filblks_t		blocks;
> > +
> > +	blocks = xfs_rtsummary_blockcount(mp, rsumlevels, rbmblocks);
> > +	return XFS_FSB_TO_B(mp, blocks) >> XFS_WORDLOG;
> > +}
> 
> > @@ -54,8 +55,10 @@ xchk_setup_rtsummary(
> >  	 * Create an xfile to construct a new rtsummary file.  The xfile allows
> >  	 * us to avoid pinning kernel memory for this purpose.
> >  	 */
> > +	wordcnt = xfs_rtsummary_wordcount(mp, mp->m_rsumlevels,
> > +			mp->m_sb.sb_rbmblocks);
> >  	descr = xchk_xfile_descr(sc, "realtime summary file");
> > -	error = xfile_create(descr, mp->m_rsumsize, &sc->xfile);
> > +	error = xfile_create(descr, wordcnt << XFS_WORDLOG, &sc->xfile);
> >  	kfree(descr);
> 
> But this confuses me.  What problem does it solve over just using
> m_rsumsize?

The rtbitmap and rtsummary repair code should be computing rbmblocks and
rsumsize from sb_rextents.

rbmblocks = xfs_rtbitmap_wordcount(mp, mp->m_sb.sb_rextents);
rsumsize = xfs_rtsummary_wordcount(mp, mp->m_rsumlevels, rbmblocks);

From that, it should be checking isize and the data fork mappings of
the file and the superblock values.  Repair ought to map (or unmap)
blocks as necessary, update isize if needed, and update the superblock
if the values there are incorrect.

--D

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

* Re: [PATCH 8/8] xfs: use accessor functions for summary info words
  2023-10-12  6:26     ` Christoph Hellwig
@ 2023-10-12 22:21       ` Darrick J. Wong
  0 siblings, 0 replies; 83+ messages in thread
From: Darrick J. Wong @ 2023-10-12 22:21 UTC (permalink / raw)
  To: Christoph Hellwig; +Cc: linux-xfs, osandov

On Thu, Oct 12, 2023 at 08:26:19AM +0200, Christoph Hellwig wrote:
> On Wed, Oct 11, 2023 at 11:08:19AM -0700, Darrick J. Wong wrote:
> > From: Darrick J. Wong <djwong@kernel.org>
> > 
> > Create get and set functions for rtsummary words so that we can redefine
> > the ondisk format with a specific endianness.  Note that this requires
> > the definition of a distinct type for ondisk summary info words so that
> > the compiler can perform proper typechecking.
> 
> Same comment as for the bitmap access, including the same offer.

<nod> I'll take you up on that, if you think the tradeoffs is worth it.
:)

--D

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

* Re: [PATCHSET RFC v1.0 0/7] xfs: clean up realtime type usage
  2023-10-12  5:05   ` [PATCHSET RFC v1.0 0/7] xfs: clean up realtime type usage Christoph Hellwig
@ 2023-10-12 22:30     ` Darrick J. Wong
  2023-10-13  4:24       ` Christoph Hellwig
  0 siblings, 1 reply; 83+ messages in thread
From: Darrick J. Wong @ 2023-10-12 22:30 UTC (permalink / raw)
  To: Christoph Hellwig; +Cc: linux-xfs, osandov

On Thu, Oct 12, 2023 at 07:05:27AM +0200, Christoph Hellwig wrote:
> On Wed, Oct 11, 2023 at 11:01:16AM -0700, Darrick J. Wong wrote:
> > Hi all,
> > 
> > The realtime code uses xfs_rtblock_t and xfs_fsblock_t in a lot of
> > places, and it's very confusing.  Clean up all the type usage so that an
> > xfs_rtblock_t is always a block within the realtime volume, an
> > xfs_fileoff_t is always a file offset within a realtime metadata file,
> > and an xfs_rtxnumber_t is always a rt extent within the realtime volume.
> 
> Question as a follow up:  now that we have proper types for all
> the RT-specific units, what's the point of even keeping xfs_rtblock_t
> around vs always using xfs_fsblock_t or xfs_rfsblock_t?

The primary advantage that I can think of is code readability -- all the
xfs_*rtb_ functions take xfs_rtblock_t types, and you can follow them
all the way through the rt allocator/rmap/refcount code.  xfs_rtblock_t
is a linear quantity even with rtgroups turned on.

The gross part is that one still has to know that br_startblock can be
either xfs_fsblock_t or xfs_rtblock_t depending on inode and whichfork.

That said, I don't think gcc actually warns about silent casts from
xfs_fsblock_t to xfs_rtblock_t.

--D

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

* Re: [PATCH 1/7] xfs: make sure maxlen is still congruent with prod when rounding down
  2023-10-12 17:31       ` Darrick J. Wong
@ 2023-10-13  4:22         ` Christoph Hellwig
  0 siblings, 0 replies; 83+ messages in thread
From: Christoph Hellwig @ 2023-10-13  4:22 UTC (permalink / raw)
  To: Darrick J. Wong; +Cc: Christoph Hellwig, linux-xfs, osandov

On Thu, Oct 12, 2023 at 10:31:46AM -0700, Darrick J. Wong wrote:
> /*
>  * Make sure we don't run off the end of the rt volume.  Be careful that
>  * adjusting maxlen downwards doesn't cause us to fail the alignment checks.
>  */
> static inline xfs_extlen_t
> xfs_rtallocate_clamp_len(
> 	struct xfs_mount	*mp,
> 	xfs_rtblock_t		startrtx,
> 	xfs_extlen_t		rtxlen,
> 	xfs_extlen_t		prod)
> {
> 	xfs_extlen_t		ret;
> 
> 	ret = min(mp->m_sb.sb_rextents, startrtx + rtxlen) - startrtx;
> 	return rounddown(ret, prod);
> }
> 
> 	minlen = xfs_rtallocate_clamp_len(mp, i, maxlen, prod);
> 
> and
> 
> 	minlen = xfs_rtalloc_clamp_len(mp, bno, maxlen, prod);

Looks good:

Reviewed-by: Christoph Hellwig <hch@lst.de>

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

* Re: [PATCHSET RFC v1.0 0/7] xfs: clean up realtime type usage
  2023-10-12 22:30     ` Darrick J. Wong
@ 2023-10-13  4:24       ` Christoph Hellwig
  2023-10-17  0:48         ` Darrick J. Wong
  0 siblings, 1 reply; 83+ messages in thread
From: Christoph Hellwig @ 2023-10-13  4:24 UTC (permalink / raw)
  To: Darrick J. Wong; +Cc: Christoph Hellwig, linux-xfs, osandov

On Thu, Oct 12, 2023 at 03:30:00PM -0700, Darrick J. Wong wrote:
> The primary advantage that I can think of is code readability -- all the
> xfs_*rtb_ functions take xfs_rtblock_t types, and you can follow them
> all the way through the rt allocator/rmap/refcount code.  xfs_rtblock_t
> is a linear quantity even with rtgroups turned on.
> 
> The gross part is that one still has to know that br_startblock can be
> either xfs_fsblock_t or xfs_rtblock_t depending on inode and whichfork.

Yeah.

> That said, I don't think gcc actually warns about silent casts from
> xfs_fsblock_t to xfs_rtblock_t.


typedefs in C are syntactix shugar.  You will never get a warning about
mixing typedefs for the same underlying type (and often also not for
mixing with other integer types).  Having an annotation for a strong
typedef that can only do arithmetic on itself without casts or special
annotations would be really handy, though.

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

* Re: [PATCH 4/7] xfs: create helpers to convert rt block numbers to rt extent numbers
  2023-10-12 17:58       ` Darrick J. Wong
@ 2023-10-13  4:25         ` Christoph Hellwig
  0 siblings, 0 replies; 83+ messages in thread
From: Christoph Hellwig @ 2023-10-13  4:25 UTC (permalink / raw)
  To: Darrick J. Wong; +Cc: Christoph Hellwig, linux-xfs, osandov

On Thu, Oct 12, 2023 at 10:58:33AM -0700, Darrick J. Wong wrote:
> <nod> I've decided to go with:

This looks good to me, thanks.


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

* Re: [PATCH 5/8] xfs: create helpers for rtbitmap block/wordcount computations
  2023-10-12 21:55       ` Darrick J. Wong
@ 2023-10-13  4:26         ` Christoph Hellwig
  0 siblings, 0 replies; 83+ messages in thread
From: Christoph Hellwig @ 2023-10-13  4:26 UTC (permalink / raw)
  To: Darrick J. Wong; +Cc: Christoph Hellwig, linux-xfs, osandov

On Thu, Oct 12, 2023 at 02:55:46PM -0700, Darrick J. Wong wrote:
> <shrug> The xfsprogs version of this patch uses this helper to decrapify
> the incore rtbitmap computation in xfs_repair:

Ok, let's keep them as-is.


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

* Re: [PATCH 6/8] xfs: use accessor functions for bitmap words
  2023-10-12 22:11       ` Darrick J. Wong
@ 2023-10-13  4:28         ` Christoph Hellwig
  2023-10-13 16:58           ` Darrick J. Wong
  0 siblings, 1 reply; 83+ messages in thread
From: Christoph Hellwig @ 2023-10-13  4:28 UTC (permalink / raw)
  To: Darrick J. Wong; +Cc: Christoph Hellwig, linux-xfs, osandov

On Thu, Oct 12, 2023 at 03:11:06PM -0700, Darrick J. Wong wrote:
> Hmm, so you want to go from:
> 
> 	union xfs_rtword_ondisk *start, *end, *b;
> 
> 	start = b = xfs_rbmblock_wordptr(bp, startword);
> 	end = xfs_rbmblock_wordptr(bp, endword);
> 
> 	while (b < end) {
> 		somevalue = xfs_rtbitmap_getword(mp, b);
> 		somevalue |= somemask;
> 		xfs_rtbitmap_setword(mp, b, somevalue);
> 		b++;
> 	}
> 
> 	xfs_trans_log_buf(tp, bp, start - bp->b_addr, b - bp->b_addr);
> 
> to something like:
> 
> 	for (word = startword; word <= endword; word++) {
> 		somevalue = xfs_rtbitmap_getword(mp, b);
> 		somevalue |= somemask;
> 		xfs_rtbitmap_setword(mp, bp, word, somevalue);
> 	}
> 	xfs_rtbitmap_log_buf(tp, bp, startword, endword);

Yes. (although xfs_rtbitmap_log_buf can't just take the words directly
of course, and the xfs_rtbitmap_getword needs word and not the now
not existing b).

> I think that could be done with relatively little churn, though it's
> unfortunate that the second version does 2x(shift + addition) each time
> it goes through the loop instead of the pointer increment that the first
> version does.

I don't really think it matter compared to all the other overhead,
and it keeps a much nicer API.


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

* Re: [PATCH 7/8] xfs: create helpers for rtsummary block/wordcount computations
  2023-10-12 22:18       ` Darrick J. Wong
@ 2023-10-13  4:29         ` Christoph Hellwig
  2023-10-13 17:11           ` Darrick J. Wong
  0 siblings, 1 reply; 83+ messages in thread
From: Christoph Hellwig @ 2023-10-13  4:29 UTC (permalink / raw)
  To: Darrick J. Wong; +Cc: Christoph Hellwig, linux-xfs, osandov

On Thu, Oct 12, 2023 at 03:18:36PM -0700, Darrick J. Wong wrote:
> > > @@ -54,8 +55,10 @@ xchk_setup_rtsummary(
> > >  	 * Create an xfile to construct a new rtsummary file.  The xfile allows
> > >  	 * us to avoid pinning kernel memory for this purpose.
> > >  	 */
> > > +	wordcnt = xfs_rtsummary_wordcount(mp, mp->m_rsumlevels,
> > > +			mp->m_sb.sb_rbmblocks);
> > >  	descr = xchk_xfile_descr(sc, "realtime summary file");
> > > -	error = xfile_create(descr, mp->m_rsumsize, &sc->xfile);
> > > +	error = xfile_create(descr, wordcnt << XFS_WORDLOG, &sc->xfile);
> > >  	kfree(descr);
> > 
> > But this confuses me.  What problem does it solve over just using
> > m_rsumsize?
> 
> The rtbitmap and rtsummary repair code should be computing rbmblocks and
> rsumsize from sb_rextents.
> 
> rbmblocks = xfs_rtbitmap_wordcount(mp, mp->m_sb.sb_rextents);
> rsumsize = xfs_rtsummary_wordcount(mp, mp->m_rsumlevels, rbmblocks);
> 
> >From that, it should be checking isize and the data fork mappings of
> the file and the superblock values.  Repair ought to map (or unmap)
> blocks as necessary, update isize if needed, and update the superblock
> if the values there are incorrect.

So this is really a feature path that should be documented as such
and not just be about adding a helper?


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

* Re: [PATCH 2/8] xfs: remove XFS_BLOCKWSIZE and XFS_BLOCKWMASK macros
  2023-10-12 18:20       ` Darrick J. Wong
@ 2023-10-13  5:53         ` Christoph Hellwig
  2023-10-17  0:49           ` Darrick J. Wong
  0 siblings, 1 reply; 83+ messages in thread
From: Christoph Hellwig @ 2023-10-13  5:53 UTC (permalink / raw)
  To: Darrick J. Wong; +Cc: Christoph Hellwig, linux-xfs, osandov

On Thu, Oct 12, 2023 at 11:20:30AM -0700, Darrick J. Wong wrote:
> > Random rambling: there is a fairly large chunk of code duplicated
> > here.  Maybe the caching series and/or Dave's suggest args cleanup
> > would be good opportunity to refactor it.  Same for the next two
> > clusters of two chunks.
> 
> Yeah, Dave and I will have to figure out how to integrate these two.
> I might just pull in his rtalloc_args patch at the end of this series.

They way I understood his review of Omars patches isn't that he
has a rtalloc_args patch, but suggest adding that structure.

I can take care of that after your series and Omar has landed, together
with the bitmap/summary access abstraction.

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

* Re: [PATCH 6/8] xfs: use accessor functions for bitmap words
  2023-10-13  4:28         ` Christoph Hellwig
@ 2023-10-13 16:58           ` Darrick J. Wong
  0 siblings, 0 replies; 83+ messages in thread
From: Darrick J. Wong @ 2023-10-13 16:58 UTC (permalink / raw)
  To: Christoph Hellwig; +Cc: linux-xfs, osandov

On Fri, Oct 13, 2023 at 06:28:33AM +0200, Christoph Hellwig wrote:
> On Thu, Oct 12, 2023 at 03:11:06PM -0700, Darrick J. Wong wrote:
> > Hmm, so you want to go from:
> > 
> > 	union xfs_rtword_ondisk *start, *end, *b;
> > 
> > 	start = b = xfs_rbmblock_wordptr(bp, startword);
> > 	end = xfs_rbmblock_wordptr(bp, endword);
> > 
> > 	while (b < end) {
> > 		somevalue = xfs_rtbitmap_getword(mp, b);
> > 		somevalue |= somemask;
> > 		xfs_rtbitmap_setword(mp, b, somevalue);
> > 		b++;
> > 	}
> > 
> > 	xfs_trans_log_buf(tp, bp, start - bp->b_addr, b - bp->b_addr);
> > 
> > to something like:
> > 
> > 	for (word = startword; word <= endword; word++) {
> > 		somevalue = xfs_rtbitmap_getword(mp, b);
> > 		somevalue |= somemask;
> > 		xfs_rtbitmap_setword(mp, bp, word, somevalue);
> > 	}
> > 	xfs_rtbitmap_log_buf(tp, bp, startword, endword);
> 
> Yes. (although xfs_rtbitmap_log_buf can't just take the words directly
> of course, and the xfs_rtbitmap_getword needs word and not the now
> not existing b).
> 
> > I think that could be done with relatively little churn, though it's
> > unfortunate that the second version does 2x(shift + addition) each time
> > it goes through the loop instead of the pointer increment that the first
> > version does.
> 
> I don't really think it matter compared to all the other overhead,
> and it keeps a much nicer API.

<nod> I suppose one could go the horrid iter function route to get
around the multiply, though at this point there's an awful lot of code
to do something very simple:

struct xfs_rbmword_cur {
	struct xfs_buf	*bp;
	xfs_rtword_t	*wordptr;
	unsigned int	endword;
	unsigned int	word;
};

static inline bool
xfs_rtbitmap_word_iter(
	struct xfs_rbmword_cur	*cur,
	xfs_rtword_t		*val)
{
	if (cur->word >= cur->endword)
		return false;

	if (!cur->wordptr)
		cur->wordptr = xfs_rbmblock_wordptr(cur->bp, cur->word);

	*val = *cur->wordptr;
	cur->word++;
	cur->wordptr++;
	return true;
}

static inline void
xfs_rtbitmap_word_set(
	struct xfs_rbmword_cur	*cur,
	xfs_rtword_t		val)
{
	*(cur->wordptr - 1) = val;
}

Usage:

	struct xfs_rbword_cur	cur = {
		.bp		= bp,
		.word		= startword,
		.endword	= endword,
	};
	xfs_rtword_t		val;

	while (xfs_rtbitmap_word_iter(&cur, &val)) {
		val |= somemask;
		xfs_rtbitmap_word_set(cur, val);
	}
	xfs_rtbitmap_log_buf(tp, bp, startword, endword);

--D

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

* Re: [PATCH 7/8] xfs: create helpers for rtsummary block/wordcount computations
  2023-10-13  4:29         ` Christoph Hellwig
@ 2023-10-13 17:11           ` Darrick J. Wong
  0 siblings, 0 replies; 83+ messages in thread
From: Darrick J. Wong @ 2023-10-13 17:11 UTC (permalink / raw)
  To: Christoph Hellwig; +Cc: linux-xfs, osandov

On Fri, Oct 13, 2023 at 06:29:47AM +0200, Christoph Hellwig wrote:
> On Thu, Oct 12, 2023 at 03:18:36PM -0700, Darrick J. Wong wrote:
> > > > @@ -54,8 +55,10 @@ xchk_setup_rtsummary(
> > > >  	 * Create an xfile to construct a new rtsummary file.  The xfile allows
> > > >  	 * us to avoid pinning kernel memory for this purpose.
> > > >  	 */
> > > > +	wordcnt = xfs_rtsummary_wordcount(mp, mp->m_rsumlevels,
> > > > +			mp->m_sb.sb_rbmblocks);
> > > >  	descr = xchk_xfile_descr(sc, "realtime summary file");
> > > > -	error = xfile_create(descr, mp->m_rsumsize, &sc->xfile);
> > > > +	error = xfile_create(descr, wordcnt << XFS_WORDLOG, &sc->xfile);
> > > >  	kfree(descr);
> > > 
> > > But this confuses me.  What problem does it solve over just using
> > > m_rsumsize?
> > 
> > The rtbitmap and rtsummary repair code should be computing rbmblocks and
> > rsumsize from sb_rextents.
> > 
> > rbmblocks = xfs_rtbitmap_wordcount(mp, mp->m_sb.sb_rextents);
> > rsumsize = xfs_rtsummary_wordcount(mp, mp->m_rsumlevels, rbmblocks);
> > 
> > >From that, it should be checking isize and the data fork mappings of
> > the file and the superblock values.  Repair ought to map (or unmap)
> > blocks as necessary, update isize if needed, and update the superblock
> > if the values there are incorrect.
> 
> So this is really a feature path that should be documented as such
> and not just be about adding a helper?

Yeah.  If these rt cleanups land before online repair, then that whole
hunk won't be in the patch that we merge anyway.  In that case, I'll
want the helpers simply to reduce the number of things I have to keep
track of.

(meanwhile I think the pre-rtgroups rtbitmap and rtsummary code need
some fixing...)

--D

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

* Re: [PATCH 7/7] xfs: use shifting and masking when converting rt extents, if possible
  2023-10-12 18:19       ` Darrick J. Wong
@ 2023-10-16 17:19         ` Omar Sandoval
  2023-10-17  0:51           ` Darrick J. Wong
  0 siblings, 1 reply; 83+ messages in thread
From: Omar Sandoval @ 2023-10-16 17:19 UTC (permalink / raw)
  To: Darrick J. Wong; +Cc: Christoph Hellwig, linux-xfs

On Thu, Oct 12, 2023 at 11:19:08AM -0700, Darrick J. Wong wrote:
> On Thu, Oct 12, 2023 at 07:25:11AM +0200, Christoph Hellwig wrote:
> > On Wed, Oct 11, 2023 at 11:06:14AM -0700, Darrick J. Wong wrote:
> > > From: Darrick J. Wong <djwong@kernel.org>
> > > 
> > > Avoid the costs of integer division (32-bit and 64-bit) if the realtime
> > > extent size is a power of two.
> > 
> > Looks good:
> > 
> > Reviewed-by: Christoph Hellwig <hch@lst.de>
> > 
> > Do you have any data on how common non-power of two rtext sizes are?
> > Might it be worth to add unlikely annotations?
> 
> I don't really know about the historical uses.  There might be old
> filesystems out there with a non-power-of-2 raid stripe size that are
> set up for full stripe allocations for speed.
> 
> We (oracle) are interested in using rt for PMD allocations on pmem/cxl
> devices and atomic writes on scsi/nvme devices.  Both of those cases
> will only ever use powers of 2.
> 
> I'll add some if-test annotations and we'll see if anyone notices. ;)
> 
> --D

We are using 1044KB realtime extents (blocksize = 4096, rextsize = 261)
for our blob storage system. It's a goofy number, but IIRC it was chosen
because their most common blob sizes were single-digit multiples of a
megabyte, and they wanted a large-ish (~1MB) realtime extent size to
reduce external fragmentation, but they also wanted to store a bit of
extra metadata without requiring an extra realtime extent and blowing up
internal fragmentation.

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

* Re: [PATCHSET RFC v1.0 0/7] xfs: clean up realtime type usage
  2023-10-13  4:24       ` Christoph Hellwig
@ 2023-10-17  0:48         ` Darrick J. Wong
  2023-10-17  4:05           ` Christoph Hellwig
  0 siblings, 1 reply; 83+ messages in thread
From: Darrick J. Wong @ 2023-10-17  0:48 UTC (permalink / raw)
  To: Christoph Hellwig; +Cc: linux-xfs, osandov

On Fri, Oct 13, 2023 at 06:24:34AM +0200, Christoph Hellwig wrote:
> On Thu, Oct 12, 2023 at 03:30:00PM -0700, Darrick J. Wong wrote:
> > The primary advantage that I can think of is code readability -- all the
> > xfs_*rtb_ functions take xfs_rtblock_t types, and you can follow them
> > all the way through the rt allocator/rmap/refcount code.  xfs_rtblock_t
> > is a linear quantity even with rtgroups turned on.
> > 
> > The gross part is that one still has to know that br_startblock can be
> > either xfs_fsblock_t or xfs_rtblock_t depending on inode and whichfork.
> 
> Yeah.
> 
> > That said, I don't think gcc actually warns about silent casts from
> > xfs_fsblock_t to xfs_rtblock_t.
> 
> 
> typedefs in C are syntactix shugar.  You will never get a warning about
> mixing typedefs for the same underlying type (and often also not for
> mixing with other integer types).  Having an annotation for a strong
> typedef that can only do arithmetic on itself without casts or special
> annotations would be really handy, though.

We can do it crappily in C with __bitwise and letting the static checker
bots go wild.  Some day when someone rewrites the entire codebase in
Rust (HA!) then we'll be able to do:

struct xfs_fsblock_t(u64);
struct xfs_agblock_t(u32);

and (to the extent that I understand Rust) the Rust compiler will
complain about stuffing xfs_agblock_t into an xfs_fsblock_t without a
proper conversion.

--D

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

* Re: [PATCH 2/8] xfs: remove XFS_BLOCKWSIZE and XFS_BLOCKWMASK macros
  2023-10-13  5:53         ` Christoph Hellwig
@ 2023-10-17  0:49           ` Darrick J. Wong
  0 siblings, 0 replies; 83+ messages in thread
From: Darrick J. Wong @ 2023-10-17  0:49 UTC (permalink / raw)
  To: Christoph Hellwig; +Cc: linux-xfs, osandov

On Fri, Oct 13, 2023 at 07:53:24AM +0200, Christoph Hellwig wrote:
> On Thu, Oct 12, 2023 at 11:20:30AM -0700, Darrick J. Wong wrote:
> > > Random rambling: there is a fairly large chunk of code duplicated
> > > here.  Maybe the caching series and/or Dave's suggest args cleanup
> > > would be good opportunity to refactor it.  Same for the next two
> > > clusters of two chunks.
> > 
> > Yeah, Dave and I will have to figure out how to integrate these two.
> > I might just pull in his rtalloc_args patch at the end of this series.
> 
> They way I understood his review of Omars patches isn't that he
> has a rtalloc_args patch, but suggest adding that structure.
> 
> I can take care of that after your series and Omar has landed, together
> with the bitmap/summary access abstraction.

Ah.  I stg import'd Dave's suggestionpatch and it more or less applied,
so it's already in the work branch.  It also reduced Omar's patchset
quite a bit.

--D

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

* Re: [PATCH 7/7] xfs: use shifting and masking when converting rt extents, if possible
  2023-10-16 17:19         ` Omar Sandoval
@ 2023-10-17  0:51           ` Darrick J. Wong
  0 siblings, 0 replies; 83+ messages in thread
From: Darrick J. Wong @ 2023-10-17  0:51 UTC (permalink / raw)
  To: Omar Sandoval; +Cc: Christoph Hellwig, linux-xfs

On Mon, Oct 16, 2023 at 10:19:47AM -0700, Omar Sandoval wrote:
> On Thu, Oct 12, 2023 at 11:19:08AM -0700, Darrick J. Wong wrote:
> > On Thu, Oct 12, 2023 at 07:25:11AM +0200, Christoph Hellwig wrote:
> > > On Wed, Oct 11, 2023 at 11:06:14AM -0700, Darrick J. Wong wrote:
> > > > From: Darrick J. Wong <djwong@kernel.org>
> > > > 
> > > > Avoid the costs of integer division (32-bit and 64-bit) if the realtime
> > > > extent size is a power of two.
> > > 
> > > Looks good:
> > > 
> > > Reviewed-by: Christoph Hellwig <hch@lst.de>
> > > 
> > > Do you have any data on how common non-power of two rtext sizes are?
> > > Might it be worth to add unlikely annotations?
> > 
> > I don't really know about the historical uses.  There might be old
> > filesystems out there with a non-power-of-2 raid stripe size that are
> > set up for full stripe allocations for speed.
> > 
> > We (oracle) are interested in using rt for PMD allocations on pmem/cxl
> > devices and atomic writes on scsi/nvme devices.  Both of those cases
> > will only ever use powers of 2.
> > 
> > I'll add some if-test annotations and we'll see if anyone notices. ;)
> > 
> > --D
> 
> We are using 1044KB realtime extents (blocksize = 4096, rextsize = 261)
> for our blob storage system. It's a goofy number, but IIRC it was chosen
> because their most common blob sizes were single-digit multiples of a
> megabyte, and they wanted a large-ish (~1MB) realtime extent size to
> reduce external fragmentation, but they also wanted to store a bit of
> extra metadata without requiring an extra realtime extent and blowing up
> internal fragmentation.

LOL, and here I thought I was only pushing weird sizes like 28k to drive
willy crazy. ;)  I wrapped some of the if tests in likely(); they can
get ripped back out.

--D

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

* Re: [PATCHSET RFC v1.0 0/7] xfs: clean up realtime type usage
  2023-10-17  0:48         ` Darrick J. Wong
@ 2023-10-17  4:05           ` Christoph Hellwig
  0 siblings, 0 replies; 83+ messages in thread
From: Christoph Hellwig @ 2023-10-17  4:05 UTC (permalink / raw)
  To: Darrick J. Wong; +Cc: Christoph Hellwig, linux-xfs, osandov

On Mon, Oct 16, 2023 at 05:48:31PM -0700, Darrick J. Wong wrote:
> We can do it crappily in C with __bitwise and letting the static checker
> bots go wild.  Some day when someone rewrites the entire codebase in
> Rust (HA!) then we'll be able to do:
> 
> struct xfs_fsblock_t(u64);
> struct xfs_agblock_t(u32);
> 
> and (to the extent that I understand Rust) the Rust compiler will
> complain about stuffing xfs_agblock_t into an xfs_fsblock_t without a
> proper conversion.

You can do the struct in C already.  Linux actually does it for PTE
types optionally.  It's just a real pain in the butt if your regularly
do arithmetics on it, which we do for the various block/size/offset
types.

> 
> --D
---end quoted text---

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

end of thread, other threads:[~2023-10-17  4:20 UTC | newest]

Thread overview: 83+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-10-11 17:57 [PATCHBOMB RFC]: xfs: realtime units cleanups Darrick J. Wong
2023-10-11 18:01 ` [PATCHSET RFC v1.0 0/3] xfs: minor bugfixes for rt stuff Darrick J. Wong
2023-10-11 18:02   ` [PATCH 1/3] xfs: bump max fsgeom struct version Darrick J. Wong
2023-10-12  4:51     ` Christoph Hellwig
2023-10-12 17:34       ` Darrick J. Wong
2023-10-11 18:02   ` [PATCH 2/3] xfs: prevent rt growfs when quota is enabled Darrick J. Wong
2023-10-12  4:51     ` Christoph Hellwig
2023-10-11 18:02   ` [PATCH 3/3] xfs: rt stubs should return negative errnos when rt disabled Darrick J. Wong
2023-10-12  4:52     ` Christoph Hellwig
2023-10-11 18:01 ` [PATCHSET RFC v1.0 0/7] xfs: clean up realtime type usage Darrick J. Wong
2023-10-11 18:02   ` [PATCH 1/7] xfs: make sure maxlen is still congruent with prod when rounding down Darrick J. Wong
2023-10-12  4:59     ` Christoph Hellwig
2023-10-12 17:31       ` Darrick J. Wong
2023-10-13  4:22         ` Christoph Hellwig
2023-10-11 18:03   ` [PATCH 2/7] xfs: move the xfs_rtbitmap.c declarations to xfs_rtbitmap.h Darrick J. Wong
2023-10-12  6:33     ` Christoph Hellwig
2023-10-11 18:03   ` [PATCH 3/7] xfs: convert xfs_extlen_t to xfs_rtxlen_t in the rt allocator Darrick J. Wong
2023-10-12  5:00     ` Christoph Hellwig
2023-10-11 18:03   ` [PATCH 4/7] xfs: convert rt bitmap/summary block numbers to xfs_fileoff_t Darrick J. Wong
2023-10-12  5:01     ` Christoph Hellwig
2023-10-11 18:03   ` [PATCH 5/7] xfs: convert rt bitmap extent lengths to xfs_rtbxlen_t Darrick J. Wong
2023-10-12  5:01     ` Christoph Hellwig
2023-10-11 18:04   ` [PATCH 6/7] xfs: rename xfs_verify_rtext to xfs_verify_rtbext Darrick J. Wong
2023-10-12  5:02     ` Christoph Hellwig
2023-10-11 18:04   ` [PATCH 7/7] xfs: convert rt extent numbers to xfs_rtxnum_t Darrick J. Wong
2023-10-12  5:03     ` Christoph Hellwig
2023-10-12  5:05   ` [PATCHSET RFC v1.0 0/7] xfs: clean up realtime type usage Christoph Hellwig
2023-10-12 22:30     ` Darrick J. Wong
2023-10-13  4:24       ` Christoph Hellwig
2023-10-17  0:48         ` Darrick J. Wong
2023-10-17  4:05           ` Christoph Hellwig
2023-10-11 18:01 ` [PATCHSET RFC v1.0 0/7] xfs: refactor rt extent unit conversions Darrick J. Wong
2023-10-11 18:04   ` [PATCH 1/7] xfs: create a helper to convert rtextents to rtblocks Darrick J. Wong
2023-10-12  5:10     ` Christoph Hellwig
2023-10-11 18:04   ` [PATCH 2/7] xfs: create a helper to compute leftovers of realtime extents Darrick J. Wong
2023-10-12  5:11     ` Christoph Hellwig
2023-10-12 17:40       ` Darrick J. Wong
2023-10-11 18:05   ` [PATCH 3/7] " Darrick J. Wong
2023-10-12  6:34     ` Christoph Hellwig
2023-10-11 18:05   ` [PATCH 4/7] xfs: create helpers to convert rt block numbers to rt extent numbers Darrick J. Wong
2023-10-12  5:17     ` Christoph Hellwig
2023-10-12 17:58       ` Darrick J. Wong
2023-10-13  4:25         ` Christoph Hellwig
2023-10-11 18:05   ` [PATCH 5/7] xfs: convert do_div calls to xfs_rtb_to_rtx helper calls Darrick J. Wong
2023-10-12  5:22     ` Christoph Hellwig
2023-10-12 18:10       ` Darrick J. Wong
2023-10-11 18:05   ` [PATCH 6/7] xfs: create rt extent rounding helpers for realtime extent blocks Darrick J. Wong
2023-10-12  5:22     ` Christoph Hellwig
2023-10-11 18:06   ` [PATCH 7/7] xfs: use shifting and masking when converting rt extents, if possible Darrick J. Wong
2023-10-12  5:25     ` Christoph Hellwig
2023-10-12 18:19       ` Darrick J. Wong
2023-10-16 17:19         ` Omar Sandoval
2023-10-17  0:51           ` Darrick J. Wong
2023-10-11 18:01 ` [PATCHSET RFC v1.0 0/8] xfs: refactor rtbitmap/summary macros Darrick J. Wong
2023-10-11 18:06   ` [PATCH 1/8] xfs: convert the rtbitmap block and bit macros to static inline functions Darrick J. Wong
2023-10-12  6:34     ` Christoph Hellwig
2023-10-11 18:06   ` [PATCH 2/8] xfs: remove XFS_BLOCKWSIZE and XFS_BLOCKWMASK macros Darrick J. Wong
2023-10-12  5:33     ` Christoph Hellwig
2023-10-12 18:20       ` Darrick J. Wong
2023-10-13  5:53         ` Christoph Hellwig
2023-10-17  0:49           ` Darrick J. Wong
2023-10-11 18:07   ` [PATCH 3/8] xfs: convert open-coded xfs_rtword_t pointer accesses to helper Darrick J. Wong
2023-10-12  5:39     ` Christoph Hellwig
2023-10-12 18:26       ` Darrick J. Wong
2023-10-11 18:07   ` [PATCH 4/8] xfs: convert rt summary macros to helpers Darrick J. Wong
2023-10-12  5:41     ` Christoph Hellwig
2023-10-11 18:07   ` [PATCH 5/8] xfs: create helpers for rtbitmap block/wordcount computations Darrick J. Wong
2023-10-12  5:44     ` Christoph Hellwig
2023-10-12 21:55       ` Darrick J. Wong
2023-10-13  4:26         ` Christoph Hellwig
2023-10-11 18:07   ` [PATCH 6/8] xfs: use accessor functions for bitmap words Darrick J. Wong
2023-10-12  6:19     ` Christoph Hellwig
2023-10-12 22:11       ` Darrick J. Wong
2023-10-13  4:28         ` Christoph Hellwig
2023-10-13 16:58           ` Darrick J. Wong
2023-10-11 18:08   ` [PATCH 7/8] xfs: create helpers for rtsummary block/wordcount computations Darrick J. Wong
2023-10-12  6:25     ` Christoph Hellwig
2023-10-12 22:18       ` Darrick J. Wong
2023-10-13  4:29         ` Christoph Hellwig
2023-10-13 17:11           ` Darrick J. Wong
2023-10-11 18:08   ` [PATCH 8/8] xfs: use accessor functions for summary info words Darrick J. Wong
2023-10-12  6:26     ` Christoph Hellwig
2023-10-12 22:21       ` 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.