diff options
author | Tejun Heo <tj@kernel.org> | 2012-02-08 03:19:38 -0500 |
---|---|---|
committer | Jens Axboe <axboe@kernel.dk> | 2012-02-08 03:19:38 -0500 |
commit | 050c8ea80e3e90019d9e981c6a117ef614e882ed (patch) | |
tree | e1c53f17a93ba48b9aedb0c1560dfb022733845f /block/blk-merge.c | |
parent | 4e8670e26135d8fbfd5e084fddc1a8ed9f8eb4cb (diff) |
block: separate out blk_rq_merge_ok() and blk_try_merge() from elevator functions
blk_rq_merge_ok() is the elevator-neutral part of merge eligibility
test. blk_try_merge() determines merge direction and expects the
caller to have tested elv_rq_merge_ok() previously.
elv_rq_merge_ok() now wraps blk_rq_merge_ok() and then calls
elv_iosched_allow_merge(). elv_try_merge() is removed and the two
callers are updated to call elv_rq_merge_ok() explicitly followed by
blk_try_merge(). While at it, make rq_merge_ok() functions return
bool.
This is to prepare for plug merge update and doesn't introduce any
behavior change.
This is based on Jens' patch to skip elevator_allow_merge_fn() from
plug merge.
Signed-off-by: Tejun Heo <tj@kernel.org>
LKML-Reference: <4F16F3CA.90904@kernel.dk>
Original-patch-by: Jens Axboe <axboe@kernel.dk>
Signed-off-by: Jens Axboe <axboe@kernel.dk>
Diffstat (limited to 'block/blk-merge.c')
-rw-r--r-- | block/blk-merge.c | 37 |
1 files changed, 37 insertions, 0 deletions
diff --git a/block/blk-merge.c b/block/blk-merge.c index cfcc37cb222b..160035f54882 100644 --- a/block/blk-merge.c +++ b/block/blk-merge.c | |||
@@ -471,3 +471,40 @@ int blk_attempt_req_merge(struct request_queue *q, struct request *rq, | |||
471 | { | 471 | { |
472 | return attempt_merge(q, rq, next); | 472 | return attempt_merge(q, rq, next); |
473 | } | 473 | } |
474 | |||
475 | bool blk_rq_merge_ok(struct request *rq, struct bio *bio) | ||
476 | { | ||
477 | if (!rq_mergeable(rq)) | ||
478 | return false; | ||
479 | |||
480 | /* don't merge file system requests and discard requests */ | ||
481 | if ((bio->bi_rw & REQ_DISCARD) != (rq->bio->bi_rw & REQ_DISCARD)) | ||
482 | return false; | ||
483 | |||
484 | /* don't merge discard requests and secure discard requests */ | ||
485 | if ((bio->bi_rw & REQ_SECURE) != (rq->bio->bi_rw & REQ_SECURE)) | ||
486 | return false; | ||
487 | |||
488 | /* different data direction or already started, don't merge */ | ||
489 | if (bio_data_dir(bio) != rq_data_dir(rq)) | ||
490 | return false; | ||
491 | |||
492 | /* must be same device and not a special request */ | ||
493 | if (rq->rq_disk != bio->bi_bdev->bd_disk || rq->special) | ||
494 | return false; | ||
495 | |||
496 | /* only merge integrity protected bio into ditto rq */ | ||
497 | if (bio_integrity(bio) != blk_integrity_rq(rq)) | ||
498 | return false; | ||
499 | |||
500 | return true; | ||
501 | } | ||
502 | |||
503 | int blk_try_merge(struct request *rq, struct bio *bio) | ||
504 | { | ||
505 | if (blk_rq_pos(rq) + blk_rq_sectors(rq) == bio->bi_sector) | ||
506 | return ELEVATOR_BACK_MERGE; | ||
507 | else if (blk_rq_pos(rq) - bio_sectors(bio) == bio->bi_sector) | ||
508 | return ELEVATOR_FRONT_MERGE; | ||
509 | return ELEVATOR_NO_MERGE; | ||
510 | } | ||