noop-iosched.c 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114
  1. /*
  2. * elevator noop
  3. */
  4. #include <linux/blkdev.h>
  5. #include <linux/elevator.h>
  6. #include <linux/bio.h>
  7. #include <linux/module.h>
  8. #include <linux/slab.h>
  9. #include <linux/init.h>
  10. struct noop_data {
  11. struct list_head queue;
  12. };
  13. static void noop_merged_requests(struct request_queue *q, struct request *rq,
  14. struct request *next)
  15. {
  16. list_del_init(&next->queuelist);
  17. }
  18. static int noop_dispatch(struct request_queue *q, int force)
  19. {
  20. struct noop_data *nd = q->elevator->elevator_data;
  21. if (!list_empty(&nd->queue)) {
  22. struct request *rq;
  23. rq = list_entry(nd->queue.next, struct request, queuelist);
  24. list_del_init(&rq->queuelist);
  25. elv_dispatch_sort(q, rq);
  26. return 1;
  27. }
  28. return 0;
  29. }
  30. static void noop_add_request(struct request_queue *q, struct request *rq)
  31. {
  32. struct noop_data *nd = q->elevator->elevator_data;
  33. list_add_tail(&rq->queuelist, &nd->queue);
  34. }
  35. static struct request *
  36. noop_former_request(struct request_queue *q, struct request *rq)
  37. {
  38. struct noop_data *nd = q->elevator->elevator_data;
  39. if (rq->queuelist.prev == &nd->queue)
  40. return NULL;
  41. return list_entry(rq->queuelist.prev, struct request, queuelist);
  42. }
  43. static struct request *
  44. noop_latter_request(struct request_queue *q, struct request *rq)
  45. {
  46. struct noop_data *nd = q->elevator->elevator_data;
  47. if (rq->queuelist.next == &nd->queue)
  48. return NULL;
  49. return list_entry(rq->queuelist.next, struct request, queuelist);
  50. }
  51. static void *noop_init_queue(struct request_queue *q)
  52. {
  53. struct noop_data *nd;
  54. nd = kmalloc_node(sizeof(*nd), GFP_KERNEL, q->node);
  55. if (!nd)
  56. return NULL;
  57. INIT_LIST_HEAD(&nd->queue);
  58. return nd;
  59. }
  60. static void noop_exit_queue(struct elevator_queue *e)
  61. {
  62. struct noop_data *nd = e->elevator_data;
  63. BUG_ON(!list_empty(&nd->queue));
  64. kfree(nd);
  65. }
  66. static struct elevator_type elevator_noop = {
  67. .ops = {
  68. .elevator_merge_req_fn = noop_merged_requests,
  69. .elevator_dispatch_fn = noop_dispatch,
  70. .elevator_add_req_fn = noop_add_request,
  71. .elevator_former_req_fn = noop_former_request,
  72. .elevator_latter_req_fn = noop_latter_request,
  73. .elevator_init_fn = noop_init_queue,
  74. .elevator_exit_fn = noop_exit_queue,
  75. },
  76. .elevator_name = "noop",
  77. .elevator_owner = THIS_MODULE,
  78. };
  79. static int __init noop_init(void)
  80. {
  81. elv_register(&elevator_noop);
  82. return 0;
  83. }
  84. static void __exit noop_exit(void)
  85. {
  86. elv_unregister(&elevator_noop);
  87. }
  88. module_init(noop_init);
  89. module_exit(noop_exit);
  90. MODULE_AUTHOR("Jens Axboe");
  91. MODULE_LICENSE("GPL");
  92. MODULE_DESCRIPTION("No-op IO scheduler");