block: rewrite blk_bvec_map_sg to avoid a nth_page call
The offset in scatterlists is allowed to be larger than the page size, so don't go to great length to avoid that case and simplify the arithmetics. Signed-off-by: Christoph Hellwig <hch@lst.de> Reviewed-by: Bart Van Assche <bvanassche@acm.org> Reviewed-by: Ming Lei <ming.lei@redhat.com> Reviewed-by: Johannes Thumshirn <jthumshirn@suse.de> Signed-off-by: Jens Axboe <axboe@kernel.dk>
This commit is contained in:
Родитель
22391ac30a
Коммит
8a96a0e408
|
@ -469,26 +469,17 @@ static unsigned blk_bvec_map_sg(struct request_queue *q,
|
||||||
struct scatterlist **sg)
|
struct scatterlist **sg)
|
||||||
{
|
{
|
||||||
unsigned nbytes = bvec->bv_len;
|
unsigned nbytes = bvec->bv_len;
|
||||||
unsigned nsegs = 0, total = 0, offset = 0;
|
unsigned nsegs = 0, total = 0;
|
||||||
|
|
||||||
while (nbytes > 0) {
|
while (nbytes > 0) {
|
||||||
unsigned seg_size;
|
unsigned offset = bvec->bv_offset + total;
|
||||||
struct page *pg;
|
unsigned len = min(get_max_segment_size(q, offset), nbytes);
|
||||||
unsigned idx;
|
|
||||||
|
|
||||||
*sg = blk_next_sg(sg, sglist);
|
*sg = blk_next_sg(sg, sglist);
|
||||||
|
sg_set_page(*sg, bvec->bv_page, len, offset);
|
||||||
|
|
||||||
seg_size = get_max_segment_size(q, bvec->bv_offset + total);
|
total += len;
|
||||||
seg_size = min(nbytes, seg_size);
|
nbytes -= len;
|
||||||
|
|
||||||
offset = (total + bvec->bv_offset) % PAGE_SIZE;
|
|
||||||
idx = (total + bvec->bv_offset) / PAGE_SIZE;
|
|
||||||
pg = bvec_nth_page(bvec->bv_page, idx);
|
|
||||||
|
|
||||||
sg_set_page(*sg, pg, seg_size, offset);
|
|
||||||
|
|
||||||
total += seg_size;
|
|
||||||
nbytes -= seg_size;
|
|
||||||
nsegs++;
|
nsegs++;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Загрузка…
Ссылка в новой задаче