aboutsummaryrefslogtreecommitdiffstats
path: root/block
diff options
context:
space:
mode:
Diffstat (limited to 'block')
-rw-r--r--block/blk-core.c265
-rw-r--r--block/cfq-iosched.c7
-rw-r--r--block/deadline-iosched.c2
-rw-r--r--block/elevator.c26
4 files changed, 225 insertions, 75 deletions
diff --git a/block/blk-core.c b/block/blk-core.c
index 074b758efc42..f224d1793ee5 100644
--- a/block/blk-core.c
+++ b/block/blk-core.c
@@ -30,6 +30,7 @@
30#include <linux/list_sort.h> 30#include <linux/list_sort.h>
31#include <linux/delay.h> 31#include <linux/delay.h>
32#include <linux/ratelimit.h> 32#include <linux/ratelimit.h>
33#include <linux/pm_runtime.h>
33 34
34#define CREATE_TRACE_POINTS 35#define CREATE_TRACE_POINTS
35#include <trace/events/block.h> 36#include <trace/events/block.h>
@@ -158,20 +159,10 @@ static void req_bio_endio(struct request *rq, struct bio *bio,
158 else if (!test_bit(BIO_UPTODATE, &bio->bi_flags)) 159 else if (!test_bit(BIO_UPTODATE, &bio->bi_flags))
159 error = -EIO; 160 error = -EIO;
160 161
161 if (unlikely(nbytes > bio->bi_size)) {
162 printk(KERN_ERR "%s: want %u bytes done, %u left\n",
163 __func__, nbytes, bio->bi_size);
164 nbytes = bio->bi_size;
165 }
166
167 if (unlikely(rq->cmd_flags & REQ_QUIET)) 162 if (unlikely(rq->cmd_flags & REQ_QUIET))
168 set_bit(BIO_QUIET, &bio->bi_flags); 163 set_bit(BIO_QUIET, &bio->bi_flags);
169 164
170 bio->bi_size -= nbytes; 165 bio_advance(bio, nbytes);
171 bio->bi_sector += (nbytes >> 9);
172
173 if (bio_integrity(bio))
174 bio_integrity_advance(bio, nbytes);
175 166
176 /* don't actually finish bio if it's part of flush sequence */ 167 /* don't actually finish bio if it's part of flush sequence */
177 if (bio->bi_size == 0 && !(rq->cmd_flags & REQ_FLUSH_SEQ)) 168 if (bio->bi_size == 0 && !(rq->cmd_flags & REQ_FLUSH_SEQ))
@@ -1263,6 +1254,16 @@ void part_round_stats(int cpu, struct hd_struct *part)
1263} 1254}
1264EXPORT_SYMBOL_GPL(part_round_stats); 1255EXPORT_SYMBOL_GPL(part_round_stats);
1265 1256
1257#ifdef CONFIG_PM_RUNTIME
1258static void blk_pm_put_request(struct request *rq)
1259{
1260 if (rq->q->dev && !(rq->cmd_flags & REQ_PM) && !--rq->q->nr_pending)
1261 pm_runtime_mark_last_busy(rq->q->dev);
1262}
1263#else
1264static inline void blk_pm_put_request(struct request *rq) {}
1265#endif
1266
1266/* 1267/*
1267 * queue lock must be held 1268 * queue lock must be held
1268 */ 1269 */
@@ -1273,6 +1274,8 @@ void __blk_put_request(struct request_queue *q, struct request *req)
1273 if (unlikely(--req->ref_count)) 1274 if (unlikely(--req->ref_count))
1274 return; 1275 return;
1275 1276
1277 blk_pm_put_request(req);
1278
1276 elv_completed_request(q, req); 1279 elv_completed_request(q, req);
1277 1280
1278 /* this is a bio leak */ 1281 /* this is a bio leak */
@@ -1596,7 +1599,7 @@ static void handle_bad_sector(struct bio *bio)
1596 printk(KERN_INFO "%s: rw=%ld, want=%Lu, limit=%Lu\n", 1599 printk(KERN_INFO "%s: rw=%ld, want=%Lu, limit=%Lu\n",
1597 bdevname(bio->bi_bdev, b), 1600 bdevname(bio->bi_bdev, b),
1598 bio->bi_rw, 1601 bio->bi_rw,
1599 (unsigned long long)bio->bi_sector + bio_sectors(bio), 1602 (unsigned long long)bio_end_sector(bio),
1600 (long long)(i_size_read(bio->bi_bdev->bd_inode) >> 9)); 1603 (long long)(i_size_read(bio->bi_bdev->bd_inode) >> 9));
1601 1604
1602 set_bit(BIO_EOF, &bio->bi_flags); 1605 set_bit(BIO_EOF, &bio->bi_flags);
@@ -2052,6 +2055,28 @@ static void blk_account_io_done(struct request *req)
2052 } 2055 }
2053} 2056}
2054 2057
2058#ifdef CONFIG_PM_RUNTIME
2059/*
2060 * Don't process normal requests when queue is suspended
2061 * or in the process of suspending/resuming
2062 */
2063static struct request *blk_pm_peek_request(struct request_queue *q,
2064 struct request *rq)
2065{
2066 if (q->dev && (q->rpm_status == RPM_SUSPENDED ||
2067 (q->rpm_status != RPM_ACTIVE && !(rq->cmd_flags & REQ_PM))))
2068 return NULL;
2069 else
2070 return rq;
2071}
2072#else
2073static inline struct request *blk_pm_peek_request(struct request_queue *q,
2074 struct request *rq)
2075{
2076 return rq;
2077}
2078#endif
2079
2055/** 2080/**
2056 * blk_peek_request - peek at the top of a request queue 2081 * blk_peek_request - peek at the top of a request queue
2057 * @q: request queue to peek at 2082 * @q: request queue to peek at
@@ -2074,6 +2099,11 @@ struct request *blk_peek_request(struct request_queue *q)
2074 int ret; 2099 int ret;
2075 2100
2076 while ((rq = __elv_next_request(q)) != NULL) { 2101 while ((rq = __elv_next_request(q)) != NULL) {
2102
2103 rq = blk_pm_peek_request(q, rq);
2104 if (!rq)
2105 break;
2106
2077 if (!(rq->cmd_flags & REQ_STARTED)) { 2107 if (!(rq->cmd_flags & REQ_STARTED)) {
2078 /* 2108 /*
2079 * This is the first time the device driver 2109 * This is the first time the device driver
@@ -2252,8 +2282,7 @@ EXPORT_SYMBOL(blk_fetch_request);
2252 **/ 2282 **/
2253bool blk_update_request(struct request *req, int error, unsigned int nr_bytes) 2283bool blk_update_request(struct request *req, int error, unsigned int nr_bytes)
2254{ 2284{
2255 int total_bytes, bio_nbytes, next_idx = 0; 2285 int total_bytes;
2256 struct bio *bio;
2257 2286
2258 if (!req->bio) 2287 if (!req->bio)
2259 return false; 2288 return false;
@@ -2299,56 +2328,21 @@ bool blk_update_request(struct request *req, int error, unsigned int nr_bytes)
2299 2328
2300 blk_account_io_completion(req, nr_bytes); 2329 blk_account_io_completion(req, nr_bytes);
2301 2330
2302 total_bytes = bio_nbytes = 0; 2331 total_bytes = 0;
2303 while ((bio = req->bio) != NULL) { 2332 while (req->bio) {
2304 int nbytes; 2333 struct bio *bio = req->bio;
2334 unsigned bio_bytes = min(bio->bi_size, nr_bytes);
2305 2335
2306 if (nr_bytes >= bio->bi_size) { 2336 if (bio_bytes == bio->bi_size)
2307 req->bio = bio->bi_next; 2337 req->bio = bio->bi_next;
2308 nbytes = bio->bi_size;
2309 req_bio_endio(req, bio, nbytes, error);
2310 next_idx = 0;
2311 bio_nbytes = 0;
2312 } else {
2313 int idx = bio->bi_idx + next_idx;
2314 2338
2315 if (unlikely(idx >= bio->bi_vcnt)) { 2339 req_bio_endio(req, bio, bio_bytes, error);
2316 blk_dump_rq_flags(req, "__end_that");
2317 printk(KERN_ERR "%s: bio idx %d >= vcnt %d\n",
2318 __func__, idx, bio->bi_vcnt);
2319 break;
2320 }
2321 2340
2322 nbytes = bio_iovec_idx(bio, idx)->bv_len; 2341 total_bytes += bio_bytes;
2323 BIO_BUG_ON(nbytes > bio->bi_size); 2342 nr_bytes -= bio_bytes;
2324 2343
2325 /* 2344 if (!nr_bytes)
2326 * not a complete bvec done 2345 break;
2327 */
2328 if (unlikely(nbytes > nr_bytes)) {
2329 bio_nbytes += nr_bytes;
2330 total_bytes += nr_bytes;
2331 break;
2332 }
2333
2334 /*
2335 * advance to the next vector
2336 */
2337 next_idx++;
2338 bio_nbytes += nbytes;
2339 }
2340
2341 total_bytes += nbytes;
2342 nr_bytes -= nbytes;
2343
2344 bio = req->bio;
2345 if (bio) {
2346 /*
2347 * end more in this run, or just return 'not-done'
2348 */
2349 if (unlikely(nr_bytes <= 0))
2350 break;
2351 }
2352 } 2346 }
2353 2347
2354 /* 2348 /*
@@ -2364,16 +2358,6 @@ bool blk_update_request(struct request *req, int error, unsigned int nr_bytes)
2364 return false; 2358 return false;
2365 } 2359 }
2366 2360
2367 /*
2368 * if the request wasn't completed, update state
2369 */
2370 if (bio_nbytes) {
2371 req_bio_endio(req, bio, bio_nbytes, error);
2372 bio->bi_idx += next_idx;
2373 bio_iovec(bio)->bv_offset += nr_bytes;
2374 bio_iovec(bio)->bv_len -= nr_bytes;
2375 }
2376
2377 req->__data_len -= total_bytes; 2361 req->__data_len -= total_bytes;
2378 req->buffer = bio_data(req->bio); 2362 req->buffer = bio_data(req->bio);
2379 2363
@@ -3045,6 +3029,149 @@ void blk_finish_plug(struct blk_plug *plug)
3045} 3029}
3046EXPORT_SYMBOL(blk_finish_plug); 3030EXPORT_SYMBOL(blk_finish_plug);
3047 3031
3032#ifdef CONFIG_PM_RUNTIME
3033/**
3034 * blk_pm_runtime_init - Block layer runtime PM initialization routine
3035 * @q: the queue of the device
3036 * @dev: the device the queue belongs to
3037 *
3038 * Description:
3039 * Initialize runtime-PM-related fields for @q and start auto suspend for
3040 * @dev. Drivers that want to take advantage of request-based runtime PM
3041 * should call this function after @dev has been initialized, and its
3042 * request queue @q has been allocated, and runtime PM for it can not happen
3043 * yet(either due to disabled/forbidden or its usage_count > 0). In most
3044 * cases, driver should call this function before any I/O has taken place.
3045 *
3046 * This function takes care of setting up using auto suspend for the device,
3047 * the autosuspend delay is set to -1 to make runtime suspend impossible
3048 * until an updated value is either set by user or by driver. Drivers do
3049 * not need to touch other autosuspend settings.
3050 *
3051 * The block layer runtime PM is request based, so only works for drivers
3052 * that use request as their IO unit instead of those directly use bio's.
3053 */
3054void blk_pm_runtime_init(struct request_queue *q, struct device *dev)
3055{
3056 q->dev = dev;
3057 q->rpm_status = RPM_ACTIVE;
3058 pm_runtime_set_autosuspend_delay(q->dev, -1);
3059 pm_runtime_use_autosuspend(q->dev);
3060}
3061EXPORT_SYMBOL(blk_pm_runtime_init);
3062
3063/**
3064 * blk_pre_runtime_suspend - Pre runtime suspend check
3065 * @q: the queue of the device
3066 *
3067 * Description:
3068 * This function will check if runtime suspend is allowed for the device
3069 * by examining if there are any requests pending in the queue. If there
3070 * are requests pending, the device can not be runtime suspended; otherwise,
3071 * the queue's status will be updated to SUSPENDING and the driver can
3072 * proceed to suspend the device.
3073 *
3074 * For the not allowed case, we mark last busy for the device so that
3075 * runtime PM core will try to autosuspend it some time later.
3076 *
3077 * This function should be called near the start of the device's
3078 * runtime_suspend callback.
3079 *
3080 * Return:
3081 * 0 - OK to runtime suspend the device
3082 * -EBUSY - Device should not be runtime suspended
3083 */
3084int blk_pre_runtime_suspend(struct request_queue *q)
3085{
3086 int ret = 0;
3087
3088 spin_lock_irq(q->queue_lock);
3089 if (q->nr_pending) {
3090 ret = -EBUSY;
3091 pm_runtime_mark_last_busy(q->dev);
3092 } else {
3093 q->rpm_status = RPM_SUSPENDING;
3094 }
3095 spin_unlock_irq(q->queue_lock);
3096 return ret;
3097}
3098EXPORT_SYMBOL(blk_pre_runtime_suspend);
3099
3100/**
3101 * blk_post_runtime_suspend - Post runtime suspend processing
3102 * @q: the queue of the device
3103 * @err: return value of the device's runtime_suspend function
3104 *
3105 * Description:
3106 * Update the queue's runtime status according to the return value of the
3107 * device's runtime suspend function and mark last busy for the device so
3108 * that PM core will try to auto suspend the device at a later time.
3109 *
3110 * This function should be called near the end of the device's
3111 * runtime_suspend callback.
3112 */
3113void blk_post_runtime_suspend(struct request_queue *q, int err)
3114{
3115 spin_lock_irq(q->queue_lock);
3116 if (!err) {
3117 q->rpm_status = RPM_SUSPENDED;
3118 } else {
3119 q->rpm_status = RPM_ACTIVE;
3120 pm_runtime_mark_last_busy(q->dev);
3121 }
3122 spin_unlock_irq(q->queue_lock);
3123}
3124EXPORT_SYMBOL(blk_post_runtime_suspend);
3125
3126/**
3127 * blk_pre_runtime_resume - Pre runtime resume processing
3128 * @q: the queue of the device
3129 *
3130 * Description:
3131 * Update the queue's runtime status to RESUMING in preparation for the
3132 * runtime resume of the device.
3133 *
3134 * This function should be called near the start of the device's
3135 * runtime_resume callback.
3136 */
3137void blk_pre_runtime_resume(struct request_queue *q)
3138{
3139 spin_lock_irq(q->queue_lock);
3140 q->rpm_status = RPM_RESUMING;
3141 spin_unlock_irq(q->queue_lock);
3142}
3143EXPORT_SYMBOL(blk_pre_runtime_resume);
3144
3145/**
3146 * blk_post_runtime_resume - Post runtime resume processing
3147 * @q: the queue of the device
3148 * @err: return value of the device's runtime_resume function
3149 *
3150 * Description:
3151 * Update the queue's runtime status according to the return value of the
3152 * device's runtime_resume function. If it is successfully resumed, process
3153 * the requests that are queued into the device's queue when it is resuming
3154 * and then mark last busy and initiate autosuspend for it.
3155 *
3156 * This function should be called near the end of the device's
3157 * runtime_resume callback.
3158 */
3159void blk_post_runtime_resume(struct request_queue *q, int err)
3160{
3161 spin_lock_irq(q->queue_lock);
3162 if (!err) {
3163 q->rpm_status = RPM_ACTIVE;
3164 __blk_run_queue(q);
3165 pm_runtime_mark_last_busy(q->dev);
3166 pm_runtime_autosuspend(q->dev);
3167 } else {
3168 q->rpm_status = RPM_SUSPENDED;
3169 }
3170 spin_unlock_irq(q->queue_lock);
3171}
3172EXPORT_SYMBOL(blk_post_runtime_resume);
3173#endif
3174
3048int __init blk_dev_init(void) 3175int __init blk_dev_init(void)
3049{ 3176{
3050 BUILD_BUG_ON(__REQ_NR_BITS > 8 * 3177 BUILD_BUG_ON(__REQ_NR_BITS > 8 *
diff --git a/block/cfq-iosched.c b/block/cfq-iosched.c
index 4f0ade74cfd0..d5cd3131c57a 100644
--- a/block/cfq-iosched.c
+++ b/block/cfq-iosched.c
@@ -2270,11 +2270,8 @@ cfq_find_rq_fmerge(struct cfq_data *cfqd, struct bio *bio)
2270 return NULL; 2270 return NULL;
2271 2271
2272 cfqq = cic_to_cfqq(cic, cfq_bio_sync(bio)); 2272 cfqq = cic_to_cfqq(cic, cfq_bio_sync(bio));
2273 if (cfqq) { 2273 if (cfqq)
2274 sector_t sector = bio->bi_sector + bio_sectors(bio); 2274 return elv_rb_find(&cfqq->sort_list, bio_end_sector(bio));
2275
2276 return elv_rb_find(&cfqq->sort_list, sector);
2277 }
2278 2275
2279 return NULL; 2276 return NULL;
2280} 2277}
diff --git a/block/deadline-iosched.c b/block/deadline-iosched.c
index 90037b5eb17f..ba19a3afab79 100644
--- a/block/deadline-iosched.c
+++ b/block/deadline-iosched.c
@@ -132,7 +132,7 @@ deadline_merge(struct request_queue *q, struct request **req, struct bio *bio)
132 * check for front merge 132 * check for front merge
133 */ 133 */
134 if (dd->front_merges) { 134 if (dd->front_merges) {
135 sector_t sector = bio->bi_sector + bio_sectors(bio); 135 sector_t sector = bio_end_sector(bio);
136 136
137 __rq = elv_rb_find(&dd->sort_list[bio_data_dir(bio)], sector); 137 __rq = elv_rb_find(&dd->sort_list[bio_data_dir(bio)], sector);
138 if (__rq) { 138 if (__rq) {
diff --git a/block/elevator.c b/block/elevator.c
index a0ffdd943c98..eba5b04c29b1 100644
--- a/block/elevator.c
+++ b/block/elevator.c
@@ -34,6 +34,7 @@
34#include <linux/blktrace_api.h> 34#include <linux/blktrace_api.h>
35#include <linux/hash.h> 35#include <linux/hash.h>
36#include <linux/uaccess.h> 36#include <linux/uaccess.h>
37#include <linux/pm_runtime.h>
37 38
38#include <trace/events/block.h> 39#include <trace/events/block.h>
39 40
@@ -536,6 +537,27 @@ void elv_bio_merged(struct request_queue *q, struct request *rq,
536 e->type->ops.elevator_bio_merged_fn(q, rq, bio); 537 e->type->ops.elevator_bio_merged_fn(q, rq, bio);
537} 538}
538 539
540#ifdef CONFIG_PM_RUNTIME
541static void blk_pm_requeue_request(struct request *rq)
542{
543 if (rq->q->dev && !(rq->cmd_flags & REQ_PM))
544 rq->q->nr_pending--;
545}
546
547static void blk_pm_add_request(struct request_queue *q, struct request *rq)
548{
549 if (q->dev && !(rq->cmd_flags & REQ_PM) && q->nr_pending++ == 0 &&
550 (q->rpm_status == RPM_SUSPENDED || q->rpm_status == RPM_SUSPENDING))
551 pm_request_resume(q->dev);
552}
553#else
554static inline void blk_pm_requeue_request(struct request *rq) {}
555static inline void blk_pm_add_request(struct request_queue *q,
556 struct request *rq)
557{
558}
559#endif
560
539void elv_requeue_request(struct request_queue *q, struct request *rq) 561void elv_requeue_request(struct request_queue *q, struct request *rq)
540{ 562{
541 /* 563 /*
@@ -550,6 +572,8 @@ void elv_requeue_request(struct request_queue *q, struct request *rq)
550 572
551 rq->cmd_flags &= ~REQ_STARTED; 573 rq->cmd_flags &= ~REQ_STARTED;
552 574
575 blk_pm_requeue_request(rq);
576
553 __elv_add_request(q, rq, ELEVATOR_INSERT_REQUEUE); 577 __elv_add_request(q, rq, ELEVATOR_INSERT_REQUEUE);
554} 578}
555 579
@@ -572,6 +596,8 @@ void __elv_add_request(struct request_queue *q, struct request *rq, int where)
572{ 596{
573 trace_block_rq_insert(q, rq); 597 trace_block_rq_insert(q, rq);
574 598
599 blk_pm_add_request(q, rq);
600
575 rq->q = q; 601 rq->q = q;
576 602
577 if (rq->cmd_flags & REQ_SOFTBARRIER) { 603 if (rq->cmd_flags & REQ_SOFTBARRIER) {