From: Christoph Hellwig <hch@lst.de>
To: Jens Axboe <axboe@kernel.dk>
Cc: Jonathan Corbet <corbet@lwn.net>,
Damien Le Moal <dlemoal@kernel.org>,
Hannes Reinecke <hare@suse.de>, Keith Busch <kbusch@kernel.org>,
linux-block@vger.kernel.org, linux-doc@vger.kernel.org,
Hannes Reinecke <hare@kernel.org>
Subject: [PATCH 2/4] block: add a "tag" for block status codes
Date: Mon, 8 Jun 2026 07:14:04 +0200 [thread overview]
Message-ID: <20260608051416.1205282-3-hch@lst.de> (raw)
In-Reply-To: <20260608051416.1205282-1-hch@lst.de>
The full name of the status codes is not good for user interfaces as it
can contain white spaces. Add the name of the status code without the
BLK_STS_ prefix as a tag so that it can be used for user interfaces.
Signed-off-by: Christoph Hellwig <hch@lst.de>
Reviewed-by: Keith Busch <kbusch@kernel.org>
Reviewed-by: Damien Le Moal <dlemoal@kernel.org>
Reviewed-by: Hannes Reinecke <hare@kernel.org>
---
block/blk-core.c | 28 ++++++++++++++++++++++++++++
block/blk.h | 2 ++
2 files changed, 30 insertions(+)
diff --git a/block/blk-core.c b/block/blk-core.c
index 1614323282f1..7aa9cd110bdd 100644
--- a/block/blk-core.c
+++ b/block/blk-core.c
@@ -135,10 +135,12 @@ EXPORT_SYMBOL_GPL(blk_op_str);
#define ENT(_tag, _errno, _desc) \
[BLK_STS_##_tag] = { \
.errno = _errno, \
+ .tag = __stringify(_tag), \
.name = _desc, \
}
static const struct {
int errno;
+ const char *tag;
const char *name;
} blk_errors[] = {
ENT(OK, 0, ""),
@@ -203,6 +205,32 @@ const char *blk_status_to_str(blk_status_t status)
return blk_errors[idx].name;
}
+const char *blk_status_to_tag(blk_status_t status)
+{
+ int idx = (__force int)status;
+
+ if (WARN_ON_ONCE(idx >= ARRAY_SIZE(blk_errors)))
+ return "<null>";
+ return blk_errors[idx].tag;
+}
+
+blk_status_t tag_to_blk_status(const char *tag)
+{
+ int i;
+
+ for (i = 0; i < ARRAY_SIZE(blk_errors); i++) {
+ if (blk_errors[i].tag &&
+ !strcmp(blk_errors[i].tag, tag))
+ return (__force blk_status_t)i;
+ }
+
+ /*
+ * Return BLK_STS_OK for mismatches as this function is intended to
+ * parse error status values.
+ */
+ return BLK_STS_OK;
+}
+
/**
* blk_sync_queue - cancel any pending callbacks on a queue
* @q: the queue
diff --git a/block/blk.h b/block/blk.h
index 1a2d9101bba0..0eb8e932ec66 100644
--- a/block/blk.h
+++ b/block/blk.h
@@ -50,6 +50,8 @@ struct blk_flush_queue *blk_alloc_flush_queue(int node, int cmd_size,
void blk_free_flush_queue(struct blk_flush_queue *q);
const char *blk_status_to_str(blk_status_t status);
+const char *blk_status_to_tag(blk_status_t status);
+blk_status_t tag_to_blk_status(const char *tag);
bool __blk_mq_unfreeze_queue(struct request_queue *q, bool force_atomic);
bool blk_queue_start_drain(struct request_queue *q);
--
2.53.0
next prev parent reply other threads:[~2026-06-08 5:14 UTC|newest]
Thread overview: 17+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-06-08 5:14 configurable block error injection v3 Christoph Hellwig
2026-06-08 5:14 ` [PATCH 1/4] block: add a macro to initialize the status table Christoph Hellwig
2026-06-08 21:51 ` Bart Van Assche
2026-06-08 5:14 ` Christoph Hellwig [this message]
2026-06-08 21:55 ` [PATCH 2/4] block: add a "tag" for block status codes Bart Van Assche
2026-06-09 7:43 ` Christoph Hellwig
2026-06-08 5:14 ` [PATCH 3/4] block: add a str_to_blk_op helper Christoph Hellwig
2026-06-08 21:57 ` Bart Van Assche
2026-06-09 7:45 ` Christoph Hellwig
2026-06-08 5:14 ` [PATCH 4/4] block: add configurable error injection Christoph Hellwig
2026-06-08 14:53 ` Jens Axboe
2026-06-09 7:41 ` Christoph Hellwig
2026-06-08 22:08 ` Bart Van Assche
2026-06-09 7:47 ` Christoph Hellwig
-- strict thread matches above, loose matches on Subject: below --
2026-06-05 18:44 configurable block error injection v2 Christoph Hellwig
2026-06-05 18:44 ` [PATCH 2/4] block: add a "tag" for block status codes Christoph Hellwig
2026-06-06 7:20 ` Damien Le Moal
2026-06-06 7:25 ` Hannes Reinecke
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=20260608051416.1205282-3-hch@lst.de \
--to=hch@lst.de \
--cc=axboe@kernel.dk \
--cc=corbet@lwn.net \
--cc=dlemoal@kernel.org \
--cc=hare@kernel.org \
--cc=hare@suse.de \
--cc=kbusch@kernel.org \
--cc=linux-block@vger.kernel.org \
--cc=linux-doc@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