block: add BLK_MQ_POLL_CLASSIC for hybrid poll and return EINVAL for unexpected value
authorYufen Yu <yuyufen@huawei.com>
Mon, 18 Mar 2019 14:44:41 +0000 (22:44 +0800)
committerJens Axboe <axboe@kernel.dk>
Wed, 20 Mar 2019 20:02:07 +0000 (14:02 -0600)
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>
block/blk-mq.c
block/blk-sysfs.c
include/linux/blkdev.h

index ea01c23b58a3d8bdd102786e43b0c956a0e1a8d7..76a3f78c566abc172396ccbca94a686089975b62 100644 (file)
@@ -2856,7 +2856,7 @@ struct request_queue *blk_mq_init_allocated_queue(struct blk_mq_tag_set *set,
        /*
         * Default to classic polling
         */
-       q->poll_nsec = -1;
+       q->poll_nsec = BLK_MQ_POLL_CLASSIC;
 
        blk_mq_init_cpu_queues(q, set->nr_hw_queues);
        blk_mq_add_queue_tag_set(set, q);
@@ -3391,7 +3391,7 @@ static bool blk_mq_poll_hybrid(struct request_queue *q,
 {
        struct request *rq;
 
-       if (q->poll_nsec == -1)
+       if (q->poll_nsec == BLK_MQ_POLL_CLASSIC)
                return false;
 
        if (!blk_qc_t_is_internal(cookie))
index 59685918167e51d80a2808861b3f2f7744dec3a7..422327089e0fd963dbfaf346be68f7951da15df2 100644 (file)
@@ -360,8 +360,8 @@ static ssize_t queue_poll_delay_show(struct request_queue *q, char *page)
 {
        int val;
 
-       if (q->poll_nsec == -1)
-               val = -1;
+       if (q->poll_nsec == BLK_MQ_POLL_CLASSIC)
+               val = BLK_MQ_POLL_CLASSIC;
        else
                val = q->poll_nsec / 1000;
 
@@ -380,10 +380,12 @@ static ssize_t queue_poll_delay_store(struct request_queue *q, const char *page,
        if (err < 0)
                return err;
 
-       if (val == -1)
-               q->poll_nsec = -1;
-       else
+       if (val == BLK_MQ_POLL_CLASSIC)
+               q->poll_nsec = BLK_MQ_POLL_CLASSIC;
+       else if (val >= 0)
                q->poll_nsec = val * 1000;
+       else
+               return -EINVAL;
 
        return count;
 }
index 0de92b29f589c949307ef716a750fb7f7a671ae7..5c58a3b2bf0038083b9dc2b88293349fa8afb22b 100644 (file)
@@ -50,6 +50,9 @@ struct blk_stat_callback;
 /* Must be consistent with blk_mq_poll_stats_bkt() */
 #define BLK_MQ_POLL_STATS_BKTS 16
 
+/* Doing classic polling */
+#define BLK_MQ_POLL_CLASSIC -1
+
 /*
  * Maximum number of blkcg policies allowed to be registered concurrently.
  * Defined here to simplify include dependency.