]> git.ipfire.org Git - thirdparty/xfsprogs-dev.git/commitdiff
xfs_db: enable rtconvert to handle segmented rtblocks
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 we've turned xfs_rtblock_t into a segmented address and
xfs_rtxnum_t into a per-rtgroup address, port the rtconvert debugger
command to handle the unit conversions correctly.  Also add an example
of the bitmap/summary-related conversion commands to the manpage.

Signed-off-by: "Darrick J. Wong" <djwong@kernel.org>
Reviewed-by: Christoph Hellwig <hch@lst.de>
db/convert.c
man/man8/xfs_db.8

index 0c5c942150fe6fb9c5a8b701e774ca93d16b08d7..2cdde7d05ac397e5d8c9dcda4fd6fcebcc81827e 100644 (file)
         agino_to_bytes(XFS_INO_TO_AGINO(mp, (x))))
 #define        inoidx_to_bytes(x)      \
        ((uint64_t)(x) << mp->m_sb.sb_inodelog)
-#define rtblock_to_bytes(x)    \
-       ((uint64_t)(x) << mp->m_sb.sb_blocklog)
-#define rtx_to_rtblock(x)      \
-       ((uint64_t)(x) * mp->m_sb.sb_rextsize)
-#define rbmblock_to_bytes(x)   \
-       rtblock_to_bytes(rtx_to_rtblock(xfs_rbmblock_to_rtx(mp, (uint64_t)x)))
-#define rbmword_to_bytes(x)    \
-       rtblock_to_bytes(rtx_to_rtblock((uint64_t)(x) << XFS_NBWORDLOG))
+#define        rtblock_to_bytes(x)     \
+       (xfs_rtb_to_daddr(mp, (x)) << BBSHIFT)
+#define        rtx_to_bytes(x)         \
+       (((uint64_t)(x) * mp->m_sb.sb_rextsize) << mp->m_sb.sb_blocklog)
+#define        rbmblock_to_bytes(x)    \
+       rtx_to_bytes(xfs_rbmblock_to_rtx(mp, (x)))
+#define        rbmword_to_bytes(x)     \
+       rtx_to_bytes((uint64_t)(x) << XFS_NBWORDLOG)
 
 typedef enum {
        CT_NONE = -1,
@@ -316,7 +316,7 @@ bytevalue(ctype_t ctype, cval_t *val)
        case CT_RTBLOCK:
                return rtblock_to_bytes(val->rtblock);
        case CT_RTX:
-               return rtblock_to_bytes(rtx_to_rtblock(val->rtx));
+               return rtx_to_bytes(val->rtx);
        case CT_RBMBLOCK:
                return rbmblock_to_bytes(val->rbmblock);
        case CT_RBMWORD:
@@ -495,6 +495,32 @@ rt_daddr_to_rsuminfo(
        return xfs_rtsumoffs_to_infoword(mp, rsumoff);
 }
 
+/* Translate an rt device disk address to be in units of realtime extents. */
+static inline uint64_t
+rt_daddr_to_rtx(
+       struct xfs_mount        *mp,
+       xfs_daddr_t             daddr)
+{
+       return XFS_BB_TO_FSBT(mp, daddr) / mp->m_sb.sb_rextsize;
+}
+
+/*
+ * Compute the offset of an rt device disk address from the start of an
+ * rtgroup and return the result in units of realtime extents.
+ */
+static inline uint64_t
+rt_daddr_to_rtgrtx(
+       struct xfs_mount        *mp,
+       xfs_daddr_t             daddr)
+{
+       uint64_t                rtx = rt_daddr_to_rtx(mp, daddr);
+
+       if (xfs_has_rtgroups(mp))
+               return rtx % mp->m_sb.sb_rgextents;
+
+       return rtx;
+}
+
 static int
 rtconvert_f(int argc, char **argv)
 {
@@ -565,17 +591,15 @@ rtconvert_f(int argc, char **argv)
                v = xfs_daddr_to_rtb(mp, v >> BBSHIFT);
                break;
        case CT_RTX:
-               v = xfs_daddr_to_rtb(mp, v >> BBSHIFT) / mp->m_sb.sb_rextsize;
+               v = rt_daddr_to_rtx(mp, v >> BBSHIFT);
                break;
        case CT_RBMBLOCK:
                v = xfs_rtx_to_rbmblock(mp,
-                               xfs_rtb_to_rtx(mp,
-                                       xfs_daddr_to_rtb(mp, v >> BBSHIFT)));
+                               rt_daddr_to_rtgrtx(mp, v >> BBSHIFT));
                break;
        case CT_RBMWORD:
                v = xfs_rtx_to_rbmword(mp,
-                               xfs_rtb_to_rtx(mp,
-                                       xfs_daddr_to_rtb(mp, v >> BBSHIFT)));
+                               rt_daddr_to_rtgrtx(mp, v >> BBSHIFT));
                break;
        case CT_RSUMBLOCK:
                v = rt_daddr_to_rsumblock(mp, v);
index 2325ef169ddc1baf67fdc80a32d647738cb7918e..38916036d76c03642bdd11d41833385765dbb166 100644 (file)
@@ -1239,10 +1239,23 @@ log2(extent length) must be specified as the last type/number pair before the
 conversion type, and the type must be
 .BR rsumlog .
 
-To compute the rt bitmap block from summary file location, the type/number pairs
-must be specified exactly in the order
+For example, these commands tell us where to look in the rt summary file for
+the number of free rtextents of length 2^21 starting in rt bitmap block 30:
+
+.B rtconvert rbmblock 30 rsumlog 21 rsumblock
+
+.B rtconvert rbmblock 30 rsumlog 21 rsuminfo
+
+To compute the rt bitmap block from summary file location, the type/number
+pairs must be specified exactly in the order
 .BR rsumlog ", " rsuminfo ", " rsumblock .
 
+For example, this command tells us which block in the rt bitmap file is
+summarized by info word 809 in rt summary block 10 assuming that the
+maximum free extent length is 2^21 rtextents:
+
+.B rtconvert rsumlog 21 rsuminfo 809 rsumblock 10 rbmblock
+
 .TP
 .BI "sb [" agno ]
 Set current address to SB header in allocation group