blk.h 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125
  1. #ifndef BLK_INTERNAL_H
  2. #define BLK_INTERNAL_H
  3. /* Amount of time in which a process may batch requests */
  4. #define BLK_BATCH_TIME (HZ/50UL)
  5. /* Number of requests a "batching" process may submit */
  6. #define BLK_BATCH_REQ 32
  7. extern struct kmem_cache *blk_requestq_cachep;
  8. extern struct kobj_type blk_queue_ktype;
  9. void init_request_from_bio(struct request *req, struct bio *bio);
  10. void blk_rq_bio_prep(struct request_queue *q, struct request *rq,
  11. struct bio *bio);
  12. void __blk_queue_free_tags(struct request_queue *q);
  13. void blk_unplug_work(struct work_struct *work);
  14. void blk_unplug_timeout(unsigned long data);
  15. void blk_rq_timed_out_timer(unsigned long data);
  16. void blk_delete_timer(struct request *);
  17. void blk_add_timer(struct request *);
  18. void __generic_unplug_device(struct request_queue *);
  19. /*
  20. * Internal atomic flags for request handling
  21. */
  22. enum rq_atomic_flags {
  23. REQ_ATOM_COMPLETE = 0,
  24. };
  25. /*
  26. * EH timer and IO completion will both attempt to 'grab' the request, make
  27. * sure that only one of them suceeds
  28. */
  29. static inline int blk_mark_rq_complete(struct request *rq)
  30. {
  31. return test_and_set_bit(REQ_ATOM_COMPLETE, &rq->atomic_flags);
  32. }
  33. static inline void blk_clear_rq_complete(struct request *rq)
  34. {
  35. clear_bit(REQ_ATOM_COMPLETE, &rq->atomic_flags);
  36. }
  37. #ifdef CONFIG_FAIL_IO_TIMEOUT
  38. int blk_should_fake_timeout(struct request_queue *);
  39. ssize_t part_timeout_show(struct device *, struct device_attribute *, char *);
  40. ssize_t part_timeout_store(struct device *, struct device_attribute *,
  41. const char *, size_t);
  42. #else
  43. static inline int blk_should_fake_timeout(struct request_queue *q)
  44. {
  45. return 0;
  46. }
  47. #endif
  48. struct io_context *current_io_context(gfp_t gfp_flags, int node);
  49. int ll_back_merge_fn(struct request_queue *q, struct request *req,
  50. struct bio *bio);
  51. int ll_front_merge_fn(struct request_queue *q, struct request *req,
  52. struct bio *bio);
  53. int attempt_back_merge(struct request_queue *q, struct request *rq);
  54. int attempt_front_merge(struct request_queue *q, struct request *rq);
  55. void blk_recalc_rq_segments(struct request *rq);
  56. void blk_recalc_rq_sectors(struct request *rq, int nsect);
  57. void blk_queue_congestion_threshold(struct request_queue *q);
  58. int blk_dev_init(void);
  59. void elv_quiesce_start(struct request_queue *q);
  60. void elv_quiesce_end(struct request_queue *q);
  61. /*
  62. * Return the threshold (number of used requests) at which the queue is
  63. * considered to be congested. It include a little hysteresis to keep the
  64. * context switch rate down.
  65. */
  66. static inline int queue_congestion_on_threshold(struct request_queue *q)
  67. {
  68. return q->nr_congestion_on;
  69. }
  70. /*
  71. * The threshold at which a queue is considered to be uncongested
  72. */
  73. static inline int queue_congestion_off_threshold(struct request_queue *q)
  74. {
  75. return q->nr_congestion_off;
  76. }
  77. #if defined(CONFIG_BLK_DEV_INTEGRITY)
  78. #define rq_for_each_integrity_segment(bvl, _rq, _iter) \
  79. __rq_for_each_bio(_iter.bio, _rq) \
  80. bip_for_each_vec(bvl, _iter.bio->bi_integrity, _iter.i)
  81. #endif /* BLK_DEV_INTEGRITY */
  82. static inline int blk_cpu_to_group(int cpu)
  83. {
  84. #ifdef CONFIG_SCHED_MC
  85. const struct cpumask *mask = cpu_coregroup_mask(cpu);
  86. return cpumask_first(mask);
  87. #elif defined(CONFIG_SCHED_SMT)
  88. return cpumask_first(topology_thread_cpumask(cpu));
  89. #else
  90. return cpu;
  91. #endif
  92. }
  93. static inline int blk_do_io_stat(struct request *rq)
  94. {
  95. struct gendisk *disk = rq->rq_disk;
  96. if (!disk || !disk->queue)
  97. return 0;
  98. return blk_queue_io_stat(disk->queue) && (rq->cmd_flags & REQ_ELVPRIV);
  99. }
  100. #endif