@@ -8914,6 +8914,77 @@ void md_allow_write(struct mddev *mddev)
89148914}
89158915EXPORT_SYMBOL_GPL (md_allow_write );
89168916
8917+ static sector_t md_sync_max_sectors (struct mddev * mddev ,
8918+ enum sync_action action )
8919+ {
8920+ switch (action ) {
8921+ case ACTION_RESYNC :
8922+ case ACTION_CHECK :
8923+ case ACTION_REPAIR :
8924+ atomic64_set (& mddev -> resync_mismatches , 0 );
8925+ fallthrough ;
8926+ case ACTION_RESHAPE :
8927+ return mddev -> resync_max_sectors ;
8928+ case ACTION_RECOVER :
8929+ return mddev -> dev_sectors ;
8930+ default :
8931+ return 0 ;
8932+ }
8933+ }
8934+
8935+ static sector_t md_sync_position (struct mddev * mddev , enum sync_action action )
8936+ {
8937+ sector_t start = 0 ;
8938+ struct md_rdev * rdev ;
8939+
8940+ switch (action ) {
8941+ case ACTION_CHECK :
8942+ case ACTION_REPAIR :
8943+ return mddev -> resync_min ;
8944+ case ACTION_RESYNC :
8945+ if (!mddev -> bitmap )
8946+ return mddev -> recovery_cp ;
8947+ return 0 ;
8948+ case ACTION_RESHAPE :
8949+ /*
8950+ * If the original node aborts reshaping then we continue the
8951+ * reshaping, so set again to avoid restart reshape from the
8952+ * first beginning
8953+ */
8954+ if (mddev_is_clustered (mddev ) &&
8955+ mddev -> reshape_position != MaxSector )
8956+ return mddev -> reshape_position ;
8957+ return 0 ;
8958+ case ACTION_RECOVER :
8959+ start = MaxSector ;
8960+ rcu_read_lock ();
8961+ rdev_for_each_rcu (rdev , mddev )
8962+ if (rdev -> raid_disk >= 0 &&
8963+ !test_bit (Journal , & rdev -> flags ) &&
8964+ !test_bit (Faulty , & rdev -> flags ) &&
8965+ !test_bit (In_sync , & rdev -> flags ) &&
8966+ rdev -> recovery_offset < start )
8967+ start = rdev -> recovery_offset ;
8968+ rcu_read_unlock ();
8969+
8970+ /* If there is a bitmap, we need to make sure all
8971+ * writes that started before we added a spare
8972+ * complete before we start doing a recovery.
8973+ * Otherwise the write might complete and (via
8974+ * bitmap_endwrite) set a bit in the bitmap after the
8975+ * recovery has checked that bit and skipped that
8976+ * region.
8977+ */
8978+ if (mddev -> bitmap ) {
8979+ mddev -> pers -> quiesce (mddev , 1 );
8980+ mddev -> pers -> quiesce (mddev , 0 );
8981+ }
8982+ return start ;
8983+ default :
8984+ return MaxSector ;
8985+ }
8986+ }
8987+
89178988#define SYNC_MARKS 10
89188989#define SYNC_MARK_STEP (3*HZ)
89198990#define UPDATE_FREQUENCY (5*60*HZ)
@@ -9032,56 +9103,8 @@ void md_do_sync(struct md_thread *thread)
90329103 spin_unlock (& all_mddevs_lock );
90339104 } while (mddev -> curr_resync < MD_RESYNC_DELAYED );
90349105
9035- j = 0 ;
9036- if (test_bit (MD_RECOVERY_SYNC , & mddev -> recovery )) {
9037- /* resync follows the size requested by the personality,
9038- * which defaults to physical size, but can be virtual size
9039- */
9040- max_sectors = mddev -> resync_max_sectors ;
9041- atomic64_set (& mddev -> resync_mismatches , 0 );
9042- /* we don't use the checkpoint if there's a bitmap */
9043- if (test_bit (MD_RECOVERY_REQUESTED , & mddev -> recovery ))
9044- j = mddev -> resync_min ;
9045- else if (!mddev -> bitmap )
9046- j = mddev -> recovery_cp ;
9047-
9048- } else if (test_bit (MD_RECOVERY_RESHAPE , & mddev -> recovery )) {
9049- max_sectors = mddev -> resync_max_sectors ;
9050- /*
9051- * If the original node aborts reshaping then we continue the
9052- * reshaping, so set j again to avoid restart reshape from the
9053- * first beginning
9054- */
9055- if (mddev_is_clustered (mddev ) &&
9056- mddev -> reshape_position != MaxSector )
9057- j = mddev -> reshape_position ;
9058- } else {
9059- /* recovery follows the physical size of devices */
9060- max_sectors = mddev -> dev_sectors ;
9061- j = MaxSector ;
9062- rcu_read_lock ();
9063- rdev_for_each_rcu (rdev , mddev )
9064- if (rdev -> raid_disk >= 0 &&
9065- !test_bit (Journal , & rdev -> flags ) &&
9066- !test_bit (Faulty , & rdev -> flags ) &&
9067- !test_bit (In_sync , & rdev -> flags ) &&
9068- rdev -> recovery_offset < j )
9069- j = rdev -> recovery_offset ;
9070- rcu_read_unlock ();
9071-
9072- /* If there is a bitmap, we need to make sure all
9073- * writes that started before we added a spare
9074- * complete before we start doing a recovery.
9075- * Otherwise the write might complete and (via
9076- * bitmap_endwrite) set a bit in the bitmap after the
9077- * recovery has checked that bit and skipped that
9078- * region.
9079- */
9080- if (mddev -> bitmap ) {
9081- mddev -> pers -> quiesce (mddev , 1 );
9082- mddev -> pers -> quiesce (mddev , 0 );
9083- }
9084- }
9106+ max_sectors = md_sync_max_sectors (mddev , action );
9107+ j = md_sync_position (mddev , action );
90859108
90869109 pr_info ("md: %s of RAID array %s\n" , desc , mdname (mddev ));
90879110 pr_debug ("md: minimum _guaranteed_ speed: %d KB/sec/disk.\n" , speed_min (mddev ));
0 commit comments