Merge branch 'topic/msnd' into for-linus
[linux-2.6.git] / block / noop-iosched.c
index e54f006..3a0d369 100644 (file)
@@ -7,21 +7,93 @@
 #include <linux/module.h>
 #include <linux/init.h>
 
-static void elevator_noop_add_request(request_queue_t *q, struct request *rq)
+struct noop_data {
+       struct list_head queue;
+};
+
+static void noop_merged_requests(struct request_queue *q, struct request *rq,
+                                struct request *next)
 {
-       rq->flags |= REQ_NOMERGE;
-       elv_dispatch_add_tail(q, rq);
+       list_del_init(&next->queuelist);
 }
 
-static int elevator_noop_dispatch(request_queue_t *q, int force)
+static int noop_dispatch(struct request_queue *q, int force)
 {
+       struct noop_data *nd = q->elevator->elevator_data;
+
+       if (!list_empty(&nd->queue)) {
+               struct request *rq;
+               rq = list_entry(nd->queue.next, struct request, queuelist);
+               list_del_init(&rq->queuelist);
+               elv_dispatch_sort(q, rq);
+               return 1;
+       }
        return 0;
 }
 
+static void noop_add_request(struct request_queue *q, struct request *rq)
+{
+       struct noop_data *nd = q->elevator->elevator_data;
+
+       list_add_tail(&rq->queuelist, &nd->queue);
+}
+
+static int noop_queue_empty(struct request_queue *q)
+{
+       struct noop_data *nd = q->elevator->elevator_data;
+
+       return list_empty(&nd->queue);
+}
+
+static struct request *
+noop_former_request(struct request_queue *q, struct request *rq)
+{
+       struct noop_data *nd = q->elevator->elevator_data;
+
+       if (rq->queuelist.prev == &nd->queue)
+               return NULL;
+       return list_entry(rq->queuelist.prev, struct request, queuelist);
+}
+
+static struct request *
+noop_latter_request(struct request_queue *q, struct request *rq)
+{
+       struct noop_data *nd = q->elevator->elevator_data;
+
+       if (rq->queuelist.next == &nd->queue)
+               return NULL;
+       return list_entry(rq->queuelist.next, struct request, queuelist);
+}
+
+static void *noop_init_queue(struct request_queue *q)
+{
+       struct noop_data *nd;
+
+       nd = kmalloc_node(sizeof(*nd), GFP_KERNEL, q->node);
+       if (!nd)
+               return NULL;
+       INIT_LIST_HEAD(&nd->queue);
+       return nd;
+}
+
+static void noop_exit_queue(struct elevator_queue *e)
+{
+       struct noop_data *nd = e->elevator_data;
+
+       BUG_ON(!list_empty(&nd->queue));
+       kfree(nd);
+}
+
 static struct elevator_type elevator_noop = {
        .ops = {
-               .elevator_dispatch_fn           = elevator_noop_dispatch,
-               .elevator_add_req_fn            = elevator_noop_add_request,
+               .elevator_merge_req_fn          = noop_merged_requests,
+               .elevator_dispatch_fn           = noop_dispatch,
+               .elevator_add_req_fn            = noop_add_request,
+               .elevator_queue_empty_fn        = noop_queue_empty,
+               .elevator_former_req_fn         = noop_former_request,
+               .elevator_latter_req_fn         = noop_latter_request,
+               .elevator_init_fn               = noop_init_queue,
+               .elevator_exit_fn               = noop_exit_queue,
        },
        .elevator_name = "noop",
        .elevator_owner = THIS_MODULE,
@@ -29,7 +101,9 @@ static struct elevator_type elevator_noop = {
 
 static int __init noop_init(void)
 {
-       return elv_register(&elevator_noop);
+       elv_register(&elevator_noop);
+
+       return 0;
 }
 
 static void __exit noop_exit(void)