From: Darrick J. Wong Date: Thu, 21 Nov 2024 00:24:36 +0000 (-0800) Subject: xfs_db: enable the rtblock and rtextent commands for segmented rt block numbers X-Git-Tag: v6.13.0~56 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=cffeab56210546d11a9642f25f5dfca74b7cc4d9;p=thirdparty%2Fxfsprogs-dev.git xfs_db: enable the rtblock and rtextent commands for segmented rt block numbers 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" Reviewed-by: Christoph Hellwig --- diff --git a/db/block.c b/db/block.c index f197e10c..00830a3d 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; }