diff mbox series

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

Message ID 173405123485.1181370.4679130203707005497.stgit@frogsfrogsfrogs (mailing list archive)
State New
Headers show
Series [01/37] xfs: add some rtgroup inode helpers | expand

Commit Message

Darrick J. Wong Dec. 13, 2024, 1:03 a.m. UTC
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(-)

Comments

Christoph Hellwig Dec. 13, 2024, 6:30 a.m. UTC | #1
On Thu, Dec 12, 2024 at 05:03:11PM -0800, Darrick J. Wong wrote:
> +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;
> +}

Having this as an inline helpers means not just the code, but also
the string array is duplicated in every caller.  While there are only
two with your entire series that's still a lіttle suboptimal.  Maybe
move it out of line to xfs_metafile.c?

And make the array file scope to be a little more readable.
Darrick J. Wong Dec. 17, 2024, 8:18 p.m. UTC | #2
On Thu, Dec 12, 2024 at 10:30:23PM -0800, Christoph Hellwig wrote:
> On Thu, Dec 12, 2024 at 05:03:11PM -0800, Darrick J. Wong wrote:
> > +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;
> > +}
> 
> Having this as an inline helpers means not just the code, but also
> the string array is duplicated in every caller.  While there are only
> two with your entire series that's still a lіttle suboptimal.  Maybe
> move it out of line to xfs_metafile.c?
> 
> And make the array file scope to be a little more readable.

Done.

--D
diff mbox series

Patch

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));
 }
 
 /*