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