diff mbox series

[35/50] xfs_db: report rt group and block number in the bmap command

Message ID 173352752480.126362.14408954135415554700.stgit@frogsfrogsfrogs (mailing list archive)
State Not Applicable, archived
Headers show
Series [01/50] libxfs: remove XFS_ILOCK_RT* | expand

Commit Message

Darrick J. Wong Dec. 7, 2024, 12:14 a.m. UTC
From: Darrick J. Wong <djwong@kernel.org>

The bmap command does not report startblocks for realtime files
correctly.  If rtgroups are enabled, we need to use the appropriate
functions to crack the startblock into rtgroup and block numbers; if
not, then we need to report a linear address and not try to report a
group number.

Fix both of these issues.

Signed-off-by: "Darrick J. Wong" <djwong@kernel.org>
---
 db/bmap.c |   56 +++++++++++++++++++++++++++++++++++++++++++++++++-------
 1 file changed, 49 insertions(+), 7 deletions(-)

Comments

Christoph Hellwig Dec. 10, 2024, 5:49 a.m. UTC | #1
On Fri, Dec 06, 2024 at 04:14:05PM -0800, Darrick J. Wong wrote:
> +static void
> +print_group_bmbt(
> +	bool			isrt,
> +	int			whichfork,
> +	const struct bmap_ext	*be)
> +{
> +	unsigned int		gno;
> +	unsigned long long	gbno;
> +
> +	if (whichfork == XFS_DATA_FORK && isrt) {
> +		gno = xfs_rtb_to_rgno(mp, be->startblock);
> +		gbno = xfs_rtb_to_rgbno(mp, be->startblock);
> +	} else {
> +		gno = XFS_FSB_TO_AGNO(mp, be->startblock);
> +		gbno = XFS_FSB_TO_AGBNO(mp, be->startblock);

Maybe use xfs_fsb_to_gno and xfs_fsb_to_gbno here?

Otherwise looks good:

Reviewed-by: Christoph Hellwig <hch@lst.de>
Darrick J. Wong Dec. 11, 2024, 9:48 p.m. UTC | #2
On Mon, Dec 09, 2024 at 09:49:27PM -0800, Christoph Hellwig wrote:
> On Fri, Dec 06, 2024 at 04:14:05PM -0800, Darrick J. Wong wrote:
> > +static void
> > +print_group_bmbt(
> > +	bool			isrt,
> > +	int			whichfork,
> > +	const struct bmap_ext	*be)
> > +{
> > +	unsigned int		gno;
> > +	unsigned long long	gbno;
> > +
> > +	if (whichfork == XFS_DATA_FORK && isrt) {
> > +		gno = xfs_rtb_to_rgno(mp, be->startblock);
> > +		gbno = xfs_rtb_to_rgbno(mp, be->startblock);
> > +	} else {
> > +		gno = XFS_FSB_TO_AGNO(mp, be->startblock);
> > +		gbno = XFS_FSB_TO_AGBNO(mp, be->startblock);
> 
> Maybe use xfs_fsb_to_gno and xfs_fsb_to_gbno here?

Will do.

> Otherwise looks good:
> 
> Reviewed-by: Christoph Hellwig <hch@lst.de>

Thanks!

--D
diff mbox series

Patch

diff --git a/db/bmap.c b/db/bmap.c
index 7915772aaee4e0..d63aa9ef9c015b 100644
--- a/db/bmap.c
+++ b/db/bmap.c
@@ -119,6 +119,41 @@  bmap(
 	*nexp = n;
 }
 
+static void
+print_group_bmbt(
+	bool			isrt,
+	int			whichfork,
+	const struct bmap_ext	*be)
+{
+	unsigned int		gno;
+	unsigned long long	gbno;
+
+	if (whichfork == XFS_DATA_FORK && isrt) {
+		gno = xfs_rtb_to_rgno(mp, be->startblock);
+		gbno = xfs_rtb_to_rgbno(mp, be->startblock);
+	} else {
+		gno = XFS_FSB_TO_AGNO(mp, be->startblock);
+		gbno = XFS_FSB_TO_AGBNO(mp, be->startblock);
+	}
+
+	dbprintf(
+ _("%s offset %lld startblock %llu (%u/%llu) count %llu flag %u\n"),
+			whichfork == XFS_DATA_FORK ? _("data") : _("attr"),
+			be->startoff, be->startblock,
+			gno, gbno,
+			be->blockcount, be->flag);
+}
+
+static void
+print_linear_bmbt(
+	const struct bmap_ext	*be)
+{
+	dbprintf(_("%s offset %lld startblock %llu count %llu flag %u\n"),
+			_("data"),
+			be->startoff, be->startblock,
+			be->blockcount, be->flag);
+}
+
 static int
 bmap_f(
 	int			argc,
@@ -135,6 +170,7 @@  bmap_f(
 	xfs_extnum_t		nex;
 	char			*p;
 	int			whichfork;
+	bool			isrt;
 
 	if (iocur_top->ino == NULLFSINO) {
 		dbprintf(_("no current inode\n"));
@@ -154,6 +190,10 @@  bmap_f(
 			return 0;
 		}
 	}
+
+	dip = iocur_top->data;
+	isrt = (dip->di_flags & cpu_to_be16(XFS_DIFLAG_REALTIME));
+
 	if (afork + dfork == 0) {
 		push_cur();
 		set_cur_inode(iocur_top->ino);
@@ -198,13 +238,15 @@  bmap_f(
 			bmap(co, eo - co + 1, whichfork, &nex, &be);
 			if (nex == 0)
 				break;
-			dbprintf(_("%s offset %lld startblock %llu (%u/%u) count "
-				 "%llu flag %u\n"),
-				whichfork == XFS_DATA_FORK ? _("data") : _("attr"),
-				be.startoff, be.startblock,
-				XFS_FSB_TO_AGNO(mp, be.startblock),
-				XFS_FSB_TO_AGBNO(mp, be.startblock),
-				be.blockcount, be.flag);
+
+			if (whichfork == XFS_DATA_FORK && isrt) {
+				if (xfs_has_rtgroups(mp))
+					print_group_bmbt(isrt, whichfork, &be);
+				else
+					print_linear_bmbt(&be);
+			} else {
+				print_group_bmbt(isrt, whichfork, &be);
+			}
 			co = be.startoff + be.blockcount;
 		}
 		co = cosave;