Skip to content

Commit 2382731

Browse files
johnpgarryaxboe
authored andcommitted
block: Catch possible entries missing from hctx_state_name[]
Add a build-time assert that we are not missing entries from hctx_state_name[]. For this, create a separate enum for state flags and add a "max" entry for BLK_MQ_S_x flags. The numbering for those enum values is as default, so don't explicitly number. Signed-off-by: John Garry <john.g.garry@oracle.com> Link: https://lore.kernel.org/r/20240719112912.3830443-10-john.g.garry@oracle.com Signed-off-by: Jens Axboe <axboe@kernel.dk>
1 parent cce496d commit 2382731

2 files changed

Lines changed: 11 additions & 7 deletions

File tree

block/blk-mq-debugfs.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -165,6 +165,7 @@ static int hctx_state_show(void *data, struct seq_file *m)
165165
{
166166
struct blk_mq_hw_ctx *hctx = data;
167167

168+
BUILD_BUG_ON(ARRAY_SIZE(hctx_state_name) != BLK_MQ_S_MAX);
168169
blk_flags_show(m, hctx->state, hctx_state_name,
169170
ARRAY_SIZE(hctx_state_name));
170171
seq_puts(m, "\n");

include/linux/blk-mq.h

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -663,13 +663,6 @@ enum {
663663
BLK_MQ_F_NO_SCHED_BY_DEFAULT = 1 << 7,
664664
BLK_MQ_F_ALLOC_POLICY_START_BIT = 8,
665665
BLK_MQ_F_ALLOC_POLICY_BITS = 1,
666-
667-
BLK_MQ_S_STOPPED = 0,
668-
BLK_MQ_S_TAG_ACTIVE = 1,
669-
BLK_MQ_S_SCHED_RESTART = 2,
670-
671-
/* hw queue is inactive after all its CPUs become offline */
672-
BLK_MQ_S_INACTIVE = 3,
673666
};
674667
#define BLK_MQ_FLAG_TO_ALLOC_POLICY(flags) \
675668
((flags >> BLK_MQ_F_ALLOC_POLICY_START_BIT) & \
@@ -681,6 +674,16 @@ enum {
681674
#define BLK_MQ_MAX_DEPTH (10240)
682675
#define BLK_MQ_NO_HCTX_IDX (-1U)
683676

677+
enum {
678+
/* Keep hctx_state_name[] in sync with the definitions below */
679+
BLK_MQ_S_STOPPED,
680+
BLK_MQ_S_TAG_ACTIVE,
681+
BLK_MQ_S_SCHED_RESTART,
682+
/* hw queue is inactive after all its CPUs become offline */
683+
BLK_MQ_S_INACTIVE,
684+
BLK_MQ_S_MAX
685+
};
686+
684687
struct gendisk *__blk_mq_alloc_disk(struct blk_mq_tag_set *set,
685688
struct queue_limits *lim, void *queuedata,
686689
struct lock_class_key *lkclass);

0 commit comments

Comments
 (0)