Motr  M0
clnt_srv_ctx.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 #include "fop/fop.h" /* m0_fop_alloc */
24 #include "rpc/rpclib.h"
25 #include "ut/cs_fop.h" /* cs_ds2_req_fop_fopt */
26 #include "ut/cs_fop_xc.h" /* cs_ds2_req_fop */
27 #include "ut/cs_service.h" /* m0_cs_default_stypes */
28 #include "ut/misc.h" /* M0_UT_PATH */
29 #define CLIENT_ENDPOINT_ADDR "0@lo:12345:34:*"
30 
31 #define SERVER_DB_NAME "rpc_ut_server.db"
32 #define SERVER_STOB_NAME "rpc_ut_server.stob"
33 #define SERVER_ADDB_STOB_NAME "linuxstob:rpc_ut_server.addb_stob"
34 #define SERVER_LOG_NAME "rpc_ut_server.log"
35 #define SERVER_ENDPOINT_ADDR "0@lo:12345:34:1"
36 #define SERVER_ENDPOINT M0_NET_XPRT_PREFIX_DEFAULT":"SERVER_ENDPOINT_ADDR
37 
38 enum {
42 };
44 
45 #ifndef __KERNEL__
46 static struct m0_rpc_client_ctx cctx = {
48  .rcx_local_addr = CLIENT_ENDPOINT_ADDR,
49  .rcx_remote_addr = SERVER_ENDPOINT_ADDR,
50  .rcx_max_rpcs_in_flight = MAX_RPCS_IN_FLIGHT,
51  .rcx_recv_queue_min_length = M0_NET_TM_RECV_QUEUE_DEF_LEN,
52  .rcx_fid = &g_process_fid,
53 };
54 
55 static char *server_argv[] = {
56  "rpclib_ut", "-T", "AD", "-D", SERVER_DB_NAME,
58  "-w", "10", "-e", SERVER_ENDPOINT, "-H", SERVER_ENDPOINT_ADDR,
59  "-f", M0_UT_CONF_PROCESS,
60  "-c", M0_UT_PATH("conf.xc")
61 };
62 
63 static struct m0_rpc_server_ctx sctx;
64 
65 /* 'inline' is used, to avoid compiler warning if the function is not used
66  in file that includes this file.
67  */
68 static inline void sctx_reset(void)
69 {
70 
71  sctx = (struct m0_rpc_server_ctx){
73  .rsx_xprts_nr = m0_net_xprt_nr(),
74  .rsx_argv = server_argv,
75  .rsx_argc = ARRAY_SIZE(server_argv),
76  .rsx_log_file_name = SERVER_LOG_NAME,
77  };
78 }
79 
80 static inline void start_rpc_client_and_server(void)
81 {
82  int rc;
84  M0_ASSERT(rc == 0);
85  sctx_reset();
87  M0_ASSERT(rc == 0);
88 
90  M0_ASSERT(rc == 0);
91 }
92 
93 /* 'inline' is used, to avoid compiler warning if the function is not used
94  in file that includes this file.
95  */
96 static inline void stop_rpc_client_and_server(void)
97 {
98  int rc;
100  M0_ASSERT(rc == 0);
103 }
104 
105 /* 'inline' is used, to avoid compiler warning if the function is not used
106  in file that includes this file.
107  */
108 static inline struct m0_fop *fop_alloc(struct m0_rpc_machine *machine)
109 {
110  struct cs_ds2_req_fop *cs_ds2_fop;
111  struct m0_fop *fop;
112 
113  M0_PRE(machine != NULL);
114 
116  M0_UT_ASSERT(fop != NULL);
117 
118  cs_ds2_fop = m0_fop_data(fop);
119  cs_ds2_fop->csr_value = 0xaaf5;
120 
121  return fop;
122 }
123 
124 #endif /* !__KERNEL__ */
125 /*
126  * Local variables:
127  * c-indentation-style: "K&R"
128  * c-basic-offset: 8
129  * tab-width: 8
130  * fill-column: 80
131  * scroll-step: 1
132  * End:
133  */
#define SERVER_ENDPOINT_ADDR
Definition: clnt_srv_ctx.c:35
#define M0_PRE(cond)
#define SERVER_STOB_NAME
Definition: clnt_srv_ctx.c:32
void m0_net_domain_fini(struct m0_net_domain *dom)
Definition: domain.c:71
#define NULL
Definition: misc.h:38
static void sctx_reset(void)
Definition: clnt_srv_ctx.c:68
int m0_rpc_server_start(struct m0_rpc_server_ctx *sctx)
Definition: rpclib.c:50
#define CLIENT_ENDPOINT_ADDR
Definition: clnt_srv_ctx.c:29
void * m0_fop_data(const struct m0_fop *fop)
Definition: fop.c:220
static struct m0_fop * fop_alloc(struct m0_rpc_machine *machine)
Definition: clnt_srv_ctx.c:108
#define SERVER_DB_NAME
Definition: clnt_srv_ctx.c:31
static void stop_rpc_client_and_server(void)
Definition: clnt_srv_ctx.c:96
#define M0_ASSERT(cond)
int m0_net_xprt_nr(void)
Definition: net.c:168
int m0_rpc_client_stop(struct m0_rpc_client_ctx *cctx)
Definition: rpclib.c:217
struct m0_net_xprt * m0_net_xprt_default_get(void)
Definition: net.c:151
int m0_rpc_client_start(struct m0_rpc_client_ctx *cctx)
Definition: rpclib.c:160
struct m0_net_xprt ** rsx_xprts
Definition: rpclib.h:69
#define SERVER_ADDB_STOB_NAME
Definition: clnt_srv_ctx.c:33
struct m0_rpc_machine machine
Definition: mdstore.c:58
struct m0_net_domain * rcx_net_dom
Definition: rpclib.h:128
struct m0_fop_type cs_ds2_req_fop_fopt
Definition: cs_fop.c:53
static char * server_argv[]
Definition: clnt_srv_ctx.c:55
static struct m0_rpc_server_ctx sctx
Definition: clnt_srv_ctx.c:63
#define SERVER_ENDPOINT
Definition: clnt_srv_ctx.c:36
int m0_net_domain_init(struct m0_net_domain *dom, const struct m0_net_xprt *xprt)
Definition: domain.c:36
#define SERVER_LOG_NAME
Definition: clnt_srv_ctx.c:34
#define M0_UT_CONF_PROCESS
Definition: misc.h:45
struct m0_net_xprt ** m0_net_all_xprt_get(void)
Definition: net.c:161
static struct m0_net_domain client_net_dom
Definition: clnt_srv_ctx.c:43
uint64_t csr_value
Definition: cs_fop.h:86
static struct m0_rpc_client_ctx cctx
Definition: clnt_srv_ctx.c:46
static struct m0_fop * fop
Definition: item.c:57
void m0_rpc_server_stop(struct m0_rpc_server_ctx *sctx)
Definition: rpclib.c:85
#define M0_UT_PATH(name)
Definition: misc.h:41
int32_t rc
Definition: trigger_fop.h:47
#define ARRAY_SIZE(a)
Definition: misc.h:45
struct m0_fid g_process_fid
Definition: ut.c:689
#define M0_UT_ASSERT(a)
Definition: ut.h:46
static void start_rpc_client_and_server(void)
Definition: clnt_srv_ctx.c:80
Definition: fop.h:79
struct m0_fop * m0_fop_alloc(struct m0_fop_type *fopt, void *data, struct m0_rpc_machine *mach)
Definition: fop.c:96