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