[PATCH 41/50] xfs_io: display rt group in verbose bmap output

Darrick J. Wong
2024-12-07T00:15:39Z

From: Darrick J. Wong <djwong@kernel.org>

Display the rt group number in the bmap -v output, just like we do for
regular data files.

Signed-off-by: "Darrick J. Wong" <djwong@kernel.org>
---
io/bmap.c | 27 ++++++++++++++++++---------
libfrog/fsgeom.h | 12 ++++++++++++
2 files changed, 30 insertions(+), 9 deletions(-)

diff --git a/io/bmap.c b/io/bmap.c
index 6182e1c591da18..b2f6b490528513 100644
--- a/io/bmap.c
+++ b/io/bmap.c
@@ -257,16 +257,18 @@ bmap_f(
#define FLG_BSW 0000010 /* Not on begin of stripe width */
#define FLG_ESW 0000001 /* Not on end of stripe width */
int agno;
- off_t agoff, bbperag;
+ off_t agoff, bbperag;
int foff_w, boff_w, aoff_w, tot_w, agno_w;
char rbuf[32], bbuf[32], abuf[32];
int sunit, swidth;

foff_w = boff_w = aoff_w = MINRANGE_WIDTH;
tot_w = MINTOT_WIDTH;
- if (is_rt)
- sunit = swidth = bbperag = 0;
- else {
+ if (is_rt) {
+ bbperag = bytes_per_rtgroup(&fsgeo) / BBSIZE;
+ sunit = 0;
+ swidth = 0;
+ } else {
bbperag = (off_t)fsgeo.agblocks *
(off_t)fsgeo.blocksize / BBSIZE;
sunit = (fsgeo.sunit * fsgeo.blocksize) / BBSIZE;
@@ -295,7 +297,7 @@ bmap_f(
(long long)(map[i + 1].bmv_block +
map[i + 1].bmv_length - 1LL));
boff_w = max(boff_w, strlen(bbuf));
- if (!is_rt) {
+ if (bbperag > 0) {
agno = map[i + 1].bmv_block / bbperag;
agoff = map[i + 1].bmv_block -
(agno * bbperag);
@@ -312,13 +314,20 @@ bmap_f(
numlen(map[i+1].bmv_length, 10));
}
}
- agno_w = is_rt ? 0 : max(MINAG_WIDTH, numlen(fsgeo.agcount, 10));
+ if (is_rt) {
+ if (fsgeo.rgcount > 0)
+ agno_w = max(MINAG_WIDTH, numlen(fsgeo.rgcount, 10));
+ else
+ agno_w = 0;
+ } else {
+ agno_w = max(MINAG_WIDTH, numlen(fsgeo.agcount, 10));
+ }
printf("%4s: %-*s %-*s %*s %-*s %*s%s\n",
_("EXT"),
foff_w, _("FILE-OFFSET"),
boff_w, is_rt ? _("RT-BLOCK-RANGE") : _("BLOCK-RANGE"),
- agno_w, is_rt ? "" : _("AG"),
- aoff_w, is_rt ? "" : _("AG-OFFSET"),
+ agno_w, is_rt ? (fsgeo.rgcount ? _("RG") : "") : _("AG"),
+ aoff_w, is_rt ? (fsgeo.rgcount ? _("RG-OFFSET") : "") : _("AG-OFFSET"),
tot_w, _("TOTAL"),
flg ? _(" FLAGS") : "");
for (i = 0; i < egcnt; i++) {
@@ -377,7 +386,7 @@ bmap_f(
map[i + 1].bmv_length - 1LL));
printf("%4d: %-*s %-*s", i, foff_w, rbuf,
boff_w, bbuf);
- if (!is_rt) {
+ if (bbperag > 0) {
agno = map[i + 1].bmv_block / bbperag;
agoff = map[i + 1].bmv_block -
(agno * bbperag);
diff --git a/libfrog/fsgeom.h b/libfrog/fsgeom.h
index c571ddbcfb9b70..b851b9bbf36a58 100644
--- a/libfrog/fsgeom.h
+++ b/libfrog/fsgeom.h
@@ -205,4 +205,16 @@ cvt_b_to_agbno(
return cvt_daddr_to_agbno(xfd, cvt_btobbt(byteno));
}

+/* Return the number of bytes in an rtgroup. */
+static inline uint64_t
+bytes_per_rtgroup(
+ const struct xfs_fsop_geom *fsgeo)
+{
+ if (!fsgeo->rgcount)
+ return 0;
+
+ return (uint64_t)fsgeo->rgextents * fsgeo->rtextsize *
+ fsgeo->blocksize;
+}
+
#endif /* __LIBFROG_FSGEOM_H__ */