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