blob: f370e4a7fe6d7a26e66f988774c002af6b772725 [file] [log] [blame]
Linus Torvalds1da177e2005-04-16 15:20:36 -07001/*
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 Heo5a7c47e2005-11-10 18:21:30 +010010struct noop_data {
11 struct list_head queue;
12};
13
14static void noop_merged_requests(request_queue_t *q, struct request *rq,
15 struct request *next)
Linus Torvalds1da177e2005-04-16 15:20:36 -070016{
Tejun Heo5a7c47e2005-11-10 18:21:30 +010017 list_del_init(&next->queuelist);
Linus Torvalds1da177e2005-04-16 15:20:36 -070018}
19
Tejun Heo5a7c47e2005-11-10 18:21:30 +010020static int noop_dispatch(request_queue_t *q, int force)
Linus Torvalds1da177e2005-04-16 15:20:36 -070021{
Tejun Heo5a7c47e2005-11-10 18:21:30 +010022 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 Axboeb4878f22005-10-20 16:42:29 +020031 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -070032}
33
Tejun Heo5a7c47e2005-11-10 18:21:30 +010034static void noop_add_request(request_queue_t *q, struct request *rq)
35{
36 struct noop_data *nd = q->elevator->elevator_data;
37
38 list_add_tail(&rq->queuelist, &nd->queue);
39}
40
41static int noop_queue_empty(request_queue_t *q)
42{
43 struct noop_data *nd = q->elevator->elevator_data;
44
45 return list_empty(&nd->queue);
46}
47
48static struct request *
49noop_former_request(request_queue_t *q, struct request *rq)
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
58static struct request *
59noop_latter_request(request_queue_t *q, struct request *rq)
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
68static int noop_init_queue(request_queue_t *q, elevator_t *e)
69{
70 struct noop_data *nd;
71
72 nd = kmalloc(sizeof(*nd), GFP_KERNEL);
73 if (!nd)
74 return -ENOMEM;
75 INIT_LIST_HEAD(&nd->queue);
76 e->elevator_data = nd;
77 return 0;
78}
79
80static void noop_exit_queue(elevator_t *e)
81{
82 struct noop_data *nd = e->elevator_data;
83
84 BUG_ON(!list_empty(&nd->queue));
85 kfree(nd);
86}
87
Linus Torvalds1da177e2005-04-16 15:20:36 -070088static struct elevator_type elevator_noop = {
89 .ops = {
Tejun Heo5a7c47e2005-11-10 18:21:30 +010090 .elevator_merge_req_fn = noop_merged_requests,
91 .elevator_dispatch_fn = noop_dispatch,
92 .elevator_add_req_fn = noop_add_request,
93 .elevator_queue_empty_fn = noop_queue_empty,
94 .elevator_former_req_fn = noop_former_request,
95 .elevator_latter_req_fn = noop_latter_request,
96 .elevator_init_fn = noop_init_queue,
97 .elevator_exit_fn = noop_exit_queue,
Linus Torvalds1da177e2005-04-16 15:20:36 -070098 },
99 .elevator_name = "noop",
100 .elevator_owner = THIS_MODULE,
101};
102
103static int __init noop_init(void)
104{
105 return elv_register(&elevator_noop);
106}
107
108static void __exit noop_exit(void)
109{
110 elv_unregister(&elevator_noop);
111}
112
113module_init(noop_init);
114module_exit(noop_exit);
115
116
117MODULE_AUTHOR("Jens Axboe");
118MODULE_LICENSE("GPL");
119MODULE_DESCRIPTION("No-op IO scheduler");