Motr  M0
module.c
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2014-2020 Seagate Technology LLC and/or its Affiliates
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  *
16  * For any questions about this software or licensing,
17  * please email opensource@seagate.com or cortx-questions@seagate.com.
18  *
19  */
20 
21 
22 #include "net/module.h"
23 #include "module/instance.h"
24 #include "net/lnet/lnet.h" /* m0_net_lnet_xprt */
25 #ifndef __KERNEL__
26 #include "net/libfab/libfab.h" /* m0_net_libfab_xprt */
27 #include "net/sock/sock.h"
28 #endif /* __KERNEL__ */
29 #include "net/net.h"
30 #include "net/bulk_mem.h" /* m0_net_bulk_mem_xprt */
31 #include "lib/memory.h" /* M0_ALLOC_PTR */
32 static struct m0_module *net_module_create(struct m0 *instance);
33 static int level_net_enter(struct m0_module *module);
34 static void level_net_leave(struct m0_module *module);
35 static int level_net_xprt_enter(struct m0_module *module);
36 static void level_net_xprt_leave(struct m0_module *module);
37 
39  .mt_name = "m0_net_module",
40  .mt_create = net_module_create
41 };
42 
43 static const struct m0_modlev levels_net[] = {
44  [M0_LEVEL_NET] = {
45  .ml_name = "M0_LEVEL_NET",
46  .ml_enter = level_net_enter,
47  .ml_leave = level_net_leave
48  }
49 };
50 
51 static const struct m0_modlev levels_net_xprt[] = {
53  .ml_name = "M0_LEVEL_NET_DOMAIN",
54  .ml_enter = level_net_xprt_enter,
55  .ml_leave = level_net_xprt_leave
56  }
57 };
58 
59 static struct {
60  const char *name;
61  struct m0_net_xprt *xprt;
62 } net_xprt_mods[] = {
63  [M0_NET_XPRT_LNET] = {
64  .name = "\"lnet\" m0_net_xprt_module",
65  .xprt = (struct m0_net_xprt *)&m0_net_lnet_xprt
66  },
68  .name = "\"bulk-mem\" m0_net_xprt_module",
69  .xprt = (struct m0_net_xprt *)&m0_net_bulk_mem_xprt
70  },
71 #ifndef __KERNEL__
72  [M0_NET_XPRT_SOCK] = {
73  .name = "\"sock\" m0_net_xprt_module",
74  .xprt = (struct m0_net_xprt *)&m0_net_sock_xprt
75  },
76 
77 #ifdef ENABLE_LIBFAB
78  [M0_NET_XPRT_LIBFABRIC] = {
79  .name = "\"libfab\" m0_net_xprt_module",
80  .xprt = (struct m0_net_xprt *)&m0_net_libfab_xprt
81  }
82 #endif /* ENABLE_LIBFAB */
83 #endif /* __KERNEL__ */
84 };
86  ARRAY_SIZE(M0_FIELD_VALUE(struct m0_net_module, n_xprts)));
87 
88 static struct m0_module *net_module_create(struct m0 *instance)
89 {
90  struct m0_net_module *net;
91  struct m0_module *m;
92  unsigned i;
93 
95  if (net == NULL)
96  return NULL;
99  for (i = 0; i < ARRAY_SIZE(net->n_xprts); ++i) {
100  m = &net->n_xprts[i].nx_module;
104  &net->n_module, M0_LEVEL_NET);
105  }
107  return &net->n_module;
108 }
109 
110 static int level_net_enter(struct m0_module *module)
111 {
112  struct m0_net_module *m = M0_AMB(m, module, n_module);
113  int i;
114 
115  M0_PRE(module->m_cur + 1 == M0_LEVEL_NET);
116  /*
117  * We could have introduced a dedicated level for assigning
118  * m0_net_xprt_module::nx_xprt pointers, but assigning them
119  * this way is good enough.
120  */
121  for (i = 0; i < ARRAY_SIZE(net_xprt_mods); ++i)
122  m->n_xprts[i].nx_xprt = net_xprt_mods[i].xprt;
123 #if 0 /* XXX TODO
124  * Rename current m0_net_init() to m0_net__init(), exclude it
125  * from subsystem[] of motr/init.c, and ENABLEME.
126  */
127  return m0_net__init();
128 #else
129  return 0;
130 #endif
131 }
132 
133 static void level_net_leave(struct m0_module *module)
134 {
135  M0_PRE(module->m_cur == M0_LEVEL_NET);
136 #if 0 /* XXX TODO
137  * Rename current m0_net_fini() to m0_net__fini(), exclude it
138  * from subsystem[] of motr/init.c, and ENABLEME.
139  */
140  m0_net__fini();
141 #endif
142 }
143 
144 static int level_net_xprt_enter(struct m0_module *module)
145 {
146  struct m0_net_xprt_module *m = M0_AMB(m, module, nx_module);
147  M0_PRE(module->m_cur + 1 == M0_LEVEL_NET_DOMAIN);
148  return m0_net_domain_init(&m->nx_domain, m->nx_xprt);
149 }
150 
151 static void level_net_xprt_leave(struct m0_module *module)
152 {
153  M0_PRE(module->m_cur == M0_LEVEL_NET_DOMAIN);
155  nx_module)->nx_domain);
156 }
struct m0_module n_module
Definition: module.h:56
static int level_net_enter(struct m0_module *module)
Definition: module.c:110
#define M0_PRE(cond)
void m0_net_domain_fini(struct m0_net_domain *dom)
Definition: domain.c:71
#define NULL
Definition: misc.h:38
static struct m0_addb2_mach * m
Definition: consumer.c:38
static const struct m0_modlev levels_net[]
Definition: module.c:43
#define M0_FIELD_VALUE(type, field)
Definition: misc.h:339
const struct m0_net_xprt m0_net_lnet_xprt
Definition: lnet_xo.c:679
struct m0_net_domain nx_domain
Definition: module.h:51
const char * ml_name
Definition: module.h:114
const char * name
Definition: module.c:60
#define container_of(ptr, type, member)
Definition: misc.h:33
const struct m0_module_type m0_net_module_type
Definition: module.c:38
int i
Definition: dir.c:1033
#define M0_AMB(obj, ptr, field)
Definition: misc.h:320
static struct @401 net_xprt_mods[]
struct m0_module nx_module
Definition: module.h:49
static const struct m0_modlev levels_net_xprt[]
Definition: module.c:51
const struct m0_net_xprt m0_net_sock_xprt
Definition: sock.c:3927
M0_INTERNAL void m0_module_setup(struct m0_module *module, const char *name, const struct m0_modlev *level, int level_nr, struct m0 *instance)
Definition: module.c:193
Definition: instance.h:80
static int level_net_xprt_enter(struct m0_module *module)
Definition: module.c:144
M0_INTERNAL void m0_module_dep_add(struct m0_module *m0, int l0, struct m0_module *m1, int l1)
Definition: module.c:168
int m0_net_domain_init(struct m0_net_domain *dom, const struct m0_net_xprt *xprt)
Definition: domain.c:36
#define M0_ALLOC_PTR(ptr)
Definition: memory.h:86
void * i_moddata[M0_MODULE_NR]
Definition: instance.h:94
static void level_net_xprt_leave(struct m0_module *module)
Definition: module.c:151
int m_cur
Definition: module.h:160
M0_BASSERT(ARRAY_SIZE(net_xprt_mods)==ARRAY_SIZE(M0_FIELD_VALUE(struct m0_net_module, n_xprts)))
const char * mt_name
Definition: module.h:186
static struct m0 instance
Definition: main.c:78
static struct m0_addb2_net * net
Definition: net.c:27
struct m0_net_xprt * xprt
Definition: module.c:61
static struct m0_module * net_module_create(struct m0 *instance)
Definition: module.c:88
static void level_net_leave(struct m0_module *module)
Definition: module.c:133
#define ARRAY_SIZE(a)
Definition: misc.h:45
const struct m0_net_xprt m0_net_bulk_mem_xprt
Definition: mem_xprt_xo.c:761