Skip to content

Commit ce35156

Browse files
Christoph Hellwigaxboe
authored andcommitted
block: add a "tag" for block status codes
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>
1 parent 8c8ebed commit ce35156

2 files changed

Lines changed: 30 additions & 0 deletions

File tree

block/blk-core.c

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -135,10 +135,12 @@ EXPORT_SYMBOL_GPL(blk_op_str);
135135
#define ENT(_tag, _errno, _desc) \
136136
[BLK_STS_##_tag] = { \
137137
.errno = _errno, \
138+
.tag = __stringify(_tag), \
138139
.name = _desc, \
139140
}
140141
static const struct {
141142
int errno;
143+
const char *tag;
142144
const char *name;
143145
} blk_errors[] = {
144146
ENT(OK, 0, ""),
@@ -203,6 +205,32 @@ const char *blk_status_to_str(blk_status_t status)
203205
return blk_errors[idx].name;
204206
}
205207

208+
const char *blk_status_to_tag(blk_status_t status)
209+
{
210+
int idx = (__force int)status;
211+
212+
if (WARN_ON_ONCE(idx >= ARRAY_SIZE(blk_errors) || !blk_errors[idx].tag))
213+
return "<null>";
214+
return blk_errors[idx].tag;
215+
}
216+
217+
blk_status_t tag_to_blk_status(const char *tag)
218+
{
219+
int i;
220+
221+
for (i = 0; i < ARRAY_SIZE(blk_errors); i++) {
222+
if (blk_errors[i].tag &&
223+
!strcmp(blk_errors[i].tag, tag))
224+
return (__force blk_status_t)i;
225+
}
226+
227+
/*
228+
* Return BLK_STS_OK for mismatches as this function is intended to
229+
* parse error status values.
230+
*/
231+
return BLK_STS_OK;
232+
}
233+
206234
/**
207235
* blk_sync_queue - cancel any pending callbacks on a queue
208236
* @q: the queue

block/blk.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,8 @@ struct blk_flush_queue *blk_alloc_flush_queue(int node, int cmd_size,
5151
void blk_free_flush_queue(struct blk_flush_queue *q);
5252

5353
const char *blk_status_to_str(blk_status_t status);
54+
const char *blk_status_to_tag(blk_status_t status);
55+
blk_status_t tag_to_blk_status(const char *tag);
5456

5557
bool __blk_mq_unfreeze_queue(struct request_queue *q, bool force_atomic);
5658
bool blk_queue_start_drain(struct request_queue *q);

0 commit comments

Comments
 (0)