Motr  M0
service.c
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2017-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 
26 #define M0_TRACE_SUBSYSTEM M0_TRACE_SUBSYS_FDMI
27 #include "lib/trace.h"
28 
29 #include "lib/errno.h"
30 #include "lib/memory.h"
31 #include "lib/locality.h"
32 #include "motr/magic.h"
33 #include "motr/setup.h"
34 #include "rpc/rpclib.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 "fdmi/fops.h"
42 #include "fdmi/service.h"
43 
44 static int fdms_allocate(struct m0_reqh_service **service,
45  const struct m0_reqh_service_type *stype);
46 static void fdms_fini(struct m0_reqh_service *service);
47 
48 static int fdms_start(struct m0_reqh_service *service);
49 static void fdms_prepare_to_stop(struct m0_reqh_service *service);
50 static void fdms_stop(struct m0_reqh_service *service);
51 
55 static const struct m0_reqh_service_type_ops fdms_type_ops = {
57 };
58 
62 static const struct m0_reqh_service_ops fdms_ops = {
64  .rso_start_async = m0_reqh_service_async_start_simple,
65  .rso_stop = fdms_stop,
66  .rso_prepare_to_stop = fdms_prepare_to_stop,
67  .rso_fini = fdms_fini
68 };
69 
70 #ifndef __KERNEL__
72  .rst_name = "M0_CST_FDMI",
73  .rst_ops = &fdms_type_ops,
74  .rst_level = M0_FDMI_SVC_LEVEL,
75  .rst_typecode = M0_CST_FDMI,
76  .rst_keep_alive = true
77 };
78 #endif
79 
80 M0_INTERNAL int m0_fdms_register(void)
81 {
82  M0_ENTRY();
84 #ifndef __KERNEL__
87 #endif
88 
89  return M0_RC(m0_fdms_fop_init());
90 }
91 
92 M0_INTERNAL void m0_fdms_unregister(void)
93 {
94  M0_ENTRY();
97  M0_LEAVE();
98 }
99 
101  const struct m0_reqh_service_type *stype)
102 {
103  struct m0_reqh_fdmi_service *fdms;
104 
105  M0_ENTRY();
106 
107  M0_PRE(service != NULL && stype != NULL);
108 
109  M0_ALLOC_PTR(fdms);
110  if (fdms == NULL)
111  return M0_RC(-ENOMEM);
112 
114 
115  *service = &fdms->rfdms_gen;
116  (*service)->rs_ops = &fdms_ops;
117  return M0_RC(0);
118 }
119 
128 static void fdms_fini(struct m0_reqh_service *service)
129 {
130  struct m0_reqh_fdmi_service *serv_obj;
131 
132  M0_ENTRY();
133 
134  M0_PRE(service != NULL);
135 
136  serv_obj = container_of(service,
138  m0_free(serv_obj);
139 
140  M0_LEAVE();
141 }
142 
149 static int fdms_start(struct m0_reqh_service *service)
150 {
151  const struct m0_filterc_ops *filterc_ops = &filterc_def_ops;
152  struct m0_reqh_fdmi_service *fdms;
153  struct m0_reqh_fdmi_svc_params *start_params;
154  int rc;
155 
156  M0_ENTRY();
157 
158  M0_PRE(service != NULL);
159 
160  fdms = container_of(service, struct m0_reqh_fdmi_service, rfdms_gen);
161 
162  /* UT can patch filterC operations */
164  start_params =
165  (struct m0_reqh_fdmi_svc_params *)
167  filterc_ops = start_params->filterc_ops;
168  }
169 
171 
172  if (rc == 0) {
175 
176  if (rc != 0) {
177  /* FIXME: Temporary workaround. Don't want the whole service
178  * startup failure (phase 2) */
179 
180  M0_LOG(M0_WARN,
181  "can't start FDMI source dock fom %d", rc);
182  /*m0_fdmi__plugin_dock_stop();*/
183  rc = 0;
184  } else {
185  fdms->rfdms_src_dock_inited = true;
186  }
187  }
188 
189  return M0_RC(rc);
190 }
191 
199 {
200  struct m0_reqh_fdmi_service *fdms;
201 
202  M0_PRE(service != NULL);
203 
205 
207 
208  if (fdms->rfdms_src_dock_inited)
210 }
211 
218 static void fdms_stop(struct m0_reqh_service *service)
219 {;}
220 
221 #undef M0_TRACE_SUBSYSTEM
222 
225 /*
226  * Local variables:
227  * c-indentation-style: "K&R"
228  * c-basic-offset: 8
229  * tab-width: 8
230  * fill-column: 80
231  * scroll-step: 1
232  * End:
233  */
234 /*
235  * vim: tabstop=8 shiftwidth=8 noexpandtab textwidth=80 nowrap
236  */
M0_INTERNAL void m0_fdmi__src_dock_fom_stop(struct m0_fdmi_src_dock *src_dock)
#define M0_PRE(cond)
M0_INTERNAL bool m0_buf_is_set(const struct m0_buf *buf)
Definition: buf.c:127
const struct m0_filterc_ops * filterc_ops
Definition: service.h:49
int(* rso_start)(struct m0_reqh_service *service)
Definition: reqh_service.h:360
const struct m0_filterc_ops filterc_def_ops
Definition: filterc.c:41
#define NULL
Definition: misc.h:38
static int fdms_start(struct m0_reqh_service *service)
Definition: service.c:149
M0_INTERNAL void m0_fdmi__plugin_dock_stop()
Definition: plugin_dock.c:611
void * b_addr
Definition: buf.h:39
#define M0_LOG(level,...)
Definition: trace.h:167
M0_LEAVE()
static int fdms_allocate(struct m0_reqh_service **service, const struct m0_reqh_service_type *stype)
Definition: service.c:100
#define container_of(ptr, type, member)
Definition: misc.h:33
int m0_reqh_service_type_register(struct m0_reqh_service_type *rstype)
Definition: reqh_service.c:473
M0_INTERNAL void m0_fdmi__src_dock_fom_init(void)
return M0_RC(rc)
struct m0_buf rs_ss_param
Definition: reqh_service.h:281
#define M0_ENTRY(...)
Definition: trace.h:170
static const struct socktype stype[]
Definition: sock.c:1156
M0_INTERNAL int m0_fdms_fop_init(void)
Definition: fops.c:108
const char * rst_name
Definition: reqh_service.h:447
M0_INTERNAL struct m0_fdmi_src_dock * m0_fdmi_src_dock_get(void)
Definition: fdmi.c:890
M0_INTERNAL void m0_fdms_fop_fini(void)
Definition: fops.c:120
uint64_t rfdms_magic
Definition: service.h:67
bool rfdms_src_dock_inited
Definition: service.h:64
static const struct m0_reqh_service_type_ops fdms_type_ops
Definition: service.c:55
M0_INTERNAL int m0_fdmi__plugin_dock_fom_init(void)
static void fdms_prepare_to_stop(struct m0_reqh_service *service)
Definition: service.c:198
int m0_reqh_service_async_start_simple(struct m0_reqh_service_start_async_ctx *asc)
Definition: reqh_service.c:601
M0_INTERNAL struct m0_reqh_service_type m0_fdmi_service_type
Definition: service.c:71
int(* rsto_service_allocate)(struct m0_reqh_service **service, const struct m0_reqh_service_type *stype)
Definition: reqh_service.h:435
#define M0_ALLOC_PTR(ptr)
Definition: memory.h:86
struct m0_reqh_service rfdms_gen
Definition: service.h:58
static void fdms_stop(struct m0_reqh_service *service)
Definition: service.c:218
static void fdms_fini(struct m0_reqh_service *service)
Definition: service.c:128
M0_INTERNAL int m0_fdms_register(void)
Definition: service.c:80
M0_INTERNAL int m0_fdmi__plugin_dock_start(struct m0_reqh *reqh)
Definition: plugin_dock.c:592
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
M0_INTERNAL void m0_fdms_unregister(void)
Definition: service.c:92
Definition: trace.h:478
static const struct m0_reqh_service_ops fdms_ops
Definition: service.c:62
M0_INTERNAL int m0_fdmi__src_dock_fom_start(struct m0_fdmi_src_dock *src_dock, const struct m0_filterc_ops *filterc_ops, struct m0_reqh *reqh)
const struct m0_reqh_service_ops * rs_ops
Definition: reqh_service.h:254