Whamcloud - gitweb
LU-1330 fid: prepare FID module for client server split
[fs/lustre-release.git] / lustre / fid / fid_request.c
index a929833..d0da85e 100644 (file)
 
 #include <obd.h>
 #include <obd_class.h>
-#include <dt_object.h>
-#include <md_object.h>
 #include <obd_support.h>
-#include <lustre_req_layout.h>
 #include <lustre_fid.h>
 /* mdc RPC locks */
 #include <lustre_mdc.h>
@@ -156,13 +153,15 @@ int seq_client_alloc_super(struct lu_client_seq *seq,
 
        mutex_lock(&seq->lcs_mutex);
 
-#ifdef __KERNEL__
         if (seq->lcs_srv) {
+#ifdef HAVE_SEQ_SERVER
                 LASSERT(env != NULL);
                 rc = seq_server_alloc_super(seq->lcs_srv, &seq->lcs_space,
                                             env);
-        } else {
+#else
+               rc = 0;
 #endif
+       } else {
                /* Check whether the connection to seq controller has been
                 * setup (lcs_exp != NULL) */
                if (seq->lcs_exp == NULL) {
@@ -172,9 +171,7 @@ int seq_client_alloc_super(struct lu_client_seq *seq,
 
                rc = seq_client_rpc(seq, &seq->lcs_space,
                                     SEQ_ALLOC_SUPER, "super");
-#ifdef __KERNEL__
         }
-#endif
        mutex_unlock(&seq->lcs_mutex);
         RETURN(rc);
 }
@@ -186,12 +183,14 @@ static int seq_client_alloc_meta(const struct lu_env *env,
         int rc;
         ENTRY;
 
-#ifdef __KERNEL__
         if (seq->lcs_srv) {
+#ifdef HAVE_SEQ_SERVER
                 LASSERT(env != NULL);
                 rc = seq_server_alloc_meta(seq->lcs_srv, &seq->lcs_space, env);
-        } else {
+#else
+               rc = 0;
 #endif
+       } else {
                do {
                        /* If meta server return -EINPROGRESS or EAGAIN,
                         * it means meta server might not be ready to
@@ -200,9 +199,8 @@ static int seq_client_alloc_meta(const struct lu_env *env,
                        rc = seq_client_rpc(seq, &seq->lcs_space,
                                            SEQ_ALLOC_META, "meta");
                } while (rc == -EINPROGRESS || rc == -EAGAIN);
-#ifdef __KERNEL__
         }
-#endif
+
         RETURN(rc);
 }
 
@@ -421,11 +419,22 @@ void seq_client_flush(struct lu_client_seq *seq)
 }
 EXPORT_SYMBOL(seq_client_flush);
 
-static void seq_client_proc_fini(struct lu_client_seq *seq);
-
+static void seq_client_proc_fini(struct lu_client_seq *seq)
+{
 #ifdef LPROCFS
+       ENTRY;
+       if (seq->lcs_proc_dir) {
+               if (!IS_ERR(seq->lcs_proc_dir))
+                       lprocfs_remove(&seq->lcs_proc_dir);
+               seq->lcs_proc_dir = NULL;
+       }
+       EXIT;
+#endif /* LPROCFS */
+}
+
 static int seq_client_proc_init(struct lu_client_seq *seq)
 {
+#ifdef LPROCFS
         int rc;
         ENTRY;
 
@@ -453,29 +462,11 @@ static int seq_client_proc_init(struct lu_client_seq *seq)
 out_cleanup:
         seq_client_proc_fini(seq);
         return rc;
-}
-
-static void seq_client_proc_fini(struct lu_client_seq *seq)
-{
-        ENTRY;
-        if (seq->lcs_proc_dir) {
-                if (!IS_ERR(seq->lcs_proc_dir))
-                        lprocfs_remove(&seq->lcs_proc_dir);
-                seq->lcs_proc_dir = NULL;
-        }
-        EXIT;
-}
-#else
-static int seq_client_proc_init(struct lu_client_seq *seq)
-{
-        return 0;
-}
 
-static void seq_client_proc_fini(struct lu_client_seq *seq)
-{
-        return;
-}
+#else /* LPROCFS */
+       return 0;
 #endif
+}
 
 int seq_client_init(struct lu_client_seq *seq,
                     struct obd_export *exp,
@@ -532,3 +523,87 @@ void seq_client_fini(struct lu_client_seq *seq)
         EXIT;
 }
 EXPORT_SYMBOL(seq_client_fini);
+
+int client_fid_init(struct obd_device *obd,
+                   struct obd_export *exp, enum lu_cli_type type)
+{
+       struct client_obd *cli = &obd->u.cli;
+       char *prefix;
+       int rc;
+       ENTRY;
+
+       OBD_ALLOC_PTR(cli->cl_seq);
+       if (cli->cl_seq == NULL)
+               RETURN(-ENOMEM);
+
+       OBD_ALLOC(prefix, MAX_OBD_NAME + 5);
+       if (prefix == NULL)
+               GOTO(out_free_seq, rc = -ENOMEM);
+
+       snprintf(prefix, MAX_OBD_NAME + 5, "cli-%s", obd->obd_name);
+
+       /* Init client side sequence-manager */
+       rc = seq_client_init(cli->cl_seq, exp, type, prefix, NULL);
+       OBD_FREE(prefix, MAX_OBD_NAME + 5);
+       if (rc)
+               GOTO(out_free_seq, rc);
+
+       RETURN(rc);
+out_free_seq:
+       OBD_FREE_PTR(cli->cl_seq);
+       cli->cl_seq = NULL;
+       return rc;
+}
+EXPORT_SYMBOL(client_fid_init);
+
+int client_fid_fini(struct obd_device *obd)
+{
+       struct client_obd *cli = &obd->u.cli;
+       ENTRY;
+
+       if (cli->cl_seq != NULL) {
+               seq_client_fini(cli->cl_seq);
+               OBD_FREE_PTR(cli->cl_seq);
+               cli->cl_seq = NULL;
+       }
+
+       RETURN(0);
+}
+EXPORT_SYMBOL(client_fid_fini);
+
+#ifdef __KERNEL__
+struct proc_dir_entry *seq_type_proc_dir;
+
+static int __init fid_mod_init(void)
+{
+       seq_type_proc_dir = lprocfs_register(LUSTRE_SEQ_NAME,
+                                            proc_lustre_root,
+                                            NULL, NULL);
+       if (IS_ERR(seq_type_proc_dir))
+               return PTR_ERR(seq_type_proc_dir);
+
+# ifdef HAVE_SERVER_SUPPORT
+       fid_server_mod_init();
+# endif
+
+       return 0;
+}
+
+static void __exit fid_mod_exit(void)
+{
+# ifdef HAVE_SERVER_SUPPORT
+       fid_server_mod_exit();
+# endif
+
+       if (seq_type_proc_dir != NULL && !IS_ERR(seq_type_proc_dir)) {
+               lprocfs_remove(&seq_type_proc_dir);
+               seq_type_proc_dir = NULL;
+       }
+}
+
+MODULE_AUTHOR("Sun Microsystems, Inc. <http://www.lustre.org/>");
+MODULE_DESCRIPTION("Lustre FID Module");
+MODULE_LICENSE("GPL");
+
+cfs_module(fid, "0.1.0", fid_mod_init, fid_mod_exit);
+#endif /* __KERNEL__ */