All of lore.kernel.org
 help / color / mirror / Atom feed
From: Benjamin Marzinski <bmarzins@redhat.com>
To: Yu Kuai <yukuai1@huaweicloud.com>
Cc: Song Liu <song@kernel.org>, Heinz Mauelshagen <heinzm@redhat.com>,
	Xiao Ni <xni@redhat.com>,
	linux-raid@vger.kernel.org, "yukuai (C)" <yukuai3@huawei.com>
Subject: Re: [PATCH] md/raid5: recheck if reshape has finished with device_lock held
Date: Thu, 27 Jun 2024 10:54:50 -0400	[thread overview]
Message-ID: <Zn19OhZ5ykV0b7-T@redhat.com> (raw)
In-Reply-To: <60e07bf5-dd1d-5eeb-d9a8-1488ab729798@huaweicloud.com>

On Thu, Jun 27, 2024 at 08:17:51PM +0800, Yu Kuai wrote:
> Hi,
> 
> 在 2024/06/27 13:37, Benjamin Marzinski 写道:
> > When handling an IO request, MD checks if a reshape is currently
> > happening, and if so, where the IO sector is in relation to the reshape
> > progress. MD uses conf->reshape_progress for both of these tasks.  When
> > the reshape finishes, conf->reshape_progress is set to MaxSector.  If
> > this occurs after MD checks if the reshape is currently happening but
> > before it calls ahead_of_reshape(), then ahead_of_reshape() will end up
> > comparing the IO sector against MaxSector. During a backwards reshape,
> > this will make MD think the IO sector is in the area not yet reshaped,
> > causing it to use the previous configuration, and map the IO to the
> > sector where that data was before the reshape.
> > 
> > This bug can be triggered by running the lvm2
> > lvconvert-raid-reshape-linear_to_raid6-single-type.sh test in a loop,
> > although it's very hard to reproduce.
> > 
> > Fix this by rechecking if the reshape has finished after grabbing the
> > device_lock.
> > 
> > Fixes: fef9c61fdfabf ("md/raid5: change reshape-progress measurement to cope with reshaping backwards.")
> > Signed-off-by: Benjamin Marzinski <bmarzins@redhat.com>
> > ---
> >   drivers/md/raid5.c | 18 ++++++++++--------
> >   1 file changed, 10 insertions(+), 8 deletions(-)
> > 
> 
> Thanks for the patch, it looks correct. However, can you factor out a
> helper and make the code more readable? The code is already quite
> complicated.

Sure.
 
> Thanks,
> Kuai
> 
> > diff --git a/drivers/md/raid5.c b/drivers/md/raid5.c
> > index 547fd15115cd..65d9b1ca815c 100644
> > --- a/drivers/md/raid5.c
> > +++ b/drivers/md/raid5.c
> > @@ -5923,15 +5923,17 @@ static enum stripe_result make_stripe_request(struct mddev *mddev,
> >   		 * to check again.
> >   		 */
> >   		spin_lock_irq(&conf->device_lock);
> > -		if (ahead_of_reshape(mddev, logical_sector,
> > -				     conf->reshape_progress)) {
> > -			previous = 1;
> > -		} else {
> > +		if (conf->reshape_progress != MaxSector) {
> >   			if (ahead_of_reshape(mddev, logical_sector,
> > -					     conf->reshape_safe)) {
> > -				spin_unlock_irq(&conf->device_lock);
> > -				ret = STRIPE_SCHEDULE_AND_RETRY;
> > -				goto out;
> > +					     conf->reshape_progress)) {
> > +				previous = 1;
> > +			} else {
> > +				if (ahead_of_reshape(mddev, logical_sector,
> > +						     conf->reshape_safe)) {
> > +					spin_unlock_irq(&conf->device_lock);
> > +					ret = STRIPE_SCHEDULE_AND_RETRY;
> > +					goto out;
> > +				}
> >   			}
> >   		}
> >   		spin_unlock_irq(&conf->device_lock);
> > 


      reply	other threads:[~2024-06-27 14:54 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-06-27  5:37 [PATCH] md/raid5: recheck if reshape has finished with device_lock held Benjamin Marzinski
2024-06-27 12:17 ` Yu Kuai
2024-06-27 14:54   ` Benjamin Marzinski [this message]

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=Zn19OhZ5ykV0b7-T@redhat.com \
    --to=bmarzins@redhat.com \
    --cc=heinzm@redhat.com \
    --cc=linux-raid@vger.kernel.org \
    --cc=song@kernel.org \
    --cc=xni@redhat.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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.