elevator.h 6.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214
  1. #ifndef _LINUX_ELEVATOR_H
  2. #define _LINUX_ELEVATOR_H
  3. #include <linux/percpu.h>
  4. #include <linux/hashtable.h>
  5. #ifdef CONFIG_BLOCK
  6. struct io_cq;
  7. struct elevator_type;
  8. typedef int (elevator_merge_fn) (struct request_queue *, struct request **,
  9. struct bio *);
  10. typedef void (elevator_merge_req_fn) (struct request_queue *, struct request *, struct request *);
  11. typedef void (elevator_merged_fn) (struct request_queue *, struct request *, int);
  12. typedef int (elevator_allow_merge_fn) (struct request_queue *, struct request *, struct bio *);
  13. typedef void (elevator_bio_merged_fn) (struct request_queue *,
  14. struct request *, struct bio *);
  15. typedef int (elevator_dispatch_fn) (struct request_queue *, int);
  16. typedef void (elevator_add_req_fn) (struct request_queue *, struct request *);
  17. typedef struct request *(elevator_request_list_fn) (struct request_queue *, struct request *);
  18. typedef void (elevator_completed_req_fn) (struct request_queue *, struct request *);
  19. typedef int (elevator_may_queue_fn) (struct request_queue *, int);
  20. typedef void (elevator_init_icq_fn) (struct io_cq *);
  21. typedef void (elevator_exit_icq_fn) (struct io_cq *);
  22. typedef int (elevator_set_req_fn) (struct request_queue *, struct request *,
  23. struct bio *, gfp_t);
  24. typedef void (elevator_put_req_fn) (struct request *);
  25. typedef void (elevator_activate_req_fn) (struct request_queue *, struct request *);
  26. typedef void (elevator_deactivate_req_fn) (struct request_queue *, struct request *);
  27. typedef int (elevator_init_fn) (struct request_queue *,
  28. struct elevator_type *e);
  29. typedef void (elevator_exit_fn) (struct elevator_queue *);
  30. typedef void (elevator_registered_fn) (struct request_queue *);
  31. struct elevator_ops
  32. {
  33. elevator_merge_fn *elevator_merge_fn;
  34. elevator_merged_fn *elevator_merged_fn;
  35. elevator_merge_req_fn *elevator_merge_req_fn;
  36. elevator_allow_merge_fn *elevator_allow_merge_fn;
  37. elevator_bio_merged_fn *elevator_bio_merged_fn;
  38. elevator_dispatch_fn *elevator_dispatch_fn;
  39. elevator_add_req_fn *elevator_add_req_fn;
  40. elevator_activate_req_fn *elevator_activate_req_fn;
  41. elevator_deactivate_req_fn *elevator_deactivate_req_fn;
  42. elevator_completed_req_fn *elevator_completed_req_fn;
  43. elevator_request_list_fn *elevator_former_req_fn;
  44. elevator_request_list_fn *elevator_latter_req_fn;
  45. elevator_init_icq_fn *elevator_init_icq_fn; /* see iocontext.h */
  46. elevator_exit_icq_fn *elevator_exit_icq_fn; /* ditto */
  47. elevator_set_req_fn *elevator_set_req_fn;
  48. elevator_put_req_fn *elevator_put_req_fn;
  49. elevator_may_queue_fn *elevator_may_queue_fn;
  50. elevator_init_fn *elevator_init_fn;
  51. elevator_exit_fn *elevator_exit_fn;
  52. elevator_registered_fn *elevator_registered_fn;
  53. };
  54. #define ELV_NAME_MAX (16)
  55. struct elv_fs_entry {
  56. struct attribute attr;
  57. ssize_t (*show)(struct elevator_queue *, char *);
  58. ssize_t (*store)(struct elevator_queue *, const char *, size_t);
  59. };
  60. /*
  61. * identifies an elevator type, such as AS or deadline
  62. */
  63. struct elevator_type
  64. {
  65. /* managed by elevator core */
  66. struct kmem_cache *icq_cache;
  67. /* fields provided by elevator implementation */
  68. struct elevator_ops ops;
  69. size_t icq_size; /* see iocontext.h */
  70. size_t icq_align; /* ditto */
  71. struct elv_fs_entry *elevator_attrs;
  72. char elevator_name[ELV_NAME_MAX];
  73. struct module *elevator_owner;
  74. /* managed by elevator core */
  75. char icq_cache_name[ELV_NAME_MAX + 5]; /* elvname + "_io_cq" */
  76. struct list_head list;
  77. };
  78. #define ELV_HASH_BITS 6
  79. /*
  80. * each queue has an elevator_queue associated with it
  81. */
  82. struct elevator_queue
  83. {
  84. struct elevator_type *type;
  85. void *elevator_data;
  86. struct kobject kobj;
  87. struct mutex sysfs_lock;
  88. unsigned int registered:1;
  89. DECLARE_HASHTABLE(hash, ELV_HASH_BITS);
  90. };
  91. /*
  92. * block elevator interface
  93. */
  94. extern void elv_dispatch_sort(struct request_queue *, struct request *);
  95. extern void elv_dispatch_add_tail(struct request_queue *, struct request *);
  96. extern void elv_add_request(struct request_queue *, struct request *, int);
  97. extern void __elv_add_request(struct request_queue *, struct request *, int);
  98. extern int elv_merge(struct request_queue *, struct request **, struct bio *);
  99. extern void elv_merge_requests(struct request_queue *, struct request *,
  100. struct request *);
  101. extern void elv_merged_request(struct request_queue *, struct request *, int);
  102. extern void elv_bio_merged(struct request_queue *q, struct request *,
  103. struct bio *);
  104. extern void elv_requeue_request(struct request_queue *, struct request *);
  105. extern struct request *elv_former_request(struct request_queue *, struct request *);
  106. extern struct request *elv_latter_request(struct request_queue *, struct request *);
  107. extern int elv_register_queue(struct request_queue *q);
  108. extern void elv_unregister_queue(struct request_queue *q);
  109. extern int elv_may_queue(struct request_queue *, int);
  110. extern void elv_completed_request(struct request_queue *, struct request *);
  111. extern int elv_set_request(struct request_queue *q, struct request *rq,
  112. struct bio *bio, gfp_t gfp_mask);
  113. extern void elv_put_request(struct request_queue *, struct request *);
  114. extern void elv_drain_elevator(struct request_queue *);
  115. /*
  116. * io scheduler registration
  117. */
  118. extern void __init load_default_elevator_module(void);
  119. extern int elv_register(struct elevator_type *);
  120. extern void elv_unregister(struct elevator_type *);
  121. /*
  122. * io scheduler sysfs switching
  123. */
  124. extern ssize_t elv_iosched_show(struct request_queue *, char *);
  125. extern ssize_t elv_iosched_store(struct request_queue *, const char *, size_t);
  126. extern int elevator_init(struct request_queue *, char *);
  127. extern void elevator_exit(struct elevator_queue *);
  128. extern int elevator_change(struct request_queue *, const char *);
  129. extern bool elv_rq_merge_ok(struct request *, struct bio *);
  130. extern struct elevator_queue *elevator_alloc(struct request_queue *,
  131. struct elevator_type *);
  132. /*
  133. * Helper functions.
  134. */
  135. extern struct request *elv_rb_former_request(struct request_queue *, struct request *);
  136. extern struct request *elv_rb_latter_request(struct request_queue *, struct request *);
  137. /*
  138. * rb support functions.
  139. */
  140. extern void elv_rb_add(struct rb_root *, struct request *);
  141. extern void elv_rb_del(struct rb_root *, struct request *);
  142. extern struct request *elv_rb_find(struct rb_root *, sector_t);
  143. /*
  144. * Return values from elevator merger
  145. */
  146. #define ELEVATOR_NO_MERGE 0
  147. #define ELEVATOR_FRONT_MERGE 1
  148. #define ELEVATOR_BACK_MERGE 2
  149. /*
  150. * Insertion selection
  151. */
  152. #define ELEVATOR_INSERT_FRONT 1
  153. #define ELEVATOR_INSERT_BACK 2
  154. #define ELEVATOR_INSERT_SORT 3
  155. #define ELEVATOR_INSERT_REQUEUE 4
  156. #define ELEVATOR_INSERT_FLUSH 5
  157. #define ELEVATOR_INSERT_SORT_MERGE 6
  158. /*
  159. * return values from elevator_may_queue_fn
  160. */
  161. enum {
  162. ELV_MQUEUE_MAY,
  163. ELV_MQUEUE_NO,
  164. ELV_MQUEUE_MUST,
  165. };
  166. #define rq_end_sector(rq) (blk_rq_pos(rq) + blk_rq_sectors(rq))
  167. #define rb_entry_rq(node) rb_entry((node), struct request, rb_node)
  168. #define rq_entry_fifo(ptr) list_entry((ptr), struct request, queuelist)
  169. #define rq_fifo_clear(rq) list_del_init(&(rq)->queuelist)
  170. #else /* CONFIG_BLOCK */
  171. static inline void load_default_elevator_module(void) { }
  172. #endif /* CONFIG_BLOCK */
  173. #endif