[PATCH md-6.15 3/7] md: introduce struct md_submodule_head and APIs

Yu Kuai
2025-02-15T09:25:59Z

Prepare to unify registration and unregistration of md personalities
and md-cluster, also prepare for add kconfig for md-bitmap.

Signed-off-by: Yu Kuai <yukuai3@huawei.com>
---
drivers/md/md-cluster.h | 2 ++
drivers/md/md.c | 14 ++++++++++++++
drivers/md/md.h | 31 +++++++++++++++++++++++++++++++
3 files changed, 47 insertions(+)

diff --git a/drivers/md/md-cluster.h b/drivers/md/md-cluster.h
index 6c7aad00f5da..4e842af11fb4 100644
--- a/drivers/md/md-cluster.h
+++ b/drivers/md/md-cluster.h
@@ -10,6 +10,8 @@ struct mddev;
struct md_rdev;

struct md_cluster_operations {
+ struct md_submodule_head head;
+
int (*join)(struct mddev *mddev, int nodes);
int (*leave)(struct mddev *mddev);
int (*slot_number)(struct mddev *mddev);
diff --git a/drivers/md/md.c b/drivers/md/md.c
index 37f3a89eba94..6b83039a3dcc 100644
--- a/drivers/md/md.c
+++ b/drivers/md/md.c
@@ -79,6 +79,8 @@ static const char *action_name[NR_SYNC_ACTIONS] = {
[ACTION_IDLE] = "idle",
};

+static DEFINE_XARRAY(md_submodule);
+
/* pers_list is a list of registered personalities protected by pers_lock. */
static LIST_HEAD(pers_list);
static DEFINE_SPINLOCK(pers_lock);
@@ -8522,6 +8524,18 @@ static const struct proc_ops mdstat_proc_ops = {
.proc_poll = mdstat_poll,
};

+int register_md_submodule(struct md_submodule_head *msh)
+{
+ return xa_insert(&md_submodule, msh->id, msh, GFP_KERNEL);
+}
+EXPORT_SYMBOL_GPL(register_md_submodule);
+
+void unregister_md_submodule(struct md_submodule_head *msh)
+{
+ xa_erase(&md_submodule, msh->id);
+}
+EXPORT_SYMBOL_GPL(unregister_md_submodule);
+
int register_md_personality(struct md_personality *p)
{
pr_debug("md: %s personality registered for level %d\n",
diff --git a/drivers/md/md.h b/drivers/md/md.h
index c9bc70e6d5b4..4807fa0d0362 100644
--- a/drivers/md/md.h
+++ b/drivers/md/md.h
@@ -18,10 +18,37 @@
#include <linux/timer.h>
#include <linux/wait.h>
#include <linux/workqueue.h>
+#include <linux/raid/md_u.h>
#include <trace/events/block.h>

#define MaxSector (~(sector_t)0)

+enum md_submodule_type {
+ MD_PERSONALITY = 0,
+ MD_CLUSTER,
+ MD_BITMAP, /* TODO */
+};
+
+enum md_submodule_id {
+ ID_LINEAR = LEVEL_LINEAR,
+ ID_RAID0 = 0,
+ ID_RAID1 = 1,
+ ID_RAID4 = 4,
+ ID_RAID5 = 5,
+ ID_RAID6 = 6,
+ ID_RAID10 = 10,
+ ID_CLUSTER,
+ ID_BITMAP, /* TODO */
+ ID_LLBITMAP, /* TODO */
+};
+
+struct md_submodule_head {
+ enum md_submodule_type type;
+ enum md_submodule_id id;
+ const char *name;
+ struct module *owner;
+};
+
/*
* These flags should really be called "NO_RETRY" rather than
* "FAILFAST" because they don't make any promise about time lapse,
@@ -698,6 +725,7 @@ static inline void md_sync_acct_bio(struct bio *bio, unsigned long nr_sectors)

struct md_personality
{
+ struct md_submodule_head head;
char *name;
int level;
struct list_head list;
@@ -842,6 +870,9 @@ static inline void safe_put_page(struct page *p)
if (p) put_page(p);
}

+int register_md_submodule(struct md_submodule_head *msh);
+void unregister_md_submodule(struct md_submodule_head *msh);
+
extern int register_md_personality(struct md_personality *p);
extern int unregister_md_personality(struct md_personality *p);
extern struct md_thread *md_register_thread(
--
2.39.2