block: fix nr_phys_segments miscalculation bug
authorFUJITA Tomonori <fujita.tomonori@lab.ntt.co.jp>
Mon, 13 Oct 2008 12:19:05 +0000 (14:19 +0200)
committerJens Axboe <jens.axboe@oracle.com>
Fri, 17 Oct 2008 06:46:56 +0000 (08:46 +0200)
commit8677142710516d986d932d6f1fba7be8382c1fec
tree5221f48b4e7e62590f8bbb832b4065886681d6cf
parent0fc71e3d6520ba7abad5cfbc9a33db0190e4d5b8
block: fix nr_phys_segments miscalculation bug

This fixes the bug reported by Nikanth Karthikesan <knikanth@suse.de>:

http://lkml.org/lkml/2008/10/2/203

The root cause of the bug is that blk_phys_contig_segment
miscalculates q->max_segment_size.

blk_phys_contig_segment checks:

req->biotail->bi_size + next_req->bio->bi_size > q->max_segment_size

But blk_recalc_rq_segments might expect that req->biotail and the
previous bio in the req are supposed be merged into one
segment. blk_recalc_rq_segments might also expect that next_req->bio
and the next bio in the next_req are supposed be merged into one
segment. In such case, we merge two requests that can't be merged
here. Later, blk_rq_map_sg gives more segments than it should.

We need to keep track of segment size in blk_recalc_rq_segments and
use it to see if two requests can be merged. This patch implements it
in the similar way that we used to do for hw merging (virtual
merging).

Signed-off-by: FUJITA Tomonori <fujita.tomonori@lab.ntt.co.jp>
Signed-off-by: Jens Axboe <jens.axboe@oracle.com>
block/blk-merge.c
include/linux/bio.h