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 | * |
Jens Axboe | 0fe2347 | 2006-09-04 15:41:16 +0200 | [diff] [blame] | 6 | * 30042000 Jens Axboe <axboe@kernel.dk> : |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7 | * |
| 8 | * Split the elevator a bit so that it is possible to choose a different |
| 9 | * one or even write a new "plug in". There are three pieces: |
| 10 | * - elevator_fn, inserts a new request in the queue list |
| 11 | * - elevator_merge_fn, decides whether a new buffer can be merged with |
| 12 | * an existing request |
| 13 | * - elevator_dequeue_fn, called when a request is taken off the active list |
| 14 | * |
| 15 | * 20082000 Dave Jones <davej@suse.de> : |
| 16 | * Removed tests for max-bomb-segments, which was breaking elvtune |
| 17 | * when run without -bN |
| 18 | * |
| 19 | * Jens: |
| 20 | * - Rework again to work with bio instead of buffer_heads |
| 21 | * - loose bi_dev comparisons, partition handling is right now |
| 22 | * - completely modularize elevator setup and teardown |
| 23 | * |
| 24 | */ |
| 25 | #include <linux/kernel.h> |
| 26 | #include <linux/fs.h> |
| 27 | #include <linux/blkdev.h> |
| 28 | #include <linux/elevator.h> |
| 29 | #include <linux/bio.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 30 | #include <linux/module.h> |
| 31 | #include <linux/slab.h> |
| 32 | #include <linux/init.h> |
| 33 | #include <linux/compiler.h> |
Jens Axboe | 2056a78 | 2006-03-23 20:00:26 +0100 | [diff] [blame] | 34 | #include <linux/blktrace_api.h> |
Jens Axboe | 9817064 | 2006-07-28 09:23:08 +0200 | [diff] [blame] | 35 | #include <linux/hash.h> |
Jens Axboe | 0835da6 | 2008-08-26 09:15:47 +0200 | [diff] [blame] | 36 | #include <linux/uaccess.h> |
Lin Ming | 0fb59e5 | 2013-03-23 11:42:27 +0800 | [diff] [blame] | 37 | #include <linux/pm_runtime.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 38 | |
Li Zefan | 5578213 | 2009-06-09 13:43:05 +0800 | [diff] [blame] | 39 | #include <trace/events/block.h> |
| 40 | |
Jens Axboe | 242f9dc | 2008-09-14 05:55:09 -0700 | [diff] [blame] | 41 | #include "blk.h" |
| 42 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 43 | static DEFINE_SPINLOCK(elv_list_lock); |
| 44 | static LIST_HEAD(elv_list); |
| 45 | |
| 46 | /* |
Jens Axboe | 9817064 | 2006-07-28 09:23:08 +0200 | [diff] [blame] | 47 | * Merge hash stuff. |
| 48 | */ |
| 49 | static const int elv_hash_shift = 6; |
| 50 | #define ELV_HASH_BLOCK(sec) ((sec) >> 3) |
Jens Axboe | 4eb166d | 2008-02-01 00:37:27 +0100 | [diff] [blame] | 51 | #define ELV_HASH_FN(sec) \ |
| 52 | (hash_long(ELV_HASH_BLOCK((sec)), elv_hash_shift)) |
Jens Axboe | 9817064 | 2006-07-28 09:23:08 +0200 | [diff] [blame] | 53 | #define ELV_HASH_ENTRIES (1 << elv_hash_shift) |
Tejun Heo | 83096eb | 2009-05-07 22:24:39 +0900 | [diff] [blame] | 54 | #define rq_hash_key(rq) (blk_rq_pos(rq) + blk_rq_sectors(rq)) |
Jens Axboe | 9817064 | 2006-07-28 09:23:08 +0200 | [diff] [blame] | 55 | |
| 56 | /* |
Jens Axboe | da77526 | 2006-12-20 11:04:12 +0100 | [diff] [blame] | 57 | * Query io scheduler to see if the current process issuing bio may be |
| 58 | * merged with rq. |
| 59 | */ |
| 60 | static int elv_iosched_allow_merge(struct request *rq, struct bio *bio) |
| 61 | { |
Jens Axboe | 165125e | 2007-07-24 09:28:11 +0200 | [diff] [blame] | 62 | struct request_queue *q = rq->q; |
Jens Axboe | b374d18 | 2008-10-31 10:05:07 +0100 | [diff] [blame] | 63 | struct elevator_queue *e = q->elevator; |
Jens Axboe | da77526 | 2006-12-20 11:04:12 +0100 | [diff] [blame] | 64 | |
Tejun Heo | 22f746e | 2011-12-14 00:33:41 +0100 | [diff] [blame] | 65 | if (e->type->ops.elevator_allow_merge_fn) |
| 66 | return e->type->ops.elevator_allow_merge_fn(q, rq, bio); |
Jens Axboe | da77526 | 2006-12-20 11:04:12 +0100 | [diff] [blame] | 67 | |
| 68 | return 1; |
| 69 | } |
| 70 | |
| 71 | /* |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 72 | * can we safely merge with this request? |
| 73 | */ |
Tejun Heo | 050c8ea | 2012-02-08 09:19:38 +0100 | [diff] [blame] | 74 | bool elv_rq_merge_ok(struct request *rq, struct bio *bio) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 75 | { |
| 76 | if (!rq_mergeable(rq)) |
| 77 | return 0; |
| 78 | |
| 79 | /* |
David Woodhouse | e17fc0a | 2008-08-09 16:42:20 +0100 | [diff] [blame] | 80 | * Don't merge file system requests and discard requests |
| 81 | */ |
Christoph Hellwig | 7b6d91d | 2010-08-07 18:20:39 +0200 | [diff] [blame] | 82 | if ((bio->bi_rw & REQ_DISCARD) != (rq->bio->bi_rw & REQ_DISCARD)) |
David Woodhouse | e17fc0a | 2008-08-09 16:42:20 +0100 | [diff] [blame] | 83 | return 0; |
| 84 | |
| 85 | /* |
Adrian Hunter | 8d57a98 | 2010-08-11 14:17:49 -0700 | [diff] [blame] | 86 | * Don't merge discard requests and secure discard requests |
| 87 | */ |
| 88 | if ((bio->bi_rw & REQ_SECURE) != (rq->bio->bi_rw & REQ_SECURE)) |
| 89 | return 0; |
| 90 | |
| 91 | /* |
Maya Erez | 73937f5 | 2012-05-24 23:33:05 +0300 | [diff] [blame] | 92 | * Don't merge sanitize requests |
| 93 | */ |
| 94 | if ((bio->bi_rw & REQ_SANITIZE) != (rq->bio->bi_rw & REQ_SANITIZE)) |
| 95 | return 0; |
| 96 | |
| 97 | /* |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 98 | * different data direction or already started, don't merge |
| 99 | */ |
| 100 | if (bio_data_dir(bio) != rq_data_dir(rq)) |
| 101 | return 0; |
| 102 | |
| 103 | /* |
Jens Axboe | da77526 | 2006-12-20 11:04:12 +0100 | [diff] [blame] | 104 | * must be same device and not a special request |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 105 | */ |
Jens Axboe | bb4067e | 2006-12-21 21:20:01 +0100 | [diff] [blame] | 106 | if (rq->rq_disk != bio->bi_bdev->bd_disk || rq->special) |
Jens Axboe | da77526 | 2006-12-20 11:04:12 +0100 | [diff] [blame] | 107 | return 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 108 | |
Martin K. Petersen | 7ba1ba1 | 2008-06-30 20:04:41 +0200 | [diff] [blame] | 109 | /* |
| 110 | * only merge integrity protected bio into ditto rq |
| 111 | */ |
| 112 | if (bio_integrity(bio) != blk_integrity_rq(rq)) |
| 113 | return 0; |
| 114 | |
Jens Axboe | da77526 | 2006-12-20 11:04:12 +0100 | [diff] [blame] | 115 | if (!elv_iosched_allow_merge(rq, bio)) |
| 116 | return 0; |
| 117 | |
| 118 | return 1; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 119 | } |
| 120 | EXPORT_SYMBOL(elv_rq_merge_ok); |
| 121 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 122 | static struct elevator_type *elevator_find(const char *name) |
| 123 | { |
Vasily Tarasov | a22b169 | 2006-10-11 09:24:27 +0200 | [diff] [blame] | 124 | struct elevator_type *e; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 125 | |
Matthias Kaehlcke | 70cee26 | 2007-07-10 12:26:24 +0200 | [diff] [blame] | 126 | list_for_each_entry(e, &elv_list, list) { |
Vasily Tarasov | a22b169 | 2006-10-11 09:24:27 +0200 | [diff] [blame] | 127 | if (!strcmp(e->elevator_name, name)) |
| 128 | return e; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 129 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 130 | |
Vasily Tarasov | a22b169 | 2006-10-11 09:24:27 +0200 | [diff] [blame] | 131 | return NULL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 132 | } |
| 133 | |
| 134 | static void elevator_put(struct elevator_type *e) |
| 135 | { |
| 136 | module_put(e->elevator_owner); |
| 137 | } |
| 138 | |
| 139 | static struct elevator_type *elevator_get(const char *name) |
| 140 | { |
Tejun Heo | 2824bc93 | 2005-10-20 10:56:41 +0200 | [diff] [blame] | 141 | struct elevator_type *e; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 142 | |
Jens Axboe | 2a12dcd | 2007-04-26 14:41:53 +0200 | [diff] [blame] | 143 | spin_lock(&elv_list_lock); |
Tejun Heo | 2824bc93 | 2005-10-20 10:56:41 +0200 | [diff] [blame] | 144 | |
| 145 | e = elevator_find(name); |
Jens Axboe | e164094 | 2008-02-19 10:20:37 +0100 | [diff] [blame] | 146 | if (!e) { |
Jens Axboe | e164094 | 2008-02-19 10:20:37 +0100 | [diff] [blame] | 147 | spin_unlock(&elv_list_lock); |
Kees Cook | 490b94b | 2011-05-05 18:02:12 -0600 | [diff] [blame] | 148 | request_module("%s-iosched", name); |
Jens Axboe | e164094 | 2008-02-19 10:20:37 +0100 | [diff] [blame] | 149 | spin_lock(&elv_list_lock); |
| 150 | e = elevator_find(name); |
| 151 | } |
| 152 | |
Tejun Heo | 2824bc93 | 2005-10-20 10:56:41 +0200 | [diff] [blame] | 153 | if (e && !try_module_get(e->elevator_owner)) |
| 154 | e = NULL; |
| 155 | |
Jens Axboe | 2a12dcd | 2007-04-26 14:41:53 +0200 | [diff] [blame] | 156 | spin_unlock(&elv_list_lock); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 157 | |
| 158 | return e; |
| 159 | } |
| 160 | |
Tejun Heo | f8fc877 | 2011-12-14 00:33:40 +0100 | [diff] [blame] | 161 | static int elevator_init_queue(struct request_queue *q, |
| 162 | struct elevator_queue *eq) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 163 | { |
Tejun Heo | 22f746e | 2011-12-14 00:33:41 +0100 | [diff] [blame] | 164 | eq->elevator_data = eq->type->ops.elevator_init_fn(q); |
Tejun Heo | f8fc877 | 2011-12-14 00:33:40 +0100 | [diff] [blame] | 165 | if (eq->elevator_data) |
| 166 | return 0; |
| 167 | return -ENOMEM; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 168 | } |
| 169 | |
Wang Sheng-Hui | 484fc25 | 2011-09-08 12:32:14 +0200 | [diff] [blame] | 170 | static char chosen_elevator[ELV_NAME_MAX]; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 171 | |
Nate Diller | 5f00397 | 2006-01-24 10:07:58 +0100 | [diff] [blame] | 172 | static int __init elevator_setup(char *str) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 173 | { |
Chuck Ebbert | 752a3b7 | 2006-01-16 09:47:37 +0100 | [diff] [blame] | 174 | /* |
| 175 | * Be backwards-compatible with previous kernels, so users |
| 176 | * won't get the wrong elevator. |
| 177 | */ |
Jens Axboe | 492af63 | 2009-10-03 09:37:51 +0200 | [diff] [blame] | 178 | strncpy(chosen_elevator, str, sizeof(chosen_elevator) - 1); |
OGAWA Hirofumi | 9b41046 | 2006-03-31 02:30:33 -0800 | [diff] [blame] | 179 | return 1; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 180 | } |
| 181 | |
| 182 | __setup("elevator=", elevator_setup); |
| 183 | |
Al Viro | 3d1ab40 | 2006-03-18 18:35:43 -0500 | [diff] [blame] | 184 | static struct kobj_type elv_ktype; |
| 185 | |
Jens Axboe | b374d18 | 2008-10-31 10:05:07 +0100 | [diff] [blame] | 186 | static struct elevator_queue *elevator_alloc(struct request_queue *q, |
Jens Axboe | 165125e | 2007-07-24 09:28:11 +0200 | [diff] [blame] | 187 | struct elevator_type *e) |
Al Viro | 3d1ab40 | 2006-03-18 18:35:43 -0500 | [diff] [blame] | 188 | { |
Jens Axboe | b374d18 | 2008-10-31 10:05:07 +0100 | [diff] [blame] | 189 | struct elevator_queue *eq; |
Jens Axboe | 9817064 | 2006-07-28 09:23:08 +0200 | [diff] [blame] | 190 | int i; |
| 191 | |
Jens Axboe | b374d18 | 2008-10-31 10:05:07 +0100 | [diff] [blame] | 192 | eq = kmalloc_node(sizeof(*eq), GFP_KERNEL | __GFP_ZERO, q->node); |
Jens Axboe | 9817064 | 2006-07-28 09:23:08 +0200 | [diff] [blame] | 193 | if (unlikely(!eq)) |
| 194 | goto err; |
| 195 | |
Tejun Heo | 22f746e | 2011-12-14 00:33:41 +0100 | [diff] [blame] | 196 | eq->type = e; |
Greg Kroah-Hartman | f9cb074 | 2007-12-17 23:05:35 -0700 | [diff] [blame] | 197 | kobject_init(&eq->kobj, &elv_ktype); |
Jens Axboe | 9817064 | 2006-07-28 09:23:08 +0200 | [diff] [blame] | 198 | mutex_init(&eq->sysfs_lock); |
| 199 | |
Jens Axboe | b5deef9 | 2006-07-19 23:39:40 +0200 | [diff] [blame] | 200 | eq->hash = kmalloc_node(sizeof(struct hlist_head) * ELV_HASH_ENTRIES, |
| 201 | GFP_KERNEL, q->node); |
Jens Axboe | 9817064 | 2006-07-28 09:23:08 +0200 | [diff] [blame] | 202 | if (!eq->hash) |
| 203 | goto err; |
| 204 | |
| 205 | for (i = 0; i < ELV_HASH_ENTRIES; i++) |
| 206 | INIT_HLIST_HEAD(&eq->hash[i]); |
| 207 | |
Al Viro | 3d1ab40 | 2006-03-18 18:35:43 -0500 | [diff] [blame] | 208 | return eq; |
Jens Axboe | 9817064 | 2006-07-28 09:23:08 +0200 | [diff] [blame] | 209 | err: |
| 210 | kfree(eq); |
| 211 | elevator_put(e); |
| 212 | return NULL; |
Al Viro | 3d1ab40 | 2006-03-18 18:35:43 -0500 | [diff] [blame] | 213 | } |
| 214 | |
| 215 | static void elevator_release(struct kobject *kobj) |
| 216 | { |
Jens Axboe | b374d18 | 2008-10-31 10:05:07 +0100 | [diff] [blame] | 217 | struct elevator_queue *e; |
Jens Axboe | 9817064 | 2006-07-28 09:23:08 +0200 | [diff] [blame] | 218 | |
Jens Axboe | b374d18 | 2008-10-31 10:05:07 +0100 | [diff] [blame] | 219 | e = container_of(kobj, struct elevator_queue, kobj); |
Tejun Heo | 22f746e | 2011-12-14 00:33:41 +0100 | [diff] [blame] | 220 | elevator_put(e->type); |
Jens Axboe | 9817064 | 2006-07-28 09:23:08 +0200 | [diff] [blame] | 221 | kfree(e->hash); |
Al Viro | 3d1ab40 | 2006-03-18 18:35:43 -0500 | [diff] [blame] | 222 | kfree(e); |
| 223 | } |
| 224 | |
Jens Axboe | 165125e | 2007-07-24 09:28:11 +0200 | [diff] [blame] | 225 | int elevator_init(struct request_queue *q, char *name) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 226 | { |
| 227 | struct elevator_type *e = NULL; |
| 228 | struct elevator_queue *eq; |
Tejun Heo | f8fc877 | 2011-12-14 00:33:40 +0100 | [diff] [blame] | 229 | int err; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 230 | |
Mike Snitzer | 1abec4f | 2010-05-25 13:15:15 -0400 | [diff] [blame] | 231 | if (unlikely(q->elevator)) |
| 232 | return 0; |
| 233 | |
Tejun Heo | cb98fc8 | 2005-10-28 08:29:39 +0200 | [diff] [blame] | 234 | INIT_LIST_HEAD(&q->queue_head); |
| 235 | q->last_merge = NULL; |
| 236 | q->end_sector = 0; |
| 237 | q->boundary_rq = NULL; |
Tejun Heo | cb98fc8 | 2005-10-28 08:29:39 +0200 | [diff] [blame] | 238 | |
Jens Axboe | 4eb166d | 2008-02-01 00:37:27 +0100 | [diff] [blame] | 239 | if (name) { |
| 240 | e = elevator_get(name); |
| 241 | if (!e) |
| 242 | return -EINVAL; |
| 243 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 244 | |
Jens Axboe | 4eb166d | 2008-02-01 00:37:27 +0100 | [diff] [blame] | 245 | if (!e && *chosen_elevator) { |
| 246 | e = elevator_get(chosen_elevator); |
| 247 | if (!e) |
| 248 | printk(KERN_ERR "I/O scheduler %s not found\n", |
| 249 | chosen_elevator); |
| 250 | } |
Nate Diller | 248d5ca | 2006-01-24 10:09:14 +0100 | [diff] [blame] | 251 | |
Jens Axboe | 4eb166d | 2008-02-01 00:37:27 +0100 | [diff] [blame] | 252 | if (!e) { |
| 253 | e = elevator_get(CONFIG_DEFAULT_IOSCHED); |
| 254 | if (!e) { |
| 255 | printk(KERN_ERR |
| 256 | "Default I/O scheduler not found. " \ |
| 257 | "Using noop.\n"); |
| 258 | e = elevator_get("noop"); |
| 259 | } |
Nate Diller | 5f00397 | 2006-01-24 10:07:58 +0100 | [diff] [blame] | 260 | } |
| 261 | |
Jens Axboe | b5deef9 | 2006-07-19 23:39:40 +0200 | [diff] [blame] | 262 | eq = elevator_alloc(q, e); |
Al Viro | 3d1ab40 | 2006-03-18 18:35:43 -0500 | [diff] [blame] | 263 | if (!eq) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 264 | return -ENOMEM; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 265 | |
Tejun Heo | f8fc877 | 2011-12-14 00:33:40 +0100 | [diff] [blame] | 266 | err = elevator_init_queue(q, eq); |
| 267 | if (err) { |
Al Viro | 3d1ab40 | 2006-03-18 18:35:43 -0500 | [diff] [blame] | 268 | kobject_put(&eq->kobj); |
Tejun Heo | f8fc877 | 2011-12-14 00:33:40 +0100 | [diff] [blame] | 269 | return err; |
Jens Axboe | bc1c116 | 2006-06-08 08:49:06 +0200 | [diff] [blame] | 270 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 271 | |
Tejun Heo | f8fc877 | 2011-12-14 00:33:40 +0100 | [diff] [blame] | 272 | q->elevator = eq; |
Mike Snitzer | 1abec4f | 2010-05-25 13:15:15 -0400 | [diff] [blame] | 273 | return 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 274 | } |
Jens Axboe | 2e662b6 | 2006-07-13 11:55:04 +0200 | [diff] [blame] | 275 | EXPORT_SYMBOL(elevator_init); |
| 276 | |
Jens Axboe | b374d18 | 2008-10-31 10:05:07 +0100 | [diff] [blame] | 277 | void elevator_exit(struct elevator_queue *e) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 278 | { |
Al Viro | 3d1ab40 | 2006-03-18 18:35:43 -0500 | [diff] [blame] | 279 | mutex_lock(&e->sysfs_lock); |
Tejun Heo | 22f746e | 2011-12-14 00:33:41 +0100 | [diff] [blame] | 280 | if (e->type->ops.elevator_exit_fn) |
| 281 | e->type->ops.elevator_exit_fn(e); |
Al Viro | 3d1ab40 | 2006-03-18 18:35:43 -0500 | [diff] [blame] | 282 | mutex_unlock(&e->sysfs_lock); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 283 | |
Al Viro | 3d1ab40 | 2006-03-18 18:35:43 -0500 | [diff] [blame] | 284 | kobject_put(&e->kobj); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 285 | } |
Jens Axboe | 2e662b6 | 2006-07-13 11:55:04 +0200 | [diff] [blame] | 286 | EXPORT_SYMBOL(elevator_exit); |
| 287 | |
Jens Axboe | 9817064 | 2006-07-28 09:23:08 +0200 | [diff] [blame] | 288 | static inline void __elv_rqhash_del(struct request *rq) |
| 289 | { |
| 290 | hlist_del_init(&rq->hash); |
| 291 | } |
| 292 | |
Jens Axboe | 165125e | 2007-07-24 09:28:11 +0200 | [diff] [blame] | 293 | static void elv_rqhash_del(struct request_queue *q, struct request *rq) |
Jens Axboe | 9817064 | 2006-07-28 09:23:08 +0200 | [diff] [blame] | 294 | { |
| 295 | if (ELV_ON_HASH(rq)) |
| 296 | __elv_rqhash_del(rq); |
| 297 | } |
| 298 | |
Jens Axboe | 165125e | 2007-07-24 09:28:11 +0200 | [diff] [blame] | 299 | static void elv_rqhash_add(struct request_queue *q, struct request *rq) |
Jens Axboe | 9817064 | 2006-07-28 09:23:08 +0200 | [diff] [blame] | 300 | { |
Jens Axboe | b374d18 | 2008-10-31 10:05:07 +0100 | [diff] [blame] | 301 | struct elevator_queue *e = q->elevator; |
Jens Axboe | 9817064 | 2006-07-28 09:23:08 +0200 | [diff] [blame] | 302 | |
| 303 | BUG_ON(ELV_ON_HASH(rq)); |
| 304 | hlist_add_head(&rq->hash, &e->hash[ELV_HASH_FN(rq_hash_key(rq))]); |
| 305 | } |
| 306 | |
Jens Axboe | 165125e | 2007-07-24 09:28:11 +0200 | [diff] [blame] | 307 | static void elv_rqhash_reposition(struct request_queue *q, struct request *rq) |
Jens Axboe | 9817064 | 2006-07-28 09:23:08 +0200 | [diff] [blame] | 308 | { |
| 309 | __elv_rqhash_del(rq); |
| 310 | elv_rqhash_add(q, rq); |
| 311 | } |
| 312 | |
Jens Axboe | 165125e | 2007-07-24 09:28:11 +0200 | [diff] [blame] | 313 | static struct request *elv_rqhash_find(struct request_queue *q, sector_t offset) |
Jens Axboe | 9817064 | 2006-07-28 09:23:08 +0200 | [diff] [blame] | 314 | { |
Jens Axboe | b374d18 | 2008-10-31 10:05:07 +0100 | [diff] [blame] | 315 | struct elevator_queue *e = q->elevator; |
Jens Axboe | 9817064 | 2006-07-28 09:23:08 +0200 | [diff] [blame] | 316 | struct hlist_head *hash_list = &e->hash[ELV_HASH_FN(offset)]; |
| 317 | struct hlist_node *entry, *next; |
| 318 | struct request *rq; |
| 319 | |
| 320 | hlist_for_each_entry_safe(rq, entry, next, hash_list, hash) { |
| 321 | BUG_ON(!ELV_ON_HASH(rq)); |
| 322 | |
| 323 | if (unlikely(!rq_mergeable(rq))) { |
| 324 | __elv_rqhash_del(rq); |
| 325 | continue; |
| 326 | } |
| 327 | |
| 328 | if (rq_hash_key(rq) == offset) |
| 329 | return rq; |
| 330 | } |
| 331 | |
| 332 | return NULL; |
| 333 | } |
| 334 | |
Tejun Heo | 8922e16 | 2005-10-20 16:23:44 +0200 | [diff] [blame] | 335 | /* |
Jens Axboe | 2e662b6 | 2006-07-13 11:55:04 +0200 | [diff] [blame] | 336 | * RB-tree support functions for inserting/lookup/removal of requests |
| 337 | * in a sorted RB tree. |
| 338 | */ |
Jeff Moyer | 796d511 | 2011-06-02 21:19:05 +0200 | [diff] [blame] | 339 | void elv_rb_add(struct rb_root *root, struct request *rq) |
Jens Axboe | 2e662b6 | 2006-07-13 11:55:04 +0200 | [diff] [blame] | 340 | { |
| 341 | struct rb_node **p = &root->rb_node; |
| 342 | struct rb_node *parent = NULL; |
| 343 | struct request *__rq; |
| 344 | |
| 345 | while (*p) { |
| 346 | parent = *p; |
| 347 | __rq = rb_entry(parent, struct request, rb_node); |
| 348 | |
Tejun Heo | 83096eb | 2009-05-07 22:24:39 +0900 | [diff] [blame] | 349 | if (blk_rq_pos(rq) < blk_rq_pos(__rq)) |
Jens Axboe | 2e662b6 | 2006-07-13 11:55:04 +0200 | [diff] [blame] | 350 | p = &(*p)->rb_left; |
Jeff Moyer | 796d511 | 2011-06-02 21:19:05 +0200 | [diff] [blame] | 351 | else if (blk_rq_pos(rq) >= blk_rq_pos(__rq)) |
Jens Axboe | 2e662b6 | 2006-07-13 11:55:04 +0200 | [diff] [blame] | 352 | p = &(*p)->rb_right; |
Jens Axboe | 2e662b6 | 2006-07-13 11:55:04 +0200 | [diff] [blame] | 353 | } |
| 354 | |
| 355 | rb_link_node(&rq->rb_node, parent, p); |
| 356 | rb_insert_color(&rq->rb_node, root); |
Jens Axboe | 2e662b6 | 2006-07-13 11:55:04 +0200 | [diff] [blame] | 357 | } |
Jens Axboe | 2e662b6 | 2006-07-13 11:55:04 +0200 | [diff] [blame] | 358 | EXPORT_SYMBOL(elv_rb_add); |
| 359 | |
| 360 | void elv_rb_del(struct rb_root *root, struct request *rq) |
| 361 | { |
| 362 | BUG_ON(RB_EMPTY_NODE(&rq->rb_node)); |
| 363 | rb_erase(&rq->rb_node, root); |
| 364 | RB_CLEAR_NODE(&rq->rb_node); |
| 365 | } |
Jens Axboe | 2e662b6 | 2006-07-13 11:55:04 +0200 | [diff] [blame] | 366 | EXPORT_SYMBOL(elv_rb_del); |
| 367 | |
| 368 | struct request *elv_rb_find(struct rb_root *root, sector_t sector) |
| 369 | { |
| 370 | struct rb_node *n = root->rb_node; |
| 371 | struct request *rq; |
| 372 | |
| 373 | while (n) { |
| 374 | rq = rb_entry(n, struct request, rb_node); |
| 375 | |
Tejun Heo | 83096eb | 2009-05-07 22:24:39 +0900 | [diff] [blame] | 376 | if (sector < blk_rq_pos(rq)) |
Jens Axboe | 2e662b6 | 2006-07-13 11:55:04 +0200 | [diff] [blame] | 377 | n = n->rb_left; |
Tejun Heo | 83096eb | 2009-05-07 22:24:39 +0900 | [diff] [blame] | 378 | else if (sector > blk_rq_pos(rq)) |
Jens Axboe | 2e662b6 | 2006-07-13 11:55:04 +0200 | [diff] [blame] | 379 | n = n->rb_right; |
| 380 | else |
| 381 | return rq; |
| 382 | } |
| 383 | |
| 384 | return NULL; |
| 385 | } |
Jens Axboe | 2e662b6 | 2006-07-13 11:55:04 +0200 | [diff] [blame] | 386 | EXPORT_SYMBOL(elv_rb_find); |
| 387 | |
| 388 | /* |
Tejun Heo | 8922e16 | 2005-10-20 16:23:44 +0200 | [diff] [blame] | 389 | * Insert rq into dispatch queue of q. Queue lock must be held on |
Uwe Kleine-König | dbe7f76 | 2007-10-20 01:55:04 +0200 | [diff] [blame] | 390 | * entry. rq is sort instead into the dispatch queue. To be used by |
Jens Axboe | 2e662b6 | 2006-07-13 11:55:04 +0200 | [diff] [blame] | 391 | * specific elevators. |
Tejun Heo | 8922e16 | 2005-10-20 16:23:44 +0200 | [diff] [blame] | 392 | */ |
Jens Axboe | 165125e | 2007-07-24 09:28:11 +0200 | [diff] [blame] | 393 | void elv_dispatch_sort(struct request_queue *q, struct request *rq) |
Tejun Heo | 8922e16 | 2005-10-20 16:23:44 +0200 | [diff] [blame] | 394 | { |
| 395 | sector_t boundary; |
Tejun Heo | 8922e16 | 2005-10-20 16:23:44 +0200 | [diff] [blame] | 396 | struct list_head *entry; |
Jens Axboe | 4eb166d | 2008-02-01 00:37:27 +0100 | [diff] [blame] | 397 | int stop_flags; |
Tejun Heo | 8922e16 | 2005-10-20 16:23:44 +0200 | [diff] [blame] | 398 | |
Tejun Heo | 06b8624 | 2005-10-20 16:46:23 +0200 | [diff] [blame] | 399 | if (q->last_merge == rq) |
| 400 | q->last_merge = NULL; |
Jens Axboe | 9817064 | 2006-07-28 09:23:08 +0200 | [diff] [blame] | 401 | |
| 402 | elv_rqhash_del(q, rq); |
| 403 | |
Tejun Heo | 15853af | 2005-11-10 08:52:05 +0100 | [diff] [blame] | 404 | q->nr_sorted--; |
Tejun Heo | 06b8624 | 2005-10-20 16:46:23 +0200 | [diff] [blame] | 405 | |
Jens Axboe | 1b47f53 | 2005-10-20 16:37:00 +0200 | [diff] [blame] | 406 | boundary = q->end_sector; |
Christoph Hellwig | 02e031c | 2010-11-10 14:54:09 +0100 | [diff] [blame] | 407 | stop_flags = REQ_SOFTBARRIER | REQ_STARTED; |
Tejun Heo | 8922e16 | 2005-10-20 16:23:44 +0200 | [diff] [blame] | 408 | list_for_each_prev(entry, &q->queue_head) { |
| 409 | struct request *pos = list_entry_rq(entry); |
| 410 | |
Christoph Hellwig | 33659eb | 2010-08-07 18:17:56 +0200 | [diff] [blame] | 411 | if ((rq->cmd_flags & REQ_DISCARD) != |
| 412 | (pos->cmd_flags & REQ_DISCARD)) |
David Woodhouse | e17fc0a | 2008-08-09 16:42:20 +0100 | [diff] [blame] | 413 | break; |
Jens Axboe | 783660b | 2007-01-19 11:27:47 +1100 | [diff] [blame] | 414 | if (rq_data_dir(rq) != rq_data_dir(pos)) |
| 415 | break; |
Jens Axboe | 4eb166d | 2008-02-01 00:37:27 +0100 | [diff] [blame] | 416 | if (pos->cmd_flags & stop_flags) |
Tejun Heo | 8922e16 | 2005-10-20 16:23:44 +0200 | [diff] [blame] | 417 | break; |
Tejun Heo | 83096eb | 2009-05-07 22:24:39 +0900 | [diff] [blame] | 418 | if (blk_rq_pos(rq) >= boundary) { |
| 419 | if (blk_rq_pos(pos) < boundary) |
Tejun Heo | 8922e16 | 2005-10-20 16:23:44 +0200 | [diff] [blame] | 420 | continue; |
| 421 | } else { |
Tejun Heo | 83096eb | 2009-05-07 22:24:39 +0900 | [diff] [blame] | 422 | if (blk_rq_pos(pos) >= boundary) |
Tejun Heo | 8922e16 | 2005-10-20 16:23:44 +0200 | [diff] [blame] | 423 | break; |
| 424 | } |
Tejun Heo | 83096eb | 2009-05-07 22:24:39 +0900 | [diff] [blame] | 425 | if (blk_rq_pos(rq) >= blk_rq_pos(pos)) |
Tejun Heo | 8922e16 | 2005-10-20 16:23:44 +0200 | [diff] [blame] | 426 | break; |
| 427 | } |
| 428 | |
| 429 | list_add(&rq->queuelist, entry); |
| 430 | } |
Jens Axboe | 2e662b6 | 2006-07-13 11:55:04 +0200 | [diff] [blame] | 431 | EXPORT_SYMBOL(elv_dispatch_sort); |
| 432 | |
Jens Axboe | 9817064 | 2006-07-28 09:23:08 +0200 | [diff] [blame] | 433 | /* |
Jens Axboe | 2e662b6 | 2006-07-13 11:55:04 +0200 | [diff] [blame] | 434 | * Insert rq into dispatch queue of q. Queue lock must be held on |
| 435 | * entry. rq is added to the back of the dispatch queue. To be used by |
| 436 | * specific elevators. |
Jens Axboe | 9817064 | 2006-07-28 09:23:08 +0200 | [diff] [blame] | 437 | */ |
| 438 | void elv_dispatch_add_tail(struct request_queue *q, struct request *rq) |
| 439 | { |
| 440 | if (q->last_merge == rq) |
| 441 | q->last_merge = NULL; |
| 442 | |
| 443 | elv_rqhash_del(q, rq); |
| 444 | |
| 445 | q->nr_sorted--; |
| 446 | |
| 447 | q->end_sector = rq_end_sector(rq); |
| 448 | q->boundary_rq = rq; |
| 449 | list_add_tail(&rq->queuelist, &q->queue_head); |
| 450 | } |
Jens Axboe | 2e662b6 | 2006-07-13 11:55:04 +0200 | [diff] [blame] | 451 | EXPORT_SYMBOL(elv_dispatch_add_tail); |
| 452 | |
Jens Axboe | 165125e | 2007-07-24 09:28:11 +0200 | [diff] [blame] | 453 | int elv_merge(struct request_queue *q, struct request **req, struct bio *bio) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 454 | { |
Jens Axboe | b374d18 | 2008-10-31 10:05:07 +0100 | [diff] [blame] | 455 | struct elevator_queue *e = q->elevator; |
Jens Axboe | 9817064 | 2006-07-28 09:23:08 +0200 | [diff] [blame] | 456 | struct request *__rq; |
Tejun Heo | 06b8624 | 2005-10-20 16:46:23 +0200 | [diff] [blame] | 457 | int ret; |
| 458 | |
Jens Axboe | 9817064 | 2006-07-28 09:23:08 +0200 | [diff] [blame] | 459 | /* |
Alan D. Brunelle | 488991e | 2010-01-29 09:04:08 +0100 | [diff] [blame] | 460 | * Levels of merges: |
| 461 | * nomerges: No merges at all attempted |
| 462 | * noxmerges: Only simple one-hit cache try |
| 463 | * merges: All merge tries attempted |
| 464 | */ |
| 465 | if (blk_queue_nomerges(q)) |
| 466 | return ELEVATOR_NO_MERGE; |
| 467 | |
| 468 | /* |
Jens Axboe | 9817064 | 2006-07-28 09:23:08 +0200 | [diff] [blame] | 469 | * First try one-hit cache. |
| 470 | */ |
Tejun Heo | 050c8ea | 2012-02-08 09:19:38 +0100 | [diff] [blame] | 471 | if (q->last_merge && elv_rq_merge_ok(q->last_merge, bio)) { |
| 472 | ret = blk_try_merge(q->last_merge, bio); |
Tejun Heo | 06b8624 | 2005-10-20 16:46:23 +0200 | [diff] [blame] | 473 | if (ret != ELEVATOR_NO_MERGE) { |
| 474 | *req = q->last_merge; |
| 475 | return ret; |
| 476 | } |
| 477 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 478 | |
Alan D. Brunelle | 488991e | 2010-01-29 09:04:08 +0100 | [diff] [blame] | 479 | if (blk_queue_noxmerges(q)) |
Alan D. Brunelle | ac9fafa | 2008-04-29 14:44:19 +0200 | [diff] [blame] | 480 | return ELEVATOR_NO_MERGE; |
| 481 | |
Jens Axboe | 9817064 | 2006-07-28 09:23:08 +0200 | [diff] [blame] | 482 | /* |
| 483 | * See if our hash lookup can find a potential backmerge. |
| 484 | */ |
| 485 | __rq = elv_rqhash_find(q, bio->bi_sector); |
| 486 | if (__rq && elv_rq_merge_ok(__rq, bio)) { |
| 487 | *req = __rq; |
| 488 | return ELEVATOR_BACK_MERGE; |
| 489 | } |
| 490 | |
Tejun Heo | 22f746e | 2011-12-14 00:33:41 +0100 | [diff] [blame] | 491 | if (e->type->ops.elevator_merge_fn) |
| 492 | return e->type->ops.elevator_merge_fn(q, req, bio); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 493 | |
| 494 | return ELEVATOR_NO_MERGE; |
| 495 | } |
| 496 | |
Jens Axboe | 5e84ea3 | 2011-03-21 10:14:27 +0100 | [diff] [blame] | 497 | /* |
| 498 | * Attempt to do an insertion back merge. Only check for the case where |
| 499 | * we can append 'rq' to an existing request, so we can throw 'rq' away |
| 500 | * afterwards. |
| 501 | * |
| 502 | * Returns true if we merged, false otherwise |
| 503 | */ |
| 504 | static bool elv_attempt_insert_merge(struct request_queue *q, |
| 505 | struct request *rq) |
| 506 | { |
| 507 | struct request *__rq; |
| 508 | |
| 509 | if (blk_queue_nomerges(q)) |
| 510 | return false; |
| 511 | |
| 512 | /* |
| 513 | * First try one-hit cache. |
| 514 | */ |
| 515 | if (q->last_merge && blk_attempt_req_merge(q, q->last_merge, rq)) |
| 516 | return true; |
| 517 | |
| 518 | if (blk_queue_noxmerges(q)) |
| 519 | return false; |
| 520 | |
| 521 | /* |
| 522 | * See if our hash lookup can find a potential backmerge. |
| 523 | */ |
Jens Axboe | 5d381ef | 2012-01-15 10:29:48 +0100 | [diff] [blame] | 524 | __rq = elv_rqhash_find(q, blk_rq_pos(rq)); |
| 525 | if (__rq && blk_attempt_req_merge(q, __rq, rq)) |
| 526 | return true; |
Jens Axboe | 5e84ea3 | 2011-03-21 10:14:27 +0100 | [diff] [blame] | 527 | |
Jens Axboe | 5d381ef | 2012-01-15 10:29:48 +0100 | [diff] [blame] | 528 | return false; |
Jens Axboe | 5e84ea3 | 2011-03-21 10:14:27 +0100 | [diff] [blame] | 529 | } |
| 530 | |
Jens Axboe | 165125e | 2007-07-24 09:28:11 +0200 | [diff] [blame] | 531 | void elv_merged_request(struct request_queue *q, struct request *rq, int type) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 532 | { |
Jens Axboe | b374d18 | 2008-10-31 10:05:07 +0100 | [diff] [blame] | 533 | struct elevator_queue *e = q->elevator; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 534 | |
Tejun Heo | 22f746e | 2011-12-14 00:33:41 +0100 | [diff] [blame] | 535 | if (e->type->ops.elevator_merged_fn) |
| 536 | e->type->ops.elevator_merged_fn(q, rq, type); |
Tejun Heo | 06b8624 | 2005-10-20 16:46:23 +0200 | [diff] [blame] | 537 | |
Jens Axboe | 2e662b6 | 2006-07-13 11:55:04 +0200 | [diff] [blame] | 538 | if (type == ELEVATOR_BACK_MERGE) |
| 539 | elv_rqhash_reposition(q, rq); |
Jens Axboe | 9817064 | 2006-07-28 09:23:08 +0200 | [diff] [blame] | 540 | |
Tejun Heo | 06b8624 | 2005-10-20 16:46:23 +0200 | [diff] [blame] | 541 | q->last_merge = rq; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 542 | } |
| 543 | |
Jens Axboe | 165125e | 2007-07-24 09:28:11 +0200 | [diff] [blame] | 544 | void elv_merge_requests(struct request_queue *q, struct request *rq, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 545 | struct request *next) |
| 546 | { |
Jens Axboe | b374d18 | 2008-10-31 10:05:07 +0100 | [diff] [blame] | 547 | struct elevator_queue *e = q->elevator; |
Jens Axboe | 5e84ea3 | 2011-03-21 10:14:27 +0100 | [diff] [blame] | 548 | const int next_sorted = next->cmd_flags & REQ_SORTED; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 549 | |
Tejun Heo | 22f746e | 2011-12-14 00:33:41 +0100 | [diff] [blame] | 550 | if (next_sorted && e->type->ops.elevator_merge_req_fn) |
| 551 | e->type->ops.elevator_merge_req_fn(q, rq, next); |
Tejun Heo | 06b8624 | 2005-10-20 16:46:23 +0200 | [diff] [blame] | 552 | |
Jens Axboe | 9817064 | 2006-07-28 09:23:08 +0200 | [diff] [blame] | 553 | elv_rqhash_reposition(q, rq); |
Jens Axboe | 9817064 | 2006-07-28 09:23:08 +0200 | [diff] [blame] | 554 | |
Jens Axboe | 5e84ea3 | 2011-03-21 10:14:27 +0100 | [diff] [blame] | 555 | if (next_sorted) { |
| 556 | elv_rqhash_del(q, next); |
| 557 | q->nr_sorted--; |
| 558 | } |
| 559 | |
Tejun Heo | 06b8624 | 2005-10-20 16:46:23 +0200 | [diff] [blame] | 560 | q->last_merge = rq; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 561 | } |
| 562 | |
Divyesh Shah | 812d402 | 2010-04-08 21:14:23 -0700 | [diff] [blame] | 563 | void elv_bio_merged(struct request_queue *q, struct request *rq, |
| 564 | struct bio *bio) |
| 565 | { |
| 566 | struct elevator_queue *e = q->elevator; |
| 567 | |
Tejun Heo | 22f746e | 2011-12-14 00:33:41 +0100 | [diff] [blame] | 568 | if (e->type->ops.elevator_bio_merged_fn) |
| 569 | e->type->ops.elevator_bio_merged_fn(q, rq, bio); |
Divyesh Shah | 812d402 | 2010-04-08 21:14:23 -0700 | [diff] [blame] | 570 | } |
| 571 | |
Lin Ming | 0fb59e5 | 2013-03-23 11:42:27 +0800 | [diff] [blame] | 572 | #ifdef CONFIG_PM_RUNTIME |
| 573 | static void blk_pm_requeue_request(struct request *rq) |
| 574 | { |
| 575 | if (rq->q->dev && !(rq->cmd_flags & REQ_PM)) |
| 576 | rq->q->nr_pending--; |
| 577 | } |
| 578 | |
| 579 | static void blk_pm_add_request(struct request_queue *q, struct request *rq) |
| 580 | { |
| 581 | if (q->dev && !(rq->cmd_flags & REQ_PM) && q->nr_pending++ == 0 && |
| 582 | (q->rpm_status == RPM_SUSPENDED || q->rpm_status == RPM_SUSPENDING)) |
| 583 | pm_request_resume(q->dev); |
| 584 | } |
| 585 | #else |
| 586 | static inline void blk_pm_requeue_request(struct request *rq) {} |
| 587 | static inline void blk_pm_add_request(struct request_queue *q, |
| 588 | struct request *rq) |
| 589 | { |
| 590 | } |
| 591 | #endif |
| 592 | |
Jens Axboe | 165125e | 2007-07-24 09:28:11 +0200 | [diff] [blame] | 593 | void elv_requeue_request(struct request_queue *q, struct request *rq) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 594 | { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 595 | /* |
| 596 | * it already went through dequeue, we need to decrement the |
| 597 | * in_flight count again |
| 598 | */ |
Tejun Heo | 8922e16 | 2005-10-20 16:23:44 +0200 | [diff] [blame] | 599 | if (blk_account_rq(rq)) { |
Jens Axboe | 0a7ae2f | 2009-05-20 08:54:31 +0200 | [diff] [blame] | 600 | q->in_flight[rq_is_sync(rq)]--; |
Christoph Hellwig | 33659eb | 2010-08-07 18:17:56 +0200 | [diff] [blame] | 601 | if (rq->cmd_flags & REQ_SORTED) |
Jens Axboe | cad9751 | 2007-01-14 22:26:09 +1100 | [diff] [blame] | 602 | elv_deactivate_rq(q, rq); |
Tejun Heo | 8922e16 | 2005-10-20 16:23:44 +0200 | [diff] [blame] | 603 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 604 | |
Jens Axboe | 4aff5e2 | 2006-08-10 08:44:47 +0200 | [diff] [blame] | 605 | rq->cmd_flags &= ~REQ_STARTED; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 606 | |
Lin Ming | 0fb59e5 | 2013-03-23 11:42:27 +0800 | [diff] [blame] | 607 | blk_pm_requeue_request(rq); |
| 608 | |
Jens Axboe | b710a48 | 2011-03-30 09:52:30 +0200 | [diff] [blame] | 609 | __elv_add_request(q, rq, ELEVATOR_INSERT_REQUEUE); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 610 | } |
| 611 | |
Tatyana Brokhman | 57d8019 | 2012-12-04 15:54:43 +0200 | [diff] [blame] | 612 | /** |
| 613 | * elv_reinsert_request() - Insert a request back to the scheduler |
| 614 | * @q: request queue where request should be inserted |
| 615 | * @rq: request to be inserted |
| 616 | * |
| 617 | * This function returns the request back to the scheduler to be |
| 618 | * inserted as if it was never dispatched |
| 619 | * |
| 620 | * Return: 0 on success, error code on failure |
| 621 | */ |
| 622 | int elv_reinsert_request(struct request_queue *q, struct request *rq) |
| 623 | { |
| 624 | int res; |
| 625 | |
| 626 | if (!q->elevator->type->ops.elevator_reinsert_req_fn) |
| 627 | return -EPERM; |
| 628 | |
| 629 | res = q->elevator->type->ops.elevator_reinsert_req_fn(q, rq); |
| 630 | if (!res) { |
| 631 | /* |
| 632 | * it already went through dequeue, we need to decrement the |
| 633 | * in_flight count again |
| 634 | */ |
| 635 | if (blk_account_rq(rq)) { |
| 636 | q->in_flight[rq_is_sync(rq)]--; |
| 637 | if (rq->cmd_flags & REQ_SORTED) |
| 638 | elv_deactivate_rq(q, rq); |
| 639 | } |
| 640 | rq->cmd_flags &= ~REQ_STARTED; |
| 641 | q->nr_sorted++; |
| 642 | } |
| 643 | |
| 644 | return res; |
| 645 | } |
| 646 | |
Jerome Marchand | 26308ea | 2009-03-27 10:31:51 +0100 | [diff] [blame] | 647 | void elv_drain_elevator(struct request_queue *q) |
Tejun Heo | 15853af | 2005-11-10 08:52:05 +0100 | [diff] [blame] | 648 | { |
| 649 | static int printed; |
Tejun Heo | e3c78ca | 2011-10-19 14:32:38 +0200 | [diff] [blame] | 650 | |
| 651 | lockdep_assert_held(q->queue_lock); |
| 652 | |
Tejun Heo | 22f746e | 2011-12-14 00:33:41 +0100 | [diff] [blame] | 653 | while (q->elevator->type->ops.elevator_dispatch_fn(q, 1)) |
Tejun Heo | 15853af | 2005-11-10 08:52:05 +0100 | [diff] [blame] | 654 | ; |
Tejun Heo | e3c78ca | 2011-10-19 14:32:38 +0200 | [diff] [blame] | 655 | if (q->nr_sorted && printed++ < 10) { |
Tejun Heo | 15853af | 2005-11-10 08:52:05 +0100 | [diff] [blame] | 656 | printk(KERN_ERR "%s: forced dispatching is broken " |
| 657 | "(nr_sorted=%u), please report this\n", |
Tejun Heo | 22f746e | 2011-12-14 00:33:41 +0100 | [diff] [blame] | 658 | q->elevator->type->elevator_name, q->nr_sorted); |
Tejun Heo | 15853af | 2005-11-10 08:52:05 +0100 | [diff] [blame] | 659 | } |
| 660 | } |
| 661 | |
Jens Axboe | f600abe | 2009-04-08 14:22:01 +0200 | [diff] [blame] | 662 | void elv_quiesce_start(struct request_queue *q) |
Jens Axboe | 6c7e8ce | 2009-03-27 10:30:47 +0100 | [diff] [blame] | 663 | { |
Martin K. Petersen | cd43e26 | 2009-05-22 17:17:52 -0400 | [diff] [blame] | 664 | if (!q->elevator) |
| 665 | return; |
| 666 | |
Tejun Heo | e3c78ca | 2011-10-19 14:32:38 +0200 | [diff] [blame] | 667 | spin_lock_irq(q->queue_lock); |
Jens Axboe | 6c7e8ce | 2009-03-27 10:30:47 +0100 | [diff] [blame] | 668 | queue_flag_set(QUEUE_FLAG_ELVSWITCH, q); |
Tejun Heo | e3c78ca | 2011-10-19 14:32:38 +0200 | [diff] [blame] | 669 | spin_unlock_irq(q->queue_lock); |
Jens Axboe | 6c7e8ce | 2009-03-27 10:30:47 +0100 | [diff] [blame] | 670 | |
Tejun Heo | c9a929d | 2011-10-19 14:42:16 +0200 | [diff] [blame] | 671 | blk_drain_queue(q, false); |
Jens Axboe | 6c7e8ce | 2009-03-27 10:30:47 +0100 | [diff] [blame] | 672 | } |
| 673 | |
Jens Axboe | f600abe | 2009-04-08 14:22:01 +0200 | [diff] [blame] | 674 | void elv_quiesce_end(struct request_queue *q) |
Jens Axboe | 6c7e8ce | 2009-03-27 10:30:47 +0100 | [diff] [blame] | 675 | { |
Tejun Heo | e3c78ca | 2011-10-19 14:32:38 +0200 | [diff] [blame] | 676 | spin_lock_irq(q->queue_lock); |
Jens Axboe | 6c7e8ce | 2009-03-27 10:30:47 +0100 | [diff] [blame] | 677 | queue_flag_clear(QUEUE_FLAG_ELVSWITCH, q); |
Tejun Heo | e3c78ca | 2011-10-19 14:32:38 +0200 | [diff] [blame] | 678 | spin_unlock_irq(q->queue_lock); |
Jens Axboe | 6c7e8ce | 2009-03-27 10:30:47 +0100 | [diff] [blame] | 679 | } |
| 680 | |
Jens Axboe | b710a48 | 2011-03-30 09:52:30 +0200 | [diff] [blame] | 681 | void __elv_add_request(struct request_queue *q, struct request *rq, int where) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 682 | { |
Arnaldo Carvalho de Melo | 5f3ea37 | 2008-10-30 08:34:33 +0100 | [diff] [blame] | 683 | trace_block_rq_insert(q, rq); |
Jens Axboe | 2056a78 | 2006-03-23 20:00:26 +0100 | [diff] [blame] | 684 | |
Lin Ming | 0fb59e5 | 2013-03-23 11:42:27 +0800 | [diff] [blame] | 685 | blk_pm_add_request(q, rq); |
| 686 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 687 | rq->q = q; |
| 688 | |
Jens Axboe | b710a48 | 2011-03-30 09:52:30 +0200 | [diff] [blame] | 689 | if (rq->cmd_flags & REQ_SOFTBARRIER) { |
| 690 | /* barriers are scheduling boundary, update end_sector */ |
| 691 | if (rq->cmd_type == REQ_TYPE_FS || |
Maya Erez | 73937f5 | 2012-05-24 23:33:05 +0300 | [diff] [blame] | 692 | (rq->cmd_flags & (REQ_DISCARD | REQ_SANITIZE))) { |
Jens Axboe | b710a48 | 2011-03-30 09:52:30 +0200 | [diff] [blame] | 693 | q->end_sector = rq_end_sector(rq); |
| 694 | q->boundary_rq = rq; |
| 695 | } |
| 696 | } else if (!(rq->cmd_flags & REQ_ELVPRIV) && |
Jens Axboe | 3aa7287 | 2011-04-21 19:28:35 +0200 | [diff] [blame] | 697 | (where == ELEVATOR_INSERT_SORT || |
| 698 | where == ELEVATOR_INSERT_SORT_MERGE)) |
Jens Axboe | b710a48 | 2011-03-30 09:52:30 +0200 | [diff] [blame] | 699 | where = ELEVATOR_INSERT_BACK; |
| 700 | |
Tejun Heo | 8922e16 | 2005-10-20 16:23:44 +0200 | [diff] [blame] | 701 | switch (where) { |
Tejun Heo | 28e7d18 | 2010-09-03 11:56:16 +0200 | [diff] [blame] | 702 | case ELEVATOR_INSERT_REQUEUE: |
Tejun Heo | 8922e16 | 2005-10-20 16:23:44 +0200 | [diff] [blame] | 703 | case ELEVATOR_INSERT_FRONT: |
Jens Axboe | 4aff5e2 | 2006-08-10 08:44:47 +0200 | [diff] [blame] | 704 | rq->cmd_flags |= REQ_SOFTBARRIER; |
Tejun Heo | 8922e16 | 2005-10-20 16:23:44 +0200 | [diff] [blame] | 705 | list_add(&rq->queuelist, &q->queue_head); |
| 706 | break; |
| 707 | |
| 708 | case ELEVATOR_INSERT_BACK: |
Jens Axboe | 4aff5e2 | 2006-08-10 08:44:47 +0200 | [diff] [blame] | 709 | rq->cmd_flags |= REQ_SOFTBARRIER; |
Tejun Heo | 15853af | 2005-11-10 08:52:05 +0100 | [diff] [blame] | 710 | elv_drain_elevator(q); |
Tejun Heo | 8922e16 | 2005-10-20 16:23:44 +0200 | [diff] [blame] | 711 | list_add_tail(&rq->queuelist, &q->queue_head); |
| 712 | /* |
| 713 | * We kick the queue here for the following reasons. |
| 714 | * - The elevator might have returned NULL previously |
| 715 | * to delay requests and returned them now. As the |
| 716 | * queue wasn't empty before this request, ll_rw_blk |
| 717 | * won't run the queue on return, resulting in hang. |
| 718 | * - Usually, back inserted requests won't be merged |
| 719 | * with anything. There's no point in delaying queue |
| 720 | * processing. |
| 721 | */ |
Christoph Hellwig | 24ecfbe | 2011-04-18 11:41:33 +0200 | [diff] [blame] | 722 | __blk_run_queue(q); |
Tejun Heo | 8922e16 | 2005-10-20 16:23:44 +0200 | [diff] [blame] | 723 | break; |
| 724 | |
Jens Axboe | 5e84ea3 | 2011-03-21 10:14:27 +0100 | [diff] [blame] | 725 | case ELEVATOR_INSERT_SORT_MERGE: |
| 726 | /* |
| 727 | * If we succeed in merging this request with one in the |
| 728 | * queue already, we are done - rq has now been freed, |
| 729 | * so no need to do anything further. |
| 730 | */ |
| 731 | if (elv_attempt_insert_merge(q, rq)) |
| 732 | break; |
Tejun Heo | 8922e16 | 2005-10-20 16:23:44 +0200 | [diff] [blame] | 733 | case ELEVATOR_INSERT_SORT: |
Christoph Hellwig | 33659eb | 2010-08-07 18:17:56 +0200 | [diff] [blame] | 734 | BUG_ON(rq->cmd_type != REQ_TYPE_FS && |
| 735 | !(rq->cmd_flags & REQ_DISCARD)); |
Jens Axboe | 4aff5e2 | 2006-08-10 08:44:47 +0200 | [diff] [blame] | 736 | rq->cmd_flags |= REQ_SORTED; |
Tejun Heo | 15853af | 2005-11-10 08:52:05 +0100 | [diff] [blame] | 737 | q->nr_sorted++; |
Jens Axboe | 9817064 | 2006-07-28 09:23:08 +0200 | [diff] [blame] | 738 | if (rq_mergeable(rq)) { |
| 739 | elv_rqhash_add(q, rq); |
| 740 | if (!q->last_merge) |
| 741 | q->last_merge = rq; |
| 742 | } |
| 743 | |
Tejun Heo | ca23509 | 2005-11-01 17:23:49 +0900 | [diff] [blame] | 744 | /* |
| 745 | * Some ioscheds (cfq) run q->request_fn directly, so |
| 746 | * rq cannot be accessed after calling |
| 747 | * elevator_add_req_fn. |
| 748 | */ |
Tejun Heo | 22f746e | 2011-12-14 00:33:41 +0100 | [diff] [blame] | 749 | q->elevator->type->ops.elevator_add_req_fn(q, rq); |
Tejun Heo | 8922e16 | 2005-10-20 16:23:44 +0200 | [diff] [blame] | 750 | break; |
| 751 | |
Tejun Heo | ae1b153 | 2011-01-25 12:43:54 +0100 | [diff] [blame] | 752 | case ELEVATOR_INSERT_FLUSH: |
| 753 | rq->cmd_flags |= REQ_SOFTBARRIER; |
| 754 | blk_insert_flush(rq); |
| 755 | break; |
Tejun Heo | 8922e16 | 2005-10-20 16:23:44 +0200 | [diff] [blame] | 756 | default: |
| 757 | printk(KERN_ERR "%s: bad insertion point %d\n", |
Harvey Harrison | 24c03d4 | 2008-05-01 04:35:17 -0700 | [diff] [blame] | 758 | __func__, where); |
Tejun Heo | 8922e16 | 2005-10-20 16:23:44 +0200 | [diff] [blame] | 759 | BUG(); |
| 760 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 761 | } |
Jens Axboe | 2e662b6 | 2006-07-13 11:55:04 +0200 | [diff] [blame] | 762 | EXPORT_SYMBOL(__elv_add_request); |
| 763 | |
Jens Axboe | 7eaceac | 2011-03-10 08:52:07 +0100 | [diff] [blame] | 764 | void elv_add_request(struct request_queue *q, struct request *rq, int where) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 765 | { |
| 766 | unsigned long flags; |
| 767 | |
| 768 | spin_lock_irqsave(q->queue_lock, flags); |
Jens Axboe | 7eaceac | 2011-03-10 08:52:07 +0100 | [diff] [blame] | 769 | __elv_add_request(q, rq, where); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 770 | spin_unlock_irqrestore(q->queue_lock, flags); |
| 771 | } |
Jens Axboe | 2e662b6 | 2006-07-13 11:55:04 +0200 | [diff] [blame] | 772 | EXPORT_SYMBOL(elv_add_request); |
| 773 | |
Jens Axboe | 165125e | 2007-07-24 09:28:11 +0200 | [diff] [blame] | 774 | struct request *elv_latter_request(struct request_queue *q, struct request *rq) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 775 | { |
Jens Axboe | b374d18 | 2008-10-31 10:05:07 +0100 | [diff] [blame] | 776 | struct elevator_queue *e = q->elevator; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 777 | |
Tejun Heo | 22f746e | 2011-12-14 00:33:41 +0100 | [diff] [blame] | 778 | if (e->type->ops.elevator_latter_req_fn) |
| 779 | return e->type->ops.elevator_latter_req_fn(q, rq); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 780 | return NULL; |
| 781 | } |
| 782 | |
Jens Axboe | 165125e | 2007-07-24 09:28:11 +0200 | [diff] [blame] | 783 | struct request *elv_former_request(struct request_queue *q, struct request *rq) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 784 | { |
Jens Axboe | b374d18 | 2008-10-31 10:05:07 +0100 | [diff] [blame] | 785 | struct elevator_queue *e = q->elevator; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 786 | |
Tejun Heo | 22f746e | 2011-12-14 00:33:41 +0100 | [diff] [blame] | 787 | if (e->type->ops.elevator_former_req_fn) |
| 788 | return e->type->ops.elevator_former_req_fn(q, rq); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 789 | return NULL; |
| 790 | } |
| 791 | |
Jens Axboe | 165125e | 2007-07-24 09:28:11 +0200 | [diff] [blame] | 792 | int elv_set_request(struct request_queue *q, struct request *rq, gfp_t gfp_mask) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 793 | { |
Jens Axboe | b374d18 | 2008-10-31 10:05:07 +0100 | [diff] [blame] | 794 | struct elevator_queue *e = q->elevator; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 795 | |
Tejun Heo | 22f746e | 2011-12-14 00:33:41 +0100 | [diff] [blame] | 796 | if (e->type->ops.elevator_set_req_fn) |
| 797 | return e->type->ops.elevator_set_req_fn(q, rq, gfp_mask); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 798 | return 0; |
| 799 | } |
| 800 | |
Jens Axboe | 165125e | 2007-07-24 09:28:11 +0200 | [diff] [blame] | 801 | void elv_put_request(struct request_queue *q, struct request *rq) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 802 | { |
Jens Axboe | b374d18 | 2008-10-31 10:05:07 +0100 | [diff] [blame] | 803 | struct elevator_queue *e = q->elevator; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 804 | |
Tejun Heo | 22f746e | 2011-12-14 00:33:41 +0100 | [diff] [blame] | 805 | if (e->type->ops.elevator_put_req_fn) |
| 806 | e->type->ops.elevator_put_req_fn(rq); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 807 | } |
| 808 | |
Jens Axboe | 165125e | 2007-07-24 09:28:11 +0200 | [diff] [blame] | 809 | int elv_may_queue(struct request_queue *q, int rw) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 810 | { |
Jens Axboe | b374d18 | 2008-10-31 10:05:07 +0100 | [diff] [blame] | 811 | struct elevator_queue *e = q->elevator; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 812 | |
Tejun Heo | 22f746e | 2011-12-14 00:33:41 +0100 | [diff] [blame] | 813 | if (e->type->ops.elevator_may_queue_fn) |
| 814 | return e->type->ops.elevator_may_queue_fn(q, rw); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 815 | |
| 816 | return ELV_MQUEUE_MAY; |
| 817 | } |
| 818 | |
Mike Anderson | 11914a5 | 2008-09-13 20:31:27 +0200 | [diff] [blame] | 819 | void elv_abort_queue(struct request_queue *q) |
| 820 | { |
| 821 | struct request *rq; |
| 822 | |
Tejun Heo | ae1b153 | 2011-01-25 12:43:54 +0100 | [diff] [blame] | 823 | blk_abort_flushes(q); |
| 824 | |
Mike Anderson | 11914a5 | 2008-09-13 20:31:27 +0200 | [diff] [blame] | 825 | while (!list_empty(&q->queue_head)) { |
| 826 | rq = list_entry_rq(q->queue_head.next); |
| 827 | rq->cmd_flags |= REQ_QUIET; |
Arnaldo Carvalho de Melo | 5f3ea37 | 2008-10-30 08:34:33 +0100 | [diff] [blame] | 828 | trace_block_rq_abort(q, rq); |
Kiyoshi Ueda | 53c663c | 2009-06-02 08:44:01 +0200 | [diff] [blame] | 829 | /* |
| 830 | * Mark this request as started so we don't trigger |
| 831 | * any debug logic in the end I/O path. |
| 832 | */ |
| 833 | blk_start_request(rq); |
Tejun Heo | 40cbbb7 | 2009-04-23 11:05:19 +0900 | [diff] [blame] | 834 | __blk_end_request_all(rq, -EIO); |
Mike Anderson | 11914a5 | 2008-09-13 20:31:27 +0200 | [diff] [blame] | 835 | } |
| 836 | } |
| 837 | EXPORT_SYMBOL(elv_abort_queue); |
| 838 | |
Jens Axboe | 165125e | 2007-07-24 09:28:11 +0200 | [diff] [blame] | 839 | void elv_completed_request(struct request_queue *q, struct request *rq) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 840 | { |
Jens Axboe | b374d18 | 2008-10-31 10:05:07 +0100 | [diff] [blame] | 841 | struct elevator_queue *e = q->elevator; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 842 | |
Tatyana Brokhman | 2c41518 | 2013-03-12 21:02:33 +0200 | [diff] [blame] | 843 | if (rq->cmd_flags & REQ_URGENT) { |
Tatyana Brokhman | 88fd1b4 | 2012-12-04 16:04:15 +0200 | [diff] [blame] | 844 | q->notified_urgent = false; |
Tatyana Brokhman | 2b3b323 | 2013-09-04 22:13:47 +0300 | [diff] [blame] | 845 | WARN_ON(!q->dispatched_urgent); |
Tatyana Brokhman | 88fd1b4 | 2012-12-04 16:04:15 +0200 | [diff] [blame] | 846 | q->dispatched_urgent = false; |
Tatyana Brokhman | 88fd1b4 | 2012-12-04 16:04:15 +0200 | [diff] [blame] | 847 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 848 | /* |
| 849 | * request is released from the driver, io must be done |
| 850 | */ |
Tejun Heo | 8922e16 | 2005-10-20 16:23:44 +0200 | [diff] [blame] | 851 | if (blk_account_rq(rq)) { |
Jens Axboe | 0a7ae2f | 2009-05-20 08:54:31 +0200 | [diff] [blame] | 852 | q->in_flight[rq_is_sync(rq)]--; |
Christoph Hellwig | 33659eb | 2010-08-07 18:17:56 +0200 | [diff] [blame] | 853 | if ((rq->cmd_flags & REQ_SORTED) && |
Tejun Heo | 22f746e | 2011-12-14 00:33:41 +0100 | [diff] [blame] | 854 | e->type->ops.elevator_completed_req_fn) |
| 855 | e->type->ops.elevator_completed_req_fn(q, rq); |
Tejun Heo | 1bc691d | 2006-01-12 15:39:26 +0100 | [diff] [blame] | 856 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 857 | } |
| 858 | |
Al Viro | 3d1ab40 | 2006-03-18 18:35:43 -0500 | [diff] [blame] | 859 | #define to_elv(atr) container_of((atr), struct elv_fs_entry, attr) |
| 860 | |
| 861 | static ssize_t |
| 862 | elv_attr_show(struct kobject *kobj, struct attribute *attr, char *page) |
| 863 | { |
Al Viro | 3d1ab40 | 2006-03-18 18:35:43 -0500 | [diff] [blame] | 864 | struct elv_fs_entry *entry = to_elv(attr); |
Jens Axboe | b374d18 | 2008-10-31 10:05:07 +0100 | [diff] [blame] | 865 | struct elevator_queue *e; |
Al Viro | 3d1ab40 | 2006-03-18 18:35:43 -0500 | [diff] [blame] | 866 | ssize_t error; |
| 867 | |
| 868 | if (!entry->show) |
| 869 | return -EIO; |
| 870 | |
Jens Axboe | b374d18 | 2008-10-31 10:05:07 +0100 | [diff] [blame] | 871 | e = container_of(kobj, struct elevator_queue, kobj); |
Al Viro | 3d1ab40 | 2006-03-18 18:35:43 -0500 | [diff] [blame] | 872 | mutex_lock(&e->sysfs_lock); |
Tejun Heo | 22f746e | 2011-12-14 00:33:41 +0100 | [diff] [blame] | 873 | error = e->type ? entry->show(e, page) : -ENOENT; |
Al Viro | 3d1ab40 | 2006-03-18 18:35:43 -0500 | [diff] [blame] | 874 | mutex_unlock(&e->sysfs_lock); |
| 875 | return error; |
| 876 | } |
| 877 | |
| 878 | static ssize_t |
| 879 | elv_attr_store(struct kobject *kobj, struct attribute *attr, |
| 880 | const char *page, size_t length) |
| 881 | { |
Al Viro | 3d1ab40 | 2006-03-18 18:35:43 -0500 | [diff] [blame] | 882 | struct elv_fs_entry *entry = to_elv(attr); |
Jens Axboe | b374d18 | 2008-10-31 10:05:07 +0100 | [diff] [blame] | 883 | struct elevator_queue *e; |
Al Viro | 3d1ab40 | 2006-03-18 18:35:43 -0500 | [diff] [blame] | 884 | ssize_t error; |
| 885 | |
| 886 | if (!entry->store) |
| 887 | return -EIO; |
| 888 | |
Jens Axboe | b374d18 | 2008-10-31 10:05:07 +0100 | [diff] [blame] | 889 | e = container_of(kobj, struct elevator_queue, kobj); |
Al Viro | 3d1ab40 | 2006-03-18 18:35:43 -0500 | [diff] [blame] | 890 | mutex_lock(&e->sysfs_lock); |
Tejun Heo | 22f746e | 2011-12-14 00:33:41 +0100 | [diff] [blame] | 891 | error = e->type ? entry->store(e, page, length) : -ENOENT; |
Al Viro | 3d1ab40 | 2006-03-18 18:35:43 -0500 | [diff] [blame] | 892 | mutex_unlock(&e->sysfs_lock); |
| 893 | return error; |
| 894 | } |
| 895 | |
Emese Revfy | 52cf25d | 2010-01-19 02:58:23 +0100 | [diff] [blame] | 896 | static const struct sysfs_ops elv_sysfs_ops = { |
Al Viro | 3d1ab40 | 2006-03-18 18:35:43 -0500 | [diff] [blame] | 897 | .show = elv_attr_show, |
| 898 | .store = elv_attr_store, |
| 899 | }; |
| 900 | |
| 901 | static struct kobj_type elv_ktype = { |
| 902 | .sysfs_ops = &elv_sysfs_ops, |
| 903 | .release = elevator_release, |
| 904 | }; |
| 905 | |
Tejun Heo | f8fc877 | 2011-12-14 00:33:40 +0100 | [diff] [blame] | 906 | int __elv_register_queue(struct request_queue *q, struct elevator_queue *e) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 907 | { |
Al Viro | 3d1ab40 | 2006-03-18 18:35:43 -0500 | [diff] [blame] | 908 | int error; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 909 | |
Greg Kroah-Hartman | b2d6db5 | 2007-12-17 23:05:35 -0700 | [diff] [blame] | 910 | error = kobject_add(&e->kobj, &q->kobj, "%s", "iosched"); |
Al Viro | 3d1ab40 | 2006-03-18 18:35:43 -0500 | [diff] [blame] | 911 | if (!error) { |
Tejun Heo | 22f746e | 2011-12-14 00:33:41 +0100 | [diff] [blame] | 912 | struct elv_fs_entry *attr = e->type->elevator_attrs; |
Al Viro | 3d1ab40 | 2006-03-18 18:35:43 -0500 | [diff] [blame] | 913 | if (attr) { |
Al Viro | e572ec7 | 2006-03-18 22:27:18 -0500 | [diff] [blame] | 914 | while (attr->attr.name) { |
| 915 | if (sysfs_create_file(&e->kobj, &attr->attr)) |
Al Viro | 3d1ab40 | 2006-03-18 18:35:43 -0500 | [diff] [blame] | 916 | break; |
Al Viro | e572ec7 | 2006-03-18 22:27:18 -0500 | [diff] [blame] | 917 | attr++; |
Al Viro | 3d1ab40 | 2006-03-18 18:35:43 -0500 | [diff] [blame] | 918 | } |
| 919 | } |
| 920 | kobject_uevent(&e->kobj, KOBJ_ADD); |
Jens Axboe | 430c62f | 2010-10-07 09:35:16 +0200 | [diff] [blame] | 921 | e->registered = 1; |
Al Viro | 3d1ab40 | 2006-03-18 18:35:43 -0500 | [diff] [blame] | 922 | } |
| 923 | return error; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 924 | } |
| 925 | |
Tejun Heo | f8fc877 | 2011-12-14 00:33:40 +0100 | [diff] [blame] | 926 | int elv_register_queue(struct request_queue *q) |
Jens Axboe | bc1c116 | 2006-06-08 08:49:06 +0200 | [diff] [blame] | 927 | { |
Tejun Heo | f8fc877 | 2011-12-14 00:33:40 +0100 | [diff] [blame] | 928 | return __elv_register_queue(q, q->elevator); |
Jens Axboe | bc1c116 | 2006-06-08 08:49:06 +0200 | [diff] [blame] | 929 | } |
Tejun Heo | f8fc877 | 2011-12-14 00:33:40 +0100 | [diff] [blame] | 930 | EXPORT_SYMBOL(elv_register_queue); |
Jens Axboe | bc1c116 | 2006-06-08 08:49:06 +0200 | [diff] [blame] | 931 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 932 | void elv_unregister_queue(struct request_queue *q) |
| 933 | { |
Tejun Heo | f8fc877 | 2011-12-14 00:33:40 +0100 | [diff] [blame] | 934 | if (q) { |
| 935 | struct elevator_queue *e = q->elevator; |
| 936 | |
| 937 | kobject_uevent(&e->kobj, KOBJ_REMOVE); |
| 938 | kobject_del(&e->kobj); |
| 939 | e->registered = 0; |
| 940 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 941 | } |
Mike Snitzer | 01effb0 | 2010-05-11 08:57:42 +0200 | [diff] [blame] | 942 | EXPORT_SYMBOL(elv_unregister_queue); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 943 | |
Tejun Heo | 3d3c237 | 2011-12-14 00:33:42 +0100 | [diff] [blame] | 944 | int elv_register(struct elevator_type *e) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 945 | { |
Thibaut VARENE | 1ffb96c | 2007-03-15 12:59:19 +0100 | [diff] [blame] | 946 | char *def = ""; |
Jens Axboe | 2a12dcd | 2007-04-26 14:41:53 +0200 | [diff] [blame] | 947 | |
Tejun Heo | 3d3c237 | 2011-12-14 00:33:42 +0100 | [diff] [blame] | 948 | /* create icq_cache if requested */ |
| 949 | if (e->icq_size) { |
| 950 | if (WARN_ON(e->icq_size < sizeof(struct io_cq)) || |
| 951 | WARN_ON(e->icq_align < __alignof__(struct io_cq))) |
| 952 | return -EINVAL; |
| 953 | |
| 954 | snprintf(e->icq_cache_name, sizeof(e->icq_cache_name), |
| 955 | "%s_io_cq", e->elevator_name); |
| 956 | e->icq_cache = kmem_cache_create(e->icq_cache_name, e->icq_size, |
| 957 | e->icq_align, 0, NULL); |
| 958 | if (!e->icq_cache) |
| 959 | return -ENOMEM; |
| 960 | } |
| 961 | |
| 962 | /* register, don't allow duplicate names */ |
Jens Axboe | 2a12dcd | 2007-04-26 14:41:53 +0200 | [diff] [blame] | 963 | spin_lock(&elv_list_lock); |
Tejun Heo | 3d3c237 | 2011-12-14 00:33:42 +0100 | [diff] [blame] | 964 | if (elevator_find(e->elevator_name)) { |
| 965 | spin_unlock(&elv_list_lock); |
| 966 | if (e->icq_cache) |
| 967 | kmem_cache_destroy(e->icq_cache); |
| 968 | return -EBUSY; |
| 969 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 970 | list_add_tail(&e->list, &elv_list); |
Jens Axboe | 2a12dcd | 2007-04-26 14:41:53 +0200 | [diff] [blame] | 971 | spin_unlock(&elv_list_lock); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 972 | |
Tejun Heo | 3d3c237 | 2011-12-14 00:33:42 +0100 | [diff] [blame] | 973 | /* print pretty message */ |
Nate Diller | 5f00397 | 2006-01-24 10:07:58 +0100 | [diff] [blame] | 974 | if (!strcmp(e->elevator_name, chosen_elevator) || |
| 975 | (!*chosen_elevator && |
| 976 | !strcmp(e->elevator_name, CONFIG_DEFAULT_IOSCHED))) |
Thibaut VARENE | 1ffb96c | 2007-03-15 12:59:19 +0100 | [diff] [blame] | 977 | def = " (default)"; |
| 978 | |
Jens Axboe | 4eb166d | 2008-02-01 00:37:27 +0100 | [diff] [blame] | 979 | printk(KERN_INFO "io scheduler %s registered%s\n", e->elevator_name, |
| 980 | def); |
Tejun Heo | 3d3c237 | 2011-12-14 00:33:42 +0100 | [diff] [blame] | 981 | return 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 982 | } |
| 983 | EXPORT_SYMBOL_GPL(elv_register); |
| 984 | |
| 985 | void elv_unregister(struct elevator_type *e) |
| 986 | { |
Tejun Heo | 3d3c237 | 2011-12-14 00:33:42 +0100 | [diff] [blame] | 987 | /* unregister */ |
Jens Axboe | 2a12dcd | 2007-04-26 14:41:53 +0200 | [diff] [blame] | 988 | spin_lock(&elv_list_lock); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 989 | list_del_init(&e->list); |
Jens Axboe | 2a12dcd | 2007-04-26 14:41:53 +0200 | [diff] [blame] | 990 | spin_unlock(&elv_list_lock); |
Tejun Heo | 3d3c237 | 2011-12-14 00:33:42 +0100 | [diff] [blame] | 991 | |
| 992 | /* |
| 993 | * Destroy icq_cache if it exists. icq's are RCU managed. Make |
| 994 | * sure all RCU operations are complete before proceeding. |
| 995 | */ |
| 996 | if (e->icq_cache) { |
| 997 | rcu_barrier(); |
| 998 | kmem_cache_destroy(e->icq_cache); |
| 999 | e->icq_cache = NULL; |
| 1000 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1001 | } |
| 1002 | EXPORT_SYMBOL_GPL(elv_unregister); |
| 1003 | |
| 1004 | /* |
| 1005 | * switch to new_e io scheduler. be careful not to introduce deadlocks - |
| 1006 | * we don't free the old io scheduler, before we have allocated what we |
| 1007 | * 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] | 1008 | * one, if the new one fails init for some reason. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1009 | */ |
Jens Axboe | 165125e | 2007-07-24 09:28:11 +0200 | [diff] [blame] | 1010 | static int elevator_switch(struct request_queue *q, struct elevator_type *new_e) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1011 | { |
Jens Axboe | b374d18 | 2008-10-31 10:05:07 +0100 | [diff] [blame] | 1012 | struct elevator_queue *old_elevator, *e; |
Jens Axboe | 5dd531a | 2010-08-23 13:52:19 +0200 | [diff] [blame] | 1013 | int err; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1014 | |
Tejun Heo | f8fc877 | 2011-12-14 00:33:40 +0100 | [diff] [blame] | 1015 | /* allocate new elevator */ |
Jens Axboe | b5deef9 | 2006-07-19 23:39:40 +0200 | [diff] [blame] | 1016 | e = elevator_alloc(q, new_e); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1017 | if (!e) |
Jens Axboe | 5dd531a | 2010-08-23 13:52:19 +0200 | [diff] [blame] | 1018 | return -ENOMEM; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1019 | |
Tejun Heo | f8fc877 | 2011-12-14 00:33:40 +0100 | [diff] [blame] | 1020 | err = elevator_init_queue(q, e); |
| 1021 | if (err) { |
Jens Axboe | bc1c116 | 2006-06-08 08:49:06 +0200 | [diff] [blame] | 1022 | kobject_put(&e->kobj); |
Tejun Heo | f8fc877 | 2011-12-14 00:33:40 +0100 | [diff] [blame] | 1023 | return err; |
Jens Axboe | bc1c116 | 2006-06-08 08:49:06 +0200 | [diff] [blame] | 1024 | } |
| 1025 | |
Tejun Heo | f8fc877 | 2011-12-14 00:33:40 +0100 | [diff] [blame] | 1026 | /* turn on BYPASS and drain all requests w/ elevator private data */ |
Jens Axboe | f600abe | 2009-04-08 14:22:01 +0200 | [diff] [blame] | 1027 | elv_quiesce_start(q); |
Tejun Heo | cb98fc8 | 2005-10-28 08:29:39 +0200 | [diff] [blame] | 1028 | |
Tejun Heo | f8fc877 | 2011-12-14 00:33:40 +0100 | [diff] [blame] | 1029 | /* unregister old queue, register new one and kill old elevator */ |
| 1030 | if (q->elevator->registered) { |
| 1031 | elv_unregister_queue(q); |
| 1032 | err = __elv_register_queue(q, e); |
Jens Axboe | 430c62f | 2010-10-07 09:35:16 +0200 | [diff] [blame] | 1033 | if (err) |
| 1034 | goto fail_register; |
| 1035 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1036 | |
Tejun Heo | 7e5a879 | 2011-12-14 00:33:42 +0100 | [diff] [blame] | 1037 | /* done, clear io_cq's, switch elevators and turn off BYPASS */ |
Tejun Heo | f8fc877 | 2011-12-14 00:33:40 +0100 | [diff] [blame] | 1038 | spin_lock_irq(q->queue_lock); |
Tejun Heo | 7e5a879 | 2011-12-14 00:33:42 +0100 | [diff] [blame] | 1039 | ioc_clear_queue(q); |
Tejun Heo | f8fc877 | 2011-12-14 00:33:40 +0100 | [diff] [blame] | 1040 | old_elevator = q->elevator; |
| 1041 | q->elevator = e; |
| 1042 | spin_unlock_irq(q->queue_lock); |
| 1043 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1044 | elevator_exit(old_elevator); |
Jens Axboe | f600abe | 2009-04-08 14:22:01 +0200 | [diff] [blame] | 1045 | elv_quiesce_end(q); |
Nick Piggin | 75ad23b | 2008-04-29 14:48:33 +0200 | [diff] [blame] | 1046 | |
Tejun Heo | 22f746e | 2011-12-14 00:33:41 +0100 | [diff] [blame] | 1047 | blk_add_trace_msg(q, "elv switch: %s", e->type->elevator_name); |
Alan D. Brunelle | 4722dc5 | 2008-05-27 14:55:00 +0200 | [diff] [blame] | 1048 | |
Jens Axboe | 5dd531a | 2010-08-23 13:52:19 +0200 | [diff] [blame] | 1049 | return 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1050 | |
| 1051 | fail_register: |
| 1052 | /* |
| 1053 | * switch failed, exit the new io scheduler and reattach the old |
| 1054 | * one again (along with re-adding the sysfs dir) |
| 1055 | */ |
| 1056 | elevator_exit(e); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1057 | elv_register_queue(q); |
Tejun Heo | e3c78ca | 2011-10-19 14:32:38 +0200 | [diff] [blame] | 1058 | elv_quiesce_end(q); |
Nick Piggin | 75ad23b | 2008-04-29 14:48:33 +0200 | [diff] [blame] | 1059 | |
Jens Axboe | 5dd531a | 2010-08-23 13:52:19 +0200 | [diff] [blame] | 1060 | return err; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1061 | } |
| 1062 | |
Jens Axboe | 5dd531a | 2010-08-23 13:52:19 +0200 | [diff] [blame] | 1063 | /* |
| 1064 | * Switch this queue to the given IO scheduler. |
| 1065 | */ |
| 1066 | int elevator_change(struct request_queue *q, const char *name) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1067 | { |
| 1068 | char elevator_name[ELV_NAME_MAX]; |
| 1069 | struct elevator_type *e; |
| 1070 | |
Martin K. Petersen | cd43e26 | 2009-05-22 17:17:52 -0400 | [diff] [blame] | 1071 | if (!q->elevator) |
Jens Axboe | 5dd531a | 2010-08-23 13:52:19 +0200 | [diff] [blame] | 1072 | return -ENXIO; |
Martin K. Petersen | cd43e26 | 2009-05-22 17:17:52 -0400 | [diff] [blame] | 1073 | |
Li Zefan | ee2e992 | 2008-10-14 08:49:56 +0200 | [diff] [blame] | 1074 | strlcpy(elevator_name, name, sizeof(elevator_name)); |
KOSAKI Motohiro | 8c27959 | 2009-10-09 08:48:08 +0200 | [diff] [blame] | 1075 | e = elevator_get(strstrip(elevator_name)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1076 | if (!e) { |
| 1077 | printk(KERN_ERR "elevator: type %s not found\n", elevator_name); |
| 1078 | return -EINVAL; |
| 1079 | } |
| 1080 | |
Tejun Heo | 22f746e | 2011-12-14 00:33:41 +0100 | [diff] [blame] | 1081 | if (!strcmp(elevator_name, q->elevator->type->elevator_name)) { |
Nate Diller | 2ca7d93 | 2005-10-30 15:02:24 -0800 | [diff] [blame] | 1082 | elevator_put(e); |
Jens Axboe | 5dd531a | 2010-08-23 13:52:19 +0200 | [diff] [blame] | 1083 | return 0; |
Nate Diller | 2ca7d93 | 2005-10-30 15:02:24 -0800 | [diff] [blame] | 1084 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1085 | |
Jens Axboe | 5dd531a | 2010-08-23 13:52:19 +0200 | [diff] [blame] | 1086 | return elevator_switch(q, e); |
| 1087 | } |
| 1088 | EXPORT_SYMBOL(elevator_change); |
| 1089 | |
| 1090 | ssize_t elv_iosched_store(struct request_queue *q, const char *name, |
| 1091 | size_t count) |
| 1092 | { |
| 1093 | int ret; |
| 1094 | |
| 1095 | if (!q->elevator) |
| 1096 | return count; |
| 1097 | |
| 1098 | ret = elevator_change(q, name); |
| 1099 | if (!ret) |
| 1100 | return count; |
| 1101 | |
| 1102 | printk(KERN_ERR "elevator: switch to %s failed\n", name); |
| 1103 | return ret; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1104 | } |
| 1105 | |
Jens Axboe | 165125e | 2007-07-24 09:28:11 +0200 | [diff] [blame] | 1106 | ssize_t elv_iosched_show(struct request_queue *q, char *name) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1107 | { |
Jens Axboe | b374d18 | 2008-10-31 10:05:07 +0100 | [diff] [blame] | 1108 | struct elevator_queue *e = q->elevator; |
Martin K. Petersen | cd43e26 | 2009-05-22 17:17:52 -0400 | [diff] [blame] | 1109 | struct elevator_type *elv; |
Matthias Kaehlcke | 70cee26 | 2007-07-10 12:26:24 +0200 | [diff] [blame] | 1110 | struct elevator_type *__e; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1111 | int len = 0; |
| 1112 | |
Mike Snitzer | e36f724 | 2010-05-24 09:07:32 +0200 | [diff] [blame] | 1113 | if (!q->elevator || !blk_queue_stackable(q)) |
Martin K. Petersen | cd43e26 | 2009-05-22 17:17:52 -0400 | [diff] [blame] | 1114 | return sprintf(name, "none\n"); |
| 1115 | |
Tejun Heo | 22f746e | 2011-12-14 00:33:41 +0100 | [diff] [blame] | 1116 | elv = e->type; |
Martin K. Petersen | cd43e26 | 2009-05-22 17:17:52 -0400 | [diff] [blame] | 1117 | |
Jens Axboe | 2a12dcd | 2007-04-26 14:41:53 +0200 | [diff] [blame] | 1118 | spin_lock(&elv_list_lock); |
Matthias Kaehlcke | 70cee26 | 2007-07-10 12:26:24 +0200 | [diff] [blame] | 1119 | list_for_each_entry(__e, &elv_list, list) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1120 | if (!strcmp(elv->elevator_name, __e->elevator_name)) |
| 1121 | len += sprintf(name+len, "[%s] ", elv->elevator_name); |
| 1122 | else |
| 1123 | len += sprintf(name+len, "%s ", __e->elevator_name); |
| 1124 | } |
Jens Axboe | 2a12dcd | 2007-04-26 14:41:53 +0200 | [diff] [blame] | 1125 | spin_unlock(&elv_list_lock); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1126 | |
| 1127 | len += sprintf(len+name, "\n"); |
| 1128 | return len; |
| 1129 | } |
| 1130 | |
Jens Axboe | 165125e | 2007-07-24 09:28:11 +0200 | [diff] [blame] | 1131 | struct request *elv_rb_former_request(struct request_queue *q, |
| 1132 | struct request *rq) |
Jens Axboe | 2e662b6 | 2006-07-13 11:55:04 +0200 | [diff] [blame] | 1133 | { |
| 1134 | struct rb_node *rbprev = rb_prev(&rq->rb_node); |
| 1135 | |
| 1136 | if (rbprev) |
| 1137 | return rb_entry_rq(rbprev); |
| 1138 | |
| 1139 | return NULL; |
| 1140 | } |
Jens Axboe | 2e662b6 | 2006-07-13 11:55:04 +0200 | [diff] [blame] | 1141 | EXPORT_SYMBOL(elv_rb_former_request); |
| 1142 | |
Jens Axboe | 165125e | 2007-07-24 09:28:11 +0200 | [diff] [blame] | 1143 | struct request *elv_rb_latter_request(struct request_queue *q, |
| 1144 | struct request *rq) |
Jens Axboe | 2e662b6 | 2006-07-13 11:55:04 +0200 | [diff] [blame] | 1145 | { |
| 1146 | struct rb_node *rbnext = rb_next(&rq->rb_node); |
| 1147 | |
| 1148 | if (rbnext) |
| 1149 | return rb_entry_rq(rbnext); |
| 1150 | |
| 1151 | return NULL; |
| 1152 | } |
Jens Axboe | 2e662b6 | 2006-07-13 11:55:04 +0200 | [diff] [blame] | 1153 | EXPORT_SYMBOL(elv_rb_latter_request); |