Motr  M0
service.c
Go to the documentation of this file.
1 /* -*- C -*- */
2 /*
3  * Copyright (c) 2012-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 #define M0_TRACE_SUBSYSTEM M0_TRACE_SUBSYS_SNSCM
24 #include "lib/memory.h"
25 #include "lib/assert.h"
26 #include "lib/errno.h"
27 #include "lib/trace.h"
28 #include "lib/misc.h"
29 #include "lib/finject.h"
30 
31 #include "reqh/reqh_service.h"
32 #include "sns/cm/cm.h"
33 #include "motr/setup.h"
34 #include "sns/cm/sns_cp_onwire.h"
35 
42 M0_INTERNAL int
44  const struct m0_reqh_service_type *stype,
45  const struct m0_reqh_service_ops *svc_ops,
46  const struct m0_cm_ops *cm_ops)
47 {
48  struct m0_sns_cm *sns_cm;
49  struct m0_cm *cm;
50  int rc;
51 
52  M0_ENTRY("stype: %p", stype);
53  M0_PRE(service != NULL && stype != NULL);
54 
55  M0_ALLOC_PTR(sns_cm);
56  if (sns_cm == NULL)
57  return M0_RC(-ENOMEM);
58 
59  cm = &sns_cm->sc_base;
60  *service = &cm->cm_service;
61  (*service)->rs_ops = svc_ops;
62  sns_cm->sc_magic = M0_SNS_CM_MAGIC;
63 
64  rc = m0_cm_init(cm, container_of(stype, struct m0_cm_type, ct_stype),
65  cm_ops);
66  if (rc != 0)
67  m0_free(sns_cm);
68 
69  M0_LOG(M0_DEBUG, "sns_cm: %p service: %p", sns_cm, *service);
70  return M0_RC(rc);
71 }
72 
74 {
75  struct m0_cm *cm;
76  int rc;
77  struct cs_endpoint_and_xprt *ep;
78  struct m0_reqh_context *rctx;
79  struct m0_motr *motr;
80 
81  M0_ENTRY("service: %p", service);
82  M0_PRE(service != NULL);
83 
84  cm = container_of(service, struct m0_cm, cm_service);
85  rc = m0_cm_setup(cm);
86  if (rc != 0)
87  return M0_RC(rc);
88 
89  /* The following shows how to retrieve ioservice endpoints list.
90  * Copy machine can establish connections to all ioservices,
91  * and build a map for "cob_id" -> "sesssion of ioservice" with
92  * the same algorithm on m0t1fs client.
93  */
95  motr = rctx->rc_motr;
96  m0_tl_for(cs_eps, &motr->cc_ios_eps, ep) {
97  M0_ASSERT(cs_endpoint_and_xprt_bob_check(ep));
98  M0_LOG(M0_DEBUG, "pool_width=%d, "
99  "ioservice xprt:endpoints: %s:%s",
101  ep->ex_xprt, ep->ex_endpoint);
102  } m0_tl_endfor;
103 
104  M0_LEAVE();
105  return M0_RC(rc);
106 }
107 
108 M0_INTERNAL void m0_sns_cm_svc_stop(struct m0_reqh_service *service)
109 {
110  struct m0_cm *cm;
111 
112  M0_ENTRY("service: %p", service);
113  M0_PRE(service != NULL);
114 
115  cm = container_of(service, struct m0_cm, cm_service);
116  /*
117  * Finalise the copy machine as the copy machine as the service is
118  * stopped.
119  */
120  m0_cm_fini(cm);
121 
122  M0_LEAVE();
123 }
124 
125 M0_INTERNAL void m0_sns_cm_svc_fini(struct m0_reqh_service *service)
126 {
127  struct m0_cm *cm;
128  struct m0_sns_cm *sns_cm;
129 
130  M0_ENTRY("service: %p", service);
131  M0_PRE(service != NULL);
132 
133  cm = container_of(service, struct m0_cm, cm_service);
134  sns_cm = cm2sns(cm);
135  m0_free(sns_cm);
136 
137  M0_LEAVE();
138 }
139 
140 #undef M0_TRACE_SUBSYSTEM
141 
143 /*
144  * Local variables:
145  * c-indentation-style: "K&R"
146  * c-basic-offset: 8
147  * tab-width: 8
148  * fill-column: 80
149  * scroll-step: 1
150  * End:
151  */
Definition: cm.h:205
#define M0_PRE(cond)
M0_INTERNAL void m0_sns_cm_svc_stop(struct m0_reqh_service *service)
Definition: service.c:108
#define NULL
Definition: misc.h:38
M0_INTERNAL struct m0_sns_cm * cm2sns(struct m0_cm *cm)
Definition: cm.c:389
uint64_t sc_magic
Definition: cm.h:277
const struct m0_cm_ops * cm_ops
Definition: cm.h:188
#define M0_LOG(level,...)
Definition: trace.h:167
M0_LEAVE()
M0_INTERNAL int m0_sns_cm_svc_start(struct m0_reqh_service *service)
Definition: service.c:73
uint32_t cc_pool_width
Definition: setup.h:409
#define container_of(ptr, type, member)
Definition: misc.h:33
M0_INTERNAL void m0_cm_fini(struct m0_cm *cm)
Definition: cm.c:964
struct m0_motr * rc_motr
Definition: setup.h:318
M0_INTERNAL int m0_sns_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)
Definition: service.c:43
#define m0_tl_endfor
Definition: tlist.h:700
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
Definition: sock.c:754
#define M0_ENTRY(...)
Definition: trace.h:170
struct m0_reqh_context rctx
M0_INTERNAL void m0_sns_cm_svc_fini(struct m0_reqh_service *service)
Definition: service.c:125
static const struct socktype stype[]
Definition: sock.c:1156
#define M0_ASSERT(cond)
struct m0_reqh_context * rs_reqh_ctx
Definition: reqh_service.h:271
Definition: cm.h:286
M0_INTERNAL int m0_cm_setup(struct m0_cm *cm)
Definition: cm.c:595
Definition: cm.h:143
Definition: setup.h:354
char * ep
Definition: sw.h:132
#define M0_ALLOC_PTR(ptr)
Definition: memory.h:86
struct m0_motr motr
struct m0_reqh_service cm_service
Definition: cm.h:191
Definition: cm.h:166
struct m0_cm sc_base
Definition: cm.h:206
#define m0_tl_for(name, head, obj)
Definition: tlist.h:695
void m0_free(void *data)
Definition: memory.c:146
struct m0_tl cc_ios_eps
Definition: setup.h:404
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