[PATCH 25/50] xfs_db: fix the rtblock and rtextent commands for segmented rt block numbers

Darrick J. Wong
2024-12-07T00:11:27Z

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

Now that xfs_rtblock_t can be a segmented address, fix the validation in
rtblock_f to handle the inputs correctly; and fix rtextent_f to do all
of its conversions in linear address space.

Signed-off-by: "Darrick J. Wong" <djwong@kernel.org>
---
db/block.c | 34 +++++++++++++++++++++++++---------
1 file changed, 25 insertions(+), 9 deletions(-)

diff --git a/db/block.c b/db/block.c
index f197e10cd5a08d..00830a3d57e1df 100644
--- a/db/block.c
+++ b/db/block.c
@@ -367,10 +367,23 @@ rtblock_f(
dbprintf(_("bad rtblock %s\n"), argv[1]);
return 0;
}
- if (rtbno >= mp->m_sb.sb_rblocks) {
- dbprintf(_("bad rtblock %s\n"), argv[1]);
- return 0;
+
+ if (xfs_has_rtgroups(mp)) {
+ xfs_rgnumber_t rgno = xfs_rtb_to_rgno(mp, rtbno);
+ xfs_rgblock_t rgbno = xfs_rtb_to_rgbno(mp, rtbno);
+
+ if (rgno >= mp->m_sb.sb_rgcount ||
+ rgbno >= mp->m_sb.sb_rgextents * mp->m_sb.sb_rextsize) {
+ dbprintf(_("bad rtblock %s\n"), argv[1]);
+ return 0;
+ }
+ } else {
+ if (rtbno >= mp->m_sb.sb_rblocks) {
+ dbprintf(_("bad rtblock %s\n"), argv[1]);
+ return 0;
+ }
}
+
ASSERT(typtab[TYP_DATA].typnm == TYP_DATA);
set_rt_cur(&typtab[TYP_DATA], xfs_rtb_to_daddr(mp, rtbno), blkbb,
DB_RING_ADD, NULL);
@@ -392,14 +405,17 @@ rtextent_help(void)
/*
* Move the cursor to a specific location on the realtime block device given
* a linear address in units of realtime extents.
+ *
+ * NOTE: The user interface assumes a global RT extent number, while the
+ * in-kernel rtx is per-RTG now, thus the odd conversions here.
*/
static int
rtextent_f(
int argc,
char **argv)
{
- xfs_rtblock_t rtbno;
- xfs_rtxnum_t rtx;
+ uint64_t rfsbno;
+ uint64_t rtx;
char *p;

if (argc == 1) {
@@ -408,9 +424,9 @@ rtextent_f(
return 0;
}

- rtbno = xfs_daddr_to_rtb(mp, iocur_top->off >> BBSHIFT);
+ rfsbno = XFS_BB_TO_FSB(mp, iocur_top->off >> BBSHIFT);
dbprintf(_("current rtextent is %lld\n"),
- xfs_rtb_to_rtx(mp, rtbno));
+ xfs_blen_to_rtbxlen(mp, rfsbno));
return 0;
}
rtx = strtoull(argv[1], &p, 0);
@@ -423,9 +439,9 @@ rtextent_f(
return 0;
}

- rtbno = xfs_rtbxlen_to_blen(mp, rtx);
+ rfsbno = xfs_rtbxlen_to_blen(mp, rtx);
ASSERT(typtab[TYP_DATA].typnm == TYP_DATA);
- set_rt_cur(&typtab[TYP_DATA], xfs_rtb_to_daddr(mp, rtbno),
+ set_rt_cur(&typtab[TYP_DATA], XFS_FSB_TO_BB(mp, rfsbno),
mp->m_sb.sb_rextsize * blkbb, DB_RING_ADD, NULL);
return 0;
}