]> www.infradead.org Git - users/hch/xfsprogs.git/commitdiff
xfs_db: make the daddr command target the realtime device
authorDarrick J. Wong <djwong@kernel.org>
Tue, 15 Oct 2024 19:43:47 +0000 (12:43 -0700)
committerDarrick J. Wong <djwong@kernel.org>
Fri, 1 Nov 2024 20:44:42 +0000 (13:44 -0700)
Make it so that users can issue the command "daddr -r XXX" to select
disk block XXX on the realtime device.

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

index bd25cdbe193f4f1fd8211d56785612ea2ed4c773..6ad9f038c6da6713269db6af091a71521e6fe382 100644 (file)
@@ -31,7 +31,7 @@ static const cmdinfo_t        ablock_cmd =
        { "ablock", NULL, ablock_f, 1, 1, 1, N_("filoff"),
          N_("set address to file offset (attr fork)"), ablock_help };
 static const cmdinfo_t daddr_cmd =
-       { "daddr", NULL, daddr_f, 0, 1, 1, N_("[d]"),
+       { "daddr", NULL, daddr_f, 0, -1, 1, N_("[d]"),
          N_("set address to daddr value"), daddr_help };
 static const cmdinfo_t dblock_cmd =
        { "dblock", NULL, dblock_f, 1, 1, 1, N_("filoff"),
@@ -117,16 +117,36 @@ daddr_help(void)
 ));
 }
 
+enum daddr_target {
+       DT_DATA,
+       DT_RT,
+};
+
 static int
 daddr_f(
        int             argc,
        char            **argv)
 {
+       xfs_rfsblock_t  max_daddrs = mp->m_sb.sb_dblocks;
        int64_t         d;
        char            *p;
        int             bb_count = BTOBB(mp->m_sb.sb_sectsize);
+       int             c;
+       enum daddr_target tgt = DT_DATA;
 
-       if (argc == 1) {
+       while ((c = getopt(argc, argv, "r")) != -1) {
+               switch (c) {
+               case 'r':
+                       tgt = DT_RT;
+                       max_daddrs = mp->m_sb.sb_rblocks;
+                       break;
+               default:
+                       daddr_help();
+                       return 0;
+               }
+       }
+
+       if (optind == argc) {
                xfs_daddr_t     daddr = iocur_top->off >> BBSHIFT;
 
                if (iocur_is_ddev(iocur_top))
@@ -140,14 +160,27 @@ daddr_f(
 
                return 0;
        }
-       d = (int64_t)strtoull(argv[1], &p, 0);
+
+       if (optind != argc - 1) {
+               daddr_help();
+               return 0;
+       }
+
+       d = (int64_t)strtoull(argv[optind], &p, 0);
        if (*p != '\0' ||
-           d >= mp->m_sb.sb_dblocks << (mp->m_sb.sb_blocklog - BBSHIFT)) {
+           d >= max_daddrs << (mp->m_sb.sb_blocklog - BBSHIFT)) {
                dbprintf(_("bad daddr %s\n"), argv[1]);
                return 0;
        }
        ASSERT(typtab[TYP_DATA].typnm == TYP_DATA);
-       set_cur(&typtab[TYP_DATA], d, bb_count, DB_RING_ADD, NULL);
+       switch (tgt) {
+       case DT_DATA:
+               set_cur(&typtab[TYP_DATA], d, bb_count, DB_RING_ADD, NULL);
+               break;
+       case DT_RT:
+               set_rt_cur(&typtab[TYP_DATA], d, bb_count, DB_RING_ADD, NULL);
+               break;
+       }
        return 0;
 }
 
index 5faf8dbb1d679fb47ccc9a7655c2c0225c73d102..f50ac949be018947d37c1cf6bfde7f7a3056794b 100644 (file)
@@ -671,7 +671,7 @@ Recalculate the current structure's correct CRC value, and write it to disk.
 Validate and display the current value and state of the structure's CRC.
 .RE
 .TP
-.BI "daddr [" d ]
+.BI "daddr [" -r "] [" d ]
 Set current address to the daddr (512 byte block) given by
 .IR d .
 If no value for
@@ -680,6 +680,10 @@ is given, the current address is printed, expressed as a daddr.
 The type is set to
 .B data
 (uninterpreted).
+
+If an address and the
+.B \-r
+option are specified, the current address is set to the realtime device.
 .TP
 .BI dblock " filoff"
 Set current address to the offset