Linux XFS filesystem development
 help / color / mirror / Atom feed
From: Christoph Hellwig <hch@lst.de>
To: Andrey Albershteyn <aalbersh@kernel.org>
Cc: linux-xfs@vger.kernel.org
Subject: [PATCH 2/2] xfs_io: use the XFS_ERRTAG macro to generate injection targets
Date: Mon, 15 Sep 2025 06:33:17 -0700	[thread overview]
Message-ID: <20250915133336.161352-3-hch@lst.de> (raw)
In-Reply-To: <20250915133336.161352-1-hch@lst.de>

Use the new magic macro table provided by libxfs to autogenerate
the list of valid error injection targets.

Signed-off-by: Christoph Hellwig <hch@lst.de>
---
 io/inject.c | 108 +++++++++++++++++-----------------------------------
 1 file changed, 35 insertions(+), 73 deletions(-)

diff --git a/io/inject.c b/io/inject.c
index 7b9a76406cc5..99186c081230 100644
--- a/io/inject.c
+++ b/io/inject.c
@@ -12,89 +12,49 @@
 
 static cmdinfo_t inject_cmd;
 
+#define ARRAY_SIZE(x)		(sizeof(x) / sizeof((x)[0]))
+#define __stringify_1(x...)	#x
+#define __stringify(x...)	__stringify_1(x)
+
+#define XFS_ERRTAG(_tag, _name, _default) \
+        [XFS_ERRTAG_##_tag]	=  __stringify(_name),
+#include "xfs_errortag.h"
+static const char *tag_names[] = { XFS_ERRTAGS };
+#undef XFS_ERRTAG
+
+/* Search for a name */
 static int
-error_tag(char *name)
+error_tag(
+	char		*name)
 {
-	static struct {
-		int	tag;
-		char	*name;
-	} *e, eflags[] = {
-		{ XFS_ERRTAG_NOERROR,			"noerror" },
-		{ XFS_ERRTAG_IFLUSH_1,			"iflush1" },
-		{ XFS_ERRTAG_IFLUSH_2,			"iflush2" },
-		{ XFS_ERRTAG_IFLUSH_3,			"iflush3" },
-		{ XFS_ERRTAG_IFLUSH_4,			"iflush4" },
-		{ XFS_ERRTAG_IFLUSH_5,			"iflush5" },
-		{ XFS_ERRTAG_IFLUSH_6,			"iflush6" },
-		{ XFS_ERRTAG_DA_READ_BUF,		"dareadbuf" },
-		{ XFS_ERRTAG_BTREE_CHECK_LBLOCK,	"btree_chk_lblk" },
-		{ XFS_ERRTAG_BTREE_CHECK_SBLOCK,	"btree_chk_sblk" },
-		{ XFS_ERRTAG_ALLOC_READ_AGF,		"readagf" },
-		{ XFS_ERRTAG_IALLOC_READ_AGI,		"readagi" },
-		{ XFS_ERRTAG_ITOBP_INOTOBP,		"itobp" },
-		{ XFS_ERRTAG_IUNLINK,			"iunlink" },
-		{ XFS_ERRTAG_IUNLINK_REMOVE,		"iunlinkrm" },
-		{ XFS_ERRTAG_DIR_INO_VALIDATE,		"dirinovalid" },
-		{ XFS_ERRTAG_BULKSTAT_READ_CHUNK,	"bulkstat" },
-		{ XFS_ERRTAG_IODONE_IOERR,		"logiodone" },
-		{ XFS_ERRTAG_STRATREAD_IOERR,		"stratread" },
-		{ XFS_ERRTAG_STRATCMPL_IOERR,		"stratcmpl" },
-		{ XFS_ERRTAG_DIOWRITE_IOERR,		"diowrite" },
-		{ XFS_ERRTAG_BMAPIFORMAT,		"bmapifmt" },
-		{ XFS_ERRTAG_FREE_EXTENT,		"free_extent" },
-		{ XFS_ERRTAG_RMAP_FINISH_ONE,		"rmap_finish_one" },
-		{ XFS_ERRTAG_REFCOUNT_CONTINUE_UPDATE,	"refcount_continue_update" },
-		{ XFS_ERRTAG_REFCOUNT_FINISH_ONE,	"refcount_finish_one" },
-		{ XFS_ERRTAG_BMAP_FINISH_ONE,		"bmap_finish_one" },
-		{ XFS_ERRTAG_AG_RESV_CRITICAL,		"ag_resv_critical" },
-		{ XFS_ERRTAG_DROP_WRITES,		"drop_writes" },
-		{ XFS_ERRTAG_LOG_BAD_CRC,		"log_bad_crc" },
-		{ XFS_ERRTAG_LOG_ITEM_PIN,		"log_item_pin" },
-		{ XFS_ERRTAG_BUF_LRU_REF,		"buf_lru_ref" },
-		{ XFS_ERRTAG_FORCE_SCRUB_REPAIR,	"force_repair" },
-		{ XFS_ERRTAG_FORCE_SUMMARY_RECALC,	"bad_summary" },
-		{ XFS_ERRTAG_IUNLINK_FALLBACK,		"iunlink_fallback" },
-		{ XFS_ERRTAG_BUF_IOERROR,		"buf_ioerror" },
-		{ XFS_ERRTAG_REDUCE_MAX_IEXTENTS,	"reduce_max_iextents" },
-		{ XFS_ERRTAG_BMAP_ALLOC_MINLEN_EXTENT,	"bmap_alloc_minlen_extent" },
-		{ XFS_ERRTAG_AG_RESV_FAIL,		"ag_resv_fail" },
-		{ XFS_ERRTAG_LARP,			"larp" },
-		{ XFS_ERRTAG_DA_LEAF_SPLIT,		"da_leaf_split" },
-		{ XFS_ERRTAG_ATTR_LEAF_TO_NODE,		"attr_leaf_to_node" },
-		{ XFS_ERRTAG_WB_DELAY_MS,		"wb_delay_ms" },
-		{ XFS_ERRTAG_WRITE_DELAY_MS,		"write_delay_ms" },
-		{ XFS_ERRTAG_EXCHMAPS_FINISH_ONE,	"exchmaps_finish_one" },
-		{ XFS_ERRTAG_METAFILE_RESV_CRITICAL,	"metafile_resv_crit" },
-		{ XFS_ERRTAG_MAX,			NULL }
-	};
-	int	count;
+	unsigned int	i;
 
-	/*
-	 * If this fails make sure every tag is defined in the array above,
-	 * see xfs_errortag_attrs in kernelspace.
-	 */
-	BUILD_BUG_ON(sizeof(eflags) != (XFS_ERRTAG_MAX + 1) * sizeof(*e));
+	for (i = 0; i < ARRAY_SIZE(tag_names); i++)
+		if (tag_names[i] && strcmp(name, tag_names[i]) == 0)
+			return i;
+	return -1;
+}
 
-	/* Search for a name */
-	if (name) {
-		for (e = eflags; e->name; e++)
-			if (strcmp(name, e->name) == 0)
-				return e->tag;
-		return -1;
-	}
+/* Dump all the names */
+static void
+list_tags(void)
+{
+	unsigned int	count = 0, i;
 
-	/* Dump all the names */
 	fputs("tags: [ ", stdout);
-	for (count = 0, e = eflags; e->name; e++, count++) {
-		if (count) {
+	for (i = 0; i < ARRAY_SIZE(tag_names); i++) {
+		if (count > 0) {
 			fputs(", ", stdout);
 			if (!(count % 5))
 				fputs("\n\t", stdout);
 		}
-		fputs(e->name, stdout);
+		if (tag_names[i]) {
+			fputs(tag_names[i], stdout);
+			count++;
+		}
+
 	}
 	fputs(" ]\n", stdout);
-	return 0;
 }
 
 static void
@@ -121,8 +81,10 @@ inject_f(
 	xfs_error_injection_t	error;
 	int			command = XFS_IOC_ERROR_INJECTION;
 
-	if (argc == 1)
-		return error_tag(NULL);
+	if (argc == 1) {
+		list_tags();
+		return 0;
+	}
 
 	while (--argc > 0) {
 		error.fd = file->fd;
-- 
2.47.2


  parent reply	other threads:[~2025-09-15 13:33 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-09-15 13:33 xfsprogs: cleanup error injection Christoph Hellwig
2025-09-15 13:33 ` [PATCH 1/2] xfs: centralize error tag definitions Christoph Hellwig
2025-09-15 13:33 ` Christoph Hellwig [this message]
2025-09-15 19:11   ` [PATCH 2/2] xfs_io: use the XFS_ERRTAG macro to generate injection targets Darrick J. Wong
2025-09-15 20:51     ` Christoph Hellwig

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20250915133336.161352-3-hch@lst.de \
    --to=hch@lst.de \
    --cc=aalbersh@kernel.org \
    --cc=linux-xfs@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox