Message ID | 173405123485.1181370.4679130203707005497.stgit@frogsfrogsfrogs (mailing list archive) |
---|---|
State | New |
Headers | show |
Series | [01/37] xfs: add some rtgroup inode helpers | expand |
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.
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 --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)); } /*