Motr  M0
service.c
Go to the documentation of this file.
1 /* -*- C -*- */
2 /*
3  * Copyright (c) 2016-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 
23 
30 #define M0_TRACE_SUBSYSTEM M0_TRACE_SUBSYS_DIXCM
31 #include "dix/cm/cm.h"
32 #include "lib/trace.h"
33 #include "lib/memory.h"
34 #include "motr/setup.h"
35 #include "dix/req.h"
36 
37 M0_INTERNAL int m0_dix_cm_module_init(void)
38 {
39  return m0_dix_cm_type_register() ?:
41 }
42 
43 M0_INTERNAL void m0_dix_cm_module_fini(void)
44 {
47 }
48 
49 M0_INTERNAL int
51  const struct m0_reqh_service_type *stype,
52  const struct m0_reqh_service_ops *svc_ops,
53  const struct m0_cm_ops *cm_ops,
54  struct m0_dix_cm_type *dcmt)
55 {
56  struct m0_dix_cm *dix_cm;
57  struct m0_cm *cm;
58  int rc;
59 
60  M0_ENTRY("stype: %p", stype);
61  M0_PRE(service != NULL && stype != NULL);
62 
63  M0_ALLOC_PTR(dix_cm);
64  if (dix_cm == NULL)
65  return M0_ERR(-ENOMEM);
66 
67  dix_cm->dcm_type = dcmt;
68  cm = &dix_cm->dcm_base;
69  *service = &cm->cm_service;
70  (*service)->rs_ops = svc_ops;
71  dix_cm->dcm_magic = M0_DIX_CM_MAGIC;
72 
73  rc = m0_cm_init(cm, container_of(stype, struct m0_cm_type, ct_stype),
74  cm_ops);
75  if (rc != 0)
76  m0_free(dix_cm);
77  M0_LOG(M0_DEBUG, "dix_cm: %p service: %p", dix_cm, *service);
78  return M0_RC(rc);
79 }
80 
82 {
83  struct m0_cm *cm;
84  int rc;
85 
86  M0_ENTRY("service: %p", service);
87  M0_PRE(service != NULL);
88 
90  rc = m0_cm_setup(cm);
91  if (rc != 0)
92  return M0_ERR(rc);
93  return M0_RC(rc);
94 }
95 
96 M0_INTERNAL void m0_dix_cm_svc_stop(struct m0_reqh_service *service)
97 {
98  struct m0_cm *cm;
99 
100  M0_ENTRY("service: %p", service);
101  M0_PRE(service != NULL);
102 
103  cm = container_of(service, struct m0_cm, cm_service);
104  /*
105  * Finalise the copy machine as the copy machine as the service is
106  * stopped.
107  */
108  m0_cm_fini(cm);
109 
110  M0_LEAVE();
111 }
112 
113 M0_INTERNAL void m0_dix_cm_svc_fini(struct m0_reqh_service *service)
114 {
115  struct m0_cm *cm;
116  struct m0_dix_cm *dix_cm;
117 
118  M0_ENTRY("service: %p", service);
119  M0_PRE(service != NULL);
120 
121  cm = container_of(service, struct m0_cm, cm_service);
122  dix_cm = cm2dix(cm);
123  m0_free(dix_cm);
124 
125  M0_LEAVE();
126 }
127 
128 #undef M0_TRACE_SUBSYSTEM
129 
132 /*
133  * Local variables:
134  * c-indentation-style: "K&R"
135  * c-basic-offset: 8
136  * tab-width: 8
137  * fill-column: 80
138  * scroll-step: 1
139  * End:
140  */
141 /*
142  * vim: tabstop=8 shiftwidth=8 noexpandtab textwidth=80 nowrap
143  */
M0_INTERNAL struct m0_dix_cm * cm2dix(struct m0_cm *cm)
Definition: cm.c:308
#define M0_PRE(cond)
#define NULL
Definition: misc.h:38
const struct m0_cm_ops * cm_ops
Definition: cm.h:188
#define M0_LOG(level,...)
Definition: trace.h:167
M0_LEAVE()
M0_INTERNAL void m0_dix_cm_svc_stop(struct m0_reqh_service *service)
Definition: service.c:96
#define container_of(ptr, type, member)
Definition: misc.h:33
M0_INTERNAL void m0_cm_fini(struct m0_cm *cm)
Definition: cm.c:964
M0_INTERNAL void m0_dix_cm_module_fini(void)
Definition: service.c:43
M0_INTERNAL int m0_dix_cm_svc_allocate(struct m0_reqh_service **service, const struct m0_reqh_service_type *stype, const struct m0_reqh_service_ops *svc_ops, const struct m0_cm_ops *cm_ops, struct m0_dix_cm_type *dcmt)
Definition: service.c:50
M0_INTERNAL int m0_cm_init(struct m0_cm *cm, struct m0_cm_type *cm_type, const struct m0_cm_ops *cm_ops)
Definition: cm.c:925
return M0_RC(rc)
static struct m0_cm * cm
Definition: cm.c:63
#define M0_ENTRY(...)
Definition: trace.h:170
uint64_t dcm_magic
Definition: cm.h:168
return M0_ERR(-EOPNOTSUPP)
#define M0_AMB(obj, ptr, field)
Definition: misc.h:320
static const struct socktype stype[]
Definition: sock.c:1156
M0_INTERNAL int m0_dix_cm_svc_start(struct m0_reqh_service *service)
Definition: service.c:81
M0_INTERNAL void m0_dix_cm_type_deregister(void)
Definition: cm.c:326
M0_INTERNAL int m0_dix_sm_conf_init(void)
Definition: req.c:2609
struct m0_cm dcm_base
Definition: cm.h:119
Definition: cm.h:286
M0_INTERNAL int m0_dix_cm_module_init(void)
Definition: service.c:37
Definition: cm.h:117
M0_INTERNAL int m0_cm_setup(struct m0_cm *cm)
Definition: cm.c:595
Definition: cm.h:143
M0_INTERNAL void m0_dix_cm_svc_fini(struct m0_reqh_service *service)
Definition: service.c:113
M0_INTERNAL void m0_dix_sm_conf_fini(void)
Definition: req.c:2617
#define M0_ALLOC_PTR(ptr)
Definition: memory.h:86
struct m0_dix_cm_type * dcm_type
Definition: cm.h:122
struct m0_reqh_service cm_service
Definition: cm.h:191
M0_INTERNAL int m0_dix_cm_type_register(void)
Definition: cm.c:313
Definition: cm.h:166
void m0_free(void *data)
Definition: memory.c:146
static struct m0_reqh_service * service[REQH_IN_UT_MAX]
Definition: long_lock_ut.c:46
int32_t rc
Definition: trigger_fop.h:47
const struct m0_reqh_service_ops * rs_ops
Definition: reqh_service.h:254