Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

Factor out code into md_should_do_recovery()

In md_check_recovery(), use new helper to make code cleaner.

Link: https://lore.kernel.org/linux-raid/e62894c8-d916-94bc-ef48-3c60e6e1fc5d@huawei.com
Signed-off-by: Wu Guanghao <wuguanghao3@huawei.com>
Reviewed-by: Yu Kuai <yukuai3@fnnas.com>
Signed-off-by: Yu Kuai <yukuai@fnnas.com>

authored by

Wu Guanghao and committed by
Yu Kuai
082d680f 0dc76205

+47 -12
+47 -12
drivers/md/md.c
··· 9978 9978 md_reap_sync_thread(mddev); 9979 9979 } 9980 9980 9981 + static bool md_should_do_recovery(struct mddev *mddev) 9982 + { 9983 + /* 9984 + * As long as one of the following flags is set, 9985 + * recovery needs to do or cleanup. 9986 + */ 9987 + if (test_bit(MD_RECOVERY_NEEDED, &mddev->recovery) || 9988 + test_bit(MD_RECOVERY_DONE, &mddev->recovery)) 9989 + return true; 9990 + 9991 + /* 9992 + * If no flags are set and it is in read-only status, 9993 + * there is nothing to do. 9994 + */ 9995 + if (!md_is_rdwr(mddev)) 9996 + return false; 9997 + 9998 + /* 9999 + * MD_SB_CHANGE_PENDING indicates that the array is switching from clean to 10000 + * active, and no action is needed for now. 10001 + * All other MD_SB_* flags require to update the superblock. 10002 + */ 10003 + if (mddev->sb_flags & ~ (1<<MD_SB_CHANGE_PENDING)) 10004 + return true; 10005 + 10006 + /* 10007 + * If the array is not using external metadata and there has been no data 10008 + * written for some time, then the array's status needs to be set to 10009 + * in_sync. 10010 + */ 10011 + if (mddev->external == 0 && mddev->safemode == 1) 10012 + return true; 10013 + 10014 + /* 10015 + * When the system is about to restart or the process receives an signal, 10016 + * the array needs to be synchronized as soon as possible. 10017 + * Once the data synchronization is completed, need to change the array 10018 + * status to in_sync. 10019 + */ 10020 + if (mddev->safemode == 2 && !mddev->in_sync && 10021 + mddev->resync_offset == MaxSector) 10022 + return true; 10023 + 10024 + return false; 10025 + } 10026 + 9981 10027 /* 9982 10028 * This routine is regularly called by all per-raid-array threads to 9983 10029 * deal with generic issues like resync and super-block update. ··· 10060 10014 flush_signals(current); 10061 10015 } 10062 10016 10063 - if (!md_is_rdwr(mddev) && 10064 - !test_bit(MD_RECOVERY_NEEDED, &mddev->recovery) && 10065 - !test_bit(MD_RECOVERY_DONE, &mddev->recovery)) 10066 - return; 10067 - if ( ! ( 10068 - (mddev->sb_flags & ~ (1<<MD_SB_CHANGE_PENDING)) || 10069 - test_bit(MD_RECOVERY_NEEDED, &mddev->recovery) || 10070 - test_bit(MD_RECOVERY_DONE, &mddev->recovery) || 10071 - (mddev->external == 0 && mddev->safemode == 1) || 10072 - (mddev->safemode == 2 10073 - && !mddev->in_sync && mddev->resync_offset == MaxSector) 10074 - )) 10017 + if (!md_should_do_recovery(mddev)) 10075 10018 return; 10076 10019 10077 10020 if (mddev_trylock(mddev)) {