md: improve usefulness and accuracy of sysfs file md/sync_completed.

The sync_completed file reports how much of a resync (or recovery or
reshape) has been completed.
However due to the possibility of out-of-order completion of writes,
it is not certain to be accurate.

We have an internal value - mddev->curr_resync_completed - which is an
accurate value (though it might not always be quite so uptodate).

So:
- make curr_resync_completed be uptodate a little more often,
particularly when raid5 reshape updates status in the metadata
- report curr_resync_completed in the sysfs file
- allow poll/select to report all updates to md/sync_completed.

This makes sync_completed completed usable by any external metadata
handler that wants to record this status information in its metadata.

Signed-off-by: NeilBrown <neilb@suse.de>

NeilBrown acb180b0 6d56e278

+27 -12
+1
drivers/md/bitmap.c
··· 1479 s += blocks; 1480 } 1481 bitmap->last_end_sync = jiffies; 1482 } 1483 1484 static void bitmap_set_memory_bits(struct bitmap *bitmap, sector_t offset, int needed)
··· 1479 s += blocks; 1480 } 1481 bitmap->last_end_sync = jiffies; 1482 + sysfs_notify(&bitmap->mddev->kobj, NULL, "sync_completed"); 1483 } 1484 1485 static void bitmap_set_memory_bits(struct bitmap *bitmap, sector_t offset, int needed)
+22 -12
drivers/md/md.c
··· 2017 clear_bit(MD_CHANGE_PENDING, &mddev->flags); 2018 spin_unlock_irq(&mddev->write_lock); 2019 wake_up(&mddev->sb_wait); 2020 2021 } 2022 ··· 3488 { 3489 unsigned long max_sectors, resync; 3490 3491 if (test_bit(MD_RECOVERY_SYNC, &mddev->recovery)) 3492 max_sectors = mddev->resync_max_sectors; 3493 else 3494 max_sectors = mddev->dev_sectors; 3495 3496 - resync = (mddev->curr_resync - atomic_read(&mddev->recovery_active)); 3497 return sprintf(page, "%lu / %lu\n", resync, max_sectors); 3498 } 3499 ··· 6343 sector_t sectors; 6344 6345 skipped = 0; 6346 - if (j >= mddev->resync_max) { 6347 - sysfs_notify(&mddev->kobj, NULL, "sync_completed"); 6348 - wait_event(mddev->recovery_wait, 6349 - mddev->resync_max > j 6350 - || kthread_should_stop()); 6351 - } 6352 - if (kthread_should_stop()) 6353 - goto interrupted; 6354 6355 - if (mddev->curr_resync > mddev->curr_resync_completed && 6356 - (mddev->curr_resync - mddev->curr_resync_completed) 6357 - > (max_sectors >> 4)) { 6358 /* time to update curr_resync_completed */ 6359 blk_unplug(mddev->queue); 6360 wait_event(mddev->recovery_wait, ··· 6356 mddev->curr_resync_completed = 6357 mddev->curr_resync; 6358 set_bit(MD_CHANGE_CLEAN, &mddev->flags); 6359 } 6360 sectors = mddev->pers->sync_request(mddev, j, &skipped, 6361 currspeed < speed_min(mddev)); 6362 if (sectors == 0) { ··· 6474 6475 skip: 6476 mddev->curr_resync = 0; 6477 mddev->resync_min = 0; 6478 mddev->resync_max = MaxSector; 6479 sysfs_notify(&mddev->kobj, NULL, "sync_completed");
··· 2017 clear_bit(MD_CHANGE_PENDING, &mddev->flags); 2018 spin_unlock_irq(&mddev->write_lock); 2019 wake_up(&mddev->sb_wait); 2020 + if (test_bit(MD_RECOVERY_RUNNING, &mddev->recovery)) 2021 + sysfs_notify(&mddev->kobj, NULL, "sync_completed"); 2022 2023 } 2024 ··· 3486 { 3487 unsigned long max_sectors, resync; 3488 3489 + if (!test_bit(MD_RECOVERY_RUNNING, &mddev->recovery)) 3490 + return sprintf(page, "none\n"); 3491 + 3492 if (test_bit(MD_RECOVERY_SYNC, &mddev->recovery)) 3493 max_sectors = mddev->resync_max_sectors; 3494 else 3495 max_sectors = mddev->dev_sectors; 3496 3497 + resync = mddev->curr_resync_completed; 3498 return sprintf(page, "%lu / %lu\n", resync, max_sectors); 3499 } 3500 ··· 6338 sector_t sectors; 6339 6340 skipped = 0; 6341 6342 + if ((mddev->curr_resync > mddev->curr_resync_completed && 6343 + (mddev->curr_resync - mddev->curr_resync_completed) 6344 + > (max_sectors >> 4)) || 6345 + j >= mddev->resync_max 6346 + ) { 6347 /* time to update curr_resync_completed */ 6348 blk_unplug(mddev->queue); 6349 wait_event(mddev->recovery_wait, ··· 6357 mddev->curr_resync_completed = 6358 mddev->curr_resync; 6359 set_bit(MD_CHANGE_CLEAN, &mddev->flags); 6360 + sysfs_notify(&mddev->kobj, NULL, "sync_completed"); 6361 } 6362 + 6363 + if (j >= mddev->resync_max) 6364 + wait_event(mddev->recovery_wait, 6365 + mddev->resync_max > j 6366 + || kthread_should_stop()); 6367 + 6368 + if (kthread_should_stop()) 6369 + goto interrupted; 6370 + 6371 sectors = mddev->pers->sync_request(mddev, j, &skipped, 6372 currspeed < speed_min(mddev)); 6373 if (sectors == 0) { ··· 6465 6466 skip: 6467 mddev->curr_resync = 0; 6468 + mddev->curr_resync_completed = 0; 6469 mddev->resync_min = 0; 6470 mddev->resync_max = MaxSector; 6471 sysfs_notify(&mddev->kobj, NULL, "sync_completed");
+4
drivers/md/raid5.c
··· 3845 wait_event(conf->wait_for_overlap, 3846 atomic_read(&conf->reshape_stripes)==0); 3847 mddev->reshape_position = conf->reshape_progress; 3848 conf->reshape_checkpoint = jiffies; 3849 set_bit(MD_CHANGE_DEVS, &mddev->flags); 3850 md_wakeup_thread(mddev->thread); ··· 3855 conf->reshape_safe = mddev->reshape_position; 3856 spin_unlock_irq(&conf->device_lock); 3857 wake_up(&conf->wait_for_overlap); 3858 } 3859 3860 if (mddev->delta_disks < 0) { ··· 3945 wait_event(conf->wait_for_overlap, 3946 atomic_read(&conf->reshape_stripes) == 0); 3947 mddev->reshape_position = conf->reshape_progress; 3948 conf->reshape_checkpoint = jiffies; 3949 set_bit(MD_CHANGE_DEVS, &mddev->flags); 3950 md_wakeup_thread(mddev->thread); ··· 3956 conf->reshape_safe = mddev->reshape_position; 3957 spin_unlock_irq(&conf->device_lock); 3958 wake_up(&conf->wait_for_overlap); 3959 } 3960 return reshape_sectors; 3961 }
··· 3845 wait_event(conf->wait_for_overlap, 3846 atomic_read(&conf->reshape_stripes)==0); 3847 mddev->reshape_position = conf->reshape_progress; 3848 + mddev->curr_resync_completed = mddev->curr_resync; 3849 conf->reshape_checkpoint = jiffies; 3850 set_bit(MD_CHANGE_DEVS, &mddev->flags); 3851 md_wakeup_thread(mddev->thread); ··· 3854 conf->reshape_safe = mddev->reshape_position; 3855 spin_unlock_irq(&conf->device_lock); 3856 wake_up(&conf->wait_for_overlap); 3857 + sysfs_notify(&mddev->kobj, NULL, "sync_completed"); 3858 } 3859 3860 if (mddev->delta_disks < 0) { ··· 3943 wait_event(conf->wait_for_overlap, 3944 atomic_read(&conf->reshape_stripes) == 0); 3945 mddev->reshape_position = conf->reshape_progress; 3946 + mddev->curr_resync_completed = mddev->curr_resync; 3947 conf->reshape_checkpoint = jiffies; 3948 set_bit(MD_CHANGE_DEVS, &mddev->flags); 3949 md_wakeup_thread(mddev->thread); ··· 3953 conf->reshape_safe = mddev->reshape_position; 3954 spin_unlock_irq(&conf->device_lock); 3955 wake_up(&conf->wait_for_overlap); 3956 + sysfs_notify(&mddev->kobj, NULL, "sync_completed"); 3957 } 3958 return reshape_sectors; 3959 }