Commit 7f60dcaa authored by Ming Lei's avatar Ming Lei Committed by Jens Axboe

block: blk-merge: fix blk_recount_segments()

For cloned bio, bio->bi_vcnt can't be used at all, and we
have resort to bio_segments() to figure out how many
segment there are in the bio.
Signed-off-by: default avatarMing Lei <tom.leiming@gmail.com>
Signed-off-by: default avatarJens Axboe <axboe@fb.com>
parent 92697dc9
...@@ -97,19 +97,22 @@ void blk_recalc_rq_segments(struct request *rq) ...@@ -97,19 +97,22 @@ void blk_recalc_rq_segments(struct request *rq)
void blk_recount_segments(struct request_queue *q, struct bio *bio) void blk_recount_segments(struct request_queue *q, struct bio *bio)
{ {
bool no_sg_merge = !!test_bit(QUEUE_FLAG_NO_SG_MERGE, unsigned short seg_cnt;
&q->queue_flags);
bool merge_not_need = bio->bi_vcnt < queue_max_segments(q); /* estimate segment number by bi_vcnt for non-cloned bio */
if (bio_flagged(bio, BIO_CLONED))
seg_cnt = bio_segments(bio);
else
seg_cnt = bio->bi_vcnt;
if (no_sg_merge && !bio_flagged(bio, BIO_CLONED) && if (test_bit(QUEUE_FLAG_NO_SG_MERGE, &q->queue_flags) &&
merge_not_need) (seg_cnt < queue_max_segments(q)))
bio->bi_phys_segments = bio->bi_vcnt; bio->bi_phys_segments = seg_cnt;
else { else {
struct bio *nxt = bio->bi_next; struct bio *nxt = bio->bi_next;
bio->bi_next = NULL; bio->bi_next = NULL;
bio->bi_phys_segments = __blk_recalc_rq_segments(q, bio, bio->bi_phys_segments = __blk_recalc_rq_segments(q, bio, false);
no_sg_merge && merge_not_need);
bio->bi_next = nxt; bio->bi_next = nxt;
} }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment