noop-iosched.c 2.61 KB
Newer Older
Linus Torvalds's avatar
Linus Torvalds committed
1 2 3 4 5 6 7
/*
 * elevator noop
 */
#include <linux/blkdev.h>
#include <linux/elevator.h>
#include <linux/bio.h>
#include <linux/module.h>
8
#include <linux/slab.h>
Linus Torvalds's avatar
Linus Torvalds committed
9 10
#include <linux/init.h>

11 12 13 14
struct noop_data {
	struct list_head queue;
};

15
static void noop_merged_requests(struct request_queue *q, struct request *rq,
16 17 18 19 20
				 struct request *next)
{
	list_del_init(&next->queuelist);
}

21
static int noop_dispatch(struct request_queue *q, int force)
22 23
{
	struct noop_data *nd = q->elevator->elevator_data;
24
	struct request *rq;
25

26 27
	rq = list_first_entry_or_null(&nd->queue, struct request, queuelist);
	if (rq) {
28 29 30 31 32 33 34
		list_del_init(&rq->queuelist);
		elv_dispatch_sort(q, rq);
		return 1;
	}
	return 0;
}

35
static void noop_add_request(struct request_queue *q, struct request *rq)
36 37 38 39 40 41 42
{
	struct noop_data *nd = q->elevator->elevator_data;

	list_add_tail(&rq->queuelist, &nd->queue);
}

static struct request *
43
noop_former_request(struct request_queue *q, struct request *rq)
44 45 46 47 48
{
	struct noop_data *nd = q->elevator->elevator_data;

	if (rq->queuelist.prev == &nd->queue)
		return NULL;
49
	return list_prev_entry(rq, queuelist);
50 51 52
}

static struct request *
53
noop_latter_request(struct request_queue *q, struct request *rq)
54 55 56 57 58
{
	struct noop_data *nd = q->elevator->elevator_data;

	if (rq->queuelist.next == &nd->queue)
		return NULL;
59
	return list_next_entry(rq, queuelist);
Linus Torvalds's avatar
Linus Torvalds committed
60 61
}

62
static int noop_init_queue(struct request_queue *q, struct elevator_type *e)
Linus Torvalds's avatar
Linus Torvalds committed
63
{
64
	struct noop_data *nd;
65 66 67 68 69
	struct elevator_queue *eq;

	eq = elevator_alloc(q, e);
	if (!eq)
		return -ENOMEM;
70

71
	nd = kmalloc_node(sizeof(*nd), GFP_KERNEL, q->node);
72 73
	if (!nd) {
		kobject_put(&eq->kobj);
74
		return -ENOMEM;
75 76
	}
	eq->elevator_data = nd;
77

78
	INIT_LIST_HEAD(&nd->queue);
79 80 81 82

	spin_lock_irq(q->queue_lock);
	q->elevator = eq;
	spin_unlock_irq(q->queue_lock);
83
	return 0;
Linus Torvalds's avatar
Linus Torvalds committed
84 85
}

86
static void noop_exit_queue(struct elevator_queue *e)
87 88 89 90 91 92 93
{
	struct noop_data *nd = e->elevator_data;

	BUG_ON(!list_empty(&nd->queue));
	kfree(nd);
}

Linus Torvalds's avatar
Linus Torvalds committed
94
static struct elevator_type elevator_noop = {
95
	.ops.sq = {
96 97 98 99 100 101 102
		.elevator_merge_req_fn		= noop_merged_requests,
		.elevator_dispatch_fn		= noop_dispatch,
		.elevator_add_req_fn		= noop_add_request,
		.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,
Linus Torvalds's avatar
Linus Torvalds committed
103 104 105 106 107 108 109
	},
	.elevator_name = "noop",
	.elevator_owner = THIS_MODULE,
};

static int __init noop_init(void)
{
110
	return elv_register(&elevator_noop);
Linus Torvalds's avatar
Linus Torvalds committed
111 112 113 114 115 116 117 118 119 120 121 122 123 124
}

static void __exit noop_exit(void)
{
	elv_unregister(&elevator_noop);
}

module_init(noop_init);
module_exit(noop_exit);


MODULE_AUTHOR("Jens Axboe");
MODULE_LICENSE("GPL");
MODULE_DESCRIPTION("No-op IO scheduler");