linux-raid.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Xiao Ni <xni@redhat.com>
To: Yu Kuai <yukuai1@huaweicloud.com>
Cc: song@kernel.org, mariusz.tkaczyk@linux.intel.com,
	linux-raid@vger.kernel.org, linux-kernel@vger.kernel.org,
	yukuai3@huawei.com, yi.zhang@huawei.com, yangerkun@huawei.com
Subject: Re: [PATCH -next v3 2/7] md: factor out a helper to choose sync action from md_check_recovery()
Date: Tue, 22 Aug 2023 18:04:43 +0800	[thread overview]
Message-ID: <CALTww29sF3OMdPfcKWqBoNcbKJPKot22SnpsJ3Dr5fudGNcfDQ@mail.gmail.com> (raw)
In-Reply-To: <20230820090949.2874537-3-yukuai1@huaweicloud.com>

On Sun, Aug 20, 2023 at 5:13 PM Yu Kuai <yukuai1@huaweicloud.com> wrote:
>
> From: Yu Kuai <yukuai3@huawei.com>
>
> There are no functional changes, on the one hand make the code cleaner,
> on the other hand prevent following checkpatch error in the next patch to
> delay choosing sync action to md_start_sync().
>
> ERROR: do not use assignment in if condition
> +       } else if ((spares = remove_and_add_spares(mddev, NULL))) {
>
> Signed-off-by: Yu Kuai <yukuai3@huawei.com>
> ---
>  drivers/md/md.c | 70 +++++++++++++++++++++++++++++++------------------
>  1 file changed, 45 insertions(+), 25 deletions(-)
>
> diff --git a/drivers/md/md.c b/drivers/md/md.c
> index 90815be1e80f..0cb9fa703a0c 100644
> --- a/drivers/md/md.c
> +++ b/drivers/md/md.c
> @@ -9246,6 +9246,50 @@ static int remove_and_add_spares(struct mddev *mddev,
>         return spares;
>  }
>
> +static bool md_choose_sync_action(struct mddev *mddev, int *spares)
> +{
> +       /* Check if reshape is in progress first. */
> +       if (mddev->reshape_position != MaxSector) {
> +               if (mddev->pers->check_reshape == NULL ||
> +                   mddev->pers->check_reshape(mddev) != 0)
> +                       return false;
> +
> +               set_bit(MD_RECOVERY_RESHAPE, &mddev->recovery);
> +               clear_bit(MD_RECOVERY_RECOVER, &mddev->recovery);
> +               return true;
> +       }
> +
> +       /*
> +        * Remove any failed drives, then add spares if possible. Spares are
> +        * also removed and re-added, to allow the personality to fail the
> +        * re-add.
> +        */
> +       *spares = remove_and_add_spares(mddev, NULL);
> +       if (*spares) {
> +               clear_bit(MD_RECOVERY_SYNC, &mddev->recovery);
> +               clear_bit(MD_RECOVERY_CHECK, &mddev->recovery);
> +               clear_bit(MD_RECOVERY_REQUESTED, &mddev->recovery);
> +
> +               /* Start new recovery. */
> +               set_bit(MD_RECOVERY_RECOVER, &mddev->recovery);
> +               return true;
> +       }
> +
> +       /* Check if recovery is in progress. */
> +       if (mddev->recovery_cp < MaxSector) {
> +               set_bit(MD_RECOVERY_SYNC, &mddev->recovery);
> +               clear_bit(MD_RECOVERY_RECOVER, &mddev->recovery);
> +               return true;
> +       }
> +
> +       /* Delay to choose resync/check/repair in md_do_sync(). */
> +       if (test_bit(MD_RECOVERY_SYNC, &mddev->recovery))
> +               return true;
> +
> +       /* Nothing to be done */
> +       return false;
> +}
> +
>  static void md_start_sync(struct work_struct *ws)
>  {
>         struct mddev *mddev = container_of(ws, struct mddev, sync_work);
> @@ -9427,32 +9471,8 @@ void md_check_recovery(struct mddev *mddev)
>                 if (!test_and_clear_bit(MD_RECOVERY_NEEDED, &mddev->recovery) ||
>                     test_bit(MD_RECOVERY_FROZEN, &mddev->recovery))
>                         goto not_running;
> -               /* no recovery is running.
> -                * remove any failed drives, then
> -                * add spares if possible.
> -                * Spares are also removed and re-added, to allow
> -                * the personality to fail the re-add.
> -                */
> -
> -               if (mddev->reshape_position != MaxSector) {
> -                       if (mddev->pers->check_reshape == NULL ||
> -                           mddev->pers->check_reshape(mddev) != 0)
> -                               /* Cannot proceed */
> -                               goto not_running;
> -                       set_bit(MD_RECOVERY_RESHAPE, &mddev->recovery);
> -                       clear_bit(MD_RECOVERY_RECOVER, &mddev->recovery);
> -               } else if ((spares = remove_and_add_spares(mddev, NULL))) {
> -                       clear_bit(MD_RECOVERY_SYNC, &mddev->recovery);
> -                       clear_bit(MD_RECOVERY_CHECK, &mddev->recovery);
> -                       clear_bit(MD_RECOVERY_REQUESTED, &mddev->recovery);
> -                       set_bit(MD_RECOVERY_RECOVER, &mddev->recovery);
> -               } else if (mddev->recovery_cp < MaxSector) {
> -                       set_bit(MD_RECOVERY_SYNC, &mddev->recovery);
> -                       clear_bit(MD_RECOVERY_RECOVER, &mddev->recovery);
> -               } else if (!test_bit(MD_RECOVERY_SYNC, &mddev->recovery))
> -                       /* nothing to be done ... */
> +               if (!md_choose_sync_action(mddev, &spares))
>                         goto not_running;
> -
>                 if (mddev->pers->sync_request) {
>                         if (spares) {
>                                 /* We are adding a device or devices to an array
> --
> 2.39.2
>

Reviewed-by: Xiao Ni <xni@redhat.com>


  reply	other threads:[~2023-08-22 10:05 UTC|newest]

Thread overview: 25+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-08-20  9:09 [PATCH -next v3 0/7] md: make rdev addition and removal independent from daemon thread Yu Kuai
2023-08-20  9:09 ` [PATCH -next v3 1/7] md: use separate work_struct for md_start_sync() Yu Kuai
2023-08-22 10:04   ` Xiao Ni
2023-08-20  9:09 ` [PATCH -next v3 2/7] md: factor out a helper to choose sync action from md_check_recovery() Yu Kuai
2023-08-22 10:04   ` Xiao Ni [this message]
2023-08-20  9:09 ` [PATCH -next v3 3/7] md: delay choosing sync action to md_start_sync() Yu Kuai
2023-08-22 10:06   ` Xiao Ni
2023-08-20  9:09 ` [PATCH -next v3 4/7] md: factor out a helper rdev_removeable() from remove_and_add_spares() Yu Kuai
2023-08-22 10:19   ` Xiao Ni
2023-08-23  2:45     ` Yu Kuai
2023-08-23  3:42       ` Xiao Ni
2023-08-20  9:09 ` [PATCH -next v3 5/7] md: factor out a helper rdev_is_spare() " Yu Kuai
2023-08-23  2:20   ` Xiao Ni
2023-08-23  2:28     ` Xiao Ni
2023-08-23  2:47       ` Yu Kuai
2023-08-20  9:09 ` [PATCH -next v3 6/7] md: factor out a helper rdev_addable() " Yu Kuai
2023-08-21 23:22   ` Song Liu
2023-08-22  2:17     ` Yu Kuai
2023-08-23  3:04       ` Yu Kuai
2023-08-23  5:26         ` Song Liu
2023-08-23  8:37           ` Yu Kuai
2023-08-23 11:25             ` Song Liu
2023-08-24  1:16               ` Yu Kuai
2023-08-20  9:09 ` [PATCH -next v3 7/7] md: delay remove_and_add_spares() for read only array to md_start_sync() Yu Kuai
2023-08-23  3:24   ` Xiao Ni

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=CALTww29sF3OMdPfcKWqBoNcbKJPKot22SnpsJ3Dr5fudGNcfDQ@mail.gmail.com \
    --to=xni@redhat.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-raid@vger.kernel.org \
    --cc=mariusz.tkaczyk@linux.intel.com \
    --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 NNTP newsgroup(s).