aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorNeilBrown <neilb@suse.de>2011-12-22 18:17:56 -0500
committerNeilBrown <neilb@suse.de>2011-12-22 18:17:56 -0500
commit8f19ccb2fd70deb1f278be5e75076074cfddee46 (patch)
tree59419e814d4d02dfdefaf6f5ef152c3468c890e8
parent301946364e0aa67c4cfaec82e94c389993c9f7c6 (diff)
md/raid1: Allocate spare to store replacement devices and their bios.
In RAID1, a replacement is much like a normal device, so we just double the size of the relevant arrays and look at all possible devices for reads and writes. This means that the array looks like it is now double the size in some way - we need to be careful about that. In particular, we checking if the array is still degraded while creating a recovery request we need to only consider the first 'half' - i.e. the real (non-replacement) devices. Signed-off-by: NeilBrown <neilb@suse.de>
-rw-r--r--drivers/md/raid1.c64
-rw-r--r--drivers/md/raid1.h7
2 files changed, 40 insertions, 31 deletions
diff --git a/drivers/md/raid1.c b/drivers/md/raid1.c
index ab8113cff7c9..e7768e37f36a 100644
--- a/drivers/md/raid1.c
+++ b/drivers/md/raid1.c
@@ -135,7 +135,7 @@ out_free_pages:
135 put_page(r1_bio->bios[j]->bi_io_vec[i].bv_page); 135 put_page(r1_bio->bios[j]->bi_io_vec[i].bv_page);
136 j = -1; 136 j = -1;
137out_free_bio: 137out_free_bio:
138 while ( ++j < pi->raid_disks ) 138 while (++j < pi->raid_disks)
139 bio_put(r1_bio->bios[j]); 139 bio_put(r1_bio->bios[j]);
140 r1bio_pool_free(r1_bio, data); 140 r1bio_pool_free(r1_bio, data);
141 return NULL; 141 return NULL;
@@ -164,7 +164,7 @@ static void put_all_bios(struct r1conf *conf, struct r1bio *r1_bio)
164{ 164{
165 int i; 165 int i;
166 166
167 for (i = 0; i < conf->raid_disks; i++) { 167 for (i = 0; i < conf->raid_disks * 2; i++) {
168 struct bio **bio = r1_bio->bios + i; 168 struct bio **bio = r1_bio->bios + i;
169 if (!BIO_SPECIAL(*bio)) 169 if (!BIO_SPECIAL(*bio))
170 bio_put(*bio); 170 bio_put(*bio);
@@ -185,7 +185,7 @@ static void put_buf(struct r1bio *r1_bio)
185 struct r1conf *conf = r1_bio->mddev->private; 185 struct r1conf *conf = r1_bio->mddev->private;
186 int i; 186 int i;
187 187
188 for (i=0; i<conf->raid_disks; i++) { 188 for (i = 0; i < conf->raid_disks * 2; i++) {
189 struct bio *bio = r1_bio->bios[i]; 189 struct bio *bio = r1_bio->bios[i];
190 if (bio->bi_end_io) 190 if (bio->bi_end_io)
191 rdev_dec_pending(conf->mirrors[i].rdev, r1_bio->mddev); 191 rdev_dec_pending(conf->mirrors[i].rdev, r1_bio->mddev);
@@ -280,11 +280,11 @@ static int find_bio_disk(struct r1bio *r1_bio, struct bio *bio)
280 struct r1conf *conf = r1_bio->mddev->private; 280 struct r1conf *conf = r1_bio->mddev->private;
281 int raid_disks = conf->raid_disks; 281 int raid_disks = conf->raid_disks;
282 282
283 for (mirror = 0; mirror < raid_disks; mirror++) 283 for (mirror = 0; mirror < raid_disks * 2; mirror++)
284 if (r1_bio->bios[mirror] == bio) 284 if (r1_bio->bios[mirror] == bio)
285 break; 285 break;
286 286
287 BUG_ON(mirror == raid_disks); 287 BUG_ON(mirror == raid_disks * 2);
288 update_head_pos(mirror, r1_bio); 288 update_head_pos(mirror, r1_bio);
289 289
290 return mirror; 290 return mirror;
@@ -506,7 +506,7 @@ static int read_balance(struct r1conf *conf, struct r1bio *r1_bio, int *max_sect
506 start_disk = conf->last_used; 506 start_disk = conf->last_used;
507 } 507 }
508 508
509 for (i = 0 ; i < conf->raid_disks ; i++) { 509 for (i = 0 ; i < conf->raid_disks * 2 ; i++) {
510 sector_t dist; 510 sector_t dist;
511 sector_t first_bad; 511 sector_t first_bad;
512 int bad_sectors; 512 int bad_sectors;
@@ -975,7 +975,7 @@ read_again:
975 */ 975 */
976 plugged = mddev_check_plugged(mddev); 976 plugged = mddev_check_plugged(mddev);
977 977
978 disks = conf->raid_disks; 978 disks = conf->raid_disks * 2;
979 retry_write: 979 retry_write:
980 blocked_rdev = NULL; 980 blocked_rdev = NULL;
981 rcu_read_lock(); 981 rcu_read_lock();
@@ -989,7 +989,8 @@ read_again:
989 } 989 }
990 r1_bio->bios[i] = NULL; 990 r1_bio->bios[i] = NULL;
991 if (!rdev || test_bit(Faulty, &rdev->flags)) { 991 if (!rdev || test_bit(Faulty, &rdev->flags)) {
992 set_bit(R1BIO_Degraded, &r1_bio->state); 992 if (i < conf->raid_disks)
993 set_bit(R1BIO_Degraded, &r1_bio->state);
993 continue; 994 continue;
994 } 995 }
995 996
@@ -1493,7 +1494,7 @@ static int fix_sync_read_error(struct r1bio *r1_bio)
1493 } 1494 }
1494 } 1495 }
1495 d++; 1496 d++;
1496 if (d == conf->raid_disks) 1497 if (d == conf->raid_disks * 2)
1497 d = 0; 1498 d = 0;
1498 } while (!success && d != r1_bio->read_disk); 1499 } while (!success && d != r1_bio->read_disk);
1499 1500
@@ -1510,7 +1511,7 @@ static int fix_sync_read_error(struct r1bio *r1_bio)
1510 mdname(mddev), 1511 mdname(mddev),
1511 bdevname(bio->bi_bdev, b), 1512 bdevname(bio->bi_bdev, b),
1512 (unsigned long long)r1_bio->sector); 1513 (unsigned long long)r1_bio->sector);
1513 for (d = 0; d < conf->raid_disks; d++) { 1514 for (d = 0; d < conf->raid_disks * 2; d++) {
1514 rdev = conf->mirrors[d].rdev; 1515 rdev = conf->mirrors[d].rdev;
1515 if (!rdev || test_bit(Faulty, &rdev->flags)) 1516 if (!rdev || test_bit(Faulty, &rdev->flags))
1516 continue; 1517 continue;
@@ -1536,7 +1537,7 @@ static int fix_sync_read_error(struct r1bio *r1_bio)
1536 /* write it back and re-read */ 1537 /* write it back and re-read */
1537 while (d != r1_bio->read_disk) { 1538 while (d != r1_bio->read_disk) {
1538 if (d == 0) 1539 if (d == 0)
1539 d = conf->raid_disks; 1540 d = conf->raid_disks * 2;
1540 d--; 1541 d--;
1541 if (r1_bio->bios[d]->bi_end_io != end_sync_read) 1542 if (r1_bio->bios[d]->bi_end_io != end_sync_read)
1542 continue; 1543 continue;
@@ -1551,7 +1552,7 @@ static int fix_sync_read_error(struct r1bio *r1_bio)
1551 d = start; 1552 d = start;
1552 while (d != r1_bio->read_disk) { 1553 while (d != r1_bio->read_disk) {
1553 if (d == 0) 1554 if (d == 0)
1554 d = conf->raid_disks; 1555 d = conf->raid_disks * 2;
1555 d--; 1556 d--;
1556 if (r1_bio->bios[d]->bi_end_io != end_sync_read) 1557 if (r1_bio->bios[d]->bi_end_io != end_sync_read)
1557 continue; 1558 continue;
@@ -1584,7 +1585,7 @@ static int process_checks(struct r1bio *r1_bio)
1584 int primary; 1585 int primary;
1585 int i; 1586 int i;
1586 1587
1587 for (primary = 0; primary < conf->raid_disks; primary++) 1588 for (primary = 0; primary < conf->raid_disks * 2; primary++)
1588 if (r1_bio->bios[primary]->bi_end_io == end_sync_read && 1589 if (r1_bio->bios[primary]->bi_end_io == end_sync_read &&
1589 test_bit(BIO_UPTODATE, &r1_bio->bios[primary]->bi_flags)) { 1590 test_bit(BIO_UPTODATE, &r1_bio->bios[primary]->bi_flags)) {
1590 r1_bio->bios[primary]->bi_end_io = NULL; 1591 r1_bio->bios[primary]->bi_end_io = NULL;
@@ -1592,7 +1593,7 @@ static int process_checks(struct r1bio *r1_bio)
1592 break; 1593 break;
1593 } 1594 }
1594 r1_bio->read_disk = primary; 1595 r1_bio->read_disk = primary;
1595 for (i = 0; i < conf->raid_disks; i++) { 1596 for (i = 0; i < conf->raid_disks * 2; i++) {
1596 int j; 1597 int j;
1597 int vcnt = r1_bio->sectors >> (PAGE_SHIFT- 9); 1598 int vcnt = r1_bio->sectors >> (PAGE_SHIFT- 9);
1598 struct bio *pbio = r1_bio->bios[primary]; 1599 struct bio *pbio = r1_bio->bios[primary];
@@ -1656,7 +1657,7 @@ static void sync_request_write(struct mddev *mddev, struct r1bio *r1_bio)
1656{ 1657{
1657 struct r1conf *conf = mddev->private; 1658 struct r1conf *conf = mddev->private;
1658 int i; 1659 int i;
1659 int disks = conf->raid_disks; 1660 int disks = conf->raid_disks * 2;
1660 struct bio *bio, *wbio; 1661 struct bio *bio, *wbio;
1661 1662
1662 bio = r1_bio->bios[r1_bio->read_disk]; 1663 bio = r1_bio->bios[r1_bio->read_disk];
@@ -1737,7 +1738,7 @@ static void fix_read_error(struct r1conf *conf, int read_disk,
1737 success = 1; 1738 success = 1;
1738 else { 1739 else {
1739 d++; 1740 d++;
1740 if (d == conf->raid_disks) 1741 if (d == conf->raid_disks * 2)
1741 d = 0; 1742 d = 0;
1742 } 1743 }
1743 } while (!success && d != read_disk); 1744 } while (!success && d != read_disk);
@@ -1753,7 +1754,7 @@ static void fix_read_error(struct r1conf *conf, int read_disk,
1753 start = d; 1754 start = d;
1754 while (d != read_disk) { 1755 while (d != read_disk) {
1755 if (d==0) 1756 if (d==0)
1756 d = conf->raid_disks; 1757 d = conf->raid_disks * 2;
1757 d--; 1758 d--;
1758 rdev = conf->mirrors[d].rdev; 1759 rdev = conf->mirrors[d].rdev;
1759 if (rdev && 1760 if (rdev &&
@@ -1765,7 +1766,7 @@ static void fix_read_error(struct r1conf *conf, int read_disk,
1765 while (d != read_disk) { 1766 while (d != read_disk) {