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

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

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

20
static int noop_dispatch(struct request_queue *q, int force)
21 22 23 24 25 26 27 28 29 30 31 32 33
{
	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;
}

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

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

41
static int noop_queue_empty(struct request_queue *q)
Linus Torvalds's avatar
Linus Torvalds committed
42
{
43 44 45 46 47 48
	struct noop_data *nd = q->elevator->elevator_data;

	return list_empty(&nd->queue);
}

static struct request *
49
noop_former_request(struct request_queue *q, struct request *rq)
50 51 52 53 54 55 56 57 58
{
	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 *
59
noop_latter_request(struct request_queue *q, struct request *rq)
60 61 62 63 64 65
{
	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);
Linus Torvalds's avatar
Linus Torvalds committed
66 67
}

68
static void *noop_init_queue(struct request_queue *q)
Linus Torvalds's avatar
Linus Torvalds committed
69
{
70 71
	struct noop_data *nd;

72
	nd = kmalloc_node(sizeof(*nd), GFP_KERNEL, q->node);
73
	if (!nd)
Jens Axboe's avatar
Jens Axboe committed
74
		return NULL;
75
	INIT_LIST_HEAD(&nd->queue);
Jens Axboe's avatar
Jens Axboe committed
76
	return nd;
Linus Torvalds's avatar
Linus Torvalds committed
77 78
}

79
static void noop_exit_queue(struct elevator_queue *e)
80 81 82 83 84 85 86
{
	struct noop_data *nd = e->elevator_data;

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

Linus Torvalds's avatar
Linus Torvalds committed
87 88
static struct elevator_type elevator_noop = {
	.ops = {
89 90 91 92 93 94 95 96
		.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,
Linus Torvalds's avatar
Linus Torvalds committed
97 98 99 100 101 102 103
	},
	.elevator_name = "noop",
	.elevator_owner = THIS_MODULE,
};

static int __init noop_init(void)
{
104 105 106
	elv_register(&elevator_noop);

	return 0;
Linus Torvalds's avatar
Linus Torvalds committed
107 108 109 110 111 112 113 114 115 116 117 118 119 120
}

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");