linux-raid.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Su Yue <l@damenly.org>
To: Yu Kuai <yukuai1@huaweicloud.com>
Cc: song@kernel.org,  yukuai3@huawei.com,
	 linux-raid@vger.kernel.org, linux-kernel@vger.kernel.org,
	 yi.zhang@huawei.com,  yangerkun@huawei.com
Subject: Re: [PATCH md-6.15 7/7] md: switch md-cluster to use md_submodle_head
Date: Tue, 18 Feb 2025 11:37:32 +0800	[thread overview]
Message-ID: <v7t76hz7.fsf@damenly.org> (raw)
In-Reply-To: <20250215092225.2427977-8-yukuai1@huaweicloud.com> (Yu Kuai's message of "Sat, 15 Feb 2025 17:22:25 +0800")

On Sat 15 Feb 2025 at 17:22, Yu Kuai <yukuai1@huaweicloud.com> 
wrote:

> From: Yu Kuai <yukuai3@huawei.com>
>
> To make code cleaner, and prepare to add kconfig for bitmap.
>
> Also remove the unsed global variables pers_lock, md_cluster_ops 
> and
> md_cluster_mod, and exported symbols 
> register_md_cluster_operations(),
> unregister_md_cluster_operations() and md_cluster_ops.
>
> Signed-off-by: Yu Kuai <yukuai3@huawei.com>
>
Reviewed-by: Su Yue <glass.su@suse.com>

> ---
>  drivers/md/md-cluster.c | 14 ++++++++++----
>  drivers/md/md-cluster.h |  3 ---
>  drivers/md/md.c         | 41 
>  ++++++-----------------------------------
>  drivers/md/md.h         |  2 +-
>  4 files changed, 17 insertions(+), 43 deletions(-)
>
> diff --git a/drivers/md/md-cluster.c b/drivers/md/md-cluster.c
> index 6fd436a1d373..94221d964d4f 100644
> --- a/drivers/md/md-cluster.c
> +++ b/drivers/md/md-cluster.c
> @@ -1612,7 +1612,14 @@ static int gather_bitmaps(struct md_rdev 
> *rdev)
>  	return err;
>  }
>
> -static const struct md_cluster_operations cluster_ops = {
> +static struct md_cluster_operations cluster_ops = {
> +	.head = {
> +		.type	= MD_CLUSTER,
> +		.id	= ID_CLUSTER,
> +		.name	= "cluster",
> +		.owner	= THIS_MODULE,
> +	},
> +
>  	.join   = join,
>  	.leave  = leave,
>  	.slot_number = slot_number,
> @@ -1642,13 +1649,12 @@ static int __init cluster_init(void)
>  {
>  	pr_warn("md-cluster: support raid1 and raid10 (limited 
>  support)\n");
>  	pr_info("Registering Cluster MD functions\n");
> -	register_md_cluster_operations(&cluster_ops, THIS_MODULE);
> -	return 0;
> +	return register_md_submodule(&cluster_ops.head);
>  }
>
>  static void cluster_exit(void)
>  {
> -	unregister_md_cluster_operations();
> +	unregister_md_submodule(&cluster_ops.head);
>  }
>
>  module_init(cluster_init);
> diff --git a/drivers/md/md-cluster.h b/drivers/md/md-cluster.h
> index 4e842af11fb4..8fb06d853173 100644
> --- a/drivers/md/md-cluster.h
> +++ b/drivers/md/md-cluster.h
> @@ -37,9 +37,6 @@ struct md_cluster_operations {
>  	void (*update_size)(struct mddev *mddev, sector_t 
>  old_dev_sectors);
>  };
>
> -extern int register_md_cluster_operations(const struct 
> md_cluster_operations *ops,
> -		struct module *module);
> -extern int unregister_md_cluster_operations(void);
>  extern int md_setup_cluster(struct mddev *mddev, int nodes);
>  extern void md_cluster_stop(struct mddev *mddev);
>  extern void md_reload_sb(struct mddev *mddev, int raid_disk);
> diff --git a/drivers/md/md.c b/drivers/md/md.c
> index d94c9aa8c3aa..4d93cc1aaabc 100644
> --- a/drivers/md/md.c
> +++ b/drivers/md/md.c
> @@ -81,13 +81,8 @@ static const char 
> *action_name[NR_SYNC_ACTIONS] = {
>
>  static DEFINE_XARRAY(md_submodule);
>
> -static DEFINE_SPINLOCK(pers_lock);
> -
>  static const struct kobj_type md_ktype;
>
> -static const struct md_cluster_operations *md_cluster_ops;
> -static struct module *md_cluster_mod;
> -
>  static DECLARE_WAIT_QUEUE_HEAD(resync_wait);
>  static struct workqueue_struct *md_wq;
>
> @@ -7452,11 +7447,12 @@ static int update_raid_disks(struct 
> mddev *mddev, int raid_disks)
>
>  static int get_cluster_ops(struct mddev *mddev)
>  {
> -	spin_lock(&pers_lock);
> -	mddev->cluster_ops = md_cluster_ops;
> -	if (mddev->cluster_ops && !try_module_get(md_cluster_mod))
> +	xa_lock(&md_submodule);
> +	mddev->cluster_ops = xa_load(&md_submodule, ID_CLUSTER);
> +	if (mddev->cluster_ops &&
> +	    !try_module_get(mddev->cluster_ops->head.owner))
>  		mddev->cluster_ops = NULL;
> -	spin_unlock(&pers_lock);
> +	xa_unlock(&md_submodule);
>
>  	return mddev->cluster_ops == NULL ? -ENOENT : 0;
>  }
> @@ -7467,7 +7463,7 @@ static void put_cluster_ops(struct mddev 
> *mddev)
>  		return;
>
>  	mddev->cluster_ops->leave(mddev);
> -	module_put(md_cluster_mod);
> +	module_put(mddev->cluster_ops->head.owner);
>  	mddev->cluster_ops = NULL;
>  }
>
> @@ -8559,31 +8555,6 @@ void unregister_md_submodule(struct 
> md_submodule_head *msh)
>  }
>  EXPORT_SYMBOL_GPL(unregister_md_submodule);
>
> -int register_md_cluster_operations(const struct 
> md_cluster_operations *ops,
> -				   struct module *module)
> -{
> -	int ret = 0;
> -	spin_lock(&pers_lock);
> -	if (md_cluster_ops != NULL)
> -		ret = -EALREADY;
> -	else {
> -		md_cluster_ops = ops;
> -		md_cluster_mod = module;
> -	}
> -	spin_unlock(&pers_lock);
> -	return ret;
> -}
> -EXPORT_SYMBOL(register_md_cluster_operations);
> -
> -int unregister_md_cluster_operations(void)
> -{
> -	spin_lock(&pers_lock);
> -	md_cluster_ops = NULL;
> -	spin_unlock(&pers_lock);
> -	return 0;
> -}
> -EXPORT_SYMBOL(unregister_md_cluster_operations);
> -
>  int md_setup_cluster(struct mddev *mddev, int nodes)
>  {
>  	int ret = get_cluster_ops(mddev);
> diff --git a/drivers/md/md.h b/drivers/md/md.h
> index 873f33e2a1f6..dd6a28f5d8e6 100644
> --- a/drivers/md/md.h
> +++ b/drivers/md/md.h
> @@ -603,7 +603,7 @@ struct mddev {
>  	mempool_t *serial_info_pool;
>  	void (*sync_super)(struct mddev *mddev, struct md_rdev *rdev);
>  	struct md_cluster_info		*cluster_info;
> -	const struct md_cluster_operations *cluster_ops;
> +	struct md_cluster_operations *cluster_ops;
>  	unsigned int			good_device_nr;	/* good device num 
>  within cluster raid */
>  	unsigned int			noio_flag; /* for memalloc scope API 
>  */

  reply	other threads:[~2025-02-18  3:42 UTC|newest]

Thread overview: 16+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-02-15  9:22 [PATCH 0/7 md-6.15] md: introduce md_submodle_head Yu Kuai
2025-02-15  9:22 ` [PATCH md-6.15 1/7] md: merge common code into find_pers() Yu Kuai
2025-02-17 10:16   ` Glass Su
2025-02-15  9:22 ` [PATCH md-6.15 2/7] md: only include md-cluster.h if necessary Yu Kuai
2025-02-17 10:20   ` Glass Su
2025-02-18  2:40     ` Yu Kuai
2025-02-18  3:40       ` Su Yue
2025-02-15  9:22 ` [PATCH md-6.15 3/7] md: introduce struct md_submodule_head and APIs Yu Kuai
2025-02-15  9:22 ` [PATCH md-6.15 4/7] md: switch personalities to use md_submodule_head Yu Kuai
2025-02-15  9:22 ` [PATCH md-6.15 5/7] md/md-cluster: cleanup md_cluster_ops reference Yu Kuai
2025-02-17 10:28   ` Glass Su
2025-02-15  9:22 ` [PATCH md-6.15 6/7] md: don't export md_cluster_ops Yu Kuai
2025-02-18  3:36   ` Su Yue
2025-02-15  9:22 ` [PATCH md-6.15 7/7] md: switch md-cluster to use md_submodle_head Yu Kuai
2025-02-18  3:37   ` Su Yue [this message]
2025-03-05  1:34 ` [PATCH 0/7 md-6.15] md: introduce md_submodle_head 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=v7t76hz7.fsf@damenly.org \
    --to=l@damenly.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-raid@vger.kernel.org \
    --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).