Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 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/init.h> |
| 9 | |
Tejun Heo | 5a7c47e | 2005-11-10 18:21:30 +0100 | [diff] [blame] | 10 | struct noop_data { |
| 11 | struct list_head queue; |
| 12 | }; |
| 13 | |
Jens Axboe | 165125e | 2007-07-24 09:28:11 +0200 | [diff] [blame] | 14 | static void noop_merged_requests(struct request_queue *q, struct request *rq, |
Tejun Heo | 5a7c47e | 2005-11-10 18:21:30 +0100 | [diff] [blame] | 15 | struct request *next) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 16 | { |
Tejun Heo | 5a7c47e | 2005-11-10 18:21:30 +0100 | [diff] [blame] | 17 | list_del_init(&next->queuelist); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 18 | } |
| 19 | |
Jens Axboe | 165125e | 2007-07-24 09:28:11 +0200 | [diff] [blame] | 20 | static int noop_dispatch(struct request_queue *q, int force) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 21 | { |
Tejun Heo | 5a7c47e | 2005-11-10 18:21:30 +0100 | [diff] [blame] | 22 | struct noop_data *nd = q->elevator->elevator_data; |
| 23 | |
| 24 | if (!list_empty(&nd->queue)) { |
| 25 | struct request *rq; |
| 26 | rq = list_entry(nd->queue.next, struct request, queuelist); |
| 27 | list_del_init(&rq->queuelist); |
| 28 | elv_dispatch_sort(q, rq); |
| 29 | return 1; |
| 30 | } |
Jens Axboe | b4878f2 | 2005-10-20 16:42:29 +0200 | [diff] [blame] | 31 | return 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 32 | } |
| 33 | |
Jens Axboe | 165125e | 2007-07-24 09:28:11 +0200 | [diff] [blame] | 34 | static void noop_add_request(struct request_queue *q, struct request *rq) |
Tejun Heo | 5a7c47e | 2005-11-10 18:21:30 +0100 | [diff] [blame] | 35 | { |
| 36 | struct noop_data *nd = q->elevator->elevator_data; |
| 37 | |
| 38 | list_add_tail(&rq->queuelist, &nd->queue); |
| 39 | } |
| 40 | |
Jens Axboe | 165125e | 2007-07-24 09:28:11 +0200 | [diff] [blame] | 41 | static int noop_queue_empty(struct request_queue *q) |
Tejun Heo | 5a7c47e | 2005-11-10 18:21:30 +0100 | [diff] [blame] | 42 | { |
| 43 | struct noop_data *nd = q->elevator->elevator_data; |
| 44 | |
| 45 | return list_empty(&nd->queue); |
| 46 | } |
| 47 | |
| 48 | static struct request * |
Jens Axboe | 165125e | 2007-07-24 09:28:11 +0200 | [diff] [blame] | 49 | noop_former_request(struct request_queue *q, struct request *rq) |
Tejun Heo | 5a7c47e | 2005-11-10 18:21:30 +0100 | [diff] [blame] | 50 | { |
| 51 | struct noop_data *nd = q->elevator->elevator_data; |
| 52 | |
| 53 | if (rq->queuelist.prev == &nd->queue) |
| 54 | return NULL; |
| 55 | return list_entry(rq->queuelist.prev, struct request, queuelist); |
| 56 | } |
| 57 | |
| 58 | static struct request * |
Jens Axboe | 165125e | 2007-07-24 09:28:11 +0200 | [diff] [blame] | 59 | noop_latter_request(struct request_queue *q, struct request *rq) |
Tejun Heo | 5a7c47e | 2005-11-10 18:21:30 +0100 | [diff] [blame] | 60 | { |
| 61 | struct noop_data *nd = q->elevator->elevator_data; |
| 62 | |
| 63 | if (rq->queuelist.next == &nd->queue) |
| 64 | return NULL; |
| 65 | return list_entry(rq->queuelist.next, struct request, queuelist); |
| 66 | } |
| 67 | |
Jens Axboe | 165125e | 2007-07-24 09:28:11 +0200 | [diff] [blame] | 68 | static void *noop_init_queue(struct request_queue *q) |
Tejun Heo | 5a7c47e | 2005-11-10 18:21:30 +0100 | [diff] [blame] | 69 | { |
| 70 | struct noop_data *nd; |
| 71 | |
Jens Axboe | b5deef9 | 2006-07-19 23:39:40 +0200 | [diff] [blame] | 72 | nd = kmalloc_node(sizeof(*nd), GFP_KERNEL, q->node); |
Tejun Heo | 5a7c47e | 2005-11-10 18:21:30 +0100 | [diff] [blame] | 73 | if (!nd) |
Jens Axboe | bc1c116 | 2006-06-08 08:49:06 +0200 | [diff] [blame] | 74 | return NULL; |
Tejun Heo | 5a7c47e | 2005-11-10 18:21:30 +0100 | [diff] [blame] | 75 | INIT_LIST_HEAD(&nd->queue); |
Jens Axboe | bc1c116 | 2006-06-08 08:49:06 +0200 | [diff] [blame] | 76 | return nd; |
Tejun Heo | 5a7c47e | 2005-11-10 18:21:30 +0100 | [diff] [blame] | 77 | } |
| 78 | |
| 79 | static void noop_exit_queue(elevator_t *e) |
| 80 | { |
| 81 | struct noop_data *nd = e->elevator_data; |
| 82 | |
| 83 | BUG_ON(!list_empty(&nd->queue)); |
| 84 | kfree(nd); |
| 85 | } |
| 86 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 87 | static struct elevator_type elevator_noop = { |
| 88 | .ops = { |
Tejun Heo | 5a7c47e | 2005-11-10 18:21:30 +0100 | [diff] [blame] | 89 | .elevator_merge_req_fn = noop_merged_requests, |
| 90 | .elevator_dispatch_fn = noop_dispatch, |
| 91 | .elevator_add_req_fn = noop_add_request, |
| 92 | .elevator_queue_empty_fn = noop_queue_empty, |
| 93 | .elevator_former_req_fn = noop_former_request, |
| 94 | .elevator_latter_req_fn = noop_latter_request, |
| 95 | .elevator_init_fn = noop_init_queue, |
| 96 | .elevator_exit_fn = noop_exit_queue, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 97 | }, |
| 98 | .elevator_name = "noop", |
| 99 | .elevator_owner = THIS_MODULE, |
| 100 | }; |
| 101 | |
| 102 | static int __init noop_init(void) |
| 103 | { |
Adrian Bunk | 2fdd82b | 2007-12-12 18:51:56 +0100 | [diff] [blame^] | 104 | elv_register(&elevator_noop); |
| 105 | |
| 106 | return 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 107 | } |
| 108 | |
| 109 | static void __exit noop_exit(void) |
| 110 | { |
| 111 | elv_unregister(&elevator_noop); |
| 112 | } |
| 113 | |
| 114 | module_init(noop_init); |
| 115 | module_exit(noop_exit); |
| 116 | |
| 117 | |
| 118 | MODULE_AUTHOR("Jens Axboe"); |
| 119 | MODULE_LICENSE("GPL"); |
| 120 | MODULE_DESCRIPTION("No-op IO scheduler"); |