2fc269f69726d67e7a8ab7bcf6a58e2a10af009b
[linux-3.10.git] / block / elevator.c
1 /*
2  *  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>
30 #include <linux/config.h>
31 #include <linux/module.h>
32 #include <linux/slab.h>
33 #include <linux/init.h>
34 #include <linux/compiler.h>
35 #include <linux/delay.h>
36
37 #include <asm/uaccess.h>
38
39 static DEFINE_SPINLOCK(elv_list_lock);
40 static LIST_HEAD(elv_list);
41
42 /*
43  * can we safely merge with this request?
44  */
45 inline int elv_rq_merge_ok(struct request *rq, struct bio *bio)
46 {
47         if (!rq_mergeable(rq))
48                 return 0;
49
50         /*
51          * different data direction or already started, don't merge
52          */
53         if (bio_data_dir(bio) != rq_data_dir(rq))
54                 return 0;
55
56         /*
57          * same device and no special stuff set, merge is ok
58          */
59         if (rq->rq_disk == bio->bi_bdev->bd_disk &&
60             !rq->waiting && !rq->special)
61                 return 1;
62
63         return 0;
64 }
65 EXPORT_SYMBOL(elv_rq_merge_ok);
66
67 static inline int elv_try_merge(struct request *__rq, struct bio *bio)
68 {
69         int ret = ELEVATOR_NO_MERGE;
70
71         /*
72          * we can merge and sequence is ok, check if it's possible
73          */
74         if (elv_rq_merge_ok(__rq, bio)) {
75                 if (__rq->sector + __rq->nr_sectors == bio->bi_sector)
76                         ret = ELEVATOR_BACK_MERGE;
77                 else if (__rq->sector - bio_sectors(bio) == bio->bi_sector)
78                         ret = ELEVATOR_FRONT_MERGE;
79         }
80
81         return ret;
82 }
83
84 static struct elevator_type *elevator_find(const char *name)
85 {
86         struct elevator_type *e = NULL;
87         struct list_head *entry;
88
89         list_for_each(entry, &elv_list) {
90                 struct elevator_type *__e;
91
92                 __e = list_entry(entry, struct elevator_type, list);
93
94                 if (!strcmp(__e->elevator_name, name)) {
95                         e = __e;
96                         break;
97                 }
98         }
99
100         return e;
101 }
102
103 static void elevator_put(struct elevator_type *e)
104 {
105         module_put(e->elevator_owner);
106 }
107
108 static struct elevator_type *elevator_get(const char *name)
109 {
110         struct elevator_type *e;
111
112         spin_lock_irq(&elv_list_lock);
113
114         e = elevator_find(name);
115         if (e && !try_module_get(e->elevator_owner))
116                 e = NULL;
117
118         spin_unlock_irq(&elv_list_lock);
119
120         return e;
121 }
122
123 static int elevator_attach(request_queue_t *q, struct elevator_type *e,
124                            struct elevator_queue *eq)
125 {
126         int ret = 0;
127
128         memset(eq, 0, sizeof(*eq));
129         eq->ops = &e->ops;
130         eq->elevator_type = e;
131
132         q->elevator = eq;
133
134         if (eq->ops->elevator_init_fn)
135                 ret = eq->ops->elevator_init_fn(q, eq);
136
137         return ret;
138 }
139
140 static char chosen_elevator[16];
141
142 static int __init elevator_setup(char *str)
143 {
144         /*
145          * Be backwards-compatible with previous kernels, so users
146          * won't get the wrong elevator.
147          */
148         if (!strcmp(str, "as"))
149                 strcpy(chosen_elevator, "anticipatory");
150         else
151                 strncpy(chosen_elevator, str, sizeof(chosen_elevator) - 1);
152         return 0;
153 }
154
155 __setup("elevator=", elevator_setup);
156
157 int elevator_init(request_queue_t *q, char *name)
158 {
159         struct elevator_type *e = NULL;
160         struct elevator_queue *eq;
161         int ret = 0;
162
163         INIT_LIST_HEAD(&q->queue_head);
164         q->last_merge = NULL;
165         q->end_sector = 0;
166         q->boundary_rq = NULL;
167
168         if (name && !(e = elevator_get(name)))
169                 return -EINVAL;
170
171         if (!e && *chosen_elevator && !(e = elevator_get(chosen_elevator)))
172                 printk("I/O scheduler %s not found\n", chosen_elevator);
173
174         if (!e && !(e = elevator_get(CONFIG_DEFAULT_IOSCHED))) {
175                 printk("Default I/O scheduler not found, using no-op\n");
176                 e = elevator_get("noop");
177         }
178
179         eq = kmalloc(sizeof(struct elevator_queue), GFP_KERNEL);
180         if (!eq) {
181                 elevator_put(e);
182                 return -ENOMEM;
183         }
184
185         ret = elevator_attach(q, e, eq);
186         if (ret) {
187                 kfree(eq);
188                 elevator_put(e);
189         }
190
191         return ret;
192 }
193
194 void elevator_exit(elevator_t *e)
195 {
196         if (e->ops->elevator_exit_fn)
197                 e->ops->elevator_exit_fn(e);
198
199         elevator_put(e->elevator_type);
200         e->elevator_type = NULL;
201         kfree(e);
202 }
203
204 /*
205  * Insert rq into dispatch queue of q.  Queue lock must be held on
206  * entry.  If sort != 0, rq is sort-inserted; otherwise, rq will be
207  * appended to the dispatch queue.  To be used by specific elevators.
208  */
209 void elv_dispatch_sort(request_queue_t *q, struct request *rq)
210 {
211         sector_t boundary;
212         struct list_head *entry;
213
214         if (q->last_merge == rq)
215                 q->last_merge = NULL;
216         q->nr_sorted--;
217
218         boundary = q->end_sector;
219
220         list_for_each_prev(entry, &q->queue_head) {
221                 struct request *pos = list_entry_rq(entry);
222
223                 if (pos->flags & (REQ_SOFTBARRIER|REQ_HARDBARRIER|REQ_STARTED))
224                         break;
225                 if (rq->sector >= boundary) {
226                         if (pos->sector < boundary)
227                                 continue;
228                 } else {
229                         if (pos->sector >= boundary)
230                                 break;
231                 }
232                 if (rq->sector >= pos->sector)
233                         break;
234         }
235
236         list_add(&rq->queuelist, entry);
237 }
238
239 int elv_merge(request_queue_t *q, struct request **req, struct bio *bio)
240 {
241         elevator_t *e = q->elevator;
242         int ret;
243
244         if (q->last_merge) {
245                 ret = elv_try_merge(q->last_merge, bio);
246                 if (ret != ELEVATOR_NO_MERGE) {
247                         *req = q->last_merge;
248                         return ret;
249                 }
250         }
251
252         if (e->ops->elevator_merge_fn)
253                 return e->ops->elevator_merge_fn(q, req, bio);
254
255         return ELEVATOR_NO_MERGE;
256 }
257
258 void elv_merged_request(request_queue_t *q, struct request *rq)
259 {
260         elevator_t *e = q->elevator;
261
262         if (e->ops->elevator_merged_fn)
263                 e->ops->elevator_merged_fn(q, rq);
264
265         q->last_merge = rq;
266 }
267
268 void elv_merge_requests(request_queue_t *q, struct request *rq,
269                              struct request *next)
270 {
271         elevator_t *e = q->elevator;
272
273         if (e->ops->elevator_merge_req_fn)
274                 e->ops->elevator_merge_req_fn(q, rq, next);
275         q->nr_sorted--;
276
277         q->last_merge = rq;
278 }
279
280 void elv_requeue_request(request_queue_t *q, struct request *rq)
281 {
282         elevator_t *e = q->elevator;
283
284         /*
285          * it already went through dequeue, we need to decrement the
286          * in_flight count again
287          */
288         if (blk_account_rq(rq)) {
289                 q->in_flight--;
290                 if (blk_sorted_rq(rq) && e->ops->elevator_deactivate_req_fn)
291                         e->ops->elevator_deactivate_req_fn(q, rq);
292         }
293
294         rq->flags &= ~REQ_STARTED;
295
296         __elv_add_request(q, rq, ELEVATOR_INSERT_REQUEUE, 0);
297 }
298
299 static void elv_drain_elevator(request_queue_t *q)
300 {
301         static int printed;
302         while (q->elevator->ops->elevator_dispatch_fn(q, 1))
303                 ;
304         if (q->nr_sorted == 0)
305                 return;
306         if (printed++ < 10) {
307                 printk(KERN_ERR "%s: forced dispatching is broken "
308                        "(nr_sorted=%u), please report this\n",
309                        q->elevator->elevator_type->elevator_name, q->nr_sorted);
310         }
311 }
312
313 void __elv_add_request(request_queue_t *q, struct request *rq, int where,
314                        int plug)
315 {
316         struct list_head *pos;
317         unsigned ordseq;
318
319         if (q->ordcolor)
320                 rq->flags |= REQ_ORDERED_COLOR;
321
322         if (rq->flags & (REQ_SOFTBARRIER | REQ_HARDBARRIER)) {
323                 /*
324                  * toggle ordered color
325                  */
326                 if (blk_barrier_rq(rq))
327                         q->ordcolor ^= 1;
328
329                 /*
330                  * barriers implicitly indicate back insertion
331                  */
332                 if (where == ELEVATOR_INSERT_SORT)
333                         where = ELEVATOR_INSERT_BACK;
334
335                 /*
336                  * this request is scheduling boundary, update end_sector
337                  */
338                 if (blk_fs_request(rq)) {
339                         q->end_sector = rq_end_sector(rq);
340                         q->boundary_rq = rq;
341                 }
342         } else if (!(rq->flags & REQ_ELVPRIV) && where == ELEVATOR_INSERT_SORT)
343                 where = ELEVATOR_INSERT_BACK;
344
345         if (plug)
346                 blk_plug_device(q);
347
348         rq->q = q;
349
350         switch (where) {
351         case ELEVATOR_INSERT_FRONT:
352                 rq->flags |= REQ_SOFTBARRIER;
353
354                 list_add(&rq->queuelist, &q->queue_head);
355                 break;
356
357         case ELEVATOR_INSERT_BACK:
358                 rq->flags |= REQ_SOFTBARRIER;
359                 elv_drain_elevator(q);
360                 list_add_tail(&rq->queuelist, &q->queue_head);
361                 /*
362                  * We kick the queue here for the following reasons.
363                  * - The elevator might have returned NULL previously
364                  *   to delay requests and returned them now.  As the
365                  *   queue wasn't empty before this request, ll_rw_blk
366                  *   won't run the queue on return, resulting in hang.
367                  * - Usually, back inserted requests won't be merged
368                  *   with anything.  There's no point in delaying queue
369                  *   processing.
370                  */
371                 blk_remove_plug(q);
372                 q->request_fn(q);
373                 break;
374
375         case ELEVATOR_INSERT_SORT:
376                 BUG_ON(!blk_fs_request(rq));
377                 rq->flags |= REQ_SORTED;
378                 q->nr_sorted++;
379                 if (q->last_merge == NULL && rq_mergeable(rq))
380                         q->last_merge = rq;
381                 /*
382                  * Some ioscheds (cfq) run q->request_fn directly, so
383                  * rq cannot be accessed after calling
384                  * elevator_add_req_fn.
385                  */
386                 q->elevator->ops->elevator_add_req_fn(q, rq);
387                 break;
388
389         case ELEVATOR_INSERT_REQUEUE:
390                 /*
391                  * If ordered flush isn't in progress, we do front
392                  * insertion; otherwise, requests should be requeued
393                  * in ordseq order.
394                  */
395                 rq->flags |= REQ_SOFTBARRIER;
396
397                 if (q->ordseq == 0) {
398                         list_add(&rq->queuelist, &q->queue_head);
399                         break;
400                 }
401
402                 ordseq = blk_ordered_req_seq(rq);
403
404                 list_for_each(pos, &q->queue_head) {
405                         struct request *pos_rq = list_entry_rq(pos);
406                         if (ordseq <= blk_ordered_req_seq(pos_rq))
407                                 break;
408                 }
409
410                 list_add_tail(&rq->queuelist, pos);
411                 break;
412
413         default:
414                 printk(KERN_ERR "%s: bad insertion point %d\n",
415                        __FUNCTION__, where);
416                 BUG();
417         }
418
419         if (blk_queue_plugged(q)) {
420                 int nrq = q->rq.count[READ] + q->rq.count[WRITE]
421                         - q->in_flight;
422
423                 if (nrq >= q->unplug_thresh)
424                         __generic_unplug_device(q);
425         }
426 }
427
428 void elv_add_request(request_queue_t *q, struct request *rq, int where,
429                      int plug)
430 {
431         unsigned long flags;
432
433         spin_lock_irqsave(q->queue_lock, flags);
434         __elv_add_request(q, rq, where, plug);
435         spin_unlock_irqrestore(q->queue_lock, flags);
436 }
437
438 static inline struct request *__elv_next_request(request_queue_t *q)
439 {
440         struct request *rq;
441
442         while (1) {
443                 while (!list_empty(&q->queue_head)) {
444                         rq = list_entry_rq(q->queue_head.next);
445                         if (blk_do_ordered(q, &rq))
446                                 return rq;
447                 }
448
449                 if (!q->elevator->ops->elevator_dispatch_fn(q, 0))
450                         return NULL;
451         }
452 }
453
454 struct request *elv_next_request(request_queue_t *q)
455 {
456         struct request *rq;
457         int ret;
458
459         while ((rq = __elv_next_request(q)) != NULL) {
460                 if (!(rq->flags & REQ_STARTED)) {
461                         elevator_t *e = q->elevator;
462
463                         /*
464                          * This is the first time the device driver
465                          * sees this request (possibly after
466                          * requeueing).  Notify IO scheduler.
467                          */
468                         if (blk_sorted_rq(rq) &&
469                             e->ops->elevator_activate_req_fn)
470                                 e->ops->elevator_activate_req_fn(q, rq);
471
472                         /*
473                          * just mark as started even if we don't start
474                          * it, a request that has been delayed should
475                          * not be passed by new incoming requests
476                          */
477                         rq->flags |= REQ_STARTED;
478                 }
479
480                 if (!q->boundary_rq || q->boundary_rq == rq) {
481                         q->end_sector = rq_end_sector(rq);
482                         q->boundary_rq = NULL;
483                 }
484
485                 if ((rq->flags & REQ_DONTPREP) || !q->prep_rq_fn)
486                         break;
487
488                 ret = q->prep_rq_fn(q, rq);
489                 if (ret == BLKPREP_OK) {
490                         break;
491                 } else if (ret == BLKPREP_DEFER) {
492                         /*
493                          * the request may have been (partially) prepped.
494                          * we need to keep this request in the front to
495                          * avoid resource deadlock.  REQ_STARTED will
496                          * prevent other fs requests from passing this one.
497                          */
498                         rq = NULL;
499                         break;
500                 } else if (ret == BLKPREP_KILL) {
501                         int nr_bytes = rq->hard_nr_sectors << 9;
502
503                         if (!nr_bytes)
504                                 nr_bytes = rq->data_len;
505
506                         blkdev_dequeue_request(rq);
507                         rq->flags |= REQ_QUIET;
508                         end_that_request_chunk(rq, 0, nr_bytes);
509                         end_that_request_last(rq, 0);
510                 } else {
511                         printk(KERN_ERR "%s: bad return=%d\n", __FUNCTION__,
512                                                                 ret);
513                         break;
514                 }
515         }
516
517         return rq;
518 }
519
520 void elv_dequeue_request(request_queue_t *q, struct request *rq)
521 {
522         BUG_ON(list_empty(&rq->queuelist));
523
524         list_del_init(&rq->queuelist);
525
526         /*
527          * the time frame between a request being removed from the lists
528          * and to it is freed is accounted as io that is in progress at
529          * the driver side.
530          */
531         if (blk_account_rq(rq))
532                 q->in_flight++;
533 }
534
535 int elv_queue_empty(request_queue_t *q)
536 {
537         elevator_t *e = q->elevator;
538
539         if (!list_empty(&q->queue_head))
540                 return 0;
541
542         if (e->ops->elevator_queue_empty_fn)
543                 return e->ops->elevator_queue_empty_fn(q);
544
545         return 1;
546 }
547
548 struct request *elv_latter_request(request_queue_t *q, struct request *rq)
549 {
550         elevator_t *e = q->elevator;
551
552         if (e->ops->elevator_latter_req_fn)
553                 return e->ops->elevator_latter_req_fn(q, rq);
554         return NULL;
555 }
556
557 struct request *elv_former_request(request_queue_t *q, struct request *rq)
558 {
559         elevator_t *e = q->elevator;
560
561         if (e->ops->elevator_former_req_fn)
562                 return e->ops->elevator_former_req_fn(q, rq);
563         return NULL;
564 }
565
566 int elv_set_request(request_queue_t *q, struct request *rq, struct bio *bio,
567                     gfp_t gfp_mask)
568 {
569         elevator_t *e = q->elevator;
570
571         if (e->ops->elevator_set_req_fn)
572                 return e->ops->elevator_set_req_fn(q, rq, bio, gfp_mask);
573
574         rq->elevator_private = NULL;
575         return 0;
576 }
577
578 void elv_put_request(request_queue_t *q, struct request *rq)
579 {
580         elevator_t *e = q->elevator;
581
582         if (e->ops->elevator_put_req_fn)
583                 e->ops->elevator_put_req_fn(q, rq);
584 }
585
586 int elv_may_queue(request_queue_t *q, int rw, struct bio *bio)
587 {
588         elevator_t *e = q->elevator;
589
590         if (e->ops->elevator_may_queue_fn)
591                 return e->ops->elevator_may_queue_fn(q, rw, bio);
592
593         return ELV_MQUEUE_MAY;
594 }
595
596 void elv_completed_request(request_queue_t *q, struct request *rq)
597 {
598         elevator_t *e = q->elevator;
599
600         /*
601          * request is released from the driver, io must be done
602          */
603         if (blk_account_rq(rq)) {
604                 q->in_flight--;
605                 if (blk_sorted_rq(rq) && e->ops->elevator_completed_req_fn)
606                         e->ops->elevator_completed_req_fn(q, rq);
607         }
608
609         /*
610          * Check if the queue is waiting for fs requests to be
611          * drained for flush sequence.
612          */
613         if (unlikely(q->ordseq)) {
614                 struct request *first_rq = list_entry_rq(q->queue_head.next);
615                 if (q->in_flight == 0 &&
616                     blk_ordered_cur_seq(q) == QUEUE_ORDSEQ_DRAIN &&
617                     blk_ordered_req_seq(first_rq) > QUEUE_ORDSEQ_DRAIN) {
618                         blk_ordered_complete_seq(q, QUEUE_ORDSEQ_DRAIN, 0);
619                         q->request_fn(q);
620                 }
621         }
622 }
623
624 int elv_register_queue(struct request_queue *q)
625 {
626         elevator_t *e = q->elevator;
627
628         e->kobj.parent = kobject_get(&q->kobj);
629         if (!e->kobj.parent)
630                 return -EBUSY;
631
632         snprintf(e->kobj.name, KOBJ_NAME_LEN, "%s", "iosched");
633         e->kobj.ktype = e->elevator_type->elevator_ktype;
634
635         return kobject_register(&e->kobj);
636 }
637
638 void elv_unregister_queue(struct request_queue *q)
639 {
640         if (q) {
641                 elevator_t *e = q->elevator;
642                 kobject_unregister(&e->kobj);
643                 kobject_put(&q->kobj);
644         }
645 }
646
647 int elv_register(struct elevator_type *e)
648 {
649         spin_lock_irq(&elv_list_lock);
650         if (elevator_find(e->elevator_name))
651                 BUG();
652         list_add_tail(&e->list, &elv_list);
653         spin_unlock_irq(&elv_list_lock);
654
655         printk(KERN_INFO "io scheduler %s registered", e->elevator_name);
656         if (!strcmp(e->elevator_name, chosen_elevator) ||
657                         (!*chosen_elevator &&
658                          !strcmp(e->elevator_name, CONFIG_DEFAULT_IOSCHED)))
659                                 printk(" (default)");
660         printk("\n");
661         return 0;
662 }
663 EXPORT_SYMBOL_GPL(elv_register);
664
665 void elv_unregister(struct elevator_type *e)
666 {
667         struct task_struct *g, *p;
668
669         /*
670          * Iterate every thread in the process to remove the io contexts.
671          */
672         read_lock(&tasklist_lock);
673         do_each_thread(g, p) {
674                 struct io_context *ioc = p->io_context;
675                 if (ioc && ioc->cic) {
676                         ioc->cic->exit(ioc->cic);
677                         ioc->cic->dtor(ioc->cic);
678                         ioc->cic = NULL;
679                 }
680                 if (ioc && ioc->aic) {
681                         ioc->aic->exit(ioc->aic);
682                         ioc->aic->dtor(ioc->aic);
683                         ioc->aic = NULL;
684                 }
685         } while_each_thread(g, p);
686         read_unlock(&tasklist_lock);
687
688         spin_lock_irq(&elv_list_lock);
689         list_del_init(&e->list);
690         spin_unlock_irq(&elv_list_lock);
691 }
692 EXPORT_SYMBOL_GPL(elv_unregister);
693
694 /*
695  * switch to new_e io scheduler. be careful not to introduce deadlocks -
696  * we don't free the old io scheduler, before we have allocated what we
697  * need for the new one. this way we have a chance of going back to the old
698  * one, if the new one fails init for some reason.
699  */
700 static void elevator_switch(request_queue_t *q, struct elevator_type *new_e)
701 {
702         elevator_t *old_elevator, *e;
703
704         /*
705          * Allocate new elevator
706          */
707         e = kmalloc(sizeof(elevator_t), GFP_KERNEL);
708         if (!e)
709                 goto error;
710
711         /*
712          * Turn on BYPASS and drain all requests w/ elevator private data
713          */
714         spin_lock_irq(q->queue_lock);
715
716         set_bit(QUEUE_FLAG_ELVSWITCH, &q->queue_flags);
717
718         elv_drain_elevator(q);
719
720         while (q->rq.elvpriv) {
721                 blk_remove_plug(q);
722                 q->request_fn(q);
723                 spin_unlock_irq(q->queue_lock);
724                 msleep(10);
725                 spin_lock_irq(q->queue_lock);
726                 elv_drain_elevator(q);
727         }
728
729         spin_unlock_irq(q->queue_lock);
730
731         /*
732          * unregister old elevator data
733          */
734         elv_unregister_queue(q);
735         old_elevator = q->elevator;
736
737         /*
738          * attach and start new elevator
739          */
740         if (elevator_attach(q, new_e, e))
741                 goto fail;
742
743         if (elv_register_queue(q))
744                 goto fail_register;
745
746         /*
747          * finally exit old elevator and turn off BYPASS.
748          */
749         elevator_exit(old_elevator);
750         clear_bit(QUEUE_FLAG_ELVSWITCH, &q->queue_flags);
751         return;
752
753 fail_register:
754         /*
755          * switch failed, exit the new io scheduler and reattach the old
756          * one again (along with re-adding the sysfs dir)
757          */
758         elevator_exit(e);
759         e = NULL;
760 fail:
761         q->elevator = old_elevator;
762         elv_register_queue(q);
763         clear_bit(QUEUE_FLAG_ELVSWITCH, &q->queue_flags);
764         kfree(e);
765 error:
766         elevator_put(new_e);
767         printk(KERN_ERR "elevator: switch to %s failed\n",new_e->elevator_name);
768 }
769
770 ssize_t elv_iosched_store(request_queue_t *q, const char *name, size_t count)
771 {
772         char elevator_name[ELV_NAME_MAX];
773         size_t len;
774         struct elevator_type *e;
775
776         elevator_name[sizeof(elevator_name) - 1] = '\0';
777         strncpy(elevator_name, name, sizeof(elevator_name) - 1);
778         len = strlen(elevator_name);
779
780         if (len && elevator_name[len - 1] == '\n')
781                 elevator_name[len - 1] = '\0';
782
783         e = elevator_get(elevator_name);
784         if (!e) {
785                 printk(KERN_ERR "elevator: type %s not found\n", elevator_name);
786                 return -EINVAL;
787         }
788
789         if (!strcmp(elevator_name, q->elevator->elevator_type->elevator_name)) {
790                 elevator_put(e);
791                 return count;
792         }
793
794         elevator_switch(q, e);
795         return count;
796 }
797
798 ssize_t elv_iosched_show(request_queue_t *q, char *name)
799 {
800         elevator_t *e = q->elevator;
801         struct elevator_type *elv = e->elevator_type;
802         struct list_head *entry;
803         int len = 0;
804
805         spin_lock_irq(q->queue_lock);
806         list_for_each(entry, &elv_list) {
807                 struct elevator_type *__e;
808
809                 __e = list_entry(entry, struct elevator_type, list);
810                 if (!strcmp(elv->elevator_name, __e->elevator_name))
811                         len += sprintf(name+len, "[%s] ", elv->elevator_name);
812                 else
813                         len += sprintf(name+len, "%s ", __e->elevator_name);
814         }
815         spin_unlock_irq(q->queue_lock);
816
817         len += sprintf(len+name, "\n");
818         return len;
819 }
820
821 EXPORT_SYMBOL(elv_dispatch_sort);
822 EXPORT_SYMBOL(elv_add_request);
823 EXPORT_SYMBOL(__elv_add_request);
824 EXPORT_SYMBOL(elv_requeue_request);
825 EXPORT_SYMBOL(elv_next_request);
826 EXPORT_SYMBOL(elv_dequeue_request);
827 EXPORT_SYMBOL(elv_queue_empty);
828 EXPORT_SYMBOL(elv_completed_request);
829 EXPORT_SYMBOL(elevator_exit);
830 EXPORT_SYMBOL(elevator_init);