From: Xiao Ni <xni@redhat.com>
To: Yu Kuai <yukuai1@huaweicloud.com>,
agk@redhat.com, snitzer@kernel.org, mpatocka@redhat.com,
song@kernel.org
Cc: dm-devel@lists.linux.dev, linux-kernel@vger.kernel.org,
linux-raid@vger.kernel.org, yukuai3@huawei.com,
yi.zhang@huawei.com, yangerkun@huawei.com
Subject: Re: [PATCH md-6.10 8/9] md: factor out helpers for different sync_action in md_do_sync()
Date: Tue, 14 May 2024 15:27:56 +0800 [thread overview]
Message-ID: <5a1ff1a3-3197-40b4-8b9c-f2ec567ff24e@redhat.com> (raw)
In-Reply-To: <20240509011900.2694291-9-yukuai1@huaweicloud.com>
在 2024/5/9 上午9:18, Yu Kuai 写道:
> From: Yu Kuai <yukuai3@huawei.com>
>
> Make code cleaner by replace if else if with switch, and it's more
> obvious now what is doning for each sync_action. There are no
Hi Kuai
type error s/doning/doing/g
Regards
Xiao
> functional changes.
>
> Signed-off-by: Yu Kuai <yukuai3@huawei.com>
> ---
> drivers/md/md.c | 123 ++++++++++++++++++++++++++++--------------------
> 1 file changed, 73 insertions(+), 50 deletions(-)
>
> diff --git a/drivers/md/md.c b/drivers/md/md.c
> index 2fc81175b46b..42db128b82d9 100644
> --- a/drivers/md/md.c
> +++ b/drivers/md/md.c
> @@ -8928,6 +8928,77 @@ void md_allow_write(struct mddev *mddev)
> }
> EXPORT_SYMBOL_GPL(md_allow_write);
>
> +static sector_t md_sync_max_sectors(struct mddev *mddev,
> + enum sync_action action)
> +{
> + switch (action) {
> + case ACTION_RESYNC:
> + case ACTION_CHECK:
> + case ACTION_REPAIR:
> + atomic64_set(&mddev->resync_mismatches, 0);
> + fallthrough;
> + case ACTION_RESHAPE:
> + return mddev->resync_max_sectors;
> + case ACTION_RECOVER:
> + return mddev->dev_sectors;
> + default:
> + return 0;
> + }
> +}
> +
> +static sector_t md_sync_position(struct mddev *mddev, enum sync_action action)
> +{
> + sector_t start = 0;
> + struct md_rdev *rdev;
> +
> + switch (action) {
> + case ACTION_CHECK:
> + case ACTION_REPAIR:
> + return mddev->resync_min;
> + case ACTION_RESYNC:
> + if (!mddev->bitmap)
> + return mddev->recovery_cp;
> + return 0;
> + case ACTION_RESHAPE:
> + /*
> + * If the original node aborts reshaping then we continue the
> + * reshaping, so set again to avoid restart reshape from the
> + * first beginning
> + */
> + if (mddev_is_clustered(mddev) &&
> + mddev->reshape_position != MaxSector)
> + return mddev->reshape_position;
> + return 0;
> + case ACTION_RECOVER:
> + start = MaxSector;
> + rcu_read_lock();
> + rdev_for_each_rcu(rdev, mddev)
> + if (rdev->raid_disk >= 0 &&
> + !test_bit(Journal, &rdev->flags) &&
> + !test_bit(Faulty, &rdev->flags) &&
> + !test_bit(In_sync, &rdev->flags) &&
> + rdev->recovery_offset < start)
> + start = rdev->recovery_offset;
> + rcu_read_unlock();
> +
> + /* If there is a bitmap, we need to make sure all
> + * writes that started before we added a spare
> + * complete before we start doing a recovery.
> + * Otherwise the write might complete and (via
> + * bitmap_endwrite) set a bit in the bitmap after the
> + * recovery has checked that bit and skipped that
> + * region.
> + */
> + if (mddev->bitmap) {
> + mddev->pers->quiesce(mddev, 1);
> + mddev->pers->quiesce(mddev, 0);
> + }
> + return start;
> + default:
> + return MaxSector;
> + }
> +}
> +
> #define SYNC_MARKS 10
> #define SYNC_MARK_STEP (3*HZ)
> #define UPDATE_FREQUENCY (5*60*HZ)
> @@ -9046,56 +9117,8 @@ void md_do_sync(struct md_thread *thread)
> spin_unlock(&all_mddevs_lock);
> } while (mddev->curr_resync < MD_RESYNC_DELAYED);
>
> - j = 0;
> - if (test_bit(MD_RECOVERY_SYNC, &mddev->recovery)) {
> - /* resync follows the size requested by the personality,
> - * which defaults to physical size, but can be virtual size
> - */
> - max_sectors = mddev->resync_max_sectors;
> - atomic64_set(&mddev->resync_mismatches, 0);
> - /* we don't use the checkpoint if there's a bitmap */
> - if (test_bit(MD_RECOVERY_REQUESTED, &mddev->recovery))
> - j = mddev->resync_min;
> - else if (!mddev->bitmap)
> - j = mddev->recovery_cp;
> -
> - } else if (test_bit(MD_RECOVERY_RESHAPE, &mddev->recovery)) {
> - max_sectors = mddev->resync_max_sectors;
> - /*
> - * If the original node aborts reshaping then we continue the
> - * reshaping, so set j again to avoid restart reshape from the
> - * first beginning
> - */
> - if (mddev_is_clustered(mddev) &&
> - mddev->reshape_position != MaxSector)
> - j = mddev->reshape_position;
> - } else {
> - /* recovery follows the physical size of devices */
> - max_sectors = mddev->dev_sectors;
> - j = MaxSector;
> - rcu_read_lock();
> - rdev_for_each_rcu(rdev, mddev)
> - if (rdev->raid_disk >= 0 &&
> - !test_bit(Journal, &rdev->flags) &&
> - !test_bit(Faulty, &rdev->flags) &&
> - !test_bit(In_sync, &rdev->flags) &&
> - rdev->recovery_offset < j)
> - j = rdev->recovery_offset;
> - rcu_read_unlock();
> -
> - /* If there is a bitmap, we need to make sure all
> - * writes that started before we added a spare
> - * complete before we start doing a recovery.
> - * Otherwise the write might complete and (via
> - * bitmap_endwrite) set a bit in the bitmap after the
> - * recovery has checked that bit and skipped that
> - * region.
> - */
> - if (mddev->bitmap) {
> - mddev->pers->quiesce(mddev, 1);
> - mddev->pers->quiesce(mddev, 0);
> - }
> - }
> + max_sectors = md_sync_max_sectors(mddev, action);
> + j = md_sync_position(mddev, action);
>
> pr_info("md: %s of RAID array %s\n", desc, mdname(mddev));
> pr_debug("md: minimum _guaranteed_ speed: %d KB/sec/disk.\n", speed_min(mddev));
next prev parent reply other threads:[~2024-05-14 7:39 UTC|newest]
Thread overview: 31+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-05-09 1:18 [PATCH RFC md-6.10 0/9] md: refactor and cleanup for sync action Yu Kuai
2024-05-09 1:18 ` [PATCH md-6.10 1/9] md: rearrange recovery_flage Yu Kuai
2024-05-13 15:12 ` Mariusz Tkaczyk
2024-05-14 1:36 ` Yu Kuai
2024-05-14 5:51 ` Xiao Ni
2024-05-14 6:10 ` Yu Kuai
2024-05-14 6:39 ` Xiao Ni
2024-05-09 1:18 ` [PATCH md-6.10 2/9] md: add a new enum type sync_action Yu Kuai
2024-05-14 6:13 ` Xiao Ni
2024-05-09 1:18 ` [PATCH md-6.10 3/9] md: add new helpers for sync_action Yu Kuai
2024-05-14 6:52 ` Xiao Ni
2024-05-14 7:39 ` Yu Kuai
2024-05-14 8:40 ` Xiao Ni
2024-05-14 8:52 ` Yu Kuai
2024-05-20 11:51 ` Su Yue
2024-05-21 2:30 ` Yu Kuai
2024-05-21 3:25 ` Xiao Ni
2024-05-21 3:50 ` Su Yue
2024-05-09 1:18 ` [PATCH md-6.10 4/9] md: factor out helper to start reshape from action_store() Yu Kuai
2024-05-09 1:18 ` [PATCH md-6.10 5/9] md: replace sysfs api sync_action with new helpers Yu Kuai
2024-05-20 15:01 ` kernel test robot
2024-05-21 2:20 ` Yu Kuai
2024-05-21 3:01 ` Oliver Sang
2024-05-21 3:11 ` Yu Kuai
2024-05-21 3:21 ` Xiao Ni
2024-05-22 2:46 ` Yu Kuai
2024-05-09 1:18 ` [PATCH md-6.10 6/9] md: use new helers in md_do_sync() Yu Kuai
2024-05-09 1:18 ` [PATCH md-6.10 7/9] md: replace last_sync_action with new enum type Yu Kuai
2024-05-09 1:18 ` [PATCH md-6.10 8/9] md: factor out helpers for different sync_action in md_do_sync() Yu Kuai
2024-05-14 7:27 ` Xiao Ni [this message]
2024-05-09 1:19 ` [PATCH md-6.10 9/9] md: pass in max_sectors for pers->sync_request() Yu Kuai
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=5a1ff1a3-3197-40b4-8b9c-f2ec567ff24e@redhat.com \
--to=xni@redhat.com \
--cc=agk@redhat.com \
--cc=dm-devel@lists.linux.dev \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-raid@vger.kernel.org \
--cc=mpatocka@redhat.com \
--cc=snitzer@kernel.org \
--cc=song@kernel.org \
--cc=yangerkun@huawei.com \
--cc=yi.zhang@huawei.com \
--cc=yukuai1@huaweicloud.com \
--cc=yukuai3@huawei.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).