20 #include <linux/module.h>
24 #include <linux/slab.h>
25 #include <linux/reboot.h>
26 #include <asm/uaccess.h>
30 #include <linux/dlm_plock.h>
85 #define OCFS2_CONTROL_PROTO "T01\n"
86 #define OCFS2_CONTROL_PROTO_LEN 4
89 #define OCFS2_CONTROL_HANDSHAKE_INVALID (0)
90 #define OCFS2_CONTROL_HANDSHAKE_READ (1)
91 #define OCFS2_CONTROL_HANDSHAKE_PROTOCOL (2)
92 #define OCFS2_CONTROL_HANDSHAKE_VALID (3)
95 #define OCFS2_CONTROL_MESSAGE_OP_LEN 4
96 #define OCFS2_CONTROL_MESSAGE_SETNODE_OP "SETN"
97 #define OCFS2_CONTROL_MESSAGE_SETNODE_TOTAL_LEN 14
98 #define OCFS2_CONTROL_MESSAGE_SETVERSION_OP "SETV"
99 #define OCFS2_CONTROL_MESSAGE_SETVERSION_TOTAL_LEN 11
100 #define OCFS2_CONTROL_MESSAGE_DOWN_OP "DOWN"
101 #define OCFS2_CONTROL_MESSAGE_DOWN_TOTAL_LEN 47
102 #define OCFS2_TEXT_UUID_LEN 32
103 #define OCFS2_CONTROL_MESSAGE_VERNUM_LEN 2
104 #define OCFS2_CONTROL_MESSAGE_NODENUM_LEN 8
159 static atomic_t ocfs2_control_opened;
160 static int ocfs2_control_this_node = -1;
163 static LIST_HEAD(ocfs2_live_connection_list);
164 static LIST_HEAD(ocfs2_control_private_list);
167 static inline void ocfs2_control_set_handshake_state(
struct file *
file,
174 static inline int ocfs2_control_get_handshake_state(
struct file *
file)
185 BUG_ON(!mutex_is_locked(&ocfs2_control_lock));
188 if ((c->
oc_conn->cc_namelen == len) &&
215 list_add(&c->
oc_list, &ocfs2_live_connection_list);
218 "ocfs2: Userspace control daemon is not present\n");
246 static int ocfs2_control_cfu(
void *
target,
size_t target_len,
247 const char __user *
buf,
size_t count)
250 if ((count != target_len) ||
261 const char __user *buf,
275 ocfs2_control_set_handshake_state(file,
281 static void ocfs2_control_send_down(
const char *
uuid,
288 c = ocfs2_connection_find(uuid);
291 c->
oc_conn->cc_recovery_handler(nodenum,
305 static int ocfs2_control_install_private(
struct file *file)
317 }
else if ((ocfs2_control_this_node >= 0) &&
325 }
else if (!list_empty(&ocfs2_live_connection_list) &&
326 ((running_proto.pv_major != p->
op_proto.pv_major) ||
327 (running_proto.pv_minor != p->
op_proto.pv_minor))) {
334 running_proto.pv_major = p->
op_proto.pv_major;
335 running_proto.pv_minor = p->
op_proto.pv_minor;
344 ocfs2_control_set_handshake_state(file,
351 static int ocfs2_control_get_this_node(
void)
356 if (ocfs2_control_this_node < 0)
359 rc = ocfs2_control_this_node;
365 static int ocfs2_control_do_setnode_msg(
struct file *file,
372 if (ocfs2_control_get_handshake_state(file) !=
389 (nodenum >
INT_MAX) || (nodenum < 0))
393 return ocfs2_control_install_private(file);
396 static int ocfs2_control_do_setversion_msg(
struct file *file,
403 &ocfs2_user_plugin.sp_max_proto;
405 if (ocfs2_control_get_handshake_state(file) !=
431 (major > (
u8)-1) || (major < 1))
434 (minor > (
u8)-1) || (minor < 0))
443 return ocfs2_control_install_private(file);
446 static int ocfs2_control_do_down_msg(
struct file *file,
452 if (ocfs2_control_get_handshake_state(file) !=
470 (nodenum >
INT_MAX) || (nodenum < 0))
473 ocfs2_control_send_down(msg->
uuid, nodenum);
479 const char __user *buf,
487 (
sizeof(msg.u_down.
tag) +
sizeof(msg.u_down.
space1)));
490 ret = ocfs2_control_cfu(&msg, count, buf, count);
497 ret = ocfs2_control_do_setnode_msg(file, &msg.u_setn);
501 ret = ocfs2_control_do_setversion_msg(file, &msg.u_setv);
505 ret = ocfs2_control_do_down_msg(file, &msg.u_down);
510 return ret ? ret :
count;
513 static ssize_t ocfs2_control_write(
struct file *file,
514 const char __user *buf,
520 switch (ocfs2_control_get_handshake_state(file)) {
526 ret = ocfs2_control_validate_protocol(file, buf,
548 static ssize_t ocfs2_control_read(
struct file *file,
560 ocfs2_control_set_handshake_state(file,
566 static int ocfs2_control_release(
struct inode *
inode,
struct file *file)
572 if (ocfs2_control_get_handshake_state(file) !=
577 if (!list_empty(&ocfs2_live_connection_list)) {
580 "ocfs2: Unexpected release of ocfs2_control!\n"
581 " Loss of cluster connection requires "
582 "an emergency restart!\n");
589 ocfs2_control_this_node = -1;
590 running_proto.pv_major = 0;
591 running_proto.pv_major = 0;
605 static int ocfs2_control_open(
struct inode *inode,
struct file *file)
616 list_add(&p->
op_list, &ocfs2_control_private_list);
623 .open = ocfs2_control_open,
624 .release = ocfs2_control_release,
625 .read = ocfs2_control_read,
626 .write = ocfs2_control_write,
631 static struct miscdevice ocfs2_control_device = {
633 .name =
"ocfs2_control",
634 .fops = &ocfs2_control_fops,
637 static int ocfs2_control_init(
void)
646 "ocfs2: Unable to register ocfs2_control device "
653 static void ocfs2_control_exit(
void)
660 "ocfs2: Unable to deregister ocfs2_control device "
665 static void fsdlm_lock_ast_wrapper(
void *astarg)
681 lksb->
lksb_conn->cc_proto->lp_unlock_ast(lksb, 0);
683 lksb->
lksb_conn->cc_proto->lp_lock_ast(lksb);
686 static void fsdlm_blocking_ast_wrapper(
void *astarg,
int level)
690 lksb->
lksb_conn->cc_proto->lp_blocking_ast(lksb, level);
708 fsdlm_lock_ast_wrapper, lksb,
709 fsdlm_blocking_ast_wrapper);
810 rc = ocfs2_live_connection_new(conn, &
control);
818 if (fs_protocol_compare(&running_proto, &conn->
cc_version)) {
820 "Unable to mount with fs locking protocol version "
821 "%u.%u because the userspace control daemon has "
822 "negotiated %u.%u\n",
824 running_proto.pv_major, running_proto.pv_minor);
826 ocfs2_live_connection_drop(
control);
833 ocfs2_live_connection_drop(
control);
852 static int user_cluster_this_node(
unsigned int *this_node)
856 rc = ocfs2_control_get_this_node();
865 .connect = user_cluster_connect,
866 .disconnect = user_cluster_disconnect,
867 .this_node = user_cluster_this_node,
868 .dlm_lock = user_dlm_lock,
869 .dlm_unlock = user_dlm_unlock,
870 .lock_status = user_dlm_lock_status,
871 .lvb_valid = user_dlm_lvb_valid,
872 .lock_lvb = user_dlm_lvb,
874 .dump_lksb = user_dlm_dump_lksb,
879 .sp_ops = &ocfs2_user_plugin_ops,
884 static int __init ocfs2_user_plugin_init(
void)
888 rc = ocfs2_control_init();
892 ocfs2_control_exit();
898 static void __exit ocfs2_user_plugin_exit(
void)
901 ocfs2_control_exit();