[PATCH 10/37] xfs: pretty print metadata file types in error messages

Darrick J. Wong
2024-12-13T01:03:12Z

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

Create a helper function to turn a metadata file type code into a
printable string, and use this to complain about lockdep problems with
rtgroup inodes. We'll use this more in the next patch.

Signed-off-by: "Darrick J. Wong" <djwong@kernel.org>
---
fs/xfs/libxfs/xfs_metafile.h | 17 +++++++++++++++++
fs/xfs/libxfs/xfs_rtgroup.c | 3 ++-
2 files changed, 19 insertions(+), 1 deletion(-)

diff --git a/fs/xfs/libxfs/xfs_metafile.h b/fs/xfs/libxfs/xfs_metafile.h
index 8d8f08a6071c23..9df8619d5fb1a9 100644
--- a/fs/xfs/libxfs/xfs_metafile.h
+++ b/fs/xfs/libxfs/xfs_metafile.h
@@ -6,6 +6,23 @@
#ifndef __XFS_METAFILE_H__
#define __XFS_METAFILE_H__

+static inline const char *
+xfs_metafile_type_str(enum xfs_metafile_type metatype)
+{
+ static const struct {
+ enum xfs_metafile_type mtype;
+ const char *name;
+ } strings[] = { XFS_METAFILE_TYPE_STR };
+ unsigned int i;
+
+ for (i = 0; i < ARRAY_SIZE(strings); i++) {
+ if (strings[i].mtype == metatype)
+ return strings[i].name;
+ }
+
+ return NULL;
+}
+
/* All metadata files must have these flags set. */
#define XFS_METAFILE_DIFLAGS (XFS_DIFLAG_IMMUTABLE | \
XFS_DIFLAG_SYNC | \
diff --git a/fs/xfs/libxfs/xfs_rtgroup.c b/fs/xfs/libxfs/xfs_rtgroup.c
index a79b734e70440d..9e5fdc0dc55cef 100644
--- a/fs/xfs/libxfs/xfs_rtgroup.c
+++ b/fs/xfs/libxfs/xfs_rtgroup.c
@@ -282,7 +282,8 @@ xfs_rtginode_ilock_print_fn(
const struct xfs_inode *ip =
container_of(m, struct xfs_inode, i_lock.dep_map);

- printk(KERN_CONT " rgno=%u", ip->i_projid);
+ printk(KERN_CONT " rgno=%u metatype=%s", ip->i_projid,
+ xfs_metafile_type_str(ip->i_metatype));
}

/*