History

block: add a poll_fn callback to struct request_queue

That we we can also poll non blk-mq queues. Mostly needed for the NVMe multipath code, but could also be useful elsewhere.

Christoph Hellwig committed 9 years ago

Commit ea435e11 parent 8ddcd658 files · +25 −16Browse files

Unified · Split

8 files
  1. block/blk-core.c +11 −0
  2. block/blk-mq.c +5 −9
  3. drivers/nvme/target/io-cmd.c +1 −1
  4. fs/block_dev.c +2 −2
  5. fs/direct-io.c +1 −1
  6. fs/iomap.c +1 −1
  7. include/linux/blkdev.h +3 −1
  8. mm/page_io.c +1 −1
block/blk-core.c+11−0
@@ -2321,6 +2321,17 @@ blk_qc_t submit_bio(struct bio *bio) · 2320 unmodified lines
23212321 }
23222322 EXPORT_SYMBOL(submit_bio);
23232323
2324+bool blk_poll(struct request_queue *q, blk_qc_t cookie)
2325+{
2326+ if (!q->poll_fn || !blk_qc_t_valid(cookie))
2327+ return false;
2328+
2329+ if (current->plug)
2330+ blk_flush_plug_list(current->plug, false);
2331+ return q->poll_fn(q, cookie);
2332+}
2333+EXPORT_SYMBOL_GPL(blk_poll);
2334+
23242335 /**
23252336 * blk_cloned_rq_check_limits - Helper function to check a cloned request
23262337 * for new the queue limits
block/blk-mq.c+5−9
@@ -37,6 +37,7 @@ · 36 unmodified lines
3737 #include "blk-wbt.h"
3838 #include "blk-mq-sched.h"
3939
40+static bool blk_mq_poll(struct request_queue *q, blk_qc_t cookie);
4041 static void blk_mq_poll_stats_start(struct request_queue *q);
4142 static void blk_mq_poll_stats_fn(struct blk_stat_callback *cb);
4243
@@ -2499,6 +2500,8 @@ struct request_queue *blk_mq_init_allocated_queue(struct blk_mq_tag_set *set, · 2456 unmodified lines
24992500 spin_lock_init(&q->requeue_lock);
25002501
25012502 blk_queue_make_request(q, blk_mq_make_request);
2503+ if (q->mq_ops->poll)
2504+ q->poll_fn = blk_mq_poll;
25022505
25032506 /*
25042507 * Do this after blk_queue_make_request() overrides it...
@@ -2961,20 +2964,14 @@ static bool __blk_mq_poll(struct blk_mq_hw_ctx *hctx, struct request *rq) · 456 unmodified lines
29612964 return false;
29622965 }
29632966
2964−bool blk_mq_poll(struct request_queue *q, blk_qc_t cookie)
2967+static bool blk_mq_poll(struct request_queue *q, blk_qc_t cookie)
29652968 {
29662969 struct blk_mq_hw_ctx *hctx;
2967− struct blk_plug *plug;
29682970 struct request *rq;
29692971
2970− if (!q->mq_ops || !q->mq_ops->poll || !blk_qc_t_valid(cookie) ||
2971− !test_bit(QUEUE_FLAG_POLL, &q->queue_flags))
2972+ if (!test_bit(QUEUE_FLAG_POLL, &q->queue_flags))
29722973 return false;
29732974
2974− plug = current->plug;
2975− if (plug)
2976− blk_flush_plug_list(plug, false);
2977−
29782975 hctx = q->queue_hw_ctx[blk_qc_t_to_queue_num(cookie)];
29792976 if (!blk_qc_t_is_internal(cookie))
29802977 rq = blk_mq_tag_to_rq(hctx->tags, blk_qc_t_to_tag(cookie));
@@ -2992,7 +2989,6 @@ bool blk_mq_poll(struct request_queue *q, blk_qc_t cookie) · 11 unmodified lines
29922989
29932990 return __blk_mq_poll(hctx, rq);
29942991 }
2995−EXPORT_SYMBOL_GPL(blk_mq_poll);
29962992
29972993 static int __init blk_mq_init(void)
29982994 {
drivers/nvme/target/io-cmd.c+1−1
@@ -94,7 +94,7 @@ static void nvmet_execute_rw(struct nvmet_req *req) · 93 unmodified lines
9494
9595 cookie = submit_bio(bio);
9696
97− blk_mq_poll(bdev_get_queue(req->ns->bdev), cookie);
97+ blk_poll(bdev_get_queue(req->ns->bdev), cookie);
9898 }
9999
100100 static void nvmet_execute_flush(struct nvmet_req *req)
fs/block_dev.c+2−2
@@ -237,7 +237,7 @@ __blkdev_direct_IO_simple(struct kiocb *iocb, struct iov_iter *iter, · 236 unmodified lines
237237 if (!READ_ONCE(bio.bi_private))
238238 break;
239239 if (!(iocb->ki_flags & IOCB_HIPRI) ||
240− !blk_mq_poll(bdev_get_queue(bdev), qc))
240+ !blk_poll(bdev_get_queue(bdev), qc))
241241 io_schedule();
242242 }
243243 __set_current_state(TASK_RUNNING);
@@ -402,7 +402,7 @@ __blkdev_direct_IO(struct kiocb *iocb, struct iov_iter *iter, int nr_pages) · 158 unmodified lines
402402 break;
403403
404404 if (!(iocb->ki_flags & IOCB_HIPRI) ||
405− !blk_mq_poll(bdev_get_queue(bdev), qc))
405+ !blk_poll(bdev_get_queue(bdev), qc))
406406 io_schedule();
407407 }
408408 __set_current_state(TASK_RUNNING);
fs/direct-io.c+1−1
@@ -486,7 +486,7 @@ static struct bio *dio_await_one(struct dio *dio) · 485 unmodified lines
486486 dio->waiter = current;
487487 spin_unlock_irqrestore(&dio->bio_lock, flags);
488488 if (!(dio->iocb->ki_flags & IOCB_HIPRI) ||
489− !blk_mq_poll(dio->bio_disk->queue, dio->bio_cookie))
489+ !blk_poll(dio->bio_disk->queue, dio->bio_cookie))
490490 io_schedule();
491491 /* wake up sets us TASK_RUNNING */
492492 spin_lock_irqsave(&dio->bio_lock, flags);
fs/iomap.c+1−1
@@ -1049,7 +1049,7 @@ iomap_dio_rw(struct kiocb *iocb, struct iov_iter *iter, · 1048 unmodified lines
10491049
10501050 if (!(iocb->ki_flags & IOCB_HIPRI) ||
10511051 !dio->submit.last_queue ||
1052− !blk_mq_poll(dio->submit.last_queue,
1052+ !blk_poll(dio->submit.last_queue,
10531053 dio->submit.cookie))
10541054 io_schedule();
10551055 }
include/linux/blkdev.h+3−1
@@ -266,6 +266,7 @@ struct blk_queue_ctx; · 265 unmodified lines
266266
267267 typedef void (request_fn_proc) (struct request_queue *q);
268268 typedef blk_qc_t (make_request_fn) (struct request_queue *q, struct bio *bio);
269+typedef bool (poll_q_fn) (struct request_queue *q, blk_qc_t);
269270 typedef int (prep_rq_fn) (struct request_queue *, struct request *);
270271 typedef void (unprep_rq_fn) (struct request_queue *, struct request *);
271272
@@ -408,6 +409,7 @@ struct request_queue { · 136 unmodified lines
408409
409410 request_fn_proc *request_fn;
410411 make_request_fn *make_request_fn;
412+ poll_q_fn *poll_fn;
411413 prep_rq_fn *prep_rq_fn;
412414 unprep_rq_fn *unprep_rq_fn;
413415 softirq_done_fn *softirq_done_fn;
@@ -975,7 +977,7 @@ extern void blk_execute_rq_nowait(struct request_queue *, struct gendisk *, · 561 unmodified lines
975977 int blk_status_to_errno(blk_status_t status);
976978 blk_status_t errno_to_blk_status(int errno);
977979
978−bool blk_mq_poll(struct request_queue *q, blk_qc_t cookie);
980+bool blk_poll(struct request_queue *q, blk_qc_t cookie);
979981
980982 static inline struct request_queue *bdev_get_queue(struct block_device *bdev)
981983 {
mm/page_io.c+1−1
@@ -407,7 +407,7 @@ int swap_readpage(struct page *page, bool do_poll) · 406 unmodified lines
407407 if (!READ_ONCE(bio->bi_private))
408408 break;
409409
410− if (!blk_mq_poll(disk->queue, qc))
410+ if (!blk_poll(disk->queue, qc))
411411 break;
412412 }
413413 __set_current_state(TASK_RUNNING);

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t