diff mbox series

[4/9] xfs_db: report the device associated with each io cursor

Message ID 170069443096.1865809.13119575401747000666.stgit@frogsfrogsfrogs (mailing list archive)
State Superseded
Headers show
Series xfsprogs: minor fixes for 6.6 | expand

Commit Message

Darrick J. Wong Nov. 22, 2023, 11:07 p.m. UTC
From: Darrick J. Wong <djwong@kernel.org>

When db is reporting on an io cursor, have it print out the device
that the cursor is pointing to.

Signed-off-by: Darrick J. Wong <djwong@kernel.org>
---
 db/block.c |   14 +++++++++++++-
 db/io.c    |   35 ++++++++++++++++++++++++++++++++---
 db/io.h    |    3 +++
 3 files changed, 48 insertions(+), 4 deletions(-)

Comments

Christoph Hellwig Nov. 23, 2023, 6:41 a.m. UTC | #1
On Wed, Nov 22, 2023 at 03:07:10PM -0800, Darrick J. Wong wrote:
> From: Darrick J. Wong <djwong@kernel.org>
> 
> When db is reporting on an io cursor, have it print out the device
> that the cursor is pointing to.

This looks very useful.  But I wonder if it risks breaking a lot
of scripts?
Darrick J. Wong Nov. 27, 2023, 6:24 p.m. UTC | #2
On Wed, Nov 22, 2023 at 10:41:09PM -0800, Christoph Hellwig wrote:
> On Wed, Nov 22, 2023 at 03:07:10PM -0800, Darrick J. Wong wrote:
> > From: Darrick J. Wong <djwong@kernel.org>
> > 
> > When db is reporting on an io cursor, have it print out the device
> > that the cursor is pointing to.
> 
> This looks very useful.  But I wonder if it risks breaking a lot
> of scripts?

<shrug> There's nothing in fstests that depends on the output of the
'stack' command, and debian code search didn't come up with any hits.

--D

> 
>
Christoph Hellwig Nov. 28, 2023, 5:37 a.m. UTC | #3
On Mon, Nov 27, 2023 at 10:24:14AM -0800, Darrick J. Wong wrote:
> On Wed, Nov 22, 2023 at 10:41:09PM -0800, Christoph Hellwig wrote:
> > On Wed, Nov 22, 2023 at 03:07:10PM -0800, Darrick J. Wong wrote:
> > > From: Darrick J. Wong <djwong@kernel.org>
> > > 
> > > When db is reporting on an io cursor, have it print out the device
> > > that the cursor is pointing to.
> > 
> > This looks very useful.  But I wonder if it risks breaking a lot
> > of scripts?
> 
> <shrug> There's nothing in fstests that depends on the output of the
> 'stack' command, and debian code search didn't come up with any hits.

I guess that's about as good as it gets..
diff mbox series

Patch

diff --git a/db/block.c b/db/block.c
index 788337d3709..d730c779671 100644
--- a/db/block.c
+++ b/db/block.c
@@ -126,7 +126,15 @@  daddr_f(
 	char		*p;
 
 	if (argc == 1) {
-		dbprintf(_("current daddr is %lld\n"), iocur_top->off >> BBSHIFT);
+		xfs_daddr_t	daddr = iocur_top->off >> BBSHIFT;
+
+		if (iocur_is_ddev(iocur_top))
+			dbprintf(_("datadev daddr is %lld\n"), daddr);
+		else if (iocur_is_extlogdev(iocur_top))
+			dbprintf(_("logdev daddr is %lld\n"), daddr);
+		else
+			dbprintf(_("current daddr is %lld\n"), daddr);
+
 		return 0;
 	}
 	d = (int64_t)strtoull(argv[1], &p, 0);
@@ -220,6 +228,10 @@  fsblock_f(
 	char		*p;
 
 	if (argc == 1) {
+		if (!iocur_is_ddev(iocur_top)) {
+			dbprintf(_("cursor does not point to data device\n"));
+			return 0;
+		}
 		dbprintf(_("current fsblock is %lld\n"),
 			XFS_DADDR_TO_FSB(mp, iocur_top->off >> BBSHIFT));
 		return 0;
diff --git a/db/io.c b/db/io.c
index 5ccfe3b536a..590dd1f82f7 100644
--- a/db/io.c
+++ b/db/io.c
@@ -137,18 +137,47 @@  pop_help(void)
 		));
 }
 
+bool
+iocur_is_ddev(const struct iocur *ioc)
+{
+	if (!ioc->bp)
+		return false;
+
+	return ioc->bp->b_target == ioc->bp->b_mount->m_ddev_targp;
+}
+
+bool
+iocur_is_extlogdev(const struct iocur *ioc)
+{
+	struct xfs_buf	*bp = ioc->bp;
+
+	if (!bp)
+		return false;
+	if (bp->b_mount->m_logdev_targp == bp->b_mount->m_ddev_targp)
+		return false;
+
+	return bp->b_target == bp->b_mount->m_logdev_targp;
+}
+
 void
 print_iocur(
 	char	*tag,
 	iocur_t	*ioc)
 {
+	const char	*block_unit = "fsbno?";
 	int	i;
 
+	if (iocur_is_ddev(ioc))
+		block_unit = "fsbno";
+	else if (iocur_is_extlogdev(ioc))
+		block_unit = "logbno";
+
 	dbprintf("%s\n", tag);
 	dbprintf(_("\tbyte offset %lld, length %d\n"), ioc->off, ioc->len);
-	dbprintf(_("\tbuffer block %lld (fsbno %lld), %d bb%s\n"), ioc->bb,
-		(xfs_fsblock_t)XFS_DADDR_TO_FSB(mp, ioc->bb), ioc->blen,
-		ioc->blen == 1 ? "" : "s");
+	dbprintf(_("\tbuffer block %lld (%s %lld), %d bb%s\n"), ioc->bb,
+			block_unit,
+			(xfs_fsblock_t)XFS_DADDR_TO_FSB(mp, ioc->bb),
+			ioc->blen, ioc->blen == 1 ? "" : "s");
 	if (ioc->bbmap) {
 		dbprintf(_("\tblock map"));
 		for (i = 0; i < ioc->bbmap->nmaps; i++)
diff --git a/db/io.h b/db/io.h
index bd86c31f67e..f48b67b47a2 100644
--- a/db/io.h
+++ b/db/io.h
@@ -56,6 +56,9 @@  extern void	set_iocur_type(const struct typ *type);
 extern void	xfs_dummy_verify(struct xfs_buf *bp);
 extern void	xfs_verify_recalc_crc(struct xfs_buf *bp);
 
+bool iocur_is_ddev(const struct iocur *ioc);
+bool iocur_is_extlogdev(const struct iocur *ioc);
+
 /*
  * returns -1 for unchecked, 0 for bad and 1 for good
  */