linux/block/noop-iosched.c
<<
>>
Prefs
   1/*
   2 * elevator noop
   3 */
   4#include <linux/blkdev.h>
   5#include <linux/elevator.h>
   6#include <linux/bio.h>
   7#include <linux/module.h>
   8#include <linux/slab.h>
   9#include <linux/init.h>
  10
  11struct noop_data {
  12        struct list_head queue;
  13};
  14
  15static void noop_merged_requests(struct request_queue *q, struct request *rq,
  16                                 struct request *next)
  17{
  18        list_del_init(&next->queuelist);
  19}
  20
  21static int noop_dispatch(struct request_queue *q, int force)
  22{
  23        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        }
  32        return 0;
  33}
  34
  35static void noop_add_request(struct request_queue *q, struct request *rq)
  36{
  37        struct noop_data *nd = q->elevator->elevator_data;
  38
  39        list_add_tail(&rq->queuelist, &nd->queue);
  40}
  41
  42static struct request *
  43noop_former_request(struct request_queue *q, struct request *rq)
  44{
  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 *
  53noop_latter_request(struct request_queue *q, struct request *rq)
  54{
  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
  62static void *noop_init_queue(struct request_queue *q)
  63{
  64        struct noop_data *nd;
  65
  66        nd = kmalloc_node(sizeof(*nd), GFP_KERNEL, q->node);
  67        if (!nd)
  68                return NULL;
  69        INIT_LIST_HEAD(&nd->queue);
  70        return nd;
  71}
  72
  73static void noop_exit_queue(struct elevator_queue *e)
  74{
  75        struct noop_data *nd = e->elevator_data;
  76
  77        BUG_ON(!list_empty(&nd->queue));
  78        kfree(nd);
  79}
  80
  81static struct elevator_type elevator_noop = {
  82        .ops = {
  83                .elevator_merge_req_fn          = noop_merged_requests,
  84                .elevator_dispatch_fn           = noop_dispatch,
  85                .elevator_add_req_fn            = noop_add_request,
  86                .elevator_former_req_fn         = noop_former_request,
  87                .elevator_latter_req_fn         = noop_latter_request,
  88                .elevator_init_fn               = noop_init_queue,
  89                .elevator_exit_fn               = noop_exit_queue,
  90        },
  91        .elevator_name = "noop",
  92        .elevator_owner = THIS_MODULE,
  93};
  94
  95static int __init noop_init(void)
  96{
  97        elv_register(&elevator_noop);
  98
  99        return 0;
 100}
 101
 102static void __exit noop_exit(void)
 103{
 104        elv_unregister(&elevator_noop);
 105}
 106
 107module_init(noop_init);
 108module_exit(noop_exit);
 109
 110
 111MODULE_AUTHOR("Jens Axboe");
 112MODULE_LICENSE("GPL");
 113MODULE_DESCRIPTION("No-op IO scheduler");
 114