blob: 3de89d4690f3bf3e0d9abec1976a379b5dc171e5 [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
Tejun Heo5a7c47e2005-11-10 18:21:30 +010042static struct request *
Jens Axboe165125e2007-07-24 09:28:11 +020043noop_former_request(struct request_queue *q, struct request *rq)
Tejun Heo5a7c47e2005-11-10 18:21:30 +010044{
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
52static struct request *
Jens Axboe165125e2007-07-24 09:28:11 +020053noop_latter_request(struct request_queue *q, struct request *rq)
Tejun Heo5a7c47e2005-11-10 18:21:30 +010054{
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
Jianpeng Mad50235b2013-07-03 13:25:24 +020062static int noop_init_queue(struct request_queue *q, struct elevator_type *e)
Tejun Heo5a7c47e2005-11-10 18:21:30 +010063{
64 struct noop_data *nd;
Jianpeng Mad50235b2013-07-03 13:25:24 +020065 struct elevator_queue *eq;
Tejun Heo5a7c47e2005-11-10 18:21:30 +010066
Jianpeng Mad50235b2013-07-03 13:25:24 +020067 eq = elevator_alloc(q, e);
68 if (!eq)
Tejun Heob2fab5a2012-03-05 13:14:57 -080069 return -ENOMEM;
70
Jianpeng Mad50235b2013-07-03 13:25:24 +020071 nd = kmalloc_node(sizeof(*nd), GFP_KERNEL, q->node);
72 if (!nd) {
73 kobject_put(&eq->kobj);
74 return -ENOMEM;
75 }
76 eq->elevator_data = nd;
77
Tejun Heo5a7c47e2005-11-10 18:21:30 +010078 INIT_LIST_HEAD(&nd->queue);
Jianpeng Mad50235b2013-07-03 13:25:24 +020079
80 spin_lock_irq(q->queue_lock);
81 q->elevator = eq;
82 spin_unlock_irq(q->queue_lock);
Tejun Heob2fab5a2012-03-05 13:14:57 -080083 return 0;
Tejun Heo5a7c47e2005-11-10 18:21:30 +010084}
85
Jens Axboeb374d182008-10-31 10:05:07 +010086static void noop_exit_queue(struct elevator_queue *e)
Tejun Heo5a7c47e2005-11-10 18:21:30 +010087{
88 struct noop_data *nd = e->elevator_data;
89
90 BUG_ON(!list_empty(&nd->queue));
91 kfree(nd);
92}
93
Linus Torvalds1da177e2005-04-16 15:20:36 -070094static struct elevator_type elevator_noop = {
95 .ops = {
Tejun Heo5a7c47e2005-11-10 18:21:30 +010096 .elevator_merge_req_fn = noop_merged_requests,
97 .elevator_dispatch_fn = noop_dispatch,
98 .elevator_add_req_fn = noop_add_request,
Tejun Heo5a7c47e2005-11-10 18:21:30 +010099 .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,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700103 },
104 .elevator_name = "noop",
105 .elevator_owner = THIS_MODULE,
106};
107
108static int __init noop_init(void)
109{
Tejun Heo3d3c2372011-12-14 00:33:42 +0100110 return elv_register(&elevator_noop);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700111}
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");