Back to home page

LXR

 
 

    


0001 /*
0002  * elevator noop
0003  */
0004 #include <linux/blkdev.h>
0005 #include <linux/elevator.h>
0006 #include <linux/bio.h>
0007 #include <linux/module.h>
0008 #include <linux/slab.h>
0009 #include <linux/init.h>
0010 
0011 struct noop_data {
0012     struct list_head queue;
0013 };
0014 
0015 static void noop_merged_requests(struct request_queue *q, struct request *rq,
0016                  struct request *next)
0017 {
0018     list_del_init(&next->queuelist);
0019 }
0020 
0021 static int noop_dispatch(struct request_queue *q, int force)
0022 {
0023     struct noop_data *nd = q->elevator->elevator_data;
0024     struct request *rq;
0025 
0026     rq = list_first_entry_or_null(&nd->queue, struct request, queuelist);
0027     if (rq) {
0028         list_del_init(&rq->queuelist);
0029         elv_dispatch_sort(q, rq);
0030         return 1;
0031     }
0032     return 0;
0033 }
0034 
0035 static void noop_add_request(struct request_queue *q, struct request *rq)
0036 {
0037     struct noop_data *nd = q->elevator->elevator_data;
0038 
0039     list_add_tail(&rq->queuelist, &nd->queue);
0040 }
0041 
0042 static struct request *
0043 noop_former_request(struct request_queue *q, struct request *rq)
0044 {
0045     struct noop_data *nd = q->elevator->elevator_data;
0046 
0047     if (rq->queuelist.prev == &nd->queue)
0048         return NULL;
0049     return list_prev_entry(rq, queuelist);
0050 }
0051 
0052 static struct request *
0053 noop_latter_request(struct request_queue *q, struct request *rq)
0054 {
0055     struct noop_data *nd = q->elevator->elevator_data;
0056 
0057     if (rq->queuelist.next == &nd->queue)
0058         return NULL;
0059     return list_next_entry(rq, queuelist);
0060 }
0061 
0062 static int noop_init_queue(struct request_queue *q, struct elevator_type *e)
0063 {
0064     struct noop_data *nd;
0065     struct elevator_queue *eq;
0066 
0067     eq = elevator_alloc(q, e);
0068     if (!eq)
0069         return -ENOMEM;
0070 
0071     nd = kmalloc_node(sizeof(*nd), GFP_KERNEL, q->node);
0072     if (!nd) {
0073         kobject_put(&eq->kobj);
0074         return -ENOMEM;
0075     }
0076     eq->elevator_data = nd;
0077 
0078     INIT_LIST_HEAD(&nd->queue);
0079 
0080     spin_lock_irq(q->queue_lock);
0081     q->elevator = eq;
0082     spin_unlock_irq(q->queue_lock);
0083     return 0;
0084 }
0085 
0086 static void noop_exit_queue(struct elevator_queue *e)
0087 {
0088     struct noop_data *nd = e->elevator_data;
0089 
0090     BUG_ON(!list_empty(&nd->queue));
0091     kfree(nd);
0092 }
0093 
0094 static struct elevator_type elevator_noop = {
0095     .ops = {
0096         .elevator_merge_req_fn      = noop_merged_requests,
0097         .elevator_dispatch_fn       = noop_dispatch,
0098         .elevator_add_req_fn        = noop_add_request,
0099         .elevator_former_req_fn     = noop_former_request,
0100         .elevator_latter_req_fn     = noop_latter_request,
0101         .elevator_init_fn       = noop_init_queue,
0102         .elevator_exit_fn       = noop_exit_queue,
0103     },
0104     .elevator_name = "noop",
0105     .elevator_owner = THIS_MODULE,
0106 };
0107 
0108 static int __init noop_init(void)
0109 {
0110     return elv_register(&elevator_noop);
0111 }
0112 
0113 static void __exit noop_exit(void)
0114 {
0115     elv_unregister(&elevator_noop);
0116 }
0117 
0118 module_init(noop_init);
0119 module_exit(noop_exit);
0120 
0121 
0122 MODULE_AUTHOR("Jens Axboe");
0123 MODULE_LICENSE("GPL");
0124 MODULE_DESCRIPTION("No-op IO scheduler");