Motr  M0
helper.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/ut/helper.h"
34 #include "ut/ut.h"
35 
36 #include "lib/types.h" /* uint32_t */
37 #include "fid/fid.h" /* m0_fid */
38 #include "rpc/rpclib.h" /* m0_rpc_client_connect */
39 
40 
41 M0_INTERNAL void m0_ha_ut_rpc_ctx_init(struct m0_ha_ut_rpc_ctx *ctx)
42 {
43  struct m0_fid process_fid = M0_FID_TINIT('r', 0, 1);
44  const uint32_t tms_nr = 1;
45  const uint32_t bufs_nr =
47  const char *ep = "0@lo:12345:42:100";
48  int rc;
49 
50  rc = m0_net_domain_init(&ctx->hurc_net_domain,
52  M0_ASSERT(rc == 0);
53  rc = m0_rpc_net_buffer_pool_setup(&ctx->hurc_net_domain,
54  &ctx->hurc_buffer_pool,
55  bufs_nr, tms_nr);
56  M0_ASSERT(rc == 0);
57  rc = M0_REQH_INIT(&ctx->hurc_reqh,
58  .rhia_dtm = (void*)1,
59  .rhia_mdstore = (void*)1,
60  .rhia_fid = &process_fid);
61  M0_ASSERT(rc == 0);
62  m0_reqh_start(&ctx->hurc_reqh);
63  rc = m0_rpc_machine_init(&ctx->hurc_rpc_machine,
64  &ctx->hurc_net_domain, ep,
65  &ctx->hurc_reqh,
66  &ctx->hurc_buffer_pool,
70  M0_ASSERT(rc == 0);
71 }
72 
73 M0_INTERNAL void m0_ha_ut_rpc_ctx_fini(struct m0_ha_ut_rpc_ctx *ctx)
74 {
75  m0_reqh_shutdown_wait(&ctx->hurc_reqh);
76  m0_rpc_machine_fini(&ctx->hurc_rpc_machine);
77  m0_reqh_services_terminate(&ctx->hurc_reqh);
78  m0_reqh_fini(&ctx->hurc_reqh);
79  m0_rpc_net_buffer_pool_cleanup(&ctx->hurc_buffer_pool);
80  m0_net_domain_fini(&ctx->hurc_net_domain);
81 }
82 
83 M0_INTERNAL void
85  struct m0_ha_ut_rpc_ctx *ctx)
86 {
87  int rc;
88 
89  rc = m0_rpc_client_connect(&sctx->husc_conn, &sctx->husc_session,
90  &ctx->hurc_rpc_machine,
91  m0_rpc_machine_ep(&ctx->hurc_rpc_machine),
94  M0_UT_ASSERT(rc == 0);
95 }
96 
97 M0_INTERNAL void
99 {
100  int rc;
101 
102  rc = m0_rpc_session_destroy(&sctx->husc_session, M0_TIME_NEVER);
103  M0_UT_ASSERT(rc == 0);
104  rc = m0_rpc_conn_destroy(&sctx->husc_conn, M0_TIME_NEVER);
105  M0_UT_ASSERT(rc == 0);
106 }
107 
108 #undef M0_TRACE_SUBSYSTEM
109 
112 /*
113  * Local variables:
114  * c-indentation-style: "K&R"
115  * c-basic-offset: 8
116  * tab-width: 8
117  * fill-column: 80
118  * scroll-step: 1
119  * End:
120  */
121 /*
122  * vim: tabstop=8 shiftwidth=8 noexpandtab textwidth=80 nowrap
123  */
void m0_rpc_machine_fini(struct m0_rpc_machine *machine)
Definition: rpc_machine.c:233
M0_INTERNAL void m0_reqh_services_terminate(struct m0_reqh *reqh)
Definition: reqh.c:675
void m0_net_domain_fini(struct m0_net_domain *dom)
Definition: domain.c:71
#define NULL
Definition: misc.h:38
#define M0_REQH_INIT(reqh,...)
Definition: reqh.h:262
const m0_time_t M0_TIME_NEVER
Definition: time.c:108
int m0_rpc_session_destroy(struct m0_rpc_session *session, m0_time_t abs_timeout)
Definition: session.c:559
M0_INTERNAL void m0_ha_ut_rpc_ctx_init(struct m0_ha_ut_rpc_ctx *ctx)
Definition: helper.c:41
M0_INTERNAL void m0_reqh_fini(struct m0_reqh *reqh)
Definition: reqh.c:320
M0_INTERNAL const char * m0_rpc_machine_ep(const struct m0_rpc_machine *rmach)
Definition: rpc_machine.c:603
M0_INTERNAL void m0_reqh_shutdown_wait(struct m0_reqh *reqh)
Definition: reqh.c:647
Definition: sock.c:754
M0_INTERNAL int m0_rpc_client_connect(struct m0_rpc_conn *conn, struct m0_rpc_session *session, struct m0_rpc_machine *rpc_mach, const char *remote_addr, struct m0_fid *svc_fid, uint64_t max_rpcs_in_flight, m0_time_t abs_timeout)
Definition: rpclib.c:102
#define M0_FID_TINIT(type, container, key)
Definition: fid.h:90
#define M0_ASSERT(cond)
M0_INTERNAL int m0_rpc_net_buffer_pool_setup(struct m0_net_domain *ndom, struct m0_net_buffer_pool *app_pool, uint32_t bufs_nr, uint32_t tm_nr)
Definition: rpc.c:229
M0_INTERNAL uint32_t m0_rpc_bufs_nr(uint32_t len, uint32_t tms_nr)
Definition: rpc.c:271
int m0_rpc_conn_destroy(struct m0_rpc_conn *conn, m0_time_t abs_timeout)
Definition: conn.c:974
M0_INTERNAL int m0_rpc_machine_init(struct m0_rpc_machine *machine, struct m0_net_domain *net_dom, const char *ep_addr, struct m0_reqh *reqh, struct m0_net_buffer_pool *receive_pool, uint32_t colour, m0_bcount_t msg_size, uint32_t queue_len)
Definition: rpc_machine.c:123
struct m0_net_xprt * m0_net_xprt_default_get(void)
Definition: net.c:151
static struct m0_rpc_server_ctx sctx
Definition: console.c:88
M0_INTERNAL void m0_ha_ut_rpc_ctx_fini(struct m0_ha_ut_rpc_ctx *ctx)
Definition: helper.c:73
M0_INTERNAL void m0_reqh_start(struct m0_reqh *reqh)
Definition: reqh.c:711
M0_INTERNAL void m0_ha_ut_rpc_session_ctx_fini(struct m0_ha_ut_rpc_session_ctx *sctx)
Definition: helper.c:98
int m0_net_domain_init(struct m0_net_domain *dom, const struct m0_net_xprt *xprt)
Definition: domain.c:36
Definition: fid.h:38
M0_INTERNAL void m0_ha_ut_rpc_session_ctx_init(struct m0_ha_ut_rpc_session_ctx *sctx, struct m0_ha_ut_rpc_ctx *ctx)
Definition: helper.c:84
Definition: nucleus.c:42
void m0_rpc_net_buffer_pool_cleanup(struct m0_net_buffer_pool *app_pool)
Definition: rpc.c:264
int32_t rc
Definition: trigger_fop.h:47
#define M0_UT_ASSERT(a)
Definition: ut.h:46
static const char * process_fid
Definition: idx_dix.c:73