4 #include <linux/blkdev.h>
5 #include <linux/elevator.h>
7 #include <linux/module.h>
8 #include <linux/slab.h>
9 #include <linux/init.h>
12 struct list_head queue
;
15 static void noop_merged_requests(struct request_queue
*q
, struct request
*rq
,
18 list_del_init(&next
->queuelist
);
21 static int noop_dispatch(struct request_queue
*q
, int force
)
23 struct noop_data
*nd
= q
->elevator
->elevator_data
;
25 if (!list_empty(&nd
->queue
)) {
27 rq
= list_entry(nd
->queue
.next
, struct request
, queuelist
);
28 list_del_init(&rq
->queuelist
);
29 elv_dispatch_sort(q
, rq
);
35 static void noop_add_request(struct request_queue
*q
, struct request
*rq
)
37 struct noop_data
*nd
= q
->elevator
->elevator_data
;
39 list_add_tail(&rq
->queuelist
, &nd
->queue
);
42 static int noop_queue_empty(struct request_queue
*q
)
44 struct noop_data
*nd
= q
->elevator
->elevator_data
;
46 return list_empty(&nd
->queue
);
49 static struct request
*
50 noop_former_request(struct request_queue
*q
, struct request
*rq
)
52 struct noop_data
*nd
= q
->elevator
->elevator_data
;
54 if (rq
->queuelist
.prev
== &nd
->queue
)
56 return list_entry(rq
->queuelist
.prev
, struct request
, queuelist
);
59 static struct request
*
60 noop_latter_request(struct request_queue
*q
, struct request
*rq
)
62 struct noop_data
*nd
= q
->elevator
->elevator_data
;
64 if (rq
->queuelist
.next
== &nd
->queue
)
66 return list_entry(rq
->queuelist
.next
, struct request
, queuelist
);
69 static void *noop_init_queue(struct request_queue
*q
)
73 nd
= kmalloc_node(sizeof(*nd
), GFP_KERNEL
, q
->node
);
76 INIT_LIST_HEAD(&nd
->queue
);
80 static void noop_exit_queue(struct elevator_queue
*e
)
82 struct noop_data
*nd
= e
->elevator_data
;
84 BUG_ON(!list_empty(&nd
->queue
));
88 static struct elevator_type elevator_noop
= {
90 .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
,
99 .elevator_name
= "noop",
100 .elevator_owner
= THIS_MODULE
,
103 static int __init
noop_init(void)
105 elv_register(&elevator_noop
);
110 static void __exit
noop_exit(void)
112 elv_unregister(&elevator_noop
);
115 module_init(noop_init
);
116 module_exit(noop_exit
);
119 MODULE_AUTHOR("Jens Axboe");
120 MODULE_LICENSE("GPL");
121 MODULE_DESCRIPTION("No-op IO scheduler");