Skip to contentSkip to conversation

Bio traversal patches - update for 2.5.33 (sans ide changes)

PATCH Suparna Bhattacharya 1 participant 1 message Sep 4, 2002

Subsystems (10)
lore
Share & tools
lore
#0 lore raw
Quoted 12 lines

BIO traversal enhancements
--------------------------
- Pre-req for full BIO splitting infrastructure [Splits
in the middle of a segment can also share the same vec]
- Pre-req for attaching a pre-built vector (not owned by block) to a bio (e.g for aio) [Avoids certain subtle side-effects in special cases like partial segment completion]
- Pre-req for IDE mult-count PIO write fixes w/o request copy [Ability to traverse a bio partially for i/o submission without effecting bio completion]

Quoted 5 lines

Introduces some new fields in the bio and request to help maintain traversal state and handle partial segment bio clones, and comes with a corresponding set of helpers to enable clean separation of traversal for i/o submission vs i/o completion.

Latest patch for 2.5.33 (dropped the ide, ide-scsi changes for now as mentioned in my last mail). This is a rollup patch combining the core and fs changes and some initial compatibility modifications to certain drivers. Its fairly easy to split these as before (as they affect different files), so let me know if that would be useful.

The biodoc update patch has not changed since the last posting, so not including it in this rollup, but can resend if required along with the introductory mail about specific changes made and things drivers might need to take care of.

Regards
Suparna

drivers/block/elevator.c +24 -0
diff -ur -X /home/suparna/dontdiff linux-2.5.33/drivers/block/elevator.c linux-2.5.33-bio/drivers/block/elevator.c
@@ -236,6 +236,9 @@
 	if (!insert_here)
 		insert_here = q->queue_head.prev;
 
+	if (rq->bio) 
+		BIO_BUG_ON(!bio_consistent(rq->bio)); /* debug only */
+
 	if (!(rq->flags & REQ_BARRIER))
 		lat = latency[rq_data_dir(rq)];
 
@@ -309,6 +312,9 @@
 void elevator_noop_add_request(request_queue_t *q, struct request *rq,
 			       struct list_head *insert_here)
 {
+	if (rq->bio) 
+		BIO_BUG_ON(!bio_consistent(rq->bio)); /* debug only */
+
 	list_add_tail(&rq->queuelist, &q->queue_head);
 
 	/*
@@ -389,6 +395,9 @@
 void __elv_add_request(request_queue_t *q, struct request *rq,
 			  struct list_head *insert_here)
 {
+	if (rq->bio) 
+		BIO_BUG_ON(!bio_consistent(rq->bio)); /* debug only */
+
 	q->elevator.elevator_add_req_fn(q, rq, insert_here);
 }
 
@@ -412,7 +421,19 @@
 
 		/*
 		 * all ok, break and return it
+		 * after presetting some fields (e.g. the req might
+		 * have been restarted)
 		 */
+		if ((rq->bio = rq->hard_bio)) {
+			rq->nr_bio_segments = bio_segments(rq->bio);
+			rq->nr_bio_sectors = bio_sectors(rq->bio);
+			rq->hard_cur_sectors = bio_segsize(rq->bio) >> 9;
+			rq->buffer = bio_data(rq->bio);
+		}
+		rq->sector = rq->hard_sector;
+		rq->nr_sectors = rq->hard_nr_sectors;
+		rq->current_nr_sectors = rq->hard_cur_sectors;
+
 		if (!q->prep_rq_fn(q, rq))
 			break;
 
@@ -426,6 +447,9 @@
 		end_that_request_last(rq);
 	}
 
+	if (rq->bio) 
+		BIO_BUG_ON(!bio_consistent(rq->bio)); /* debug only */
+
 	return rq;
 }
 
drivers/block/floppy.c +9 -0
diff -ur -X /home/suparna/dontdiff linux-2.5.33/drivers/block/floppy.c linux-2.5.33-bio/drivers/block/floppy.c
@@ -2480,6 +2480,9 @@
 	size = 0;
 
 	rq_for_each_bio(bio, CURRENT) {
+		/* Can't handle arbitrary split bio pieces */
+		BIO_BUG_ON(bio_startoffset(bio) != 0);
+		BIO_BUG_ON(bio_endoffset(bio) != 0);
 		bio_for_each_segment(bv, bio, i) {
 			if (page_address(bv->bv_page) + bv->bv_offset != base + size)
 				break;
@@ -2547,6 +2550,9 @@
 	size = CURRENT->current_nr_sectors << 9;
 
 	rq_for_each_bio(bio, CURRENT) {
+		/* Can't handle arbitrary bio pieces as yet */
+		BIO_BUG_ON(bio_startoffset(bio) != 0);
+		BIO_BUG_ON(bio_endoffset(bio) != 0);
 		bio_for_each_segment(bv, bio, i) {
 			if (!remaining)
 				break;
@@ -3899,6 +3905,9 @@
 	bio.bi_vcnt = 1;
 	bio.bi_idx = 0;
 	bio.bi_size = size;
+	bio.bi_voffset = __BVEC_START(&bio)->bv_offset;
+	bio.bi_endvoffset = __BVEC_END(&bio)->bv_offset +
+		__BVEC_END(&bio)->bv_len;
 	bio.bi_bdev = bdev;
 	bio.bi_sector = 0;
 	init_completion(&complete);
drivers/block/ll_rw_blk.c +185 -34

406 lines not on this page · raw message

drivers/block/loop.c +36 -13

114 lines not on this page · raw message

drivers/block/nbd.c +3 -0
diff -ur -X /home/suparna/dontdiff linux-2.5.33/drivers/block/nbd.c linux-2.5.33-bio/drivers/block/nbd.c
@@ -180,6 +180,9 @@
 		 * whether to set MSG_MORE or not...
 		 */
 		rq_for_each_bio(bio, req) {
+			/* Can't handle arbitrary bio pieces yet */
+			BIO_BUG_ON(bio_startoffset(bio) != 0);
+			BIO_BUG_ON(bio_endoffset(bio) != 0);
 			struct bio_vec *bvec;
 			bio_for_each_segment(bvec, bio, i) {
 				flags = 0;
drivers/block/rd.c +3 -0
diff -ur -X /home/suparna/dontdiff linux-2.5.33/drivers/block/rd.c linux-2.5.33-bio/drivers/block/rd.c
@@ -227,6 +227,9 @@
 
 	sector = bio->bi_sector;
 	rw = bio_data_dir(bio);
+	/* Can't handle a bio split in the middle of a segment */
+	BIO_BUG_ON(bio_startoffset(bio) > 0);
+	BIO_BUG_ON(bio_offset(bio) > 0);
 	bio_for_each_segment(bvec, bio, i) {
 		ret |= rd_blkdev_pagecache_IO(rw, bvec, sector, minor);
 		sector += bvec->bv_len >> 9;
drivers/block/umem.c +1 -1
diff -ur -X /home/suparna/dontdiff linux-2.5.33/drivers/block/umem.c linux-2.5.33-bio/drivers/block/umem.c
@@ -417,7 +417,7 @@
 	if (card->mm_pages[card->Ready].cnt >= DESC_PER_PAGE)
 		return 0;
 
-	len = bio_iovec(bio)->bv_len;
+	len = bio_segsize(bio);
 	dma_handle = pci_map_page(card->dev, 
 				  bio_page(bio),
 				  bio_offset(bio),
drivers/md/raid1.c +3 -0
diff -ur -X /home/suparna/dontdiff linux-2.5.33/drivers/md/raid1.c linux-2.5.33-bio/drivers/md/raid1.c
@@ -90,6 +90,9 @@
 	bio->bi_vcnt = RESYNC_PAGES;
 	bio->bi_idx = 0;
 	bio->bi_size = RESYNC_BLOCK_SIZE;
+	bio->bi_voffset = __BVEC_START(bio)->bv_offset;
+	bio->bi_endvoffset = __BVEC_END(bio)->bv_offset +
+		__BVEC_END(bio)->bv_len;
 	bio->bi_end_io = NULL;
 	atomic_set(&bio->bi_cnt, 1);
 
drivers/md/raid5.c +7 -0
diff -ur -X /home/suparna/dontdiff linux-2.5.33/drivers/md/raid5.c linux-2.5.33-bio/drivers/md/raid5.c
@@ -431,6 +431,8 @@
 	dev->vec.bv_page = dev->page;
 	dev->vec.bv_len = STRIPE_SIZE;
 	dev->vec.bv_offset = 0;
+	dev->req.bi_voffset = 0;
+	dev->req.bi_endvoffset = STRIPE_SIZE;
 
 	dev->req.bi_sector = sh->sector;
 	dev->req.bi_private = sh;
@@ -592,6 +594,11 @@
 	for (;bio && bio->bi_sector < sector+STRIPE_SECTORS;
 		bio = bio->bi_next) {
 		int page_offset;
+
+		/* Can't handle arbitrary bio pieces yet */
+		BIO_BUG_ON(bio_startoffset(bio) != 0);
+		BIO_BUG_ON(bio_endoffset(bio) != 0);
+
 		if (bio->bi_sector >= sector)
 			page_offset = (signed)(bio->bi_sector - sector) * 512;
 		else 
drivers/scsi/scsi_lib.c +3 -2
diff -ur -X /home/suparna/dontdiff linux-2.5.33/drivers/scsi/scsi_lib.c linux-2.5.33-bio/drivers/scsi/scsi_lib.c
@@ -481,10 +481,11 @@
 		if (SCpnt->buffer != req->buffer) {
 			if (rq_data_dir(req) == READ) {
 				unsigned long flags;
-				char *to = bio_kmap_irq(req->bio, &flags);
+				/* Todo: check if this is all we need to do */
+				char *to = rq_map_buffer(req, &flags);
 
 				memcpy(to, SCpnt->buffer, SCpnt->bufflen);
-				bio_kunmap_irq(to, &flags);
+				rq_unmap_buffer(to, &flags);
 			}
 			kfree(SCpnt->buffer);
 		}
fs/bio.c +30 -0
diff -ur -X /home/suparna/dontdiff linux-2.5.33/fs/bio.c linux-2.5.33-bio/fs/bio.c
@@ -178,6 +178,28 @@
 	}
 }
 
+/* Perform some sanity checks on the bio vectors, size and offsets */
+int bio_consistent(struct bio *bio)
+{
+	struct bio_vec *bvec;
+	int i;
+	int size = 0;
+
+	/* Verify that the size is consistent with sigma vec len */
+	bio_for_each_segment(bvec, bio, i)
+		size += bvec->bv_len;
+
+	/* Adjust for both ends */
+	size -= bio_startoffset(bio) + bio_endoffset(bio);
+
+	if (size != bio->bi_size)
+		return 0; /* size mismatch */
+
+	/* Place any other checks here */
+
+	return 1;
+}
+
 inline int bio_phys_segments(request_queue_t *q, struct bio *bio)
 {
 	if (unlikely(!(bio->bi_flags & (1 << BIO_SEG_VALID))))
@@ -225,6 +247,8 @@
 	}
 	bio->bi_size = bio_src->bi_size;
 	bio->bi_max = bio_src->bi_max;
+	bio->bi_voffset = bio_src->bi_voffset;
+	bio->bi_endvoffset = bio_src->bi_endvoffset;
 }
 
 /**
@@ -312,6 +336,9 @@
 	b->bi_vcnt = bio->bi_vcnt;
 	b->bi_size = bio->bi_size;
 
+	b->bi_voffset = bio->bi_voffset;
+	b->bi_endvoffset = bio->bi_endvoffset;
+
 	return b;
 
 oom:
@@ -424,6 +451,9 @@
 	}
 
 queue_io:
+	bio->bi_voffset = bio_iovec(bio)->bv_offset;
+	bio->bi_endvoffset = __BVEC_END(bio)->bv_offset +
+		__BVEC_END(bio)->bv_len;
 	submit_bio(rw, bio);
 
 	if (total_nr_pages)
fs/direct-io.c +3 -0
diff -ur -X /home/suparna/dontdiff linux-2.5.33/fs/direct-io.c linux-2.5.33-bio/fs/direct-io.c
@@ -193,6 +193,9 @@
 
 	bio->bi_vcnt = bio->bi_idx;
 	bio->bi_idx = 0;
+	bio->bi_voffset = __BVEC_START(bio)->bv_offset;
+	bio->bi_endvoffset = __BVEC_END(bio)->bv_offset +
+		__BVEC_END(bio)->bv_len;
 	bio->bi_private = dio;
 	atomic_inc(&dio->bio_count);
 	submit_bio(dio->rw, bio);
fs/jfs/jfs_logmgr.c +6 -0
diff -ur -X /home/suparna/dontdiff linux-2.5.33/fs/jfs/jfs_logmgr.c linux-2.5.33-bio/fs/jfs/jfs_logmgr.c
@@ -1775,6 +1775,9 @@
 	bio->bi_vcnt = 1;
 	bio->bi_idx = 0;
 	bio->bi_size = LOGPSIZE;
+	bio->bi_voffset = __BVEC_START(bio)->bv_offset;
+	bio->bi_endvoffset = __BVEC_END(bio)->bv_offset +
+		__BVEC_END(bio)->bv_len;
 
 	bio->bi_end_io = lbmIODone;
 	bio->bi_private = bp;
@@ -1917,6 +1920,9 @@
 	bio->bi_vcnt = 1;
 	bio->bi_idx = 0;
 	bio->bi_size = LOGPSIZE;
+	bio->bi_voffset = __BVEC_START(bio)->bv_offset;
+	bio->bi_endvoffset = __BVEC_END(bio)->bv_offset +
+		__BVEC_END(bio)->bv_len;
 
 	bio->bi_end_io = lbmIODone;
 	bio->bi_private = bp;
fs/mpage.c +3 -0
diff -ur -X /home/suparna/dontdiff linux-2.5.33/fs/mpage.c linux-2.5.33-bio/fs/mpage.c
@@ -84,6 +84,9 @@
 {
 	bio->bi_vcnt = bio->bi_idx;
 	bio->bi_idx = 0;
+	bio->bi_voffset = __BVEC_START(bio)->bv_offset;
+	bio->bi_endvoffset = __BVEC_END(bio)->bv_offset +
+		__BVEC_END(bio)->bv_len;
 	bio->bi_end_io = mpage_end_io_read;
 	if (rw == WRITE)
 		bio->bi_end_io = mpage_end_io_write;
include/linux/bio.h +63 -11

147 lines not on this page · raw message

include/linux/blk.h +4 -0
diff -ur -X /home/suparna/dontdiff linux-2.5.33/include/linux/blk.h linux-2.5.33-bio/include/linux/blk.h
@@ -40,6 +40,7 @@
 
 extern int end_that_request_first(struct request *, int, int);
 extern void end_that_request_last(struct request *);
+extern int process_that_request_first(struct request *, unsigned int);
 struct request *elv_next_request(request_queue_t *q);
 
 static inline void blkdev_dequeue_request(struct request *req)
@@ -50,11 +51,14 @@
 		elv_remove_request(req->q, req);
 }
 
+
+
 #define _elv_add_request_core(q, rq, where, plug)			\
 	do {								\
 		if ((plug))						\
 			blk_plug_device((q));				\
 		(q)->elevator.elevator_add_req_fn((q), (rq), (where));	\
+		if ((rq)->bio) BIO_BUG_ON(!bio_consistent((rq)->bio)); \
 	} while (0)
 
 #define _elv_add_request(q, rq, back, p) do {				      \
include/linux/blkdev.h +53 -8

97 lines not on this page · raw message

mm/highmem.c +5 -1
diff -ur -X /home/suparna/dontdiff linux-2.5.33/mm/highmem.c linux-2.5.33-bio/mm/highmem.c
@@ -432,8 +432,10 @@
 	bio->bi_rw = (*bio_orig)->bi_rw;
 
 	bio->bi_vcnt = (*bio_orig)->bi_vcnt;
-	bio->bi_idx = 0;
+	bio->bi_idx = (*bio_orig)->bi_idx;
 	bio->bi_size = (*bio_orig)->bi_size;
+	bio->bi_voffset = (*bio_orig)->bi_voffset;
+	bio->bi_endvoffset = (*bio_orig)->bi_endvoffset;
 
 	if (pool == page_pool) {
 		if (rw & WRITE)
@@ -447,6 +449,8 @@
 			bio->bi_end_io = bounce_end_io_read_isa;
 	}
 
+	BIO_BUG_ON(!bio_consistent(bio)); /* debug only */
+
 	bio->bi_private = *bio_orig;
 	*bio_orig = bio;
 }
mm/page_io.c +3 -0
diff -ur -X /home/suparna/dontdiff linux-2.5.33/mm/page_io.c linux-2.5.33-bio/mm/page_io.c
@@ -42,6 +42,9 @@
 		bio->bi_vcnt = 1;
 		bio->bi_idx = 0;
 		bio->bi_size = PAGE_SIZE;
+		bio->bi_voffset = __BVEC_START(bio)->bv_offset;
+		bio->bi_endvoffset = __BVEC_END(bio)->bv_offset +
+		__BVEC_END(bio)->bv_len;
 		bio->bi_end_io = end_io;
 	}
 	return bio;