public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
From: NeilBrown <neilb@suse.de>
To: Jens Axboe <jens.axboe@oracle.com>
Cc: linux-kernel@vger.kernel.org, Tejun Heo <htejun@gmail.com>
Subject: [PATCH 003 of 6] Fix various abuse of bio fields in umem.c
Date: Thu, 16 Aug 2007 21:21:09 +1000	[thread overview]
Message-ID: <1070816112109.12200@suse.de> (raw)
In-Reply-To: 20070816211551.11839.patches@notabene


umem.c:
  advances bi_idx and bi_sector to track where it is up to.
   But it is only ever doing this on one bio, so the updated
   fields can easily be kept elsewhere (current_*).
  updates bi_size, but never uses the updated values, so
   this isn't needed.
  reuses bi_phys_segments to count how many iovecs have been
   completely.  As the completion happens sequentiually, we
   can store this information outside the bio too.


Signed-off-by: Neil Brown <neilb@suse.de>

### Diffstat output
 ./drivers/block/umem.c |   38 +++++++++++++++++++++++++-------------
 1 file changed, 25 insertions(+), 13 deletions(-)

diff .prev/drivers/block/umem.c ./drivers/block/umem.c
--- .prev/drivers/block/umem.c	2007-08-16 21:10:00.000000000 +1000
+++ ./drivers/block/umem.c	2007-08-16 21:10:12.000000000 +1000
@@ -113,6 +113,8 @@ struct cardinfo {
 				    * have been written
 				    */
 	struct bio	*bio, *currentbio, **biotail;
+	int		current_idx;
+	sector_t	current_sector;
 
 	struct request_queue *queue;
 
@@ -121,6 +123,7 @@ struct cardinfo {
 		struct mm_dma_desc	*desc;
 		int	 		cnt, headcnt;
 		struct bio		*bio, **biotail;
+		int			idx;
 	} mm_pages[2];
 #define DESC_PER_PAGE ((PAGE_SIZE*2)/sizeof(struct mm_dma_desc))
 
@@ -380,12 +383,16 @@ static int add_bio(struct cardinfo *card
 	dma_addr_t dma_handle;
 	int offset;
 	struct bio *bio;
+	struct bio_vec *vec;
+	int idx;
 	int rw;
 	int len;
 
 	bio = card->currentbio;
 	if (!bio && card->bio) {
 		card->currentbio = card->bio;
+		card->current_idx = card->bio->bi_idx;
+		card->current_sector = card->bio->bi_sector;
 		card->bio = card->bio->bi_next;
 		if (card->bio == NULL)
 			card->biotail = &card->bio;
@@ -394,15 +401,17 @@ static int add_bio(struct cardinfo *card
 	}
 	if (!bio)
 		return 0;
+	idx = card->current_idx;
 
 	rw = bio_rw(bio);
 	if (card->mm_pages[card->Ready].cnt >= DESC_PER_PAGE)
 		return 0;
 
-	len = bio_iovec(bio)->bv_len;
-	dma_handle = pci_map_page(card->dev, 
-				  bio_page(bio),
-				  bio_offset(bio),
+	vec = bio_iovec_idx(bio, idx);
+	len = vec->bv_len;
+	dma_handle = pci_map_page(card->dev,
+				  vec->bv_page,
+				  vec->bv_offset,
 				  len,
 				  (rw==READ) ?
 				  PCI_DMA_FROMDEVICE : PCI_DMA_TODEVICE);
@@ -410,6 +419,8 @@ static int add_bio(struct cardinfo *card
 	p = &card->mm_pages[card->Ready];
 	desc = &p->desc[p->cnt];
 	p->cnt++;
+	if (p->bio == NULL)
+		p->idx = idx;
 	if ((p->biotail) != &bio->bi_next) {
 		*(p->biotail) = bio;
 		p->biotail = &(bio->bi_next);
@@ -419,7 +430,7 @@ static int add_bio(struct cardinfo *card
 	desc->data_dma_handle = dma_handle;
 
 	desc->pci_addr = cpu_to_le64((u64)desc->data_dma_handle);
-	desc->local_addr= cpu_to_le64(bio->bi_sector << 9);
+	desc->local_addr = cpu_to_le64(card->current_sector << 9);
 	desc->transfer_size = cpu_to_le32(len);
 	offset = ( ((char*)&desc->sem_control_bits) - ((char*)p->desc));
 	desc->sem_addr = cpu_to_le64((u64)(p->page_dma+offset));
@@ -435,10 +446,10 @@ static int add_bio(struct cardinfo *card
 		desc->control_bits |= cpu_to_le32(DMASCR_TRANSFER_READ);
 	desc->sem_control_bits = desc->control_bits;
 
-	bio->bi_sector += (len>>9);
-	bio->bi_size -= len;
-	bio->bi_idx++;
-	if (bio->bi_idx >= bio->bi_vcnt) 
+	card->current_sector += (len >> 9);
+	idx++;
+	card->current_idx = idx;
+	if (idx >= bio->bi_vcnt)
 		card->currentbio = NULL;
 
 	return 1;
@@ -474,10 +485,12 @@ static void process_page(unsigned long d
 			last=1; 
 		}
 		page->headcnt++;
-		idx = bio->bi_phys_segments;
-		bio->bi_phys_segments++;
-		if (bio->bi_phys_segments >= bio->bi_vcnt)
+		idx = page->idx;
+		page->idx++;
+		if (page->idx >= bio->bi_vcnt) {
 			page->bio = bio->bi_next;
+			page->idx = page->bio->bi_idx;
+		}
 
 		pci_unmap_page(card->dev, desc->data_dma_handle, 
 			       bio_iovec_idx(bio,idx)->bv_len,
@@ -547,7 +560,6 @@ static int mm_make_request(struct reques
 	pr_debug("mm_make_request %llu %u\n",
 		 (unsigned long long)bio->bi_sector, bio->bi_size);
 
-	bio->bi_phys_segments = bio->bi_idx; /* count of completed segments*/
 	spin_lock_irq(&card->lock);
 	*card->biotail = bio;
 	bio->bi_next = NULL;

  parent reply	other threads:[~2007-08-16 11:22 UTC|newest]

Thread overview: 38+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2007-08-16 11:20 [PATCH 000 of 6] A few block-layer tidy-up patches NeilBrown
2007-08-16 11:20 ` [PATCH 001 of 6] Merge blk_recount_segments into blk_recalc_rq_segments NeilBrown
2007-08-16 11:21 ` [PATCH 002 of 6] Introduce rq_for_each_segment replacing rq_for_each_bio NeilBrown
2007-08-17  7:13   ` Geert Uytterhoeven
2007-08-18 14:37     ` Satyam Sharma
2007-08-18 14:30       ` Jan Engelhardt
2007-08-18 14:48         ` Satyam Sharma
2007-08-20 11:21           ` Geert Uytterhoeven
2007-08-20 12:46             ` Jan Engelhardt
2007-08-21  1:38             ` Satyam Sharma
2007-08-21  7:09               ` Geert Uytterhoeven
2007-08-21  9:46                 ` Satyam Sharma
2007-08-21  9:52                   ` Geert Uytterhoeven
2007-08-21 10:41                     ` [PATCH] PS3: Update MAINTAINERS Satyam Sharma
2007-08-21 19:01                       ` Geoff Levand
2007-08-21 20:01                         ` Joe Perches
2007-08-21 20:06                           ` Rene Herman
2007-08-21 20:17                             ` Geoff Levand
2007-08-21 20:33                               ` Rene Herman
2007-08-21 20:48                               ` Satyam Sharma
2007-08-21 20:41                                 ` Rene Herman
2007-08-21 20:47                                 ` Joe Perches
2007-08-21 21:58                         ` Hugh Blemings
2007-08-23 18:14                           ` Matt Mackall
2007-08-24  5:52                             ` Hugh Blemings
2007-08-21 20:10                       ` Geoff Levand
2007-08-24  6:25                       ` [Cbe-oss-dev] " Hugh Blemings
2007-08-24  6:47                         ` Satyam Sharma
2007-08-24  6:48                           ` Hugh Blemings
2007-08-16 11:21 ` NeilBrown [this message]
2007-08-16 11:21 ` [PATCH 004 of 6] New function blk_req_append_bio NeilBrown
2007-08-16 11:21 ` [PATCH 005 of 6] Stop exporting blk_rq_bio_prep NeilBrown
2007-08-16 11:21 ` [PATCH 006 of 6] Share code between init_request_from_bio and blk_rq_bio_prep NeilBrown
2007-08-16 11:36 ` [PATCH 000 of 6] A few block-layer tidy-up patches Jens Axboe
2007-08-17  0:40   ` Neil Brown
2007-08-17  6:17     ` Jens Axboe
2007-08-17  7:21       ` Neil Brown
2007-08-17 12:37         ` Jens Axboe

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1070816112109.12200@suse.de \
    --to=neilb@suse.de \
    --cc=htejun@gmail.com \
    --cc=jens.axboe@oracle.com \
    --cc=linux-kernel@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox