noop-iosched.c 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125
  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. struct request *rq;
  22. rq = list_first_entry_or_null(&nd->queue, struct request, queuelist);
  23. if (rq) {
  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_prev_entry(rq, 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_next_entry(rq, queuelist);
  50. }
  51. static int noop_init_queue(struct request_queue *q, struct elevator_type *e)
  52. {
  53. struct noop_data *nd;
  54. struct elevator_queue *eq;
  55. eq = elevator_alloc(q, e);
  56. if (!eq)
  57. return -ENOMEM;
  58. nd = kmalloc_node(sizeof(*nd), GFP_KERNEL, q->node);
  59. if (!nd) {
  60. kobject_put(&eq->kobj);
  61. return -ENOMEM;
  62. }
  63. eq->elevator_data = nd;
  64. INIT_LIST_HEAD(&nd->queue);
  65. spin_lock_irq(q->queue_lock);
  66. q->elevator = eq;
  67. spin_unlock_irq(q->queue_lock);
  68. return 0;
  69. }
  70. static void noop_exit_queue(struct elevator_queue *e)
  71. {
  72. struct noop_data *nd = e->elevator_data;
  73. BUG_ON(!list_empty(&nd->queue));
  74. kfree(nd);
  75. }
  76. static struct elevator_type elevator_noop = {
  77. .ops = {
  78. .elevator_merge_req_fn = noop_merged_requests,
  79. .elevator_dispatch_fn = noop_dispatch,
  80. .elevator_add_req_fn = noop_add_request,
  81. .elevator_former_req_fn = noop_former_request,
  82. .elevator_latter_req_fn = noop_latter_request,
  83. .elevator_init_fn = noop_init_queue,
  84. .elevator_exit_fn = noop_exit_queue,
  85. },
  86. .elevator_name = "noop",
  87. .elevator_owner = THIS_MODULE,
  88. };
  89. static int __init noop_init(void)
  90. {
  91. return elv_register(&elevator_noop);
  92. }
  93. static void __exit noop_exit(void)
  94. {
  95. elv_unregister(&elevator_noop);
  96. }
  97. module_init(noop_init);
  98. module_exit(noop_exit);
  99. MODULE_AUTHOR("Jens Axboe");
  100. MODULE_LICENSE("GPL");
  101. MODULE_DESCRIPTION("No-op IO scheduler");