21 #include <linux/list.h>
23 #include <linux/module.h>
24 #include <linux/slab.h>
29 #include <linux/sysctl.h>
35 #define OCFS2_STACK_PLUGIN_O2CB "o2cb"
36 #define OCFS2_STACK_PLUGIN_USER "user"
37 #define OCFS2_MAX_HB_CTL_PATH 256
65 static int ocfs2_stack_driver_request(
const char *stack_name,
66 const char *plugin_name)
71 spin_lock(&ocfs2_stack_lock);
77 if (
strcmp(stack_name, cluster_stack_name)) {
94 p = ocfs2_stack_lookup(plugin_name);
95 if (!p || !try_module_get(p->
sp_owner)) {
108 spin_unlock(&ocfs2_stack_lock);
117 static int ocfs2_stack_driver_get(
const char *stack_name)
126 if (!stack_name || !*stack_name)
131 "ocfs2 passed an invalid cluster stack label: \"%s\"\n",
140 rc = ocfs2_stack_driver_request(stack_name, plugin_name);
142 request_module(
"ocfs2_stack_%s", plugin_name);
143 rc = ocfs2_stack_driver_request(stack_name, plugin_name);
148 "ocfs2: Cluster stack driver \"%s\" cannot be found\n",
150 }
else if (rc == -
EBUSY) {
152 "ocfs2: A different cluster stack is in use\n");
158 static void ocfs2_stack_driver_put(
void)
160 spin_lock(&ocfs2_stack_lock);
169 spin_unlock(&ocfs2_stack_lock);
176 spin_lock(&ocfs2_stack_lock);
177 if (!ocfs2_stack_lookup(plugin->
sp_name)) {
180 list_add(&plugin->
sp_list, &ocfs2_stack_list);
189 spin_unlock(&ocfs2_stack_lock);
199 spin_lock(&ocfs2_stack_lock);
200 p = ocfs2_stack_lookup(plugin->
sp_name);
203 BUG_ON(plugin == active_stack);
205 list_del_init(&plugin->
sp_list);
212 spin_unlock(&ocfs2_stack_lock);
220 spin_lock(&ocfs2_stack_lock);
221 if (
memcmp(max_proto, &locking_max_version,
223 BUG_ON(locking_max_version.pv_major != 0);
225 locking_max_version = *max_proto;
230 spin_unlock(&ocfs2_stack_lock);
252 return active_stack->
sp_ops->dlm_lock(conn, mode, lksb, flags,
263 return active_stack->
sp_ops->dlm_unlock(conn, lksb, flags);
269 return active_stack->
sp_ops->lock_status(lksb);
275 return active_stack->
sp_ops->lvb_valid(lksb);
281 return active_stack->
sp_ops->lock_lvb(lksb);
287 active_stack->
sp_ops->dump_lksb(lksb);
293 return active_stack && active_stack->
sp_ops->plock;
305 if (active_stack->
sp_ops->plock)
306 return active_stack->
sp_ops->plock(conn, ino, file, cmd, fl);
315 void (*recovery_handler)(
int node_num,
316 void *recovery_data),
355 rc = ocfs2_stack_driver_get(stack_name);
359 rc = active_stack->
sp_ops->connect(new_conn);
361 ocfs2_stack_driver_put();
380 void (*recovery_handler)(
int node_num,
381 void *recovery_data),
385 char *stack_name =
NULL;
387 if (cluster_stack_name[0])
388 stack_name = cluster_stack_name;
390 recovery_handler, recovery_data, conn);
402 ret = active_stack->
sp_ops->disconnect(conn);
408 ocfs2_stack_driver_put();
419 static void ocfs2_leave_group(
const char *group)
422 char *argv[5], *envp[3];
424 argv[0] = ocfs2_hb_ctl_path;
427 argv[3] = (
char *)group;
432 envp[1] =
"PATH=/sbin:/bin:/usr/sbin:/usr/bin";
435 ret = call_usermodehelper(argv[0], argv, envp,
UMH_WAIT_PROC);
438 "ocfs2: Error %d running user helper "
440 ret, argv[0], argv[1], argv[2], argv[3]);
454 BUG_ON(group[grouplen] !=
'\0');
456 ocfs2_leave_group(group);
459 ocfs2_stack_driver_put();
465 return active_stack->
sp_ops->this_node(node);
474 static ssize_t ocfs2_max_locking_protocol_show(
struct kobject *kobj,
480 spin_lock(&ocfs2_stack_lock);
481 if (locking_max_version.pv_major)
483 locking_max_version.pv_major,
484 locking_max_version.pv_minor);
485 spin_unlock(&ocfs2_stack_lock);
492 ocfs2_max_locking_protocol_show,
NULL);
494 static ssize_t ocfs2_loaded_cluster_plugins_show(
struct kobject *kobj,
501 spin_lock(&ocfs2_stack_lock);
517 spin_unlock(&ocfs2_stack_lock);
524 ocfs2_loaded_cluster_plugins_show,
NULL);
526 static ssize_t ocfs2_active_cluster_plugin_show(
struct kobject *kobj,
532 spin_lock(&ocfs2_stack_lock);
539 spin_unlock(&ocfs2_stack_lock);
546 ocfs2_active_cluster_plugin_show,
NULL);
553 spin_lock(&ocfs2_stack_lock);
555 spin_unlock(&ocfs2_stack_lock);
562 const char *buf,
size_t count)
570 if (buf[len - 1] ==
'\n')
577 spin_lock(&ocfs2_stack_lock);
579 if (!
strncmp(buf, cluster_stack_name, len))
584 memcpy(cluster_stack_name, buf, len);
587 spin_unlock(&ocfs2_stack_lock);
595 ocfs2_cluster_stack_show,
596 ocfs2_cluster_stack_store);
598 static struct attribute *ocfs2_attrs[] = {
599 &ocfs2_attr_max_locking_protocol.
attr,
600 &ocfs2_attr_loaded_cluster_plugins.
attr,
601 &ocfs2_attr_active_cluster_plugin.
attr,
602 &ocfs2_attr_cluster_stack.
attr,
607 .attrs = ocfs2_attrs,
610 static struct kset *ocfs2_kset;
612 static void ocfs2_sysfs_exit(
void)
617 static int ocfs2_sysfs_init(
void)
644 #define FS_OCFS2_NM 1
649 .data = ocfs2_hb_ctl_path,
663 .child = ocfs2_nm_table
674 .child = ocfs2_mod_table
685 .child = ocfs2_kern_table
697 static int __init ocfs2_stack_glue_init(
void)
702 if (!ocfs2_table_header) {
704 "ocfs2 stack glue: unable to register sysctl\n");
708 return ocfs2_sysfs_init();
711 static void __exit ocfs2_stack_glue_exit(
void)
713 memset(&locking_max_version, 0,
715 locking_max_version.pv_major = 0;
716 locking_max_version.pv_minor = 0;
718 if (ocfs2_table_header)