]> git.ipfire.org Git - thirdparty/xfsprogs-dev.git/commitdiff
xfs_db: enable the rtblock and rtextent commands for segmented rt block numbers
authorDarrick J. Wong <djwong@kernel.org>
Thu, 21 Nov 2024 00:24:36 +0000 (16:24 -0800)
committerDarrick J. Wong <djwong@kernel.org>
Tue, 24 Dec 2024 02:01:33 +0000 (18:01 -0800)
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>
Reviewed-by: Christoph Hellwig <hch@lst.de>
db/block.c

index f197e10cd5a08d792047141eb2429f58efa72b53..00830a3d57e1df2863251248b74bff206de47fcd 100644 (file)
@@ -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;
 }