Skip to content

Commit

Permalink
Introduce md_cluster_operations to handle cluster functions
Browse files Browse the repository at this point in the history
This allows dynamic registering of cluster hooks.

Signed-off-by: Goldwyn Rodrigues <[email protected]>
  • Loading branch information
goldwynr committed Feb 23, 2015
1 parent 47741b7 commit edb39c9
Show file tree
Hide file tree
Showing 4 changed files with 92 additions and 0 deletions.
18 changes: 18 additions & 0 deletions drivers/md/md-cluster.c
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
#include <linux/dlm.h>
#include <linux/sched.h>
#include "md.h"
#include "md-cluster.h"

#define LVB_SIZE 64

Expand Down Expand Up @@ -113,15 +114,32 @@ static void lockres_free(struct dlm_lock_resource *res)
kfree(res);
}

static int join(struct mddev *mddev, int nodes)
{
return 0;
}

static int leave(struct mddev *mddev)
{
return 0;
}

static struct md_cluster_operations cluster_ops = {
.join = join,
.leave = leave,
};

static int __init cluster_init(void)
{
pr_warn("md-cluster: EXPERIMENTAL. Use with caution\n");
pr_info("Registering Cluster MD functions\n");
register_md_cluster_operations(&cluster_ops, THIS_MODULE);
return 0;
}

static void cluster_exit(void)
{
unregister_md_cluster_operations();
}

module_init(cluster_init);
Expand Down
15 changes: 15 additions & 0 deletions drivers/md/md-cluster.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@


#ifndef _MD_CLUSTER_H
#define _MD_CLUSTER_H

#include "md.h"

struct mddev;

struct md_cluster_operations {
int (*join)(struct mddev *mddev);
int (*leave)(struct mddev *mddev);
};

#endif /* _MD_CLUSTER_H */
52 changes: 52 additions & 0 deletions drivers/md/md.c
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@
#include <linux/slab.h>
#include "md.h"
#include "bitmap.h"
#include "md-cluster.h"

#ifndef MODULE
static void autostart_arrays(int part);
Expand All @@ -66,6 +67,10 @@ static void autostart_arrays(int part);
static LIST_HEAD(pers_list);
static DEFINE_SPINLOCK(pers_lock);

struct md_cluster_operations *md_cluster_ops;
struct module *md_cluster_mod;
EXPORT_SYMBOL(md_cluster_mod);

static DECLARE_WAIT_QUEUE_HEAD(resync_wait);
static struct workqueue_struct *md_wq;
static struct workqueue_struct *md_misc_wq;
Expand Down Expand Up @@ -7231,6 +7236,53 @@ int unregister_md_personality(struct md_personality *p)
}
EXPORT_SYMBOL(unregister_md_personality);

int register_md_cluster_operations(struct md_cluster_operations *ops, struct module *module)
{
if (md_cluster_ops != NULL)
return -EALREADY;
spin_lock(&pers_lock);
md_cluster_ops = ops;
md_cluster_mod = module;
spin_unlock(&pers_lock);
return 0;
}
EXPORT_SYMBOL(register_md_cluster_operations);

int unregister_md_cluster_operations(void)
{
spin_lock(&pers_lock);
md_cluster_ops = NULL;
spin_unlock(&pers_lock);
return 0;
}
EXPORT_SYMBOL(unregister_md_cluster_operations);

int md_setup_cluster(struct mddev *mddev, int nodes)
{
int err;

err = request_module("md-cluster");
if (err) {
pr_err("md-cluster module not found.\n");
return err;
}

spin_lock(&pers_lock);
if (!md_cluster_ops || !try_module_get(md_cluster_mod)) {
spin_unlock(&pers_lock);
return -ENOENT;
}
spin_unlock(&pers_lock);

return md_cluster_ops->join(mddev);
}

void md_cluster_stop(struct mddev *mddev)
{
md_cluster_ops->leave(mddev);
module_put(md_cluster_mod);
}

static int is_mddev_idle(struct mddev *mddev, int init)
{
struct md_rdev *rdev;
Expand Down
7 changes: 7 additions & 0 deletions drivers/md/md.h
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
#include <linux/timer.h>
#include <linux/wait.h>
#include <linux/workqueue.h>
#include "md-cluster.h"

#define MaxSector (~(sector_t)0)

Expand Down Expand Up @@ -608,6 +609,11 @@ static inline void safe_put_page(struct page *p)

extern int register_md_personality(struct md_personality *p);
extern int unregister_md_personality(struct md_personality *p);
extern int register_md_cluster_operations(struct md_cluster_operations *ops,
struct module *module);
extern int unregister_md_cluster_operations(void);
extern int md_setup_cluster(struct mddev *mddev, int nodes);
extern void md_cluster_stop(struct mddev *mddev);
extern struct md_thread *md_register_thread(
void (*run)(struct md_thread *thread),
struct mddev *mddev,
Expand Down Expand Up @@ -669,4 +675,5 @@ static inline void rdev_dec_pending(struct md_rdev *rdev, struct mddev *mddev)
}
}

extern struct md_cluster_operations *md_cluster_ops;
#endif /* _MD_MD_H */

0 comments on commit edb39c9

Please sign in to comment.