From: NeilBrown If raid1 decides it needs to resync it will do so even if there is only one working device. This is pointless. With this patch we abort resync if there is nowhere to write to. Signed-off-by: Neil Brown Signed-off-by: Andrew Morton --- 25-akpm/drivers/md/md.c | 2 +- 25-akpm/drivers/md/raid1.c | 13 +++++++++++++ 2 files changed, 14 insertions(+), 1 deletion(-) diff -puN drivers/md/md.c~md-6-of-8-abort-the-resync-of-raid1-there-is-only-one-device drivers/md/md.c --- 25/drivers/md/md.c~md-6-of-8-abort-the-resync-of-raid1-there-is-only-one-device 2004-05-28 00:22:13.777196320 -0700 +++ 25-akpm/drivers/md/md.c 2004-05-28 00:22:13.785195104 -0700 @@ -3317,7 +3317,7 @@ static void md_do_sync(mddev_t *mddev) j += sectors; if (j>1) mddev->curr_resync = j; - if (last_check + window > j) + if (last_check + window > j || j == max_sectors) continue; last_check = j; diff -puN drivers/md/raid1.c~md-6-of-8-abort-the-resync-of-raid1-there-is-only-one-device drivers/md/raid1.c --- 25/drivers/md/raid1.c~md-6-of-8-abort-the-resync-of-raid1-there-is-only-one-device 2004-05-28 00:22:13.778196168 -0700 +++ 25-akpm/drivers/md/raid1.c 2004-05-28 00:22:13.786194952 -0700 @@ -1005,6 +1005,7 @@ static int sync_request(mddev_t *mddev, sector_t max_sector, nr_sectors; int disk; int i; + int write_targets = 0; if (!conf->r1buf_pool) if (init_resync(conf)) @@ -1081,12 +1082,24 @@ static int sync_request(mddev_t *mddev, sector_nr + RESYNC_SECTORS > mddev->recovery_cp)) { bio->bi_rw = WRITE; bio->bi_end_io = end_sync_write; + write_targets ++; } else continue; bio->bi_sector = sector_nr + conf->mirrors[i].rdev->data_offset; bio->bi_bdev = conf->mirrors[i].rdev->bdev; bio->bi_private = r1_bio; } + if (write_targets == 0) { + /* There is nowhere to write, so all non-sync + * drives must be failed - so we are finished + */ + int rv = max_sector - sector_nr; + md_done_sync(mddev, rv, 1); + put_buf(r1_bio); + atomic_dec(&conf->mirrors[disk].rdev->nr_pending); + return rv; + } + nr_sectors = 0; do { struct page *page; _