blob: 232c4b38cd3769d31e0c79700a49f42915c683a6 [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>
Tejun Heo5a0e3ad2010-03-24 17:04:11 +09008#include <linux/slab.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -07009#include <linux/init.h>
10
Tejun Heo5a7c47e2005-11-10 18:21:30 +010011struct noop_data {
12 struct list_head queue;
13};
14
Jens Axboe165125e2007-07-24 09:28:11 +020015static void noop_merged_requests(struct request_queue *q, struct request *rq,
Tejun Heo5a7c47e2005-11-10 18:21:30 +010016 struct request *next)
Linus Torvalds1da177e2005-04-16 15:20:36 -070017{
Tejun Heo5a7c47e2005-11-10 18:21:30 +010018 list_del_init(&next->queuelist);
Linus Torvalds1da177e2005-04-16 15:20:36 -070019}
20
Jens Axboe165125e2007-07-24 09:28:11 +020021static int noop_dispatch(struct request_queue *q, int force)
Linus Torvalds1da177e2005-04-16 15:20:36 -070022{
Tejun Heo5a7c47e2005-11-10 18:21:30 +010023 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 Axboeb4878f22005-10-20 16:42:29 +020032 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -070033}
34
Jens Axboe165125e2007-07-24 09:28:11 +020035static void noop_add_request(struct request_queue *q, struct request *rq)
Tejun Heo5a7c47e2005-11-10 18:21:30 +010036{
37 struct noop_data *nd = q->elevator->elevator_data;
38
39 list_add_tail(&rq->queuelist, &nd->queue);
40}
41
Jens Axboe165125e2007-07-24 09:28:11 +020042static int noop_queue_empty(struct request_queue *q)
Tejun Heo5a7c47e2005-11-10 18:21:30 +010043{
44 struct noop_data *nd = q->elevator->elevator_data;
45
46 return list_empty(&nd->queue);
47}
48
49static struct request *
Jens Axboe165125e2007-07-24 09:28:11 +020050noop_former_request(struct request_queue *q, struct request *rq)
Tejun Heo5a7c47e2005-11-10 18:21:30 +010051{
52 struct noop_data *nd = q->elevator->elevator_data;
53
54 if (rq->queuelist.prev == &nd->queue)
55 return NULL;
56 return list_entry(rq->queuelist.prev, struct request, queuelist);
57}
58
59static struct request *
Jens Axboe165125e2007-07-24 09:28:11 +020060noop_latter_request(struct request_queue *q, struct request *rq)
Tejun Heo5a7c47e2005-11-10 18:21:30 +010061{
62 struct noop_data *nd = q->elevator->elevator_data;
63
64 if (rq->queuelist.next == &nd->queue)
65 return NULL;
66 return list_entry(rq->queuelist.next, struct request, queuelist);
67}
68
Jens Axboe165125e2007-07-24 09:28:11 +020069static void *noop_init_queue(struct request_queue *q)
Tejun Heo5a7c47e2005-11-10 18:21:30 +010070{
71 struct noop_data *nd;
72
Jens Axboeb5deef92006-07-19 23:39:40 +020073 nd = kmalloc_node(sizeof(*nd), GFP_KERNEL, q->node);
Tejun Heo5a7c47e2005-11-10 18:21:30 +010074 if (!nd)
Jens Axboebc1c1162006-06-08 08:49:06 +020075 return NULL;
Tejun Heo5a7c47e2005-11-10 18:21:30 +010076 INIT_LIST_HEAD(&nd->queue);
Jens Axboebc1c1162006-06-08 08:49:06 +020077 return nd;
Tejun Heo5a7c47e2005-11-10 18:21:30 +010078}
79
Jens Axboeb374d182008-10-31 10:05:07 +010080static void noop_exit_queue(struct elevator_queue *e)
Tejun Heo5a7c47e2005-11-10 18:21:30 +010081{
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{
Adrian Bunk2fdd82b2007-12-12 18:51:56 +0100105 elv_register(&elevator_noop);
106
107 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700108}
109
110static void __exit noop_exit(void)
111{
112 elv_unregister(&elevator_noop);
113}
114
115module_init(noop_init);
116module_exit(noop_exit);
117
118
119MODULE_AUTHOR("Jens Axboe");
120MODULE_LICENSE("GPL");
121MODULE_DESCRIPTION("No-op IO scheduler");