blk-mq-sched.h 2.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495
  1. /* SPDX-License-Identifier: GPL-2.0 */
  2. #ifndef BLK_MQ_SCHED_H
  3. #define BLK_MQ_SCHED_H
  4. #include "blk-mq.h"
  5. #include "blk-mq-tag.h"
  6. void blk_mq_sched_free_hctx_data(struct request_queue *q,
  7. void (*exit)(struct blk_mq_hw_ctx *));
  8. void blk_mq_sched_assign_ioc(struct request *rq, struct bio *bio);
  9. void blk_mq_sched_request_inserted(struct request *rq);
  10. bool blk_mq_sched_try_merge(struct request_queue *q, struct bio *bio,
  11. struct request **merged_request);
  12. bool __blk_mq_sched_bio_merge(struct request_queue *q, struct bio *bio);
  13. bool blk_mq_sched_try_insert_merge(struct request_queue *q, struct request *rq);
  14. void blk_mq_sched_mark_restart_hctx(struct blk_mq_hw_ctx *hctx);
  15. void blk_mq_sched_restart(struct blk_mq_hw_ctx *hctx);
  16. void blk_mq_sched_insert_request(struct request *rq, bool at_head,
  17. bool run_queue, bool async);
  18. void blk_mq_sched_insert_requests(struct request_queue *q,
  19. struct blk_mq_ctx *ctx,
  20. struct list_head *list, bool run_queue_async);
  21. void blk_mq_sched_dispatch_requests(struct blk_mq_hw_ctx *hctx);
  22. int blk_mq_init_sched(struct request_queue *q, struct elevator_type *e);
  23. void blk_mq_exit_sched(struct request_queue *q, struct elevator_queue *e);
  24. static inline bool
  25. blk_mq_sched_bio_merge(struct request_queue *q, struct bio *bio)
  26. {
  27. if (blk_queue_nomerges(q) || !bio_mergeable(bio))
  28. return false;
  29. return __blk_mq_sched_bio_merge(q, bio);
  30. }
  31. static inline bool
  32. blk_mq_sched_allow_merge(struct request_queue *q, struct request *rq,
  33. struct bio *bio)
  34. {
  35. struct elevator_queue *e = q->elevator;
  36. if (e && e->type->ops.mq.allow_merge)
  37. return e->type->ops.mq.allow_merge(q, rq, bio);
  38. return true;
  39. }
  40. static inline void blk_mq_sched_completed_request(struct request *rq)
  41. {
  42. struct elevator_queue *e = rq->q->elevator;
  43. if (e && e->type->ops.mq.completed_request)
  44. e->type->ops.mq.completed_request(rq);
  45. }
  46. static inline void blk_mq_sched_started_request(struct request *rq)
  47. {
  48. struct request_queue *q = rq->q;
  49. struct elevator_queue *e = q->elevator;
  50. if (e && e->type->ops.mq.started_request)
  51. e->type->ops.mq.started_request(rq);
  52. }
  53. static inline void blk_mq_sched_requeue_request(struct request *rq)
  54. {
  55. struct request_queue *q = rq->q;
  56. struct elevator_queue *e = q->elevator;
  57. if (e && e->type->ops.mq.requeue_request)
  58. e->type->ops.mq.requeue_request(rq);
  59. }
  60. static inline bool blk_mq_sched_has_work(struct blk_mq_hw_ctx *hctx)
  61. {
  62. struct elevator_queue *e = hctx->queue->elevator;
  63. if (e && e->type->ops.mq.has_work)
  64. return e->type->ops.mq.has_work(hctx);
  65. return false;
  66. }
  67. static inline bool blk_mq_sched_needs_restart(struct blk_mq_hw_ctx *hctx)
  68. {
  69. return test_bit(BLK_MQ_S_SCHED_RESTART, &hctx->state);
  70. }
  71. #endif