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 | * Copyright (C) 1991, 1992 Linus Torvalds |
| 3 | * Copyright (C) 1994, Karl Keyte: Added support for disk statistics |
| 4 | * Elevator latency, (C) 2000 Andrea Arcangeli <andrea@suse.de> SuSE |
| 5 | * Queue request tables / lock, selectable elevator, Jens Axboe <axboe@suse.de> |
Jens Axboe | 6728cb0 | 2008-01-31 13:03:55 +0100 | [diff] [blame] | 6 | * kernel-doc documentation started by NeilBrown <neilb@cse.unsw.edu.au> |
| 7 | * - July2000 |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 8 | * bio rewrite, highmem i/o, etc, Jens Axboe <axboe@suse.de> - may 2001 |
| 9 | */ |
| 10 | |
| 11 | /* |
| 12 | * This handles all read/write requests to block devices |
| 13 | */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 14 | #include <linux/kernel.h> |
| 15 | #include <linux/module.h> |
| 16 | #include <linux/backing-dev.h> |
| 17 | #include <linux/bio.h> |
| 18 | #include <linux/blkdev.h> |
| 19 | #include <linux/highmem.h> |
| 20 | #include <linux/mm.h> |
| 21 | #include <linux/kernel_stat.h> |
| 22 | #include <linux/string.h> |
| 23 | #include <linux/init.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 24 | #include <linux/completion.h> |
| 25 | #include <linux/slab.h> |
| 26 | #include <linux/swap.h> |
| 27 | #include <linux/writeback.h> |
Andrew Morton | faccbd4b | 2006-12-10 02:19:35 -0800 | [diff] [blame] | 28 | #include <linux/task_io_accounting_ops.h> |
Akinobu Mita | c17bb49 | 2006-12-08 02:39:46 -0800 | [diff] [blame] | 29 | #include <linux/fault-inject.h> |
Li Zefan | 5578213 | 2009-06-09 13:43:05 +0800 | [diff] [blame] | 30 | |
| 31 | #define CREATE_TRACE_POINTS |
| 32 | #include <trace/events/block.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 33 | |
Jens Axboe | 8324aa9 | 2008-01-29 14:51:59 +0100 | [diff] [blame] | 34 | #include "blk.h" |
| 35 | |
Ingo Molnar | 0bfc245 | 2008-11-26 11:59:56 +0100 | [diff] [blame] | 36 | EXPORT_TRACEPOINT_SYMBOL_GPL(block_remap); |
Li Zefan | 5578213 | 2009-06-09 13:43:05 +0800 | [diff] [blame] | 37 | EXPORT_TRACEPOINT_SYMBOL_GPL(block_bio_complete); |
Ingo Molnar | 0bfc245 | 2008-11-26 11:59:56 +0100 | [diff] [blame] | 38 | |
Jens Axboe | 165125e | 2007-07-24 09:28:11 +0200 | [diff] [blame] | 39 | static int __make_request(struct request_queue *q, struct bio *bio); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 40 | |
| 41 | /* |
| 42 | * For the allocated request tables |
| 43 | */ |
Adrian Bunk | 5ece6c5 | 2008-02-18 13:45:51 +0100 | [diff] [blame] | 44 | static struct kmem_cache *request_cachep; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 45 | |
| 46 | /* |
| 47 | * For queue allocation |
| 48 | */ |
Jens Axboe | 6728cb0 | 2008-01-31 13:03:55 +0100 | [diff] [blame] | 49 | struct kmem_cache *blk_requestq_cachep; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 50 | |
| 51 | /* |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 52 | * Controlling structure to kblockd |
| 53 | */ |
Jens Axboe | ff856ba | 2006-01-09 16:02:34 +0100 | [diff] [blame] | 54 | static struct workqueue_struct *kblockd_workqueue; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 55 | |
Jens Axboe | 26b8256 | 2008-01-29 13:54:41 +0100 | [diff] [blame] | 56 | static void drive_stat_acct(struct request *rq, int new_io) |
| 57 | { |
Jens Axboe | 28f1370 | 2008-05-07 10:15:46 +0200 | [diff] [blame] | 58 | struct hd_struct *part; |
Jens Axboe | 26b8256 | 2008-01-29 13:54:41 +0100 | [diff] [blame] | 59 | int rw = rq_data_dir(rq); |
Tejun Heo | c995905 | 2008-08-25 19:47:21 +0900 | [diff] [blame] | 60 | int cpu; |
Jens Axboe | 26b8256 | 2008-01-29 13:54:41 +0100 | [diff] [blame] | 61 | |
Jens Axboe | c2553b5 | 2009-04-24 08:10:11 +0200 | [diff] [blame] | 62 | if (!blk_do_io_stat(rq)) |
Jens Axboe | 26b8256 | 2008-01-29 13:54:41 +0100 | [diff] [blame] | 63 | return; |
| 64 | |
Tejun Heo | 074a7ac | 2008-08-25 19:56:14 +0900 | [diff] [blame] | 65 | cpu = part_stat_lock(); |
Tejun Heo | 83096eb | 2009-05-07 22:24:39 +0900 | [diff] [blame] | 66 | part = disk_map_sector_rcu(rq->rq_disk, blk_rq_pos(rq)); |
Tejun Heo | c995905 | 2008-08-25 19:47:21 +0900 | [diff] [blame] | 67 | |
Jens Axboe | 28f1370 | 2008-05-07 10:15:46 +0200 | [diff] [blame] | 68 | if (!new_io) |
Tejun Heo | 074a7ac | 2008-08-25 19:56:14 +0900 | [diff] [blame] | 69 | part_stat_inc(cpu, part, merges[rw]); |
Jens Axboe | 28f1370 | 2008-05-07 10:15:46 +0200 | [diff] [blame] | 70 | else { |
Tejun Heo | 074a7ac | 2008-08-25 19:56:14 +0900 | [diff] [blame] | 71 | part_round_stats(cpu, part); |
| 72 | part_inc_in_flight(part); |
Jens Axboe | 26b8256 | 2008-01-29 13:54:41 +0100 | [diff] [blame] | 73 | } |
Tejun Heo | e71bf0d | 2008-09-03 09:03:02 +0200 | [diff] [blame] | 74 | |
Tejun Heo | 074a7ac | 2008-08-25 19:56:14 +0900 | [diff] [blame] | 75 | part_stat_unlock(); |
Jens Axboe | 26b8256 | 2008-01-29 13:54:41 +0100 | [diff] [blame] | 76 | } |
| 77 | |
Jens Axboe | 8324aa9 | 2008-01-29 14:51:59 +0100 | [diff] [blame] | 78 | void blk_queue_congestion_threshold(struct request_queue *q) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 79 | { |
| 80 | int nr; |
| 81 | |
| 82 | nr = q->nr_requests - (q->nr_requests / 8) + 1; |
| 83 | if (nr > q->nr_requests) |
| 84 | nr = q->nr_requests; |
| 85 | q->nr_congestion_on = nr; |
| 86 | |
| 87 | nr = q->nr_requests - (q->nr_requests / 8) - (q->nr_requests / 16) - 1; |
| 88 | if (nr < 1) |
| 89 | nr = 1; |
| 90 | q->nr_congestion_off = nr; |
| 91 | } |
| 92 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 93 | /** |
| 94 | * blk_get_backing_dev_info - get the address of a queue's backing_dev_info |
| 95 | * @bdev: device |
| 96 | * |
| 97 | * Locates the passed device's request queue and returns the address of its |
| 98 | * backing_dev_info |
| 99 | * |
| 100 | * Will return NULL if the request queue cannot be located. |
| 101 | */ |
| 102 | struct backing_dev_info *blk_get_backing_dev_info(struct block_device *bdev) |
| 103 | { |
| 104 | struct backing_dev_info *ret = NULL; |
Jens Axboe | 165125e | 2007-07-24 09:28:11 +0200 | [diff] [blame] | 105 | struct request_queue *q = bdev_get_queue(bdev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 106 | |
| 107 | if (q) |
| 108 | ret = &q->backing_dev_info; |
| 109 | return ret; |
| 110 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 111 | EXPORT_SYMBOL(blk_get_backing_dev_info); |
| 112 | |
FUJITA Tomonori | 2a4aa30 | 2008-04-29 09:54:36 +0200 | [diff] [blame] | 113 | void blk_rq_init(struct request_queue *q, struct request *rq) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 114 | { |
FUJITA Tomonori | 1afb20f | 2008-04-25 12:26:28 +0200 | [diff] [blame] | 115 | memset(rq, 0, sizeof(*rq)); |
| 116 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 117 | INIT_LIST_HEAD(&rq->queuelist); |
Jens Axboe | 242f9dc | 2008-09-14 05:55:09 -0700 | [diff] [blame] | 118 | INIT_LIST_HEAD(&rq->timeout_list); |
Jens Axboe | c7c22e4 | 2008-09-13 20:26:01 +0200 | [diff] [blame] | 119 | rq->cpu = -1; |
Jens Axboe | 63a7138 | 2008-02-08 12:41:03 +0100 | [diff] [blame] | 120 | rq->q = q; |
Tejun Heo | a2dec7b | 2009-05-07 22:24:44 +0900 | [diff] [blame] | 121 | rq->__sector = (sector_t) -1; |
Jens Axboe | 2e662b6 | 2006-07-13 11:55:04 +0200 | [diff] [blame] | 122 | INIT_HLIST_NODE(&rq->hash); |
| 123 | RB_CLEAR_NODE(&rq->rb_node); |
FUJITA Tomonori | d7e3c32 | 2008-04-29 09:54:39 +0200 | [diff] [blame] | 124 | rq->cmd = rq->__cmd; |
Li Zefan | e2494e1 | 2009-04-02 13:43:26 +0800 | [diff] [blame] | 125 | rq->cmd_len = BLK_MAX_CDB; |
Jens Axboe | 63a7138 | 2008-02-08 12:41:03 +0100 | [diff] [blame] | 126 | rq->tag = -1; |
Jens Axboe | 63a7138 | 2008-02-08 12:41:03 +0100 | [diff] [blame] | 127 | rq->ref_count = 1; |
Tejun Heo | b243ddc | 2009-04-23 11:05:18 +0900 | [diff] [blame] | 128 | rq->start_time = jiffies; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 129 | } |
FUJITA Tomonori | 2a4aa30 | 2008-04-29 09:54:36 +0200 | [diff] [blame] | 130 | EXPORT_SYMBOL(blk_rq_init); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 131 | |
NeilBrown | 5bb23a6 | 2007-09-27 12:46:13 +0200 | [diff] [blame] | 132 | static void req_bio_endio(struct request *rq, struct bio *bio, |
| 133 | unsigned int nbytes, int error) |
Tejun Heo | 797e7db | 2006-01-06 09:51:03 +0100 | [diff] [blame] | 134 | { |
Jens Axboe | 165125e | 2007-07-24 09:28:11 +0200 | [diff] [blame] | 135 | struct request_queue *q = rq->q; |
Tejun Heo | 797e7db | 2006-01-06 09:51:03 +0100 | [diff] [blame] | 136 | |
NeilBrown | 5bb23a6 | 2007-09-27 12:46:13 +0200 | [diff] [blame] | 137 | if (&q->bar_rq != rq) { |
| 138 | if (error) |
| 139 | clear_bit(BIO_UPTODATE, &bio->bi_flags); |
| 140 | else if (!test_bit(BIO_UPTODATE, &bio->bi_flags)) |
| 141 | error = -EIO; |
Tejun Heo | 797e7db | 2006-01-06 09:51:03 +0100 | [diff] [blame] | 142 | |
NeilBrown | 5bb23a6 | 2007-09-27 12:46:13 +0200 | [diff] [blame] | 143 | if (unlikely(nbytes > bio->bi_size)) { |
Jens Axboe | 6728cb0 | 2008-01-31 13:03:55 +0100 | [diff] [blame] | 144 | printk(KERN_ERR "%s: want %u bytes done, %u left\n", |
Harvey Harrison | 24c03d4 | 2008-05-01 04:35:17 -0700 | [diff] [blame] | 145 | __func__, nbytes, bio->bi_size); |
NeilBrown | 5bb23a6 | 2007-09-27 12:46:13 +0200 | [diff] [blame] | 146 | nbytes = bio->bi_size; |
| 147 | } |
Tejun Heo | 797e7db | 2006-01-06 09:51:03 +0100 | [diff] [blame] | 148 | |
Keith Mannthey | 08bafc0 | 2008-11-25 10:24:35 +0100 | [diff] [blame] | 149 | if (unlikely(rq->cmd_flags & REQ_QUIET)) |
| 150 | set_bit(BIO_QUIET, &bio->bi_flags); |
| 151 | |
NeilBrown | 5bb23a6 | 2007-09-27 12:46:13 +0200 | [diff] [blame] | 152 | bio->bi_size -= nbytes; |
| 153 | bio->bi_sector += (nbytes >> 9); |
Martin K. Petersen | 7ba1ba1 | 2008-06-30 20:04:41 +0200 | [diff] [blame] | 154 | |
| 155 | if (bio_integrity(bio)) |
| 156 | bio_integrity_advance(bio, nbytes); |
| 157 | |
NeilBrown | 5bb23a6 | 2007-09-27 12:46:13 +0200 | [diff] [blame] | 158 | if (bio->bi_size == 0) |
NeilBrown | 6712ecf | 2007-09-27 12:47:43 +0200 | [diff] [blame] | 159 | bio_endio(bio, error); |
NeilBrown | 5bb23a6 | 2007-09-27 12:46:13 +0200 | [diff] [blame] | 160 | } else { |
| 161 | |
| 162 | /* |
| 163 | * Okay, this is the barrier request in progress, just |
| 164 | * record the error; |
| 165 | */ |
| 166 | if (error && !q->orderr) |
| 167 | q->orderr = error; |
| 168 | } |
Tejun Heo | 797e7db | 2006-01-06 09:51:03 +0100 | [diff] [blame] | 169 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 170 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 171 | void blk_dump_rq_flags(struct request *rq, char *msg) |
| 172 | { |
| 173 | int bit; |
| 174 | |
Jens Axboe | 6728cb0 | 2008-01-31 13:03:55 +0100 | [diff] [blame] | 175 | printk(KERN_INFO "%s: dev %s: type=%x, flags=%x\n", msg, |
Jens Axboe | 4aff5e2 | 2006-08-10 08:44:47 +0200 | [diff] [blame] | 176 | rq->rq_disk ? rq->rq_disk->disk_name : "?", rq->cmd_type, |
| 177 | rq->cmd_flags); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 178 | |
Tejun Heo | 83096eb | 2009-05-07 22:24:39 +0900 | [diff] [blame] | 179 | printk(KERN_INFO " sector %llu, nr/cnr %u/%u\n", |
| 180 | (unsigned long long)blk_rq_pos(rq), |
| 181 | blk_rq_sectors(rq), blk_rq_cur_sectors(rq)); |
Tejun Heo | 731ec49 | 2009-04-23 11:05:20 +0900 | [diff] [blame] | 182 | printk(KERN_INFO " bio %p, biotail %p, buffer %p, len %u\n", |
Tejun Heo | 2e46e8b | 2009-05-07 22:24:41 +0900 | [diff] [blame] | 183 | rq->bio, rq->biotail, rq->buffer, blk_rq_bytes(rq)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 184 | |
Jens Axboe | 4aff5e2 | 2006-08-10 08:44:47 +0200 | [diff] [blame] | 185 | if (blk_pc_request(rq)) { |
Jens Axboe | 6728cb0 | 2008-01-31 13:03:55 +0100 | [diff] [blame] | 186 | printk(KERN_INFO " cdb: "); |
FUJITA Tomonori | d34c87e | 2008-04-29 14:37:52 +0200 | [diff] [blame] | 187 | for (bit = 0; bit < BLK_MAX_CDB; bit++) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 188 | printk("%02x ", rq->cmd[bit]); |
| 189 | printk("\n"); |
| 190 | } |
| 191 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 192 | EXPORT_SYMBOL(blk_dump_rq_flags); |
| 193 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 194 | /* |
| 195 | * "plug" the device if there are no outstanding requests: this will |
| 196 | * force the transfer to start only after we have put all the requests |
| 197 | * on the list. |
| 198 | * |
| 199 | * This is called with interrupts off and no requests on the queue and |
| 200 | * with the queue lock held. |
| 201 | */ |
Jens Axboe | 165125e | 2007-07-24 09:28:11 +0200 | [diff] [blame] | 202 | void blk_plug_device(struct request_queue *q) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 203 | { |
| 204 | WARN_ON(!irqs_disabled()); |
| 205 | |
| 206 | /* |
| 207 | * don't plug a stopped queue, it must be paired with blk_start_queue() |
| 208 | * which will restart the queueing |
| 209 | */ |
Coywolf Qi Hunt | 7daac49 | 2006-04-19 10:14:49 +0200 | [diff] [blame] | 210 | if (blk_queue_stopped(q)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 211 | return; |
| 212 | |
Jens Axboe | e48ec69 | 2008-07-03 13:18:54 +0200 | [diff] [blame] | 213 | if (!queue_flag_test_and_set(QUEUE_FLAG_PLUGGED, q)) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 214 | mod_timer(&q->unplug_timer, jiffies + q->unplug_delay); |
Arnaldo Carvalho de Melo | 5f3ea37 | 2008-10-30 08:34:33 +0100 | [diff] [blame] | 215 | trace_block_plug(q); |
Jens Axboe | 2056a78 | 2006-03-23 20:00:26 +0100 | [diff] [blame] | 216 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 217 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 218 | EXPORT_SYMBOL(blk_plug_device); |
| 219 | |
Jens Axboe | 6c5e0c4 | 2008-08-01 20:31:32 +0200 | [diff] [blame] | 220 | /** |
| 221 | * blk_plug_device_unlocked - plug a device without queue lock held |
| 222 | * @q: The &struct request_queue to plug |
| 223 | * |
| 224 | * Description: |
| 225 | * Like @blk_plug_device(), but grabs the queue lock and disables |
| 226 | * interrupts. |
| 227 | **/ |
| 228 | void blk_plug_device_unlocked(struct request_queue *q) |
| 229 | { |
| 230 | unsigned long flags; |
| 231 | |
| 232 | spin_lock_irqsave(q->queue_lock, flags); |
| 233 | blk_plug_device(q); |
| 234 | spin_unlock_irqrestore(q->queue_lock, flags); |
| 235 | } |
| 236 | EXPORT_SYMBOL(blk_plug_device_unlocked); |
| 237 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 238 | /* |
| 239 | * remove the queue from the plugged list, if present. called with |
| 240 | * queue lock held and interrupts disabled. |
| 241 | */ |
Jens Axboe | 165125e | 2007-07-24 09:28:11 +0200 | [diff] [blame] | 242 | int blk_remove_plug(struct request_queue *q) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 243 | { |
| 244 | WARN_ON(!irqs_disabled()); |
| 245 | |
Jens Axboe | e48ec69 | 2008-07-03 13:18:54 +0200 | [diff] [blame] | 246 | if (!queue_flag_test_and_clear(QUEUE_FLAG_PLUGGED, q)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 247 | return 0; |
| 248 | |
| 249 | del_timer(&q->unplug_timer); |
| 250 | return 1; |
| 251 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 252 | EXPORT_SYMBOL(blk_remove_plug); |
| 253 | |
| 254 | /* |
| 255 | * remove the plug and let it rip.. |
| 256 | */ |
Jens Axboe | 165125e | 2007-07-24 09:28:11 +0200 | [diff] [blame] | 257 | void __generic_unplug_device(struct request_queue *q) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 258 | { |
Coywolf Qi Hunt | 7daac49 | 2006-04-19 10:14:49 +0200 | [diff] [blame] | 259 | if (unlikely(blk_queue_stopped(q))) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 260 | return; |
Jens Axboe | a31a973 | 2008-10-17 13:58:29 +0200 | [diff] [blame] | 261 | if (!blk_remove_plug(q) && !blk_queue_nonrot(q)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 262 | return; |
| 263 | |
Jens Axboe | 22e2c50 | 2005-06-27 10:55:12 +0200 | [diff] [blame] | 264 | q->request_fn(q); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 265 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 266 | |
| 267 | /** |
| 268 | * generic_unplug_device - fire a request queue |
Jens Axboe | 165125e | 2007-07-24 09:28:11 +0200 | [diff] [blame] | 269 | * @q: The &struct request_queue in question |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 270 | * |
| 271 | * Description: |
| 272 | * Linux uses plugging to build bigger requests queues before letting |
| 273 | * the device have at them. If a queue is plugged, the I/O scheduler |
| 274 | * is still adding and merging requests on the queue. Once the queue |
| 275 | * gets unplugged, the request_fn defined for the queue is invoked and |
| 276 | * transfers started. |
| 277 | **/ |
Jens Axboe | 165125e | 2007-07-24 09:28:11 +0200 | [diff] [blame] | 278 | void generic_unplug_device(struct request_queue *q) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 279 | { |
Jens Axboe | dbaf2c0 | 2008-05-07 09:48:17 +0200 | [diff] [blame] | 280 | if (blk_queue_plugged(q)) { |
| 281 | spin_lock_irq(q->queue_lock); |
| 282 | __generic_unplug_device(q); |
| 283 | spin_unlock_irq(q->queue_lock); |
| 284 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 285 | } |
| 286 | EXPORT_SYMBOL(generic_unplug_device); |
| 287 | |
| 288 | static void blk_backing_dev_unplug(struct backing_dev_info *bdi, |
| 289 | struct page *page) |
| 290 | { |
Jens Axboe | 165125e | 2007-07-24 09:28:11 +0200 | [diff] [blame] | 291 | struct request_queue *q = bdi->unplug_io_data; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 292 | |
Alan D. Brunelle | 2ad8b1e | 2007-11-07 14:26:56 -0500 | [diff] [blame] | 293 | blk_unplug(q); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 294 | } |
| 295 | |
Jens Axboe | 86db1e2 | 2008-01-29 14:53:40 +0100 | [diff] [blame] | 296 | void blk_unplug_work(struct work_struct *work) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 297 | { |
Jens Axboe | 165125e | 2007-07-24 09:28:11 +0200 | [diff] [blame] | 298 | struct request_queue *q = |
| 299 | container_of(work, struct request_queue, unplug_work); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 300 | |
Arnaldo Carvalho de Melo | 5f3ea37 | 2008-10-30 08:34:33 +0100 | [diff] [blame] | 301 | trace_block_unplug_io(q); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 302 | q->unplug_fn(q); |
| 303 | } |
| 304 | |
Jens Axboe | 86db1e2 | 2008-01-29 14:53:40 +0100 | [diff] [blame] | 305 | void blk_unplug_timeout(unsigned long data) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 306 | { |
Jens Axboe | 165125e | 2007-07-24 09:28:11 +0200 | [diff] [blame] | 307 | struct request_queue *q = (struct request_queue *)data; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 308 | |
Arnaldo Carvalho de Melo | 5f3ea37 | 2008-10-30 08:34:33 +0100 | [diff] [blame] | 309 | trace_block_unplug_timer(q); |
Jens Axboe | 18887ad | 2008-07-28 13:08:45 +0200 | [diff] [blame] | 310 | kblockd_schedule_work(q, &q->unplug_work); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 311 | } |
| 312 | |
Alan D. Brunelle | 2ad8b1e | 2007-11-07 14:26:56 -0500 | [diff] [blame] | 313 | void blk_unplug(struct request_queue *q) |
| 314 | { |
| 315 | /* |
| 316 | * devices don't necessarily have an ->unplug_fn defined |
| 317 | */ |
| 318 | if (q->unplug_fn) { |
Arnaldo Carvalho de Melo | 5f3ea37 | 2008-10-30 08:34:33 +0100 | [diff] [blame] | 319 | trace_block_unplug_io(q); |
Alan D. Brunelle | 2ad8b1e | 2007-11-07 14:26:56 -0500 | [diff] [blame] | 320 | q->unplug_fn(q); |
| 321 | } |
| 322 | } |
| 323 | EXPORT_SYMBOL(blk_unplug); |
| 324 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 325 | /** |
| 326 | * blk_start_queue - restart a previously stopped queue |
Jens Axboe | 165125e | 2007-07-24 09:28:11 +0200 | [diff] [blame] | 327 | * @q: The &struct request_queue in question |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 328 | * |
| 329 | * Description: |
| 330 | * blk_start_queue() will clear the stop flag on the queue, and call |
| 331 | * the request_fn for the queue if it was in a stopped state when |
| 332 | * entered. Also see blk_stop_queue(). Queue lock must be held. |
| 333 | **/ |
Jens Axboe | 165125e | 2007-07-24 09:28:11 +0200 | [diff] [blame] | 334 | void blk_start_queue(struct request_queue *q) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 335 | { |
Paolo 'Blaisorblade' Giarrusso | a038e25 | 2006-06-05 12:09:01 +0200 | [diff] [blame] | 336 | WARN_ON(!irqs_disabled()); |
| 337 | |
Nick Piggin | 75ad23b | 2008-04-29 14:48:33 +0200 | [diff] [blame] | 338 | queue_flag_clear(QUEUE_FLAG_STOPPED, q); |
Tejun Heo | a538cd0 | 2009-04-23 11:05:17 +0900 | [diff] [blame] | 339 | __blk_run_queue(q); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 340 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 341 | EXPORT_SYMBOL(blk_start_queue); |
| 342 | |
| 343 | /** |
| 344 | * blk_stop_queue - stop a queue |
Jens Axboe | 165125e | 2007-07-24 09:28:11 +0200 | [diff] [blame] | 345 | * @q: The &struct request_queue in question |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 346 | * |
| 347 | * Description: |
| 348 | * The Linux block layer assumes that a block driver will consume all |
| 349 | * entries on the request queue when the request_fn strategy is called. |
| 350 | * Often this will not happen, because of hardware limitations (queue |
| 351 | * depth settings). If a device driver gets a 'queue full' response, |
| 352 | * or if it simply chooses not to queue more I/O at one point, it can |
| 353 | * call this function to prevent the request_fn from being called until |
| 354 | * the driver has signalled it's ready to go again. This happens by calling |
| 355 | * blk_start_queue() to restart queue operations. Queue lock must be held. |
| 356 | **/ |
Jens Axboe | 165125e | 2007-07-24 09:28:11 +0200 | [diff] [blame] | 357 | void blk_stop_queue(struct request_queue *q) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 358 | { |
| 359 | blk_remove_plug(q); |
Nick Piggin | 75ad23b | 2008-04-29 14:48:33 +0200 | [diff] [blame] | 360 | queue_flag_set(QUEUE_FLAG_STOPPED, q); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 361 | } |
| 362 | EXPORT_SYMBOL(blk_stop_queue); |
| 363 | |
| 364 | /** |
| 365 | * blk_sync_queue - cancel any pending callbacks on a queue |
| 366 | * @q: the queue |
| 367 | * |
| 368 | * Description: |
| 369 | * The block layer may perform asynchronous callback activity |
| 370 | * on a queue, such as calling the unplug function after a timeout. |
| 371 | * A block device may call blk_sync_queue to ensure that any |
| 372 | * such activity is cancelled, thus allowing it to release resources |
Michael Opdenacker | 59c5159 | 2007-05-09 08:57:56 +0200 | [diff] [blame] | 373 | * that the callbacks might use. The caller must already have made sure |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 374 | * that its ->make_request_fn will not re-add plugging prior to calling |
| 375 | * this function. |
| 376 | * |
| 377 | */ |
| 378 | void blk_sync_queue(struct request_queue *q) |
| 379 | { |
| 380 | del_timer_sync(&q->unplug_timer); |
Jens Axboe | 70ed28b | 2008-11-19 14:38:39 +0100 | [diff] [blame] | 381 | del_timer_sync(&q->timeout); |
Cheng Renquan | 64d01dc | 2008-12-03 12:41:39 +0100 | [diff] [blame] | 382 | cancel_work_sync(&q->unplug_work); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 383 | } |
| 384 | EXPORT_SYMBOL(blk_sync_queue); |
| 385 | |
| 386 | /** |
Jens Axboe | 80a4b58 | 2008-10-14 09:51:06 +0200 | [diff] [blame] | 387 | * __blk_run_queue - run a single device queue |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 388 | * @q: The queue to run |
Jens Axboe | 80a4b58 | 2008-10-14 09:51:06 +0200 | [diff] [blame] | 389 | * |
| 390 | * Description: |
| 391 | * See @blk_run_queue. This variant must be called with the queue lock |
| 392 | * held and interrupts disabled. |
| 393 | * |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 394 | */ |
Nick Piggin | 75ad23b | 2008-04-29 14:48:33 +0200 | [diff] [blame] | 395 | void __blk_run_queue(struct request_queue *q) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 396 | { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 397 | blk_remove_plug(q); |
Jens Axboe | dac07ec | 2006-05-11 08:20:16 +0200 | [diff] [blame] | 398 | |
Tejun Heo | a538cd0 | 2009-04-23 11:05:17 +0900 | [diff] [blame] | 399 | if (unlikely(blk_queue_stopped(q))) |
| 400 | return; |
| 401 | |
| 402 | if (elv_queue_empty(q)) |
| 403 | return; |
| 404 | |
Jens Axboe | dac07ec | 2006-05-11 08:20:16 +0200 | [diff] [blame] | 405 | /* |
| 406 | * Only recurse once to avoid overrunning the stack, let the unplug |
| 407 | * handling reinvoke the handler shortly if we already got there. |
| 408 | */ |
Tejun Heo | a538cd0 | 2009-04-23 11:05:17 +0900 | [diff] [blame] | 409 | if (!queue_flag_test_and_set(QUEUE_FLAG_REENTER, q)) { |
| 410 | q->request_fn(q); |
| 411 | queue_flag_clear(QUEUE_FLAG_REENTER, q); |
| 412 | } else { |
| 413 | queue_flag_set(QUEUE_FLAG_PLUGGED, q); |
| 414 | kblockd_schedule_work(q, &q->unplug_work); |
| 415 | } |
Nick Piggin | 75ad23b | 2008-04-29 14:48:33 +0200 | [diff] [blame] | 416 | } |
| 417 | EXPORT_SYMBOL(__blk_run_queue); |
Jens Axboe | dac07ec | 2006-05-11 08:20:16 +0200 | [diff] [blame] | 418 | |
Nick Piggin | 75ad23b | 2008-04-29 14:48:33 +0200 | [diff] [blame] | 419 | /** |
| 420 | * blk_run_queue - run a single device queue |
| 421 | * @q: The queue to run |
Jens Axboe | 80a4b58 | 2008-10-14 09:51:06 +0200 | [diff] [blame] | 422 | * |
| 423 | * Description: |
| 424 | * Invoke request handling on this queue, if it has pending work to do. |
Tejun Heo | a7f5579 | 2009-04-23 11:05:17 +0900 | [diff] [blame] | 425 | * May be used to restart queueing when a request has completed. |
Nick Piggin | 75ad23b | 2008-04-29 14:48:33 +0200 | [diff] [blame] | 426 | */ |
| 427 | void blk_run_queue(struct request_queue *q) |
| 428 | { |
| 429 | unsigned long flags; |
| 430 | |
| 431 | spin_lock_irqsave(q->queue_lock, flags); |
| 432 | __blk_run_queue(q); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 433 | spin_unlock_irqrestore(q->queue_lock, flags); |
| 434 | } |
| 435 | EXPORT_SYMBOL(blk_run_queue); |
| 436 | |
Jens Axboe | 165125e | 2007-07-24 09:28:11 +0200 | [diff] [blame] | 437 | void blk_put_queue(struct request_queue *q) |
Al Viro | 483f4af | 2006-03-18 18:34:37 -0500 | [diff] [blame] | 438 | { |
| 439 | kobject_put(&q->kobj); |
| 440 | } |
Al Viro | 483f4af | 2006-03-18 18:34:37 -0500 | [diff] [blame] | 441 | |
Jens Axboe | 6728cb0 | 2008-01-31 13:03:55 +0100 | [diff] [blame] | 442 | void blk_cleanup_queue(struct request_queue *q) |
Al Viro | 483f4af | 2006-03-18 18:34:37 -0500 | [diff] [blame] | 443 | { |
Jens Axboe | e3335de | 2008-09-18 09:22:54 -0700 | [diff] [blame] | 444 | /* |
| 445 | * We know we have process context here, so we can be a little |
| 446 | * cautious and ensure that pending block actions on this device |
| 447 | * are done before moving on. Going into this function, we should |
| 448 | * not have processes doing IO to this device. |
| 449 | */ |
| 450 | blk_sync_queue(q); |
| 451 | |
Al Viro | 483f4af | 2006-03-18 18:34:37 -0500 | [diff] [blame] | 452 | mutex_lock(&q->sysfs_lock); |
Nick Piggin | 75ad23b | 2008-04-29 14:48:33 +0200 | [diff] [blame] | 453 | queue_flag_set_unlocked(QUEUE_FLAG_DEAD, q); |
Al Viro | 483f4af | 2006-03-18 18:34:37 -0500 | [diff] [blame] | 454 | mutex_unlock(&q->sysfs_lock); |
| 455 | |
| 456 | if (q->elevator) |
| 457 | elevator_exit(q->elevator); |
| 458 | |
| 459 | blk_put_queue(q); |
| 460 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 461 | EXPORT_SYMBOL(blk_cleanup_queue); |
| 462 | |
Jens Axboe | 165125e | 2007-07-24 09:28:11 +0200 | [diff] [blame] | 463 | static int blk_init_free_list(struct request_queue *q) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 464 | { |
| 465 | struct request_list *rl = &q->rq; |
| 466 | |
Jens Axboe | 1faa16d | 2009-04-06 14:48:01 +0200 | [diff] [blame] | 467 | rl->count[BLK_RW_SYNC] = rl->count[BLK_RW_ASYNC] = 0; |
| 468 | rl->starved[BLK_RW_SYNC] = rl->starved[BLK_RW_ASYNC] = 0; |
Tejun Heo | cb98fc8 | 2005-10-28 08:29:39 +0200 | [diff] [blame] | 469 | rl->elvpriv = 0; |
Jens Axboe | 1faa16d | 2009-04-06 14:48:01 +0200 | [diff] [blame] | 470 | init_waitqueue_head(&rl->wait[BLK_RW_SYNC]); |
| 471 | init_waitqueue_head(&rl->wait[BLK_RW_ASYNC]); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 472 | |
Christoph Lameter | 1946089 | 2005-06-23 00:08:19 -0700 | [diff] [blame] | 473 | rl->rq_pool = mempool_create_node(BLKDEV_MIN_RQ, mempool_alloc_slab, |
| 474 | mempool_free_slab, request_cachep, q->node); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 475 | |
| 476 | if (!rl->rq_pool) |
| 477 | return -ENOMEM; |
| 478 | |
| 479 | return 0; |
| 480 | } |
| 481 | |
Jens Axboe | 165125e | 2007-07-24 09:28:11 +0200 | [diff] [blame] | 482 | struct request_queue *blk_alloc_queue(gfp_t gfp_mask) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 483 | { |
Christoph Lameter | 1946089 | 2005-06-23 00:08:19 -0700 | [diff] [blame] | 484 | return blk_alloc_queue_node(gfp_mask, -1); |
| 485 | } |
| 486 | EXPORT_SYMBOL(blk_alloc_queue); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 487 | |
Jens Axboe | 165125e | 2007-07-24 09:28:11 +0200 | [diff] [blame] | 488 | struct request_queue *blk_alloc_queue_node(gfp_t gfp_mask, int node_id) |
Christoph Lameter | 1946089 | 2005-06-23 00:08:19 -0700 | [diff] [blame] | 489 | { |
Jens Axboe | 165125e | 2007-07-24 09:28:11 +0200 | [diff] [blame] | 490 | struct request_queue *q; |
Peter Zijlstra | e0bf68d | 2007-10-16 23:25:46 -0700 | [diff] [blame] | 491 | int err; |
Christoph Lameter | 1946089 | 2005-06-23 00:08:19 -0700 | [diff] [blame] | 492 | |
Jens Axboe | 8324aa9 | 2008-01-29 14:51:59 +0100 | [diff] [blame] | 493 | q = kmem_cache_alloc_node(blk_requestq_cachep, |
Christoph Lameter | 94f6030 | 2007-07-17 04:03:29 -0700 | [diff] [blame] | 494 | gfp_mask | __GFP_ZERO, node_id); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 495 | if (!q) |
| 496 | return NULL; |
| 497 | |
Peter Zijlstra | e0bf68d | 2007-10-16 23:25:46 -0700 | [diff] [blame] | 498 | q->backing_dev_info.unplug_io_fn = blk_backing_dev_unplug; |
| 499 | q->backing_dev_info.unplug_io_data = q; |
Jens Axboe | 0989a02 | 2009-06-12 14:42:56 +0200 | [diff] [blame] | 500 | q->backing_dev_info.ra_pages = |
| 501 | (VM_MAX_READAHEAD * 1024) / PAGE_CACHE_SIZE; |
| 502 | q->backing_dev_info.state = 0; |
| 503 | q->backing_dev_info.capabilities = BDI_CAP_MAP_COPY; |
| 504 | |
Peter Zijlstra | e0bf68d | 2007-10-16 23:25:46 -0700 | [diff] [blame] | 505 | err = bdi_init(&q->backing_dev_info); |
| 506 | if (err) { |
Jens Axboe | 8324aa9 | 2008-01-29 14:51:59 +0100 | [diff] [blame] | 507 | kmem_cache_free(blk_requestq_cachep, q); |
Peter Zijlstra | e0bf68d | 2007-10-16 23:25:46 -0700 | [diff] [blame] | 508 | return NULL; |
| 509 | } |
| 510 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 511 | init_timer(&q->unplug_timer); |
Jens Axboe | 242f9dc | 2008-09-14 05:55:09 -0700 | [diff] [blame] | 512 | setup_timer(&q->timeout, blk_rq_timed_out_timer, (unsigned long) q); |
| 513 | INIT_LIST_HEAD(&q->timeout_list); |
Peter Zijlstra | 713ada9 | 2008-10-16 13:44:57 +0200 | [diff] [blame] | 514 | INIT_WORK(&q->unplug_work, blk_unplug_work); |
Al Viro | 483f4af | 2006-03-18 18:34:37 -0500 | [diff] [blame] | 515 | |
Jens Axboe | 8324aa9 | 2008-01-29 14:51:59 +0100 | [diff] [blame] | 516 | kobject_init(&q->kobj, &blk_queue_ktype); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 517 | |
Al Viro | 483f4af | 2006-03-18 18:34:37 -0500 | [diff] [blame] | 518 | mutex_init(&q->sysfs_lock); |
Neil Brown | e7e72bf | 2008-05-14 16:05:54 -0700 | [diff] [blame] | 519 | spin_lock_init(&q->__queue_lock); |
Al Viro | 483f4af | 2006-03-18 18:34:37 -0500 | [diff] [blame] | 520 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 521 | return q; |
| 522 | } |
Christoph Lameter | 1946089 | 2005-06-23 00:08:19 -0700 | [diff] [blame] | 523 | EXPORT_SYMBOL(blk_alloc_queue_node); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 524 | |
| 525 | /** |
| 526 | * blk_init_queue - prepare a request queue for use with a block device |
| 527 | * @rfn: The function to be called to process requests that have been |
| 528 | * placed on the queue. |
| 529 | * @lock: Request queue spin lock |
| 530 | * |
| 531 | * Description: |
| 532 | * If a block device wishes to use the standard request handling procedures, |
| 533 | * which sorts requests and coalesces adjacent requests, then it must |
| 534 | * call blk_init_queue(). The function @rfn will be called when there |
| 535 | * are requests on the queue that need to be processed. If the device |
| 536 | * supports plugging, then @rfn may not be called immediately when requests |
| 537 | * are available on the queue, but may be called at some time later instead. |
| 538 | * Plugged queues are generally unplugged when a buffer belonging to one |
| 539 | * of the requests on the queue is needed, or due to memory pressure. |
| 540 | * |
| 541 | * @rfn is not required, or even expected, to remove all requests off the |
| 542 | * queue, but only as many as it can handle at a time. If it does leave |
| 543 | * requests on the queue, it is responsible for arranging that the requests |
| 544 | * get dealt with eventually. |
| 545 | * |
| 546 | * The queue spin lock must be held while manipulating the requests on the |
Paolo 'Blaisorblade' Giarrusso | a038e25 | 2006-06-05 12:09:01 +0200 | [diff] [blame] | 547 | * request queue; this lock will be taken also from interrupt context, so irq |
| 548 | * disabling is needed for it. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 549 | * |
Randy Dunlap | 710027a | 2008-08-19 20:13:11 +0200 | [diff] [blame] | 550 | * Function returns a pointer to the initialized request queue, or %NULL if |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 551 | * it didn't succeed. |
| 552 | * |
| 553 | * Note: |
| 554 | * blk_init_queue() must be paired with a blk_cleanup_queue() call |
| 555 | * when the block device is deactivated (such as at module unload). |
| 556 | **/ |
Christoph Lameter | 1946089 | 2005-06-23 00:08:19 -0700 | [diff] [blame] | 557 | |
Jens Axboe | 165125e | 2007-07-24 09:28:11 +0200 | [diff] [blame] | 558 | struct request_queue *blk_init_queue(request_fn_proc *rfn, spinlock_t *lock) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 559 | { |
Christoph Lameter | 1946089 | 2005-06-23 00:08:19 -0700 | [diff] [blame] | 560 | return blk_init_queue_node(rfn, lock, -1); |
| 561 | } |
| 562 | EXPORT_SYMBOL(blk_init_queue); |
| 563 | |
Jens Axboe | 165125e | 2007-07-24 09:28:11 +0200 | [diff] [blame] | 564 | struct request_queue * |
Christoph Lameter | 1946089 | 2005-06-23 00:08:19 -0700 | [diff] [blame] | 565 | blk_init_queue_node(request_fn_proc *rfn, spinlock_t *lock, int node_id) |
| 566 | { |
Jens Axboe | 165125e | 2007-07-24 09:28:11 +0200 | [diff] [blame] | 567 | struct request_queue *q = blk_alloc_queue_node(GFP_KERNEL, node_id); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 568 | |
| 569 | if (!q) |
| 570 | return NULL; |
| 571 | |
Christoph Lameter | 1946089 | 2005-06-23 00:08:19 -0700 | [diff] [blame] | 572 | q->node = node_id; |
Al Viro | 8669aaf | 2006-03-18 13:50:00 -0500 | [diff] [blame] | 573 | if (blk_init_free_list(q)) { |
Jens Axboe | 8324aa9 | 2008-01-29 14:51:59 +0100 | [diff] [blame] | 574 | kmem_cache_free(blk_requestq_cachep, q); |
Al Viro | 8669aaf | 2006-03-18 13:50:00 -0500 | [diff] [blame] | 575 | return NULL; |
| 576 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 577 | |
| 152587d | 2005-04-12 16:22:06 -0500 | [diff] [blame] | 578 | /* |
| 579 | * if caller didn't supply a lock, they get per-queue locking with |
| 580 | * our embedded lock |
| 581 | */ |
Neil Brown | e7e72bf | 2008-05-14 16:05:54 -0700 | [diff] [blame] | 582 | if (!lock) |
| 152587d | 2005-04-12 16:22:06 -0500 | [diff] [blame] | 583 | lock = &q->__queue_lock; |
| 152587d | 2005-04-12 16:22:06 -0500 | [diff] [blame] | 584 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 585 | q->request_fn = rfn; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 586 | q->prep_rq_fn = NULL; |
| 587 | q->unplug_fn = generic_unplug_device; |
Jens Axboe | bc58ba9 | 2009-01-23 10:54:44 +0100 | [diff] [blame] | 588 | q->queue_flags = QUEUE_FLAG_DEFAULT; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 589 | q->queue_lock = lock; |
| 590 | |
Jens Axboe | f3b144a | 2009-03-06 08:48:33 +0100 | [diff] [blame] | 591 | /* |
| 592 | * This also sets hw/phys segments, boundary and size |
| 593 | */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 594 | blk_queue_make_request(q, __make_request); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 595 | |
Alan Stern | 44ec954 | 2007-02-20 11:01:57 -0500 | [diff] [blame] | 596 | q->sg_reserved_size = INT_MAX; |
| 597 | |
FUJITA Tomonori | abf5439 | 2008-08-16 14:10:05 +0900 | [diff] [blame] | 598 | blk_set_cmd_filter_defaults(&q->cmd_filter); |
| 599 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 600 | /* |
| 601 | * all done |
| 602 | */ |
| 603 | if (!elevator_init(q, NULL)) { |
| 604 | blk_queue_congestion_threshold(q); |
| 605 | return q; |
| 606 | } |
| 607 | |
Al Viro | 8669aaf | 2006-03-18 13:50:00 -0500 | [diff] [blame] | 608 | blk_put_queue(q); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 609 | return NULL; |
| 610 | } |
Christoph Lameter | 1946089 | 2005-06-23 00:08:19 -0700 | [diff] [blame] | 611 | EXPORT_SYMBOL(blk_init_queue_node); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 612 | |
Jens Axboe | 165125e | 2007-07-24 09:28:11 +0200 | [diff] [blame] | 613 | int blk_get_queue(struct request_queue *q) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 614 | { |
Nick Piggin | fde6ad2 | 2005-06-23 00:08:53 -0700 | [diff] [blame] | 615 | if (likely(!test_bit(QUEUE_FLAG_DEAD, &q->queue_flags))) { |
Al Viro | 483f4af | 2006-03-18 18:34:37 -0500 | [diff] [blame] | 616 | kobject_get(&q->kobj); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 617 | return 0; |
| 618 | } |
| 619 | |
| 620 | return 1; |
| 621 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 622 | |
Jens Axboe | 165125e | 2007-07-24 09:28:11 +0200 | [diff] [blame] | 623 | static inline void blk_free_request(struct request_queue *q, struct request *rq) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 624 | { |
Jens Axboe | 4aff5e2 | 2006-08-10 08:44:47 +0200 | [diff] [blame] | 625 | if (rq->cmd_flags & REQ_ELVPRIV) |
Tejun Heo | cb98fc8 | 2005-10-28 08:29:39 +0200 | [diff] [blame] | 626 | elv_put_request(q, rq); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 627 | mempool_free(rq, q->rq.rq_pool); |
| 628 | } |
| 629 | |
Jens Axboe | 1ea25ecb | 2006-07-18 22:24:11 +0200 | [diff] [blame] | 630 | static struct request * |
Jerome Marchand | 42dad76 | 2009-04-22 14:01:49 +0200 | [diff] [blame] | 631 | blk_alloc_request(struct request_queue *q, int flags, int priv, gfp_t gfp_mask) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 632 | { |
| 633 | struct request *rq = mempool_alloc(q->rq.rq_pool, gfp_mask); |
| 634 | |
| 635 | if (!rq) |
| 636 | return NULL; |
| 637 | |
FUJITA Tomonori | 2a4aa30 | 2008-04-29 09:54:36 +0200 | [diff] [blame] | 638 | blk_rq_init(q, rq); |
FUJITA Tomonori | 1afb20f | 2008-04-25 12:26:28 +0200 | [diff] [blame] | 639 | |
Jerome Marchand | 42dad76 | 2009-04-22 14:01:49 +0200 | [diff] [blame] | 640 | rq->cmd_flags = flags | REQ_ALLOCED; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 641 | |
Tejun Heo | cb98fc8 | 2005-10-28 08:29:39 +0200 | [diff] [blame] | 642 | if (priv) { |
Jens Axboe | cb78b28 | 2006-07-28 09:32:57 +0200 | [diff] [blame] | 643 | if (unlikely(elv_set_request(q, rq, gfp_mask))) { |
Tejun Heo | cb98fc8 | 2005-10-28 08:29:39 +0200 | [diff] [blame] | 644 | mempool_free(rq, q->rq.rq_pool); |
| 645 | return NULL; |
| 646 | } |
Jens Axboe | 4aff5e2 | 2006-08-10 08:44:47 +0200 | [diff] [blame] | 647 | rq->cmd_flags |= REQ_ELVPRIV; |
Tejun Heo | cb98fc8 | 2005-10-28 08:29:39 +0200 | [diff] [blame] | 648 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 649 | |
Tejun Heo | cb98fc8 | 2005-10-28 08:29:39 +0200 | [diff] [blame] | 650 | return rq; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 651 | } |
| 652 | |
| 653 | /* |
| 654 | * ioc_batching returns true if the ioc is a valid batching request and |
| 655 | * should be given priority access to a request. |
| 656 | */ |
Jens Axboe | 165125e | 2007-07-24 09:28:11 +0200 | [diff] [blame] | 657 | static inline int ioc_batching(struct request_queue *q, struct io_context *ioc) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 658 | { |
| 659 | if (!ioc) |
| 660 | return 0; |
| 661 | |
| 662 | /* |
| 663 | * Make sure the process is able to allocate at least 1 request |
| 664 | * even if the batch times out, otherwise we could theoretically |
| 665 | * lose wakeups. |
| 666 | */ |
| 667 | return ioc->nr_batch_requests == q->nr_batching || |
| 668 | (ioc->nr_batch_requests > 0 |
| 669 | && time_before(jiffies, ioc->last_waited + BLK_BATCH_TIME)); |
| 670 | } |
| 671 | |
| 672 | /* |
| 673 | * ioc_set_batching sets ioc to be a new "batcher" if it is not one. This |
| 674 | * will cause the process to be a "batcher" on all queues in the system. This |
| 675 | * is the behaviour we want though - once it gets a wakeup it should be given |
| 676 | * a nice run. |
| 677 | */ |
Jens Axboe | 165125e | 2007-07-24 09:28:11 +0200 | [diff] [blame] | 678 | static void ioc_set_batching(struct request_queue *q, struct io_context *ioc) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 679 | { |
| 680 | if (!ioc || ioc_batching(q, ioc)) |
| 681 | return; |
| 682 | |
| 683 | ioc->nr_batch_requests = q->nr_batching; |
| 684 | ioc->last_waited = jiffies; |
| 685 | } |
| 686 | |
Jens Axboe | 1faa16d | 2009-04-06 14:48:01 +0200 | [diff] [blame] | 687 | static void __freed_request(struct request_queue *q, int sync) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 688 | { |
| 689 | struct request_list *rl = &q->rq; |
| 690 | |
Jens Axboe | 1faa16d | 2009-04-06 14:48:01 +0200 | [diff] [blame] | 691 | if (rl->count[sync] < queue_congestion_off_threshold(q)) |
| 692 | blk_clear_queue_congested(q, sync); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 693 | |
Jens Axboe | 1faa16d | 2009-04-06 14:48:01 +0200 | [diff] [blame] | 694 | if (rl->count[sync] + 1 <= q->nr_requests) { |
| 695 | if (waitqueue_active(&rl->wait[sync])) |
| 696 | wake_up(&rl->wait[sync]); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 697 | |
Jens Axboe | 1faa16d | 2009-04-06 14:48:01 +0200 | [diff] [blame] | 698 | blk_clear_queue_full(q, sync); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 699 | } |
| 700 | } |
| 701 | |
| 702 | /* |
| 703 | * A request has just been released. Account for it, update the full and |
| 704 | * congestion status, wake up any waiters. Called under q->queue_lock. |
| 705 | */ |
Jens Axboe | 1faa16d | 2009-04-06 14:48:01 +0200 | [diff] [blame] | 706 | static void freed_request(struct request_queue *q, int sync, int priv) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 707 | { |
| 708 | struct request_list *rl = &q->rq; |
| 709 | |
Jens Axboe | 1faa16d | 2009-04-06 14:48:01 +0200 | [diff] [blame] | 710 | rl->count[sync]--; |
Tejun Heo | cb98fc8 | 2005-10-28 08:29:39 +0200 | [diff] [blame] | 711 | if (priv) |
| 712 | rl->elvpriv--; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 713 | |
Jens Axboe | 1faa16d | 2009-04-06 14:48:01 +0200 | [diff] [blame] | 714 | __freed_request(q, sync); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 715 | |
Jens Axboe | 1faa16d | 2009-04-06 14:48:01 +0200 | [diff] [blame] | 716 | if (unlikely(rl->starved[sync ^ 1])) |
| 717 | __freed_request(q, sync ^ 1); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 718 | } |
| 719 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 720 | /* |
Nick Piggin | d634453 | 2005-06-28 20:45:14 -0700 | [diff] [blame] | 721 | * Get a free request, queue_lock must be held. |
| 722 | * Returns NULL on failure, with queue_lock held. |
| 723 | * Returns !NULL on success, with queue_lock *not held*. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 724 | */ |
Jens Axboe | 165125e | 2007-07-24 09:28:11 +0200 | [diff] [blame] | 725 | static struct request *get_request(struct request_queue *q, int rw_flags, |
Jens Axboe | 7749a8d | 2006-12-13 13:02:26 +0100 | [diff] [blame] | 726 | struct bio *bio, gfp_t gfp_mask) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 727 | { |
| 728 | struct request *rq = NULL; |
| 729 | struct request_list *rl = &q->rq; |
Jens Axboe | 88ee5ef | 2005-11-12 11:09:12 +0100 | [diff] [blame] | 730 | struct io_context *ioc = NULL; |
Jens Axboe | 1faa16d | 2009-04-06 14:48:01 +0200 | [diff] [blame] | 731 | const bool is_sync = rw_is_sync(rw_flags) != 0; |
Jens Axboe | 88ee5ef | 2005-11-12 11:09:12 +0100 | [diff] [blame] | 732 | int may_queue, priv; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 733 | |
Jens Axboe | 7749a8d | 2006-12-13 13:02:26 +0100 | [diff] [blame] | 734 | may_queue = elv_may_queue(q, rw_flags); |
Jens Axboe | 88ee5ef | 2005-11-12 11:09:12 +0100 | [diff] [blame] | 735 | if (may_queue == ELV_MQUEUE_NO) |
| 736 | goto rq_starved; |
| 737 | |
Jens Axboe | 1faa16d | 2009-04-06 14:48:01 +0200 | [diff] [blame] | 738 | if (rl->count[is_sync]+1 >= queue_congestion_on_threshold(q)) { |
| 739 | if (rl->count[is_sync]+1 >= q->nr_requests) { |
Jens Axboe | b5deef9 | 2006-07-19 23:39:40 +0200 | [diff] [blame] | 740 | ioc = current_io_context(GFP_ATOMIC, q->node); |
Jens Axboe | 88ee5ef | 2005-11-12 11:09:12 +0100 | [diff] [blame] | 741 | /* |
| 742 | * The queue will fill after this allocation, so set |
| 743 | * it as full, and mark this process as "batching". |
| 744 | * This process will be allowed to complete a batch of |
| 745 | * requests, others will be blocked. |
| 746 | */ |
Jens Axboe | 1faa16d | 2009-04-06 14:48:01 +0200 | [diff] [blame] | 747 | if (!blk_queue_full(q, is_sync)) { |
Jens Axboe | 88ee5ef | 2005-11-12 11:09:12 +0100 | [diff] [blame] | 748 | ioc_set_batching(q, ioc); |
Jens Axboe | 1faa16d | 2009-04-06 14:48:01 +0200 | [diff] [blame] | 749 | blk_set_queue_full(q, is_sync); |
Jens Axboe | 88ee5ef | 2005-11-12 11:09:12 +0100 | [diff] [blame] | 750 | } else { |
| 751 | if (may_queue != ELV_MQUEUE_MUST |
| 752 | && !ioc_batching(q, ioc)) { |
| 753 | /* |
| 754 | * The queue is full and the allocating |
| 755 | * process is not a "batcher", and not |
| 756 | * exempted by the IO scheduler |
| 757 | */ |
| 758 | goto out; |
| 759 | } |
| 760 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 761 | } |
Jens Axboe | 1faa16d | 2009-04-06 14:48:01 +0200 | [diff] [blame] | 762 | blk_set_queue_congested(q, is_sync); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 763 | } |
| 764 | |
Jens Axboe | 082cf69 | 2005-06-28 16:35:11 +0200 | [diff] [blame] | 765 | /* |
| 766 | * Only allow batching queuers to allocate up to 50% over the defined |
| 767 | * limit of requests, otherwise we could have thousands of requests |
| 768 | * allocated with any setting of ->nr_requests |
| 769 | */ |
Jens Axboe | 1faa16d | 2009-04-06 14:48:01 +0200 | [diff] [blame] | 770 | if (rl->count[is_sync] >= (3 * q->nr_requests / 2)) |
Jens Axboe | 082cf69 | 2005-06-28 16:35:11 +0200 | [diff] [blame] | 771 | goto out; |
Hugh Dickins | fd782a4 | 2005-06-29 15:15:40 +0100 | [diff] [blame] | 772 | |
Jens Axboe | 1faa16d | 2009-04-06 14:48:01 +0200 | [diff] [blame] | 773 | rl->count[is_sync]++; |
| 774 | rl->starved[is_sync] = 0; |
Tejun Heo | cb98fc8 | 2005-10-28 08:29:39 +0200 | [diff] [blame] | 775 | |
Jens Axboe | 64521d1 | 2005-10-28 08:30:39 +0200 | [diff] [blame] | 776 | priv = !test_bit(QUEUE_FLAG_ELVSWITCH, &q->queue_flags); |
Tejun Heo | cb98fc8 | 2005-10-28 08:29:39 +0200 | [diff] [blame] | 777 | if (priv) |
| 778 | rl->elvpriv++; |
| 779 | |
Jerome Marchand | 42dad76 | 2009-04-22 14:01:49 +0200 | [diff] [blame] | 780 | if (blk_queue_io_stat(q)) |
| 781 | rw_flags |= REQ_IO_STAT; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 782 | spin_unlock_irq(q->queue_lock); |
| 783 | |
Jens Axboe | 7749a8d | 2006-12-13 13:02:26 +0100 | [diff] [blame] | 784 | rq = blk_alloc_request(q, rw_flags, priv, gfp_mask); |
Jens Axboe | 88ee5ef | 2005-11-12 11:09:12 +0100 | [diff] [blame] | 785 | if (unlikely(!rq)) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 786 | /* |
| 787 | * Allocation failed presumably due to memory. Undo anything |
| 788 | * we might have messed up. |
| 789 | * |
| 790 | * Allocating task should really be put onto the front of the |
| 791 | * wait queue, but this is pretty rare. |
| 792 | */ |
| 793 | spin_lock_irq(q->queue_lock); |
Jens Axboe | 1faa16d | 2009-04-06 14:48:01 +0200 | [diff] [blame] | 794 | freed_request(q, is_sync, priv); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 795 | |
| 796 | /* |
| 797 | * in the very unlikely event that allocation failed and no |
| 798 | * requests for this direction was pending, mark us starved |
| 799 | * so that freeing of a request in the other direction will |
| 800 | * notice us. another possible fix would be to split the |
| 801 | * rq mempool into READ and WRITE |
| 802 | */ |
| 803 | rq_starved: |
Jens Axboe | 1faa16d | 2009-04-06 14:48:01 +0200 | [diff] [blame] | 804 | if (unlikely(rl->count[is_sync] == 0)) |
| 805 | rl->starved[is_sync] = 1; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 806 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 807 | goto out; |
| 808 | } |
| 809 | |
Jens Axboe | 88ee5ef | 2005-11-12 11:09:12 +0100 | [diff] [blame] | 810 | /* |
| 811 | * ioc may be NULL here, and ioc_batching will be false. That's |
| 812 | * OK, if the queue is under the request limit then requests need |
| 813 | * not count toward the nr_batch_requests limit. There will always |
| 814 | * be some limit enforced by BLK_BATCH_TIME. |
| 815 | */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 816 | if (ioc_batching(q, ioc)) |
| 817 | ioc->nr_batch_requests--; |
Jens Axboe | 6728cb0 | 2008-01-31 13:03:55 +0100 | [diff] [blame] | 818 | |
Jens Axboe | 1faa16d | 2009-04-06 14:48:01 +0200 | [diff] [blame] | 819 | trace_block_getrq(q, bio, rw_flags & 1); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 820 | out: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 821 | return rq; |
| 822 | } |
| 823 | |
| 824 | /* |
| 825 | * No available requests for this queue, unplug the device and wait for some |
| 826 | * requests to become available. |
Nick Piggin | d634453 | 2005-06-28 20:45:14 -0700 | [diff] [blame] | 827 | * |
| 828 | * Called with q->queue_lock held, and returns with it unlocked. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 829 | */ |
Jens Axboe | 165125e | 2007-07-24 09:28:11 +0200 | [diff] [blame] | 830 | static struct request *get_request_wait(struct request_queue *q, int rw_flags, |
Jens Axboe | 22e2c50 | 2005-06-27 10:55:12 +0200 | [diff] [blame] | 831 | struct bio *bio) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 832 | { |
Jens Axboe | 1faa16d | 2009-04-06 14:48:01 +0200 | [diff] [blame] | 833 | const bool is_sync = rw_is_sync(rw_flags) != 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 834 | struct request *rq; |
| 835 | |
Jens Axboe | 7749a8d | 2006-12-13 13:02:26 +0100 | [diff] [blame] | 836 | rq = get_request(q, rw_flags, bio, GFP_NOIO); |
Nick Piggin | 450991b | 2005-06-28 20:45:13 -0700 | [diff] [blame] | 837 | while (!rq) { |
| 838 | DEFINE_WAIT(wait); |
Zhang, Yanmin | 05caf8d | 2008-05-22 15:13:29 +0200 | [diff] [blame] | 839 | struct io_context *ioc; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 840 | struct request_list *rl = &q->rq; |
| 841 | |
Jens Axboe | 1faa16d | 2009-04-06 14:48:01 +0200 | [diff] [blame] | 842 | prepare_to_wait_exclusive(&rl->wait[is_sync], &wait, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 843 | TASK_UNINTERRUPTIBLE); |
| 844 | |
Jens Axboe | 1faa16d | 2009-04-06 14:48:01 +0200 | [diff] [blame] | 845 | trace_block_sleeprq(q, bio, rw_flags & 1); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 846 | |
Zhang, Yanmin | 05caf8d | 2008-05-22 15:13:29 +0200 | [diff] [blame] | 847 | __generic_unplug_device(q); |
| 848 | spin_unlock_irq(q->queue_lock); |
| 849 | io_schedule(); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 850 | |
Zhang, Yanmin | 05caf8d | 2008-05-22 15:13:29 +0200 | [diff] [blame] | 851 | /* |
| 852 | * After sleeping, we become a "batching" process and |
| 853 | * will be able to allocate at least one request, and |
| 854 | * up to a big batch of them for a small period time. |
| 855 | * See ioc_batching, ioc_set_batching |
| 856 | */ |
| 857 | ioc = current_io_context(GFP_NOIO, q->node); |
| 858 | ioc_set_batching(q, ioc); |
Jens Axboe | 2056a78 | 2006-03-23 20:00:26 +0100 | [diff] [blame] | 859 | |
Zhang, Yanmin | 05caf8d | 2008-05-22 15:13:29 +0200 | [diff] [blame] | 860 | spin_lock_irq(q->queue_lock); |
Jens Axboe | 1faa16d | 2009-04-06 14:48:01 +0200 | [diff] [blame] | 861 | finish_wait(&rl->wait[is_sync], &wait); |
Zhang, Yanmin | 05caf8d | 2008-05-22 15:13:29 +0200 | [diff] [blame] | 862 | |
| 863 | rq = get_request(q, rw_flags, bio, GFP_NOIO); |
| 864 | }; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 865 | |
| 866 | return rq; |
| 867 | } |
| 868 | |
Jens Axboe | 165125e | 2007-07-24 09:28:11 +0200 | [diff] [blame] | 869 | struct request *blk_get_request(struct request_queue *q, int rw, gfp_t gfp_mask) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 870 | { |
| 871 | struct request *rq; |
| 872 | |
| 873 | BUG_ON(rw != READ && rw != WRITE); |
| 874 | |
Nick Piggin | d634453 | 2005-06-28 20:45:14 -0700 | [diff] [blame] | 875 | spin_lock_irq(q->queue_lock); |
| 876 | if (gfp_mask & __GFP_WAIT) { |
Jens Axboe | 22e2c50 | 2005-06-27 10:55:12 +0200 | [diff] [blame] | 877 | rq = get_request_wait(q, rw, NULL); |
Nick Piggin | d634453 | 2005-06-28 20:45:14 -0700 | [diff] [blame] | 878 | } else { |
Jens Axboe | 22e2c50 | 2005-06-27 10:55:12 +0200 | [diff] [blame] | 879 | rq = get_request(q, rw, NULL, gfp_mask); |
Nick Piggin | d634453 | 2005-06-28 20:45:14 -0700 | [diff] [blame] | 880 | if (!rq) |
| 881 | spin_unlock_irq(q->queue_lock); |
| 882 | } |
| 883 | /* q->queue_lock is unlocked at this point */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 884 | |
| 885 | return rq; |
| 886 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 887 | EXPORT_SYMBOL(blk_get_request); |
| 888 | |
| 889 | /** |
Boaz Harrosh | 79eb63e | 2009-05-17 18:57:15 +0300 | [diff] [blame] | 890 | * blk_make_request - given a bio, allocate a corresponding struct request. |
Randy Dunlap | 8ebf975 | 2009-06-11 20:00:41 -0700 | [diff] [blame] | 891 | * @q: target request queue |
Boaz Harrosh | 79eb63e | 2009-05-17 18:57:15 +0300 | [diff] [blame] | 892 | * @bio: The bio describing the memory mappings that will be submitted for IO. |
| 893 | * It may be a chained-bio properly constructed by block/bio layer. |
Randy Dunlap | 8ebf975 | 2009-06-11 20:00:41 -0700 | [diff] [blame] | 894 | * @gfp_mask: gfp flags to be used for memory allocation |
Jens Axboe | dc72ef4 | 2006-07-20 14:54:05 +0200 | [diff] [blame] | 895 | * |
Boaz Harrosh | 79eb63e | 2009-05-17 18:57:15 +0300 | [diff] [blame] | 896 | * blk_make_request is the parallel of generic_make_request for BLOCK_PC |
| 897 | * type commands. Where the struct request needs to be farther initialized by |
| 898 | * the caller. It is passed a &struct bio, which describes the memory info of |
| 899 | * the I/O transfer. |
| 900 | * |
| 901 | * The caller of blk_make_request must make sure that bi_io_vec |
| 902 | * are set to describe the memory buffers. That bio_data_dir() will return |
| 903 | * the needed direction of the request. (And all bio's in the passed bio-chain |
| 904 | * are properly set accordingly) |
| 905 | * |
| 906 | * If called under none-sleepable conditions, mapped bio buffers must not |
| 907 | * need bouncing, by calling the appropriate masked or flagged allocator, |
| 908 | * suitable for the target device. Otherwise the call to blk_queue_bounce will |
| 909 | * BUG. |
Jens Axboe | 53674ac | 2009-05-19 19:52:35 +0200 | [diff] [blame] | 910 | * |
| 911 | * WARNING: When allocating/cloning a bio-chain, careful consideration should be |
| 912 | * given to how you allocate bios. In particular, you cannot use __GFP_WAIT for |
| 913 | * anything but the first bio in the chain. Otherwise you risk waiting for IO |
| 914 | * completion of a bio that hasn't been submitted yet, thus resulting in a |
| 915 | * deadlock. Alternatively bios should be allocated using bio_kmalloc() instead |
| 916 | * of bio_alloc(), as that avoids the mempool deadlock. |
| 917 | * If possible a big IO should be split into smaller parts when allocation |
| 918 | * fails. Partial allocation should not be an error, or you risk a live-lock. |
Jens Axboe | dc72ef4 | 2006-07-20 14:54:05 +0200 | [diff] [blame] | 919 | */ |
Boaz Harrosh | 79eb63e | 2009-05-17 18:57:15 +0300 | [diff] [blame] | 920 | struct request *blk_make_request(struct request_queue *q, struct bio *bio, |
| 921 | gfp_t gfp_mask) |
Jens Axboe | dc72ef4 | 2006-07-20 14:54:05 +0200 | [diff] [blame] | 922 | { |
Boaz Harrosh | 79eb63e | 2009-05-17 18:57:15 +0300 | [diff] [blame] | 923 | struct request *rq = blk_get_request(q, bio_data_dir(bio), gfp_mask); |
| 924 | |
| 925 | if (unlikely(!rq)) |
| 926 | return ERR_PTR(-ENOMEM); |
| 927 | |
| 928 | for_each_bio(bio) { |
| 929 | struct bio *bounce_bio = bio; |
| 930 | int ret; |
| 931 | |
| 932 | blk_queue_bounce(q, &bounce_bio); |
| 933 | ret = blk_rq_append_bio(q, rq, bounce_bio); |
| 934 | if (unlikely(ret)) { |
| 935 | blk_put_request(rq); |
| 936 | return ERR_PTR(ret); |
| 937 | } |
| 938 | } |
| 939 | |
| 940 | return rq; |
Jens Axboe | dc72ef4 | 2006-07-20 14:54:05 +0200 | [diff] [blame] | 941 | } |
Boaz Harrosh | 79eb63e | 2009-05-17 18:57:15 +0300 | [diff] [blame] | 942 | EXPORT_SYMBOL(blk_make_request); |
Jens Axboe | dc72ef4 | 2006-07-20 14:54:05 +0200 | [diff] [blame] | 943 | |
| 944 | /** |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 945 | * blk_requeue_request - put a request back on queue |
| 946 | * @q: request queue where request should be inserted |
| 947 | * @rq: request to be inserted |
| 948 | * |
| 949 | * Description: |
| 950 | * Drivers often keep queueing requests until the hardware cannot accept |
| 951 | * more, when that condition happens we need to put the request back |
| 952 | * on the queue. Must be called with queue lock held. |
| 953 | */ |
Jens Axboe | 165125e | 2007-07-24 09:28:11 +0200 | [diff] [blame] | 954 | void blk_requeue_request(struct request_queue *q, struct request *rq) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 955 | { |
Jens Axboe | 242f9dc | 2008-09-14 05:55:09 -0700 | [diff] [blame] | 956 | blk_delete_timer(rq); |
| 957 | blk_clear_rq_complete(rq); |
Arnaldo Carvalho de Melo | 5f3ea37 | 2008-10-30 08:34:33 +0100 | [diff] [blame] | 958 | trace_block_rq_requeue(q, rq); |
Jens Axboe | 2056a78 | 2006-03-23 20:00:26 +0100 | [diff] [blame] | 959 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 960 | if (blk_rq_tagged(rq)) |
| 961 | blk_queue_end_tag(q, rq); |
| 962 | |
James Bottomley | ba396a6 | 2009-05-27 14:17:08 +0200 | [diff] [blame] | 963 | BUG_ON(blk_queued_rq(rq)); |
| 964 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 965 | elv_requeue_request(q, rq); |
| 966 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 967 | EXPORT_SYMBOL(blk_requeue_request); |
| 968 | |
| 969 | /** |
Randy Dunlap | 710027a | 2008-08-19 20:13:11 +0200 | [diff] [blame] | 970 | * blk_insert_request - insert a special request into a request queue |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 971 | * @q: request queue where request should be inserted |
| 972 | * @rq: request to be inserted |
| 973 | * @at_head: insert request at head or tail of queue |
| 974 | * @data: private data |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 975 | * |
| 976 | * Description: |
| 977 | * Many block devices need to execute commands asynchronously, so they don't |
| 978 | * block the whole kernel from preemption during request execution. This is |
| 979 | * accomplished normally by inserting aritficial requests tagged as |
Randy Dunlap | 710027a | 2008-08-19 20:13:11 +0200 | [diff] [blame] | 980 | * REQ_TYPE_SPECIAL in to the corresponding request queue, and letting them |
| 981 | * be scheduled for actual execution by the request queue. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 982 | * |
| 983 | * We have the option of inserting the head or the tail of the queue. |
| 984 | * Typically we use the tail for new ioctls and so forth. We use the head |
| 985 | * of the queue for things like a QUEUE_FULL message from a device, or a |
| 986 | * host that is unable to accept a particular command. |
| 987 | */ |
Jens Axboe | 165125e | 2007-07-24 09:28:11 +0200 | [diff] [blame] | 988 | void blk_insert_request(struct request_queue *q, struct request *rq, |
Tejun Heo | 867d119 | 2005-04-24 02:06:05 -0500 | [diff] [blame] | 989 | int at_head, void *data) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 990 | { |
Tejun Heo | 867d119 | 2005-04-24 02:06:05 -0500 | [diff] [blame] | 991 | int where = at_head ? ELEVATOR_INSERT_FRONT : ELEVATOR_INSERT_BACK; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 992 | unsigned long flags; |
| 993 | |
| 994 | /* |
| 995 | * tell I/O scheduler that this isn't a regular read/write (ie it |
| 996 | * must not attempt merges on this) and that it acts as a soft |
| 997 | * barrier |
| 998 | */ |
Jens Axboe | 4aff5e2 | 2006-08-10 08:44:47 +0200 | [diff] [blame] | 999 | rq->cmd_type = REQ_TYPE_SPECIAL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1000 | |
| 1001 | rq->special = data; |
| 1002 | |
| 1003 | spin_lock_irqsave(q->queue_lock, flags); |
| 1004 | |
| 1005 | /* |
| 1006 | * If command is tagged, release the tag |
| 1007 | */ |
Tejun Heo | 867d119 | 2005-04-24 02:06:05 -0500 | [diff] [blame] | 1008 | if (blk_rq_tagged(rq)) |
| 1009 | blk_queue_end_tag(q, rq); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1010 | |
Jerome Marchand | b238b3d | 2007-10-23 15:05:46 +0200 | [diff] [blame] | 1011 | drive_stat_acct(rq, 1); |
Tejun Heo | 867d119 | 2005-04-24 02:06:05 -0500 | [diff] [blame] | 1012 | __elv_add_request(q, rq, where, 0); |
Tejun Heo | a7f5579 | 2009-04-23 11:05:17 +0900 | [diff] [blame] | 1013 | __blk_run_queue(q); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1014 | spin_unlock_irqrestore(q->queue_lock, flags); |
| 1015 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1016 | EXPORT_SYMBOL(blk_insert_request); |
| 1017 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1018 | /* |
| 1019 | * add-request adds a request to the linked list. |
| 1020 | * queue lock is held and interrupts disabled, as we muck with the |
| 1021 | * request queue list. |
| 1022 | */ |
Jens Axboe | 6728cb0 | 2008-01-31 13:03:55 +0100 | [diff] [blame] | 1023 | static inline void add_request(struct request_queue *q, struct request *req) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1024 | { |
Jerome Marchand | b238b3d | 2007-10-23 15:05:46 +0200 | [diff] [blame] | 1025 | drive_stat_acct(req, 1); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1026 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1027 | /* |
| 1028 | * elevator indicated where it wants this request to be |
| 1029 | * inserted at elevator_merge time |
| 1030 | */ |
| 1031 | __elv_add_request(q, req, ELEVATOR_INSERT_SORT, 0); |
| 1032 | } |
Jens Axboe | 6728cb0 | 2008-01-31 13:03:55 +0100 | [diff] [blame] | 1033 | |
Tejun Heo | 074a7ac | 2008-08-25 19:56:14 +0900 | [diff] [blame] | 1034 | static void part_round_stats_single(int cpu, struct hd_struct *part, |
| 1035 | unsigned long now) |
| 1036 | { |
| 1037 | if (now == part->stamp) |
| 1038 | return; |
| 1039 | |
| 1040 | if (part->in_flight) { |
| 1041 | __part_stat_add(cpu, part, time_in_queue, |
| 1042 | part->in_flight * (now - part->stamp)); |
| 1043 | __part_stat_add(cpu, part, io_ticks, (now - part->stamp)); |
| 1044 | } |
| 1045 | part->stamp = now; |
| 1046 | } |
| 1047 | |
| 1048 | /** |
Randy Dunlap | 496aa8a | 2008-10-16 07:46:23 +0200 | [diff] [blame] | 1049 | * part_round_stats() - Round off the performance stats on a struct disk_stats. |
| 1050 | * @cpu: cpu number for stats access |
| 1051 | * @part: target partition |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1052 | * |
| 1053 | * The average IO queue length and utilisation statistics are maintained |
| 1054 | * by observing the current state of the queue length and the amount of |
| 1055 | * time it has been in this state for. |
| 1056 | * |
| 1057 | * Normally, that accounting is done on IO completion, but that can result |
| 1058 | * in more than a second's worth of IO being accounted for within any one |
| 1059 | * second, leading to >100% utilisation. To deal with that, we call this |
| 1060 | * function to do a round-off before returning the results when reading |
| 1061 | * /proc/diskstats. This accounts immediately for all queue usage up to |
| 1062 | * the current jiffies and restarts the counters again. |
| 1063 | */ |
Tejun Heo | c995905 | 2008-08-25 19:47:21 +0900 | [diff] [blame] | 1064 | void part_round_stats(int cpu, struct hd_struct *part) |
Jerome Marchand | 6f2576af | 2008-02-08 11:04:35 +0100 | [diff] [blame] | 1065 | { |
| 1066 | unsigned long now = jiffies; |
| 1067 | |
Tejun Heo | 074a7ac | 2008-08-25 19:56:14 +0900 | [diff] [blame] | 1068 | if (part->partno) |
| 1069 | part_round_stats_single(cpu, &part_to_disk(part)->part0, now); |
| 1070 | part_round_stats_single(cpu, part, now); |
Jerome Marchand | 6f2576af | 2008-02-08 11:04:35 +0100 | [diff] [blame] | 1071 | } |
Tejun Heo | 074a7ac | 2008-08-25 19:56:14 +0900 | [diff] [blame] | 1072 | EXPORT_SYMBOL_GPL(part_round_stats); |
Jerome Marchand | 6f2576af | 2008-02-08 11:04:35 +0100 | [diff] [blame] | 1073 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1074 | /* |
| 1075 | * queue lock must be held |
| 1076 | */ |
Jens Axboe | 165125e | 2007-07-24 09:28:11 +0200 | [diff] [blame] | 1077 | void __blk_put_request(struct request_queue *q, struct request *req) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1078 | { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1079 | if (unlikely(!q)) |
| 1080 | return; |
| 1081 | if (unlikely(--req->ref_count)) |
| 1082 | return; |
| 1083 | |
Tejun Heo | 8922e16 | 2005-10-20 16:23:44 +0200 | [diff] [blame] | 1084 | elv_completed_request(q, req); |
| 1085 | |
Boaz Harrosh | 1cd96c2 | 2009-03-24 12:35:07 +0100 | [diff] [blame] | 1086 | /* this is a bio leak */ |
| 1087 | WARN_ON(req->bio != NULL); |
| 1088 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1089 | /* |
| 1090 | * Request may not have originated from ll_rw_blk. if not, |
| 1091 | * it didn't come out of our reserved rq pools |
| 1092 | */ |
Jens Axboe | 49171e5 | 2006-08-10 08:59:11 +0200 | [diff] [blame] | 1093 | if (req->cmd_flags & REQ_ALLOCED) { |
Jens Axboe | 1faa16d | 2009-04-06 14:48:01 +0200 | [diff] [blame] | 1094 | int is_sync = rq_is_sync(req) != 0; |
Jens Axboe | 4aff5e2 | 2006-08-10 08:44:47 +0200 | [diff] [blame] | 1095 | int priv = req->cmd_flags & REQ_ELVPRIV; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1096 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1097 | BUG_ON(!list_empty(&req->queuelist)); |
Jens Axboe | 9817064 | 2006-07-28 09:23:08 +0200 | [diff] [blame] | 1098 | BUG_ON(!hlist_unhashed(&req->hash)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1099 | |
| 1100 | blk_free_request(q, req); |
Jens Axboe | 1faa16d | 2009-04-06 14:48:01 +0200 | [diff] [blame] | 1101 | freed_request(q, is_sync, priv); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1102 | } |
| 1103 | } |
Mike Christie | 6e39b69 | 2005-11-11 05:30:24 -0600 | [diff] [blame] | 1104 | EXPORT_SYMBOL_GPL(__blk_put_request); |
| 1105 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1106 | void blk_put_request(struct request *req) |
| 1107 | { |
Tejun Heo | 8922e16 | 2005-10-20 16:23:44 +0200 | [diff] [blame] | 1108 | unsigned long flags; |
Jens Axboe | 165125e | 2007-07-24 09:28:11 +0200 | [diff] [blame] | 1109 | struct request_queue *q = req->q; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1110 | |
FUJITA Tomonori | 52a93ba | 2008-07-15 21:21:45 +0200 | [diff] [blame] | 1111 | spin_lock_irqsave(q->queue_lock, flags); |
| 1112 | __blk_put_request(q, req); |
| 1113 | spin_unlock_irqrestore(q->queue_lock, flags); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1114 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1115 | EXPORT_SYMBOL(blk_put_request); |
| 1116 | |
Jens Axboe | 86db1e2 | 2008-01-29 14:53:40 +0100 | [diff] [blame] | 1117 | void init_request_from_bio(struct request *req, struct bio *bio) |
Tejun Heo | 52d9e67 | 2006-01-06 09:49:58 +0100 | [diff] [blame] | 1118 | { |
Jens Axboe | c7c22e4 | 2008-09-13 20:26:01 +0200 | [diff] [blame] | 1119 | req->cpu = bio->bi_comp_cpu; |
Jens Axboe | 4aff5e2 | 2006-08-10 08:44:47 +0200 | [diff] [blame] | 1120 | req->cmd_type = REQ_TYPE_FS; |
Tejun Heo | 52d9e67 | 2006-01-06 09:49:58 +0100 | [diff] [blame] | 1121 | |
| 1122 | /* |
| 1123 | * inherit FAILFAST from bio (for read-ahead, and explicit FAILFAST) |
| 1124 | */ |
Mike Christie | 6000a36 | 2008-08-19 18:45:30 -0500 | [diff] [blame] | 1125 | if (bio_rw_ahead(bio)) |
| 1126 | req->cmd_flags |= (REQ_FAILFAST_DEV | REQ_FAILFAST_TRANSPORT | |
| 1127 | REQ_FAILFAST_DRIVER); |
| 1128 | if (bio_failfast_dev(bio)) |
| 1129 | req->cmd_flags |= REQ_FAILFAST_DEV; |
| 1130 | if (bio_failfast_transport(bio)) |
| 1131 | req->cmd_flags |= REQ_FAILFAST_TRANSPORT; |
| 1132 | if (bio_failfast_driver(bio)) |
| 1133 | req->cmd_flags |= REQ_FAILFAST_DRIVER; |
Tejun Heo | 52d9e67 | 2006-01-06 09:49:58 +0100 | [diff] [blame] | 1134 | |
David Woodhouse | fb2dce8 | 2008-08-05 18:01:53 +0100 | [diff] [blame] | 1135 | if (unlikely(bio_discard(bio))) { |
David Woodhouse | e17fc0a | 2008-08-09 16:42:20 +0100 | [diff] [blame] | 1136 | req->cmd_flags |= REQ_DISCARD; |
| 1137 | if (bio_barrier(bio)) |
| 1138 | req->cmd_flags |= REQ_SOFTBARRIER; |
David Woodhouse | fb2dce8 | 2008-08-05 18:01:53 +0100 | [diff] [blame] | 1139 | req->q->prepare_discard_fn(req->q, req); |
David Woodhouse | e17fc0a | 2008-08-09 16:42:20 +0100 | [diff] [blame] | 1140 | } else if (unlikely(bio_barrier(bio))) |
Tejun Heo | e4025f6 | 2009-04-23 11:05:17 +0900 | [diff] [blame] | 1141 | req->cmd_flags |= REQ_HARDBARRIER; |
Tejun Heo | 52d9e67 | 2006-01-06 09:49:58 +0100 | [diff] [blame] | 1142 | |
Jens Axboe | b31dc66 | 2006-06-13 08:26:10 +0200 | [diff] [blame] | 1143 | if (bio_sync(bio)) |
Jens Axboe | 4aff5e2 | 2006-08-10 08:44:47 +0200 | [diff] [blame] | 1144 | req->cmd_flags |= REQ_RW_SYNC; |
Jens Axboe | 5404bc7 | 2006-08-10 09:01:02 +0200 | [diff] [blame] | 1145 | if (bio_rw_meta(bio)) |
| 1146 | req->cmd_flags |= REQ_RW_META; |
Jens Axboe | aeb6faf | 2009-04-06 14:48:07 +0200 | [diff] [blame] | 1147 | if (bio_noidle(bio)) |
| 1148 | req->cmd_flags |= REQ_NOIDLE; |
Jens Axboe | b31dc66 | 2006-06-13 08:26:10 +0200 | [diff] [blame] | 1149 | |
Tejun Heo | 52d9e67 | 2006-01-06 09:49:58 +0100 | [diff] [blame] | 1150 | req->errors = 0; |
Tejun Heo | a2dec7b | 2009-05-07 22:24:44 +0900 | [diff] [blame] | 1151 | req->__sector = bio->bi_sector; |
Tejun Heo | 52d9e67 | 2006-01-06 09:49:58 +0100 | [diff] [blame] | 1152 | req->ioprio = bio_prio(bio); |
NeilBrown | bc1c56f | 2007-08-16 13:31:30 +0200 | [diff] [blame] | 1153 | blk_rq_bio_prep(req->q, req, bio); |
Tejun Heo | 52d9e67 | 2006-01-06 09:49:58 +0100 | [diff] [blame] | 1154 | } |
| 1155 | |
Jens Axboe | 644b2d9 | 2009-04-06 14:48:06 +0200 | [diff] [blame] | 1156 | /* |
| 1157 | * Only disabling plugging for non-rotational devices if it does tagging |
| 1158 | * as well, otherwise we do need the proper merging |
| 1159 | */ |
| 1160 | static inline bool queue_should_plug(struct request_queue *q) |
| 1161 | { |
| 1162 | return !(blk_queue_nonrot(q) && blk_queue_tagged(q)); |
| 1163 | } |
| 1164 | |
Jens Axboe | 165125e | 2007-07-24 09:28:11 +0200 | [diff] [blame] | 1165 | static int __make_request(struct request_queue *q, struct bio *bio) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1166 | { |
Nick Piggin | 450991b | 2005-06-28 20:45:13 -0700 | [diff] [blame] | 1167 | struct request *req; |
Tejun Heo | 2e46e8b | 2009-05-07 22:24:41 +0900 | [diff] [blame] | 1168 | int el_ret; |
| 1169 | unsigned int bytes = bio->bi_size; |
Jens Axboe | 51da90f | 2006-07-18 04:14:45 +0200 | [diff] [blame] | 1170 | const unsigned short prio = bio_prio(bio); |
| 1171 | const int sync = bio_sync(bio); |
Jens Axboe | 213d941 | 2009-01-06 09:16:05 +0100 | [diff] [blame] | 1172 | const int unplug = bio_unplug(bio); |
Jens Axboe | 7749a8d | 2006-12-13 13:02:26 +0100 | [diff] [blame] | 1173 | int rw_flags; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1174 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1175 | /* |
| 1176 | * low level driver can indicate that it wants pages above a |
| 1177 | * certain limit bounced to low memory (ie for highmem, or even |
| 1178 | * ISA dma in theory) |
| 1179 | */ |
| 1180 | blk_queue_bounce(q, &bio); |
| 1181 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1182 | spin_lock_irq(q->queue_lock); |
| 1183 | |
Tejun Heo | a738467 | 2008-11-28 13:32:03 +0900 | [diff] [blame] | 1184 | if (unlikely(bio_barrier(bio)) || elv_queue_empty(q)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1185 | goto get_rq; |
| 1186 | |
| 1187 | el_ret = elv_merge(q, &req, bio); |
| 1188 | switch (el_ret) { |
Jens Axboe | 6728cb0 | 2008-01-31 13:03:55 +0100 | [diff] [blame] | 1189 | case ELEVATOR_BACK_MERGE: |
| 1190 | BUG_ON(!rq_mergeable(req)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1191 | |
Jens Axboe | 6728cb0 | 2008-01-31 13:03:55 +0100 | [diff] [blame] | 1192 | if (!ll_back_merge_fn(q, req, bio)) |
| 1193 | break; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1194 | |
Arnaldo Carvalho de Melo | 5f3ea37 | 2008-10-30 08:34:33 +0100 | [diff] [blame] | 1195 | trace_block_bio_backmerge(q, bio); |
Jens Axboe | 2056a78 | 2006-03-23 20:00:26 +0100 | [diff] [blame] | 1196 | |
Jens Axboe | 6728cb0 | 2008-01-31 13:03:55 +0100 | [diff] [blame] | 1197 | req->biotail->bi_next = bio; |
| 1198 | req->biotail = bio; |
Tejun Heo | a2dec7b | 2009-05-07 22:24:44 +0900 | [diff] [blame] | 1199 | req->__data_len += bytes; |
Jens Axboe | 6728cb0 | 2008-01-31 13:03:55 +0100 | [diff] [blame] | 1200 | req->ioprio = ioprio_best(req->ioprio, prio); |
Jens Axboe | ab780f1 | 2008-08-26 10:25:02 +0200 | [diff] [blame] | 1201 | if (!blk_rq_cpu_valid(req)) |
| 1202 | req->cpu = bio->bi_comp_cpu; |
Jens Axboe | 6728cb0 | 2008-01-31 13:03:55 +0100 | [diff] [blame] | 1203 | drive_stat_acct(req, 0); |
| 1204 | if (!attempt_back_merge(q, req)) |
| 1205 | elv_merged_request(q, req, el_ret); |
| 1206 | goto out; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1207 | |
Jens Axboe | 6728cb0 | 2008-01-31 13:03:55 +0100 | [diff] [blame] | 1208 | case ELEVATOR_FRONT_MERGE: |
| 1209 | BUG_ON(!rq_mergeable(req)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1210 | |
Jens Axboe | 6728cb0 | 2008-01-31 13:03:55 +0100 | [diff] [blame] | 1211 | if (!ll_front_merge_fn(q, req, bio)) |
| 1212 | break; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1213 | |
Arnaldo Carvalho de Melo | 5f3ea37 | 2008-10-30 08:34:33 +0100 | [diff] [blame] | 1214 | trace_block_bio_frontmerge(q, bio); |
Jens Axboe | 2056a78 | 2006-03-23 20:00:26 +0100 | [diff] [blame] | 1215 | |
Jens Axboe | 6728cb0 | 2008-01-31 13:03:55 +0100 | [diff] [blame] | 1216 | bio->bi_next = req->bio; |
| 1217 | req->bio = bio; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1218 | |
Jens Axboe | 6728cb0 | 2008-01-31 13:03:55 +0100 | [diff] [blame] | 1219 | /* |
| 1220 | * may not be valid. if the low level driver said |
| 1221 | * it didn't need a bounce buffer then it better |
| 1222 | * not touch req->buffer either... |
| 1223 | */ |
| 1224 | req->buffer = bio_data(bio); |
Tejun Heo | a2dec7b | 2009-05-07 22:24:44 +0900 | [diff] [blame] | 1225 | req->__sector = bio->bi_sector; |
| 1226 | req->__data_len += bytes; |
Jens Axboe | 6728cb0 | 2008-01-31 13:03:55 +0100 | [diff] [blame] | 1227 | req->ioprio = ioprio_best(req->ioprio, prio); |
Jens Axboe | ab780f1 | 2008-08-26 10:25:02 +0200 | [diff] [blame] | 1228 | if (!blk_rq_cpu_valid(req)) |
| 1229 | req->cpu = bio->bi_comp_cpu; |
Jens Axboe | 6728cb0 | 2008-01-31 13:03:55 +0100 | [diff] [blame] | 1230 | drive_stat_acct(req, 0); |
| 1231 | if (!attempt_front_merge(q, req)) |
| 1232 | elv_merged_request(q, req, el_ret); |
| 1233 | goto out; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1234 | |
Jens Axboe | 6728cb0 | 2008-01-31 13:03:55 +0100 | [diff] [blame] | 1235 | /* ELV_NO_MERGE: elevator says don't/can't merge. */ |
| 1236 | default: |
| 1237 | ; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1238 | } |
| 1239 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1240 | get_rq: |
Nick Piggin | 450991b | 2005-06-28 20:45:13 -0700 | [diff] [blame] | 1241 | /* |
Jens Axboe | 7749a8d | 2006-12-13 13:02:26 +0100 | [diff] [blame] | 1242 | * This sync check and mask will be re-done in init_request_from_bio(), |
| 1243 | * but we need to set it earlier to expose the sync flag to the |
| 1244 | * rq allocator and io schedulers. |
| 1245 | */ |
| 1246 | rw_flags = bio_data_dir(bio); |
| 1247 | if (sync) |
| 1248 | rw_flags |= REQ_RW_SYNC; |
| 1249 | |
| 1250 | /* |
Nick Piggin | 450991b | 2005-06-28 20:45:13 -0700 | [diff] [blame] | 1251 | * Grab a free request. This is might sleep but can not fail. |
Nick Piggin | d634453 | 2005-06-28 20:45:14 -0700 | [diff] [blame] | 1252 | * Returns with the queue unlocked. |
Nick Piggin | 450991b | 2005-06-28 20:45:13 -0700 | [diff] [blame] | 1253 | */ |
Jens Axboe | 7749a8d | 2006-12-13 13:02:26 +0100 | [diff] [blame] | 1254 | req = get_request_wait(q, rw_flags, bio); |
Nick Piggin | d634453 | 2005-06-28 20:45:14 -0700 | [diff] [blame] | 1255 | |
Nick Piggin | 450991b | 2005-06-28 20:45:13 -0700 | [diff] [blame] | 1256 | /* |
| 1257 | * After dropping the lock and possibly sleeping here, our request |
| 1258 | * may now be mergeable after it had proven unmergeable (above). |
| 1259 | * We don't worry about that case for efficiency. It won't happen |
| 1260 | * often, and the elevators are able to handle it. |
| 1261 | */ |
Tejun Heo | 52d9e67 | 2006-01-06 09:49:58 +0100 | [diff] [blame] | 1262 | init_request_from_bio(req, bio); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1263 | |
Nick Piggin | 450991b | 2005-06-28 20:45:13 -0700 | [diff] [blame] | 1264 | spin_lock_irq(q->queue_lock); |
Jens Axboe | c7c22e4 | 2008-09-13 20:26:01 +0200 | [diff] [blame] | 1265 | if (test_bit(QUEUE_FLAG_SAME_COMP, &q->queue_flags) || |
| 1266 | bio_flagged(bio, BIO_CPU_AFFINE)) |
| 1267 | req->cpu = blk_cpu_to_group(smp_processor_id()); |
Jens Axboe | 644b2d9 | 2009-04-06 14:48:06 +0200 | [diff] [blame] | 1268 | if (queue_should_plug(q) && elv_queue_empty(q)) |
Nick Piggin | 450991b | 2005-06-28 20:45:13 -0700 | [diff] [blame] | 1269 | blk_plug_device(q); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1270 | add_request(q, req); |
| 1271 | out: |
Jens Axboe | 644b2d9 | 2009-04-06 14:48:06 +0200 | [diff] [blame] | 1272 | if (unplug || !queue_should_plug(q)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1273 | __generic_unplug_device(q); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1274 | spin_unlock_irq(q->queue_lock); |
| 1275 | return 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1276 | } |
| 1277 | |
| 1278 | /* |
| 1279 | * If bio->bi_dev is a partition, remap the location |
| 1280 | */ |
| 1281 | static inline void blk_partition_remap(struct bio *bio) |
| 1282 | { |
| 1283 | struct block_device *bdev = bio->bi_bdev; |
| 1284 | |
Jens Axboe | bf2de6f | 2007-09-27 13:01:25 +0200 | [diff] [blame] | 1285 | if (bio_sectors(bio) && bdev != bdev->bd_contains) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1286 | struct hd_struct *p = bdev->bd_part; |
Jens Axboe | a362357 | 2005-11-01 09:26:16 +0100 | [diff] [blame] | 1287 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1288 | bio->bi_sector += p->start_sect; |
| 1289 | bio->bi_bdev = bdev->bd_contains; |
Alan D. Brunelle | c7149d6 | 2007-08-07 15:30:23 +0200 | [diff] [blame] | 1290 | |
Arnaldo Carvalho de Melo | 5f3ea37 | 2008-10-30 08:34:33 +0100 | [diff] [blame] | 1291 | trace_block_remap(bdev_get_queue(bio->bi_bdev), bio, |
Alan D. Brunelle | 22a7c31 | 2009-05-04 16:35:08 -0400 | [diff] [blame] | 1292 | bdev->bd_dev, |
Alan D. Brunelle | c7149d6 | 2007-08-07 15:30:23 +0200 | [diff] [blame] | 1293 | bio->bi_sector - p->start_sect); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1294 | } |
| 1295 | } |
| 1296 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1297 | static void handle_bad_sector(struct bio *bio) |
| 1298 | { |
| 1299 | char b[BDEVNAME_SIZE]; |
| 1300 | |
| 1301 | printk(KERN_INFO "attempt to access beyond end of device\n"); |
| 1302 | printk(KERN_INFO "%s: rw=%ld, want=%Lu, limit=%Lu\n", |
| 1303 | bdevname(bio->bi_bdev, b), |
| 1304 | bio->bi_rw, |
| 1305 | (unsigned long long)bio->bi_sector + bio_sectors(bio), |
| 1306 | (long long)(bio->bi_bdev->bd_inode->i_size >> 9)); |
| 1307 | |
| 1308 | set_bit(BIO_EOF, &bio->bi_flags); |
| 1309 | } |
| 1310 | |
Akinobu Mita | c17bb49 | 2006-12-08 02:39:46 -0800 | [diff] [blame] | 1311 | #ifdef CONFIG_FAIL_MAKE_REQUEST |
| 1312 | |
| 1313 | static DECLARE_FAULT_ATTR(fail_make_request); |
| 1314 | |
| 1315 | static int __init setup_fail_make_request(char *str) |
| 1316 | { |
| 1317 | return setup_fault_attr(&fail_make_request, str); |
| 1318 | } |
| 1319 | __setup("fail_make_request=", setup_fail_make_request); |
| 1320 | |
| 1321 | static int should_fail_request(struct bio *bio) |
| 1322 | { |
Tejun Heo | eddb2e2 | 2008-08-25 19:56:13 +0900 | [diff] [blame] | 1323 | struct hd_struct *part = bio->bi_bdev->bd_part; |
| 1324 | |
| 1325 | if (part_to_disk(part)->part0.make_it_fail || part->make_it_fail) |
Akinobu Mita | c17bb49 | 2006-12-08 02:39:46 -0800 | [diff] [blame] | 1326 | return should_fail(&fail_make_request, bio->bi_size); |
| 1327 | |
| 1328 | return 0; |
| 1329 | } |
| 1330 | |
| 1331 | static int __init fail_make_request_debugfs(void) |
| 1332 | { |
| 1333 | return init_fault_attr_dentries(&fail_make_request, |
| 1334 | "fail_make_request"); |
| 1335 | } |
| 1336 | |
| 1337 | late_initcall(fail_make_request_debugfs); |
| 1338 | |
| 1339 | #else /* CONFIG_FAIL_MAKE_REQUEST */ |
| 1340 | |
| 1341 | static inline int should_fail_request(struct bio *bio) |
| 1342 | { |
| 1343 | return 0; |
| 1344 | } |
| 1345 | |
| 1346 | #endif /* CONFIG_FAIL_MAKE_REQUEST */ |
| 1347 | |
Jens Axboe | c07e2b4 | 2007-07-18 13:27:58 +0200 | [diff] [blame] | 1348 | /* |
| 1349 | * Check whether this bio extends beyond the end of the device. |
| 1350 | */ |
| 1351 | static inline int bio_check_eod(struct bio *bio, unsigned int nr_sectors) |
| 1352 | { |
| 1353 | sector_t maxsector; |
| 1354 | |
| 1355 | if (!nr_sectors) |
| 1356 | return 0; |
| 1357 | |
| 1358 | /* Test device or partition size, when known. */ |
| 1359 | maxsector = bio->bi_bdev->bd_inode->i_size >> 9; |
| 1360 | if (maxsector) { |
| 1361 | sector_t sector = bio->bi_sector; |
| 1362 | |
| 1363 | if (maxsector < nr_sectors || maxsector - nr_sectors < sector) { |
| 1364 | /* |
| 1365 | * This may well happen - the kernel calls bread() |
| 1366 | * without checking the size of the device, e.g., when |
| 1367 | * mounting a device. |
| 1368 | */ |
| 1369 | handle_bad_sector(bio); |
| 1370 | return 1; |
| 1371 | } |
| 1372 | } |
| 1373 | |
| 1374 | return 0; |
| 1375 | } |
| 1376 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1377 | /** |
Randy Dunlap | 710027a | 2008-08-19 20:13:11 +0200 | [diff] [blame] | 1378 | * generic_make_request - hand a buffer to its device driver for I/O |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1379 | * @bio: The bio describing the location in memory and on the device. |
| 1380 | * |
| 1381 | * generic_make_request() is used to make I/O requests of block |
| 1382 | * devices. It is passed a &struct bio, which describes the I/O that needs |
| 1383 | * to be done. |
| 1384 | * |
| 1385 | * generic_make_request() does not return any status. The |
| 1386 | * success/failure status of the request, along with notification of |
| 1387 | * completion, is delivered asynchronously through the bio->bi_end_io |
| 1388 | * function described (one day) else where. |
| 1389 | * |
| 1390 | * The caller of generic_make_request must make sure that bi_io_vec |
| 1391 | * are set to describe the memory buffer, and that bi_dev and bi_sector are |
| 1392 | * set to describe the device address, and the |
| 1393 | * bi_end_io and optionally bi_private are set to describe how |
| 1394 | * completion notification should be signaled. |
| 1395 | * |
| 1396 | * generic_make_request and the drivers it calls may use bi_next if this |
| 1397 | * bio happens to be merged with someone else, and may change bi_dev and |
| 1398 | * bi_sector for remaps as it sees fit. So the values of these fields |
| 1399 | * should NOT be depended on after the call to generic_make_request. |
| 1400 | */ |
Neil Brown | d89d879 | 2007-05-01 09:53:42 +0200 | [diff] [blame] | 1401 | static inline void __generic_make_request(struct bio *bio) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1402 | { |
Jens Axboe | 165125e | 2007-07-24 09:28:11 +0200 | [diff] [blame] | 1403 | struct request_queue *q; |
NeilBrown | 5ddfe96 | 2006-10-30 22:07:21 -0800 | [diff] [blame] | 1404 | sector_t old_sector; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1405 | int ret, nr_sectors = bio_sectors(bio); |
Jens Axboe | 2056a78 | 2006-03-23 20:00:26 +0100 | [diff] [blame] | 1406 | dev_t old_dev; |
Jens Axboe | 51fd77b | 2007-11-02 08:49:08 +0100 | [diff] [blame] | 1407 | int err = -EIO; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1408 | |
| 1409 | might_sleep(); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1410 | |
Jens Axboe | c07e2b4 | 2007-07-18 13:27:58 +0200 | [diff] [blame] | 1411 | if (bio_check_eod(bio, nr_sectors)) |
| 1412 | goto end_io; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1413 | |
| 1414 | /* |
| 1415 | * Resolve the mapping until finished. (drivers are |
| 1416 | * still free to implement/resolve their own stacking |
| 1417 | * by explicitly returning 0) |
| 1418 | * |
| 1419 | * NOTE: we don't repeat the blk_size check for each new device. |
| 1420 | * Stacking drivers are expected to know what they are doing. |
| 1421 | */ |
NeilBrown | 5ddfe96 | 2006-10-30 22:07:21 -0800 | [diff] [blame] | 1422 | old_sector = -1; |
Jens Axboe | 2056a78 | 2006-03-23 20:00:26 +0100 | [diff] [blame] | 1423 | old_dev = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1424 | do { |
| 1425 | char b[BDEVNAME_SIZE]; |
| 1426 | |
| 1427 | q = bdev_get_queue(bio->bi_bdev); |
Tejun Heo | a738467 | 2008-11-28 13:32:03 +0900 | [diff] [blame] | 1428 | if (unlikely(!q)) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1429 | printk(KERN_ERR |
| 1430 | "generic_make_request: Trying to access " |
| 1431 | "nonexistent block-device %s (%Lu)\n", |
| 1432 | bdevname(bio->bi_bdev, b), |
| 1433 | (long long) bio->bi_sector); |
Tejun Heo | a738467 | 2008-11-28 13:32:03 +0900 | [diff] [blame] | 1434 | goto end_io; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1435 | } |
| 1436 | |
Martin K. Petersen | ae03bf6 | 2009-05-22 17:17:50 -0400 | [diff] [blame] | 1437 | if (unlikely(nr_sectors > queue_max_hw_sectors(q))) { |
Jens Axboe | 6728cb0 | 2008-01-31 13:03:55 +0100 | [diff] [blame] | 1438 | printk(KERN_ERR "bio too big device %s (%u > %u)\n", |
Martin K. Petersen | ae03bf6 | 2009-05-22 17:17:50 -0400 | [diff] [blame] | 1439 | bdevname(bio->bi_bdev, b), |
| 1440 | bio_sectors(bio), |
| 1441 | queue_max_hw_sectors(q)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1442 | goto end_io; |
| 1443 | } |
| 1444 | |
Nick Piggin | fde6ad2 | 2005-06-23 00:08:53 -0700 | [diff] [blame] | 1445 | if (unlikely(test_bit(QUEUE_FLAG_DEAD, &q->queue_flags))) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1446 | goto end_io; |
| 1447 | |
Akinobu Mita | c17bb49 | 2006-12-08 02:39:46 -0800 | [diff] [blame] | 1448 | if (should_fail_request(bio)) |
| 1449 | goto end_io; |
| 1450 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1451 | /* |
| 1452 | * If this device has partitions, remap block n |
| 1453 | * of partition p to block n+start(p) of the disk. |
| 1454 | */ |
| 1455 | blk_partition_remap(bio); |
| 1456 | |
Martin K. Petersen | 7ba1ba1 | 2008-06-30 20:04:41 +0200 | [diff] [blame] | 1457 | if (bio_integrity_enabled(bio) && bio_integrity_prep(bio)) |
| 1458 | goto end_io; |
| 1459 | |
NeilBrown | 5ddfe96 | 2006-10-30 22:07:21 -0800 | [diff] [blame] | 1460 | if (old_sector != -1) |
Alan D. Brunelle | 22a7c31 | 2009-05-04 16:35:08 -0400 | [diff] [blame] | 1461 | trace_block_remap(q, bio, old_dev, old_sector); |
Jens Axboe | 2056a78 | 2006-03-23 20:00:26 +0100 | [diff] [blame] | 1462 | |
Arnaldo Carvalho de Melo | 5f3ea37 | 2008-10-30 08:34:33 +0100 | [diff] [blame] | 1463 | trace_block_bio_queue(q, bio); |
Jens Axboe | 2056a78 | 2006-03-23 20:00:26 +0100 | [diff] [blame] | 1464 | |
NeilBrown | 5ddfe96 | 2006-10-30 22:07:21 -0800 | [diff] [blame] | 1465 | old_sector = bio->bi_sector; |
Jens Axboe | 2056a78 | 2006-03-23 20:00:26 +0100 | [diff] [blame] | 1466 | old_dev = bio->bi_bdev->bd_dev; |
| 1467 | |
Jens Axboe | c07e2b4 | 2007-07-18 13:27:58 +0200 | [diff] [blame] | 1468 | if (bio_check_eod(bio, nr_sectors)) |
| 1469 | goto end_io; |
Tejun Heo | a738467 | 2008-11-28 13:32:03 +0900 | [diff] [blame] | 1470 | |
| 1471 | if (bio_discard(bio) && !q->prepare_discard_fn) { |
Jens Axboe | 51fd77b | 2007-11-02 08:49:08 +0100 | [diff] [blame] | 1472 | err = -EOPNOTSUPP; |
| 1473 | goto end_io; |
| 1474 | } |
Jens Axboe | cec0707 | 2009-01-13 15:28:32 +0100 | [diff] [blame] | 1475 | if (bio_barrier(bio) && bio_has_data(bio) && |
| 1476 | (q->next_ordered == QUEUE_ORDERED_NONE)) { |
| 1477 | err = -EOPNOTSUPP; |
| 1478 | goto end_io; |
| 1479 | } |
NeilBrown | 5ddfe96 | 2006-10-30 22:07:21 -0800 | [diff] [blame] | 1480 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1481 | ret = q->make_request_fn(q, bio); |
| 1482 | } while (ret); |
Tejun Heo | a738467 | 2008-11-28 13:32:03 +0900 | [diff] [blame] | 1483 | |
| 1484 | return; |
| 1485 | |
| 1486 | end_io: |
| 1487 | bio_endio(bio, err); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1488 | } |
| 1489 | |
Neil Brown | d89d879 | 2007-05-01 09:53:42 +0200 | [diff] [blame] | 1490 | /* |
| 1491 | * We only want one ->make_request_fn to be active at a time, |
| 1492 | * else stack usage with stacked devices could be a problem. |
| 1493 | * So use current->bio_{list,tail} to keep a list of requests |
| 1494 | * submited by a make_request_fn function. |
| 1495 | * current->bio_tail is also used as a flag to say if |
| 1496 | * generic_make_request is currently active in this task or not. |
| 1497 | * If it is NULL, then no make_request is active. If it is non-NULL, |
| 1498 | * then a make_request is active, and new requests should be added |
| 1499 | * at the tail |
| 1500 | */ |
| 1501 | void generic_make_request(struct bio *bio) |
| 1502 | { |
| 1503 | if (current->bio_tail) { |
| 1504 | /* make_request is active */ |
| 1505 | *(current->bio_tail) = bio; |
| 1506 | bio->bi_next = NULL; |
| 1507 | current->bio_tail = &bio->bi_next; |
| 1508 | return; |
| 1509 | } |
| 1510 | /* following loop may be a bit non-obvious, and so deserves some |
| 1511 | * explanation. |
| 1512 | * Before entering the loop, bio->bi_next is NULL (as all callers |
| 1513 | * ensure that) so we have a list with a single bio. |
| 1514 | * We pretend that we have just taken it off a longer list, so |
| 1515 | * we assign bio_list to the next (which is NULL) and bio_tail |
| 1516 | * to &bio_list, thus initialising the bio_list of new bios to be |
| 1517 | * added. __generic_make_request may indeed add some more bios |
| 1518 | * through a recursive call to generic_make_request. If it |
| 1519 | * did, we find a non-NULL value in bio_list and re-enter the loop |
| 1520 | * from the top. In this case we really did just take the bio |
| 1521 | * of the top of the list (no pretending) and so fixup bio_list and |
| 1522 | * bio_tail or bi_next, and call into __generic_make_request again. |
| 1523 | * |
| 1524 | * The loop was structured like this to make only one call to |
| 1525 | * __generic_make_request (which is important as it is large and |
| 1526 | * inlined) and to keep the structure simple. |
| 1527 | */ |
| 1528 | BUG_ON(bio->bi_next); |
| 1529 | do { |
| 1530 | current->bio_list = bio->bi_next; |
| 1531 | if (bio->bi_next == NULL) |
| 1532 | current->bio_tail = ¤t->bio_list; |
| 1533 | else |
| 1534 | bio->bi_next = NULL; |
| 1535 | __generic_make_request(bio); |
| 1536 | bio = current->bio_list; |
| 1537 | } while (bio); |
| 1538 | current->bio_tail = NULL; /* deactivate */ |
| 1539 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1540 | EXPORT_SYMBOL(generic_make_request); |
| 1541 | |
| 1542 | /** |
Randy Dunlap | 710027a | 2008-08-19 20:13:11 +0200 | [diff] [blame] | 1543 | * submit_bio - submit a bio to the block device layer for I/O |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1544 | * @rw: whether to %READ or %WRITE, or maybe to %READA (read ahead) |
| 1545 | * @bio: The &struct bio which describes the I/O |
| 1546 | * |
| 1547 | * submit_bio() is very similar in purpose to generic_make_request(), and |
| 1548 | * uses that function to do most of the work. Both are fairly rough |
Randy Dunlap | 710027a | 2008-08-19 20:13:11 +0200 | [diff] [blame] | 1549 | * interfaces; @bio must be presetup and ready for I/O. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1550 | * |
| 1551 | */ |
| 1552 | void submit_bio(int rw, struct bio *bio) |
| 1553 | { |
| 1554 | int count = bio_sectors(bio); |
| 1555 | |
Jens Axboe | 22e2c50 | 2005-06-27 10:55:12 +0200 | [diff] [blame] | 1556 | bio->bi_rw |= rw; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1557 | |
Jens Axboe | bf2de6f | 2007-09-27 13:01:25 +0200 | [diff] [blame] | 1558 | /* |
| 1559 | * If it's a regular read/write or a barrier with data attached, |
| 1560 | * go through the normal accounting stuff before submission. |
| 1561 | */ |
Jens Axboe | a9c701e | 2008-08-08 11:04:44 +0200 | [diff] [blame] | 1562 | if (bio_has_data(bio)) { |
Jens Axboe | bf2de6f | 2007-09-27 13:01:25 +0200 | [diff] [blame] | 1563 | if (rw & WRITE) { |
| 1564 | count_vm_events(PGPGOUT, count); |
| 1565 | } else { |
| 1566 | task_io_account_read(bio->bi_size); |
| 1567 | count_vm_events(PGPGIN, count); |
| 1568 | } |
| 1569 | |
| 1570 | if (unlikely(block_dump)) { |
| 1571 | char b[BDEVNAME_SIZE]; |
| 1572 | printk(KERN_DEBUG "%s(%d): %s block %Lu on %s\n", |
Pavel Emelyanov | ba25f9d | 2007-10-18 23:40:40 -0700 | [diff] [blame] | 1573 | current->comm, task_pid_nr(current), |
Jens Axboe | bf2de6f | 2007-09-27 13:01:25 +0200 | [diff] [blame] | 1574 | (rw & WRITE) ? "WRITE" : "READ", |
| 1575 | (unsigned long long)bio->bi_sector, |
Jens Axboe | 6728cb0 | 2008-01-31 13:03:55 +0100 | [diff] [blame] | 1576 | bdevname(bio->bi_bdev, b)); |
Jens Axboe | bf2de6f | 2007-09-27 13:01:25 +0200 | [diff] [blame] | 1577 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1578 | } |
| 1579 | |
| 1580 | generic_make_request(bio); |
| 1581 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1582 | EXPORT_SYMBOL(submit_bio); |
| 1583 | |
Kiyoshi Ueda | 3bcddea | 2007-12-11 17:52:28 -0500 | [diff] [blame] | 1584 | /** |
Kiyoshi Ueda | 82124d6 | 2008-09-18 10:45:38 -0400 | [diff] [blame] | 1585 | * blk_rq_check_limits - Helper function to check a request for the queue limit |
| 1586 | * @q: the queue |
| 1587 | * @rq: the request being checked |
| 1588 | * |
| 1589 | * Description: |
| 1590 | * @rq may have been made based on weaker limitations of upper-level queues |
| 1591 | * in request stacking drivers, and it may violate the limitation of @q. |
| 1592 | * Since the block layer and the underlying device driver trust @rq |
| 1593 | * after it is inserted to @q, it should be checked against @q before |
| 1594 | * the insertion using this generic function. |
| 1595 | * |
| 1596 | * This function should also be useful for request stacking drivers |
| 1597 | * in some cases below, so export this fuction. |
| 1598 | * Request stacking drivers like request-based dm may change the queue |
| 1599 | * limits while requests are in the queue (e.g. dm's table swapping). |
| 1600 | * Such request stacking drivers should check those requests agaist |
| 1601 | * the new queue limits again when they dispatch those requests, |
| 1602 | * although such checkings are also done against the old queue limits |
| 1603 | * when submitting requests. |
| 1604 | */ |
| 1605 | int blk_rq_check_limits(struct request_queue *q, struct request *rq) |
| 1606 | { |
Martin K. Petersen | ae03bf6 | 2009-05-22 17:17:50 -0400 | [diff] [blame] | 1607 | if (blk_rq_sectors(rq) > queue_max_sectors(q) || |
| 1608 | blk_rq_bytes(rq) > queue_max_hw_sectors(q) << 9) { |
Kiyoshi Ueda | 82124d6 | 2008-09-18 10:45:38 -0400 | [diff] [blame] | 1609 | printk(KERN_ERR "%s: over max size limit.\n", __func__); |
| 1610 | return -EIO; |
| 1611 | } |
| 1612 | |
| 1613 | /* |
| 1614 | * queue's settings related to segment counting like q->bounce_pfn |
| 1615 | * may differ from that of other stacking queues. |
| 1616 | * Recalculate it to check the request correctly on this queue's |
| 1617 | * limitation. |
| 1618 | */ |
| 1619 | blk_recalc_rq_segments(rq); |
Martin K. Petersen | ae03bf6 | 2009-05-22 17:17:50 -0400 | [diff] [blame] | 1620 | if (rq->nr_phys_segments > queue_max_phys_segments(q) || |
| 1621 | rq->nr_phys_segments > queue_max_hw_segments(q)) { |
Kiyoshi Ueda | 82124d6 | 2008-09-18 10:45:38 -0400 | [diff] [blame] | 1622 | printk(KERN_ERR "%s: over max segments limit.\n", __func__); |
| 1623 | return -EIO; |
| 1624 | } |
| 1625 | |
| 1626 | return 0; |
| 1627 | } |
| 1628 | EXPORT_SYMBOL_GPL(blk_rq_check_limits); |
| 1629 | |
| 1630 | /** |
| 1631 | * blk_insert_cloned_request - Helper for stacking drivers to submit a request |
| 1632 | * @q: the queue to submit the request |
| 1633 | * @rq: the request being queued |
| 1634 | */ |
| 1635 | int blk_insert_cloned_request(struct request_queue *q, struct request *rq) |
| 1636 | { |
| 1637 | unsigned long flags; |
| 1638 | |
| 1639 | if (blk_rq_check_limits(q, rq)) |
| 1640 | return -EIO; |
| 1641 | |
| 1642 | #ifdef CONFIG_FAIL_MAKE_REQUEST |
| 1643 | if (rq->rq_disk && rq->rq_disk->part0.make_it_fail && |
| 1644 | should_fail(&fail_make_request, blk_rq_bytes(rq))) |
| 1645 | return -EIO; |
| 1646 | #endif |
| 1647 | |
| 1648 | spin_lock_irqsave(q->queue_lock, flags); |
| 1649 | |
| 1650 | /* |
| 1651 | * Submitting request must be dequeued before calling this function |
| 1652 | * because it will be linked to another request_queue |
| 1653 | */ |
| 1654 | BUG_ON(blk_queued_rq(rq)); |
| 1655 | |
| 1656 | drive_stat_acct(rq, 1); |
| 1657 | __elv_add_request(q, rq, ELEVATOR_INSERT_BACK, 0); |
| 1658 | |
| 1659 | spin_unlock_irqrestore(q->queue_lock, flags); |
| 1660 | |
| 1661 | return 0; |
| 1662 | } |
| 1663 | EXPORT_SYMBOL_GPL(blk_insert_cloned_request); |
| 1664 | |
Jens Axboe | bc58ba9 | 2009-01-23 10:54:44 +0100 | [diff] [blame] | 1665 | static void blk_account_io_completion(struct request *req, unsigned int bytes) |
| 1666 | { |
Jens Axboe | c2553b5 | 2009-04-24 08:10:11 +0200 | [diff] [blame] | 1667 | if (blk_do_io_stat(req)) { |
Jens Axboe | bc58ba9 | 2009-01-23 10:54:44 +0100 | [diff] [blame] | 1668 | const int rw = rq_data_dir(req); |
| 1669 | struct hd_struct *part; |
| 1670 | int cpu; |
| 1671 | |
| 1672 | cpu = part_stat_lock(); |
Tejun Heo | 83096eb | 2009-05-07 22:24:39 +0900 | [diff] [blame] | 1673 | part = disk_map_sector_rcu(req->rq_disk, blk_rq_pos(req)); |
Jens Axboe | bc58ba9 | 2009-01-23 10:54:44 +0100 | [diff] [blame] | 1674 | part_stat_add(cpu, part, sectors[rw], bytes >> 9); |
| 1675 | part_stat_unlock(); |
| 1676 | } |
| 1677 | } |
| 1678 | |
| 1679 | static void blk_account_io_done(struct request *req) |
| 1680 | { |
Jens Axboe | bc58ba9 | 2009-01-23 10:54:44 +0100 | [diff] [blame] | 1681 | /* |
| 1682 | * Account IO completion. bar_rq isn't accounted as a normal |
| 1683 | * IO on queueing nor completion. Accounting the containing |
| 1684 | * request is enough. |
| 1685 | */ |
Jens Axboe | c2553b5 | 2009-04-24 08:10:11 +0200 | [diff] [blame] | 1686 | if (blk_do_io_stat(req) && req != &req->q->bar_rq) { |
Jens Axboe | bc58ba9 | 2009-01-23 10:54:44 +0100 | [diff] [blame] | 1687 | unsigned long duration = jiffies - req->start_time; |
| 1688 | const int rw = rq_data_dir(req); |
| 1689 | struct hd_struct *part; |
| 1690 | int cpu; |
| 1691 | |
| 1692 | cpu = part_stat_lock(); |
Tejun Heo | 83096eb | 2009-05-07 22:24:39 +0900 | [diff] [blame] | 1693 | part = disk_map_sector_rcu(req->rq_disk, blk_rq_pos(req)); |
Jens Axboe | bc58ba9 | 2009-01-23 10:54:44 +0100 | [diff] [blame] | 1694 | |
| 1695 | part_stat_inc(cpu, part, ios[rw]); |
| 1696 | part_stat_add(cpu, part, ticks[rw], duration); |
| 1697 | part_round_stats(cpu, part); |
| 1698 | part_dec_in_flight(part); |
| 1699 | |
| 1700 | part_stat_unlock(); |
| 1701 | } |
| 1702 | } |
| 1703 | |
Tejun Heo | 53a0880 | 2008-12-03 12:41:26 +0100 | [diff] [blame] | 1704 | /** |
Tejun Heo | 9934c8c | 2009-05-08 11:54:16 +0900 | [diff] [blame] | 1705 | * blk_peek_request - peek at the top of a request queue |
| 1706 | * @q: request queue to peek at |
Kiyoshi Ueda | 3bcddea | 2007-12-11 17:52:28 -0500 | [diff] [blame] | 1707 | * |
| 1708 | * Description: |
Tejun Heo | 9934c8c | 2009-05-08 11:54:16 +0900 | [diff] [blame] | 1709 | * Return the request at the top of @q. The returned request |
| 1710 | * should be started using blk_start_request() before LLD starts |
| 1711 | * processing it. |
Kiyoshi Ueda | 3bcddea | 2007-12-11 17:52:28 -0500 | [diff] [blame] | 1712 | * |
| 1713 | * Return: |
Tejun Heo | 9934c8c | 2009-05-08 11:54:16 +0900 | [diff] [blame] | 1714 | * Pointer to the request at the top of @q if available. Null |
| 1715 | * otherwise. |
| 1716 | * |
| 1717 | * Context: |
| 1718 | * queue_lock must be held. |
| 1719 | */ |
| 1720 | struct request *blk_peek_request(struct request_queue *q) |
Tejun Heo | 158dbda | 2009-04-23 11:05:18 +0900 | [diff] [blame] | 1721 | { |
| 1722 | struct request *rq; |
| 1723 | int ret; |
| 1724 | |
| 1725 | while ((rq = __elv_next_request(q)) != NULL) { |
| 1726 | if (!(rq->cmd_flags & REQ_STARTED)) { |
| 1727 | /* |
| 1728 | * This is the first time the device driver |
| 1729 | * sees this request (possibly after |
| 1730 | * requeueing). Notify IO scheduler. |
| 1731 | */ |
| 1732 | if (blk_sorted_rq(rq)) |
| 1733 | elv_activate_rq(q, rq); |
| 1734 | |
| 1735 | /* |
| 1736 | * just mark as started even if we don't start |
| 1737 | * it, a request that has been delayed should |
| 1738 | * not be passed by new incoming requests |
| 1739 | */ |
| 1740 | rq->cmd_flags |= REQ_STARTED; |
| 1741 | trace_block_rq_issue(q, rq); |
| 1742 | } |
| 1743 | |
| 1744 | if (!q->boundary_rq || q->boundary_rq == rq) { |
| 1745 | q->end_sector = rq_end_sector(rq); |
| 1746 | q->boundary_rq = NULL; |
| 1747 | } |
| 1748 | |
| 1749 | if (rq->cmd_flags & REQ_DONTPREP) |
| 1750 | break; |
| 1751 | |
Tejun Heo | 2e46e8b | 2009-05-07 22:24:41 +0900 | [diff] [blame] | 1752 | if (q->dma_drain_size && blk_rq_bytes(rq)) { |
Tejun Heo | 158dbda | 2009-04-23 11:05:18 +0900 | [diff] [blame] | 1753 | /* |
| 1754 | * make sure space for the drain appears we |
| 1755 | * know we can do this because max_hw_segments |
| 1756 | * has been adjusted to be one fewer than the |
| 1757 | * device can handle |
| 1758 | */ |
| 1759 | rq->nr_phys_segments++; |
| 1760 | } |
| 1761 | |
| 1762 | if (!q->prep_rq_fn) |
| 1763 | break; |
| 1764 | |
| 1765 | ret = q->prep_rq_fn(q, rq); |
| 1766 | if (ret == BLKPREP_OK) { |
| 1767 | break; |
| 1768 | } else if (ret == BLKPREP_DEFER) { |
| 1769 | /* |
| 1770 | * the request may have been (partially) prepped. |
| 1771 | * we need to keep this request in the front to |
| 1772 | * avoid resource deadlock. REQ_STARTED will |
| 1773 | * prevent other fs requests from passing this one. |
| 1774 | */ |
Tejun Heo | 2e46e8b | 2009-05-07 22:24:41 +0900 | [diff] [blame] | 1775 | if (q->dma_drain_size && blk_rq_bytes(rq) && |
Tejun Heo | 158dbda | 2009-04-23 11:05:18 +0900 | [diff] [blame] | 1776 | !(rq->cmd_flags & REQ_DONTPREP)) { |
| 1777 | /* |
| 1778 | * remove the space for the drain we added |
| 1779 | * so that we don't add it again |
| 1780 | */ |
| 1781 | --rq->nr_phys_segments; |
| 1782 | } |
| 1783 | |
| 1784 | rq = NULL; |
| 1785 | break; |
| 1786 | } else if (ret == BLKPREP_KILL) { |
| 1787 | rq->cmd_flags |= REQ_QUIET; |
James Bottomley | c143dc9 | 2009-05-30 06:43:49 +0200 | [diff] [blame] | 1788 | /* |
| 1789 | * Mark this request as started so we don't trigger |
| 1790 | * any debug logic in the end I/O path. |
| 1791 | */ |
| 1792 | blk_start_request(rq); |
Tejun Heo | 40cbbb7 | 2009-04-23 11:05:19 +0900 | [diff] [blame] | 1793 | __blk_end_request_all(rq, -EIO); |
Tejun Heo | 158dbda | 2009-04-23 11:05:18 +0900 | [diff] [blame] | 1794 | } else { |
| 1795 | printk(KERN_ERR "%s: bad return=%d\n", __func__, ret); |
| 1796 | break; |
| 1797 | } |
| 1798 | } |
| 1799 | |
| 1800 | return rq; |
| 1801 | } |
Tejun Heo | 9934c8c | 2009-05-08 11:54:16 +0900 | [diff] [blame] | 1802 | EXPORT_SYMBOL(blk_peek_request); |
Tejun Heo | 158dbda | 2009-04-23 11:05:18 +0900 | [diff] [blame] | 1803 | |
Tejun Heo | 9934c8c | 2009-05-08 11:54:16 +0900 | [diff] [blame] | 1804 | void blk_dequeue_request(struct request *rq) |
Tejun Heo | 158dbda | 2009-04-23 11:05:18 +0900 | [diff] [blame] | 1805 | { |
Tejun Heo | 9934c8c | 2009-05-08 11:54:16 +0900 | [diff] [blame] | 1806 | struct request_queue *q = rq->q; |
| 1807 | |
Tejun Heo | 158dbda | 2009-04-23 11:05:18 +0900 | [diff] [blame] | 1808 | BUG_ON(list_empty(&rq->queuelist)); |
| 1809 | BUG_ON(ELV_ON_HASH(rq)); |
| 1810 | |
| 1811 | list_del_init(&rq->queuelist); |
| 1812 | |
| 1813 | /* |
| 1814 | * the time frame between a request being removed from the lists |
| 1815 | * and to it is freed is accounted as io that is in progress at |
| 1816 | * the driver side. |
| 1817 | */ |
| 1818 | if (blk_account_rq(rq)) |
Jens Axboe | 0a7ae2f | 2009-05-20 08:54:31 +0200 | [diff] [blame] | 1819 | q->in_flight[rq_is_sync(rq)]++; |
Tejun Heo | 158dbda | 2009-04-23 11:05:18 +0900 | [diff] [blame] | 1820 | } |
| 1821 | |
Tejun Heo | 5efccd1 | 2009-04-23 11:05:18 +0900 | [diff] [blame] | 1822 | /** |
Tejun Heo | 9934c8c | 2009-05-08 11:54:16 +0900 | [diff] [blame] | 1823 | * blk_start_request - start request processing on the driver |
| 1824 | * @req: request to dequeue |
| 1825 | * |
| 1826 | * Description: |
| 1827 | * Dequeue @req and start timeout timer on it. This hands off the |
| 1828 | * request to the driver. |
| 1829 | * |
| 1830 | * Block internal functions which don't want to start timer should |
| 1831 | * call blk_dequeue_request(). |
| 1832 | * |
| 1833 | * Context: |
| 1834 | * queue_lock must be held. |
| 1835 | */ |
| 1836 | void blk_start_request(struct request *req) |
| 1837 | { |
| 1838 | blk_dequeue_request(req); |
| 1839 | |
| 1840 | /* |
Tejun Heo | 5f49f63 | 2009-05-19 18:33:05 +0900 | [diff] [blame] | 1841 | * We are now handing the request to the hardware, initialize |
| 1842 | * resid_len to full count and add the timeout handler. |
Tejun Heo | 9934c8c | 2009-05-08 11:54:16 +0900 | [diff] [blame] | 1843 | */ |
Tejun Heo | 5f49f63 | 2009-05-19 18:33:05 +0900 | [diff] [blame] | 1844 | req->resid_len = blk_rq_bytes(req); |
FUJITA Tomonori | dbb66c4 | 2009-06-09 05:47:10 +0200 | [diff] [blame] | 1845 | if (unlikely(blk_bidi_rq(req))) |
| 1846 | req->next_rq->resid_len = blk_rq_bytes(req->next_rq); |
| 1847 | |
Tejun Heo | 9934c8c | 2009-05-08 11:54:16 +0900 | [diff] [blame] | 1848 | blk_add_timer(req); |
| 1849 | } |
| 1850 | EXPORT_SYMBOL(blk_start_request); |
| 1851 | |
| 1852 | /** |
| 1853 | * blk_fetch_request - fetch a request from a request queue |
| 1854 | * @q: request queue to fetch a request from |
| 1855 | * |
| 1856 | * Description: |
| 1857 | * Return the request at the top of @q. The request is started on |
| 1858 | * return and LLD can start processing it immediately. |
| 1859 | * |
| 1860 | * Return: |
| 1861 | * Pointer to the request at the top of @q if available. Null |
| 1862 | * otherwise. |
| 1863 | * |
| 1864 | * Context: |
| 1865 | * queue_lock must be held. |
| 1866 | */ |
| 1867 | struct request *blk_fetch_request(struct request_queue *q) |
| 1868 | { |
| 1869 | struct request *rq; |
| 1870 | |
| 1871 | rq = blk_peek_request(q); |
| 1872 | if (rq) |
| 1873 | blk_start_request(rq); |
| 1874 | return rq; |
| 1875 | } |
| 1876 | EXPORT_SYMBOL(blk_fetch_request); |
| 1877 | |
| 1878 | /** |
Tejun Heo | 2e60e02 | 2009-04-23 11:05:18 +0900 | [diff] [blame] | 1879 | * blk_update_request - Special helper function for request stacking drivers |
Randy Dunlap | 8ebf975 | 2009-06-11 20:00:41 -0700 | [diff] [blame] | 1880 | * @req: the request being processed |
Kiyoshi Ueda | 3bcddea | 2007-12-11 17:52:28 -0500 | [diff] [blame] | 1881 | * @error: %0 for success, < %0 for error |
Randy Dunlap | 8ebf975 | 2009-06-11 20:00:41 -0700 | [diff] [blame] | 1882 | * @nr_bytes: number of bytes to complete @req |
Kiyoshi Ueda | 3bcddea | 2007-12-11 17:52:28 -0500 | [diff] [blame] | 1883 | * |
| 1884 | * Description: |
Randy Dunlap | 8ebf975 | 2009-06-11 20:00:41 -0700 | [diff] [blame] | 1885 | * Ends I/O on a number of bytes attached to @req, but doesn't complete |
| 1886 | * the request structure even if @req doesn't have leftover. |
| 1887 | * If @req has leftover, sets it up for the next range of segments. |
Tejun Heo | 2e60e02 | 2009-04-23 11:05:18 +0900 | [diff] [blame] | 1888 | * |
| 1889 | * This special helper function is only for request stacking drivers |
| 1890 | * (e.g. request-based dm) so that they can handle partial completion. |
| 1891 | * Actual device drivers should use blk_end_request instead. |
| 1892 | * |
| 1893 | * Passing the result of blk_rq_bytes() as @nr_bytes guarantees |
| 1894 | * %false return from this function. |
Kiyoshi Ueda | 3bcddea | 2007-12-11 17:52:28 -0500 | [diff] [blame] | 1895 | * |
| 1896 | * Return: |
Tejun Heo | 2e60e02 | 2009-04-23 11:05:18 +0900 | [diff] [blame] | 1897 | * %false - this request doesn't have any more data |
| 1898 | * %true - this request has more data |
Kiyoshi Ueda | 3bcddea | 2007-12-11 17:52:28 -0500 | [diff] [blame] | 1899 | **/ |
Tejun Heo | 2e60e02 | 2009-04-23 11:05:18 +0900 | [diff] [blame] | 1900 | bool blk_update_request(struct request *req, int error, unsigned int nr_bytes) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1901 | { |
Kiyoshi Ueda | 5450d3e | 2007-12-11 17:53:03 -0500 | [diff] [blame] | 1902 | int total_bytes, bio_nbytes, next_idx = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1903 | struct bio *bio; |
| 1904 | |
Tejun Heo | 2e60e02 | 2009-04-23 11:05:18 +0900 | [diff] [blame] | 1905 | if (!req->bio) |
| 1906 | return false; |
| 1907 | |
Arnaldo Carvalho de Melo | 5f3ea37 | 2008-10-30 08:34:33 +0100 | [diff] [blame] | 1908 | trace_block_rq_complete(req->q, req); |
Jens Axboe | 2056a78 | 2006-03-23 20:00:26 +0100 | [diff] [blame] | 1909 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1910 | /* |
Tejun Heo | 6f41469 | 2009-04-19 07:00:41 +0900 | [diff] [blame] | 1911 | * For fs requests, rq is just carrier of independent bio's |
| 1912 | * and each partial completion should be handled separately. |
| 1913 | * Reset per-request error on each partial completion. |
| 1914 | * |
| 1915 | * TODO: tj: This is too subtle. It would be better to let |
| 1916 | * low level drivers do what they see fit. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1917 | */ |
Tejun Heo | 6f41469 | 2009-04-19 07:00:41 +0900 | [diff] [blame] | 1918 | if (blk_fs_request(req)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1919 | req->errors = 0; |
| 1920 | |
Jens Axboe | 6728cb0 | 2008-01-31 13:03:55 +0100 | [diff] [blame] | 1921 | if (error && (blk_fs_request(req) && !(req->cmd_flags & REQ_QUIET))) { |
| 1922 | printk(KERN_ERR "end_request: I/O error, dev %s, sector %llu\n", |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1923 | req->rq_disk ? req->rq_disk->disk_name : "?", |
Tejun Heo | 83096eb | 2009-05-07 22:24:39 +0900 | [diff] [blame] | 1924 | (unsigned long long)blk_rq_pos(req)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1925 | } |
| 1926 | |
Jens Axboe | bc58ba9 | 2009-01-23 10:54:44 +0100 | [diff] [blame] | 1927 | blk_account_io_completion(req, nr_bytes); |
Jens Axboe | d72d904 | 2005-11-01 08:35:42 +0100 | [diff] [blame] | 1928 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1929 | total_bytes = bio_nbytes = 0; |
| 1930 | while ((bio = req->bio) != NULL) { |
| 1931 | int nbytes; |
| 1932 | |
| 1933 | if (nr_bytes >= bio->bi_size) { |
| 1934 | req->bio = bio->bi_next; |
| 1935 | nbytes = bio->bi_size; |
NeilBrown | 5bb23a6 | 2007-09-27 12:46:13 +0200 | [diff] [blame] | 1936 | req_bio_endio(req, bio, nbytes, error); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1937 | next_idx = 0; |
| 1938 | bio_nbytes = 0; |
| 1939 | } else { |
| 1940 | int idx = bio->bi_idx + next_idx; |
| 1941 | |
Kazuhisa Ichikawa | af498d7 | 2009-05-12 13:27:45 +0200 | [diff] [blame] | 1942 | if (unlikely(idx >= bio->bi_vcnt)) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1943 | blk_dump_rq_flags(req, "__end_that"); |
Jens Axboe | 6728cb0 | 2008-01-31 13:03:55 +0100 | [diff] [blame] | 1944 | printk(KERN_ERR "%s: bio idx %d >= vcnt %d\n", |
Kazuhisa Ichikawa | af498d7 | 2009-05-12 13:27:45 +0200 | [diff] [blame] | 1945 | __func__, idx, bio->bi_vcnt); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1946 | break; |
| 1947 | } |
| 1948 | |
| 1949 | nbytes = bio_iovec_idx(bio, idx)->bv_len; |
| 1950 | BIO_BUG_ON(nbytes > bio->bi_size); |
| 1951 | |
| 1952 | /* |
| 1953 | * not a complete bvec done |
| 1954 | */ |
| 1955 | if (unlikely(nbytes > nr_bytes)) { |
| 1956 | bio_nbytes += nr_bytes; |
| 1957 | total_bytes += nr_bytes; |
| 1958 | break; |
| 1959 | } |
| 1960 | |
| 1961 | /* |
| 1962 | * advance to the next vector |
| 1963 | */ |
| 1964 | next_idx++; |
| 1965 | bio_nbytes += nbytes; |
| 1966 | } |
| 1967 | |
| 1968 | total_bytes += nbytes; |
| 1969 | nr_bytes -= nbytes; |
| 1970 | |
Jens Axboe | 6728cb0 | 2008-01-31 13:03:55 +0100 | [diff] [blame] | 1971 | bio = req->bio; |
| 1972 | if (bio) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1973 | /* |
| 1974 | * end more in this run, or just return 'not-done' |
| 1975 | */ |
| 1976 | if (unlikely(nr_bytes <= 0)) |
| 1977 | break; |
| 1978 | } |
| 1979 | } |
| 1980 | |
| 1981 | /* |
| 1982 | * completely done |
| 1983 | */ |
Tejun Heo | 2e60e02 | 2009-04-23 11:05:18 +0900 | [diff] [blame] | 1984 | if (!req->bio) { |
| 1985 | /* |
| 1986 | * Reset counters so that the request stacking driver |
| 1987 | * can find how many bytes remain in the request |
| 1988 | * later. |
| 1989 | */ |
Tejun Heo | a2dec7b | 2009-05-07 22:24:44 +0900 | [diff] [blame] | 1990 | req->__data_len = 0; |
Tejun Heo | 2e60e02 | 2009-04-23 11:05:18 +0900 | [diff] [blame] | 1991 | return false; |
| 1992 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1993 | |
| 1994 | /* |
| 1995 | * if the request wasn't completed, update state |
| 1996 | */ |
| 1997 | if (bio_nbytes) { |
NeilBrown | 5bb23a6 | 2007-09-27 12:46:13 +0200 | [diff] [blame] | 1998 | req_bio_endio(req, bio, bio_nbytes, error); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1999 | bio->bi_idx += next_idx; |
| 2000 | bio_iovec(bio)->bv_offset += nr_bytes; |
| 2001 | bio_iovec(bio)->bv_len -= nr_bytes; |
| 2002 | } |
| 2003 | |
Tejun Heo | a2dec7b | 2009-05-07 22:24:44 +0900 | [diff] [blame] | 2004 | req->__data_len -= total_bytes; |
Tejun Heo | 2e46e8b | 2009-05-07 22:24:41 +0900 | [diff] [blame] | 2005 | req->buffer = bio_data(req->bio); |
| 2006 | |
| 2007 | /* update sector only for requests with clear definition of sector */ |
| 2008 | if (blk_fs_request(req) || blk_discard_rq(req)) |
Tejun Heo | a2dec7b | 2009-05-07 22:24:44 +0900 | [diff] [blame] | 2009 | req->__sector += total_bytes >> 9; |
Tejun Heo | 2e46e8b | 2009-05-07 22:24:41 +0900 | [diff] [blame] | 2010 | |
| 2011 | /* |
| 2012 | * If total number of sectors is less than the first segment |
| 2013 | * size, something has gone terribly wrong. |
| 2014 | */ |
| 2015 | if (blk_rq_bytes(req) < blk_rq_cur_bytes(req)) { |
| 2016 | printk(KERN_ERR "blk: request botched\n"); |
Tejun Heo | a2dec7b | 2009-05-07 22:24:44 +0900 | [diff] [blame] | 2017 | req->__data_len = blk_rq_cur_bytes(req); |
Tejun Heo | 2e46e8b | 2009-05-07 22:24:41 +0900 | [diff] [blame] | 2018 | } |
| 2019 | |
| 2020 | /* recalculate the number of segments */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2021 | blk_recalc_rq_segments(req); |
Tejun Heo | 2e46e8b | 2009-05-07 22:24:41 +0900 | [diff] [blame] | 2022 | |
Tejun Heo | 2e60e02 | 2009-04-23 11:05:18 +0900 | [diff] [blame] | 2023 | return true; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2024 | } |
Tejun Heo | 2e60e02 | 2009-04-23 11:05:18 +0900 | [diff] [blame] | 2025 | EXPORT_SYMBOL_GPL(blk_update_request); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2026 | |
Tejun Heo | 2e60e02 | 2009-04-23 11:05:18 +0900 | [diff] [blame] | 2027 | static bool blk_update_bidi_request(struct request *rq, int error, |
| 2028 | unsigned int nr_bytes, |
| 2029 | unsigned int bidi_bytes) |
Tejun Heo | 5efccd1 | 2009-04-23 11:05:18 +0900 | [diff] [blame] | 2030 | { |
Tejun Heo | 2e60e02 | 2009-04-23 11:05:18 +0900 | [diff] [blame] | 2031 | if (blk_update_request(rq, error, nr_bytes)) |
| 2032 | return true; |
Tejun Heo | 5efccd1 | 2009-04-23 11:05:18 +0900 | [diff] [blame] | 2033 | |
Tejun Heo | 2e60e02 | 2009-04-23 11:05:18 +0900 | [diff] [blame] | 2034 | /* Bidi request must be completed as a whole */ |
| 2035 | if (unlikely(blk_bidi_rq(rq)) && |
| 2036 | blk_update_request(rq->next_rq, error, bidi_bytes)) |
| 2037 | return true; |
Tejun Heo | 5efccd1 | 2009-04-23 11:05:18 +0900 | [diff] [blame] | 2038 | |
Tejun Heo | 2e60e02 | 2009-04-23 11:05:18 +0900 | [diff] [blame] | 2039 | add_disk_randomness(rq->rq_disk); |
| 2040 | |
| 2041 | return false; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2042 | } |
| 2043 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2044 | /* |
| 2045 | * queue lock must be held |
| 2046 | */ |
Tejun Heo | 2e60e02 | 2009-04-23 11:05:18 +0900 | [diff] [blame] | 2047 | static void blk_finish_request(struct request *req, int error) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2048 | { |
Kiyoshi Ueda | b828623 | 2007-12-11 17:53:24 -0500 | [diff] [blame] | 2049 | if (blk_rq_tagged(req)) |
| 2050 | blk_queue_end_tag(req->q, req); |
| 2051 | |
James Bottomley | ba396a6 | 2009-05-27 14:17:08 +0200 | [diff] [blame] | 2052 | BUG_ON(blk_queued_rq(req)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2053 | |
| 2054 | if (unlikely(laptop_mode) && blk_fs_request(req)) |
| 2055 | laptop_io_completion(); |
| 2056 | |
Mike Anderson | e78042e5 | 2008-10-30 02:16:20 -0700 | [diff] [blame] | 2057 | blk_delete_timer(req); |
| 2058 | |
Jens Axboe | bc58ba9 | 2009-01-23 10:54:44 +0100 | [diff] [blame] | 2059 | blk_account_io_done(req); |
Kiyoshi Ueda | b828623 | 2007-12-11 17:53:24 -0500 | [diff] [blame] | 2060 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2061 | if (req->end_io) |
Tejun Heo | 8ffdc65 | 2006-01-06 09:49:03 +0100 | [diff] [blame] | 2062 | req->end_io(req, error); |
Kiyoshi Ueda | b828623 | 2007-12-11 17:53:24 -0500 | [diff] [blame] | 2063 | else { |
| 2064 | if (blk_bidi_rq(req)) |
| 2065 | __blk_put_request(req->next_rq->q, req->next_rq); |
| 2066 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2067 | __blk_put_request(req->q, req); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2068 | } |
| 2069 | } |
| 2070 | |
Kiyoshi Ueda | 3b11313 | 2007-12-11 17:41:17 -0500 | [diff] [blame] | 2071 | /** |
Tejun Heo | 2e60e02 | 2009-04-23 11:05:18 +0900 | [diff] [blame] | 2072 | * blk_end_bidi_request - Complete a bidi request |
| 2073 | * @rq: the request to complete |
Randy Dunlap | 710027a | 2008-08-19 20:13:11 +0200 | [diff] [blame] | 2074 | * @error: %0 for success, < %0 for error |
Kiyoshi Ueda | e3a04fe | 2007-12-11 17:51:46 -0500 | [diff] [blame] | 2075 | * @nr_bytes: number of bytes to complete @rq |
| 2076 | * @bidi_bytes: number of bytes to complete @rq->next_rq |
Kiyoshi Ueda | 336cdb4 | 2007-12-11 17:40:30 -0500 | [diff] [blame] | 2077 | * |
| 2078 | * Description: |
| 2079 | * Ends I/O on a number of bytes attached to @rq and @rq->next_rq. |
Tejun Heo | 2e60e02 | 2009-04-23 11:05:18 +0900 | [diff] [blame] | 2080 | * Drivers that supports bidi can safely call this member for any |
| 2081 | * type of request, bidi or uni. In the later case @bidi_bytes is |
| 2082 | * just ignored. |
Kiyoshi Ueda | 336cdb4 | 2007-12-11 17:40:30 -0500 | [diff] [blame] | 2083 | * |
| 2084 | * Return: |
Tejun Heo | 2e60e02 | 2009-04-23 11:05:18 +0900 | [diff] [blame] | 2085 | * %false - we are done with this request |
| 2086 | * %true - still buffers pending for this request |
Kiyoshi Ueda | 336cdb4 | 2007-12-11 17:40:30 -0500 | [diff] [blame] | 2087 | **/ |
FUJITA Tomonori | b1f7449 | 2009-05-11 17:56:09 +0900 | [diff] [blame] | 2088 | static bool blk_end_bidi_request(struct request *rq, int error, |
| 2089 | unsigned int nr_bytes, unsigned int bidi_bytes) |
Kiyoshi Ueda | 336cdb4 | 2007-12-11 17:40:30 -0500 | [diff] [blame] | 2090 | { |
| 2091 | struct request_queue *q = rq->q; |
Tejun Heo | 2e60e02 | 2009-04-23 11:05:18 +0900 | [diff] [blame] | 2092 | unsigned long flags; |
Kiyoshi Ueda | 336cdb4 | 2007-12-11 17:40:30 -0500 | [diff] [blame] | 2093 | |
Tejun Heo | 2e60e02 | 2009-04-23 11:05:18 +0900 | [diff] [blame] | 2094 | if (blk_update_bidi_request(rq, error, nr_bytes, bidi_bytes)) |
| 2095 | return true; |
Kiyoshi Ueda | e19a3ab | 2007-12-11 17:51:02 -0500 | [diff] [blame] | 2096 | |
Kiyoshi Ueda | 336cdb4 | 2007-12-11 17:40:30 -0500 | [diff] [blame] | 2097 | spin_lock_irqsave(q->queue_lock, flags); |
Tejun Heo | 2e60e02 | 2009-04-23 11:05:18 +0900 | [diff] [blame] | 2098 | blk_finish_request(rq, error); |
Kiyoshi Ueda | 336cdb4 | 2007-12-11 17:40:30 -0500 | [diff] [blame] | 2099 | spin_unlock_irqrestore(q->queue_lock, flags); |
| 2100 | |
Tejun Heo | 2e60e02 | 2009-04-23 11:05:18 +0900 | [diff] [blame] | 2101 | return false; |
Kiyoshi Ueda | e3a04fe | 2007-12-11 17:51:46 -0500 | [diff] [blame] | 2102 | } |
Kiyoshi Ueda | e3a04fe | 2007-12-11 17:51:46 -0500 | [diff] [blame] | 2103 | |
| 2104 | /** |
Tejun Heo | 2e60e02 | 2009-04-23 11:05:18 +0900 | [diff] [blame] | 2105 | * __blk_end_bidi_request - Complete a bidi request with queue lock held |
| 2106 | * @rq: the request to complete |
| 2107 | * @error: %0 for success, < %0 for error |
| 2108 | * @nr_bytes: number of bytes to complete @rq |
| 2109 | * @bidi_bytes: number of bytes to complete @rq->next_rq |
Tejun Heo | 5efccd1 | 2009-04-23 11:05:18 +0900 | [diff] [blame] | 2110 | * |
| 2111 | * Description: |
Tejun Heo | 2e60e02 | 2009-04-23 11:05:18 +0900 | [diff] [blame] | 2112 | * Identical to blk_end_bidi_request() except that queue lock is |
| 2113 | * assumed to be locked on entry and remains so on return. |
Tejun Heo | 5efccd1 | 2009-04-23 11:05:18 +0900 | [diff] [blame] | 2114 | * |
Tejun Heo | 2e60e02 | 2009-04-23 11:05:18 +0900 | [diff] [blame] | 2115 | * Return: |
| 2116 | * %false - we are done with this request |
| 2117 | * %true - still buffers pending for this request |
Tejun Heo | 5efccd1 | 2009-04-23 11:05:18 +0900 | [diff] [blame] | 2118 | **/ |
FUJITA Tomonori | b1f7449 | 2009-05-11 17:56:09 +0900 | [diff] [blame] | 2119 | static bool __blk_end_bidi_request(struct request *rq, int error, |
| 2120 | unsigned int nr_bytes, unsigned int bidi_bytes) |
Tejun Heo | 5efccd1 | 2009-04-23 11:05:18 +0900 | [diff] [blame] | 2121 | { |
Tejun Heo | 2e60e02 | 2009-04-23 11:05:18 +0900 | [diff] [blame] | 2122 | if (blk_update_bidi_request(rq, error, nr_bytes, bidi_bytes)) |
| 2123 | return true; |
Tejun Heo | 5efccd1 | 2009-04-23 11:05:18 +0900 | [diff] [blame] | 2124 | |
Tejun Heo | 2e60e02 | 2009-04-23 11:05:18 +0900 | [diff] [blame] | 2125 | blk_finish_request(rq, error); |
Tejun Heo | 5efccd1 | 2009-04-23 11:05:18 +0900 | [diff] [blame] | 2126 | |
Tejun Heo | 2e60e02 | 2009-04-23 11:05:18 +0900 | [diff] [blame] | 2127 | return false; |
Kiyoshi Ueda | 336cdb4 | 2007-12-11 17:40:30 -0500 | [diff] [blame] | 2128 | } |
| 2129 | |
| 2130 | /** |
| 2131 | * blk_end_request - Helper function for drivers to complete the request. |
| 2132 | * @rq: the request being processed |
| 2133 | * @error: %0 for success, < %0 for error |
| 2134 | * @nr_bytes: number of bytes to complete |
| 2135 | * |
| 2136 | * Description: |
| 2137 | * Ends I/O on a number of bytes attached to @rq. |
| 2138 | * If @rq has leftover, sets it up for the next range of segments. |
| 2139 | * |
| 2140 | * Return: |
FUJITA Tomonori | b1f7449 | 2009-05-11 17:56:09 +0900 | [diff] [blame] | 2141 | * %false - we are done with this request |
| 2142 | * %true - still buffers pending for this request |
Kiyoshi Ueda | 336cdb4 | 2007-12-11 17:40:30 -0500 | [diff] [blame] | 2143 | **/ |
FUJITA Tomonori | b1f7449 | 2009-05-11 17:56:09 +0900 | [diff] [blame] | 2144 | bool blk_end_request(struct request *rq, int error, unsigned int nr_bytes) |
Kiyoshi Ueda | 336cdb4 | 2007-12-11 17:40:30 -0500 | [diff] [blame] | 2145 | { |
FUJITA Tomonori | b1f7449 | 2009-05-11 17:56:09 +0900 | [diff] [blame] | 2146 | return blk_end_bidi_request(rq, error, nr_bytes, 0); |
Kiyoshi Ueda | 336cdb4 | 2007-12-11 17:40:30 -0500 | [diff] [blame] | 2147 | } |
| 2148 | EXPORT_SYMBOL_GPL(blk_end_request); |
| 2149 | |
| 2150 | /** |
FUJITA Tomonori | b1f7449 | 2009-05-11 17:56:09 +0900 | [diff] [blame] | 2151 | * blk_end_request_all - Helper function for drives to finish the request. |
| 2152 | * @rq: the request to finish |
Randy Dunlap | 8ebf975 | 2009-06-11 20:00:41 -0700 | [diff] [blame] | 2153 | * @error: %0 for success, < %0 for error |
FUJITA Tomonori | b1f7449 | 2009-05-11 17:56:09 +0900 | [diff] [blame] | 2154 | * |
| 2155 | * Description: |
| 2156 | * Completely finish @rq. |
| 2157 | */ |
| 2158 | void blk_end_request_all(struct request *rq, int error) |
| 2159 | { |
| 2160 | bool pending; |
| 2161 | unsigned int bidi_bytes = 0; |
| 2162 | |
| 2163 | if (unlikely(blk_bidi_rq(rq))) |
| 2164 | bidi_bytes = blk_rq_bytes(rq->next_rq); |
| 2165 | |
| 2166 | pending = blk_end_bidi_request(rq, error, blk_rq_bytes(rq), bidi_bytes); |
| 2167 | BUG_ON(pending); |
| 2168 | } |
| 2169 | EXPORT_SYMBOL_GPL(blk_end_request_all); |
| 2170 | |
| 2171 | /** |
| 2172 | * blk_end_request_cur - Helper function to finish the current request chunk. |
| 2173 | * @rq: the request to finish the current chunk for |
Randy Dunlap | 8ebf975 | 2009-06-11 20:00:41 -0700 | [diff] [blame] | 2174 | * @error: %0 for success, < %0 for error |
FUJITA Tomonori | b1f7449 | 2009-05-11 17:56:09 +0900 | [diff] [blame] | 2175 | * |
| 2176 | * Description: |
| 2177 | * Complete the current consecutively mapped chunk from @rq. |
| 2178 | * |
| 2179 | * Return: |
| 2180 | * %false - we are done with this request |
| 2181 | * %true - still buffers pending for this request |
| 2182 | */ |
| 2183 | bool blk_end_request_cur(struct request *rq, int error) |
| 2184 | { |
| 2185 | return blk_end_request(rq, error, blk_rq_cur_bytes(rq)); |
| 2186 | } |
| 2187 | EXPORT_SYMBOL_GPL(blk_end_request_cur); |
| 2188 | |
| 2189 | /** |
Kiyoshi Ueda | e19a3ab | 2007-12-11 17:51:02 -0500 | [diff] [blame] | 2190 | * __blk_end_request - Helper function for drivers to complete the request. |
Kiyoshi Ueda | 336cdb4 | 2007-12-11 17:40:30 -0500 | [diff] [blame] | 2191 | * @rq: the request being processed |
Kiyoshi Ueda | e19a3ab | 2007-12-11 17:51:02 -0500 | [diff] [blame] | 2192 | * @error: %0 for success, < %0 for error |
| 2193 | * @nr_bytes: number of bytes to complete |
Kiyoshi Ueda | 336cdb4 | 2007-12-11 17:40:30 -0500 | [diff] [blame] | 2194 | * |
| 2195 | * Description: |
| 2196 | * Must be called with queue lock held unlike blk_end_request(). |
| 2197 | * |
| 2198 | * Return: |
FUJITA Tomonori | b1f7449 | 2009-05-11 17:56:09 +0900 | [diff] [blame] | 2199 | * %false - we are done with this request |
| 2200 | * %true - still buffers pending for this request |
Kiyoshi Ueda | 336cdb4 | 2007-12-11 17:40:30 -0500 | [diff] [blame] | 2201 | **/ |
FUJITA Tomonori | b1f7449 | 2009-05-11 17:56:09 +0900 | [diff] [blame] | 2202 | bool __blk_end_request(struct request *rq, int error, unsigned int nr_bytes) |
Kiyoshi Ueda | 336cdb4 | 2007-12-11 17:40:30 -0500 | [diff] [blame] | 2203 | { |
FUJITA Tomonori | b1f7449 | 2009-05-11 17:56:09 +0900 | [diff] [blame] | 2204 | return __blk_end_bidi_request(rq, error, nr_bytes, 0); |
Kiyoshi Ueda | 336cdb4 | 2007-12-11 17:40:30 -0500 | [diff] [blame] | 2205 | } |
| 2206 | EXPORT_SYMBOL_GPL(__blk_end_request); |
| 2207 | |
| 2208 | /** |
FUJITA Tomonori | b1f7449 | 2009-05-11 17:56:09 +0900 | [diff] [blame] | 2209 | * __blk_end_request_all - Helper function for drives to finish the request. |
| 2210 | * @rq: the request to finish |
Randy Dunlap | 8ebf975 | 2009-06-11 20:00:41 -0700 | [diff] [blame] | 2211 | * @error: %0 for success, < %0 for error |
Kiyoshi Ueda | 336cdb4 | 2007-12-11 17:40:30 -0500 | [diff] [blame] | 2212 | * |
| 2213 | * Description: |
FUJITA Tomonori | b1f7449 | 2009-05-11 17:56:09 +0900 | [diff] [blame] | 2214 | * Completely finish @rq. Must be called with queue lock held. |
Kiyoshi Ueda | 32fab44 | 2008-09-18 10:45:09 -0400 | [diff] [blame] | 2215 | */ |
FUJITA Tomonori | b1f7449 | 2009-05-11 17:56:09 +0900 | [diff] [blame] | 2216 | void __blk_end_request_all(struct request *rq, int error) |
Kiyoshi Ueda | 32fab44 | 2008-09-18 10:45:09 -0400 | [diff] [blame] | 2217 | { |
FUJITA Tomonori | b1f7449 | 2009-05-11 17:56:09 +0900 | [diff] [blame] | 2218 | bool pending; |
| 2219 | unsigned int bidi_bytes = 0; |
| 2220 | |
| 2221 | if (unlikely(blk_bidi_rq(rq))) |
| 2222 | bidi_bytes = blk_rq_bytes(rq->next_rq); |
| 2223 | |
| 2224 | pending = __blk_end_bidi_request(rq, error, blk_rq_bytes(rq), bidi_bytes); |
| 2225 | BUG_ON(pending); |
Kiyoshi Ueda | 32fab44 | 2008-09-18 10:45:09 -0400 | [diff] [blame] | 2226 | } |
FUJITA Tomonori | b1f7449 | 2009-05-11 17:56:09 +0900 | [diff] [blame] | 2227 | EXPORT_SYMBOL_GPL(__blk_end_request_all); |
Kiyoshi Ueda | 32fab44 | 2008-09-18 10:45:09 -0400 | [diff] [blame] | 2228 | |
| 2229 | /** |
FUJITA Tomonori | b1f7449 | 2009-05-11 17:56:09 +0900 | [diff] [blame] | 2230 | * __blk_end_request_cur - Helper function to finish the current request chunk. |
| 2231 | * @rq: the request to finish the current chunk for |
Randy Dunlap | 8ebf975 | 2009-06-11 20:00:41 -0700 | [diff] [blame] | 2232 | * @error: %0 for success, < %0 for error |
Kiyoshi Ueda | e19a3ab | 2007-12-11 17:51:02 -0500 | [diff] [blame] | 2233 | * |
| 2234 | * Description: |
FUJITA Tomonori | b1f7449 | 2009-05-11 17:56:09 +0900 | [diff] [blame] | 2235 | * Complete the current consecutively mapped chunk from @rq. Must |
| 2236 | * be called with queue lock held. |
Kiyoshi Ueda | e19a3ab | 2007-12-11 17:51:02 -0500 | [diff] [blame] | 2237 | * |
| 2238 | * Return: |
FUJITA Tomonori | b1f7449 | 2009-05-11 17:56:09 +0900 | [diff] [blame] | 2239 | * %false - we are done with this request |
| 2240 | * %true - still buffers pending for this request |
| 2241 | */ |
| 2242 | bool __blk_end_request_cur(struct request *rq, int error) |
Kiyoshi Ueda | e19a3ab | 2007-12-11 17:51:02 -0500 | [diff] [blame] | 2243 | { |
FUJITA Tomonori | b1f7449 | 2009-05-11 17:56:09 +0900 | [diff] [blame] | 2244 | return __blk_end_request(rq, error, blk_rq_cur_bytes(rq)); |
Kiyoshi Ueda | e19a3ab | 2007-12-11 17:51:02 -0500 | [diff] [blame] | 2245 | } |
FUJITA Tomonori | b1f7449 | 2009-05-11 17:56:09 +0900 | [diff] [blame] | 2246 | EXPORT_SYMBOL_GPL(__blk_end_request_cur); |
Kiyoshi Ueda | e19a3ab | 2007-12-11 17:51:02 -0500 | [diff] [blame] | 2247 | |
Jens Axboe | 86db1e2 | 2008-01-29 14:53:40 +0100 | [diff] [blame] | 2248 | void blk_rq_bio_prep(struct request_queue *q, struct request *rq, |
| 2249 | struct bio *bio) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2250 | { |
David Woodhouse | d628eae | 2008-08-09 16:22:17 +0100 | [diff] [blame] | 2251 | /* Bit 0 (R/W) is identical in rq->cmd_flags and bio->bi_rw, and |
| 2252 | we want BIO_RW_AHEAD (bit 1) to imply REQ_FAILFAST (bit 1). */ |
Jens Axboe | 4aff5e2 | 2006-08-10 08:44:47 +0200 | [diff] [blame] | 2253 | rq->cmd_flags |= (bio->bi_rw & 3); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2254 | |
David Woodhouse | fb2dce8 | 2008-08-05 18:01:53 +0100 | [diff] [blame] | 2255 | if (bio_has_data(bio)) { |
| 2256 | rq->nr_phys_segments = bio_phys_segments(q, bio); |
David Woodhouse | fb2dce8 | 2008-08-05 18:01:53 +0100 | [diff] [blame] | 2257 | rq->buffer = bio_data(bio); |
| 2258 | } |
Tejun Heo | a2dec7b | 2009-05-07 22:24:44 +0900 | [diff] [blame] | 2259 | rq->__data_len = bio->bi_size; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2260 | rq->bio = rq->biotail = bio; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2261 | |
NeilBrown | 6684657 | 2007-08-16 13:31:28 +0200 | [diff] [blame] | 2262 | if (bio->bi_bdev) |
| 2263 | rq->rq_disk = bio->bi_bdev->bd_disk; |
| 2264 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2265 | |
Kiyoshi Ueda | ef9e3fa | 2008-10-01 16:12:15 +0200 | [diff] [blame] | 2266 | /** |
| 2267 | * blk_lld_busy - Check if underlying low-level drivers of a device are busy |
| 2268 | * @q : the queue of the device being checked |
| 2269 | * |
| 2270 | * Description: |
| 2271 | * Check if underlying low-level drivers of a device are busy. |
| 2272 | * If the drivers want to export their busy state, they must set own |
| 2273 | * exporting function using blk_queue_lld_busy() first. |
| 2274 | * |
| 2275 | * Basically, this function is used only by request stacking drivers |
| 2276 | * to stop dispatching requests to underlying devices when underlying |
| 2277 | * devices are busy. This behavior helps more I/O merging on the queue |
| 2278 | * of the request stacking driver and prevents I/O throughput regression |
| 2279 | * on burst I/O load. |
| 2280 | * |
| 2281 | * Return: |
| 2282 | * 0 - Not busy (The request stacking driver should dispatch request) |
| 2283 | * 1 - Busy (The request stacking driver should stop dispatching request) |
| 2284 | */ |
| 2285 | int blk_lld_busy(struct request_queue *q) |
| 2286 | { |
| 2287 | if (q->lld_busy_fn) |
| 2288 | return q->lld_busy_fn(q); |
| 2289 | |
| 2290 | return 0; |
| 2291 | } |
| 2292 | EXPORT_SYMBOL_GPL(blk_lld_busy); |
| 2293 | |
Kiyoshi Ueda | b0fd271 | 2009-06-11 13:10:16 +0200 | [diff] [blame] | 2294 | /** |
| 2295 | * blk_rq_unprep_clone - Helper function to free all bios in a cloned request |
| 2296 | * @rq: the clone request to be cleaned up |
| 2297 | * |
| 2298 | * Description: |
| 2299 | * Free all bios in @rq for a cloned request. |
| 2300 | */ |
| 2301 | void blk_rq_unprep_clone(struct request *rq) |
| 2302 | { |
| 2303 | struct bio *bio; |
| 2304 | |
| 2305 | while ((bio = rq->bio) != NULL) { |
| 2306 | rq->bio = bio->bi_next; |
| 2307 | |
| 2308 | bio_put(bio); |
| 2309 | } |
| 2310 | } |
| 2311 | EXPORT_SYMBOL_GPL(blk_rq_unprep_clone); |
| 2312 | |
| 2313 | /* |
| 2314 | * Copy attributes of the original request to the clone request. |
| 2315 | * The actual data parts (e.g. ->cmd, ->buffer, ->sense) are not copied. |
| 2316 | */ |
| 2317 | static void __blk_rq_prep_clone(struct request *dst, struct request *src) |
| 2318 | { |
| 2319 | dst->cpu = src->cpu; |
| 2320 | dst->cmd_flags = (rq_data_dir(src) | REQ_NOMERGE); |
| 2321 | dst->cmd_type = src->cmd_type; |
| 2322 | dst->__sector = blk_rq_pos(src); |
| 2323 | dst->__data_len = blk_rq_bytes(src); |
| 2324 | dst->nr_phys_segments = src->nr_phys_segments; |
| 2325 | dst->ioprio = src->ioprio; |
| 2326 | dst->extra_len = src->extra_len; |
| 2327 | } |
| 2328 | |
| 2329 | /** |
| 2330 | * blk_rq_prep_clone - Helper function to setup clone request |
| 2331 | * @rq: the request to be setup |
| 2332 | * @rq_src: original request to be cloned |
| 2333 | * @bs: bio_set that bios for clone are allocated from |
| 2334 | * @gfp_mask: memory allocation mask for bio |
| 2335 | * @bio_ctr: setup function to be called for each clone bio. |
| 2336 | * Returns %0 for success, non %0 for failure. |
| 2337 | * @data: private data to be passed to @bio_ctr |
| 2338 | * |
| 2339 | * Description: |
| 2340 | * Clones bios in @rq_src to @rq, and copies attributes of @rq_src to @rq. |
| 2341 | * The actual data parts of @rq_src (e.g. ->cmd, ->buffer, ->sense) |
| 2342 | * are not copied, and copying such parts is the caller's responsibility. |
| 2343 | * Also, pages which the original bios are pointing to are not copied |
| 2344 | * and the cloned bios just point same pages. |
| 2345 | * So cloned bios must be completed before original bios, which means |
| 2346 | * the caller must complete @rq before @rq_src. |
| 2347 | */ |
| 2348 | int blk_rq_prep_clone(struct request *rq, struct request *rq_src, |
| 2349 | struct bio_set *bs, gfp_t gfp_mask, |
| 2350 | int (*bio_ctr)(struct bio *, struct bio *, void *), |
| 2351 | void *data) |
| 2352 | { |
| 2353 | struct bio *bio, *bio_src; |
| 2354 | |
| 2355 | if (!bs) |
| 2356 | bs = fs_bio_set; |
| 2357 | |
| 2358 | blk_rq_init(NULL, rq); |
| 2359 | |
| 2360 | __rq_for_each_bio(bio_src, rq_src) { |
| 2361 | bio = bio_alloc_bioset(gfp_mask, bio_src->bi_max_vecs, bs); |
| 2362 | if (!bio) |
| 2363 | goto free_and_out; |
| 2364 | |
| 2365 | __bio_clone(bio, bio_src); |
| 2366 | |
| 2367 | if (bio_integrity(bio_src) && |
| 2368 | bio_integrity_clone(bio, bio_src, gfp_mask)) |
| 2369 | goto free_and_out; |
| 2370 | |
| 2371 | if (bio_ctr && bio_ctr(bio, bio_src, data)) |
| 2372 | goto free_and_out; |
| 2373 | |
| 2374 | if (rq->bio) { |
| 2375 | rq->biotail->bi_next = bio; |
| 2376 | rq->biotail = bio; |
| 2377 | } else |
| 2378 | rq->bio = rq->biotail = bio; |
| 2379 | } |
| 2380 | |
| 2381 | __blk_rq_prep_clone(rq, rq_src); |
| 2382 | |
| 2383 | return 0; |
| 2384 | |
| 2385 | free_and_out: |
| 2386 | if (bio) |
| 2387 | bio_free(bio, bs); |
| 2388 | blk_rq_unprep_clone(rq); |
| 2389 | |
| 2390 | return -ENOMEM; |
| 2391 | } |
| 2392 | EXPORT_SYMBOL_GPL(blk_rq_prep_clone); |
| 2393 | |
Jens Axboe | 18887ad | 2008-07-28 13:08:45 +0200 | [diff] [blame] | 2394 | int kblockd_schedule_work(struct request_queue *q, struct work_struct *work) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2395 | { |
| 2396 | return queue_work(kblockd_workqueue, work); |
| 2397 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2398 | EXPORT_SYMBOL(kblockd_schedule_work); |
| 2399 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2400 | int __init blk_dev_init(void) |
| 2401 | { |
Nikanth Karthikesan | 9eb55b0 | 2009-04-27 14:53:54 +0200 | [diff] [blame] | 2402 | BUILD_BUG_ON(__REQ_NR_BITS > 8 * |
| 2403 | sizeof(((struct request *)0)->cmd_flags)); |
| 2404 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2405 | kblockd_workqueue = create_workqueue("kblockd"); |
| 2406 | if (!kblockd_workqueue) |
| 2407 | panic("Failed to create kblockd\n"); |
| 2408 | |
| 2409 | request_cachep = kmem_cache_create("blkdev_requests", |
Paul Mundt | 20c2df8 | 2007-07-20 10:11:58 +0900 | [diff] [blame] | 2410 | sizeof(struct request), 0, SLAB_PANIC, NULL); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2411 | |
Jens Axboe | 8324aa9 | 2008-01-29 14:51:59 +0100 | [diff] [blame] | 2412 | blk_requestq_cachep = kmem_cache_create("blkdev_queue", |
Jens Axboe | 165125e | 2007-07-24 09:28:11 +0200 | [diff] [blame] | 2413 | sizeof(struct request_queue), 0, SLAB_PANIC, NULL); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2414 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2415 | return 0; |
| 2416 | } |
| 2417 | |