aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/md/md.c
diff options
context:
space:
mode:
Diffstat (limited to 'drivers/md/md.c')
-rw-r--r--drivers/md/md.c111
1 files changed, 67 insertions, 44 deletions
diff --git a/drivers/md/md.c b/drivers/md/md.c
index ed5727c089a9..fccc8343a250 100644
--- a/drivers/md/md.c
+++ b/drivers/md/md.c
@@ -2017,6 +2017,8 @@ repeat:
2017 clear_bit(MD_CHANGE_PENDING, &mddev->flags); 2017 clear_bit(MD_CHANGE_PENDING, &mddev->flags);
2018 spin_unlock_irq(&mddev->write_lock); 2018 spin_unlock_irq(&mddev->write_lock);
2019 wake_up(&mddev->sb_wait); 2019 wake_up(&mddev->sb_wait);
2020 if (test_bit(MD_RECOVERY_RUNNING, &mddev->recovery))
2021 sysfs_notify(&mddev->kobj, NULL, "sync_completed");
2020 2022
2021} 2023}
2022 2024
@@ -2086,6 +2088,7 @@ state_store(mdk_rdev_t *rdev, const char *buf, size_t len)
2086 * -writemostly - clears write_mostly 2088 * -writemostly - clears write_mostly
2087 * blocked - sets the Blocked flag 2089 * blocked - sets the Blocked flag
2088 * -blocked - clears the Blocked flag 2090 * -blocked - clears the Blocked flag
2091 * insync - sets Insync providing device isn't active
2089 */ 2092 */
2090 int err = -EINVAL; 2093 int err = -EINVAL;
2091 if (cmd_match(buf, "faulty") && rdev->mddev->pers) { 2094 if (cmd_match(buf, "faulty") && rdev->mddev->pers) {
@@ -2118,6 +2121,9 @@ state_store(mdk_rdev_t *rdev, const char *buf, size_t len)
2118 md_wakeup_thread(rdev->mddev->thread); 2121 md_wakeup_thread(rdev->mddev->thread);
2119 2122
2120 err = 0; 2123 err = 0;
2124 } else if (cmd_match(buf, "insync") && rdev->raid_disk == -1) {
2125 set_bit(In_sync, &rdev->flags);
2126 err = 0;
2121 } 2127 }
2122 if (!err && rdev->sysfs_state) 2128 if (!err && rdev->sysfs_state)
2123 sysfs_notify_dirent(rdev->sysfs_state); 2129 sysfs_notify_dirent(rdev->sysfs_state);
@@ -2190,7 +2196,7 @@ slot_store(mdk_rdev_t *rdev, const char *buf, size_t len)
2190 } else if (rdev->mddev->pers) { 2196 } else if (rdev->mddev->pers) {
2191 mdk_rdev_t *rdev2; 2197 mdk_rdev_t *rdev2;
2192 /* Activating a spare .. or possibly reactivating 2198 /* Activating a spare .. or possibly reactivating
2193 * if we every get bitmaps working here. 2199 * if we ever get bitmaps working here.
2194 */ 2200 */
2195 2201
2196 if (rdev->raid_disk != -1) 2202 if (rdev->raid_disk != -1)
@@ -3060,11 +3066,8 @@ array_state_store(mddev_t *mddev, const char *buf, size_t len)
3060 } else 3066 } else
3061 err = -EBUSY; 3067 err = -EBUSY;
3062 spin_unlock_irq(&mddev->write_lock); 3068 spin_unlock_irq(&mddev->write_lock);
3063 } else { 3069 } else
3064 mddev->ro = 0; 3070 err = -EINVAL;
3065 mddev->recovery_cp = MaxSector;
3066 err = do_md_run(mddev);
3067 }
3068 break; 3071 break;
3069 case active: 3072 case active:
3070 if (mddev->pers) { 3073 if (mddev->pers) {
@@ -3482,12 +3485,15 @@ sync_completed_show(mddev_t *mddev, char *page)
3482{ 3485{
3483 unsigned long max_sectors, resync; 3486 unsigned long max_sectors, resync;
3484 3487
3488 if (!test_bit(MD_RECOVERY_RUNNING, &mddev->recovery))
3489 return sprintf(page, "none\n");
3490
3485 if (test_bit(MD_RECOVERY_SYNC, &mddev->recovery)) 3491 if (test_bit(MD_RECOVERY_SYNC, &mddev->recovery))
3486 max_sectors = mddev->resync_max_sectors; 3492 max_sectors = mddev->resync_max_sectors;
3487 else 3493 else
3488 max_sectors = mddev->dev_sectors; 3494 max_sectors = mddev->dev_sectors;
3489 3495
3490 resync = (mddev->curr_resync - atomic_read(&mddev->recovery_active)); 3496 resync = mddev->curr_resync_completed;
3491 return sprintf(page, "%lu / %lu\n", resync, max_sectors); 3497 return sprintf(page, "%lu / %lu\n", resync, max_sectors);
3492} 3498}
3493 3499
@@ -4288,6 +4294,7 @@ static int do_md_stop(mddev_t * mddev, int mode, int is_open)
4288{ 4294{
4289 int err = 0; 4295 int err = 0;
4290 struct gendisk *disk = mddev->gendisk; 4296 struct gendisk *disk = mddev->gendisk;
4297 mdk_rdev_t *rdev;
4291 4298
4292 if (atomic_read(&mddev->openers) > is_open) { 4299 if (atomic_read(&mddev->openers) > is_open) {
4293 printk("md: %s still in use.\n",mdname(mddev)); 4300 printk("md: %s still in use.\n",mdname(mddev));
@@ -4330,6 +4337,13 @@ static int do_md_stop(mddev_t * mddev, int mode, int is_open)
4330 /* tell userspace to handle 'inactive' */ 4337 /* tell userspace to handle 'inactive' */
4331 sysfs_notify_dirent(mddev->sysfs_state); 4338 sysfs_notify_dirent(mddev->sysfs_state);
4332 4339
4340 list_for_each_entry(rdev, &mddev->disks, same_set)
4341 if (rdev->raid_disk >= 0) {
4342 char nm[20];
4343 sprintf(nm, "rd%d", rdev->raid_disk);
4344 sysfs_remove_link(&mddev->kobj, nm);
4345 }
4346
4333 set_capacity(disk, 0); 4347 set_capacity(disk, 0);
4334 mddev->changed = 1; 4348 mddev->changed = 1;
4335 4349
@@ -4350,7 +4364,6 @@ static int do_md_stop(mddev_t * mddev, int mode, int is_open)
4350 * Free resources if final stop 4364 * Free resources if final stop
4351 */ 4365 */
4352 if (mode == 0) { 4366 if (mode == 0) {
4353 mdk_rdev_t *rdev;
4354 4367
4355 printk(KERN_INFO "md: %s stopped.\n", mdname(mddev)); 4368 printk(KERN_INFO "md: %s stopped.\n", mdname(mddev));
4356 4369
@@ -4362,13 +4375,6 @@ static int do_md_stop(mddev_t * mddev, int mode, int is_open)
4362 } 4375 }
4363 mddev->bitmap_offset = 0; 4376 mddev->bitmap_offset = 0;
4364 4377
4365 list_for_each_entry(rdev, &mddev->disks, same_set)
4366 if (rdev->raid_disk >= 0) {
4367 char nm[20];
4368 sprintf(nm, "rd%d", rdev->raid_disk);
4369 sysfs_remove_link(&mddev->kobj, nm);
4370 }
4371
4372 /* make sure all md_delayed_delete calls have finished */ 4378 /* make sure all md_delayed_delete calls have finished */
4373 flush_scheduled_work(); 4379 flush_scheduled_work();
4374 4380
@@ -5696,37 +5702,38 @@ static void status_unused(struct seq_file *seq)
5696 5702
5697static void status_resync(struct seq_file *seq, mddev_t * mddev) 5703static void status_resync(struct seq_file *seq, mddev_t * mddev)
5698{ 5704{
5699 sector_t max_blocks, resync, res; 5705 sector_t max_sectors, resync, res;
5700 unsigned long dt, db, rt; 5706 unsigned long dt, db;
5707 sector_t rt;
5701 int scale; 5708 int scale;
5702 unsigned int per_milli; 5709 unsigned int per_milli;
5703 5710
5704 resync = (mddev->curr_resync - atomic_read(&mddev->recovery_active))/2; 5711 resync = mddev->curr_resync - atomic_read(&mddev->recovery_active);
5705 5712
5706 if (test_bit(MD_RECOVERY_SYNC, &mddev->recovery)) 5713 if (test_bit(MD_RECOVERY_SYNC, &mddev->recovery))
5707 max_blocks = mddev->resync_max_sectors >> 1; 5714 max_sectors = mddev->resync_max_sectors;
5708 else 5715 else
5709 max_blocks = mddev->dev_sectors / 2; 5716 max_sectors = mddev->dev_sectors;
5710 5717
5711 /* 5718 /*
5712 * Should not happen. 5719 * Should not happen.
5713 */ 5720 */
5714 if (!max_blocks) { 5721 if (!max_sectors) {
5715 MD_BUG(); 5722 MD_BUG();
5716 return; 5723 return;
5717 } 5724 }
5718 /* Pick 'scale' such that (resync>>scale)*1000 will fit 5725 /* Pick 'scale' such that (resync>>scale)*1000 will fit
5719 * in a sector_t, and (max_blocks>>scale) will fit in a 5726 * in a sector_t, and (max_sectors>>scale) will fit in a
5720 * u32, as those are the requirements for sector_div. 5727 * u32, as those are the requirements for sector_div.
5721 * Thus 'scale' must be at least 10 5728 * Thus 'scale' must be at least 10
5722 */ 5729 */
5723 scale = 10; 5730 scale = 10;
5724 if (sizeof(sector_t) > sizeof(unsigned long)) { 5731 if (sizeof(sector_t) > sizeof(unsigned long)) {
5725 while ( max_blocks/2 > (1ULL<<(scale+32))) 5732 while ( max_sectors/2 > (1ULL<<(scale+32)))
5726 scale++; 5733 scale++;
5727 } 5734 }
5728 res = (resync>>scale)*1000; 5735 res = (resync>>scale)*1000;
5729 sector_div(res, (u32)((max_blocks>>scale)+1)); 5736 sector_div(res, (u32)((max_sectors>>scale)+1));
5730 5737
5731 per_milli = res; 5738 per_milli = res;
5732 { 5739 {
@@ -5747,25 +5754,35 @@ static void status_resync(struct seq_file *seq, mddev_t * mddev)
5747 (test_bit(MD_RECOVERY_SYNC, &mddev->recovery) ? 5754 (test_bit(MD_RECOVERY_SYNC, &mddev->recovery) ?
5748 "resync" : "recovery"))), 5755 "resync" : "recovery"))),
5749 per_milli/10, per_milli % 10, 5756 per_milli/10, per_milli % 10,
5750 (unsigned long long) resync, 5757 (unsigned long long) resync/2,
5751 (unsigned long long) max_blocks); 5758 (unsigned long long) max_sectors/2);
5752 5759
5753 /* 5760 /*
5754 * We do not want to overflow, so the order of operands and
5755 * the * 100 / 100 trick are important. We do a +1 to be
5756 * safe against division by zero. We only estimate anyway.
5757 *
5758 * dt: time from mark until now 5761 * dt: time from mark until now
5759 * db: blocks written from mark until now 5762 * db: blocks written from mark until now
5760 * rt: remaining time 5763 * rt: remaining time
5764 *
5765 * rt is a sector_t, so could be 32bit or 64bit.
5766 * So we divide before multiply in case it is 32bit and close
5767 * to the limit.
5768 * We scale the divisor (db) by 32 to avoid loosing precision
5769 * near the end of resync when the number of remaining sectors
5770 * is close to 'db'.
5771 * We then divide rt by 32 after multiplying by db to compensate.
5772 * The '+1' avoids division by zero if db is very small.
5761 */ 5773 */
5762 dt = ((jiffies - mddev->resync_mark) / HZ); 5774 dt = ((jiffies - mddev->resync_mark) / HZ);
5763 if (!dt) dt++; 5775 if (!dt) dt++;
5764 db = (mddev->curr_mark_cnt - atomic_read(&mddev->recovery_active)) 5776 db = (mddev->curr_mark_cnt - atomic_read(&mddev->recovery_active))
5765 - mddev->resync_mark_cnt; 5777 - mddev->resync_mark_cnt;
5766 rt = (dt * ((unsigned long)(max_blocks-resync) / (db/2/100+1)))/100;
5767 5778
5768 seq_printf(seq, " finish=%lu.%lumin", rt / 60, (rt % 60)/6); 5779 rt = max_sectors - resync; /* number of remaining sectors */
5780 sector_div(rt, db/32+1);
5781 rt *= dt;
5782 rt >>= 5;
5783
5784 seq_printf(seq, " finish=%lu.%lumin", (unsigned long)rt / 60,
5785 ((unsigned long)rt % 60)/6);
5769 5786
5770 seq_printf(seq, " speed=%ldK/sec", db/2/dt); 5787 seq_printf(seq, " speed=%ldK/sec", db/2/dt);
5771} 5788}
@@ -5956,7 +5973,7 @@ static int md_seq_show(struct seq_file *seq, void *v)
5956 return 0; 5973 return 0;
5957} 5974}
5958 5975
5959static struct seq_operations md_seq_ops = { 5976static const struct seq_operations md_seq_ops = {
5960 .start = md_seq_start, 5977 .start = md_seq_start,
5961 .next = md_seq_next, 5978 .next = md_seq_next,
5962 .stop = md_seq_stop, 5979 .stop = md_seq_stop,
@@ -6334,18 +6351,13 @@ void md_do_sync(mddev_t *mddev)
6334 sector_t sectors; 6351 sector_t sectors;
6335 6352
6336 skipped = 0; 6353 skipped = 0;
6337 if (j >= mddev->resync_max) {
6338 sysfs_notify(&mddev->kobj, NULL, "sync_completed");
6339 wait_event(mddev->recovery_wait,
6340 mddev->resync_max > j
6341 || kthread_should_stop());
6342 }
6343 if (kthread_should_stop())
6344 goto interrupted;
6345 6354
6346 if (mddev->curr_resync > mddev->curr_resync_completed && 6355 if ((mddev->curr_resync > mddev->curr_resync_completed &&
6347 (mddev->curr_resync - mddev->curr_resync_completed) 6356 (mddev->curr_resync - mddev->curr_resync_completed)
6348 > (max_sectors >> 4)) { 6357 > (max_sectors >> 4)) ||
6358 (j - mddev->curr_resync_completed)*2
6359 >= mddev->resync_max - mddev->curr_resync_completed
6360 ) {
6349 /* time to update curr_resync_completed */ 6361 /* time to update curr_resync_completed */
6350 blk_unplug(mddev->queue); 6362 blk_unplug(mddev->queue);
6351 wait_event(mddev->recovery_wait, 6363 wait_event(mddev->recovery_wait,
@@ -6353,7 +6365,17 @@ void md_do_sync(mddev_t *mddev)
6353 mddev->curr_resync_completed = 6365 mddev->curr_resync_completed =
6354 mddev->curr_resync; 6366 mddev->curr_resync;
6355 set_bit(MD_CHANGE_CLEAN, &mddev->flags); 6367 set_bit(MD_CHANGE_CLEAN, &mddev->flags);
6368 sysfs_notify(&mddev->kobj, NULL, "sync_completed");
6356 } 6369 }
6370
6371 if (j >= mddev->resync_max)
6372 wait_event(mddev->recovery_wait,
6373 mddev->resync_max > j
6374 || kthread_should_stop());
6375
6376 if (kthread_should_stop())
6377 goto interrupted;
6378
6357 sectors = mddev->pers->sync_request(mddev, j, &skipped, 6379 sectors = mddev->pers->sync_request(mddev, j, &skipped,
6358 currspeed < speed_min(mddev)); 6380 currspeed < speed_min(mddev));
6359 if (sectors == 0) { 6381 if (sectors == 0) {
@@ -6461,6 +6483,7 @@ void md_do_sync(mddev_t *mddev)
6461 6483
6462 skip: 6484 skip:
6463 mddev->curr_resync = 0; 6485 mddev->curr_resync = 0;
6486 mddev->curr_resync_completed = 0;
6464 mddev->resync_min = 0; 6487 mddev->resync_min = 0;
6465 mddev->resync_max = MaxSector; 6488 mddev->resync_max = MaxSector;
6466 sysfs_notify(&mddev->kobj, NULL, "sync_completed"); 6489 sysfs_notify(&mddev->kobj, NULL, "sync_completed");