aboutsummaryrefslogtreecommitdiffstats
path: root/block
diff options
context:
space:
mode:
authorPaul Mackerras <paulus@samba.org>2006-12-03 23:59:07 -0500
committerPaul Mackerras <paulus@samba.org>2006-12-03 23:59:07 -0500
commit79acbb3ff2d8095b692e1502b9eb2ccec348de26 (patch)
tree6ab773e5a8f9de2cd6443362b21d0d6fffe3b35e /block
parent19a79859e168640f8e16d7b216d211c1c52b687a (diff)
parent2b5f6dcce5bf94b9b119e9ed8d537098ec61c3d2 (diff)
Merge branch 'linux-2.6' into for-linus
Diffstat (limited to 'block')
-rw-r--r--block/as-iosched.c2
-rw-r--r--block/blktrace.c57
-rw-r--r--block/cfq-iosched.c25
-rw-r--r--block/deadline-iosched.c2
-rw-r--r--block/elevator.c4
-rw-r--r--block/ll_rw_blk.c274
-rw-r--r--block/noop-iosched.c2
-rw-r--r--block/scsi_ioctl.c58
8 files changed, 244 insertions, 180 deletions
diff --git a/block/as-iosched.c b/block/as-iosched.c
index 50b95e4c14..00242111a4 100644
--- a/block/as-iosched.c
+++ b/block/as-iosched.c
@@ -1317,7 +1317,7 @@ static void as_exit_queue(elevator_t *e)
1317/* 1317/*
1318 * initialize elevator private data (as_data). 1318 * initialize elevator private data (as_data).
1319 */ 1319 */
1320static void *as_init_queue(request_queue_t *q, elevator_t *e) 1320static void *as_init_queue(request_queue_t *q)
1321{ 1321{
1322 struct as_data *ad; 1322 struct as_data *ad;
1323 1323
diff --git a/block/blktrace.c b/block/blktrace.c
index 135593c8e4..562ca7cbf8 100644
--- a/block/blktrace.c
+++ b/block/blktrace.c
@@ -22,30 +22,61 @@
22#include <linux/init.h> 22#include <linux/init.h>
23#include <linux/mutex.h> 23#include <linux/mutex.h>
24#include <linux/debugfs.h> 24#include <linux/debugfs.h>
25#include <linux/time.h>
25#include <asm/uaccess.h> 26#include <asm/uaccess.h>
26 27
27static DEFINE_PER_CPU(unsigned long long, blk_trace_cpu_offset) = { 0, }; 28static DEFINE_PER_CPU(unsigned long long, blk_trace_cpu_offset) = { 0, };
28static unsigned int blktrace_seq __read_mostly = 1; 29static unsigned int blktrace_seq __read_mostly = 1;
29 30
30/* 31/*
32 * Send out a notify message.
33 */
34static inline unsigned int trace_note(struct blk_trace *bt,
35 pid_t pid, int action,
36 const void *data, size_t len)
37{
38 struct blk_io_trace *t;
39 int cpu = smp_processor_id();
40
41 t = relay_reserve(bt->rchan, sizeof(*t) + len);
42 if (t == NULL)
43 return 0;
44
45 t->magic = BLK_IO_TRACE_MAGIC | BLK_IO_TRACE_VERSION;
46 t->time = sched_clock() - per_cpu(blk_trace_cpu_offset, cpu);
47 t->device = bt->dev;
48 t->action = action;
49 t->pid = pid;
50 t->cpu = cpu;
51 t->pdu_len = len;
52 memcpy((void *) t + sizeof(*t), data, len);
53 return blktrace_seq;
54}
55
56/*
31 * Send out a notify for this process, if we haven't done so since a trace 57 * Send out a notify for this process, if we haven't done so since a trace
32 * started 58 * started
33 */ 59 */
34static void trace_note_tsk(struct blk_trace *bt, struct task_struct *tsk) 60static void trace_note_tsk(struct blk_trace *bt, struct task_struct *tsk)
35{ 61{
36 struct blk_io_trace *t; 62 tsk->btrace_seq = trace_note(bt, tsk->pid,
63 BLK_TN_PROCESS,
64 tsk->comm, sizeof(tsk->comm));
65}
37 66
38 t = relay_reserve(bt->rchan, sizeof(*t) + sizeof(tsk->comm)); 67static void trace_note_time(struct blk_trace *bt)
39 if (t) { 68{
40 t->magic = BLK_IO_TRACE_MAGIC | BLK_IO_TRACE_VERSION; 69 struct timespec now;
41 t->device = bt->dev; 70 unsigned long flags;
42 t->action = BLK_TC_ACT(BLK_TC_NOTIFY); 71 u32 words[2];
43 t->pid = tsk->pid; 72
44 t->cpu = smp_processor_id(); 73 getnstimeofday(&now);
45 t->pdu_len = sizeof(tsk->comm); 74 words[0] = now.tv_sec;
46 memcpy((void *) t + sizeof(*t), tsk->comm, t->pdu_len); 75 words[1] = now.tv_nsec;
47 tsk->btrace_seq = blktrace_seq; 76
48 } 77 local_irq_save(flags);
78 trace_note(bt, 0, BLK_TN_TIMESTAMP, words, sizeof(words));
79 local_irq_restore(flags);
49} 80}
50 81
51static int act_log_check(struct blk_trace *bt, u32 what, sector_t sector, 82static int act_log_check(struct blk_trace *bt, u32 what, sector_t sector,
@@ -394,6 +425,8 @@ static int blk_trace_startstop(request_queue_t *q, int start)
394 blktrace_seq++; 425 blktrace_seq++;
395 smp_mb(); 426 smp_mb();
396 bt->trace_state = Blktrace_running; 427 bt->trace_state = Blktrace_running;
428
429 trace_note_time(bt);
397 ret = 0; 430 ret = 0;
398 } 431 }
399 } else { 432 } else {
diff --git a/block/cfq-iosched.c b/block/cfq-iosched.c
index d3d76136f5..e9019ed39b 100644
--- a/block/cfq-iosched.c
+++ b/block/cfq-iosched.c
@@ -456,6 +456,9 @@ static void cfq_add_rq_rb(struct request *rq)
456 */ 456 */
457 while ((__alias = elv_rb_add(&cfqq->sort_list, rq)) != NULL) 457 while ((__alias = elv_rb_add(&cfqq->sort_list, rq)) != NULL)
458 cfq_dispatch_insert(cfqd->queue, __alias); 458 cfq_dispatch_insert(cfqd->queue, __alias);
459
460 if (!cfq_cfqq_on_rr(cfqq))
461 cfq_add_cfqq_rr(cfqd, cfqq);
459} 462}
460 463
461static inline void 464static inline void
@@ -1215,11 +1218,12 @@ static inline void changed_ioprio(struct cfq_io_context *cic)
1215{ 1218{
1216 struct cfq_data *cfqd = cic->key; 1219 struct cfq_data *cfqd = cic->key;
1217 struct cfq_queue *cfqq; 1220 struct cfq_queue *cfqq;
1221 unsigned long flags;
1218 1222
1219 if (unlikely(!cfqd)) 1223 if (unlikely(!cfqd))
1220 return; 1224 return;
1221 1225
1222 spin_lock(cfqd->queue->queue_lock); 1226 spin_lock_irqsave(cfqd->queue->queue_lock, flags);
1223 1227
1224 cfqq = cic->cfqq[ASYNC]; 1228 cfqq = cic->cfqq[ASYNC];
1225 if (cfqq) { 1229 if (cfqq) {
@@ -1236,7 +1240,7 @@ static inline void changed_ioprio(struct cfq_io_context *cic)
1236 if (cfqq) 1240 if (cfqq)
1237 cfq_mark_cfqq_prio_changed(cfqq); 1241 cfq_mark_cfqq_prio_changed(cfqq);
1238 1242
1239 spin_unlock(cfqd->queue->queue_lock); 1243 spin_unlock_irqrestore(cfqd->queue->queue_lock, flags);
1240} 1244}
1241 1245
1242static void cfq_ioc_set_ioprio(struct io_context *ioc) 1246static void cfq_ioc_set_ioprio(struct io_context *ioc)
@@ -1362,6 +1366,7 @@ cfq_cic_link(struct cfq_data *cfqd, struct io_context *ioc,
1362 struct rb_node **p; 1366 struct rb_node **p;
1363 struct rb_node *parent; 1367 struct rb_node *parent;
1364 struct cfq_io_context *__cic; 1368 struct cfq_io_context *__cic;
1369 unsigned long flags;
1365 void *k; 1370 void *k;
1366 1371
1367 cic->ioc = ioc; 1372 cic->ioc = ioc;
@@ -1391,9 +1396,9 @@ restart:
1391 rb_link_node(&cic->rb_node, parent, p); 1396 rb_link_node(&cic->rb_node, parent, p);
1392 rb_insert_color(&cic->rb_node, &ioc->cic_root); 1397 rb_insert_color(&cic->rb_node, &ioc->cic_root);
1393 1398
1394 spin_lock_irq(cfqd->queue->queue_lock); 1399 spin_lock_irqsave(cfqd->queue->queue_lock, flags);
1395 list_add(&cic->queue_list, &cfqd->cic_list); 1400 list_add(&cic->queue_list, &cfqd->cic_list);
1396 spin_unlock_irq(cfqd->queue->queue_lock); 1401 spin_unlock_irqrestore(cfqd->queue->queue_lock, flags);
1397} 1402}
1398 1403
1399/* 1404/*
@@ -1459,8 +1464,7 @@ cfq_update_io_thinktime(struct cfq_data *cfqd, struct cfq_io_context *cic)
1459} 1464}
1460 1465
1461static void 1466static void
1462cfq_update_io_seektime(struct cfq_data *cfqd, struct cfq_io_context *cic, 1467cfq_update_io_seektime(struct cfq_io_context *cic, struct request *rq)
1463 struct request *rq)
1464{ 1468{
1465 sector_t sdist; 1469 sector_t sdist;
1466 u64 total; 1470 u64 total;
@@ -1612,7 +1616,7 @@ cfq_rq_enqueued(struct cfq_data *cfqd, struct cfq_queue *cfqq,
1612 } 1616 }
1613 1617
1614 cfq_update_io_thinktime(cfqd, cic); 1618 cfq_update_io_thinktime(cfqd, cic);
1615 cfq_update_io_seektime(cfqd, cic, rq); 1619 cfq_update_io_seektime(cic, rq);
1616 cfq_update_idle_window(cfqd, cfqq, cic); 1620 cfq_update_idle_window(cfqd, cfqq, cic);
1617 1621
1618 cic->last_queue = jiffies; 1622 cic->last_queue = jiffies;
@@ -1650,9 +1654,6 @@ static void cfq_insert_request(request_queue_t *q, struct request *rq)
1650 1654
1651 cfq_add_rq_rb(rq); 1655 cfq_add_rq_rb(rq);
1652 1656
1653 if (!cfq_cfqq_on_rr(cfqq))
1654 cfq_add_cfqq_rr(cfqd, cfqq);
1655
1656 list_add_tail(&rq->queuelist, &cfqq->fifo); 1657 list_add_tail(&rq->queuelist, &cfqq->fifo);
1657 1658
1658 cfq_rq_enqueued(cfqd, cfqq, rq); 1659 cfq_rq_enqueued(cfqd, cfqq, rq);
@@ -1768,7 +1769,7 @@ static int cfq_may_queue(request_queue_t *q, int rw)
1768/* 1769/*
1769 * queue lock held here 1770 * queue lock held here
1770 */ 1771 */
1771static void cfq_put_request(request_queue_t *q, struct request *rq) 1772static void cfq_put_request(struct request *rq)
1772{ 1773{
1773 struct cfq_queue *cfqq = RQ_CFQQ(rq); 1774 struct cfq_queue *cfqq = RQ_CFQQ(rq);
1774 1775
@@ -1949,7 +1950,7 @@ static void cfq_exit_queue(elevator_t *e)
1949 kfree(cfqd); 1950 kfree(cfqd);
1950} 1951}
1951 1952
1952static void *cfq_init_queue(request_queue_t *q, elevator_t *e) 1953static void *cfq_init_queue(request_queue_t *q)
1953{ 1954{
1954 struct cfq_data *cfqd; 1955 struct cfq_data *cfqd;
1955 int i; 1956 int i;
diff --git a/block/deadline-iosched.c b/block/deadline-iosched.c
index b7c5b34cb7..6d673e938d 100644
--- a/block/deadline-iosched.c
+++ b/block/deadline-iosched.c
@@ -356,7 +356,7 @@ static void deadline_exit_queue(elevator_t *e)
356/* 356/*
357 * initialize elevator private data (deadline_data). 357 * initialize elevator private data (deadline_data).
358 */ 358 */
359static void *deadline_init_queue(request_queue_t *q, elevator_t *e) 359static void *deadline_init_queue(request_queue_t *q)
360{ 360{
361 struct deadline_data *dd; 361 struct deadline_data *dd;
362 362
diff --git a/block/elevator.c b/block/elevator.c
index 8ccd163254..c0063f345c 100644
--- a/block/elevator.c
+++ b/block/elevator.c
@@ -129,7 +129,7 @@ static struct elevator_type *elevator_get(const char *name)
129 129
130static void *elevator_init_queue(request_queue_t *q, struct elevator_queue *eq) 130static void *elevator_init_queue(request_queue_t *q, struct elevator_queue *eq)
131{ 131{
132 return eq->ops->elevator_init_fn(q, eq); 132 return eq->ops->elevator_init_fn(q);
133} 133}
134 134
135static void elevator_attach(request_queue_t *q, struct elevator_queue *eq, 135static void elevator_attach(request_queue_t *q, struct elevator_queue *eq,
@@ -810,7 +810,7 @@ void elv_put_request(request_queue_t *q, struct request *rq)
810 elevator_t *e = q->elevator; 810 elevator_t *e = q->elevator;
811 811
812 if (e->ops->elevator_put_req_fn) 812 if (e->ops->elevator_put_req_fn)
813 e->ops->elevator_put_req_fn(q, rq); 813 e->ops->elevator_put_req_fn(rq);
814} 814}
815 815
816int elv_may_queue(request_queue_t *q, int rw) 816int elv_may_queue(request_queue_t *q, int rw)
diff --git a/block/ll_rw_blk.c b/block/ll_rw_blk.c
index c847e17e5c..0f82e12f7b 100644
--- a/block/ll_rw_blk.c
+++ b/block/ll_rw_blk.c
@@ -56,11 +56,6 @@ static kmem_cache_t *requestq_cachep;
56 */ 56 */
57static kmem_cache_t *iocontext_cachep; 57static kmem_cache_t *iocontext_cachep;
58 58
59static wait_queue_head_t congestion_wqh[2] = {
60 __WAIT_QUEUE_HEAD_INITIALIZER(congestion_wqh[0]),
61 __WAIT_QUEUE_HEAD_INITIALIZER(congestion_wqh[1])
62 };
63
64/* 59/*
65 * Controlling structure to kblockd 60 * Controlling structure to kblockd
66 */ 61 */
@@ -112,35 +107,6 @@ static void blk_queue_congestion_threshold(struct request_queue *q)
112 q->nr_congestion_off = nr; 107 q->nr_congestion_off = nr;
113} 108}
114 109
115/*
116 * A queue has just exitted congestion. Note this in the global counter of
117 * congested queues, and wake up anyone who was waiting for requests to be
118 * put back.
119 */
120static void clear_queue_congested(request_queue_t *q, int rw)
121{
122 enum bdi_state bit;
123 wait_queue_head_t *wqh = &congestion_wqh[rw];
124
125 bit = (rw == WRITE) ? BDI_write_congested : BDI_read_congested;
126 clear_bit(bit, &q->backing_dev_info.state);
127 smp_mb__after_clear_bit();
128 if (waitqueue_active(wqh))
129 wake_up(wqh);
130}
131
132/*
133 * A queue has just entered congestion. Flag that in the queue's VM-visible
134 * state flags and increment the global gounter of congested queues.
135 */
136static void set_queue_congested(request_queue_t *q, int rw)
137{
138 enum bdi_state bit;
139
140 bit = (rw == WRITE) ? BDI_write_congested : BDI_read_congested;
141 set_bit(bit, &q->backing_dev_info.state);
142}
143
144/** 110/**
145 * blk_get_backing_dev_info - get the address of a queue's backing_dev_info 111 * blk_get_backing_dev_info - get the address of a queue's backing_dev_info
146 * @bdev: device 112 * @bdev: device
@@ -159,7 +125,6 @@ struct backing_dev_info *blk_get_backing_dev_info(struct block_device *bdev)
159 ret = &q->backing_dev_info; 125 ret = &q->backing_dev_info;
160 return ret; 126 return ret;
161} 127}
162
163EXPORT_SYMBOL(blk_get_backing_dev_info); 128EXPORT_SYMBOL(blk_get_backing_dev_info);
164 129
165void blk_queue_activity_fn(request_queue_t *q, activity_fn *fn, void *data) 130void blk_queue_activity_fn(request_queue_t *q, activity_fn *fn, void *data)
@@ -167,7 +132,6 @@ void blk_queue_activity_fn(request_queue_t *q, activity_fn *fn, void *data)
167 q->activity_fn = fn; 132 q->activity_fn = fn;
168 q->activity_data = data; 133 q->activity_data = data;
169} 134}
170
171EXPORT_SYMBOL(blk_queue_activity_fn); 135EXPORT_SYMBOL(blk_queue_activity_fn);
172 136
173/** 137/**
@@ -2067,7 +2031,7 @@ static void __freed_request(request_queue_t *q, int rw)
2067 struct request_list *rl = &q->rq; 2031 struct request_list *rl = &q->rq;
2068 2032
2069 if (rl->count[rw] < queue_congestion_off_threshold(q)) 2033 if (rl->count[rw] < queue_congestion_off_threshold(q))
2070 clear_queue_congested(q, rw); 2034 blk_clear_queue_congested(q, rw);
2071 2035
2072 if (rl->count[rw] + 1 <= q->nr_requests) { 2036 if (rl->count[rw] + 1 <= q->nr_requests) {
2073 if (waitqueue_active(&rl->wait[rw])) 2037 if (waitqueue_active(&rl->wait[rw]))
@@ -2137,7 +2101,7 @@ static struct request *get_request(request_queue_t *q, int rw, struct bio *bio,
2137 } 2101 }
2138 } 2102 }
2139 } 2103 }
2140 set_queue_congested(q, rw); 2104 blk_set_queue_congested(q, rw);
2141 } 2105 }
2142 2106
2143 /* 2107 /*
@@ -2358,6 +2322,84 @@ void blk_insert_request(request_queue_t *q, struct request *rq,
2358 2322
2359EXPORT_SYMBOL(blk_insert_request); 2323EXPORT_SYMBOL(blk_insert_request);
2360 2324
2325static int __blk_rq_unmap_user(struct bio *bio)
2326{
2327 int ret = 0;
2328
2329 if (bio) {
2330 if (bio_flagged(bio, BIO_USER_MAPPED))
2331 bio_unmap_user(bio);
2332 else
2333 ret = bio_uncopy_user(bio);
2334 }
2335
2336 return ret;
2337}
2338
2339static int __blk_rq_map_user(request_queue_t *q, struct request *rq,
2340 void __user *ubuf, unsigned int len)
2341{
2342 unsigned long uaddr;
2343 struct bio *bio, *orig_bio;
2344 int reading, ret;
2345
2346 reading = rq_data_dir(rq) == READ;
2347
2348 /*
2349 * if alignment requirement is satisfied, map in user pages for
2350 * direct dma. else, set up kernel bounce buffers
2351 */
2352 uaddr = (unsigned long) ubuf;
2353 if (!(uaddr & queue_dma_alignment(q)) && !(len & queue_dma_alignment(q)))
2354 bio = bio_map_user(q, NULL, uaddr, len, reading);
2355 else
2356 bio = bio_copy_user(q, uaddr, len, reading);
2357
2358 if (IS_ERR(bio)) {
2359 return PTR_ERR(bio);
2360 }
2361
2362 orig_bio = bio;
2363 blk_queue_bounce(q, &bio);
2364 /*
2365 * We link the bounce buffer in and could have to traverse it
2366 * later so we have to get a ref to prevent it from being freed
2367 */
2368 bio_get(bio);
2369
2370 /*
2371 * for most (all? don't know of any) queues we could
2372 * skip grabbing the queue lock here. only drivers with
2373 * funky private ->back_merge_fn() function could be
2374 * problematic.
2375 */
2376 spin_lock_irq(q->queue_lock);
2377 if (!rq->bio)
2378 blk_rq_bio_prep(q, rq, bio);
2379 else if (!q->back_merge_fn(q, rq, bio)) {
2380 ret = -EINVAL;
2381 spin_unlock_irq(q->queue_lock);
2382 goto unmap_bio;
2383 } else {
2384 rq->biotail->bi_next = bio;
2385 rq->biotail = bio;
2386
2387 rq->nr_sectors += bio_sectors(bio);
2388 rq->hard_nr_sectors = rq->nr_sectors;
2389 rq->data_len += bio->bi_size;
2390 }
2391 spin_unlock_irq(q->queue_lock);
2392
2393 return bio->bi_size;
2394
2395unmap_bio:
2396 /* if it was boucned we must call the end io function */
2397 bio_endio(bio, bio->bi_size, 0);
2398 __blk_rq_unmap_user(orig_bio);
2399 bio_put(bio);
2400 return ret;
2401}
2402
2361/** 2403/**
2362 * blk_rq_map_user - map user data to a request, for REQ_BLOCK_PC usage 2404 * blk_rq_map_user - map user data to a request, for REQ_BLOCK_PC usage
2363 * @q: request queue where request should be inserted 2405 * @q: request queue where request should be inserted
@@ -2379,42 +2421,44 @@ EXPORT_SYMBOL(blk_insert_request);
2379 * unmapping. 2421 * unmapping.
2380 */ 2422 */
2381int blk_rq_map_user(request_queue_t *q, struct request *rq, void __user *ubuf, 2423int blk_rq_map_user(request_queue_t *q, struct request *rq, void __user *ubuf,
2382 unsigned int len) 2424 unsigned long len)
2383{ 2425{
2384 unsigned long uaddr; 2426 unsigned long bytes_read = 0;
2385 struct bio *bio; 2427 int ret;
2386 int reading;
2387 2428
2388 if (len > (q->max_hw_sectors << 9)) 2429 if (len > (q->max_hw_sectors << 9))
2389 return -EINVAL; 2430 return -EINVAL;
2390 if (!len || !ubuf) 2431 if (!len || !ubuf)
2391 return -EINVAL; 2432 return -EINVAL;
2392 2433
2393 reading = rq_data_dir(rq) == READ; 2434 while (bytes_read != len) {
2435 unsigned long map_len, end, start;
2394 2436
2395 /* 2437 map_len = min_t(unsigned long, len - bytes_read, BIO_MAX_SIZE);
2396 * if alignment requirement is satisfied, map in user pages for 2438 end = ((unsigned long)ubuf + map_len + PAGE_SIZE - 1)
2397 * direct dma. else, set up kernel bounce buffers 2439 >> PAGE_SHIFT;
2398 */ 2440 start = (unsigned long)ubuf >> PAGE_SHIFT;
2399 uaddr = (unsigned long) ubuf;
2400 if (!(uaddr & queue_dma_alignment(q)) && !(len & queue_dma_alignment(q)))
2401 bio = bio_map_user(q, NULL, uaddr, len, reading);
2402 else
2403 bio = bio_copy_user(q, uaddr, len, reading);
2404 2441
2405 if (!IS_ERR(bio)) { 2442 /*
2406 rq->bio = rq->biotail = bio; 2443 * A bad offset could cause us to require BIO_MAX_PAGES + 1
2407 blk_rq_bio_prep(q, rq, bio); 2444 * pages. If this happens we just lower the requested
2445 * mapping len by a page so that we can fit
2446 */
2447 if (end - start > BIO_MAX_PAGES)
2448 map_len -= PAGE_SIZE;
2408 2449
2409 rq->buffer = rq->data = NULL; 2450 ret = __blk_rq_map_user(q, rq, ubuf, map_len);
2410 rq->data_len = len; 2451 if (ret < 0)
2411 return 0; 2452 goto unmap_rq;
2453 bytes_read += ret;
2454 ubuf += ret;
2412 } 2455 }
2413 2456
2414 /* 2457 rq->buffer = rq->data = NULL;
2415 * bio is the err-ptr 2458 return 0;
2416 */ 2459unmap_rq:
2417 return PTR_ERR(bio); 2460 blk_rq_unmap_user(rq);
2461 return ret;
2418} 2462}
2419 2463
2420EXPORT_SYMBOL(blk_rq_map_user); 2464EXPORT_SYMBOL(blk_rq_map_user);
@@ -2440,7 +2484,7 @@ EXPORT_SYMBOL(blk_rq_map_user);
2440 * unmapping. 2484 * unmapping.
2441 */ 2485 */
2442int blk_rq_map_user_iov(request_queue_t *q, struct request *rq, 2486int blk_rq_map_user_iov(request_queue_t *q, struct request *rq,
2443 struct sg_iovec *iov, int iov_count) 2487 struct sg_iovec *iov, int iov_count, unsigned int len)
2444{ 2488{
2445 struct bio *bio; 2489 struct bio *bio;
2446 2490
@@ -2454,10 +2498,15 @@ int blk_rq_map_user_iov(request_queue_t *q, struct request *rq,
2454 if (IS_ERR(bio)) 2498 if (IS_ERR(bio))
2455 return PTR_ERR(bio); 2499 return PTR_ERR(bio);
2456 2500
2457 rq->bio = rq->biotail = bio; 2501 if (bio->bi_size != len) {
2502 bio_endio(bio, bio->bi_size, 0);
2503 bio_unmap_user(bio);
2504 return -EINVAL;
2505 }
2506
2507 bio_get(bio);
2458 blk_rq_bio_prep(q, rq, bio); 2508 blk_rq_bio_prep(q, rq, bio);
2459 rq->buffer = rq->data = NULL; 2509 rq->buffer = rq->data = NULL;
2460 rq->data_len = bio->bi_size;
2461 return 0; 2510 return 0;
2462} 2511}
2463 2512
@@ -2465,23 +2514,26 @@ EXPORT_SYMBOL(blk_rq_map_user_iov);
2465 2514
2466/** 2515/**
2467 * blk_rq_unmap_user - unmap a request with user data 2516 * blk_rq_unmap_user - unmap a request with user data
2468 * @bio: bio to be unmapped 2517 * @rq: rq to be unmapped
2469 * @ulen: length of user buffer
2470 * 2518 *
2471 * Description: 2519 * Description:
2472 * Unmap a bio previously mapped by blk_rq_map_user(). 2520 * Unmap a rq previously mapped by blk_rq_map_user().
2521 * rq->bio must be set to the original head of the request.
2473 */ 2522 */
2474int blk_rq_unmap_user(struct bio *bio, unsigned int ulen) 2523int blk_rq_unmap_user(struct request *rq)
2475{ 2524{
2476 int ret = 0; 2525 struct bio *bio, *mapped_bio;
2477 2526
2478 if (bio) { 2527 while ((bio = rq->bio)) {
2479 if (bio_flagged(bio, BIO_USER_MAPPED)) 2528 if (bio_flagged(bio, BIO_BOUNCED))
2480 bio_unmap_user(bio); 2529 mapped_bio = bio->bi_private;
2481 else 2530 else
2482 ret = bio_uncopy_user(bio); 2531 mapped_bio = bio;
2483 }
2484 2532
2533 __blk_rq_unmap_user(mapped_bio);
2534 rq->bio = bio->bi_next;
2535 bio_put(bio);
2536 }
2485 return 0; 2537 return 0;
2486} 2538}
2487 2539
@@ -2512,11 +2564,8 @@ int blk_rq_map_kern(request_queue_t *q, struct request *rq, void *kbuf,
2512 if (rq_data_dir(rq) == WRITE) 2564 if (rq_data_dir(rq) == WRITE)
2513 bio->bi_rw |= (1 << BIO_RW); 2565 bio->bi_rw |= (1 << BIO_RW);
2514 2566
2515 rq->bio = rq->biotail = bio;
2516 blk_rq_bio_prep(q, rq, bio); 2567 blk_rq_bio_prep(q, rq, bio);
2517
2518 rq->buffer = rq->data = NULL; 2568 rq->buffer = rq->data = NULL;
2519 rq->data_len = len;
2520 return 0; 2569 return 0;
2521} 2570}
2522 2571
@@ -2755,41 +2804,6 @@ void blk_end_sync_rq(struct request *rq, int error)
2755} 2804}
2756EXPORT_SYMBOL(blk_end_sync_rq); 2805EXPORT_SYMBOL(blk_end_sync_rq);
2757 2806
2758/**
2759 * blk_congestion_wait - wait for a queue to become uncongested
2760 * @rw: READ or WRITE
2761 * @timeout: timeout in jiffies
2762 *
2763 * Waits for up to @timeout jiffies for a queue (any queue) to exit congestion.
2764 * If no queues are congested then just wait for the next request to be
2765 * returned.
2766 */
2767long blk_congestion_wait(int rw, long timeout)
2768{
2769 long ret;
2770 DEFINE_WAIT(wait);
2771 wait_queue_head_t *wqh = &congestion_wqh[rw];
2772
2773 prepare_to_wait(wqh, &wait, TASK_UNINTERRUPTIBLE);
2774 ret = io_schedule_timeout(timeout);
2775 finish_wait(wqh, &wait);
2776 return ret;
2777}
2778
2779EXPORT_SYMBOL(blk_congestion_wait);
2780
2781/**
2782 * blk_congestion_end - wake up sleepers on a congestion queue
2783 * @rw: READ or WRITE
2784 */
2785void blk_congestion_end(int rw)
2786{
2787 wait_queue_head_t *wqh = &congestion_wqh[rw];
2788
2789 if (waitqueue_active(wqh))
2790 wake_up(wqh);
2791}
2792
2793/* 2807/*
2794 * Has to be called with the request spinlock acquired 2808 * Has to be called with the request spinlock acquired
2795 */ 2809 */
@@ -3070,6 +3084,7 @@ void generic_make_request(struct bio *bio)
3070{ 3084{
3071 request_queue_t *q; 3085 request_queue_t *q;
3072 sector_t maxsector; 3086 sector_t maxsector;
3087 sector_t old_sector;
3073 int ret, nr_sectors = bio_sectors(bio); 3088 int ret, nr_sectors = bio_sectors(bio);
3074 dev_t old_dev; 3089 dev_t old_dev;
3075 3090
@@ -3098,7 +3113,7 @@ void generic_make_request(struct bio *bio)
3098 * NOTE: we don't repeat the blk_size check for each new device. 3113 * NOTE: we don't repeat the blk_size check for each new device.
3099 * Stacking drivers are expected to know what they are doing. 3114 * Stacking drivers are expected to know what they are doing.
3100 */ 3115 */
3101 maxsector = -1; 3116 old_sector = -1;
3102 old_dev = 0; 3117 old_dev = 0;
3103 do { 3118 do {
3104 char b[BDEVNAME_SIZE]; 3119 char b[BDEVNAME_SIZE];
@@ -3132,15 +3147,31 @@ end_io:
3132 */ 3147 */
3133 blk_partition_remap(bio); 3148 blk_partition_remap(bio);
3134 3149
3135 if (maxsector != -1) 3150 if (old_sector != -1)
3136 blk_add_trace_remap(q, bio, old_dev, bio->bi_sector, 3151 blk_add_trace_remap(q, bio, old_dev, bio->bi_sector,
3137 maxsector); 3152 old_sector);
3138 3153
3139 blk_add_trace_bio(q, bio, BLK_TA_QUEUE); 3154 blk_add_trace_bio(q, bio, BLK_TA_QUEUE);
3140 3155
3141 maxsector = bio->bi_sector; 3156 old_sector = bio->bi_sector;
3142 old_dev = bio->bi_bdev->bd_dev; 3157 old_dev = bio->bi_bdev->bd_dev;
3143 3158
3159 maxsector = bio->bi_bdev->bd_inode->i_size >> 9;
3160 if (maxsector) {
3161 sector_t sector = bio->bi_sector;
3162
3163 if (maxsector < nr_sectors ||
3164 maxsector - nr_sectors < sector) {
3165 /*
3166 * This may well happen - partitions are not
3167 * checked to make sure they are within the size
3168 * of the whole device.
3169 */
3170 handle_bad_sector(bio);
3171 goto end_io;
3172 }
3173 }
3174
3144 ret = q->make_request_fn(q, bio); 3175 ret = q->make_request_fn(q, bio);
3145 } while (ret); 3176 } while (ret);
3146} 3177}
@@ -3549,6 +3580,7 @@ void blk_rq_bio_prep(request_queue_t *q, struct request *rq, struct bio *bio)
3549 rq->hard_cur_sectors = rq->current_nr_sectors; 3580 rq->hard_cur_sectors = rq->current_nr_sectors;
3550 rq->hard_nr_sectors = rq->nr_sectors = bio_sectors(bio); 3581 rq->hard_nr_sectors = rq->nr_sectors = bio_sectors(bio);
3551 rq->buffer = bio_data(bio); 3582 rq->buffer = bio_data(bio);
3583 rq->data_len = bio->bi_size;
3552 3584
3553 rq->bio = rq->biotail = bio; 3585 rq->bio = rq->biotail = bio;
3554} 3586}
@@ -3765,14 +3797,14 @@ queue_requests_store(struct request_queue *q, const char *page, size_t count)
3765 blk_queue_congestion_threshold(q); 3797 blk_queue_congestion_threshold(q);
3766 3798
3767 if (rl->count[READ] >= queue_congestion_on_threshold(q)) 3799 if (rl->count[READ] >= queue_congestion_on_threshold(q))
3768 set_queue_congested(q, READ); 3800 blk_set_queue_congested(q, READ);
3769 else if (rl->count[READ] < queue_congestion_off_threshold(q)) 3801 else if (rl->count[READ] < queue_congestion_off_threshold(q))
3770 clear_queue_congested(q, READ); 3802 blk_clear_queue_congested(q, READ);
3771 3803
3772 if (rl->count[WRITE] >= queue_congestion_on_threshold(q)) 3804 if (rl->count[WRITE] >= queue_congestion_on_threshold(q))
3773 set_queue_congested(q, WRITE); 3805 blk_set_queue_congested(q, WRITE);
3774 else if (rl->count[WRITE] < queue_congestion_off_threshold(q)) 3806 else if (rl->count[WRITE] < queue_congestion_off_threshold(q))
3775 clear_queue_congested(q, WRITE); 3807 blk_clear_queue_congested(q, WRITE);
3776 3808
3777 if (rl->count[READ] >= q->nr_requests) { 3809 if (rl->count[READ] >= q->nr_requests) {
3778 blk_set_queue_full(q, READ); 3810 blk_set_queue_full(q, READ);
diff --git a/block/noop-iosched.c b/block/noop-iosched.c
index 79af431794..1c3de2b9a6 100644
--- a/block/noop-iosched.c
+++ b/block/noop-iosched.c
@@ -65,7 +65,7 @@ noop_latter_request(request_queue_t *q, struct request *rq)
65 return list_entry(rq->queuelist.next, struct request, queuelist); 65 return list_entry(rq->queuelist.next, struct request, queuelist);
66} 66}
67 67
68static void *noop_init_queue(request_queue_t *q, elevator_t *e) 68static void *noop_init_queue(request_queue_t *q)
69{ 69{
70 struct noop_data *nd; 70 struct noop_data *nd;
71 71
diff --git a/block/scsi_ioctl.c b/block/scsi_ioctl.c
index 2dc326421a..5493c2fbba 100644
--- a/block/scsi_ioctl.c
+++ b/block/scsi_ioctl.c
@@ -226,7 +226,6 @@ static int sg_io(struct file *file, request_queue_t *q,
226 unsigned long start_time; 226 unsigned long start_time;
227 int writing = 0, ret = 0; 227 int writing = 0, ret = 0;
228 struct request *rq; 228 struct request *rq;
229 struct bio *bio;
230 char sense[SCSI_SENSE_BUFFERSIZE]; 229 char sense[SCSI_SENSE_BUFFERSIZE];
231 unsigned char cmd[BLK_MAX_CDB]; 230 unsigned char cmd[BLK_MAX_CDB];
232 231
@@ -246,10 +245,10 @@ static int sg_io(struct file *file, request_queue_t *q,
246 switch (hdr->dxfer_direction) { 245 switch (hdr->dxfer_direction) {
247 default: 246 default:
248 return -EINVAL; 247 return -EINVAL;
249 case SG_DXFER_TO_FROM_DEV:
250 case SG_DXFER_TO_DEV: 248 case SG_DXFER_TO_DEV:
251 writing = 1; 249 writing = 1;
252 break; 250 break;
251 case SG_DXFER_TO_FROM_DEV:
253 case SG_DXFER_FROM_DEV: 252 case SG_DXFER_FROM_DEV:
254 break; 253 break;
255 } 254 }
@@ -258,44 +257,18 @@ static int sg_io(struct file *file, request_queue_t *q,
258 if (!rq) 257 if (!rq)
259 return -ENOMEM; 258 return -ENOMEM;
260 259
261 if (hdr->iovec_count) {
262 const int size = sizeof(struct sg_iovec) * hdr->iovec_count;
263 struct sg_iovec *iov;
264
265 iov = kmalloc(size, GFP_KERNEL);
266 if (!iov) {
267 ret = -ENOMEM;
268 goto out;
269 }
270
271 if (copy_from_user(iov, hdr->dxferp, size)) {
272 kfree(iov);
273 ret = -EFAULT;
274 goto out;
275 }
276
277 ret = blk_rq_map_user_iov(q, rq, iov, hdr->iovec_count);
278 kfree(iov);
279 } else if (hdr->dxfer_len)
280 ret = blk_rq_map_user(q, rq, hdr->dxferp, hdr->dxfer_len);
281
282 if (ret)
283 goto out;
284
285 /* 260 /*
286 * fill in request structure 261 * fill in request structure
287 */ 262 */
288 rq->cmd_len = hdr->cmd_len; 263 rq->cmd_len = hdr->cmd_len;
264 memset(rq->cmd, 0, BLK_MAX_CDB); /* ATAPI hates garbage after CDB */
289 memcpy(rq->cmd, cmd, hdr->cmd_len); 265 memcpy(rq->cmd, cmd, hdr->cmd_len);
290 if (sizeof(rq->cmd) != hdr->cmd_len)
291 memset(rq->cmd + hdr->cmd_len, 0, sizeof(rq->cmd) - hdr->cmd_len);
292 266
293 memset(sense, 0, sizeof(sense)); 267 memset(sense, 0, sizeof(sense));
294 rq->sense = sense; 268 rq->sense = sense;
295 rq->sense_len = 0; 269 rq->sense_len = 0;
296 270
297 rq->cmd_type = REQ_TYPE_BLOCK_PC; 271 rq->cmd_type = REQ_TYPE_BLOCK_PC;
298 bio = rq->bio;
299 272
300 /* 273 /*
301 * bounce this after holding a reference to the original bio, it's 274 * bounce this after holding a reference to the original bio, it's
@@ -310,6 +283,31 @@ static int sg_io(struct file *file, request_queue_t *q,
310 if (!rq->timeout) 283 if (!rq->timeout)
311 rq->timeout = BLK_DEFAULT_TIMEOUT; 284 rq->timeout = BLK_DEFAULT_TIMEOUT;
312 285
286 if (hdr->iovec_count) {
287 const int size = sizeof(struct sg_iovec) * hdr->iovec_count;
288 struct sg_iovec *iov;
289
290 iov = kmalloc(size, GFP_KERNEL);
291 if (!iov) {
292 ret = -ENOMEM;
293 goto out;
294 }
295
296 if (copy_from_user(iov, hdr->dxferp, size)) {
297 kfree(iov);
298 ret = -EFAULT;
299 goto out;
300 }
301
302 ret = blk_rq_map_user_iov(q, rq, iov, hdr->iovec_count,
303 hdr->dxfer_len);
304 kfree(iov);
305 } else if (hdr->dxfer_len)
306 ret = blk_rq_map_user(q, rq, hdr->dxferp, hdr->dxfer_len);
307
308 if (ret)
309 goto out;
310
313 rq->retries = 0; 311 rq->retries = 0;
314 312
315 start_time = jiffies; 313 start_time = jiffies;
@@ -340,7 +338,7 @@ static int sg_io(struct file *file, request_queue_t *q,
340 hdr->sb_len_wr = len; 338 hdr->sb_len_wr = len;
341 } 339 }
342 340
343 if (blk_rq_unmap_user(bio, hdr->dxfer_len)) 341 if (blk_rq_unmap_user(rq))
344 ret = -EFAULT; 342 ret = -EFAULT;
345 343
346 /* may not have succeeded, but output values written to control 344 /* may not have succeeded, but output values written to control