elevator.h 6.7 KB
Newer Older
L
Linus Torvalds 已提交
1 2 3
#ifndef _LINUX_ELEVATOR_H
#define _LINUX_ELEVATOR_H

4 5
#include <linux/percpu.h>

6 7
#ifdef CONFIG_BLOCK

8
typedef int (elevator_merge_fn) (struct request_queue *, struct request **,
L
Linus Torvalds 已提交
9 10
				 struct bio *);

11
typedef void (elevator_merge_req_fn) (struct request_queue *, struct request *, struct request *);
L
Linus Torvalds 已提交
12

13
typedef void (elevator_merged_fn) (struct request_queue *, struct request *, int);
L
Linus Torvalds 已提交
14

15
typedef int (elevator_allow_merge_fn) (struct request_queue *, struct request *, struct bio *);
16

17
typedef int (elevator_dispatch_fn) (struct request_queue *, int);
L
Linus Torvalds 已提交
18

19 20 21 22 23
typedef void (elevator_add_req_fn) (struct request_queue *, struct request *);
typedef int (elevator_queue_empty_fn) (struct request_queue *);
typedef struct request *(elevator_request_list_fn) (struct request_queue *, struct request *);
typedef void (elevator_completed_req_fn) (struct request_queue *, struct request *);
typedef int (elevator_may_queue_fn) (struct request_queue *, int);
L
Linus Torvalds 已提交
24

25
typedef int (elevator_set_req_fn) (struct request_queue *, struct request *, gfp_t);
26
typedef void (elevator_put_req_fn) (struct request *);
27 28
typedef void (elevator_activate_req_fn) (struct request_queue *, struct request *);
typedef void (elevator_deactivate_req_fn) (struct request_queue *, struct request *);
L
Linus Torvalds 已提交
29

30
typedef void *(elevator_init_fn) (struct request_queue *);
L
Linus Torvalds 已提交
31 32 33 34 35 36 37
typedef void (elevator_exit_fn) (elevator_t *);

struct elevator_ops
{
	elevator_merge_fn *elevator_merge_fn;
	elevator_merged_fn *elevator_merged_fn;
	elevator_merge_req_fn *elevator_merge_req_fn;
38
	elevator_allow_merge_fn *elevator_allow_merge_fn;
L
Linus Torvalds 已提交
39

40
	elevator_dispatch_fn *elevator_dispatch_fn;
L
Linus Torvalds 已提交
41
	elevator_add_req_fn *elevator_add_req_fn;
42
	elevator_activate_req_fn *elevator_activate_req_fn;
L
Linus Torvalds 已提交
43 44 45 46 47 48 49 50 51 52 53 54 55 56 57
	elevator_deactivate_req_fn *elevator_deactivate_req_fn;

	elevator_queue_empty_fn *elevator_queue_empty_fn;
	elevator_completed_req_fn *elevator_completed_req_fn;

	elevator_request_list_fn *elevator_former_req_fn;
	elevator_request_list_fn *elevator_latter_req_fn;

	elevator_set_req_fn *elevator_set_req_fn;
	elevator_put_req_fn *elevator_put_req_fn;

	elevator_may_queue_fn *elevator_may_queue_fn;

	elevator_init_fn *elevator_init_fn;
	elevator_exit_fn *elevator_exit_fn;
58
	void (*trim)(struct io_context *);
L
Linus Torvalds 已提交
59 60 61 62
};

#define ELV_NAME_MAX	(16)

63 64 65 66 67 68
struct elv_fs_entry {
	struct attribute attr;
	ssize_t (*show)(elevator_t *, char *);
	ssize_t (*store)(elevator_t *, const char *, size_t);
};

L
Linus Torvalds 已提交
69 70 71 72 73 74 75
/*
 * identifies an elevator type, such as AS or deadline
 */
struct elevator_type
{
	struct list_head list;
	struct elevator_ops ops;
76
	struct elv_fs_entry *elevator_attrs;
L
Linus Torvalds 已提交
77 78 79 80 81
	char elevator_name[ELV_NAME_MAX];
	struct module *elevator_owner;
};

/*
A
Adrian Bunk 已提交
82
 * each queue has an elevator_queue associated with it
L
Linus Torvalds 已提交
83 84 85 86 87 88 89
 */
struct elevator_queue
{
	struct elevator_ops *ops;
	void *elevator_data;
	struct kobject kobj;
	struct elevator_type *elevator_type;
90
	struct mutex sysfs_lock;
91
	struct hlist_head *hash;
L
Linus Torvalds 已提交
92 93 94 95 96
};

/*
 * block elevator interface
 */
97 98 99 100 101 102 103
extern void elv_dispatch_sort(struct request_queue *, struct request *);
extern void elv_dispatch_add_tail(struct request_queue *, struct request *);
extern void elv_add_request(struct request_queue *, struct request *, int, int);
extern void __elv_add_request(struct request_queue *, struct request *, int, int);
extern void elv_insert(struct request_queue *, struct request *, int);
extern int elv_merge(struct request_queue *, struct request **, struct bio *);
extern void elv_merge_requests(struct request_queue *, struct request *,
L
Linus Torvalds 已提交
104
			       struct request *);
105 106 107 108
extern void elv_merged_request(struct request_queue *, struct request *, int);
extern void elv_dequeue_request(struct request_queue *, struct request *);
extern void elv_requeue_request(struct request_queue *, struct request *);
extern int elv_queue_empty(struct request_queue *);
L
Linus Torvalds 已提交
109
extern struct request *elv_next_request(struct request_queue *q);
110 111 112 113 114 115 116 117
extern struct request *elv_former_request(struct request_queue *, struct request *);
extern struct request *elv_latter_request(struct request_queue *, struct request *);
extern int elv_register_queue(struct request_queue *q);
extern void elv_unregister_queue(struct request_queue *q);
extern int elv_may_queue(struct request_queue *, int);
extern void elv_completed_request(struct request_queue *, struct request *);
extern int elv_set_request(struct request_queue *, struct request *, gfp_t);
extern void elv_put_request(struct request_queue *, struct request *);
L
Linus Torvalds 已提交
118 119 120 121

/*
 * io scheduler registration
 */
122
extern void elv_register(struct elevator_type *);
L
Linus Torvalds 已提交
123 124 125 126 127
extern void elv_unregister(struct elevator_type *);

/*
 * io scheduler sysfs switching
 */
128 129
extern ssize_t elv_iosched_show(struct request_queue *, char *);
extern ssize_t elv_iosched_store(struct request_queue *, const char *, size_t);
L
Linus Torvalds 已提交
130

131
extern int elevator_init(struct request_queue *, char *);
L
Linus Torvalds 已提交
132 133 134
extern void elevator_exit(elevator_t *);
extern int elv_rq_merge_ok(struct request *, struct bio *);

135 136 137
/*
 * Helper functions.
 */
138 139
extern struct request *elv_rb_former_request(struct request_queue *, struct request *);
extern struct request *elv_rb_latter_request(struct request_queue *, struct request *);
140 141 142 143 144 145 146 147

/*
 * rb support functions.
 */
extern struct request *elv_rb_add(struct rb_root *, struct request *);
extern void elv_rb_del(struct rb_root *, struct request *);
extern struct request *elv_rb_find(struct rb_root *, sector_t);

L
Linus Torvalds 已提交
148 149 150 151 152 153 154 155 156 157 158 159 160
/*
 * Return values from elevator merger
 */
#define ELEVATOR_NO_MERGE	0
#define ELEVATOR_FRONT_MERGE	1
#define ELEVATOR_BACK_MERGE	2

/*
 * Insertion selection
 */
#define ELEVATOR_INSERT_FRONT	1
#define ELEVATOR_INSERT_BACK	2
#define ELEVATOR_INSERT_SORT	3
161
#define ELEVATOR_INSERT_REQUEUE	4
L
Linus Torvalds 已提交
162 163 164 165 166 167 168 169 170 171

/*
 * return values from elevator_may_queue_fn
 */
enum {
	ELV_MQUEUE_MAY,
	ELV_MQUEUE_NO,
	ELV_MQUEUE_MUST,
};

J
Jens Axboe 已提交
172
#define rq_end_sector(rq)	((rq)->sector + (rq)->nr_sectors)
173
#define rb_entry_rq(node)	rb_entry((node), struct request, rb_node)
J
Jens Axboe 已提交
174

175 176 177 178 179 180 181 182 183 184 185 186
/*
 * Hack to reuse the donelist list_head as the fifo time holder while
 * the request is in the io scheduler. Saves an unsigned long in rq.
 */
#define rq_fifo_time(rq)	((unsigned long) (rq)->donelist.next)
#define rq_set_fifo_time(rq,exp)	((rq)->donelist.next = (void *) (exp))
#define rq_entry_fifo(ptr)	list_entry((ptr), struct request, queuelist)
#define rq_fifo_clear(rq)	do {		\
	list_del_init(&(rq)->queuelist);	\
	INIT_LIST_HEAD(&(rq)->donelist);	\
	} while (0)

187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209
/*
 * io context count accounting
 */
#define elv_ioc_count_mod(name, __val)				\
	do {							\
		preempt_disable();				\
		__get_cpu_var(name) += (__val);			\
		preempt_enable();				\
	} while (0)

#define elv_ioc_count_inc(name)	elv_ioc_count_mod(name, 1)
#define elv_ioc_count_dec(name)	elv_ioc_count_mod(name, -1)

#define elv_ioc_count_read(name)				\
({								\
	unsigned long __val = 0;				\
	int __cpu;						\
	smp_wmb();						\
	for_each_possible_cpu(__cpu)				\
		__val += per_cpu(name, __cpu);			\
	__val;							\
})

210
#endif /* CONFIG_BLOCK */
L
Linus Torvalds 已提交
211
#endif