ia64/linux-2.6.18-xen.hg

changeset 896:f59c5daed527

blktap2: use blk_rq_map_sg() here too

Just like in blkfront, not doing so can cause the maximum number of
segments check to trigger.

Signed-off-by: Jan Beulich <jbeulich@novell.com>
author Keir Fraser <keir.fraser@citrix.com>
date Thu Jun 04 10:46:54 2009 +0100 (2009-06-04)
parents 20be7f6d414a
children 329ea0ccb344
files drivers/xen/blktap2/blktap.h drivers/xen/blktap2/device.c
line diff
     1.1 --- a/drivers/xen/blktap2/blktap.h	Thu Jun 04 10:45:49 2009 +0100
     1.2 +++ b/drivers/xen/blktap2/blktap.h	Thu Jun 04 10:46:54 2009 +0100
     1.3 @@ -4,6 +4,7 @@
     1.4  #include <linux/fs.h>
     1.5  #include <linux/poll.h>
     1.6  #include <linux/cdev.h>
     1.7 +#include <linux/scatterlist.h>
     1.8  #include <xen/blkif.h>
     1.9  #include <xen/gnttab.h>
    1.10  
    1.11 @@ -174,6 +175,7 @@ struct blktap {
    1.12  
    1.13  	int                            pending_cnt;
    1.14  	struct blktap_request         *pending_requests[MAX_PENDING_REQS];
    1.15 +	struct scatterlist             sg[BLKIF_MAX_SEGMENTS_PER_REQUEST];
    1.16  
    1.17  	wait_queue_head_t              wq;
    1.18  	struct list_head               deferred_queue;
     2.1 --- a/drivers/xen/blktap2/device.c	Thu Jun 04 10:45:49 2009 +0100
     2.2 +++ b/drivers/xen/blktap2/device.c	Thu Jun 04 10:46:54 2009 +0100
     2.3 @@ -574,11 +574,10 @@ blktap_device_process_request(struct blk
     2.4  			      struct blktap_request *request,
     2.5  			      struct request *req)
     2.6  {
     2.7 -	struct bio *bio;
     2.8  	struct page *page;
     2.9 -	struct bio_vec *bvec;
    2.10 -	int idx, usr_idx, err;
    2.11 +	int i, usr_idx, err;
    2.12  	struct blktap_ring *ring;
    2.13 +	struct scatterlist *sg;
    2.14  	struct blktap_grant_table table;
    2.15  	unsigned int fsect, lsect, nr_sects;
    2.16  	unsigned long offset, uvaddr, kvaddr;
    2.17 @@ -605,43 +604,39 @@ blktap_device_process_request(struct blk
    2.18  
    2.19  	nr_sects = 0;
    2.20  	request->nr_pages = 0;
    2.21 -	blkif_req.nr_segments = 0;
    2.22 -	rq_for_each_bio(bio, req) {
    2.23 -		bio_for_each_segment(bvec, bio, idx) {
    2.24 -			BUG_ON(blkif_req.nr_segments ==
    2.25 -			       BLKIF_MAX_SEGMENTS_PER_REQUEST);
    2.26 +	blkif_req.nr_segments = blk_rq_map_sg(req->q, req, tap->sg);
    2.27 +	BUG_ON(blkif_req.nr_segments > BLKIF_MAX_SEGMENTS_PER_REQUEST);
    2.28 +	for (i = 0; i < blkif_req.nr_segments; ++i) {
    2.29 +			sg = tap->sg + i;
    2.30 +			fsect = sg->offset >> 9;
    2.31 +			lsect = fsect + (sg->length >> 9) - 1;
    2.32 +			nr_sects += sg->length >> 9;
    2.33  
    2.34 -			fsect     = bvec->bv_offset >> 9;
    2.35 -			lsect     = fsect + (bvec->bv_len >> 9) - 1;
    2.36 -			nr_sects += bvec->bv_len >> 9;
    2.37 -
    2.38 -			blkif_req.seg[blkif_req.nr_segments] =
    2.39 +			blkif_req.seg[i] =
    2.40  				(struct blkif_request_segment) {
    2.41  				.gref       = 0,
    2.42  				.first_sect = fsect,
    2.43  				.last_sect  = lsect };
    2.44  
    2.45 -			if (PageBlkback(bvec->bv_page)) {
    2.46 +			if (PageBlkback(sg->page)) {
    2.47  				/* foreign page -- use xen */
    2.48  				if (blktap_prep_foreign(tap,
    2.49  							request,
    2.50  							&blkif_req,
    2.51 -							blkif_req.nr_segments,
    2.52 -							bvec->bv_page,
    2.53 +							i,
    2.54 +							sg->page,
    2.55  							&table))
    2.56  					goto out;
    2.57  			} else {
    2.58  				/* do it the old fashioned way */
    2.59  				blktap_map(tap,
    2.60  					   request,
    2.61 -					   blkif_req.nr_segments,
    2.62 -					   bvec->bv_page);
    2.63 +					   i,
    2.64 +					   sg->page);
    2.65  			}
    2.66  
    2.67 -			uvaddr = MMAP_VADDR(ring->user_vstart,
    2.68 -					    usr_idx, blkif_req.nr_segments);
    2.69 -			kvaddr = request_to_kaddr(request,
    2.70 -						  blkif_req.nr_segments);
    2.71 +			uvaddr = MMAP_VADDR(ring->user_vstart, usr_idx, i);
    2.72 +			kvaddr = request_to_kaddr(request, i);
    2.73  			offset = (uvaddr - ring->vma->vm_start) >> PAGE_SHIFT;
    2.74  			page   = pfn_to_page(__pa(kvaddr) >> PAGE_SHIFT);
    2.75  			ring->foreign_map.map[offset] = page;
    2.76 @@ -651,12 +646,10 @@ blktap_device_process_request(struct blk
    2.77  			      uvaddr, page, __pa(kvaddr) >> PAGE_SHIFT);
    2.78  			BTDBG("offset: 0x%08lx, pending_req: %p, seg: %d, "
    2.79  			      "page: %p, kvaddr: 0x%08lx, uvaddr: 0x%08lx\n",
    2.80 -			      offset, request, blkif_req.nr_segments,
    2.81 +			      offset, request, i,
    2.82  			      page, kvaddr, uvaddr);
    2.83  
    2.84 -			blkif_req.nr_segments++;
    2.85  			request->nr_pages++;
    2.86 -		}
    2.87  	}
    2.88  
    2.89  	if (blktap_map_foreign(tap, request, &blkif_req, &table))