From: Yu Kuai <yukuai1@huaweicloud.com>
To: hch@lst.de, corbet@lwn.net, song@kernel.org, yukuai3@huawei.com,
agk@redhat.com, snitzer@kernel.org, mpatocka@redhat.com,
linan122@huawei.com, xni@redhat.com, hare@suse.de
Cc: linux-doc@vger.kernel.org, linux-kernel@vger.kernel.org,
linux-raid@vger.kernel.org, dm-devel@lists.linux.dev,
yukuai1@huaweicloud.com, yi.zhang@huawei.com,
yangerkun@huawei.com, johnny.chenyi@huawei.com
Subject: [PATCH v5 04/11] md: add a new mddev field 'bitmap_id'
Date: Fri, 1 Aug 2025 15:03:39 +0800 [thread overview]
Message-ID: <20250801070346.4127558-5-yukuai1@huaweicloud.com> (raw)
In-Reply-To: <20250801070346.4127558-1-yukuai1@huaweicloud.com>
From: Yu Kuai <yukuai3@huawei.com>
Prepare to store the bitmap id selected by user, also refactor
mddev_set_bitmap_ops a bit in case the value is invalid.
Signed-off-by: Yu Kuai <yukuai3@huawei.com>
Reviewed-by: Hannes Reinecke <hare@suse.de>
Reviewed-by: Li Nan <linan122@huawei.com>
Reviewed-by: Xiao Ni <xni@redhat.com>
---
drivers/md/md.c | 37 +++++++++++++++++++++++++++++++------
drivers/md/md.h | 2 ++
2 files changed, 33 insertions(+), 6 deletions(-)
diff --git a/drivers/md/md.c b/drivers/md/md.c
index 4e90d2143813..393e6547a086 100644
--- a/drivers/md/md.c
+++ b/drivers/md/md.c
@@ -675,13 +675,33 @@ static void active_io_release(struct percpu_ref *ref)
static void no_op(struct percpu_ref *r) {}
-static void mddev_set_bitmap_ops(struct mddev *mddev, enum md_submodule_id id)
+static bool mddev_set_bitmap_ops(struct mddev *mddev)
{
+ struct md_submodule_head *head;
+
+ if (mddev->bitmap_id == ID_BITMAP_NONE)
+ return true;
+
xa_lock(&md_submodule);
- mddev->bitmap_ops = xa_load(&md_submodule, id);
+ head = xa_load(&md_submodule, mddev->bitmap_id);
+
+ if (!head) {
+ pr_warn("md: can't find bitmap id %d\n", mddev->bitmap_id);
+ goto err;
+ }
+
+ if (head->type != MD_BITMAP) {
+ pr_warn("md: invalid bitmap id %d\n", mddev->bitmap_id);
+ goto err;
+ }
+
+ mddev->bitmap_ops = (void *)head;
xa_unlock(&md_submodule);
- if (!mddev->bitmap_ops)
- pr_warn_once("md: can't find bitmap id %d\n", id);
+ return true;
+
+err:
+ xa_unlock(&md_submodule);
+ return false;
}
static void mddev_clear_bitmap_ops(struct mddev *mddev)
@@ -691,8 +711,13 @@ static void mddev_clear_bitmap_ops(struct mddev *mddev)
int mddev_init(struct mddev *mddev)
{
- /* TODO: support more versions */
- mddev_set_bitmap_ops(mddev, ID_BITMAP);
+ if (!IS_ENABLED(CONFIG_MD_BITMAP)) {
+ mddev->bitmap_id = ID_BITMAP_NONE;
+ } else {
+ 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)) {
diff --git a/drivers/md/md.h b/drivers/md/md.h
index 1b767b5320cf..4fa5a3e68a0c 100644
--- a/drivers/md/md.h
+++ b/drivers/md/md.h
@@ -40,6 +40,7 @@ enum md_submodule_id {
ID_CLUSTER,
ID_BITMAP,
ID_LLBITMAP, /* TODO */
+ ID_BITMAP_NONE,
};
struct md_submodule_head {
@@ -565,6 +566,7 @@ struct mddev {
struct percpu_ref writes_pending;
int sync_checkers; /* # of threads checking writes_pending */
+ enum md_submodule_id bitmap_id;
void *bitmap; /* the bitmap for the device */
struct bitmap_operations *bitmap_ops;
struct {
--
2.39.2
next prev parent reply other threads:[~2025-08-01 7:10 UTC|newest]
Thread overview: 18+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-08-01 7:03 [PATCH v5 00/11] md/llbitmap: md/md-llbitmap: introduce a new lockless bitmap Yu Kuai
2025-08-01 7:03 ` [PATCH v5 01/11] md: add a new parameter 'offset' to md_super_write() Yu Kuai
2025-08-01 7:03 ` [PATCH v5 02/11] md: factor out a helper raid_is_456() Yu Kuai
2025-08-01 7:03 ` [PATCH v5 03/11] md/md-bitmap: support discard for bitmap ops Yu Kuai
2025-08-01 7:03 ` Yu Kuai [this message]
2025-08-01 7:03 ` [PATCH v5 05/11] md/md-bitmap: add a new sysfs api bitmap_type Yu Kuai
2025-08-01 7:03 ` [PATCH v5 06/11] md/md-bitmap: delay registration of bitmap_ops until creating bitmap Yu Kuai
2025-08-01 7:03 ` [PATCH v5 07/11] md/md-bitmap: add a new method skip_sync_blocks() in bitmap_operations Yu Kuai
2025-08-01 7:03 ` [PATCH v5 08/11] md/md-bitmap: add a new method blocks_synced() " Yu Kuai
2025-08-04 9:15 ` Xiao Ni
2025-08-05 1:15 ` Yu Kuai
2025-08-01 7:03 ` [PATCH v5 09/11] md: add a new recovery_flag MD_RECOVERY_LAZY_RECOVER Yu Kuai
2025-08-01 7:03 ` [PATCH v5 10/11] md/md-bitmap: make method bitmap_ops->daemon_work optional Yu Kuai
2025-08-01 7:03 ` [PATCH v5 11/11] md/md-llbitmap: introduce new lockless bitmap Yu Kuai
2025-08-03 9:48 ` Li Nan
2025-08-03 10:33 ` Yu Kuai
2025-08-07 3:57 ` Xiao Ni
2025-08-08 6:17 ` 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=20250801070346.4127558-5-yukuai1@huaweicloud.com \
--to=yukuai1@huaweicloud.com \
--cc=agk@redhat.com \
--cc=corbet@lwn.net \
--cc=dm-devel@lists.linux.dev \
--cc=hare@suse.de \
--cc=hch@lst.de \
--cc=johnny.chenyi@huawei.com \
--cc=linan122@huawei.com \
--cc=linux-doc@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-raid@vger.kernel.org \
--cc=mpatocka@redhat.com \
--cc=snitzer@kernel.org \
--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 NNTP newsgroup(s).