<html><head><meta name="color-scheme" content="light dark"></head><body><pre style="word-wrap: break-word; white-space: pre-wrap;">
From: NeilBrown &lt;neilb@cse.unsw.edu.au&gt;

next_r1 is never used, so it can just go.

read_bio isn't needed as we can easily use one of the pointers in the
write_bios array - write_bios[-&gt;read_disk].  So rename "write_bios" to "bios"
and store the pointer to the read bio in there.



---

 drivers/md/raid1.c         |   55 +++++++++++++++------------------------------
 include/linux/raid/raid1.h |    6 +---
 2 files changed, 21 insertions(+), 40 deletions(-)

diff -puN drivers/md/raid1.c~md-04-r1_bio-cleanup drivers/md/raid1.c
--- 25/drivers/md/raid1.c~md-04-r1_bio-cleanup	2004-02-05 22:05:54.000000000 -0800
+++ 25-akpm/drivers/md/raid1.c	2004-02-05 22:05:54.000000000 -0800
@@ -42,7 +42,7 @@ static void * r1bio_pool_alloc(int gfp_f
 	mddev_t *mddev = data;
 	r1bio_t *r1_bio;
 
-	/* allocate a r1bio with room for raid_disks entries in the write_bios array */
+	/* allocate a r1bio with room for raid_disks entries in the bios array */
 	r1_bio = kmalloc(sizeof(r1bio_t) + sizeof(struct bio*)*mddev-&gt;raid_disks,
 			 gfp_flags);
 	if (r1_bio)
@@ -132,19 +132,10 @@ static void put_all_bios(conf_t *conf, r
 {
 	int i;
 
-	if (r1_bio-&gt;read_bio) {
-		if (atomic_read(&amp;r1_bio-&gt;read_bio-&gt;bi_cnt) != 1)
-			BUG();
-		bio_put(r1_bio-&gt;read_bio);
-		r1_bio-&gt;read_bio = NULL;
-	}
 	for (i = 0; i &lt; conf-&gt;raid_disks; i++) {
-		struct bio **bio = r1_bio-&gt;write_bios + i;
-		if (*bio) {
-			if (atomic_read(&amp;(*bio)-&gt;bi_cnt) != 1)
-				BUG();
+		struct bio **bio = r1_bio-&gt;bios + i;
+		if (*bio)
 			bio_put(*bio);
-		}
 		*bio = NULL;
 	}
 }
@@ -291,8 +282,6 @@ static int raid1_end_read_request(struct
 
 	update_head_pos(mirror, r1_bio);
 
-	if (!r1_bio-&gt;read_bio)
-		BUG();
 	/*
 	 * we have only one bio on the read side
 	 */
@@ -323,7 +312,7 @@ static int raid1_end_write_request(struc
 		return 1;
 
 	for (mirror = 0; mirror &lt; conf-&gt;raid_disks; mirror++)
-		if (r1_bio-&gt;write_bios[mirror] == bio)
+		if (r1_bio-&gt;bios[mirror] == bio)
 			break;
 
 	/*
@@ -345,8 +334,6 @@ static int raid1_end_write_request(struc
 
 	update_head_pos(mirror, r1_bio);
 
-	if (r1_bio-&gt;read_bio)
-		BUG();
 	/*
 	 *
 	 * Let's see if all mirrored write operations have finished
@@ -531,9 +518,8 @@ static int make_request(request_queue_t 
 		mirror = conf-&gt;mirrors + read_balance(conf, bio, r1_bio);
 
 		read_bio = bio_clone(bio, GFP_NOIO);
-		if (r1_bio-&gt;read_bio)
-			BUG();
-		r1_bio-&gt;read_bio = read_bio;
+
+		r1_bio-&gt;bios[r1_bio-&gt;read_disk] = read_bio;
 
 		read_bio-&gt;bi_sector = r1_bio-&gt;sector + mirror-&gt;rdev-&gt;data_offset;
 		read_bio-&gt;bi_bdev = mirror-&gt;rdev-&gt;bdev;
@@ -550,16 +536,16 @@ static int make_request(request_queue_t 
 	 */
 	/* first select target devices under spinlock and
 	 * inc refcount on their rdev.  Record them by setting
-	 * write_bios[x] to bio
+	 * bios[x] to bio
 	 */
 	spin_lock_irq(&amp;conf-&gt;device_lock);
 	for (i = 0;  i &lt; disks; i++) {
 		if (conf-&gt;mirrors[i].rdev &amp;&amp;
 		    !conf-&gt;mirrors[i].rdev-&gt;faulty) {
 			atomic_inc(&amp;conf-&gt;mirrors[i].rdev-&gt;nr_pending);
-			r1_bio-&gt;write_bios[i] = bio;
+			r1_bio-&gt;bios[i] = bio;
 		} else
-			r1_bio-&gt;write_bios[i] = NULL;
+			r1_bio-&gt;bios[i] = NULL;
 	}
 	spin_unlock_irq(&amp;conf-&gt;device_lock);
 
@@ -567,11 +553,11 @@ static int make_request(request_queue_t 
 	md_write_start(mddev);
 	for (i = 0; i &lt; disks; i++) {
 		struct bio *mbio;
-		if (!r1_bio-&gt;write_bios[i])
+		if (!r1_bio-&gt;bios[i])
 			continue;
 
 		mbio = bio_clone(bio, GFP_NOIO);
-		r1_bio-&gt;write_bios[i] = mbio;
+		r1_bio-&gt;bios[i] = mbio;
 
 		mbio-&gt;bi_sector	= r1_bio-&gt;sector + conf-&gt;mirrors[i].rdev-&gt;data_offset;
 		mbio-&gt;bi_bdev = conf-&gt;mirrors[i].rdev-&gt;bdev;
@@ -773,7 +759,7 @@ static int end_sync_read(struct bio *bio
 	if (bio-&gt;bi_size)
 		return 1;
 
-	if (r1_bio-&gt;read_bio != bio)
+	if (r1_bio-&gt;bios[r1_bio-&gt;read_disk] != bio)
 		BUG();
 	update_head_pos(r1_bio-&gt;read_disk, r1_bio);
 	/*
@@ -804,7 +790,7 @@ static int end_sync_write(struct bio *bi
 		return 1;
 
 	for (i = 0; i &lt; conf-&gt;raid_disks; i++)
-		if (r1_bio-&gt;write_bios[i] == bio) {
+		if (r1_bio-&gt;bios[i] == bio) {
 			mirror = i;
 			break;
 		}
@@ -850,11 +836,11 @@ static void sync_request_write(mddev_t *
 
 	spin_lock_irq(&amp;conf-&gt;device_lock);
 	for (i = 0; i &lt; disks ; i++) {
-		r1_bio-&gt;write_bios[i] = NULL;
+		r1_bio-&gt;bios[i] = NULL;
 		if (!conf-&gt;mirrors[i].rdev || 
 		    conf-&gt;mirrors[i].rdev-&gt;faulty)
 			continue;
-		if (conf-&gt;mirrors[i].rdev-&gt;bdev == bio-&gt;bi_bdev)
+		if (i == r1_bio-&gt;read_disk)
 			/*
 			 * we read from here, no need to write
 			 */
@@ -866,16 +852,16 @@ static void sync_request_write(mddev_t *
 			 */
 			continue;
 		atomic_inc(&amp;conf-&gt;mirrors[i].rdev-&gt;nr_pending);
-		r1_bio-&gt;write_bios[i] = bio;
+		r1_bio-&gt;bios[i] = bio;
 	}
 	spin_unlock_irq(&amp;conf-&gt;device_lock);
 
 	atomic_set(&amp;r1_bio-&gt;remaining, 1);
 	for (i = disks; i-- ; ) {
-		if (!r1_bio-&gt;write_bios[i])
+		if (!r1_bio-&gt;bios[i])
 			continue;
 		mbio = bio_clone(bio, GFP_NOIO);
-		r1_bio-&gt;write_bios[i] = mbio;
+		r1_bio-&gt;bios[i] = mbio;
 		mbio-&gt;bi_bdev = conf-&gt;mirrors[i].rdev-&gt;bdev;
 		mbio-&gt;bi_sector = r1_bio-&gt;sector + conf-&gt;mirrors[i].rdev-&gt;data_offset;
 		mbio-&gt;bi_end_io	= end_sync_write;
@@ -1056,10 +1042,7 @@ static int sync_request(mddev_t *mddev, 
 	read_bio-&gt;bi_end_io = end_sync_read;
 	read_bio-&gt;bi_rw = READ;
 	read_bio-&gt;bi_private = r1_bio;
-
-	if (r1_bio-&gt;read_bio)
-		BUG();
-	r1_bio-&gt;read_bio = read_bio;
+	r1_bio-&gt;bios[r1_bio-&gt;read_disk] = read_bio;
 
 	md_sync_acct(mirror-&gt;rdev, nr_sectors);
 
diff -puN include/linux/raid/raid1.h~md-04-r1_bio-cleanup include/linux/raid/raid1.h
--- 25/include/linux/raid/raid1.h~md-04-r1_bio-cleanup	2004-02-05 22:05:54.000000000 -0800
+++ 25-akpm/include/linux/raid/raid1.h	2004-02-05 22:05:54.000000000 -0800
@@ -62,18 +62,16 @@ struct r1bio_s {
 	 */
 	struct bio		*master_bio;
 	/*
-	 * if the IO is in READ direction, then this bio is used:
+	 * if the IO is in READ direction, then this is where we read
 	 */
-	struct bio		*read_bio;
 	int			read_disk;
 
-	r1bio_t			*next_r1; /* next for retry or in free list */
 	struct list_head	retry_list;
 	/*
 	 * if the IO is in WRITE direction, then multiple bios are used.
 	 * We choose the number when they are allocated.
 	 */
-	struct bio		*write_bios[0];
+	struct bio		*bios[0];
 };
 
 /* bits for r1bio.state */

_
</pre></body></html>