Motr  M0
md_service.c
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2012-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 
27 #define M0_TRACE_SUBSYSTEM M0_TRACE_SUBSYS_MDS
28 #include "lib/trace.h"
29 
30 #include "lib/errno.h"
31 #include "lib/memory.h"
32 #include "lib/locality.h"
33 #include "motr/magic.h"
34 #include "motr/setup.h"
35 #include "reqh/reqh_service.h"
36 #include "reqh/reqh.h"
37 #include "layout/layout.h"
38 #include "layout/linear_enum.h"
39 #include "layout/pdclust.h"
40 #include "conf/confc.h"
41 #include "conf/helpers.h"
42 #include "mdservice/md_fops.h"
43 #include "mdservice/md_service.h"
44 #include "mdservice/fsync_fops.h"
45 #include "module/instance.h" /* m0_get */
46 
47 
48 static int mds_allocate(struct m0_reqh_service **service,
49  const struct m0_reqh_service_type *stype);
50 static void mds_fini(struct m0_reqh_service *service);
51 
52 static int mds_start(struct m0_reqh_service *service);
53 static void mds_stop(struct m0_reqh_service *service);
54 
58 static const struct m0_reqh_service_type_ops mds_type_ops = {
60 };
61 
65 static const struct m0_reqh_service_ops mds_ops = {
67  .rso_start_async = m0_reqh_service_async_start_simple,
68  .rso_stop = mds_stop,
69  .rso_fini = mds_fini
70 };
71 
73  .rst_name = "M0_CST_MDS",
74  .rst_ops = &mds_type_ops,
75  .rst_level = M0_MD_SVC_LEVEL,
76  .rst_typecode = M0_CST_MDS,
77 };
78 
79 M0_INTERNAL int m0_mds_register(void)
80 {
81  int rc;
82 
83  m0_get()->i_mds_cdom_key = m0_reqh_lockers_allot();
84 
85  /* XXX: find better place */
86  m0_get()->i_actrec_dom_key = m0_reqh_lockers_allot();
87  m0_get()->i_dtm0_log_key = m0_reqh_lockers_allot();
88 
90 
92  if (rc != 0) {
93  return M0_ERR_INFO(rc,
94  "Unable to initialize mdservice fsync fop");
95  }
97  if (rc != 0) {
99  return M0_ERR_INFO(rc, "Unable to initialize mdservice fop");
100  }
101  return M0_RC(rc);
102 }
103 
104 M0_INTERNAL void m0_mds_unregister(void)
105 {
109 
110  m0_reqh_lockers_free(m0_get()->i_mds_cdom_key);
111 
112  /* XXX: find better place */
113  m0_reqh_lockers_free(m0_get()->i_actrec_dom_key);
114  m0_reqh_lockers_free(m0_get()->i_dtm0_log_key);
115 }
116 
123  const struct m0_reqh_service_type *stype)
124 {
125  struct m0_reqh_md_service *mds;
126 
127  M0_PRE(service != NULL && stype != NULL);
128 
129  M0_ALLOC_PTR(mds);
130  if (mds == NULL)
131  return M0_ERR(-ENOMEM);
132 
134 
135  *service = &mds->rmds_gen;
136  (*service)->rs_ops = &mds_ops;
137  return 0;
138 }
139 
148 static void mds_fini(struct m0_reqh_service *service)
149 {
150  struct m0_reqh_md_service *serv_obj;
151 
152  M0_PRE(service != NULL);
153 
154  serv_obj = container_of(service, struct m0_reqh_md_service, rmds_gen);
155  m0_free(serv_obj);
156 }
157 
164 static int mds_start(struct m0_reqh_service *service)
165 {
166  struct m0_motr *cctx;
167  /*struct m0_reqh *reqh;*/
168  struct m0_reqh_md_service *mds;
169  /*struct m0_sm_group *grp;*/
170 
171  M0_PRE(service != NULL);
172 
174 
175  /* in UT we don't init layouts */
176  if (mds->rmds_gen.rs_reqh_ctx == NULL)
177  return 0;
178 
180  if (cctx->cc_ha_addr == NULL)
181  return 0;
182  /*reqh = mds->rmds_gen.rs_reqh;*/
183  /* grp = &reqh->rh_sm_grp; - no, reqh is not started yet */
187  /*grp = m0_locality0_get()->lo_grp;*/
188  return 0;
189 }
190 
197 static void mds_stop(struct m0_reqh_service *service)
198 {
199  m0_reqh_lockers_clear(service->rs_reqh, m0_get()->i_mds_cdom_key);
200 
201  /* XXX: find better place */
202  m0_reqh_lockers_clear(service->rs_reqh, m0_get()->i_actrec_dom_key);
203  m0_reqh_lockers_clear(service->rs_reqh, m0_get()->i_dtm0_log_key);
204 }
205 
206 #undef M0_TRACE_SUBSYSTEM
207 
210 #undef M0_TRACE_SUBSYSTEM
211 /*
212  * Local variables:
213  * c-indentation-style: "K&R"
214  * c-basic-offset: 8
215  * tab-width: 8
216  * fill-column: 80
217  * scroll-step: 1
218  * End:
219  */
static const struct m0_reqh_service_ops mds_ops
Definition: md_service.c:65
#define M0_PRE(cond)
int(* rso_start)(struct m0_reqh_service *service)
Definition: reqh_service.h:360
#define NULL
Definition: misc.h:38
unsigned i_actrec_dom_key
Definition: instance.h:139
M0_INTERNAL int m0_mdservice_fop_init(void)
Definition: md_fops.c:341
static struct m0_rpc_client_ctx cctx
Definition: rconfc.c:69
struct m0_reqh_service_type m0_mds_type
Definition: md_service.c:72
M0_INTERNAL struct m0 * m0_get(void)
Definition: instance.c:41
#define container_of(ptr, type, member)
Definition: misc.h:33
unsigned i_dtm0_log_key
Definition: instance.h:141
struct m0_motr * rc_motr
Definition: setup.h:318
int m0_reqh_service_type_register(struct m0_reqh_service_type *rstype)
Definition: reqh_service.c:473
return M0_RC(rc)
M0_INTERNAL void m0_mds_unregister(void)
Definition: md_service.c:104
#define M0_ERR_INFO(rc, fmt,...)
Definition: trace.h:215
return M0_ERR(-EOPNOTSUPP)
M0_INTERNAL void m0_mdservice_fop_fini(void)
Definition: md_fops.c:348
static const struct socktype stype[]
Definition: sock.c:1156
M0_INTERNAL int m0_mdservice_fsync_fop_init(struct m0_reqh_service_type *svct)
Definition: fsync_fops.c:113
uint64_t rmds_magic
Definition: md_service.h:53
const char * rst_name
Definition: reqh_service.h:447
struct m0_reqh_context * rs_reqh_ctx
Definition: reqh_service.h:271
unsigned i_mds_cdom_key
Definition: instance.h:137
M0_INTERNAL int m0_mds_register(void)
Definition: md_service.c:79
static void mds_stop(struct m0_reqh_service *service)
Definition: md_service.c:197
int m0_reqh_service_async_start_simple(struct m0_reqh_service_start_async_ctx *asc)
Definition: reqh_service.c:601
Definition: setup.h:354
int(* rsto_service_allocate)(struct m0_reqh_service **service, const struct m0_reqh_service_type *stype)
Definition: reqh_service.h:435
static const struct m0_reqh_service_type_ops mds_type_ops
Definition: md_service.c:58
#define M0_ALLOC_PTR(ptr)
Definition: memory.h:86
static void mds_fini(struct m0_reqh_service *service)
Definition: md_service.c:148
struct m0_reqh_service rmds_gen
Definition: md_service.h:51
struct m0_reqh * rs_reqh
Definition: reqh_service.h:259
void m0_free(void *data)
Definition: memory.c:146
void m0_reqh_service_type_unregister(struct m0_reqh_service_type *rstype)
Definition: reqh_service.c:490
static struct m0_reqh_service * service[REQH_IN_UT_MAX]
Definition: long_lock_ut.c:46
int32_t rc
Definition: trigger_fop.h:47
static int mds_allocate(struct m0_reqh_service **service, const struct m0_reqh_service_type *stype)
Definition: md_service.c:122
M0_INTERNAL void m0_mdservice_fsync_fop_fini(void)
Definition: fsync_fops.c:44
const struct m0_reqh_service_ops * rs_ops
Definition: reqh_service.h:254
static int mds_start(struct m0_reqh_service *service)
Definition: md_service.c:164