blob: f65766ef053290ba94c93a5302c891e150284563 [file] [log] [blame]
Linus Torvalds1da177e2005-04-16 15:20:36 -07001#ifndef _LINUX_ELEVATOR_H
2#define _LINUX_ELEVATOR_H
3
4typedef int (elevator_merge_fn) (request_queue_t *, struct request **,
5 struct bio *);
6
7typedef void (elevator_merge_req_fn) (request_queue_t *, struct request *, struct request *);
8
9typedef void (elevator_merged_fn) (request_queue_t *, struct request *);
10
Tejun Heo8922e162005-10-20 16:23:44 +020011typedef int (elevator_dispatch_fn) (request_queue_t *, int);
Linus Torvalds1da177e2005-04-16 15:20:36 -070012
Tejun Heo8922e162005-10-20 16:23:44 +020013typedef void (elevator_add_req_fn) (request_queue_t *, struct request *);
Linus Torvalds1da177e2005-04-16 15:20:36 -070014typedef int (elevator_queue_empty_fn) (request_queue_t *);
Linus Torvalds1da177e2005-04-16 15:20:36 -070015typedef struct request *(elevator_request_list_fn) (request_queue_t *, struct request *);
16typedef void (elevator_completed_req_fn) (request_queue_t *, struct request *);
Jens Axboe22e2c502005-06-27 10:55:12 +020017typedef int (elevator_may_queue_fn) (request_queue_t *, int, struct bio *);
Linus Torvalds1da177e2005-04-16 15:20:36 -070018
Al Viro8267e262005-10-21 03:20:53 -040019typedef int (elevator_set_req_fn) (request_queue_t *, struct request *, struct bio *, gfp_t);
Linus Torvalds1da177e2005-04-16 15:20:36 -070020typedef void (elevator_put_req_fn) (request_queue_t *, struct request *);
Tejun Heo8922e162005-10-20 16:23:44 +020021typedef void (elevator_activate_req_fn) (request_queue_t *, struct request *);
Linus Torvalds1da177e2005-04-16 15:20:36 -070022typedef void (elevator_deactivate_req_fn) (request_queue_t *, struct request *);
23
24typedef int (elevator_init_fn) (request_queue_t *, elevator_t *);
25typedef void (elevator_exit_fn) (elevator_t *);
26
27struct elevator_ops
28{
29 elevator_merge_fn *elevator_merge_fn;
30 elevator_merged_fn *elevator_merged_fn;
31 elevator_merge_req_fn *elevator_merge_req_fn;
32
Tejun Heo8922e162005-10-20 16:23:44 +020033 elevator_dispatch_fn *elevator_dispatch_fn;
Linus Torvalds1da177e2005-04-16 15:20:36 -070034 elevator_add_req_fn *elevator_add_req_fn;
Tejun Heo8922e162005-10-20 16:23:44 +020035 elevator_activate_req_fn *elevator_activate_req_fn;
Linus Torvalds1da177e2005-04-16 15:20:36 -070036 elevator_deactivate_req_fn *elevator_deactivate_req_fn;
37
38 elevator_queue_empty_fn *elevator_queue_empty_fn;
39 elevator_completed_req_fn *elevator_completed_req_fn;
40
41 elevator_request_list_fn *elevator_former_req_fn;
42 elevator_request_list_fn *elevator_latter_req_fn;
43
44 elevator_set_req_fn *elevator_set_req_fn;
45 elevator_put_req_fn *elevator_put_req_fn;
46
47 elevator_may_queue_fn *elevator_may_queue_fn;
48
49 elevator_init_fn *elevator_init_fn;
50 elevator_exit_fn *elevator_exit_fn;
Al Viroe17a9482006-03-18 13:21:20 -050051 void (*trim)(struct io_context *);
Linus Torvalds1da177e2005-04-16 15:20:36 -070052};
53
54#define ELV_NAME_MAX (16)
55
56/*
57 * identifies an elevator type, such as AS or deadline
58 */
59struct elevator_type
60{
61 struct list_head list;
62 struct elevator_ops ops;
63 struct elevator_type *elevator_type;
64 struct kobj_type *elevator_ktype;
65 char elevator_name[ELV_NAME_MAX];
66 struct module *elevator_owner;
67};
68
69/*
Adrian Bunk54069582006-01-10 00:09:36 +010070 * each queue has an elevator_queue associated with it
Linus Torvalds1da177e2005-04-16 15:20:36 -070071 */
72struct elevator_queue
73{
74 struct elevator_ops *ops;
75 void *elevator_data;
76 struct kobject kobj;
77 struct elevator_type *elevator_type;
78};
79
80/*
81 * block elevator interface
82 */
Jens Axboe1b47f532005-10-20 16:37:00 +020083extern void elv_dispatch_sort(request_queue_t *, struct request *);
Linus Torvalds1da177e2005-04-16 15:20:36 -070084extern void elv_add_request(request_queue_t *, struct request *, int, int);
85extern void __elv_add_request(request_queue_t *, struct request *, int, int);
Tejun Heo30e96562006-02-08 01:01:31 -080086extern void elv_insert(request_queue_t *, struct request *, int);
Linus Torvalds1da177e2005-04-16 15:20:36 -070087extern int elv_merge(request_queue_t *, struct request **, struct bio *);
88extern void elv_merge_requests(request_queue_t *, struct request *,
89 struct request *);
90extern void elv_merged_request(request_queue_t *, struct request *);
Tejun Heo8922e162005-10-20 16:23:44 +020091extern void elv_dequeue_request(request_queue_t *, struct request *);
Linus Torvalds1da177e2005-04-16 15:20:36 -070092extern void elv_requeue_request(request_queue_t *, struct request *);
Linus Torvalds1da177e2005-04-16 15:20:36 -070093extern int elv_queue_empty(request_queue_t *);
94extern struct request *elv_next_request(struct request_queue *q);
95extern struct request *elv_former_request(request_queue_t *, struct request *);
96extern struct request *elv_latter_request(request_queue_t *, struct request *);
97extern int elv_register_queue(request_queue_t *q);
98extern void elv_unregister_queue(request_queue_t *q);
Jens Axboe22e2c502005-06-27 10:55:12 +020099extern int elv_may_queue(request_queue_t *, int, struct bio *);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700100extern void elv_completed_request(request_queue_t *, struct request *);
Al Viro8267e262005-10-21 03:20:53 -0400101extern int elv_set_request(request_queue_t *, struct request *, struct bio *, gfp_t);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700102extern void elv_put_request(request_queue_t *, struct request *);
103
104/*
105 * io scheduler registration
106 */
107extern int elv_register(struct elevator_type *);
108extern void elv_unregister(struct elevator_type *);
109
110/*
111 * io scheduler sysfs switching
112 */
113extern ssize_t elv_iosched_show(request_queue_t *, char *);
114extern ssize_t elv_iosched_store(request_queue_t *, const char *, size_t);
115
116extern int elevator_init(request_queue_t *, char *);
117extern void elevator_exit(elevator_t *);
118extern int elv_rq_merge_ok(struct request *, struct bio *);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700119
120/*
121 * Return values from elevator merger
122 */
123#define ELEVATOR_NO_MERGE 0
124#define ELEVATOR_FRONT_MERGE 1
125#define ELEVATOR_BACK_MERGE 2
126
127/*
128 * Insertion selection
129 */
130#define ELEVATOR_INSERT_FRONT 1
131#define ELEVATOR_INSERT_BACK 2
132#define ELEVATOR_INSERT_SORT 3
Tejun Heo797e7db2006-01-06 09:51:03 +0100133#define ELEVATOR_INSERT_REQUEUE 4
Linus Torvalds1da177e2005-04-16 15:20:36 -0700134
135/*
136 * return values from elevator_may_queue_fn
137 */
138enum {
139 ELV_MQUEUE_MAY,
140 ELV_MQUEUE_NO,
141 ELV_MQUEUE_MUST,
142};
143
Jens Axboe1b47f532005-10-20 16:37:00 +0200144#define rq_end_sector(rq) ((rq)->sector + (rq)->nr_sectors)
145
Linus Torvalds1da177e2005-04-16 15:20:36 -0700146#endif