All of lore.kernel.org
 help / color / mirror / Atom feed
From: Su Yue <l@damenly.org>
To: Yu Kuai <yukuai1@huaweicloud.com>
Cc: mariusz.tkaczyk@linux.intel.com, hch@infradead.org,
	song@kernel.org, linux-kernel@vger.kernel.org,
	linux-raid@vger.kernel.org, yukuai3@huawei.com,
	yi.zhang@huawei.com, yangerkun@huawei.com
Subject: Re: [PATCH RFC -next v2 11/41] md/md-bitmap: simplify md_bitmap_create() + md_bitmap_load()
Date: Mon, 19 Aug 2024 16:10:39 +0800	[thread overview]
Message-ID: <ikvxorrl.fsf@damenly.org> (raw)
In-Reply-To: <20240814071113.346781-12-yukuai1@huaweicloud.com>


On Wed 14 Aug 2024 at 15:10, Yu Kuai <yukuai1@huaweicloud.com> 
wrote:

> From: Yu Kuai <yukuai3@huawei.com>
>
> Other than internal api get_bitmap_from_slot(), all other places 
> will
> set returned bitmap to mddev->bitmap. So move the setting of
> mddev->bitmap into md_bitmap_create() to simplify code.
>
> Signed-off-by: Yu Kuai <yukuai3@huawei.com>
> ---
>  drivers/md/md-bitmap.c | 23 +++++++++++++++--------
>  drivers/md/md-bitmap.h |  2 +-
>  drivers/md/md.c        | 30 +++++++++---------------------
>  3 files changed, 25 insertions(+), 30 deletions(-)
>
> diff --git a/drivers/md/md-bitmap.c b/drivers/md/md-bitmap.c
> index eed3b930ade4..75e58da9a1a5 100644
> --- a/drivers/md/md-bitmap.c
> +++ b/drivers/md/md-bitmap.c
> @@ -1879,7 +1879,7 @@ void md_bitmap_destroy(struct mddev 
> *mddev)
>   * if this returns an error, bitmap_destroy must be called to 
>   do clean up
>   * once mddev->bitmap is set
>   */
> -struct bitmap *md_bitmap_create(struct mddev *mddev, int slot)
> +static struct bitmap *bitmap_create(struct mddev *mddev, int 
> slot)
>  {
>  	struct bitmap *bitmap;
>  	sector_t blocks = mddev->resync_max_sectors;
> @@ -1966,6 +1966,17 @@ struct bitmap *md_bitmap_create(struct 
> mddev *mddev, int slot)
>  	return ERR_PTR(err);
>  }
>
> +int md_bitmap_create(struct mddev *mddev, int slot)
>
NIT: We have two functions named md_bitmap_create() now. The 
static
one will be renamed to __md_bitmap_create in next patch. Better to 
rename
in this patch.

--
Su

> +{
> +	struct bitmap *bitmap = bitmap_create(mddev, slot);
> +
> +	if (IS_ERR(bitmap))
> +		return PTR_ERR(bitmap);
> +
> +	mddev->bitmap = bitmap;
> +	return 0;
> +}
> +
>  int md_bitmap_load(struct mddev *mddev)
>  {
>  	int err = 0;
> @@ -2030,7 +2041,7 @@ struct bitmap *get_bitmap_from_slot(struct 
> mddev *mddev, int slot)
>  	int rv = 0;
>  	struct bitmap *bitmap;
>
> -	bitmap = md_bitmap_create(mddev, slot);
> +	bitmap = bitmap_create(mddev, slot);
>  	if (IS_ERR(bitmap)) {
>  		rv = PTR_ERR(bitmap);
>  		return ERR_PTR(rv);
> @@ -2381,7 +2392,6 @@ location_store(struct mddev *mddev, const 
> char *buf, size_t len)
>  	} else {
>  		/* No bitmap, OK to set a location */
>  		long long offset;
> -		struct bitmap *bitmap;
>
>  		if (strncmp(buf, "none", 4) == 0)
>  			/* nothing to be done */;
> @@ -2408,13 +2418,10 @@ location_store(struct mddev *mddev, 
> const char *buf, size_t len)
>  			}
>
>  			mddev->bitmap_info.offset = offset;
> -			bitmap = md_bitmap_create(mddev, -1);
> -			if (IS_ERR(bitmap)) {
> -				rv = PTR_ERR(bitmap);
> +			rv = md_bitmap_create(mddev, -1);
> +			if (rv)
>  				goto out;
> -			}
>
> -			mddev->bitmap = bitmap;
>  			rv = md_bitmap_load(mddev);
>  			if (rv) {
>  				mddev->bitmap_info.offset = 0;
> diff --git a/drivers/md/md-bitmap.h b/drivers/md/md-bitmap.h
> index a8a5d4804174..e187f9099f2e 100644
> --- a/drivers/md/md-bitmap.h
> +++ b/drivers/md/md-bitmap.h
> @@ -252,7 +252,7 @@ struct bitmap_operations {
>  void mddev_set_bitmap_ops(struct mddev *mddev);
>
>  /* these are used only by md/bitmap */
> -struct bitmap *md_bitmap_create(struct mddev *mddev, int slot);
> +int md_bitmap_create(struct mddev *mddev, int slot);
>  int md_bitmap_load(struct mddev *mddev);
>  void md_bitmap_flush(struct mddev *mddev);
>  void md_bitmap_destroy(struct mddev *mddev);
> diff --git a/drivers/md/md.c b/drivers/md/md.c
> index f67f2540fd6c..6e130f6c2abd 100644
> --- a/drivers/md/md.c
> +++ b/drivers/md/md.c
> @@ -6211,16 +6211,10 @@ int md_run(struct mddev *mddev)
>  	}
>  	if (err == 0 && pers->sync_request &&
>  	    (mddev->bitmap_info.file || mddev->bitmap_info.offset)) {
> -		struct bitmap *bitmap;
> -
> -		bitmap = md_bitmap_create(mddev, -1);
> -		if (IS_ERR(bitmap)) {
> -			err = PTR_ERR(bitmap);
> +		err = md_bitmap_create(mddev, -1);
> +		if (err)
>  			pr_warn("%s: failed to create bitmap (%d)\n",
>  				mdname(mddev), err);
> -		} else
> -			mddev->bitmap = bitmap;
> -
>  	}
>  	if (err)
>  		goto bitmap_abort;
> @@ -7275,14 +7269,10 @@ static int set_bitmap_file(struct mddev 
> *mddev, int fd)
>  	err = 0;
>  	if (mddev->pers) {
>  		if (fd >= 0) {
> -			struct bitmap *bitmap;
> -
> -			bitmap = md_bitmap_create(mddev, -1);
> -			if (!IS_ERR(bitmap)) {
> -				mddev->bitmap = bitmap;
> +			err = md_bitmap_create(mddev, -1);
> +			if (!err)
>  				err = md_bitmap_load(mddev);
> -			} else
> -				err = PTR_ERR(bitmap);
> +
>  			if (err) {
>  				md_bitmap_destroy(mddev);
>  				fd = -1;
> @@ -7291,6 +7281,7 @@ static int set_bitmap_file(struct mddev 
> *mddev, int fd)
>  			md_bitmap_destroy(mddev);
>  		}
>  	}
> +
>  	if (fd < 0) {
>  		struct file *f = mddev->bitmap_info.file;
>  		if (f) {
> @@ -7559,7 +7550,6 @@ static int update_array_info(struct mddev 
> *mddev, mdu_array_info_t *info)
>  			goto err;
>  		}
>  		if (info->state & (1<<MD_SB_BITMAP_PRESENT)) {
> -			struct bitmap *bitmap;
>  			/* add the bitmap */
>  			if (mddev->bitmap) {
>  				rv = -EEXIST;
> @@ -7573,12 +7563,10 @@ static int update_array_info(struct 
> mddev *mddev, mdu_array_info_t *info)
>  				mddev->bitmap_info.default_offset;
>  			mddev->bitmap_info.space =
>  				mddev->bitmap_info.default_space;
> -			bitmap = md_bitmap_create(mddev, -1);
> -			if (!IS_ERR(bitmap)) {
> -				mddev->bitmap = bitmap;
> +			rv = md_bitmap_create(mddev, -1);
> +			if (!rv)
>  				rv = md_bitmap_load(mddev);
> -			} else
> -				rv = PTR_ERR(bitmap);
> +
>  			if (rv)
>  				md_bitmap_destroy(mddev);
>  		} else {

  reply	other threads:[~2024-08-19  8:18 UTC|newest]

Thread overview: 47+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-08-14  7:10 [PATCH RFC -next v2 00/41] md/md-bitmap: introduce bitmap_operations and make structure internel Yu Kuai
2024-08-14  7:10 ` [PATCH RFC -next v2 01/41] md/raid1: use md_bitmap_wait_behind_writes() in raid1_read_request() Yu Kuai
2024-08-14  7:10 ` [PATCH RFC -next v2 02/41] md/md-bitmap: replace md_bitmap_status() with a new helper md_bitmap_get_stats() Yu Kuai
2024-08-14  7:10 ` [PATCH RFC -next v2 03/41] md: use new helper md_bitmap_get_stats() in update_array_info() Yu Kuai
2024-08-14  7:10 ` [PATCH RFC -next v2 04/41] md/md-bitmap: add 'events_cleared' into struct md_bitmap_stats Yu Kuai
2024-08-14  7:10 ` [PATCH RFC -next v2 05/41] md/md-bitmap: add 'sync_size' " Yu Kuai
2024-08-14 12:52   ` Mariusz Tkaczyk
2024-08-14  7:10 ` [PATCH RFC -next v2 06/41] md/md-bitmap: add 'file_pages' " Yu Kuai
2024-08-14  7:10 ` [PATCH RFC -next v2 07/41] md/md-bitmap: add 'behind_writes' and 'behind_wait' " Yu Kuai
2024-08-14  7:10 ` [PATCH RFC -next v2 08/41] md/md-cluster: use helper md_bitmap_get_stats() to get pages in resize_bitmaps() Yu Kuai
2024-08-14  7:10 ` [PATCH RFC -next v2 09/41] md/md-bitmap: add a new helper md_bitmap_set_pages() Yu Kuai
2024-08-14  7:10 ` [PATCH RFC -next v2 10/41] md/md-bitmap: introduce struct bitmap_operations Yu Kuai
2024-08-14  7:10 ` [PATCH RFC -next v2 11/41] md/md-bitmap: simplify md_bitmap_create() + md_bitmap_load() Yu Kuai
2024-08-19  8:10   ` Su Yue [this message]
2024-08-19 11:06     ` Yu Kuai
2024-08-14  7:10 ` [PATCH RFC -next v2 12/41] md/md-bitmap: merge md_bitmap_create() into bitmap_operations Yu Kuai
2024-08-14  7:10 ` [PATCH RFC -next v2 13/41] md/md-bitmap: merge md_bitmap_load() " Yu Kuai
2024-08-14  7:10 ` [PATCH RFC -next v2 14/41] md/md-bitmap: merge md_bitmap_destroy() " Yu Kuai
2024-08-14  7:10 ` [PATCH RFC -next v2 15/41] md/md-bitmap: merge md_bitmap_flush() " Yu Kuai
2024-08-14  7:10 ` [PATCH RFC -next v2 16/41] md/md-bitmap: make md_bitmap_print_sb() internal Yu Kuai
2024-08-14  7:10 ` [PATCH RFC -next v2 17/41] md/md-bitmap: merge md_bitmap_update_sb() into bitmap_operations Yu Kuai
2024-08-14  7:10 ` [PATCH RFC -next v2 18/41] md/md-bitmap: merge md_bitmap_status() " Yu Kuai
2024-08-14  7:10 ` [PATCH RFC -next v2 19/41] md/md-bitmap: remove md_bitmap_setallbits() Yu Kuai
2024-08-14  7:10 ` [PATCH RFC -next v2 20/41] md/md-bitmap: merge bitmap_write_all() into bitmap_operations Yu Kuai
2024-08-14  7:10 ` [PATCH RFC -next v2 21/41] md/md-bitmap: merge md_bitmap_dirty_bits() " Yu Kuai
2024-08-14  7:10 ` [PATCH RFC -next v2 22/41] md/md-bitmap: merge md_bitmap_startwrite() " Yu Kuai
2024-08-14  7:10 ` [PATCH RFC -next v2 23/41] md/md-bitmap: merge md_bitmap_endwrite() " Yu Kuai
2024-08-14  7:10 ` [PATCH RFC -next v2 24/41] md/md-bitmap: merge md_bitmap_start_sync() " Yu Kuai
2024-08-14  7:10 ` [PATCH RFC -next v2 25/41] md/md-bitmap: remove the parameter 'aborted' for md_bitmap_end_sync() Yu Kuai
2024-08-14  7:10 ` [PATCH RFC -next v2 26/41] md/md-bitmap: merge md_bitmap_end_sync() into bitmap_operations Yu Kuai
2024-08-14  7:10 ` [PATCH RFC -next v2 27/41] md/md-bitmap: merge md_bitmap_close_sync() " Yu Kuai
2024-08-14  7:11 ` [PATCH RFC -next v2 28/41] md/md-bitmap: mrege md_bitmap_cond_end_sync() " Yu Kuai
2024-08-14  7:11 ` [PATCH RFC -next v2 29/41] md/md-bitmap: merge md_bitmap_sync_with_cluster() " Yu Kuai
2024-08-14  7:11 ` [PATCH RFC -next v2 30/41] md/md-bitmap: merge md_bitmap_unplug_async() into md_bitmap_unplug() Yu Kuai
2024-08-14  7:11 ` [PATCH RFC -next v2 31/41] md/md-bitmap: merge bitmap_unplug() into bitmap_operations Yu Kuai
2024-08-14  7:11 ` [PATCH RFC -next v2 32/41] md/md-bitmap: merge md_bitmap_daemon_work() " Yu Kuai
2024-08-14  7:11 ` [PATCH RFC -next v2 33/41] md/md-bitmap: pass in mddev directly for md_bitmap_resize() Yu Kuai
2024-08-14  7:11 ` [PATCH RFC -next v2 34/41] md/md-bitmap: merge md_bitmap_resize() into bitmap_operations Yu Kuai
2024-08-14  7:11 ` [PATCH RFC -next v2 35/41] md/md-bitmap: merge get_bitmap_from_slot() " Yu Kuai
2024-08-14  7:11 ` [PATCH RFC -next v2 36/41] md/md-bitmap: merge md_bitmap_copy_from_slot() into struct bitmap_operation Yu Kuai
2024-08-14  7:11 ` [PATCH RFC -next v2 37/41] md/md-bitmap: merge md_bitmap_set_pages() into struct bitmap_operations Yu Kuai
2024-08-14  7:11 ` [PATCH RFC -next v2 38/41] md/md-bitmap: merge md_bitmap_free() into bitmap_operations Yu Kuai
2024-08-14  7:11 ` [PATCH RFC -next v2 39/41] md/md-bitmap: merge md_bitmap_wait_behind_writes() " Yu Kuai
2024-08-14  7:11 ` [PATCH RFC -next v2 40/41] md/md-bitmap: merge md_bitmap_enabled() " Yu Kuai
2024-08-14  7:11 ` [PATCH RFC -next v2 41/41] md/md-bitmap: make in memory structure internal Yu Kuai
2024-08-19  8:18 ` [PATCH RFC -next v2 00/41] md/md-bitmap: introduce bitmap_operations and make structure internel Su Yue
2024-08-19 11:13   ` 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=ikvxorrl.fsf@damenly.org \
    --to=l@damenly.org \
    --cc=hch@infradead.org \
    --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 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.