aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorNamhyung Kim <namhyung@gmail.com>2011-10-06 23:22:53 -0400
committerNeilBrown <neilb@suse.de>2011-10-06 23:22:53 -0400
commitba3ae3bee317f0a5db813c026c8a8c113a4e40fb (patch)
tree30a8c9d55afc32156973a3b1efb1cec94f4411d4
parente4f869d9de18bc8272df8d0ab764178aa24bdf33 (diff)
md/raid1: factor out common bio handling code
When normal-write and sync-read/write bio completes, we should find out the disk number the bio belongs to. Factor those common code out to a separate function. Signed-off-by: Namhyung Kim <namhyung@gmail.com> Signed-off-by: NeilBrown <neilb@suse.de>
-rw-r--r--drivers/md/raid1.c44
1 files changed, 24 insertions, 20 deletions
diff --git a/drivers/md/raid1.c b/drivers/md/raid1.c
index d9587dffe533..a0c02fb8af2a 100644
--- a/drivers/md/raid1.c
+++ b/drivers/md/raid1.c
@@ -268,6 +268,24 @@ static inline void update_head_pos(int disk, r1bio_t *r1_bio)
268 r1_bio->sector + (r1_bio->sectors); 268 r1_bio->sector + (r1_bio->sectors);
269} 269}
270 270
271/*
272 * Find the disk number which triggered given bio
273 */
274static int find_bio_disk(r1bio_t *r1_bio, struct bio *bio)
275{
276 int mirror;
277 int raid_disks = r1_bio->mddev->raid_disks;
278
279 for (mirror = 0; mirror < raid_disks; mirror++)
280 if (r1_bio->bios[mirror] == bio)
281 break;
282
283 BUG_ON(mirror == raid_disks);
284 update_head_pos(mirror, r1_bio);
285
286 return mirror;
287}
288
271static void raid1_end_read_request(struct bio *bio, int error) 289static void raid1_end_read_request(struct bio *bio, int error)
272{ 290{
273 int uptodate = test_bit(BIO_UPTODATE, &bio->bi_flags); 291 int uptodate = test_bit(BIO_UPTODATE, &bio->bi_flags);
@@ -361,10 +379,7 @@ static void raid1_end_write_request(struct bio *bio, int error)
361 conf_t *conf = r1_bio->mddev->private; 379 conf_t *conf = r1_bio->mddev->private;
362 struct bio *to_put = NULL; 380 struct bio *to_put = NULL;
363 381
364 382 mirror = find_bio_disk(r1_bio, bio);
365 for (mirror = 0; mirror < conf->raid_disks; mirror++)
366 if (r1_bio->bios[mirror] == bio)
367 break;
368 383
369 /* 384 /*
370 * 'one mirror IO has finished' event handler: 385 * 'one mirror IO has finished' event handler:
@@ -400,8 +415,6 @@ static void raid1_end_write_request(struct bio *bio, int error)
400 } 415 }
401 } 416 }
402 417
403 update_head_pos(mirror, r1_bio);
404
405 if (behind) { 418 if (behind) {
406 if (test_bit(WriteMostly, &conf->mirrors[mirror].rdev->flags)) 419 if (test_bit(WriteMostly, &conf->mirrors[mirror].rdev->flags))
407 atomic_dec(&r1_bio->behind_remaining); 420 atomic_dec(&r1_bio->behind_remaining);
@@ -1344,13 +1357,10 @@ abort:
1344static void end_sync_read(struct bio *bio, int error) 1357static void end_sync_read(struct bio *bio, int error)
1345{ 1358{
1346 r1bio_t *r1_bio = bio->bi_private; 1359 r1bio_t *r1_bio = bio->bi_private;
1347 int i;
1348 1360
1349 for (i=r1_bio->mddev->raid_disks; i--; ) 1361 /* this will call update_head_pos() */
1350 if (r1_bio->bios[i] == bio) 1362 find_bio_disk(r1_bio, bio);
1351 break; 1363
1352 BUG_ON(i < 0);
1353 update_head_pos(i, r1_bio);
1354 /* 1364 /*
1355 * we have read a block, now it needs to be re-written, 1365 * we have read a block, now it needs to be re-written,
1356 * or re-read if the read failed. 1366 * or re-read if the read failed.
@@ -1369,16 +1379,12 @@ static void end_sync_write(struct bio *bio, int error)
1369 r1bio_t *r1_bio = bio->bi_private; 1379 r1bio_t *r1_bio = bio->bi_private;
1370 mddev_t *mddev = r1_bio->mddev; 1380 mddev_t *mddev = r1_bio->mddev;
1371 conf_t *conf = mddev->private; 1381 conf_t *conf = mddev->private;
1372 int i;
1373 int mirror=0; 1382 int mirror=0;
1374 sector_t first_bad; 1383 sector_t first_bad;
1375 int bad_sectors; 1384 int bad_sectors;
1376 1385
1377 for (i = 0; i < conf->raid_disks; i++) 1386 mirror = find_bio_disk(r1_bio, bio);
1378 if (r1_bio->bios[i] == bio) { 1387
1379 mirror = i;
1380 break;
1381 }
1382 if (!uptodate) { 1388 if (!uptodate) {
1383 sector_t sync_blocks = 0; 1389 sector_t sync_blocks = 0;
1384 sector_t s = r1_bio->sector; 1390 sector_t s = r1_bio->sector;
@@ -1404,8 +1410,6 @@ static void end_sync_write(struct bio *bio, int error)
1404 ) 1410 )
1405 set_bit(R1BIO_MadeGood, &r1_bio->state); 1411 set_bit(R1BIO_MadeGood, &r1_bio->state);
1406 1412
1407 update_head_pos(mirror, r1_bio);
1408
1409 if (atomic_dec_and_test(&r1_bio->remaining)) { 1413 if (atomic_dec_and_test(&r1_bio->remaining)) {
1410 int s = r1_bio->sectors; 1414 int s = r1_bio->sectors;
1411 if (test_bit(R1BIO_MadeGood, &r1_bio->state) || 1415 if (test_bit(R1BIO_MadeGood, &r1_bio->state) ||