Merge tag 'metag-for-v4.9-rc1' of git://git.kernel.org/pub/scm/linux/kernel/git/jhoga...
[linux-2.6-block.git] / block / noop-iosched.c
CommitLineData
1da177e4
LT
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>
5a0e3ad6 8#include <linux/slab.h>
1da177e4
LT
9#include <linux/init.h>
10
5a7c47ee
TH
11struct noop_data {
12 struct list_head queue;
13};
14
165125e1 15static void noop_merged_requests(struct request_queue *q, struct request *rq,
5a7c47ee
TH
16 struct request *next)
17{
18 list_del_init(&next->queuelist);
19}
20
165125e1 21static int noop_dispatch(struct request_queue *q, int force)
5a7c47ee
TH
22{
23 struct noop_data *nd = q->elevator->elevator_data;
4736346b 24 struct request *rq;
5a7c47ee 25
4736346b
GT
26 rq = list_first_entry_or_null(&nd->queue, struct request, queuelist);
27 if (rq) {
5a7c47ee
TH
28 list_del_init(&rq->queuelist);
29 elv_dispatch_sort(q, rq);
30 return 1;
31 }
32 return 0;
33}
34
165125e1 35static void noop_add_request(struct request_queue *q, struct request *rq)
5a7c47ee
TH
36{
37 struct noop_data *nd = q->elevator->elevator_data;
38
39 list_add_tail(&rq->queuelist, &nd->queue);
40}
41
5a7c47ee 42static struct request *
165125e1 43noop_former_request(struct request_queue *q, struct request *rq)
5a7c47ee
TH
44{
45 struct noop_data *nd = q->elevator->elevator_data;
46
47 if (rq->queuelist.prev == &nd->queue)
48 return NULL;
4736346b 49 return list_prev_entry(rq, queuelist);
5a7c47ee
TH
50}
51
52static struct request *
165125e1 53noop_latter_request(struct request_queue *q, struct request *rq)
5a7c47ee
TH
54{
55 struct noop_data *nd = q->elevator->elevator_data;
56
57 if (rq->queuelist.next == &nd->queue)
58 return NULL;
4736346b 59 return list_next_entry(rq, queuelist);
1da177e4
LT
60}
61
d50235b7 62static int noop_init_queue(struct request_queue *q, struct elevator_type *e)
1da177e4 63{
5a7c47ee 64 struct noop_data *nd;
d50235b7
JM
65 struct elevator_queue *eq;
66
67 eq = elevator_alloc(q, e);
68 if (!eq)
69 return -ENOMEM;
5a7c47ee 70
b5deef90 71 nd = kmalloc_node(sizeof(*nd), GFP_KERNEL, q->node);
d50235b7
JM
72 if (!nd) {
73 kobject_put(&eq->kobj);
b2fab5ac 74 return -ENOMEM;
d50235b7
JM
75 }
76 eq->elevator_data = nd;
b2fab5ac 77
5a7c47ee 78 INIT_LIST_HEAD(&nd->queue);
d50235b7
JM
79
80 spin_lock_irq(q->queue_lock);
81 q->elevator = eq;
82 spin_unlock_irq(q->queue_lock);
b2fab5ac 83 return 0;
1da177e4
LT
84}
85
b374d18a 86static void noop_exit_queue(struct elevator_queue *e)
5a7c47ee
TH
87{
88 struct noop_data *nd = e->elevator_data;
89
90 BUG_ON(!list_empty(&nd->queue));
91 kfree(nd);
92}
93
1da177e4
LT
94static struct elevator_type elevator_noop = {
95 .ops = {
5a7c47ee
TH
96 .elevator_merge_req_fn = noop_merged_requests,
97 .elevator_dispatch_fn = noop_dispatch,
98 .elevator_add_req_fn = noop_add_request,
5a7c47ee
TH
99 .elevator_former_req_fn = noop_former_request,
100 .elevator_latter_req_fn = noop_latter_request,
101 .elevator_init_fn = noop_init_queue,
102 .elevator_exit_fn = noop_exit_queue,
1da177e4
LT
103 },
104 .elevator_name = "noop",
105 .elevator_owner = THIS_MODULE,
106};
107
108static int __init noop_init(void)
109{
3d3c2379 110 return elv_register(&elevator_noop);
1da177e4
LT
111}
112
113static void __exit noop_exit(void)
114{
115 elv_unregister(&elevator_noop);
116}
117
118module_init(noop_init);
119module_exit(noop_exit);
120
121
122MODULE_AUTHOR("Jens Axboe");
123MODULE_LICENSE("GPL");
124MODULE_DESCRIPTION("No-op IO scheduler");