]> err.no Git - linux-2.6/blobdiff - fs/ocfs2/stack_user.c
Merge branch 'linus' into x86/cleanups
[linux-2.6] / fs / ocfs2 / stack_user.c
index de982c11e69bd3f0f833b474bb0a7f2ac2ac98f7..6b97d11f6bf89c067912c2c7c571af2430ea0e2b 100644 (file)
@@ -24,6 +24,7 @@
 #include <linux/reboot.h>
 #include <asm/uaccess.h>
 
+#include "ocfs2.h"  /* For struct ocfs2_lock_res */
 #include "stackglue.h"
 
 
@@ -60,7 +61,7 @@
  * negotiated by the client.  The client negotiates based on the maximum
  * version advertised in /sys/fs/ocfs2/max_locking_protocol.  The major
  * number from the "SETV" message must match
- * user_stack.sp_proto->lp_max_version.pv_major, and the minor number
+ * ocfs2_user_plugin.sp_proto->lp_max_version.pv_major, and the minor number
  * must be less than or equal to ...->lp_max_version.pv_minor.
  *
  * Once this information has been set, mounts will be allowed.  From this
@@ -152,6 +153,8 @@ union ocfs2_control_message {
        struct ocfs2_control_message_down       u_down;
 };
 
+static struct ocfs2_stack_plugin ocfs2_user_plugin;
+
 static atomic_t ocfs2_control_opened;
 static int ocfs2_control_this_node = -1;
 static struct ocfs2_protocol_version running_proto;
@@ -344,6 +347,20 @@ out_unlock:
        return rc;
 }
 
+static int ocfs2_control_get_this_node(void)
+{
+       int rc;
+
+       mutex_lock(&ocfs2_control_lock);
+       if (ocfs2_control_this_node < 0)
+               rc = -EINVAL;
+       else
+               rc = ocfs2_control_this_node;
+       mutex_unlock(&ocfs2_control_lock);
+
+       return rc;
+}
+
 static int ocfs2_control_do_setnode_msg(struct file *file,
                                        struct ocfs2_control_message_setn *msg)
 {
@@ -382,7 +399,7 @@ static int ocfs2_control_do_setversion_msg(struct file *file,
        char *ptr = NULL;
        struct ocfs2_control_private *p = file->private_data;
        struct ocfs2_protocol_version *max =
-               &user_stack.sp_proto->lp_max_version;
+               &ocfs2_user_plugin.sp_proto->lp_max_version;
 
        if (ocfs2_control_get_handshake_state(file) !=
            OCFS2_CONTROL_HANDSHAKE_PROTOCOL)
@@ -618,7 +635,7 @@ static const struct file_operations ocfs2_control_fops = {
        .owner   = THIS_MODULE,
 };
 
-struct miscdevice ocfs2_control_device = {
+static struct miscdevice ocfs2_control_device = {
        .minor          = MISC_DYNAMIC_MINOR,
        .name           = "ocfs2_control",
        .fops           = &ocfs2_control_fops,
@@ -652,18 +669,215 @@ static void ocfs2_control_exit(void)
                       -rc);
 }
 
-static int __init user_stack_init(void)
+static struct dlm_lksb *fsdlm_astarg_to_lksb(void *astarg)
+{
+       struct ocfs2_lock_res *res = astarg;
+       return &res->l_lksb.lksb_fsdlm;
+}
+
+static void fsdlm_lock_ast_wrapper(void *astarg)
+{
+       struct dlm_lksb *lksb = fsdlm_astarg_to_lksb(astarg);
+       int status = lksb->sb_status;
+
+       BUG_ON(ocfs2_user_plugin.sp_proto == NULL);
+
+       /*
+        * For now we're punting on the issue of other non-standard errors
+        * where we can't tell if the unlock_ast or lock_ast should be called.
+        * The main "other error" that's possible is EINVAL which means the
+        * function was called with invalid args, which shouldn't be possible
+        * since the caller here is under our control.  Other non-standard
+        * errors probably fall into the same category, or otherwise are fatal
+        * which means we can't carry on anyway.
+        */
+
+       if (status == -DLM_EUNLOCK || status == -DLM_ECANCEL)
+               ocfs2_user_plugin.sp_proto->lp_unlock_ast(astarg, 0);
+       else
+               ocfs2_user_plugin.sp_proto->lp_lock_ast(astarg);
+}
+
+static void fsdlm_blocking_ast_wrapper(void *astarg, int level)
+{
+       BUG_ON(ocfs2_user_plugin.sp_proto == NULL);
+
+       ocfs2_user_plugin.sp_proto->lp_blocking_ast(astarg, level);
+}
+
+static int user_dlm_lock(struct ocfs2_cluster_connection *conn,
+                        int mode,
+                        union ocfs2_dlm_lksb *lksb,
+                        u32 flags,
+                        void *name,
+                        unsigned int namelen,
+                        void *astarg)
 {
-       return ocfs2_control_init();
+       int ret;
+
+       if (!lksb->lksb_fsdlm.sb_lvbptr)
+               lksb->lksb_fsdlm.sb_lvbptr = (char *)lksb +
+                                            sizeof(struct dlm_lksb);
+
+       ret = dlm_lock(conn->cc_lockspace, mode, &lksb->lksb_fsdlm,
+                      flags|DLM_LKF_NODLCKWT, name, namelen, 0,
+                      fsdlm_lock_ast_wrapper, astarg,
+                      fsdlm_blocking_ast_wrapper);
+       return ret;
+}
+
+static int user_dlm_unlock(struct ocfs2_cluster_connection *conn,
+                          union ocfs2_dlm_lksb *lksb,
+                          u32 flags,
+                          void *astarg)
+{
+       int ret;
+
+       ret = dlm_unlock(conn->cc_lockspace, lksb->lksb_fsdlm.sb_lkid,
+                        flags, &lksb->lksb_fsdlm, astarg);
+       return ret;
+}
+
+static int user_dlm_lock_status(union ocfs2_dlm_lksb *lksb)
+{
+       return lksb->lksb_fsdlm.sb_status;
+}
+
+static void *user_dlm_lvb(union ocfs2_dlm_lksb *lksb)
+{
+       return (void *)(lksb->lksb_fsdlm.sb_lvbptr);
+}
+
+static void user_dlm_dump_lksb(union ocfs2_dlm_lksb *lksb)
+{
+}
+
+/*
+ * Compare a requested locking protocol version against the current one.
+ *
+ * If the major numbers are different, they are incompatible.
+ * If the current minor is greater than the request, they are incompatible.
+ * If the current minor is less than or equal to the request, they are
+ * compatible, and the requester should run at the current minor version.
+ */
+static int fs_protocol_compare(struct ocfs2_protocol_version *existing,
+                              struct ocfs2_protocol_version *request)
+{
+       if (existing->pv_major != request->pv_major)
+               return 1;
+
+       if (existing->pv_minor > request->pv_minor)
+               return 1;
+
+       if (existing->pv_minor < request->pv_minor)
+               request->pv_minor = existing->pv_minor;
+
+       return 0;
+}
+
+static int user_cluster_connect(struct ocfs2_cluster_connection *conn)
+{
+       dlm_lockspace_t *fsdlm;
+       struct ocfs2_live_connection *control;
+       int rc = 0;
+
+       BUG_ON(conn == NULL);
+
+       rc = ocfs2_live_connection_new(conn, &control);
+       if (rc)
+               goto out;
+
+       /*
+        * running_proto must have been set before we allowed any mounts
+        * to proceed.
+        */
+       if (fs_protocol_compare(&running_proto, &conn->cc_version)) {
+               printk(KERN_ERR
+                      "Unable to mount with fs locking protocol version "
+                      "%u.%u because the userspace control daemon has "
+                      "negotiated %u.%u\n",
+                      conn->cc_version.pv_major, conn->cc_version.pv_minor,
+                      running_proto.pv_major, running_proto.pv_minor);
+               rc = -EPROTO;
+               ocfs2_live_connection_drop(control);
+               goto out;
+       }
+
+       rc = dlm_new_lockspace(conn->cc_name, strlen(conn->cc_name),
+                              &fsdlm, DLM_LSFL_FS, DLM_LVB_LEN);
+       if (rc) {
+               ocfs2_live_connection_drop(control);
+               goto out;
+       }
+
+       conn->cc_private = control;
+       conn->cc_lockspace = fsdlm;
+out:
+       return rc;
+}
+
+static int user_cluster_disconnect(struct ocfs2_cluster_connection *conn,
+                                  int hangup_pending)
+{
+       dlm_release_lockspace(conn->cc_lockspace, 2);
+       conn->cc_lockspace = NULL;
+       ocfs2_live_connection_drop(conn->cc_private);
+       conn->cc_private = NULL;
+       return 0;
+}
+
+static int user_cluster_this_node(unsigned int *this_node)
+{
+       int rc;
+
+       rc = ocfs2_control_get_this_node();
+       if (rc < 0)
+               return rc;
+
+       *this_node = rc;
+       return 0;
+}
+
+static struct ocfs2_stack_operations ocfs2_user_plugin_ops = {
+       .connect        = user_cluster_connect,
+       .disconnect     = user_cluster_disconnect,
+       .this_node      = user_cluster_this_node,
+       .dlm_lock       = user_dlm_lock,
+       .dlm_unlock     = user_dlm_unlock,
+       .lock_status    = user_dlm_lock_status,
+       .lock_lvb       = user_dlm_lvb,
+       .dump_lksb      = user_dlm_dump_lksb,
+};
+
+static struct ocfs2_stack_plugin ocfs2_user_plugin = {
+       .sp_name        = "user",
+       .sp_ops         = &ocfs2_user_plugin_ops,
+       .sp_owner       = THIS_MODULE,
+};
+
+
+static int __init ocfs2_user_plugin_init(void)
+{
+       int rc;
+
+       rc = ocfs2_control_init();
+       if (!rc) {
+               rc = ocfs2_stack_glue_register(&ocfs2_user_plugin);
+               if (rc)
+                       ocfs2_control_exit();
+       }
+
+       return rc;
 }
 
-static void __exit user_stack_exit(void)
+static void __exit ocfs2_user_plugin_exit(void)
 {
+       ocfs2_stack_glue_unregister(&ocfs2_user_plugin);
        ocfs2_control_exit();
 }
 
 MODULE_AUTHOR("Oracle");
 MODULE_DESCRIPTION("ocfs2 driver for userspace cluster stacks");
 MODULE_LICENSE("GPL");
-module_init(user_stack_init);
-module_exit(user_stack_exit);
+module_init(ocfs2_user_plugin_init);
+module_exit(ocfs2_user_plugin_exit);