Motr  M0
lnet_main.c
Go to the documentation of this file.
1 /* -*- C -*- */
2 /*
3  * Copyright (c) 2012-2020 Seagate Technology LLC and/or its Affiliates
4  *
5  * Licensed under the Apache License, Version 2.0 (the "License");
6  * you may not use this file except in compliance with the License.
7  * You may obtain a copy of the License at
8  *
9  * http://www.apache.org/licenses/LICENSE-2.0
10  *
11  * Unless required by applicable law or agreed to in writing, software
12  * distributed under the License is distributed on an "AS IS" BASIS,
13  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14  * See the License for the specific language governing permissions and
15  * limitations under the License.
16  *
17  * For any questions about this software or licensing,
18  * please email opensource@seagate.com or cortx-questions@seagate.com.
19  *
20  */
21 
22 
765 /*
766  ******************************************************************************
767  End of DLD
768  ******************************************************************************
769  */
770 
771 #ifdef __KERNEL__
772 /* lustre config defines package macros also defined by m0 config */
773 #undef PACKAGE /* to avoid conflicts */
774 #undef PACKAGE_BUGREPORT
775 #undef PACKAGE_NAME
776 #undef PACKAGE_STRING
777 #undef PACKAGE_TARNAME
778 #undef PACKAGE_VERSION
779 #undef VERSION
780 #include "lustre_config.h" /* required by lnet/types.h */
781 #include "libcfs/libcfs.h" /* lnet/types.h fails if this is not included */
782 
783 /* LUSTRE_VERSION_CODE, OBD_OCD_VERSION */
784 #if M0_LUSTRE_VERSION < 2110
785 #include <lustre_ver.h>
786 #else
787 #include <lustre/lustre_ver.h>
788 #include <lustre/lustre_idl.h>
789 #endif
790 
791 #include <lustre/lustre_idl.h> /* OBD_OCD_VERSION */
792 #if LUSTRE_VERSION_CODE > OBD_OCD_VERSION(2, 10, 51, 0)
793 #include "lnet/lib-types.h"
794 #else
795 #include "lnet/types.h"
796 #endif
797 
798 #undef PACKAGE /* suppress lustre specific values */
799 #undef PACKAGE_BUGREPORT
800 #undef PACKAGE_NAME
801 #undef PACKAGE_STRING
802 #undef PACKAGE_TARNAME
803 #undef PACKAGE_VERSION
804 #undef VERSION
805 /*
806  * Above values were lustre specific, change them again to motr specific.
807  * since there are no guard macros around, this will not be a problem.
808  */
809 #endif
810 
811 #define M0_TRACE_SUBSYSTEM M0_TRACE_SUBSYS_LNET
812 #include "lib/trace.h"
813 
814 #include "lib/errno.h"
815 #include "lib/misc.h"
816 #include "lib/memory.h"
817 #include "lib/string.h" /* m0_streq */
818 #include "net/net_internal.h"
819 #include "net/lnet/lnet_core.h"
820 #include "net/lnet/lnet_xo.h"
821 #include "net/lnet/lnet_pvt.h"
822 #include "motr/magic.h"
823 
824 #include <asm/byteorder.h> /* byte swapping macros */
825 
826 /* debug print support */
827 #ifdef __KERNEL__
828 #define NLX_DEBUG
829 #else
830 #undef NLX_DEBUG
831 #endif
832 
833 #ifdef NLX_DEBUG
834 
835 struct nlx_debug {
836  int _debug_;
837 };
838 static struct nlx_debug nlx_debug = {
839  ._debug_ = 0,
840 }; /* global debug control */
841 
842 /* note Linux uses the LP64 standard */
843 #define NLXP(fmt, ...) M0_LOG(M0_DEBUG, fmt, ## __VA_ARGS__)
844 
845 #define NLXDBG(ptr, dbg, stmt) \
846 do { \
847  if ((ptr)->_debug_ >= (dbg)) { \
848  M0_LOG(M0_DEBUG, "%s: %d:\n", (char*) __FILE__, __LINE__);\
849  stmt; \
850  } \
851 } while (0)
852 
853 #define NLXDBGnl(ptr, dbg, stmt) \
854 do { \
855  if ((ptr)->_debug_ >= (dbg)) { \
856  stmt; \
857  } \
858 } while (0)
859 
860 #define NLXDBGP(ptr, dbg, fmt, ...) \
861 do { \
862  if ((ptr)->_debug_ >= (dbg)) { \
863  M0_LOG(M0_DEBUG, fmt, ## __VA_ARGS__); \
864  } \
865 } while (0)
866 
867 #define NLXDBGPnl(ptr, dbg, fmt, ...) \
868 do { \
869  if ((ptr)->_debug_ >= (dbg)) { \
870  M0_LOG(M0_DEBUG, fmt, ## __VA_ARGS__); \
871  } \
872 } while (0)
873 
874 #else /* !NLX_DEBUG */
875 
876 #define NLXP(fmt, ...)
877 #define NLXDBG(ptr, dbg, stmt) do { ; } while (0)
878 #define NLXDBGnl(ptr, dbg, stmt) do { ; } while (0)
879 #define NLXDBGP(ptr, dbg, fmt, ...) do { ; } while (0)
880 #define NLXDBGPnl(ptr, dbg, fmt, ...) do { ; } while (0)
881 
882 #endif /* !NLX_DEBUG */
883 
884 /*
885  To reduce global symbols, yet make the code readable, we
886  include other .c files with static symbols into this file.
887 
888  Static functions should be declared in the private header file
889  so that the order of their definition does not matter.
890  */
891 #include "net/lnet/bev_cqueue.c"
892 #include "net/lnet/lnet_core.c"
893 #include "net/lnet/lnet_ioctl.h"
894 #ifdef __KERNEL__
900 /*
901  * LUSTRE_SRV_LNET_PID is not available in user space, so assert that the
902  * M0 equivalent is valid. Depending on the lustre version, the name may be
903  * LUSTRE_SRV_LNET_PID or LNET_PID_LUSTRE.
904  */
905 #ifdef LNET_PID_LUSTRE
906 M0_BASSERT(M0_NET_LNET_PID == LNET_PID_LUSTRE);
907 #else
908 M0_BASSERT(M0_NET_LNET_PID == LUSTRE_SRV_LNET_PID);
909 #endif
910 #else
911 #include "net/lnet/ulnet_core.h"
912 #include "net/lnet/ulnet_core.c"
913 #endif
914 #include "net/lnet/lnet_xo.c"
915 #include "net/lnet/lnet_ep.c"
916 #include "net/lnet/lnet_tm.c"
917 
923 M0_INTERNAL int m0_net_lnet_init(void)
924 {
925 #if !defined(ENABLE_SOCK_MOCK_LNET) || defined(__KERNEL__)
927  if (m0_streq(M0_DEFAULT_NETWORK, "LNET"))
929 #endif
930  return M0_RC(nlx_core_init());
931 }
932 
933 M0_INTERNAL void m0_net_lnet_fini(void)
934 {
935  nlx_core_fini();
936 #if !defined(ENABLE_SOCK_MOCK_LNET) || defined(__KERNEL__)
938 #endif
939 }
940 
941 M0_INTERNAL int m0_net_lnet_ep_addr_net_cmp(const char *addr1,
942  const char *addr2)
943 {
944  const char *cp1;
945  const char *cp2;
946 
947  cp1 = strchr(addr1, ':');
948  cp2 = strchr(addr2, ':');
949  if (cp1 == NULL || cp2 == NULL)
950  return -1;
951  return strncmp(addr1, addr2, min32(cp1 - addr1, cp2 - addr2));
952 }
953 M0_EXPORTED(m0_net_lnet_ep_addr_net_cmp);
954 
955 M0_INTERNAL int m0_net_lnet_ifaces_get(struct m0_net_domain *dom,
956  char ***addrs)
957 {
958  struct nlx_xo_domain *dp;
959 
961  dp = dom->nd_xprt_private;
962  return nlx_core_nidstrs_get(&dp->xd_core, addrs);
963 }
964 M0_EXPORTED(m0_net_lnet_ifaces_get);
965 
966 M0_INTERNAL void m0_net_lnet_ifaces_put(struct m0_net_domain *dom,
967  char ***addrs)
968 {
969  struct nlx_xo_domain *dp;
970 
972  dp = dom->nd_xprt_private;
973  nlx_core_nidstrs_put(&dp->xd_core, addrs);
974 }
975 M0_EXPORTED(m0_net_lnet_ifaces_put);
976 
977 M0_INTERNAL void m0_net_lnet_dom_set_debug(struct m0_net_domain *dom,
978  unsigned dbg)
979 {
980  struct nlx_xo_domain *dp;
981 
982  M0_PRE(dom != NULL);
985  dp = dom->nd_xprt_private;
986  dp->_debug_ = dbg;
987  nlx_core_dom_set_debug(&dp->xd_core, dbg);
989 }
990 M0_EXPORTED(m0_net_lnet_dom_set_debug);
991 
992 M0_INTERNAL void m0_net_lnet_tm_set_debug(struct m0_net_transfer_mc *tm,
993  unsigned dbg)
994 {
995  struct nlx_xo_transfer_mc *tp;
996 
997  M0_PRE(tm != NULL);
998  m0_mutex_lock(&tm->ntm_mutex);
1000  tp = tm->ntm_xprt_private;
1001  tp->_debug_ = dbg;
1002  nlx_core_tm_set_debug(&tp->xtm_core, dbg);
1003  m0_mutex_unlock(&tm->ntm_mutex);
1004 }
1005 M0_EXPORTED(m0_net_lnet_tm_set_debug);
1006  /* LNetDFS */
1008 #undef M0_TRACE_SUBSYSTEM
1009 
1010 /*
1011  * Local variables:
1012  * c-indentation-style: "K&R"
1013  * c-basic-offset: 8
1014  * tab-width: 8
1015  * fill-column: 79
1016  * scroll-step: 1
1017  * End:
1018  */
M0_INTERNAL void m0_net_lnet_dom_set_debug(struct m0_net_domain *dom, unsigned dbg)
Definition: lnet_main.c:977
#define M0_PRE(cond)
static bool nlx_dom_invariant(const struct m0_net_domain *dom)
Definition: lnet_xo.c:28
M0_INTERNAL void m0_mutex_unlock(struct m0_mutex *mutex)
Definition: mutex.c:66
#define NULL
Definition: misc.h:38
const struct m0_net_xprt m0_net_lnet_xprt
Definition: lnet_xo.c:679
static void nlx_core_fini(void)
Definition: klnet_core.c:1991
M0_INTERNAL void m0_net_xprt_default_set(const struct m0_net_xprt *xprt)
Definition: net.c:143
unsigned _debug_
Definition: lnet_xo.h:79
struct m0_mutex m0_net_mutex
Definition: net.c:59
M0_INTERNAL void m0_mutex_lock(struct m0_mutex *mutex)
Definition: mutex.c:49
M0_INTERNAL int m0_net_lnet_ep_addr_net_cmp(const char *addr1, const char *addr2)
Definition: lnet_main.c:941
M0_INTERNAL void nlx_core_dom_set_debug(struct nlx_core_domain *lcdom, unsigned dbg)
Definition: lnet_core.c:447
return M0_RC(rc)
M0_INTERNAL void m0_net_xprt_register(const struct m0_net_xprt *xprt)
Definition: net.c:182
void * ntm_xprt_private
Definition: net.h:886
M0_INTERNAL void m0_net_lnet_tm_set_debug(struct m0_net_transfer_mc *tm, unsigned dbg)
Definition: lnet_main.c:992
M0_INTERNAL void nlx_core_tm_set_debug(struct nlx_core_transfer_mc *lctm, unsigned dbg)
Definition: lnet_core.c:453
M0_INTERNAL int m0_net_lnet_ifaces_get(struct m0_net_domain *dom, char ***addrs)
Definition: lnet_main.c:955
#define M0_DEFAULT_NETWORK
Definition: config.h:281
#define m0_streq(a, b)
Definition: string.h:34
struct nlx_core_domain xd_core
Definition: lnet_xo.h:77
unsigned _debug_
Definition: lnet_xo.h:106
static struct m0_stob_domain * dom
Definition: storage.c:38
static bool nlx_tm_invariant(const struct m0_net_transfer_mc *tm)
M0_INTERNAL void m0_net_lnet_ifaces_put(struct m0_net_domain *dom, char ***addrs)
Definition: lnet_main.c:966
M0_INTERNAL void nlx_core_nidstrs_put(struct nlx_core_domain *lcdom, char ***nidary)
Definition: klnet_core.c:1774
M0_INTERNAL int m0_net_lnet_init(void)
Definition: lnet_main.c:923
M0_INTERNAL void m0_net_xprt_deregister(const struct m0_net_xprt *xprt)
Definition: net.c:197
static int32_t min32(int32_t a, int32_t b)
Definition: arith.h:36
static int nlx_core_init(void)
Definition: klnet_core.c:2002
M0_INTERNAL void m0_net_lnet_fini(void)
Definition: lnet_main.c:933
#define M0_BASSERT(cond)
M0_INTERNAL int nlx_core_nidstrs_get(struct nlx_core_domain *lcdom, char ***nidary)
Definition: klnet_core.c:1744
struct nlx_core_transfer_mc xtm_core
Definition: lnet_xo.h:104