md: introduce struct md_submodule_head and APIs

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

Link: https://lore.kernel.org/linux-raid/20250215092225.2427977-4-yukuai1@huaweicloud.com
Signed-off-by: Yu Kuai <yukuai3@huawei.com>
This commit is contained in:
Yu Kuai 2025-02-15 17:22:21 +08:00 committed by Yu Kuai
parent bf0a73264f
commit d3beb7c9c6
3 changed files with 47 additions and 0 deletions

View File

@ -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);

View File

@ -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",

View File

@ -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(