]> git.ipfire.org Git - thirdparty/linux.git/commitdiff
block: add a "tag" for block status codes
authorChristoph Hellwig <hch@lst.de>
Thu, 11 Jun 2026 14:06:45 +0000 (16:06 +0200)
committerJens Axboe <axboe@kernel.dk>
Fri, 12 Jun 2026 16:40:35 +0000 (10:40 -0600)
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>
Reviewed-by: Md Haris Iqbal <haris.iqbal@linux.dev>
Link: https://patch.msgid.link/20260611140703.2401204-3-hch@lst.de
Signed-off-by: Jens Axboe <axboe@kernel.dk>
block/blk-core.c
block/blk.h

index 43121a9f99f009576f16d1ecc0d2145f2aa0b040..842b5c6f2fb4537e890f7ff0d1880f1e9990a5df 100644 (file)
@@ -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) || !blk_errors[idx].tag))
+               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
index 7fdfb9012ce1b392f0ad256a6c6fc5cacd1273c2..3ab2cdd6ed12074cf21b05864b998d5697e514e5 100644 (file)
@@ -51,6 +51,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);