Motr  M0
domain.c
Go to the documentation of this file.
1 /* -*- C -*- */
2 /*
3  * Copyright (c) 2013-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 
28 #define M0_TRACE_SUBSYSTEM M0_TRACE_SUBSYS_DTM0
29 #include "lib/trace.h"
30 
31 #include "dtm0/domain.h"
32 
33 #include "lib/bob.h" /* M0_BOB_DEFINE */
34 #include "module/instance.h" /* m0_get */
35 
36 
37 static const struct m0_bob_type dtm0_domain_bob_type = {
38  .bt_name = "m0_dtm0_domain",
39  .bt_magix_offset = M0_MAGIX_OFFSET(struct m0_dtm0_domain, dod_magix),
40  .bt_magix = M0_DTM0_DOMAIN_MAGIC,
41 };
43 
44 static struct m0_dtm0_domain *dtm0_module2domain(struct m0_module *module)
45 {
46  return bob_of(module, struct m0_dtm0_domain, dod_module,
48 }
49 
50 static int dtm0_domain_level_enter(struct m0_module *module);
51 static void dtm0_domain_level_leave(struct m0_module *module);
52 
53 #define DTM0_DOMAIN_LEVEL(level) [level] = { \
54  .ml_name = #level, \
55  .ml_enter = &dtm0_domain_level_enter, \
56  .ml_leave = &dtm0_domain_level_leave, \
57  }
58 
61 
64 
69 
73 
75 };
76 
77 static const struct m0_modlev levels_dtm0_domain[] = {
79 
82 
87 
91 
93 };
94 #undef DTM0_DOMAIN_LEVEL
95 
96 static int dtm0_domain_level_enter(struct m0_module *module)
97 {
98  enum dtm0_domain_level level = module->m_cur + 1;
99  struct m0_dtm0_domain *dod = dtm0_module2domain(module);
100  struct m0_dtm0_domain_cfg *cfg = &dod->dod_cfg;
101 
102  M0_ENTRY("dod=%p level=%d level_name=%s",
103  dod, level, levels_dtm0_domain[level].ml_name);
104  switch (level) {
106  return M0_RC(0);
108  return M0_RC(0);
110  return M0_RC(m0_dtm0_log_init(&dod->dod_log,
111  &cfg->dodc_log));
112 
114  return M0_RC(m0_dtm0_remach_init(&dod->dod_remach,
115  &cfg->dodc_remach));
117  return M0_RC(m0_dtm0_pmach_init(&dod->dod_pmach,
118  &cfg->dodc_pmach));
120  return M0_RC(0);
122  return M0_RC(m0_dtm0_net_init(&dod->dod_net, &cfg->dodc_net));
125  return M0_RC(0);
128  return M0_RC(0);
130  return M0_RC(m0_dtm0_pruner_init(&dod->dod_pruner,
131  &cfg->dodc_pruner));
133  return M0_RC(0);
134  default:
135  M0_IMPOSSIBLE("Unexpected level: %d", level);
136  }
137 }
138 
139 static void dtm0_domain_level_leave(struct m0_module *module)
140 {
141  enum dtm0_domain_level level = module->m_cur;
142  struct m0_dtm0_domain *dod = dtm0_module2domain(module);
143 
144  M0_ENTRY("dod=%p level=%d level_name=%s",
145  dod, level, levels_dtm0_domain[level].ml_name);
146  switch (level) {
148  break;
150  break;
152  m0_dtm0_log_fini(&dod->dod_log);
153  break;
156  break;
159  break;
161  break;
163  m0_dtm0_net_fini(&dod->dod_net);
164  break;
165 
168  break;
171  break;
174  break;
175 
177  break;
178  default:
179  M0_IMPOSSIBLE("Unexpected level: %d", level);
180  }
181 }
182 
183 M0_INTERNAL int m0_dtm0_domain_init(struct m0_dtm0_domain *dod,
184  struct m0_dtm0_domain_cfg *dod_cfg)
185 {
186  int rc;
187 
188  M0_ENTRY("dod=%p dod_cfg=%p", dod, dod_cfg);
189  m0_module_setup(&dod->dod_module, "m0_dtm0_domain module",
191  m0_get());
192  /*
193  * TODO use m0_dtm0_domain_cfg_dup to copy the configuration
194  * into dod::dod_cfg.
195  */
196  m0_dtm0_domain_bob_init(dod);
198  if (rc != 0)
200  return M0_RC(rc);
201 }
202 
203 M0_INTERNAL void m0_dtm0_domain_fini(struct m0_dtm0_domain *dod)
204 {
206  m0_dtm0_domain_bob_fini(dod);
207 }
208 
209 M0_INTERNAL int m0_dtm0_domain_create(struct m0_dtm0_domain *dod,
210  struct m0_dtm0_domain_create_cfg *dc_cfg)
211 {
212  return 0;
213 }
214 
215 M0_INTERNAL void m0_dtm0_domain_destroy(struct m0_dtm0_domain *dod)
216 {
217 }
218 
219 #undef M0_TRACE_SUBSYSTEM
220 
223 /*
224  * Local variables:
225  * c-indentation-style: "K&R"
226  * c-basic-offset: 8
227  * tab-width: 8
228  * fill-column: 80
229  * scroll-step: 1
230  * End:
231  */
232 /*
233  * vim: tabstop=8 shiftwidth=8 noexpandtab textwidth=80 nowrap
234  */
M0_INTERNAL int m0_dtm0_pmach_init(struct m0_dtm0_pmach *drm, struct m0_dtm0_pmach_cfg *drm_cfg)
Definition: pmach.c:34
struct m0_dtm0_log dod_log
Definition: domain.h:63
static const struct m0_modlev levels_dtm0_domain[]
Definition: domain.c:77
M0_INTERNAL int m0_dtm0_remach_init(struct m0_dtm0_remach *drm, struct m0_dtm0_remach_cfg *drm_cfg)
Definition: remach.c:33
struct m0_module dod_module
Definition: domain.h:69
M0_INTERNAL void m0_dtm0_remach_fini(struct m0_dtm0_remach *drm)
Definition: remach.c:39
struct m0_dtm0_domain_cfg dod_cfg
Definition: domain.h:68
M0_INTERNAL void m0_dtm0_log_fini(struct m0_dtm0_log *dol)
Definition: log.c:39
enum m0_trace_level level
Definition: trace.c:111
static void dtm0_domain_level_leave(struct m0_module *module)
Definition: domain.c:139
static int dtm0_domain_level_enter(struct m0_module *module)
Definition: domain.c:96
M0_INTERNAL int m0_dtm0_domain_create(struct m0_dtm0_domain *dod, struct m0_dtm0_domain_create_cfg *dc_cfg)
Definition: domain.c:209
M0_INTERNAL int m0_dtm0_domain_init(struct m0_dtm0_domain *dod, struct m0_dtm0_domain_cfg *dod_cfg)
Definition: domain.c:183
M0_INTERNAL void m0_dtm0_pruner_fini(struct m0_dtm0_pruner *dpn)
Definition: pruner.c:39
struct m0_dtm0_net dod_net
Definition: domain.h:67
M0_INTERNAL struct m0 * m0_get(void)
Definition: instance.c:41
const char * bt_name
Definition: bob.h:73
return M0_RC(rc)
#define M0_ENTRY(...)
Definition: trace.h:170
M0_INTERNAL int m0_dtm0_net_init(struct m0_dtm0_net *dnet, struct m0_dtm0_net_cfg *dnet_cfg)
Definition: net.c:33
M0_INTERNAL void m0_dtm0_pmach_start(struct m0_dtm0_pmach *drm)
Definition: pmach.c:44
struct m0_dtm0_pruner dod_pruner
Definition: domain.h:64
M0_INTERNAL void m0_dtm0_domain_destroy(struct m0_dtm0_domain *dod)
Definition: domain.c:215
#define bob_of(ptr, type, field, bt)
Definition: bob.h:140
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
#define DTM0_DOMAIN_LEVEL(level)
Definition: domain.c:53
M0_INTERNAL int m0_dtm0_pruner_init(struct m0_dtm0_pruner *dpn, struct m0_dtm0_pruner_cfg *dpn_cfg)
Definition: pruner.c:33
M0_BOB_DEFINE(static, &dtm0_domain_bob_type, m0_dtm0_domain)
M0_INTERNAL int m0_dtm0_log_init(struct m0_dtm0_log *dol, struct m0_dtm0_log_cfg *dol_cfg)
Definition: log.c:33
struct m0_dtm0_net_cfg dodc_net
Definition: domain.h:55
M0_INTERNAL void m0_dtm0_net_fini(struct m0_dtm0_net *dnet)
Definition: net.c:39
static struct m0_dtm0_domain * dtm0_module2domain(struct m0_module *module)
Definition: domain.c:44
struct m0_dtm0_log_cfg dodc_log
Definition: domain.h:51
M0_INTERNAL void m0_dtm0_remach_start(struct m0_dtm0_remach *drm)
Definition: remach.c:43
#define M0_MAGIX_OFFSET(type, field)
Definition: misc.h:356
M0_INTERNAL void m0_dtm0_pmach_stop(struct m0_dtm0_pmach *drm)
Definition: pmach.c:48
struct m0_dtm0_remach_cfg dodc_remach
Definition: domain.h:53
static const struct m0_bob_type dtm0_domain_bob_type
Definition: domain.c:37
int m_cur
Definition: module.h:160
struct m0_dtm0_pmach dod_pmach
Definition: domain.h:66
dtm0_domain_level
Definition: domain.c:59
struct m0_dtm0_pruner_cfg dodc_pruner
Definition: domain.h:52
struct m0_dtm0_remach dod_remach
Definition: domain.h:65
M0_INTERNAL void m0_dtm0_remach_stop(struct m0_dtm0_remach *drm)
Definition: remach.c:47
M0_INTERNAL void m0_dtm0_domain_fini(struct m0_dtm0_domain *dod)
Definition: domain.c:203
int32_t rc
Definition: trigger_fop.h:47
#define ARRAY_SIZE(a)
Definition: misc.h:45
M0_INTERNAL void m0_dtm0_pmach_fini(struct m0_dtm0_pmach *drm)
Definition: pmach.c:40
struct m0_dtm0_pmach_cfg dodc_pmach
Definition: domain.h:54
M0_INTERNAL void m0_module_fini(struct m0_module *module, int level)
Definition: module.c:142
M0_INTERNAL int m0_module_init(struct m0_module *module, int level)
Definition: module.c:131
#define M0_IMPOSSIBLE(fmt,...)