Whamcloud - gitweb
b=16776
[fs/lustre-release.git] / lustre / ptlrpc / ptlrpc_module.c
index 57f3653..b6d9a6e 100644 (file)
 /* -*- mode: c; c-basic-offset: 8; indent-tabs-mode: nil; -*-
  * vim:expandtab:shiftwidth=8:tabstop=8:
  *
- *  Copyright (c) 2002, 2003 Cluster File Systems, Inc.
+ * GPL HEADER START
  *
- *   This file is part of Lustre, http://www.lustre.org.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
  *
- *   Lustre is free software; you can redistribute it and/or
- *   modify it under the terms of version 2 of the GNU General Public
- *   License as published by the Free Software Foundation.
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License version 2 only,
+ * as published by the Free Software Foundation.
  *
- *   Lustre is distributed in the hope that it will be useful,
- *   but WITHOUT ANY WARRANTY; without even the implied warranty of
- *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
- *   GNU General Public License for more details.
+ * This program is distributed in the hope that it will be useful, but
+ * WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * General Public License version 2 for more details (a copy is included
+ * in the LICENSE file that accompanied this code).
  *
- *   You should have received a copy of the GNU General Public License
- *   along with Lustre; if not, write to the Free Software
- *   Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
+ * You should have received a copy of the GNU General Public License
+ * version 2 along with this program; If not, see
+ * http://www.sun.com/software/products/lustre/docs/GPLv2.pdf
  *
+ * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
+ * CA 95054 USA or visit www.sun.com if you need additional information or
+ * have any questions.
+ *
+ * GPL HEADER END
+ */
+/*
+ * Copyright  2008 Sun Microsystems, Inc. All rights reserved
+ * Use is subject to license terms.
+ */
+/*
+ * This file is part of Lustre, http://www.lustre.org/
+ * Lustre is a trademark of Sun Microsystems, Inc.
  */
 
-#define EXPORT_SYMTAB
+#ifndef EXPORT_SYMTAB
+# define EXPORT_SYMTAB
+#endif
 #define DEBUG_SUBSYSTEM S_RPC
 
-#ifdef __KERNEL__
-# include <linux/module.h>
-# include <linux/init.h>
-#else
+#ifndef __KERNEL__
 # include <liblustre.h>
 #endif
 
-#include <linux/obd_support.h>
-#include <linux/obd_class.h>
-#include <linux/lustre_net.h>
+#include <obd_support.h>
+#include <obd_class.h>
+#include <lustre_net.h>
+#include <lustre_req_layout.h>
 
 #include "ptlrpc_internal.h"
 
+extern spinlock_t ptlrpc_last_xid_lock;
+extern spinlock_t ptlrpc_rs_debug_lock;
+extern spinlock_t ptlrpc_all_services_lock;
+extern struct semaphore pinger_sem;
+extern struct semaphore ptlrpcd_sem;
 extern int ptlrpc_init_portals(void);
 extern void ptlrpc_exit_portals(void);
-static int ldlm_hooks_referenced = 0;
 
-int (*ptlrpc_ldlm_namespace_cleanup)(struct ldlm_namespace *, int);
-int (*ptlrpc_ldlm_replay_locks)(struct obd_import *);
-
-#define GET_HOOK(name)                                                         \
-if (!ptlrpc_##name) {                                                          \
-        if (!(ptlrpc_##name = inter_module_get(#name))) {                      \
-                CERROR("can't i_m_g(\"" #name "\")\n");                        \
-                return 0;                                                      \
-        }                                                                      \
-}
-
-static int ldlm_hooks_referenced;
-
-/* This is called from ptlrpc_get_connection, which runs after all the modules
- * are loaded, but before anything else interesting happens.
- */
-int ptlrpc_get_ldlm_hooks(void)
+__init int ptlrpc_init(void)
 {
-        if (ldlm_hooks_referenced)
-                return 1;
-
-        GET_HOOK(ldlm_namespace_cleanup);
-        GET_HOOK(ldlm_replay_locks);
-
-        ldlm_hooks_referenced = 1;
-        RETURN(1);
-}
+        int rc, cleanup_phase = 0;
+        ENTRY;
 
-#undef GET_HOOK
+        lustre_assert_wire_constants();
+        spin_lock_init(&ptlrpc_last_xid_lock);
+        spin_lock_init(&ptlrpc_rs_debug_lock);
+        spin_lock_init(&ptlrpc_all_services_lock);
+        init_mutex(&pinger_sem);
+        init_mutex(&ptlrpcd_sem);
 
-#define PUT_HOOK(hook)                                                         \
-if (ptlrpc_##hook) {                                                           \
-        inter_module_put(#hook);                                               \
-        ptlrpc_##hook = NULL;                                                  \
-}
+        rc = req_layout_init();
+        if (rc)
+                RETURN(rc);
+        cleanup_phase = 1;
 
-void ptlrpc_put_ldlm_hooks(void)
-{
-        ENTRY;
-        if (!ldlm_hooks_referenced)
-                return;
+        rc = ptlrpc_init_portals();
+        if (rc)
+                RETURN(rc);
+        cleanup_phase = 2;
 
-        PUT_HOOK(ldlm_namespace_cleanup);
-        PUT_HOOK(ldlm_replay_locks);
-        ldlm_hooks_referenced = 0;
-        EXIT;
-}
+        rc = ptlrpc_connection_init();
+        if (rc)
+                GOTO(cleanup, rc);
+        cleanup_phase = 3;
 
-#undef PUT_HOOK
+        ptlrpc_put_connection_superhack = ptlrpc_connection_put;
 
-int ptlrpc_ldlm_hooks_referenced(void)
-{
-        return ldlm_hooks_referenced;
-}
+        rc = ptlrpc_start_pinger();
+        if (rc)
+                GOTO(cleanup, rc);
+        cleanup_phase = 4;
 
-__init int ptlrpc_init(void)
-{
-        int rc;
-        ENTRY;
+        rc = ldlm_init();
+        if (rc)
+                GOTO(cleanup, rc);
+        cleanup_phase = 5;
 
-        lustre_assert_wire_constants ();
-        
-        rc = ptlrpc_init_portals();
+        rc = sptlrpc_init();
         if (rc)
-                RETURN(rc);
+                GOTO(cleanup, rc);
 
-        ptlrpc_init_connection();
+        cleanup_phase = 6;
+        rc = llog_recov_init();
+        if (rc)
+                GOTO(cleanup, rc);
 
-        ptlrpc_put_connection_superhack = ptlrpc_put_connection;
-        ptlrpc_abort_inflight_superhack = ptlrpc_abort_inflight;
         RETURN(0);
+
+cleanup:
+        switch(cleanup_phase) {
+        case 6:
+                sptlrpc_fini();
+        case 5:
+                ldlm_exit();
+        case 4:
+                ptlrpc_stop_pinger();
+        case 3:
+                ptlrpc_connection_fini();
+        case 2:
+                ptlrpc_exit_portals();
+        case 1:
+                req_layout_fini();
+        default: ;
+        }
+
+        return rc;
 }
 
+#ifdef __KERNEL__
 static void __exit ptlrpc_exit(void)
 {
+        llog_recov_fini();
+        sptlrpc_fini();
+        ldlm_exit();
+        ptlrpc_stop_pinger();
         ptlrpc_exit_portals();
-        ptlrpc_cleanup_connection();
+        ptlrpc_connection_fini();
 }
 
 /* connection.c */
-EXPORT_SYMBOL(ptlrpc_dump_connections);
-EXPORT_SYMBOL(ptlrpc_readdress_connection);
-EXPORT_SYMBOL(ptlrpc_get_connection);
-EXPORT_SYMBOL(ptlrpc_put_connection);
+EXPORT_SYMBOL(ptlrpc_connection_get);
+EXPORT_SYMBOL(ptlrpc_connection_put);
 EXPORT_SYMBOL(ptlrpc_connection_addref);
-EXPORT_SYMBOL(ptlrpc_init_connection);
-EXPORT_SYMBOL(ptlrpc_cleanup_connection);
+EXPORT_SYMBOL(ptlrpc_connection_init);
+EXPORT_SYMBOL(ptlrpc_connection_fini);
 
 /* niobuf.c */
-EXPORT_SYMBOL(ptlrpc_bulk_put);
-EXPORT_SYMBOL(ptlrpc_bulk_get);
+EXPORT_SYMBOL(ptlrpc_start_bulk_transfer);
 EXPORT_SYMBOL(ptlrpc_abort_bulk);
 EXPORT_SYMBOL(ptlrpc_register_bulk);
 EXPORT_SYMBOL(ptlrpc_unregister_bulk);
+EXPORT_SYMBOL(ptlrpc_send_reply);
 EXPORT_SYMBOL(ptlrpc_reply);
+EXPORT_SYMBOL(ptlrpc_send_error);
 EXPORT_SYMBOL(ptlrpc_error);
 EXPORT_SYMBOL(ptlrpc_resend_req);
 EXPORT_SYMBOL(ptl_send_rpc);
-EXPORT_SYMBOL(ptlrpc_link_svc_me);
 
 /* client.c */
 EXPORT_SYMBOL(ptlrpc_init_client);
 EXPORT_SYMBOL(ptlrpc_cleanup_client);
-EXPORT_SYMBOL(ptlrpc_req_to_uuid);
 EXPORT_SYMBOL(ptlrpc_uuid_to_connection);
 EXPORT_SYMBOL(ptlrpc_queue_wait);
 EXPORT_SYMBOL(ptlrpc_replay_req);
 EXPORT_SYMBOL(ptlrpc_restart_req);
+EXPORT_SYMBOL(ptlrpc_add_rqs_to_pool);
+EXPORT_SYMBOL(ptlrpc_init_rq_pool);
+EXPORT_SYMBOL(ptlrpc_free_rq_pool);
+EXPORT_SYMBOL(ptlrpc_prep_req_pool);
+EXPORT_SYMBOL(ptlrpc_at_set_req_timeout);
+EXPORT_SYMBOL(ptlrpc_request_alloc);
+EXPORT_SYMBOL(ptlrpc_request_alloc_pool);
+EXPORT_SYMBOL(ptlrpc_request_free);
+EXPORT_SYMBOL(ptlrpc_request_pack);
+EXPORT_SYMBOL(ptlrpc_request_alloc_pack);
 EXPORT_SYMBOL(ptlrpc_prep_req);
 EXPORT_SYMBOL(ptlrpc_free_req);
 EXPORT_SYMBOL(ptlrpc_unregister_reply);
 EXPORT_SYMBOL(ptlrpc_req_finished);
+EXPORT_SYMBOL(ptlrpc_req_finished_with_imp_lock);
 EXPORT_SYMBOL(ptlrpc_request_addref);
 EXPORT_SYMBOL(ptlrpc_prep_bulk_imp);
 EXPORT_SYMBOL(ptlrpc_prep_bulk_exp);
 EXPORT_SYMBOL(ptlrpc_free_bulk);
 EXPORT_SYMBOL(ptlrpc_prep_bulk_page);
-EXPORT_SYMBOL(ptlrpc_free_bulk_page);
 EXPORT_SYMBOL(ptlrpc_abort_inflight);
 EXPORT_SYMBOL(ptlrpc_retain_replayable_request);
 EXPORT_SYMBOL(ptlrpc_next_xid);
+EXPORT_SYMBOL(ptlrpc_req_set_repsize);
+EXPORT_SYMBOL(ptlrpc_request_set_replen);
 
 EXPORT_SYMBOL(ptlrpc_prep_set);
+EXPORT_SYMBOL(ptlrpc_set_add_cb);
 EXPORT_SYMBOL(ptlrpc_set_add_req);
+EXPORT_SYMBOL(ptlrpc_set_add_new_req);
 EXPORT_SYMBOL(ptlrpc_set_destroy);
+EXPORT_SYMBOL(ptlrpc_set_next_timeout);
+EXPORT_SYMBOL(ptlrpc_check_set);
 EXPORT_SYMBOL(ptlrpc_set_wait);
+EXPORT_SYMBOL(ptlrpc_expired_set);
+EXPORT_SYMBOL(ptlrpc_interrupted_set);
+EXPORT_SYMBOL(ptlrpc_mark_interrupted);
 
 /* service.c */
+EXPORT_SYMBOL(ptlrpc_save_lock);
+EXPORT_SYMBOL(ptlrpc_schedule_difficult_reply);
+EXPORT_SYMBOL(ptlrpc_commit_replies);
 EXPORT_SYMBOL(ptlrpc_init_svc);
 EXPORT_SYMBOL(ptlrpc_stop_all_threads);
+EXPORT_SYMBOL(ptlrpc_start_threads);
 EXPORT_SYMBOL(ptlrpc_start_thread);
 EXPORT_SYMBOL(ptlrpc_unregister_service);
+EXPORT_SYMBOL(ptlrpc_daemonize);
+EXPORT_SYMBOL(ptlrpc_service_health_check);
 
 /* pack_generic.c */
-EXPORT_SYMBOL(lustre_pack_msg);
+EXPORT_SYMBOL(lustre_msg_swabbed);
+EXPORT_SYMBOL(lustre_msg_check_version);
+EXPORT_SYMBOL(lustre_pack_request);
+EXPORT_SYMBOL(lustre_pack_reply);
+EXPORT_SYMBOL(lustre_pack_reply_flags);
+EXPORT_SYMBOL(lustre_shrink_msg);
+EXPORT_SYMBOL(lustre_free_reply_state);
 EXPORT_SYMBOL(lustre_msg_size);
+EXPORT_SYMBOL(lustre_packed_msg_size);
 EXPORT_SYMBOL(lustre_unpack_msg);
 EXPORT_SYMBOL(lustre_msg_buf);
 EXPORT_SYMBOL(lustre_msg_string);
+EXPORT_SYMBOL(lustre_swab_ptlrpc_body);
+EXPORT_SYMBOL(lustre_swab_buf);
 EXPORT_SYMBOL(lustre_swab_reqbuf);
 EXPORT_SYMBOL(lustre_swab_repbuf);
 EXPORT_SYMBOL(lustre_swab_obdo);
@@ -186,57 +237,110 @@ EXPORT_SYMBOL(lustre_swab_obd_statfs);
 EXPORT_SYMBOL(lustre_swab_obd_ioobj);
 EXPORT_SYMBOL(lustre_swab_niobuf_remote);
 EXPORT_SYMBOL(lustre_swab_ost_body);
-EXPORT_SYMBOL(lustre_swab_ll_fid);
+EXPORT_SYMBOL(lustre_swab_ost_last_id);
+EXPORT_SYMBOL(lustre_swab_ost_lvb);
 EXPORT_SYMBOL(lustre_swab_mds_status_req);
-EXPORT_SYMBOL(lustre_swab_mds_fileh_body);
 EXPORT_SYMBOL(lustre_swab_mds_body);
+EXPORT_SYMBOL(lustre_swab_mdt_body);
+EXPORT_SYMBOL(lustre_swab_mdt_epoch);
+EXPORT_SYMBOL(lustre_swab_obd_quotactl);
+EXPORT_SYMBOL(lustre_swab_mds_remote_perm);
+EXPORT_SYMBOL(lustre_swab_mdt_remote_perm);
 EXPORT_SYMBOL(lustre_swab_mds_rec_setattr);
 EXPORT_SYMBOL(lustre_swab_mds_rec_create);
+EXPORT_SYMBOL(lustre_swab_mds_rec_join);
+EXPORT_SYMBOL(lustre_swab_mdt_rec_join);
 EXPORT_SYMBOL(lustre_swab_mds_rec_link);
 EXPORT_SYMBOL(lustre_swab_mds_rec_unlink);
 EXPORT_SYMBOL(lustre_swab_mds_rec_rename);
+EXPORT_SYMBOL(lustre_swab_mdt_rec_reint);
 EXPORT_SYMBOL(lustre_swab_lov_desc);
+EXPORT_SYMBOL(lustre_swab_lov_user_md);
+EXPORT_SYMBOL(lustre_swab_lov_mds_md);
+EXPORT_SYMBOL(lustre_swab_lov_user_md_objects);
+EXPORT_SYMBOL(lustre_swab_lov_user_md_join);
 EXPORT_SYMBOL(lustre_swab_ldlm_res_id);
-EXPORT_SYMBOL(lustre_swab_ldlm_extent);
+EXPORT_SYMBOL(lustre_swab_ldlm_policy_data);
 EXPORT_SYMBOL(lustre_swab_ldlm_intent);
 EXPORT_SYMBOL(lustre_swab_ldlm_resource_desc);
 EXPORT_SYMBOL(lustre_swab_ldlm_lock_desc);
 EXPORT_SYMBOL(lustre_swab_ldlm_request);
 EXPORT_SYMBOL(lustre_swab_ldlm_reply);
-EXPORT_SYMBOL(lustre_swab_ptlbd_op);
-EXPORT_SYMBOL(lustre_swab_ptlbd_niob);
-EXPORT_SYMBOL(lustre_swab_ptlbd_rsp);
-
-/* ptlrpc_module.c */
-EXPORT_SYMBOL(ptlrpc_put_ldlm_hooks);
-EXPORT_SYMBOL(ptlrpc_ldlm_hooks_referenced);
+EXPORT_SYMBOL(lustre_swab_qdata);
+EXPORT_SYMBOL(lustre_swab_qdata_old);
+EXPORT_SYMBOL(lustre_msg_get_flags);
+EXPORT_SYMBOL(lustre_msg_add_flags);
+EXPORT_SYMBOL(lustre_msg_set_flags);
+EXPORT_SYMBOL(lustre_msg_clear_flags);
+EXPORT_SYMBOL(lustre_msg_get_op_flags);
+EXPORT_SYMBOL(lustre_msg_add_op_flags);
+EXPORT_SYMBOL(lustre_msg_set_op_flags);
+EXPORT_SYMBOL(lustre_msg_get_handle );
+EXPORT_SYMBOL(lustre_msg_get_type);
+EXPORT_SYMBOL(lustre_msg_get_version);
+EXPORT_SYMBOL(lustre_msg_add_version);
+EXPORT_SYMBOL(lustre_msg_get_opc);
+EXPORT_SYMBOL(lustre_msg_get_last_xid);
+EXPORT_SYMBOL(lustre_msg_get_last_committed);
+EXPORT_SYMBOL(lustre_msg_get_transno);
+EXPORT_SYMBOL(lustre_msg_get_status);
+EXPORT_SYMBOL(lustre_msg_get_slv);
+EXPORT_SYMBOL(lustre_msg_get_limit);
+EXPORT_SYMBOL(lustre_msg_set_slv);
+EXPORT_SYMBOL(lustre_msg_set_limit);
+EXPORT_SYMBOL(lustre_msg_get_conn_cnt);
+EXPORT_SYMBOL(lustre_msg_is_v1);
+EXPORT_SYMBOL(lustre_msg_get_magic);
+EXPORT_SYMBOL(lustre_msg_set_handle);
+EXPORT_SYMBOL(lustre_msg_set_type);
+EXPORT_SYMBOL(lustre_msg_set_opc);
+EXPORT_SYMBOL(lustre_msg_set_last_xid);
+EXPORT_SYMBOL(lustre_msg_set_last_committed);
+EXPORT_SYMBOL(lustre_msg_set_transno);
+EXPORT_SYMBOL(lustre_msg_set_status);
+EXPORT_SYMBOL(lustre_msg_set_conn_cnt);
+EXPORT_SYMBOL(lustre_swab_mgs_target_info);
+EXPORT_SYMBOL(lustre_swab_md_fld);
+EXPORT_SYMBOL(lustre_swab_generic_32s);
+EXPORT_SYMBOL(lustre_swab_lustre_capa);
+EXPORT_SYMBOL(lustre_swab_lustre_capa_key);
+EXPORT_SYMBOL(lustre_swab_fiemap);
 
 /* recover.c */
-EXPORT_SYMBOL(ptlrpc_run_recovery_over_upcall);
-EXPORT_SYMBOL(ptlrpc_run_failed_import_upcall);
-EXPORT_SYMBOL(ptlrpc_reconnect_import);
-EXPORT_SYMBOL(ptlrpc_replay);
+EXPORT_SYMBOL(ptlrpc_disconnect_import);
 EXPORT_SYMBOL(ptlrpc_resend);
 EXPORT_SYMBOL(ptlrpc_wake_delayed);
 EXPORT_SYMBOL(ptlrpc_set_import_active);
+EXPORT_SYMBOL(ptlrpc_activate_import);
+EXPORT_SYMBOL(ptlrpc_deactivate_import);
+EXPORT_SYMBOL(ptlrpc_invalidate_import);
 EXPORT_SYMBOL(ptlrpc_fail_import);
-EXPORT_SYMBOL(ptlrpc_fail_export);
 EXPORT_SYMBOL(ptlrpc_recover_import);
 
-/*ptlrpc_lib.c*/
-EXPORT_SYMBOL(client_obd_setup);
-EXPORT_SYMBOL(client_obd_cleanup);
-
 /* pinger.c */
 EXPORT_SYMBOL(ptlrpc_pinger_add_import);
 EXPORT_SYMBOL(ptlrpc_pinger_del_import);
 EXPORT_SYMBOL(ptlrpc_pinger_sending_on_import);
 
-#ifdef __KERNEL__
-MODULE_AUTHOR("Cluster File Systems, Inc. <info@clusterfs.com>");
-MODULE_DESCRIPTION("Lustre Request Processor");
+/* ptlrpcd.c */
+EXPORT_SYMBOL(ptlrpcd_addref);
+EXPORT_SYMBOL(ptlrpcd_decref);
+EXPORT_SYMBOL(ptlrpcd_add_req);
+EXPORT_SYMBOL(ptlrpcd_wake);
+
+/* llogd.c */
+EXPORT_SYMBOL(llog_origin_handle_create);
+EXPORT_SYMBOL(llog_origin_handle_destroy);
+EXPORT_SYMBOL(llog_origin_handle_next_block);
+EXPORT_SYMBOL(llog_origin_handle_prev_block);
+EXPORT_SYMBOL(llog_origin_handle_read_header);
+EXPORT_SYMBOL(llog_origin_handle_close);
+EXPORT_SYMBOL(llog_client_ops);
+EXPORT_SYMBOL(llog_catinfo);
+
+MODULE_AUTHOR("Sun Microsystems, Inc. <http://www.lustre.org/>");
+MODULE_DESCRIPTION("Lustre Request Processor and Lock Management");
 MODULE_LICENSE("GPL");
 
-module_init(ptlrpc_init);
-module_exit(ptlrpc_exit);
+cfs_module(ptlrpc, "1.0.0", ptlrpc_init, ptlrpc_exit);
 #endif