From 263be06224ba5d3fe0fff456330f8851ad69bc23 Mon Sep 17 00:00:00 2001 From: Namhyung Kim Date: Fri, 7 Oct 2011 14:22:53 +1100 Subject: [PATCH] --- yaml --- r: 269249 b: refs/heads/master c: ba3ae3bee317f0a5db813c026c8a8c113a4e40fb h: refs/heads/master i: 269247: b1d800bc823db66b43392a79aeaa416c69e58b97 v: v3 --- [refs] | 2 +- trunk/drivers/md/raid1.c | 44 ++++++++++++++++++++++------------------ 2 files changed, 25 insertions(+), 21 deletions(-) diff --git a/[refs] b/[refs] index b4aa159b34d2..d2073e0f0f39 100644 --- a/[refs] +++ b/[refs] @@ -1,2 +1,2 @@ --- -refs/heads/master: e4f869d9de18bc8272df8d0ab764178aa24bdf33 +refs/heads/master: ba3ae3bee317f0a5db813c026c8a8c113a4e40fb diff --git a/trunk/drivers/md/raid1.c b/trunk/drivers/md/raid1.c index d9587dffe533..a0c02fb8af2a 100644 --- a/trunk/drivers/md/raid1.c +++ b/trunk/drivers/md/raid1.c @@ -268,6 +268,24 @@ static inline void update_head_pos(int disk, r1bio_t *r1_bio) r1_bio->sector + (r1_bio->sectors); } +/* + * Find the disk number which triggered given bio + */ +static int find_bio_disk(r1bio_t *r1_bio, struct bio *bio) +{ + int mirror; + int raid_disks = r1_bio->mddev->raid_disks; + + for (mirror = 0; mirror < raid_disks; mirror++) + if (r1_bio->bios[mirror] == bio) + break; + + BUG_ON(mirror == raid_disks); + update_head_pos(mirror, r1_bio); + + return mirror; +} + static void raid1_end_read_request(struct bio *bio, int error) { int uptodate = test_bit(BIO_UPTODATE, &bio->bi_flags); @@ -361,10 +379,7 @@ static void raid1_end_write_request(struct bio *bio, int error) conf_t *conf = r1_bio->mddev->private; struct bio *to_put = NULL; - - for (mirror = 0; mirror < conf->raid_disks; mirror++) - if (r1_bio->bios[mirror] == bio) - break; + mirror = find_bio_disk(r1_bio, bio); /* * 'one mirror IO has finished' event handler: @@ -400,8 +415,6 @@ static void raid1_end_write_request(struct bio *bio, int error) } } - update_head_pos(mirror, r1_bio); - if (behind) { if (test_bit(WriteMostly, &conf->mirrors[mirror].rdev->flags)) atomic_dec(&r1_bio->behind_remaining); @@ -1344,13 +1357,10 @@ static int raid1_remove_disk(mddev_t *mddev, int number) static void end_sync_read(struct bio *bio, int error) { r1bio_t *r1_bio = bio->bi_private; - int i; - for (i=r1_bio->mddev->raid_disks; i--; ) - if (r1_bio->bios[i] == bio) - break; - BUG_ON(i < 0); - update_head_pos(i, r1_bio); + /* this will call update_head_pos() */ + find_bio_disk(r1_bio, bio); + /* * we have read a block, now it needs to be re-written, * or re-read if the read failed. @@ -1369,16 +1379,12 @@ static void end_sync_write(struct bio *bio, int error) r1bio_t *r1_bio = bio->bi_private; mddev_t *mddev = r1_bio->mddev; conf_t *conf = mddev->private; - int i; int mirror=0; sector_t first_bad; int bad_sectors; - for (i = 0; i < conf->raid_disks; i++) - if (r1_bio->bios[i] == bio) { - mirror = i; - break; - } + mirror = find_bio_disk(r1_bio, bio); + if (!uptodate) { sector_t sync_blocks = 0; sector_t s = r1_bio->sector; @@ -1404,8 +1410,6 @@ static void end_sync_write(struct bio *bio, int error) ) set_bit(R1BIO_MadeGood, &r1_bio->state); - update_head_pos(mirror, r1_bio); - if (atomic_dec_and_test(&r1_bio->remaining)) { int s = r1_bio->sectors; if (test_bit(R1BIO_MadeGood, &r1_bio->state) ||