From: Xiao Ni <xni@redhat.com>
To: Yu Kuai <yukuai1@huaweicloud.com>
Cc: hch@lst.de, colyli@kernel.org, song@kernel.org,
yukuai3@huawei.com, linux-doc@vger.kernel.org,
linux-kernel@vger.kernel.org, linux-raid@vger.kernel.org,
yi.zhang@huawei.com, yangerkun@huawei.com,
johnny.chenyi@huawei.com
Subject: Re: [PATCH 07/23] md/md-bitmap: delay registration of bitmap_ops until creating bitmap
Date: Mon, 26 May 2025 14:52:12 +0800 [thread overview]
Message-ID: <CALTww2_03_fVt+KMcmtbGw-kcRsLLpAG7W62e3y0W9SpvhUVtg@mail.gmail.com> (raw)
In-Reply-To: <20250524061320.370630-8-yukuai1@huaweicloud.com>
On Sat, May 24, 2025 at 2:18 PM Yu Kuai <yukuai1@huaweicloud.com> wrote:
>
> From: Yu Kuai <yukuai3@huawei.com>
>
> Currently bitmap_ops is registered while allocating mddev, this is fine
> when there is only one bitmap_ops, however, after introduing a new
> bitmap_ops, user space need a time window to choose which bitmap_ops to
> use while creating new array.
Could you give more explanation about what the time window is? Is it
between setting llbitmap by bitmap_type and md_bitmap_create?
>
> Signed-off-by: Yu Kuai <yukuai3@huawei.com>
> ---
> drivers/md/md.c | 86 +++++++++++++++++++++++++++++++------------------
> 1 file changed, 55 insertions(+), 31 deletions(-)
>
> diff --git a/drivers/md/md.c b/drivers/md/md.c
> index 4eb0c6effd5b..dc4b85f30e13 100644
> --- a/drivers/md/md.c
> +++ b/drivers/md/md.c
> @@ -674,39 +674,50 @@ static void no_op(struct percpu_ref *r) {}
>
> static bool mddev_set_bitmap_ops(struct mddev *mddev)
> {
> + struct bitmap_operations *old = mddev->bitmap_ops;
> + struct md_submodule_head *head;
> +
> + if (mddev->bitmap_id == ID_BITMAP_NONE ||
> + (old && old->head.id == mddev->bitmap_id))
> + return true;
> +
> xa_lock(&md_submodule);
> - mddev->bitmap_ops = xa_load(&md_submodule, mddev->bitmap_id);
> + head = xa_load(&md_submodule, mddev->bitmap_id);
> xa_unlock(&md_submodule);
>
> - if (!mddev->bitmap_ops) {
> - pr_warn_once("md: can't find bitmap id %d\n", mddev->bitmap_id);
> + if (WARN_ON_ONCE(!head || head->type != MD_BITMAP)) {
> + pr_err("md: can't find bitmap id %d\n", mddev->bitmap_id);
> return false;
> }
>
> + if (old && old->group)
> + sysfs_remove_group(&mddev->kobj, old->group);
I think you're handling a competition problem here. But I don't know
how the old/old->group is already created when creating an array.
Could you explain this?
Regards
Xiao
> +
> + mddev->bitmap_ops = (void *)head;
> + if (mddev->bitmap_ops && mddev->bitmap_ops->group &&
> + sysfs_create_group(&mddev->kobj, mddev->bitmap_ops->group))
> + pr_warn("md: cannot register extra bitmap attributes for %s\n",
> + mdname(mddev));
> +
> return true;
> }
>
> static void mddev_clear_bitmap_ops(struct mddev *mddev)
> {
> + if (mddev->bitmap_ops && mddev->bitmap_ops->group)
> + sysfs_remove_group(&mddev->kobj, mddev->bitmap_ops->group);
> +
> mddev->bitmap_ops = NULL;
> }
>
> int mddev_init(struct mddev *mddev)
> {
> - mddev->bitmap_id = ID_BITMAP;
> -
> - if (!mddev_set_bitmap_ops(mddev))
> - return -EINVAL;
> -
> if (percpu_ref_init(&mddev->active_io, active_io_release,
> - PERCPU_REF_ALLOW_REINIT, GFP_KERNEL)) {
> - mddev_clear_bitmap_ops(mddev);
> + PERCPU_REF_ALLOW_REINIT, GFP_KERNEL))
> return -ENOMEM;
> - }
>
> if (percpu_ref_init(&mddev->writes_pending, no_op,
> PERCPU_REF_ALLOW_REINIT, GFP_KERNEL)) {
> - mddev_clear_bitmap_ops(mddev);
> percpu_ref_exit(&mddev->active_io);
> return -ENOMEM;
> }
> @@ -734,6 +745,7 @@ int mddev_init(struct mddev *mddev)
> mddev->resync_min = 0;
> mddev->resync_max = MaxSector;
> mddev->level = LEVEL_NONE;
> + mddev->bitmap_id = ID_BITMAP;
>
> INIT_WORK(&mddev->sync_work, md_start_sync);
> INIT_WORK(&mddev->del_work, mddev_delayed_delete);
> @@ -744,7 +756,6 @@ EXPORT_SYMBOL_GPL(mddev_init);
>
> void mddev_destroy(struct mddev *mddev)
> {
> - mddev_clear_bitmap_ops(mddev);
> percpu_ref_exit(&mddev->active_io);
> percpu_ref_exit(&mddev->writes_pending);
> }
> @@ -6093,11 +6104,6 @@ struct mddev *md_alloc(dev_t dev, char *name)
> return ERR_PTR(error);
> }
>
> - if (md_bitmap_registered(mddev) && mddev->bitmap_ops->group)
> - if (sysfs_create_group(&mddev->kobj, mddev->bitmap_ops->group))
> - pr_warn("md: cannot register extra bitmap attributes for %s\n",
> - mdname(mddev));
> -
> kobject_uevent(&mddev->kobj, KOBJ_ADD);
> mddev->sysfs_state = sysfs_get_dirent_safe(mddev->kobj.sd, "array_state");
> mddev->sysfs_level = sysfs_get_dirent_safe(mddev->kobj.sd, "level");
> @@ -6173,6 +6179,26 @@ static void md_safemode_timeout(struct timer_list *t)
>
> static int start_dirty_degraded;
>
> +static int md_bitmap_create(struct mddev *mddev)
> +{
> + if (mddev->bitmap_id == ID_BITMAP_NONE)
> + return -EINVAL;
> +
> + if (!mddev_set_bitmap_ops(mddev))
> + return -ENOENT;
> +
> + return mddev->bitmap_ops->create(mddev);
> +}
> +
> +static void md_bitmap_destroy(struct mddev *mddev)
> +{
> + if (!md_bitmap_registered(mddev))
> + return;
> +
> + mddev->bitmap_ops->destroy(mddev);
> + mddev_clear_bitmap_ops(mddev);
> +}
> +
> int md_run(struct mddev *mddev)
> {
> int err;
> @@ -6337,9 +6363,9 @@ int md_run(struct mddev *mddev)
> (unsigned long long)pers->size(mddev, 0, 0) / 2);
> err = -EINVAL;
> }
> - if (err == 0 && pers->sync_request && md_bitmap_registered(mddev) &&
> + if (err == 0 && pers->sync_request &&
> (mddev->bitmap_info.file || mddev->bitmap_info.offset)) {
> - err = mddev->bitmap_ops->create(mddev);
> + err = md_bitmap_create(mddev);
> if (err)
> pr_warn("%s: failed to create bitmap (%d)\n",
> mdname(mddev), err);
> @@ -6412,8 +6438,7 @@ int md_run(struct mddev *mddev)
> pers->free(mddev, mddev->private);
> mddev->private = NULL;
> put_pers(pers);
> - if (md_bitmap_registered(mddev))
> - mddev->bitmap_ops->destroy(mddev);
> + md_bitmap_destroy(mddev);
> abort:
> bioset_exit(&mddev->io_clone_set);
> exit_sync_set:
> @@ -6436,7 +6461,7 @@ int do_md_run(struct mddev *mddev)
> if (md_bitmap_registered(mddev)) {
> err = mddev->bitmap_ops->load(mddev);
> if (err) {
> - mddev->bitmap_ops->destroy(mddev);
> + md_bitmap_destroy(mddev);
> goto out;
> }
> }
> @@ -6627,8 +6652,7 @@ static void __md_stop(struct mddev *mddev)
> {
> struct md_personality *pers = mddev->pers;
>
> - if (md_bitmap_registered(mddev))
> - mddev->bitmap_ops->destroy(mddev);
> + md_bitmap_destroy(mddev);
> mddev_detach(mddev);
> spin_lock(&mddev->lock);
> mddev->pers = NULL;
> @@ -7408,16 +7432,16 @@ static int set_bitmap_file(struct mddev *mddev, int fd)
> err = 0;
> if (mddev->pers) {
> if (fd >= 0) {
> - err = mddev->bitmap_ops->create(mddev);
> + err = md_bitmap_create(mddev);
> if (!err)
> err = mddev->bitmap_ops->load(mddev);
>
> if (err) {
> - mddev->bitmap_ops->destroy(mddev);
> + md_bitmap_destroy(mddev);
> fd = -1;
> }
> } else if (fd < 0) {
> - mddev->bitmap_ops->destroy(mddev);
> + md_bitmap_destroy(mddev);
> }
> }
>
> @@ -7732,12 +7756,12 @@ 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;
> - rv = mddev->bitmap_ops->create(mddev);
> + rv = md_bitmap_create(mddev);
> if (!rv)
> rv = mddev->bitmap_ops->load(mddev);
>
> if (rv)
> - mddev->bitmap_ops->destroy(mddev);
> + md_bitmap_destroy(mddev);
> } else {
> struct md_bitmap_stats stats;
>
> @@ -7763,7 +7787,7 @@ static int update_array_info(struct mddev *mddev, mdu_array_info_t *info)
> put_cluster_ops(mddev);
> mddev->safemode_delay = DEFAULT_SAFEMODE_DELAY;
> }
> - mddev->bitmap_ops->destroy(mddev);
> + md_bitmap_destroy(mddev);
> mddev->bitmap_info.offset = 0;
> }
> }
> --
> 2.39.2
>
next prev parent reply other threads:[~2025-05-26 6:52 UTC|newest]
Thread overview: 108+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-05-24 6:12 [PATCH 00/23] md/llbitmap: md/md-llbitmap: introduce a new lockless bitmap Yu Kuai
2025-05-24 6:12 ` [PATCH 01/23] md: add a new parameter 'offset' to md_super_write() Yu Kuai
2025-05-25 15:50 ` Xiao Ni
2025-05-26 6:28 ` Christoph Hellwig
2025-05-26 7:28 ` Yu Kuai
2025-05-27 5:54 ` Hannes Reinecke
2025-05-24 6:12 ` [PATCH 02/23] md: factor out a helper raid_is_456() Yu Kuai
2025-05-25 15:50 ` Xiao Ni
2025-05-26 6:28 ` Christoph Hellwig
2025-05-27 5:55 ` Hannes Reinecke
2025-05-24 6:13 ` [PATCH 03/23] md/md-bitmap: cleanup bitmap_ops->startwrite() Yu Kuai
2025-05-25 15:51 ` Xiao Ni
2025-05-26 6:29 ` Christoph Hellwig
2025-05-27 5:56 ` Hannes Reinecke
2025-05-24 6:13 ` [PATCH 04/23] md/md-bitmap: support discard for bitmap ops Yu Kuai
2025-05-25 15:53 ` Xiao Ni
2025-05-26 6:29 ` Christoph Hellwig
2025-05-27 6:01 ` Hannes Reinecke
2025-05-28 7:04 ` Glass Su
2025-05-24 6:13 ` [PATCH 05/23] md/md-bitmap: remove parameter slot from bitmap_create() Yu Kuai
2025-05-25 16:09 ` Xiao Ni
2025-05-26 6:30 ` Christoph Hellwig
2025-05-27 6:01 ` Hannes Reinecke
2025-05-24 6:13 ` [PATCH 06/23] md/md-bitmap: add a new sysfs api bitmap_type Yu Kuai
2025-05-25 16:32 ` Xiao Ni
2025-05-26 1:13 ` Yu Kuai
2025-05-26 5:11 ` Xiao Ni
2025-05-26 8:02 ` Yu Kuai
2025-05-26 6:32 ` Christoph Hellwig
2025-05-26 7:45 ` Yu Kuai
2025-05-27 8:21 ` Christoph Hellwig
2025-05-27 6:10 ` Hannes Reinecke
2025-05-27 7:43 ` Yu Kuai
2025-05-24 6:13 ` [PATCH 07/23] md/md-bitmap: delay registration of bitmap_ops until creating bitmap Yu Kuai
2025-05-26 6:32 ` Christoph Hellwig
2025-05-26 6:52 ` Xiao Ni [this message]
2025-05-26 7:57 ` Yu Kuai
2025-05-27 2:15 ` Xiao Ni
2025-05-27 2:49 ` Yu Kuai
2025-05-27 6:13 ` Hannes Reinecke
2025-05-27 7:53 ` Yu Kuai
2025-05-27 8:54 ` Hannes Reinecke
2025-05-24 6:13 ` [PATCH 08/23] md/md-bitmap: add a new method skip_sync_blocks() in bitmap_operations Yu Kuai
2025-05-26 7:03 ` Xiao Ni
2025-05-27 6:14 ` Hannes Reinecke
2025-05-24 6:13 ` [PATCH 09/23] md/md-bitmap: add a new method blocks_synced() " Yu Kuai
2025-05-27 2:35 ` Xiao Ni
2025-05-27 2:48 ` Yu Kuai
2025-05-27 6:16 ` Hannes Reinecke
2025-05-24 6:13 ` [PATCH 10/23] md: add a new recovery_flag MD_RECOVERY_LAZY_RECOVER Yu Kuai
2025-05-27 6:17 ` Hannes Reinecke
2025-05-27 8:00 ` Yu Kuai
2025-05-24 6:13 ` [PATCH 11/23] md/md-bitmap: make method bitmap_ops->daemon_work optional Yu Kuai
2025-05-26 6:34 ` Christoph Hellwig
2025-05-27 6:19 ` Hannes Reinecke
2025-05-27 8:03 ` Yu Kuai
2025-05-27 8:55 ` Hannes Reinecke
2025-05-24 6:13 ` [PATCH 12/23] md/md-bitmap: add macros for lockless bitmap Yu Kuai
2025-05-26 6:40 ` Christoph Hellwig
2025-05-26 8:12 ` Yu Kuai
2025-05-27 8:22 ` Christoph Hellwig
2025-05-27 6:21 ` Hannes Reinecke
2025-05-28 4:53 ` Xiao Ni
2025-05-24 6:13 ` [PATCH 13/23] md/md-bitmap: fix dm-raid max_write_behind setting Yu Kuai
2025-05-26 6:40 ` Christoph Hellwig
2025-05-27 6:21 ` Hannes Reinecke
2025-05-24 6:13 ` [PATCH 14/23] md/dm-raid: remove max_write_behind setting limit Yu Kuai
2025-05-26 6:41 ` Christoph Hellwig
2025-05-27 6:26 ` Hannes Reinecke
2025-05-28 4:58 ` Xiao Ni
2025-05-24 6:13 ` [PATCH 15/23] md/md-llbitmap: implement llbitmap IO Yu Kuai
2025-05-27 8:27 ` Christoph Hellwig
2025-05-27 8:55 ` Yu Kuai
2025-05-27 8:58 ` Yu Kuai
2025-06-06 3:21 ` Xiao Ni
2025-06-06 3:48 ` Yu Kuai
2025-06-06 6:24 ` Xiao Ni
2025-06-06 8:56 ` Yu Kuai
2025-06-30 2:07 ` Xiao Ni
2025-06-30 2:17 ` Yu Kuai
2025-05-24 6:13 ` [PATCH 16/23] md/md-llbitmap: implement bit state machine Yu Kuai
2025-06-30 2:14 ` Xiao Ni
2025-06-30 2:25 ` Yu Kuai
2025-06-30 8:25 ` Xiao Ni
2025-06-30 11:05 ` Yu Kuai
2025-06-30 11:30 ` Yu Kuai
2025-07-01 1:55 ` Xiao Ni
2025-07-01 2:02 ` Yu Kuai
2025-07-01 2:31 ` Xiao Ni
2025-05-24 6:13 ` [PATCH 17/23] md/md-llbitmap: implement APIs for page level dirty bits synchronization Yu Kuai
2025-05-24 6:13 ` [PATCH 18/23] md/md-llbitmap: implement APIs to mange bitmap lifetime Yu Kuai
2025-05-29 7:03 ` Xiao Ni
2025-05-29 9:03 ` Yu Kuai
2025-05-24 6:13 ` [PATCH 19/23] md/md-llbitmap: implement APIs to dirty bits and clear bits Yu Kuai
2025-05-24 6:13 ` [PATCH 20/23] md/md-llbitmap: implement APIs for sync_thread Yu Kuai
2025-05-24 6:13 ` [PATCH 21/23] md/md-llbitmap: implement all bitmap operations Yu Kuai
2025-05-24 6:13 ` [PATCH 22/23] md/md-llbitmap: implement sysfs APIs Yu Kuai
2025-05-24 6:13 ` [PATCH 23/23] md/md-llbitmap: add Kconfig Yu Kuai
2025-05-27 8:29 ` Christoph Hellwig
2025-05-27 9:00 ` Yu Kuai
2025-05-24 7:07 ` [PATCH 00/23] md/llbitmap: md/md-llbitmap: introduce a new lockless bitmap Yu Kuai
2025-05-30 6:45 ` Yu Kuai
2025-06-30 1:59 ` Xiao Ni
2025-06-30 2:34 ` Yu Kuai
2025-06-30 3:25 ` Xiao Ni
2025-06-30 3:46 ` Yu Kuai
2025-06-30 5:38 ` Xiao Ni
2025-06-30 6:09 ` 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=CALTww2_03_fVt+KMcmtbGw-kcRsLLpAG7W62e3y0W9SpvhUVtg@mail.gmail.com \
--to=xni@redhat.com \
--cc=colyli@kernel.org \
--cc=hch@lst.de \
--cc=johnny.chenyi@huawei.com \
--cc=linux-doc@vger.kernel.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).