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