Skip to content

Commit d3beb7c

Browse files
YuKuai-huaweiYu Kuai
authored andcommitted
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/[email protected] Signed-off-by: Yu Kuai <[email protected]>
1 parent bf0a732 commit d3beb7c

File tree

3 files changed

+47
-0
lines changed

3 files changed

+47
-0
lines changed

drivers/md/md-cluster.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,8 @@ struct mddev;
1010
struct md_rdev;
1111

1212
struct md_cluster_operations {
13+
struct md_submodule_head head;
14+
1315
int (*join)(struct mddev *mddev, int nodes);
1416
int (*leave)(struct mddev *mddev);
1517
int (*slot_number)(struct mddev *mddev);

drivers/md/md.c

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,8 @@ static const char *action_name[NR_SYNC_ACTIONS] = {
7979
[ACTION_IDLE] = "idle",
8080
};
8181

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

8527+
int register_md_submodule(struct md_submodule_head *msh)
8528+
{
8529+
return xa_insert(&md_submodule, msh->id, msh, GFP_KERNEL);
8530+
}
8531+
EXPORT_SYMBOL_GPL(register_md_submodule);
8532+
8533+
void unregister_md_submodule(struct md_submodule_head *msh)
8534+
{
8535+
xa_erase(&md_submodule, msh->id);
8536+
}
8537+
EXPORT_SYMBOL_GPL(unregister_md_submodule);
8538+
85258539
int register_md_personality(struct md_personality *p)
85268540
{
85278541
pr_debug("md: %s personality registered for level %d\n",

drivers/md/md.h

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,10 +18,37 @@
1818
#include <linux/timer.h>
1919
#include <linux/wait.h>
2020
#include <linux/workqueue.h>
21+
#include <linux/raid/md_u.h>
2122
#include <trace/events/block.h>
2223

2324
#define MaxSector (~(sector_t)0)
2425

26+
enum md_submodule_type {
27+
MD_PERSONALITY = 0,
28+
MD_CLUSTER,
29+
MD_BITMAP, /* TODO */
30+
};
31+
32+
enum md_submodule_id {
33+
ID_LINEAR = LEVEL_LINEAR,
34+
ID_RAID0 = 0,
35+
ID_RAID1 = 1,
36+
ID_RAID4 = 4,
37+
ID_RAID5 = 5,
38+
ID_RAID6 = 6,
39+
ID_RAID10 = 10,
40+
ID_CLUSTER,
41+
ID_BITMAP, /* TODO */
42+
ID_LLBITMAP, /* TODO */
43+
};
44+
45+
struct md_submodule_head {
46+
enum md_submodule_type type;
47+
enum md_submodule_id id;
48+
const char *name;
49+
struct module *owner;
50+
};
51+
2552
/*
2653
* These flags should really be called "NO_RETRY" rather than
2754
* "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)
698725

699726
struct md_personality
700727
{
728+
struct md_submodule_head head;
701729
char *name;
702730
int level;
703731
struct list_head list;
@@ -842,6 +870,9 @@ static inline void safe_put_page(struct page *p)
842870
if (p) put_page(p);
843871
}
844872

873+
int register_md_submodule(struct md_submodule_head *msh);
874+
void unregister_md_submodule(struct md_submodule_head *msh);
875+
845876
extern int register_md_personality(struct md_personality *p);
846877
extern int unregister_md_personality(struct md_personality *p);
847878
extern struct md_thread *md_register_thread(

0 commit comments

Comments
 (0)