Linux-Raid Archives mirror
 help / color / mirror / Atom feed
From: Yu Kuai <yukuai1@huaweicloud.com>
To: Yu Kuai <yukuai1@huaweicloud.com>,
	xni@redhat.com, paul.e.luse@linux.intel.com, song@kernel.org,
	shli@fb.com, neilb@suse.com
Cc: linux-raid@vger.kernel.org, linux-kernel@vger.kernel.org,
	yi.zhang@huawei.com, yangerkun@huawei.com,
	"yukuai (C)" <yukuai3@huawei.com>
Subject: Re: [PATCH md-6.9 v3 02/11] md/raid1: factor out helpers to add rdev to conf
Date: Thu, 29 Feb 2024 10:11:55 +0800	[thread overview]
Message-ID: <ca4adb05-2e99-2f83-3032-e7a2e03e94f3@huaweicloud.com> (raw)
In-Reply-To: <20240228114333.527222-3-yukuai1@huaweicloud.com>

Hi,

在 2024/02/28 19:43, Yu Kuai 写道:
> From: Yu Kuai <yukuai3@huawei.com>
> 
> There are no functional changes, just make code cleaner and prepare to
> record disk non-rotational information while adding and removing rdev to
> conf
> 
> Signed-off-by: Yu Kuai <yukuai3@huawei.com>
> ---
>   drivers/md/raid1.c | 74 ++++++++++++++++++++++++++++------------------
>   1 file changed, 46 insertions(+), 28 deletions(-)
> 
> diff --git a/drivers/md/raid1.c b/drivers/md/raid1.c
> index a145fe48b9ce..1940ff398c23 100644
> --- a/drivers/md/raid1.c
> +++ b/drivers/md/raid1.c
> @@ -1757,6 +1757,40 @@ static int raid1_spare_active(struct mddev *mddev)
>   	return count;
>   }
>   
> +static bool raid1_add_conf(struct r1conf *conf, struct md_rdev *rdev, int disk)
> +{
> +	struct raid1_info *info = conf->mirrors + disk;
> +
> +	if (info->rdev)
> +		return false;
> +
> +	rdev->raid_disk = disk;
> +	info->head_position = 0;
> +	info->seq_start = MaxSector;
> +	WRITE_ONCE(info->rdev, rdev);
> +
> +	return true;
> +}

I misread the code, for replacement, rdev->raid_disk is the same as the
original rdev, while this patch set it to "raid_disk + conf->raid_disks"
and following should be merged with this patch:

diff --git a/drivers/md/raid1.c b/drivers/md/raid1.c
index 1940ff398c23..ff1e1aeaf336 100644
--- a/drivers/md/raid1.c
+++ b/drivers/md/raid1.c
@@ -1757,10 +1757,14 @@ static int raid1_spare_active(struct mddev *mddev)
         return count;
  }

-static bool raid1_add_conf(struct r1conf *conf, struct md_rdev *rdev, 
int disk)
+static bool raid1_add_conf(struct r1conf *conf, struct md_rdev *rdev, 
int disk,
+                          bool replacement)
  {
         struct raid1_info *info = conf->mirrors + disk;

+       if (replacement)
+               info += conf->raid_disks;
+
         if (info->rdev)
                 return false;

@@ -1826,7 +1830,7 @@ static int raid1_add_disk(struct mddev *mddev, 
struct md_rdev *rdev)
                                 disk_stack_limits(mddev->gendisk, 
rdev->bdev,
                                                   rdev->data_offset << 9);

-                       raid1_add_conf(conf, rdev, mirror);
+                       raid1_add_conf(conf, rdev, mirror, false);
                         err = 0;
                         /* As all devices are equivalent, we don't need 
a full recovery
                          * if this was recently any drive of the array
@@ -1844,7 +1848,7 @@ static int raid1_add_disk(struct mddev *mddev, 
struct md_rdev *rdev)
                 /* Add this device as a replacement */
                 clear_bit(In_sync, &rdev->flags);
                 set_bit(Replacement, &rdev->flags);
-               raid1_add_conf(conf, rdev, repl_slot);
+               raid1_add_conf(conf, rdev, repl_slot, true);
                 err = 0;
                 conf->fullsync = 1;
         }
@@ -3017,18 +3021,16 @@ static struct r1conf *setup_conf(struct mddev 
*mddev)

         err = -EINVAL;
         spin_lock_init(&conf->device_lock);
+       conf->raid_disks = mddev->raid_disks;
         rdev_for_each(rdev, mddev) {
                 int disk_idx = rdev->raid_disk;
-               if (disk_idx >= mddev->raid_disks
+               if (disk_idx >= conf->raid_disks
                     || disk_idx < 0)
                         continue;
-               if (test_bit(Replacement, &rdev->flags))
-                       disk_idx += mddev->raid_disks;
-
-               if (!raid1_add_conf(conf, rdev, disk_idx))
+               if (!raid1_add_conf(conf, rdev, disk_idx,
+                                   test_bit(Replacement, &rdev->flags)))
                         goto abort;
         }
-       conf->raid_disks = mddev->raid_disks;
         conf->mddev = mddev;
         INIT_LIST_HEAD(&conf->retry_list);
         INIT_LIST_HEAD(&conf->bio_end_io_list);


I'll finish mdadm tests suite before v4.

Thanks,
Kuai
> +
> +static bool raid1_remove_conf(struct r1conf *conf, int disk)
> +{
> +	struct raid1_info *info = conf->mirrors + disk;
> +	struct md_rdev *rdev = info->rdev;
> +
> +	if (!rdev || test_bit(In_sync, &rdev->flags) ||
> +	    atomic_read(&rdev->nr_pending))
> +		return false;
> +
> +	/* Only remove non-faulty devices if recovery is not possible. */
> +	if (!test_bit(Faulty, &rdev->flags) &&
> +	    rdev->mddev->recovery_disabled != conf->recovery_disabled &&
> +	    rdev->mddev->degraded < conf->raid_disks)
> +		return false;
> +
> +	WRITE_ONCE(info->rdev, NULL);
> +	return true;
> +}
> +
>   static int raid1_add_disk(struct mddev *mddev, struct md_rdev *rdev)
>   {
>   	struct r1conf *conf = mddev->private;
> @@ -1792,15 +1826,13 @@ static int raid1_add_disk(struct mddev *mddev, struct md_rdev *rdev)
>   				disk_stack_limits(mddev->gendisk, rdev->bdev,
>   						  rdev->data_offset << 9);
>   
> -			p->head_position = 0;
> -			rdev->raid_disk = mirror;
> +			raid1_add_conf(conf, rdev, mirror);
>   			err = 0;
>   			/* As all devices are equivalent, we don't need a full recovery
>   			 * if this was recently any drive of the array
>   			 */
>   			if (rdev->saved_raid_disk < 0)
>   				conf->fullsync = 1;
> -			WRITE_ONCE(p->rdev, rdev);
>   			break;
>   		}
>   		if (test_bit(WantReplacement, &p->rdev->flags) &&
> @@ -1810,13 +1842,11 @@ static int raid1_add_disk(struct mddev *mddev, struct md_rdev *rdev)
>   
>   	if (err && repl_slot >= 0) {
>   		/* Add this device as a replacement */
> -		p = conf->mirrors + repl_slot;
>   		clear_bit(In_sync, &rdev->flags);
>   		set_bit(Replacement, &rdev->flags);
> -		rdev->raid_disk = repl_slot;
> +		raid1_add_conf(conf, rdev, repl_slot);
>   		err = 0;
>   		conf->fullsync = 1;
> -		WRITE_ONCE(p[conf->raid_disks].rdev, rdev);
>   	}
>   
>   	print_conf(conf);
> @@ -1833,27 +1863,20 @@ static int raid1_remove_disk(struct mddev *mddev, struct md_rdev *rdev)
>   	if (unlikely(number >= conf->raid_disks))
>   		goto abort;
>   
> -	if (rdev != p->rdev)
> -		p = conf->mirrors + conf->raid_disks + number;
> +	if (rdev != p->rdev) {
> +		number += conf->raid_disks;
> +		p = conf->mirrors + number;
> +	}
>   
>   	print_conf(conf);
>   	if (rdev == p->rdev) {
> -		if (test_bit(In_sync, &rdev->flags) ||
> -		    atomic_read(&rdev->nr_pending)) {
> -			err = -EBUSY;
> -			goto abort;
> -		}
> -		/* Only remove non-faulty devices if recovery
> -		 * is not possible.
> -		 */
> -		if (!test_bit(Faulty, &rdev->flags) &&
> -		    mddev->recovery_disabled != conf->recovery_disabled &&
> -		    mddev->degraded < conf->raid_disks) {
> +		if (!raid1_remove_conf(conf, number)) {
>   			err = -EBUSY;
>   			goto abort;
>   		}
> -		WRITE_ONCE(p->rdev, NULL);
> -		if (conf->mirrors[conf->raid_disks + number].rdev) {
> +
> +		if (number < conf->raid_disks &&
> +		    conf->mirrors[conf->raid_disks + number].rdev) {
>   			/* We just removed a device that is being replaced.
>   			 * Move down the replacement.  We drain all IO before
>   			 * doing this to avoid confusion.
> @@ -3000,15 +3023,10 @@ static struct r1conf *setup_conf(struct mddev *mddev)
>   		    || disk_idx < 0)
>   			continue;
>   		if (test_bit(Replacement, &rdev->flags))
> -			disk = conf->mirrors + mddev->raid_disks + disk_idx;
> -		else
> -			disk = conf->mirrors + disk_idx;
> +			disk_idx += mddev->raid_disks;
>   
> -		if (disk->rdev)
> +		if (!raid1_add_conf(conf, rdev, disk_idx))
>   			goto abort;
> -		disk->rdev = rdev;
> -		disk->head_position = 0;
> -		disk->seq_start = MaxSector;
>   	}
>   	conf->raid_disks = mddev->raid_disks;
>   	conf->mddev = mddev;
> 


  reply	other threads:[~2024-02-29  2:12 UTC|newest]

Thread overview: 16+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-02-28 11:43 [PATCH md-6.9 v3 00/11] md/raid1: refactor read_balance() and some minor fix Yu Kuai
2024-02-28 11:43 ` [PATCH md-6.9 v3 01/11] md: add a new helper rdev_has_badblock() Yu Kuai
2024-02-28 11:43 ` [PATCH md-6.9 v3 02/11] md/raid1: factor out helpers to add rdev to conf Yu Kuai
2024-02-29  2:11   ` Yu Kuai [this message]
2024-02-28 11:43 ` [PATCH md-6.9 v3 03/11] md/raid1: record nonrot rdevs while adding/removing rdevs " Yu Kuai
2024-02-28 11:43 ` [PATCH md-6.9 v3 04/11] md/raid1: fix choose next idle in read_balance() Yu Kuai
2024-02-28 11:43 ` [PATCH md-6.9 v3 05/11] md/raid1-10: add a helper raid1_check_read_range() Yu Kuai
2024-02-28 11:43 ` [PATCH md-6.9 v3 06/11] md/raid1-10: factor out a new helper raid1_should_read_first() Yu Kuai
2024-02-28 11:43 ` [PATCH md-6.9 v3 07/11] md/raid1: factor out read_first_rdev() from read_balance() Yu Kuai
2024-02-28 11:43 ` [PATCH md-6.9 v3 08/11] md/raid1: factor out choose_slow_rdev() " Yu Kuai
2024-02-28 11:43 ` [PATCH md-6.9 v3 09/11] md/raid1: factor out choose_bb_rdev() " Yu Kuai
2024-02-28 11:43 ` [PATCH md-6.9 v3 10/11] md/raid1: factor out the code to manage sequential IO Yu Kuai
2024-02-28 11:43 ` [PATCH md-6.9 v3 11/11] md/raid1: factor out helpers to choose the best rdev from read_balance() Yu Kuai
2024-02-28 12:35 ` [PATCH md-6.9 v3 00/11] md/raid1: refactor read_balance() and some minor fix Xiao Ni
2024-02-28 21:23 ` Song Liu
2024-02-29  1:14   ` 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=ca4adb05-2e99-2f83-3032-e7a2e03e94f3@huaweicloud.com \
    --to=yukuai1@huaweicloud.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-raid@vger.kernel.org \
    --cc=neilb@suse.com \
    --cc=paul.e.luse@linux.intel.com \
    --cc=shli@fb.com \
    --cc=song@kernel.org \
    --cc=xni@redhat.com \
    --cc=yangerkun@huawei.com \
    --cc=yi.zhang@huawei.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).