Motr  M0
entrypoint.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_UT
31 #include "lib/trace.h"
32 
33 #include "ha/entrypoint.h"
34 #include "ut/ut.h"
35 
36 #include "lib/memory.h" /* M0_ALLOC_PTR */
37 #include "lib/types.h" /* uint32_t */
38 #include "lib/string.h" /* m0_strdup */
39 #include "lib/arith.h" /* m0_rnd64 */
40 #include "lib/misc.h" /* container_of */
41 #include "fid/fid.h" /* m0_fid */
42 #include "ha/ut/helper.h" /* m0_ha_ut_rpc_ctx */
43 
44 enum {
46 };
47 
52  uint32_t ueus_quorum;
53  uint32_t ueus_confd_nr;
56  char *ueus_rm_ep;
58  uint32_t ueus_req_count;
60 };
61 
63  struct m0_ha_entrypoint_server *hes,
64  const struct m0_ha_entrypoint_req *req,
65  const struct m0_uint128 *req_id)
66 {
67  struct ha_ut_entrypoint_usecase_ctx *uctx;
68  struct m0_ha_entrypoint_rep *rep;
69 
70  uctx = container_of(hes, struct ha_ut_entrypoint_usecase_ctx,
71  ueus_server);
73  *rep = (struct m0_ha_entrypoint_rep){
74  .hae_quorum = uctx->ueus_quorum,
75  .hae_confd_fids = {
76  .af_count = uctx->ueus_confd_nr,
77  .af_elems = uctx->ueus_confd_fids,
78  },
79  .hae_confd_eps = (const char **)uctx->ueus_confd_endpoints,
80  .hae_active_rm_fid = uctx->ueus_rm_fid,
81  .hae_active_rm_ep = uctx->ueus_rm_ep,
82  .hae_control = uctx->ueus_control,
83  };
84  ++uctx->ueus_req_count;
85  m0_ha_entrypoint_server_reply(hes, req_id, rep);
86  m0_free(rep);
87 }
88 
89 static void
91 {
92  uint64_t seed = 42;
93  char buf[0x100];
94  int rc;
95  int i;
96 
102  for (i = 0; i < uctx->ueus_confd_nr; ++i) {
104  m0_rnd64(&seed));
105  rc = snprintf(buf, ARRAY_SIZE(buf), "confd endpoint %d %"PRIu64,
106  i, m0_rnd64(&seed));
109  }
110  uctx->ueus_rm_ep = "rm endpoint";
112  uctx->ueus_req_count = 0;
113 }
114 
115 static void
117 {
118  int i;
119 
120  for (i = 0; i < uctx->ueus_confd_nr; ++i) {
122  }
124  m0_free(uctx->ueus_confd_fids);
125 }
126 
127 static void
129  struct m0_ha_entrypoint_rep *rep)
130 {
131  int i;
132 
133  M0_UT_ASSERT(rep->hae_control == uctx->ueus_control);
134  M0_UT_ASSERT(rep->hae_quorum == uctx->ueus_quorum);
135  M0_UT_ASSERT(rep->hae_confd_fids.af_count == uctx->ueus_confd_nr);
136  for (i = 0; i < uctx->ueus_confd_nr; ++i) {
137  M0_UT_ASSERT(m0_fid_eq(&rep->hae_confd_fids.af_elems[i],
138  &uctx->ueus_confd_fids[i]));
139  M0_UT_ASSERT(m0_streq(rep->hae_confd_eps[i],
140  uctx->ueus_confd_endpoints[i]));
141  }
142  M0_UT_ASSERT(m0_streq(rep->hae_active_rm_ep, uctx->ueus_rm_ep));
143  M0_UT_ASSERT(m0_fid_eq(&rep->hae_active_rm_fid, &uctx->ueus_rm_fid));
144 }
145 
146 static void
148  struct m0_ha_ut_rpc_ctx *ctx,
149  struct m0_ha_entrypoint_server *esr)
150 {
151  struct m0_ha_entrypoint_server_cfg esr_cfg;
152  int rc;
153 
154  esr_cfg = (struct m0_ha_entrypoint_server_cfg){
155  .hesc_reqh = &ctx->hurc_reqh,
156  .hesc_rpc_machine = &ctx->hurc_rpc_machine,
157  .hesc_request_received = &ha_ut_entrypoint_request_arrived,
158  };
159  rc = m0_ha_entrypoint_server_init(esr, &esr_cfg);
160  M0_UT_ASSERT(rc == 0);
162 }
163 
164 static void
166  struct m0_ha_entrypoint_server *esr)
167 {
170 }
171 
172 static void
174  struct m0_ha_ut_rpc_ctx *ctx,
175  struct m0_ha_entrypoint_client *ecl)
176 {
177  struct m0_ha_entrypoint_client_cfg ecl_cfg;
178  int rc;
179 
180  ecl_cfg = (struct m0_ha_entrypoint_client_cfg){
181  .hecc_reqh = &ctx->hurc_reqh,
182  .hecc_rpc_machine = &ctx->hurc_rpc_machine,
183  .hecc_process_fid = M0_FID_INIT(0, 0),
184  };
186  ctx->hurc_rpc_machine.rm_tm.ntm_ep->nep_addr, &ecl_cfg);
187  M0_UT_ASSERT(rc == 0);
189 }
190 
191 static void
193  struct m0_ha_entrypoint_client *ecl)
194 {
197 }
198 
200 {
201  struct ha_ut_entrypoint_usecase_ctx *uctx;
202  struct m0_ha_entrypoint_server *esr;
203  struct m0_ha_entrypoint_client *ecl;
204  struct m0_ha_ut_rpc_ctx *ctx;
205  struct m0_ha_entrypoint_rep *rep;
206 
207  M0_ALLOC_PTR(uctx);
208  M0_ALLOC_PTR(ctx);
209  M0_ALLOC_PTR(ecl);
211 
213 
214  esr = &uctx->ueus_server;
216 
218  rep = &ecl->ecl_rep;
219 
221  M0_UT_ASSERT(uctx->ueus_req_count == 1);
222 
223  ha_ut_entrypoint_client_stop(uctx, ecl);
224  ha_ut_entrypoint_server_stop(uctx, esr);
225  M0_UT_ASSERT(uctx->ueus_req_count == 1);
226 
228 
230  m0_free(ecl);
231  m0_free(ctx);
232  m0_free(uctx);
233 }
234 
236 {
237  struct ha_ut_entrypoint_usecase_ctx *uctx =
239  ueus_clink);
240  struct m0_ha_entrypoint_client *ecl = &uctx->ueus_client;
241  struct m0_ha_entrypoint_rep *rep = &ecl->ecl_rep;
243 
245  if (state == M0_HEC_UNAVAILABLE)
246  M0_SET0(rep);
247  if (state == M0_HEC_AVAILABLE)
249 
250  return state != M0_HEC_AVAILABLE;
251 }
252 
254 {
255  struct ha_ut_entrypoint_usecase_ctx *uctx;
256  struct m0_ha_entrypoint_server *esr;
257  struct m0_ha_entrypoint_client *ecl;
258  struct m0_ha_ut_rpc_ctx *ctx;
259  struct m0_ha_entrypoint_rep *rep;
260 
261  M0_ALLOC_PTR(uctx);
262  M0_ALLOC_PTR(ctx);
264 
266 
267  esr = &uctx->ueus_server;
269 
270  ecl = &uctx->ueus_client;
272  rep = &ecl->ecl_rep;
274  M0_UT_ASSERT(uctx->ueus_req_count == 1);
275 
279  m0_chan_wait(&uctx->ueus_clink);
281  m0_clink_fini(&uctx->ueus_clink);
282  M0_UT_ASSERT(uctx->ueus_req_count == 2);
283 
284  /* starts successfully after stop */
286  M0_SET0(rep);
289  M0_UT_ASSERT(uctx->ueus_req_count == 3);
290 
291  ha_ut_entrypoint_client_stop(uctx, ecl);
292  ha_ut_entrypoint_server_stop(uctx, esr);
293  M0_UT_ASSERT(uctx->ueus_req_count == 3);
294 
296 
298  m0_free(ctx);
299  m0_free(uctx);
300 }
301 
302 #undef M0_TRACE_SUBSYSTEM
303 
306 /*
307  * Local variables:
308  * c-indentation-style: "K&R"
309  * c-basic-offset: 8
310  * tab-width: 8
311  * fill-column: 80
312  * scroll-step: 1
313  * End:
314  */
315 /*
316  * vim: tabstop=8 shiftwidth=8 noexpandtab textwidth=80 nowrap
317  */
M0_INTERNAL void m0_chan_wait(struct m0_clink *link)
Definition: chan.c:336
#define M0_ALLOC_ARR(arr, nr)
Definition: memory.h:84
#define m0_strdup(s)
Definition: string.h:43
M0_INTERNAL void m0_clink_init(struct m0_clink *link, m0_chan_cb_t cb)
Definition: chan.c:201
void m0_ha_ut_entrypoint_client(void)
Definition: entrypoint.c:253
M0_INTERNAL void m0_clink_del_lock(struct m0_clink *link)
Definition: chan.c:293
static struct io_request req
Definition: file.c:100
static bool ha_ut_entrypoint_client_cb(struct m0_clink *clink)
Definition: entrypoint.c:235
M0_INTERNAL void m0_ha_entrypoint_server_start(struct m0_ha_entrypoint_server *hes)
Definition: entrypoint.c:241
#define M0_FID_INIT(container, key)
Definition: fid.h:84
M0_INTERNAL void m0_ha_entrypoint_client_stop(struct m0_ha_entrypoint_client *ecl)
Definition: entrypoint.c:785
M0_INTERNAL enum m0_ha_entrypoint_client_state m0_ha_entrypoint_client_state_get(struct m0_ha_entrypoint_client *ecl)
Definition: entrypoint.c:829
M0_INTERNAL void m0_ha_ut_rpc_ctx_init(struct m0_ha_ut_rpc_ctx *ctx)
Definition: helper.c:41
#define container_of(ptr, type, member)
Definition: misc.h:33
#define M0_SET0(obj)
Definition: misc.h:64
M0_INTERNAL void m0_ha_entrypoint_client_request(struct m0_ha_entrypoint_client *ecl)
Definition: entrypoint.c:708
M0_INTERNAL void m0_ha_entrypoint_server_reply(struct m0_ha_entrypoint_server *hes, const struct m0_uint128 *req_id, const struct m0_ha_entrypoint_rep *rep)
Definition: entrypoint.c:306
struct m0_fop_getxattr_rep * rep
Definition: dir.c:455
Definition: sock.c:887
struct m0_ha_entrypoint_server ueus_server
Definition: entrypoint.c:49
struct m0_reqh * hecc_reqh
Definition: entrypoint.h:102
static void ha_ut_entrypoint_reply_check(struct ha_ut_entrypoint_usecase_ctx *uctx, struct m0_ha_entrypoint_rep *rep)
Definition: entrypoint.c:128
int i
Definition: dir.c:1033
#define PRIu64
Definition: types.h:58
static void ha_ut_entrypoint_request_arrived(struct m0_ha_entrypoint_server *hes, const struct m0_ha_entrypoint_req *req, const struct m0_uint128 *req_id)
Definition: entrypoint.c:62
M0_INTERNAL int m0_ha_entrypoint_server_init(struct m0_ha_entrypoint_server *hes, struct m0_ha_entrypoint_server_cfg *hes_cfg)
Definition: entrypoint.c:220
void m0_ha_ut_entrypoint_usecase(void)
Definition: entrypoint.c:199
M0_INTERNAL void m0_ha_entrypoint_server_fini(struct m0_ha_entrypoint_server *hes)
Definition: entrypoint.c:234
M0_INTERNAL int m0_ha_entrypoint_client_init(struct m0_ha_entrypoint_client *ecl, const char *ep, struct m0_ha_entrypoint_client_cfg *ecl_cfg)
Definition: entrypoint.c:434
#define m0_streq(a, b)
Definition: string.h:34
static void ha_ut_entrypoint_client_start(struct ha_ut_entrypoint_usecase_ctx *uctx, struct m0_ha_ut_rpc_ctx *ctx, struct m0_ha_entrypoint_client *ecl)
Definition: entrypoint.c:173
struct m0_reqh * hesc_reqh
Definition: entrypoint.h:69
static void ha_ut_entrypoint_server_start(struct ha_ut_entrypoint_usecase_ctx *uctx, struct m0_ha_ut_rpc_ctx *ctx, struct m0_ha_entrypoint_server *esr)
Definition: entrypoint.c:147
static struct m0_clink clink[RDWR_REQUEST_MAX]
static struct fdmi_ctx ctx
Definition: main.c:80
static void ha_ut_entrypoint_client_stop(struct ha_ut_entrypoint_usecase_ctx *uctx, struct m0_ha_entrypoint_client *ecl)
Definition: entrypoint.c:192
M0_INTERNAL void m0_ha_ut_rpc_ctx_fini(struct m0_ha_ut_rpc_ctx *ctx)
Definition: helper.c:73
M0_INTERNAL bool m0_fid_eq(const struct m0_fid *fid0, const struct m0_fid *fid1)
Definition: fid.c:164
void m0_clink_add_lock(struct m0_chan *chan, struct m0_clink *link)
Definition: chan.c:255
enum m0_ha_entrypoint_control ueus_control
Definition: entrypoint.c:51
M0_INTERNAL void m0_ha_entrypoint_client_start_sync(struct m0_ha_entrypoint_client *ecl)
Definition: entrypoint.c:772
M0_INTERNAL uint64_t m0_rnd64(uint64_t *seed)
Definition: misc.c:100
m0_ha_entrypoint_client_state
Definition: entrypoint.h:86
Definition: fid.h:38
M0_INTERNAL void m0_ha_entrypoint_client_fini(struct m0_ha_entrypoint_client *ecl)
Definition: entrypoint.c:464
#define M0_ALLOC_PTR(ptr)
Definition: memory.h:86
static void ha_ut_entrypoint_server_stop(struct ha_ut_entrypoint_usecase_ctx *uctx, struct m0_ha_entrypoint_server *esr)
Definition: entrypoint.c:165
M0_INTERNAL void m0_clink_fini(struct m0_clink *link)
Definition: chan.c:208
M0_INTERNAL void m0_ha_entrypoint_server_stop(struct m0_ha_entrypoint_server *hes)
Definition: entrypoint.c:258
static void ha_ut_entrypoint_reply_fini(struct ha_ut_entrypoint_usecase_ctx *uctx)
Definition: entrypoint.c:116
M0_INTERNAL struct m0_chan * m0_ha_entrypoint_client_chan(struct m0_ha_entrypoint_client *ecl)
Definition: entrypoint.c:823
struct m0_fid * ueus_confd_fids
Definition: entrypoint.c:54
struct m0_ha_entrypoint_client ueus_client
Definition: entrypoint.c:50
Definition: nucleus.c:42
void m0_free(void *data)
Definition: memory.c:146
m0_ha_entrypoint_control
struct m0_ha_entrypoint_rep ecl_rep
Definition: entrypoint.h:114
int32_t rc
Definition: trigger_fop.h:47
#define ARRAY_SIZE(a)
Definition: misc.h:45
struct m0_clink ueus_clink
Definition: entrypoint.c:59
#define M0_UT_ASSERT(a)
Definition: ut.h:46
static void ha_ut_entrypoint_reply_init(struct ha_ut_entrypoint_usecase_ctx *uctx)
Definition: entrypoint.c:90