Skip to content

Commit 29ece8b

Browse files
Yufen Yuaxboe
authored andcommitted
block: add BLK_MQ_POLL_CLASSIC for hybrid poll and return EINVAL for unexpected value
For q->poll_nsec == -1, means doing classic poll, not hybrid poll. We introduce a new flag BLK_MQ_POLL_CLASSIC to replace -1, which may make code much easier to read. Additionally, since val is an int obtained with kstrtoint(), val can be a negative value other than -1, so return -EINVAL for that case. Thanks to Damien Le Moal for some good suggestion. Reviewed-by: Damien Le Moal <damien.lemoal@wdc.com> Signed-off-by: Yufen Yu <yuyufen@huawei.com> Signed-off-by: Jens Axboe <axboe@kernel.dk>
1 parent 9496c01 commit 29ece8b

File tree

3 files changed

+12
-7
lines changed

3 files changed

+12
-7
lines changed

block/blk-mq.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2856,7 +2856,7 @@ struct request_queue *blk_mq_init_allocated_queue(struct blk_mq_tag_set *set,
28562856
/*
28572857
* Default to classic polling
28582858
*/
2859-
q->poll_nsec = -1;
2859+
q->poll_nsec = BLK_MQ_POLL_CLASSIC;
28602860

28612861
blk_mq_init_cpu_queues(q, set->nr_hw_queues);
28622862
blk_mq_add_queue_tag_set(set, q);
@@ -3391,7 +3391,7 @@ static bool blk_mq_poll_hybrid(struct request_queue *q,
33913391
{
33923392
struct request *rq;
33933393

3394-
if (q->poll_nsec == -1)
3394+
if (q->poll_nsec == BLK_MQ_POLL_CLASSIC)
33953395
return false;
33963396

33973397
if (!blk_qc_t_is_internal(cookie))

block/blk-sysfs.c

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -360,8 +360,8 @@ static ssize_t queue_poll_delay_show(struct request_queue *q, char *page)
360360
{
361361
int val;
362362

363-
if (q->poll_nsec == -1)
364-
val = -1;
363+
if (q->poll_nsec == BLK_MQ_POLL_CLASSIC)
364+
val = BLK_MQ_POLL_CLASSIC;
365365
else
366366
val = q->poll_nsec / 1000;
367367

@@ -380,10 +380,12 @@ static ssize_t queue_poll_delay_store(struct request_queue *q, const char *page,
380380
if (err < 0)
381381
return err;
382382

383-
if (val == -1)
384-
q->poll_nsec = -1;
385-
else
383+
if (val == BLK_MQ_POLL_CLASSIC)
384+
q->poll_nsec = BLK_MQ_POLL_CLASSIC;
385+
else if (val >= 0)
386386
q->poll_nsec = val * 1000;
387+
else
388+
return -EINVAL;
387389

388390
return count;
389391
}

include/linux/blkdev.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,9 @@ struct blk_stat_callback;
5050
/* Must be consistent with blk_mq_poll_stats_bkt() */
5151
#define BLK_MQ_POLL_STATS_BKTS 16
5252

53+
/* Doing classic polling */
54+
#define BLK_MQ_POLL_CLASSIC -1
55+
5356
/*
5457
* Maximum number of blkcg policies allowed to be registered concurrently.
5558
* Defined here to simplify include dependency.

0 commit comments

Comments
 (0)