blob: cff1102dac9d5fc4d17c9c339d2805bf22255ac5 [file] [log] [blame]
Linus Torvalds1da177e2005-04-16 15:20:36 -07001/*
Linus Torvalds1da177e2005-04-16 15:20:36 -07002 * Block device elevator/IO-scheduler.
3 *
4 * Copyright (C) 2000 Andrea Arcangeli <andrea@suse.de> SuSE
5 *
6 * 30042000 Jens Axboe <axboe@suse.de> :
7 *
8 * Split the elevator a bit so that it is possible to choose a different
9 * one or even write a new "plug in". There are three pieces:
10 * - elevator_fn, inserts a new request in the queue list
11 * - elevator_merge_fn, decides whether a new buffer can be merged with
12 * an existing request
13 * - elevator_dequeue_fn, called when a request is taken off the active list
14 *
15 * 20082000 Dave Jones <davej@suse.de> :
16 * Removed tests for max-bomb-segments, which was breaking elvtune
17 * when run without -bN
18 *
19 * Jens:
20 * - Rework again to work with bio instead of buffer_heads
21 * - loose bi_dev comparisons, partition handling is right now
22 * - completely modularize elevator setup and teardown
23 *
24 */
25#include <linux/kernel.h>
26#include <linux/fs.h>
27#include <linux/blkdev.h>
28#include <linux/elevator.h>
29#include <linux/bio.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070030#include <linux/module.h>
31#include <linux/slab.h>
32#include <linux/init.h>
33#include <linux/compiler.h>
Tejun Heocb98fc82005-10-28 08:29:39 +020034#include <linux/delay.h>
Jens Axboe2056a782006-03-23 20:00:26 +010035#include <linux/blktrace_api.h>
Jens Axboe98170642006-07-28 09:23:08 +020036#include <linux/hash.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070037
38#include <asm/uaccess.h>
39
40static DEFINE_SPINLOCK(elv_list_lock);
41static LIST_HEAD(elv_list);
42
43/*
Jens Axboe98170642006-07-28 09:23:08 +020044 * Merge hash stuff.
45 */
46static const int elv_hash_shift = 6;
47#define ELV_HASH_BLOCK(sec) ((sec) >> 3)
48#define ELV_HASH_FN(sec) (hash_long(ELV_HASH_BLOCK((sec)), elv_hash_shift))
49#define ELV_HASH_ENTRIES (1 << elv_hash_shift)
50#define rq_hash_key(rq) ((rq)->sector + (rq)->nr_sectors)
51#define ELV_ON_HASH(rq) (!hlist_unhashed(&(rq)->hash))
52
53/*
Linus Torvalds1da177e2005-04-16 15:20:36 -070054 * can we safely merge with this request?
55 */
56inline int elv_rq_merge_ok(struct request *rq, struct bio *bio)
57{
58 if (!rq_mergeable(rq))
59 return 0;
60
61 /*
62 * different data direction or already started, don't merge
63 */
64 if (bio_data_dir(bio) != rq_data_dir(rq))
65 return 0;
66
67 /*
68 * same device and no special stuff set, merge is ok
69 */
70 if (rq->rq_disk == bio->bi_bdev->bd_disk &&
71 !rq->waiting && !rq->special)
72 return 1;
73
74 return 0;
75}
76EXPORT_SYMBOL(elv_rq_merge_ok);
77
Coywolf Qi Hunt769db452005-12-28 10:55:49 +010078static inline int elv_try_merge(struct request *__rq, struct bio *bio)
Linus Torvalds1da177e2005-04-16 15:20:36 -070079{
80 int ret = ELEVATOR_NO_MERGE;
81
82 /*
83 * we can merge and sequence is ok, check if it's possible
84 */
85 if (elv_rq_merge_ok(__rq, bio)) {
86 if (__rq->sector + __rq->nr_sectors == bio->bi_sector)
87 ret = ELEVATOR_BACK_MERGE;
88 else if (__rq->sector - bio_sectors(bio) == bio->bi_sector)
89 ret = ELEVATOR_FRONT_MERGE;
90 }
91
92 return ret;
93}
Linus Torvalds1da177e2005-04-16 15:20:36 -070094
Linus Torvalds1da177e2005-04-16 15:20:36 -070095static struct elevator_type *elevator_find(const char *name)
96{
97 struct elevator_type *e = NULL;
98 struct list_head *entry;
99
Linus Torvalds1da177e2005-04-16 15:20:36 -0700100 list_for_each(entry, &elv_list) {
101 struct elevator_type *__e;
102
103 __e = list_entry(entry, struct elevator_type, list);
104
105 if (!strcmp(__e->elevator_name, name)) {
106 e = __e;
107 break;
108 }
109 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700110
111 return e;
112}
113
114static void elevator_put(struct elevator_type *e)
115{
116 module_put(e->elevator_owner);
117}
118
119static struct elevator_type *elevator_get(const char *name)
120{
Tejun Heo2824bc932005-10-20 10:56:41 +0200121 struct elevator_type *e;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700122
Tejun Heo2824bc932005-10-20 10:56:41 +0200123 spin_lock_irq(&elv_list_lock);
124
125 e = elevator_find(name);
126 if (e && !try_module_get(e->elevator_owner))
127 e = NULL;
128
129 spin_unlock_irq(&elv_list_lock);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700130
131 return e;
132}
133
Jens Axboebc1c1162006-06-08 08:49:06 +0200134static void *elevator_init_queue(request_queue_t *q, struct elevator_queue *eq)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700135{
Jens Axboebc1c1162006-06-08 08:49:06 +0200136 return eq->ops->elevator_init_fn(q, eq);
137}
Linus Torvalds1da177e2005-04-16 15:20:36 -0700138
Jens Axboebc1c1162006-06-08 08:49:06 +0200139static void elevator_attach(request_queue_t *q, struct elevator_queue *eq,
140 void *data)
141{
Linus Torvalds1da177e2005-04-16 15:20:36 -0700142 q->elevator = eq;
Jens Axboebc1c1162006-06-08 08:49:06 +0200143 eq->elevator_data = data;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700144}
145
146static char chosen_elevator[16];
147
Nate Diller5f003972006-01-24 10:07:58 +0100148static int __init elevator_setup(char *str)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700149{
Chuck Ebbert752a3b72006-01-16 09:47:37 +0100150 /*
151 * Be backwards-compatible with previous kernels, so users
152 * won't get the wrong elevator.
153 */
Nate Diller5f003972006-01-24 10:07:58 +0100154 if (!strcmp(str, "as"))
Chuck Ebbert752a3b72006-01-16 09:47:37 +0100155 strcpy(chosen_elevator, "anticipatory");
Zachary Amsdencff3ba22005-11-09 13:24:20 +0100156 else
Nate Diller5f003972006-01-24 10:07:58 +0100157 strncpy(chosen_elevator, str, sizeof(chosen_elevator) - 1);
OGAWA Hirofumi9b410462006-03-31 02:30:33 -0800158 return 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700159}
160
161__setup("elevator=", elevator_setup);
162
Al Viro3d1ab402006-03-18 18:35:43 -0500163static struct kobj_type elv_ktype;
164
165static elevator_t *elevator_alloc(struct elevator_type *e)
166{
Jens Axboe98170642006-07-28 09:23:08 +0200167 elevator_t *eq;
168 int i;
169
170 eq = kmalloc(sizeof(elevator_t), GFP_KERNEL);
171 if (unlikely(!eq))
172 goto err;
173
174 memset(eq, 0, sizeof(*eq));
175 eq->ops = &e->ops;
176 eq->elevator_type = e;
177 kobject_init(&eq->kobj);
178 snprintf(eq->kobj.name, KOBJ_NAME_LEN, "%s", "iosched");
179 eq->kobj.ktype = &elv_ktype;
180 mutex_init(&eq->sysfs_lock);
181
182 eq->hash = kmalloc(sizeof(struct hlist_head) * ELV_HASH_ENTRIES, GFP_KERNEL);
183 if (!eq->hash)
184 goto err;
185
186 for (i = 0; i < ELV_HASH_ENTRIES; i++)
187 INIT_HLIST_HEAD(&eq->hash[i]);
188
Al Viro3d1ab402006-03-18 18:35:43 -0500189 return eq;
Jens Axboe98170642006-07-28 09:23:08 +0200190err:
191 kfree(eq);
192 elevator_put(e);
193 return NULL;
Al Viro3d1ab402006-03-18 18:35:43 -0500194}
195
196static void elevator_release(struct kobject *kobj)
197{
198 elevator_t *e = container_of(kobj, elevator_t, kobj);
Jens Axboe98170642006-07-28 09:23:08 +0200199
Al Viro3d1ab402006-03-18 18:35:43 -0500200 elevator_put(e->elevator_type);
Jens Axboe98170642006-07-28 09:23:08 +0200201 kfree(e->hash);
Al Viro3d1ab402006-03-18 18:35:43 -0500202 kfree(e);
203}
204
Linus Torvalds1da177e2005-04-16 15:20:36 -0700205int elevator_init(request_queue_t *q, char *name)
206{
207 struct elevator_type *e = NULL;
208 struct elevator_queue *eq;
209 int ret = 0;
Jens Axboebc1c1162006-06-08 08:49:06 +0200210 void *data;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700211
Tejun Heocb98fc82005-10-28 08:29:39 +0200212 INIT_LIST_HEAD(&q->queue_head);
213 q->last_merge = NULL;
214 q->end_sector = 0;
215 q->boundary_rq = NULL;
Tejun Heocb98fc82005-10-28 08:29:39 +0200216
Nate Diller5f003972006-01-24 10:07:58 +0100217 if (name && !(e = elevator_get(name)))
Linus Torvalds1da177e2005-04-16 15:20:36 -0700218 return -EINVAL;
219
Nate Diller248d5ca2006-01-24 10:09:14 +0100220 if (!e && *chosen_elevator && !(e = elevator_get(chosen_elevator)))
221 printk("I/O scheduler %s not found\n", chosen_elevator);
222
223 if (!e && !(e = elevator_get(CONFIG_DEFAULT_IOSCHED))) {
224 printk("Default I/O scheduler not found, using no-op\n");
225 e = elevator_get("noop");
Nate Diller5f003972006-01-24 10:07:58 +0100226 }
227
Al Viro3d1ab402006-03-18 18:35:43 -0500228 eq = elevator_alloc(e);
229 if (!eq)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700230 return -ENOMEM;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700231
Jens Axboebc1c1162006-06-08 08:49:06 +0200232 data = elevator_init_queue(q, eq);
233 if (!data) {
Al Viro3d1ab402006-03-18 18:35:43 -0500234 kobject_put(&eq->kobj);
Jens Axboebc1c1162006-06-08 08:49:06 +0200235 return -ENOMEM;
236 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700237
Jens Axboebc1c1162006-06-08 08:49:06 +0200238 elevator_attach(q, eq, data);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700239 return ret;
240}
241
242void elevator_exit(elevator_t *e)
243{
Al Viro3d1ab402006-03-18 18:35:43 -0500244 mutex_lock(&e->sysfs_lock);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700245 if (e->ops->elevator_exit_fn)
246 e->ops->elevator_exit_fn(e);
Al Viro3d1ab402006-03-18 18:35:43 -0500247 e->ops = NULL;
248 mutex_unlock(&e->sysfs_lock);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700249
Al Viro3d1ab402006-03-18 18:35:43 -0500250 kobject_put(&e->kobj);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700251}
252
Jens Axboe98170642006-07-28 09:23:08 +0200253static inline void __elv_rqhash_del(struct request *rq)
254{
255 hlist_del_init(&rq->hash);
256}
257
258static void elv_rqhash_del(request_queue_t *q, struct request *rq)
259{
260 if (ELV_ON_HASH(rq))
261 __elv_rqhash_del(rq);
262}
263
264static void elv_rqhash_add(request_queue_t *q, struct request *rq)
265{
266 elevator_t *e = q->elevator;
267
268 BUG_ON(ELV_ON_HASH(rq));
269 hlist_add_head(&rq->hash, &e->hash[ELV_HASH_FN(rq_hash_key(rq))]);
270}
271
272static void elv_rqhash_reposition(request_queue_t *q, struct request *rq)
273{
274 __elv_rqhash_del(rq);
275 elv_rqhash_add(q, rq);
276}
277
278static struct request *elv_rqhash_find(request_queue_t *q, sector_t offset)
279{
280 elevator_t *e = q->elevator;
281 struct hlist_head *hash_list = &e->hash[ELV_HASH_FN(offset)];
282 struct hlist_node *entry, *next;
283 struct request *rq;
284
285 hlist_for_each_entry_safe(rq, entry, next, hash_list, hash) {
286 BUG_ON(!ELV_ON_HASH(rq));
287
288 if (unlikely(!rq_mergeable(rq))) {
289 __elv_rqhash_del(rq);
290 continue;
291 }
292
293 if (rq_hash_key(rq) == offset)
294 return rq;
295 }
296
297 return NULL;
298}
299
Tejun Heo8922e162005-10-20 16:23:44 +0200300/*
301 * Insert rq into dispatch queue of q. Queue lock must be held on
302 * entry. If sort != 0, rq is sort-inserted; otherwise, rq will be
303 * appended to the dispatch queue. To be used by specific elevators.
304 */
Jens Axboe1b47f532005-10-20 16:37:00 +0200305void elv_dispatch_sort(request_queue_t *q, struct request *rq)
Tejun Heo8922e162005-10-20 16:23:44 +0200306{
307 sector_t boundary;
Tejun Heo8922e162005-10-20 16:23:44 +0200308 struct list_head *entry;
309
Tejun Heo06b86242005-10-20 16:46:23 +0200310 if (q->last_merge == rq)
311 q->last_merge = NULL;
Jens Axboe98170642006-07-28 09:23:08 +0200312
313 elv_rqhash_del(q, rq);
314
Tejun Heo15853af2005-11-10 08:52:05 +0100315 q->nr_sorted--;
Tejun Heo06b86242005-10-20 16:46:23 +0200316
Jens Axboe1b47f532005-10-20 16:37:00 +0200317 boundary = q->end_sector;
Tejun Heocb198332005-10-24 08:35:58 +0200318
Tejun Heo8922e162005-10-20 16:23:44 +0200319 list_for_each_prev(entry, &q->queue_head) {
320 struct request *pos = list_entry_rq(entry);
321
Jens Axboe4aff5e22006-08-10 08:44:47 +0200322 if (pos->cmd_flags & (REQ_SOFTBARRIER|REQ_HARDBARRIER|REQ_STARTED))
Tejun Heo8922e162005-10-20 16:23:44 +0200323 break;
324 if (rq->sector >= boundary) {
325 if (pos->sector < boundary)
326 continue;
327 } else {
328 if (pos->sector >= boundary)
329 break;
330 }
331 if (rq->sector >= pos->sector)
332 break;
333 }
334
335 list_add(&rq->queuelist, entry);
336}
337
Jens Axboe98170642006-07-28 09:23:08 +0200338/*
339 * This should be in elevator.h, but that requires pulling in rq and q
340 */
341void elv_dispatch_add_tail(struct request_queue *q, struct request *rq)
342{
343 if (q->last_merge == rq)
344 q->last_merge = NULL;
345
346 elv_rqhash_del(q, rq);
347
348 q->nr_sorted--;
349
350 q->end_sector = rq_end_sector(rq);
351 q->boundary_rq = rq;
352 list_add_tail(&rq->queuelist, &q->queue_head);
353}
354
Linus Torvalds1da177e2005-04-16 15:20:36 -0700355int elv_merge(request_queue_t *q, struct request **req, struct bio *bio)
356{
357 elevator_t *e = q->elevator;
Jens Axboe98170642006-07-28 09:23:08 +0200358 struct request *__rq;
Tejun Heo06b86242005-10-20 16:46:23 +0200359 int ret;
360
Jens Axboe98170642006-07-28 09:23:08 +0200361 /*
362 * First try one-hit cache.
363 */
Tejun Heo06b86242005-10-20 16:46:23 +0200364 if (q->last_merge) {
365 ret = elv_try_merge(q->last_merge, bio);
366 if (ret != ELEVATOR_NO_MERGE) {
367 *req = q->last_merge;
368 return ret;
369 }
370 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700371
Jens Axboe98170642006-07-28 09:23:08 +0200372 /*
373 * See if our hash lookup can find a potential backmerge.
374 */
375 __rq = elv_rqhash_find(q, bio->bi_sector);
376 if (__rq && elv_rq_merge_ok(__rq, bio)) {
377 *req = __rq;
378 return ELEVATOR_BACK_MERGE;
379 }
380
Linus Torvalds1da177e2005-04-16 15:20:36 -0700381 if (e->ops->elevator_merge_fn)
382 return e->ops->elevator_merge_fn(q, req, bio);
383
384 return ELEVATOR_NO_MERGE;
385}
386
387void elv_merged_request(request_queue_t *q, struct request *rq)
388{
389 elevator_t *e = q->elevator;
390
391 if (e->ops->elevator_merged_fn)
392 e->ops->elevator_merged_fn(q, rq);
Tejun Heo06b86242005-10-20 16:46:23 +0200393
Jens Axboe98170642006-07-28 09:23:08 +0200394 elv_rqhash_reposition(q, rq);
395
Tejun Heo06b86242005-10-20 16:46:23 +0200396 q->last_merge = rq;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700397}
398
399void elv_merge_requests(request_queue_t *q, struct request *rq,
400 struct request *next)
401{
402 elevator_t *e = q->elevator;
403
Linus Torvalds1da177e2005-04-16 15:20:36 -0700404 if (e->ops->elevator_merge_req_fn)
405 e->ops->elevator_merge_req_fn(q, rq, next);
Tejun Heo06b86242005-10-20 16:46:23 +0200406
Jens Axboe98170642006-07-28 09:23:08 +0200407 elv_rqhash_reposition(q, rq);
408 elv_rqhash_del(q, next);
409
410 q->nr_sorted--;
Tejun Heo06b86242005-10-20 16:46:23 +0200411 q->last_merge = rq;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700412}
413
Tejun Heo8922e162005-10-20 16:23:44 +0200414void elv_requeue_request(request_queue_t *q, struct request *rq)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700415{
416 elevator_t *e = q->elevator;
417
418 /*
419 * it already went through dequeue, we need to decrement the
420 * in_flight count again
421 */
Tejun Heo8922e162005-10-20 16:23:44 +0200422 if (blk_account_rq(rq)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700423 q->in_flight--;
Tejun Heo8922e162005-10-20 16:23:44 +0200424 if (blk_sorted_rq(rq) && e->ops->elevator_deactivate_req_fn)
425 e->ops->elevator_deactivate_req_fn(q, rq);
426 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700427
Jens Axboe4aff5e22006-08-10 08:44:47 +0200428 rq->cmd_flags &= ~REQ_STARTED;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700429
Tejun Heo30e96562006-02-08 01:01:31 -0800430 elv_insert(q, rq, ELEVATOR_INSERT_REQUEUE);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700431}
432
Tejun Heo15853af2005-11-10 08:52:05 +0100433static void elv_drain_elevator(request_queue_t *q)
434{
435 static int printed;
436 while (q->elevator->ops->elevator_dispatch_fn(q, 1))
437 ;
438 if (q->nr_sorted == 0)
439 return;
440 if (printed++ < 10) {
441 printk(KERN_ERR "%s: forced dispatching is broken "
442 "(nr_sorted=%u), please report this\n",
443 q->elevator->elevator_type->elevator_name, q->nr_sorted);
444 }
445}
446
Tejun Heo30e96562006-02-08 01:01:31 -0800447void elv_insert(request_queue_t *q, struct request *rq, int where)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700448{
Tejun Heo797e7db2006-01-06 09:51:03 +0100449 struct list_head *pos;
450 unsigned ordseq;
Jens Axboedac07ec2006-05-11 08:20:16 +0200451 int unplug_it = 1;
Tejun Heo797e7db2006-01-06 09:51:03 +0100452
Jens Axboe2056a782006-03-23 20:00:26 +0100453 blk_add_trace_rq(q, rq, BLK_TA_INSERT);
454
Linus Torvalds1da177e2005-04-16 15:20:36 -0700455 rq->q = q;
456
Tejun Heo8922e162005-10-20 16:23:44 +0200457 switch (where) {
458 case ELEVATOR_INSERT_FRONT:
Jens Axboe4aff5e22006-08-10 08:44:47 +0200459 rq->cmd_flags |= REQ_SOFTBARRIER;
Tejun Heo8922e162005-10-20 16:23:44 +0200460
461 list_add(&rq->queuelist, &q->queue_head);
462 break;
463
464 case ELEVATOR_INSERT_BACK:
Jens Axboe4aff5e22006-08-10 08:44:47 +0200465 rq->cmd_flags |= REQ_SOFTBARRIER;
Tejun Heo15853af2005-11-10 08:52:05 +0100466 elv_drain_elevator(q);
Tejun Heo8922e162005-10-20 16:23:44 +0200467 list_add_tail(&rq->queuelist, &q->queue_head);
468 /*
469 * We kick the queue here for the following reasons.
470 * - The elevator might have returned NULL previously
471 * to delay requests and returned them now. As the
472 * queue wasn't empty before this request, ll_rw_blk
473 * won't run the queue on return, resulting in hang.
474 * - Usually, back inserted requests won't be merged
475 * with anything. There's no point in delaying queue
476 * processing.
477 */
478 blk_remove_plug(q);
479 q->request_fn(q);
480 break;
481
482 case ELEVATOR_INSERT_SORT:
483 BUG_ON(!blk_fs_request(rq));
Jens Axboe4aff5e22006-08-10 08:44:47 +0200484 rq->cmd_flags |= REQ_SORTED;
Tejun Heo15853af2005-11-10 08:52:05 +0100485 q->nr_sorted++;
Jens Axboe98170642006-07-28 09:23:08 +0200486 if (rq_mergeable(rq)) {
487 elv_rqhash_add(q, rq);
488 if (!q->last_merge)
489 q->last_merge = rq;
490 }
491
Tejun Heoca235092005-11-01 17:23:49 +0900492 /*
493 * Some ioscheds (cfq) run q->request_fn directly, so
494 * rq cannot be accessed after calling
495 * elevator_add_req_fn.
496 */
497 q->elevator->ops->elevator_add_req_fn(q, rq);
Tejun Heo8922e162005-10-20 16:23:44 +0200498 break;
499
Tejun Heo797e7db2006-01-06 09:51:03 +0100500 case ELEVATOR_INSERT_REQUEUE:
501 /*
502 * If ordered flush isn't in progress, we do front
503 * insertion; otherwise, requests should be requeued
504 * in ordseq order.
505 */
Jens Axboe4aff5e22006-08-10 08:44:47 +0200506 rq->cmd_flags |= REQ_SOFTBARRIER;
Tejun Heo797e7db2006-01-06 09:51:03 +0100507
508 if (q->ordseq == 0) {
509 list_add(&rq->queuelist, &q->queue_head);
510 break;
511 }
512
513 ordseq = blk_ordered_req_seq(rq);
514
515 list_for_each(pos, &q->queue_head) {
516 struct request *pos_rq = list_entry_rq(pos);
517 if (ordseq <= blk_ordered_req_seq(pos_rq))
518 break;
519 }
520
521 list_add_tail(&rq->queuelist, pos);
Jens Axboedac07ec2006-05-11 08:20:16 +0200522 /*
523 * most requeues happen because of a busy condition, don't
524 * force unplug of the queue for that case.
525 */
526 unplug_it = 0;
Tejun Heo797e7db2006-01-06 09:51:03 +0100527 break;
528
Tejun Heo8922e162005-10-20 16:23:44 +0200529 default:
530 printk(KERN_ERR "%s: bad insertion point %d\n",
531 __FUNCTION__, where);
532 BUG();
533 }
534
Jens Axboedac07ec2006-05-11 08:20:16 +0200535 if (unplug_it && blk_queue_plugged(q)) {
Tejun Heo8922e162005-10-20 16:23:44 +0200536 int nrq = q->rq.count[READ] + q->rq.count[WRITE]
537 - q->in_flight;
538
539 if (nrq >= q->unplug_thresh)
540 __generic_unplug_device(q);
541 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700542}
543
Tejun Heo30e96562006-02-08 01:01:31 -0800544void __elv_add_request(request_queue_t *q, struct request *rq, int where,
545 int plug)
546{
547 if (q->ordcolor)
Jens Axboe4aff5e22006-08-10 08:44:47 +0200548 rq->cmd_flags |= REQ_ORDERED_COLOR;
Tejun Heo30e96562006-02-08 01:01:31 -0800549
Jens Axboe4aff5e22006-08-10 08:44:47 +0200550 if (rq->cmd_flags & (REQ_SOFTBARRIER | REQ_HARDBARRIER)) {
Tejun Heo30e96562006-02-08 01:01:31 -0800551 /*
552 * toggle ordered color
553 */
554 if (blk_barrier_rq(rq))
555 q->ordcolor ^= 1;
556
557 /*
558 * barriers implicitly indicate back insertion
559 */
560 if (where == ELEVATOR_INSERT_SORT)
561 where = ELEVATOR_INSERT_BACK;
562
563 /*
564 * this request is scheduling boundary, update
565 * end_sector
566 */
567 if (blk_fs_request(rq)) {
568 q->end_sector = rq_end_sector(rq);
569 q->boundary_rq = rq;
570 }
Jens Axboe4aff5e22006-08-10 08:44:47 +0200571 } else if (!(rq->cmd_flags & REQ_ELVPRIV) && where == ELEVATOR_INSERT_SORT)
Tejun Heo30e96562006-02-08 01:01:31 -0800572 where = ELEVATOR_INSERT_BACK;
573
574 if (plug)
575 blk_plug_device(q);
576
577 elv_insert(q, rq, where);
578}
579
Linus Torvalds1da177e2005-04-16 15:20:36 -0700580void elv_add_request(request_queue_t *q, struct request *rq, int where,
581 int plug)
582{
583 unsigned long flags;
584
585 spin_lock_irqsave(q->queue_lock, flags);
586 __elv_add_request(q, rq, where, plug);
587 spin_unlock_irqrestore(q->queue_lock, flags);
588}
589
590static inline struct request *__elv_next_request(request_queue_t *q)
591{
Tejun Heo8922e162005-10-20 16:23:44 +0200592 struct request *rq;
593
Tejun Heo797e7db2006-01-06 09:51:03 +0100594 while (1) {
595 while (!list_empty(&q->queue_head)) {
596 rq = list_entry_rq(q->queue_head.next);
597 if (blk_do_ordered(q, &rq))
598 return rq;
599 }
Tejun Heo8922e162005-10-20 16:23:44 +0200600
Tejun Heo797e7db2006-01-06 09:51:03 +0100601 if (!q->elevator->ops->elevator_dispatch_fn(q, 0))
602 return NULL;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700603 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700604}
605
606struct request *elv_next_request(request_queue_t *q)
607{
608 struct request *rq;
609 int ret;
610
611 while ((rq = __elv_next_request(q)) != NULL) {
Jens Axboe4aff5e22006-08-10 08:44:47 +0200612 if (!(rq->cmd_flags & REQ_STARTED)) {
Tejun Heo8922e162005-10-20 16:23:44 +0200613 elevator_t *e = q->elevator;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700614
Tejun Heo8922e162005-10-20 16:23:44 +0200615 /*
616 * This is the first time the device driver
617 * sees this request (possibly after
618 * requeueing). Notify IO scheduler.
619 */
620 if (blk_sorted_rq(rq) &&
621 e->ops->elevator_activate_req_fn)
622 e->ops->elevator_activate_req_fn(q, rq);
623
624 /*
625 * just mark as started even if we don't start
626 * it, a request that has been delayed should
627 * not be passed by new incoming requests
628 */
Jens Axboe4aff5e22006-08-10 08:44:47 +0200629 rq->cmd_flags |= REQ_STARTED;
Jens Axboe2056a782006-03-23 20:00:26 +0100630 blk_add_trace_rq(q, rq, BLK_TA_ISSUE);
Tejun Heo8922e162005-10-20 16:23:44 +0200631 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700632
Tejun Heo8922e162005-10-20 16:23:44 +0200633 if (!q->boundary_rq || q->boundary_rq == rq) {
Jens Axboe1b47f532005-10-20 16:37:00 +0200634 q->end_sector = rq_end_sector(rq);
Tejun Heo8922e162005-10-20 16:23:44 +0200635 q->boundary_rq = NULL;
636 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700637
Jens Axboe4aff5e22006-08-10 08:44:47 +0200638 if ((rq->cmd_flags & REQ_DONTPREP) || !q->prep_rq_fn)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700639 break;
640
641 ret = q->prep_rq_fn(q, rq);
642 if (ret == BLKPREP_OK) {
643 break;
644 } else if (ret == BLKPREP_DEFER) {
Tejun Heo 2e759cd2005-04-24 02:04:21 -0500645 /*
646 * the request may have been (partially) prepped.
647 * we need to keep this request in the front to
Tejun Heo8922e162005-10-20 16:23:44 +0200648 * avoid resource deadlock. REQ_STARTED will
649 * prevent other fs requests from passing this one.
Tejun Heo 2e759cd2005-04-24 02:04:21 -0500650 */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700651 rq = NULL;
652 break;
653 } else if (ret == BLKPREP_KILL) {
654 int nr_bytes = rq->hard_nr_sectors << 9;
655
656 if (!nr_bytes)
657 nr_bytes = rq->data_len;
658
659 blkdev_dequeue_request(rq);
Jens Axboe4aff5e22006-08-10 08:44:47 +0200660 rq->cmd_flags |= REQ_QUIET;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700661 end_that_request_chunk(rq, 0, nr_bytes);
Tejun Heo8ffdc652006-01-06 09:49:03 +0100662 end_that_request_last(rq, 0);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700663 } else {
664 printk(KERN_ERR "%s: bad return=%d\n", __FUNCTION__,
665 ret);
666 break;
667 }
668 }
669
670 return rq;
671}
672
Tejun Heo8922e162005-10-20 16:23:44 +0200673void elv_dequeue_request(request_queue_t *q, struct request *rq)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700674{
Tejun Heo8922e162005-10-20 16:23:44 +0200675 BUG_ON(list_empty(&rq->queuelist));
Jens Axboe98170642006-07-28 09:23:08 +0200676 BUG_ON(ELV_ON_HASH(rq));
Tejun Heo8922e162005-10-20 16:23:44 +0200677
678 list_del_init(&rq->queuelist);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700679
680 /*
681 * the time frame between a request being removed from the lists
682 * and to it is freed is accounted as io that is in progress at
Tejun Heo8922e162005-10-20 16:23:44 +0200683 * the driver side.
Linus Torvalds1da177e2005-04-16 15:20:36 -0700684 */
685 if (blk_account_rq(rq))
686 q->in_flight++;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700687}
688
689int elv_queue_empty(request_queue_t *q)
690{
691 elevator_t *e = q->elevator;
692
Tejun Heo8922e162005-10-20 16:23:44 +0200693 if (!list_empty(&q->queue_head))
694 return 0;
695
Linus Torvalds1da177e2005-04-16 15:20:36 -0700696 if (e->ops->elevator_queue_empty_fn)
697 return e->ops->elevator_queue_empty_fn(q);
698
Tejun Heo8922e162005-10-20 16:23:44 +0200699 return 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700700}
701
702struct request *elv_latter_request(request_queue_t *q, struct request *rq)
703{
Linus Torvalds1da177e2005-04-16 15:20:36 -0700704 elevator_t *e = q->elevator;
705
706 if (e->ops->elevator_latter_req_fn)
707 return e->ops->elevator_latter_req_fn(q, rq);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700708 return NULL;
709}
710
711struct request *elv_former_request(request_queue_t *q, struct request *rq)
712{
Linus Torvalds1da177e2005-04-16 15:20:36 -0700713 elevator_t *e = q->elevator;
714
715 if (e->ops->elevator_former_req_fn)
716 return e->ops->elevator_former_req_fn(q, rq);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700717 return NULL;
718}
719
Jens Axboe22e2c502005-06-27 10:55:12 +0200720int elv_set_request(request_queue_t *q, struct request *rq, struct bio *bio,
Al Viro8267e262005-10-21 03:20:53 -0400721 gfp_t gfp_mask)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700722{
723 elevator_t *e = q->elevator;
724
725 if (e->ops->elevator_set_req_fn)
Jens Axboe22e2c502005-06-27 10:55:12 +0200726 return e->ops->elevator_set_req_fn(q, rq, bio, gfp_mask);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700727
728 rq->elevator_private = NULL;
729 return 0;
730}
731
732void elv_put_request(request_queue_t *q, struct request *rq)
733{
734 elevator_t *e = q->elevator;
735
736 if (e->ops->elevator_put_req_fn)
737 e->ops->elevator_put_req_fn(q, rq);
738}
739
Jens Axboe22e2c502005-06-27 10:55:12 +0200740int elv_may_queue(request_queue_t *q, int rw, struct bio *bio)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700741{
742 elevator_t *e = q->elevator;
743
744 if (e->ops->elevator_may_queue_fn)
Jens Axboe22e2c502005-06-27 10:55:12 +0200745 return e->ops->elevator_may_queue_fn(q, rw, bio);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700746
747 return ELV_MQUEUE_MAY;
748}
749
750void elv_completed_request(request_queue_t *q, struct request *rq)
751{
752 elevator_t *e = q->elevator;
753
754 /*
755 * request is released from the driver, io must be done
756 */
Tejun Heo8922e162005-10-20 16:23:44 +0200757 if (blk_account_rq(rq)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700758 q->in_flight--;
Tejun Heo1bc691d2006-01-12 15:39:26 +0100759 if (blk_sorted_rq(rq) && e->ops->elevator_completed_req_fn)
760 e->ops->elevator_completed_req_fn(q, rq);
761 }
Tejun Heo797e7db2006-01-06 09:51:03 +0100762
Tejun Heo1bc691d2006-01-12 15:39:26 +0100763 /*
764 * Check if the queue is waiting for fs requests to be
765 * drained for flush sequence.
766 */
767 if (unlikely(q->ordseq)) {
768 struct request *first_rq = list_entry_rq(q->queue_head.next);
769 if (q->in_flight == 0 &&
Tejun Heo797e7db2006-01-06 09:51:03 +0100770 blk_ordered_cur_seq(q) == QUEUE_ORDSEQ_DRAIN &&
771 blk_ordered_req_seq(first_rq) > QUEUE_ORDSEQ_DRAIN) {
772 blk_ordered_complete_seq(q, QUEUE_ORDSEQ_DRAIN, 0);
773 q->request_fn(q);
774 }
Tejun Heo8922e162005-10-20 16:23:44 +0200775 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700776}
777
Al Viro3d1ab402006-03-18 18:35:43 -0500778#define to_elv(atr) container_of((atr), struct elv_fs_entry, attr)
779
780static ssize_t
781elv_attr_show(struct kobject *kobj, struct attribute *attr, char *page)
782{
783 elevator_t *e = container_of(kobj, elevator_t, kobj);
784 struct elv_fs_entry *entry = to_elv(attr);
785 ssize_t error;
786
787 if (!entry->show)
788 return -EIO;
789
790 mutex_lock(&e->sysfs_lock);
791 error = e->ops ? entry->show(e, page) : -ENOENT;
792 mutex_unlock(&e->sysfs_lock);
793 return error;
794}
795
796static ssize_t
797elv_attr_store(struct kobject *kobj, struct attribute *attr,
798 const char *page, size_t length)
799{
800 elevator_t *e = container_of(kobj, elevator_t, kobj);
801 struct elv_fs_entry *entry = to_elv(attr);
802 ssize_t error;
803
804 if (!entry->store)
805 return -EIO;
806
807 mutex_lock(&e->sysfs_lock);
808 error = e->ops ? entry->store(e, page, length) : -ENOENT;
809 mutex_unlock(&e->sysfs_lock);
810 return error;
811}
812
813static struct sysfs_ops elv_sysfs_ops = {
814 .show = elv_attr_show,
815 .store = elv_attr_store,
816};
817
818static struct kobj_type elv_ktype = {
819 .sysfs_ops = &elv_sysfs_ops,
820 .release = elevator_release,
821};
822
Linus Torvalds1da177e2005-04-16 15:20:36 -0700823int elv_register_queue(struct request_queue *q)
824{
825 elevator_t *e = q->elevator;
Al Viro3d1ab402006-03-18 18:35:43 -0500826 int error;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700827
Al Viro3d1ab402006-03-18 18:35:43 -0500828 e->kobj.parent = &q->kobj;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700829
Al Viro3d1ab402006-03-18 18:35:43 -0500830 error = kobject_add(&e->kobj);
831 if (!error) {
Al Viroe572ec72006-03-18 22:27:18 -0500832 struct elv_fs_entry *attr = e->elevator_type->elevator_attrs;
Al Viro3d1ab402006-03-18 18:35:43 -0500833 if (attr) {
Al Viroe572ec72006-03-18 22:27:18 -0500834 while (attr->attr.name) {
835 if (sysfs_create_file(&e->kobj, &attr->attr))
Al Viro3d1ab402006-03-18 18:35:43 -0500836 break;
Al Viroe572ec72006-03-18 22:27:18 -0500837 attr++;
Al Viro3d1ab402006-03-18 18:35:43 -0500838 }
839 }
840 kobject_uevent(&e->kobj, KOBJ_ADD);
841 }
842 return error;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700843}
844
Jens Axboebc1c1162006-06-08 08:49:06 +0200845static void __elv_unregister_queue(elevator_t *e)
846{
847 kobject_uevent(&e->kobj, KOBJ_REMOVE);
848 kobject_del(&e->kobj);
849}
850
Linus Torvalds1da177e2005-04-16 15:20:36 -0700851void elv_unregister_queue(struct request_queue *q)
852{
Jens Axboebc1c1162006-06-08 08:49:06 +0200853 if (q)
854 __elv_unregister_queue(q->elevator);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700855}
856
857int elv_register(struct elevator_type *e)
858{
Tejun Heo2824bc932005-10-20 10:56:41 +0200859 spin_lock_irq(&elv_list_lock);
Eric Sesterhennce524492006-03-24 18:43:26 +0100860 BUG_ON(elevator_find(e->elevator_name));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700861 list_add_tail(&e->list, &elv_list);
862 spin_unlock_irq(&elv_list_lock);
863
864 printk(KERN_INFO "io scheduler %s registered", e->elevator_name);
Nate Diller5f003972006-01-24 10:07:58 +0100865 if (!strcmp(e->elevator_name, chosen_elevator) ||
866 (!*chosen_elevator &&
867 !strcmp(e->elevator_name, CONFIG_DEFAULT_IOSCHED)))
868 printk(" (default)");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700869 printk("\n");
870 return 0;
871}
872EXPORT_SYMBOL_GPL(elv_register);
873
874void elv_unregister(struct elevator_type *e)
875{
Christoph Hellwig83521d32005-10-30 15:01:39 -0800876 struct task_struct *g, *p;
877
878 /*
879 * Iterate every thread in the process to remove the io contexts.
880 */
Al Viroe17a9482006-03-18 13:21:20 -0500881 if (e->ops.trim) {
882 read_lock(&tasklist_lock);
883 do_each_thread(g, p) {
884 task_lock(p);
Oleg Nesterov2d8f6132006-08-22 21:22:13 +0400885 if (p->io_context)
886 e->ops.trim(p->io_context);
Al Viroe17a9482006-03-18 13:21:20 -0500887 task_unlock(p);
888 } while_each_thread(g, p);
889 read_unlock(&tasklist_lock);
890 }
Christoph Hellwig83521d32005-10-30 15:01:39 -0800891
Linus Torvalds1da177e2005-04-16 15:20:36 -0700892 spin_lock_irq(&elv_list_lock);
893 list_del_init(&e->list);
894 spin_unlock_irq(&elv_list_lock);
895}
896EXPORT_SYMBOL_GPL(elv_unregister);
897
898/*
899 * switch to new_e io scheduler. be careful not to introduce deadlocks -
900 * we don't free the old io scheduler, before we have allocated what we
901 * need for the new one. this way we have a chance of going back to the old
Tejun Heocb98fc82005-10-28 08:29:39 +0200902 * one, if the new one fails init for some reason.
Linus Torvalds1da177e2005-04-16 15:20:36 -0700903 */
Al Viro3d1ab402006-03-18 18:35:43 -0500904static int elevator_switch(request_queue_t *q, struct elevator_type *new_e)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700905{
Tejun Heocb98fc82005-10-28 08:29:39 +0200906 elevator_t *old_elevator, *e;
Jens Axboebc1c1162006-06-08 08:49:06 +0200907 void *data;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700908
Tejun Heocb98fc82005-10-28 08:29:39 +0200909 /*
910 * Allocate new elevator
911 */
Al Viro3d1ab402006-03-18 18:35:43 -0500912 e = elevator_alloc(new_e);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700913 if (!e)
Al Viro3d1ab402006-03-18 18:35:43 -0500914 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700915
Jens Axboebc1c1162006-06-08 08:49:06 +0200916 data = elevator_init_queue(q, e);
917 if (!data) {
918 kobject_put(&e->kobj);
919 return 0;
920 }
921
Linus Torvalds1da177e2005-04-16 15:20:36 -0700922 /*
Tejun Heocb98fc82005-10-28 08:29:39 +0200923 * Turn on BYPASS and drain all requests w/ elevator private data
Linus Torvalds1da177e2005-04-16 15:20:36 -0700924 */
Tejun Heocb98fc82005-10-28 08:29:39 +0200925 spin_lock_irq(q->queue_lock);
926
Jens Axboe64521d12005-10-28 08:30:39 +0200927 set_bit(QUEUE_FLAG_ELVSWITCH, &q->queue_flags);
Tejun Heocb98fc82005-10-28 08:29:39 +0200928
Tejun Heo15853af2005-11-10 08:52:05 +0100929 elv_drain_elevator(q);
Tejun Heocb98fc82005-10-28 08:29:39 +0200930
931 while (q->rq.elvpriv) {
Tejun Heo407df2a2005-11-10 08:48:21 +0100932 blk_remove_plug(q);
933 q->request_fn(q);
Tejun Heocb98fc82005-10-28 08:29:39 +0200934 spin_unlock_irq(q->queue_lock);
Jens Axboe64521d12005-10-28 08:30:39 +0200935 msleep(10);
Tejun Heocb98fc82005-10-28 08:29:39 +0200936 spin_lock_irq(q->queue_lock);
Tejun Heo15853af2005-11-10 08:52:05 +0100937 elv_drain_elevator(q);
Tejun Heocb98fc82005-10-28 08:29:39 +0200938 }
939
Linus Torvalds1da177e2005-04-16 15:20:36 -0700940 /*
Jens Axboebc1c1162006-06-08 08:49:06 +0200941 * Remember old elevator.
Linus Torvalds1da177e2005-04-16 15:20:36 -0700942 */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700943 old_elevator = q->elevator;
944
945 /*
Linus Torvalds1da177e2005-04-16 15:20:36 -0700946 * attach and start new elevator
947 */
Jens Axboebc1c1162006-06-08 08:49:06 +0200948 elevator_attach(q, e, data);
949
950 spin_unlock_irq(q->queue_lock);
951
952 __elv_unregister_queue(old_elevator);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700953
954 if (elv_register_queue(q))
955 goto fail_register;
956
957 /*
Tejun Heocb98fc82005-10-28 08:29:39 +0200958 * finally exit old elevator and turn off BYPASS.
Linus Torvalds1da177e2005-04-16 15:20:36 -0700959 */
960 elevator_exit(old_elevator);
Jens Axboe64521d12005-10-28 08:30:39 +0200961 clear_bit(QUEUE_FLAG_ELVSWITCH, &q->queue_flags);
Al Viro3d1ab402006-03-18 18:35:43 -0500962 return 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700963
964fail_register:
965 /*
966 * switch failed, exit the new io scheduler and reattach the old
967 * one again (along with re-adding the sysfs dir)
968 */
969 elevator_exit(e);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700970 q->elevator = old_elevator;
971 elv_register_queue(q);
Jens Axboe64521d12005-10-28 08:30:39 +0200972 clear_bit(QUEUE_FLAG_ELVSWITCH, &q->queue_flags);
Al Viro3d1ab402006-03-18 18:35:43 -0500973 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700974}
975
976ssize_t elv_iosched_store(request_queue_t *q, const char *name, size_t count)
977{
978 char elevator_name[ELV_NAME_MAX];
Tejun Heobe561232005-11-10 08:55:01 +0100979 size_t len;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700980 struct elevator_type *e;
981
Tejun Heobe561232005-11-10 08:55:01 +0100982 elevator_name[sizeof(elevator_name) - 1] = '\0';
983 strncpy(elevator_name, name, sizeof(elevator_name) - 1);
984 len = strlen(elevator_name);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700985
Tejun Heobe561232005-11-10 08:55:01 +0100986 if (len && elevator_name[len - 1] == '\n')
987 elevator_name[len - 1] = '\0';
Linus Torvalds1da177e2005-04-16 15:20:36 -0700988
989 e = elevator_get(elevator_name);
990 if (!e) {
991 printk(KERN_ERR "elevator: type %s not found\n", elevator_name);
992 return -EINVAL;
993 }
994
Nate Diller2ca7d932005-10-30 15:02:24 -0800995 if (!strcmp(elevator_name, q->elevator->elevator_type->elevator_name)) {
996 elevator_put(e);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700997 return count;
Nate Diller2ca7d932005-10-30 15:02:24 -0800998 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700999
Al Viro3d1ab402006-03-18 18:35:43 -05001000 if (!elevator_switch(q, e))
1001 printk(KERN_ERR "elevator: switch to %s failed\n",elevator_name);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001002 return count;
1003}
1004
1005ssize_t elv_iosched_show(request_queue_t *q, char *name)
1006{
1007 elevator_t *e = q->elevator;
1008 struct elevator_type *elv = e->elevator_type;
1009 struct list_head *entry;
1010 int len = 0;
1011
1012 spin_lock_irq(q->queue_lock);
1013 list_for_each(entry, &elv_list) {
1014 struct elevator_type *__e;
1015
1016 __e = list_entry(entry, struct elevator_type, list);
1017 if (!strcmp(elv->elevator_name, __e->elevator_name))
1018 len += sprintf(name+len, "[%s] ", elv->elevator_name);
1019 else
1020 len += sprintf(name+len, "%s ", __e->elevator_name);
1021 }
1022 spin_unlock_irq(q->queue_lock);
1023
1024 len += sprintf(len+name, "\n");
1025 return len;
1026}
1027
Jens Axboe1b47f532005-10-20 16:37:00 +02001028EXPORT_SYMBOL(elv_dispatch_sort);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001029EXPORT_SYMBOL(elv_add_request);
1030EXPORT_SYMBOL(__elv_add_request);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001031EXPORT_SYMBOL(elv_next_request);
Tejun Heo8922e162005-10-20 16:23:44 +02001032EXPORT_SYMBOL(elv_dequeue_request);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001033EXPORT_SYMBOL(elv_queue_empty);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001034EXPORT_SYMBOL(elevator_exit);
1035EXPORT_SYMBOL(elevator_init);