linux-raid.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: NeilBrown <neilb@suse.de>
To: majianpeng <majianpeng@gmail.com>
Cc: linux-raid <linux-raid@vger.kernel.org>
Subject: Re: [PATCH] md/raid5:Choose to replacing or recoverying when  raid degraded and had a want_replacement disk at the same time.
Date: Wed, 6 Jun 2012 13:55:43 +1000	[thread overview]
Message-ID: <20120606135543.6b233ff9@notabene.brown> (raw)
In-Reply-To: <201206061124295788941@gmail.com>

[-- Attachment #1: Type: text/plain, Size: 4974 bytes --]

On Wed, 6 Jun 2012 11:24:34 +0800 majianpeng <majianpeng@gmail.com> wrote:

> On  Tue, 5 Jun 2012 18:28:13 neil wrote:
> >On Tue, 5 Jun 2012 15:32:56 +0800 majianpeng <majianpeng@gmail.com> wrote:
> >
> >> In Commit 7bfec5f35c68121e7b1849f3f4166dd96c8da5b3:
> >> "if there is a spare and a want_replacement device, start replacement."
> >> But it did not consider the raid was degraded at the same time.
> >> When we add spare disk in order to recovery, unless raid was ok and then
> >> started replacement or vice versa.
> >> 
> >> Signed-off-by: majianpeng <majianpeng@gmail.com>
> >> ---
> >>  drivers/md/raid5.c |   48 +++++++++++++++++++++++++++++-------------------
> >>  1 files changed, 29 insertions(+), 19 deletions(-)
> >> 
> >> diff --git a/drivers/md/raid5.c b/drivers/md/raid5.c
> >> index d267672..f74c9a5 100644
> >> --- a/drivers/md/raid5.c
> >> +++ b/drivers/md/raid5.c
> >
> >Good point, but the code feels a little ... clumsy.
> >
> >How about this?
> >
> >NeilBrown
> >
> >
> >diff --git a/drivers/md/raid5.c b/drivers/md/raid5.c
> >index d267672..4f0861e 100644
> >--- a/drivers/md/raid5.c
> >+++ b/drivers/md/raid5.c
> >@@ -5465,10 +5465,9 @@ static int raid5_add_disk(struct mddev *mddev, struct md_rdev *rdev)
> > 	if (rdev->saved_raid_disk >= 0 &&
> > 	    rdev->saved_raid_disk >= first &&
> > 	    conf->disks[rdev->saved_raid_disk].rdev == NULL)
> >-		disk = rdev->saved_raid_disk;
> >-	else
> >-		disk = first;
> >-	for ( ; disk <= last ; disk++) {
> >+		first = rdev->saved_raid_disk;
> >+
> >+	for (disk = first; disk <= last; disk++) {
> > 		p = conf->disks + disk;
> > 		if (p->rdev == NULL) {
> > 			clear_bit(In_sync, &rdev->flags);
> >@@ -5477,8 +5476,10 @@ static int raid5_add_disk(struct mddev *mddev, struct md_rdev *rdev)
> > 			if (rdev->saved_raid_disk != disk)
> > 				conf->fullsync = 1;
> > 			rcu_assign_pointer(p->rdev, rdev);
> >-			break;
> >+			goto out;
> > 		}
> >+	}
> >+	for (disk = first; disk <= last; disk++) {
> > 		if (test_bit(WantReplacement, &p->rdev->flags) &&
> > 		    p->replacement == NULL) {
> > 			clear_bit(In_sync, &rdev->flags);
> >@@ -5490,6 +5491,7 @@ static int raid5_add_disk(struct mddev *mddev, struct md_rdev *rdev)
> > 			break;
> > 		}
> > 	}
> >+out:
> > 	print_raid5_conf(conf);
> > 	return err;
> > }
> >
> >
> I tested and found a bug.I corrected it like this.

You've added a test for 'p->rdev != NULL' - is that all?

That isn't necessary.  If any p->rdev were NULL then the first loop would
find it and the second loop would never be entered.


> But I had a question:why  p->rdev not protect by rcu_read_lock?
> I think it should be.

rcu is not necessary here.  We hold mddev->mutex as does the code which
removes devices, so we cannot race with it.  We only need rcu when not
holding the mutex, and when not performing resync/recovery/etc as that
prevents ->rdev from being removed too.

Thanks,
NeilBrown



> 
> diff --git a/drivers/md/raid5.c b/drivers/md/raid5.c
> index d267672..24162c1 100644
> --- a/drivers/md/raid5.c
> +++ b/drivers/md/raid5.c
> @@ -5465,10 +5465,9 @@ static int raid5_add_disk(struct mddev *mddev, struct md_rdev *rdev)
>         if (rdev->saved_raid_disk >= 0 &&
>             rdev->saved_raid_disk >= first &&
>             conf->disks[rdev->saved_raid_disk].rdev == NULL)
> -               disk = rdev->saved_raid_disk;
> -       else
> -               disk = first;
> -       for ( ; disk <= last ; disk++) {
> +               first = rdev->saved_raid_disk;
> +
> +       for (disk = first; disk <= last; disk++) {
>                 p = conf->disks + disk;
>                 if (p->rdev == NULL) {
>                         clear_bit(In_sync, &rdev->flags);
> @@ -5477,10 +5476,15 @@ static int raid5_add_disk(struct mddev *mddev, struct md_rdev *rdev)
>                         if (rdev->saved_raid_disk != disk)
>                                 conf->fullsync = 1;
>                         rcu_assign_pointer(p->rdev, rdev);
> -                       break;
> +                       goto out;
>                 }
> -               if (test_bit(WantReplacement, &p->rdev->flags) &&
> -                   p->replacement == NULL) {
> +       }
> +
> +       for (disk = first; disk <= last; disk++) {
> +               p = conf->disks + disk;
> +               if (p->rdev != NULL &&
> +                       test_bit(WantReplacement, &p->rdev->flags) &&
> +                       p->replacement == NULL) {
>                         clear_bit(In_sync, &rdev->flags);
>                         set_bit(Replacement, &rdev->flags);
>                         rdev->raid_disk = disk;
> @@ -5490,6 +5494,7 @@ static int raid5_add_disk(struct mddev *mddev, struct md_rdev *rdev)
>                         break;
>                 }
>         }
> +out:
>         print_raid5_conf(conf);
>         return err;
>  }
> 


[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 828 bytes --]

  reply	other threads:[~2012-06-06  3:55 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2012-06-05  7:32 [PATCH] md/raid5:Choose to replacing or recoverying when raid degraded and had a want_replacement disk at the same time majianpeng
2012-06-06  1:28 ` NeilBrown
2012-06-06  3:24   ` majianpeng
2012-06-06  3:55     ` NeilBrown [this message]
2012-06-06  5:06       ` majianpeng
2012-06-27  3:47         ` NeilBrown

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=20120606135543.6b233ff9@notabene.brown \
    --to=neilb@suse.de \
    --cc=linux-raid@vger.kernel.org \
    --cc=majianpeng@gmail.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).