patch-2.3.9 linux/drivers/block/raid5.c

Next file: linux/drivers/block/rd.c
Previous file: linux/drivers/block/raid1.c
Back to the patch index
Back to the overall index

diff -u --recursive --new-file v2.3.8/linux/drivers/block/raid5.c linux/drivers/block/raid5.c
@@ -586,13 +586,15 @@
 
 	b_data = ((volatile struct buffer_head *) bh)->b_data;
 	memset (bh, 0, sizeof (struct buffer_head));
-	init_buffer(bh, dev, block, raid5_end_request, sh);
+	init_buffer(bh, raid5_end_request, sh);
+	bh->b_dev = dev;
+	bh->b_blocknr = block;
 	((volatile struct buffer_head *) bh)->b_data = b_data;
 
 	bh->b_rdev	= raid_conf->disks[i].dev;
 	bh->b_rsector   = sh->sector;
 
-	bh->b_state	= (1 << BH_Req);
+	bh->b_state	= (1 << BH_Req) | (1 << BH_Mapped);
 	bh->b_size	= sh->size;
 	bh->b_list	= BUF_LOCKED;
 }
@@ -1030,19 +1032,24 @@
 				if (sh->bh_new[i])
 					continue;
 				block = (int) compute_blocknr(sh, i);
-				bh = find_buffer(MKDEV(MD_MAJOR, minor), block, sh->size);
-				if (bh && bh->b_count == 0 && buffer_dirty(bh) && !buffer_locked(bh)) {
-					PRINTK(("Whee.. sector %lu, index %d (%d) found in the buffer cache!\n", sh->sector, i, block));
-					add_stripe_bh(sh, bh, i, WRITE);
-					sh->new[i] = 0;
-					nr++; nr_write++;
-					if (sh->bh_old[i]) {
-						nr_cache_overwrite++;
-						nr_cache_other--;
-					} else if (!operational[i]) {
-						nr_failed_overwrite++;
-						nr_failed_other--;
+				bh = get_hash_table(MKDEV(MD_MAJOR, minor), block, sh->size);
+				if (bh) {
+					if (atomic_read(&bh->b_count) == 1 &&
+					    buffer_dirty(bh) &&
+					    !buffer_locked(bh)) {
+						PRINTK(("Whee.. sector %lu, index %d (%d) found in the buffer cache!\n", sh->sector, i, block));
+						add_stripe_bh(sh, bh, i, WRITE);
+						sh->new[i] = 0;
+						nr++; nr_write++;
+						if (sh->bh_old[i]) {
+							nr_cache_overwrite++;
+							nr_cache_other--;
+						} else if (!operational[i]) {
+							nr_failed_overwrite++;
+							nr_failed_other--;
+						}
 					}
+					atomic_dec(&bh->b_count);
 				}
 			}
 		}

FUNET's LINUX-ADM group, linux-adm@nic.funet.fi
TCL-scripts by Sam Shen (who was at: slshen@lbl.gov)