Motr  M0
ut_rpc_machine.c
Go to the documentation of this file.
1 /* -*- C -*- */
2 /*
3  * Copyright (c) 2013-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 "ut/ut.h"
24 #include "ut/be.h"
25 #include "ut/ut_rpc_machine.h"
26 
27 static void ut_reqh_and_stuff_init(struct m0_ut_rpc_mach_ctx *ctx);
28 
29 static void buf_dummy(struct m0_net_buffer_pool *bp)
30 {
31 }
32 
33 static const struct m0_net_buffer_pool_ops buf_ops = {
35  .nbpo_not_empty = buf_dummy
36 };
37 
39 {
40  enum { UT_BUF_NR = 8, UT_TM_NR = 2 };
41  int rc;
42 
43  ctx->rmc_xprt = m0_net_xprt_default_get();
44  rc = m0_net_domain_init(&ctx->rmc_net_dom, ctx->rmc_xprt);
45  M0_ASSERT(rc == 0);
46 
47  ctx->rmc_bufpool.nbp_ops = &buf_ops;
48  rc = m0_rpc_net_buffer_pool_setup(&ctx->rmc_net_dom, &ctx->rmc_bufpool,
49  UT_BUF_NR, UT_TM_NR);
50  M0_ASSERT(rc == 0);
51 
53 
54  m0_reqh_start(&ctx->rmc_reqh);
55  rc = m0_rpc_machine_init(&ctx->rmc_rpc, &ctx->rmc_net_dom,
56  ctx->rmc_ep_addr, &ctx->rmc_reqh,
57  &ctx->rmc_bufpool, M0_BUFFER_ANY_COLOUR,
60  M0_ASSERT(rc == 0);
61 }
62 
63 #ifndef __KERNEL__
64 
65 static char *ut_reqh_location_get(void)
66 {
67  static const size_t str_len = 100;
68  char *str = m0_alloc(str_len);
69  static uint64_t start = 10000;
70 
71  M0_ASSERT(str != NULL);
72  snprintf(str, str_len, "linuxstob:./ut_reqh%"PRIu64, start++);
73  return str;
74 }
75 
77 {
78  struct m0_sm_group *grp;
79  struct m0_be_seg *seg;
80  struct m0_be_tx tx;
81  struct m0_be_tx_credit cred = {};
82  char *location;
83  int rc;
84  /*
85  * Instead of using m0d and dealing with network, database and
86  * other subsystems, request handler is initialised in a 'special way'.
87  * This allows it to operate in a 'limited mode' which is enough for
88  * this test.
89  */
90  rc = M0_REQH_INIT(&ctx->rmc_reqh,
91  .rhia_mdstore = &ctx->rmc_mdstore,
92  .rhia_fid = &g_process_fid,
93  );
94  M0_ASSERT(rc == 0);
95 
96  ctx->rmc_ut_be.but_dom_cfg.bc_engine.bec_reqh = &ctx->rmc_reqh;
98  ctx->rmc_ut_be.but_stob_domain_location = location;
99  rc = m0_be_ut_backend_init_cfg(&ctx->rmc_ut_be, NULL, true);
100  M0_ASSERT(rc == 0);
101  m0_be_ut_seg_init(&ctx->rmc_ut_seg, &ctx->rmc_ut_be, 1 << 20);
102  seg = ctx->rmc_ut_seg.bus_seg;
104 
105  rc = m0_reqh_be_init(&ctx->rmc_reqh, seg);
106  M0_ASSERT(rc == 0);
107 
108  rc = m0_mdstore_init(&ctx->rmc_mdstore, seg, 0);
109  M0_ASSERT(rc == -ENOENT);
110  rc = m0_mdstore_create(&ctx->rmc_mdstore, grp, &ctx->rmc_cob_id,
111  &ctx->rmc_ut_be.but_dom, seg);
112  M0_ASSERT(rc == 0);
113 
114  m0_cob_tx_credit(ctx->rmc_mdstore.md_dom, M0_COB_OP_DOMAIN_MKFS,
115  &cred);
116  m0_ut_be_tx_begin(&tx, &ctx->rmc_ut_be, &cred);
117  rc = m0_cob_domain_mkfs(ctx->rmc_mdstore.md_dom,
118  &M0_MDSERVICE_SLASH_FID, &tx);
119  m0_ut_be_tx_end(&tx);
120  M0_ASSERT(rc == 0);
121 }
122 
123 M0_INTERNAL void m0_ut_rpc_mach_fini(struct m0_ut_rpc_mach_ctx *ctx)
124 {
125  struct m0_sm_group *grp;
126  int rc;
127 
128  m0_reqh_idle_wait(&ctx->rmc_reqh);
132  rc = m0_mdstore_destroy(&ctx->rmc_mdstore, grp,
133  &ctx->rmc_ut_be.but_dom);
134  M0_ASSERT(rc == 0);
135 
136  m0_be_ut_seg_fini(&ctx->rmc_ut_seg);
137  m0_be_ut_backend_fini(&ctx->rmc_ut_be);
139  ctx->rmc_ut_be.but_stob_domain_location);
140  m0_free(ctx->rmc_ut_be.but_stob_domain_location);
142  m0_rpc_machine_fini(&ctx->rmc_rpc);
143  m0_reqh_fini(&ctx->rmc_reqh);
144 
145  m0_rpc_net_buffer_pool_cleanup(&ctx->rmc_bufpool);
146  m0_net_domain_fini(&ctx->rmc_net_dom);
147 }
148 
149 #else /* __KERNEL__ */
150 
151 static void ut_reqh_and_stuff_init(struct m0_ut_rpc_mach_ctx *ctx)
152 {
153  int rc;
154  /*
155  * Instead of using m0d and dealing with network, database and
156  * other subsystems, request handler is initialised in a 'special way'.
157  * This allows it to operate in a 'limited mode' which is enough for
158  * this test.
159  */
160  rc = M0_REQH_INIT(&ctx->rmc_reqh,
161  .rhia_dtm = (void*)1,
162  .rhia_mdstore = (void*)1,
163  .rhia_fid = &g_process_fid,
164  );
165  M0_ASSERT(rc == 0);
166 }
167 
168 M0_INTERNAL void m0_ut_rpc_mach_fini(struct m0_ut_rpc_mach_ctx *ctx)
169 {
170  m0_reqh_services_terminate(&ctx->rmc_reqh);
171  m0_rpc_machine_fini(&ctx->rmc_rpc);
172  m0_reqh_fini(&ctx->rmc_reqh);
173 }
174 
175 #endif
176 
177 /*
178  * Local variables:
179  * c-indentation-style: "K&R"
180  * c-basic-offset: 8
181  * tab-width: 8
182  * fill-column: 80
183  * scroll-step: 1
184  * End:
185  */
186 /*
187  * vim: tabstop=8 shiftwidth=8 noexpandtab textwidth=80 nowrap
188  */
void m0_be_ut_seg_fini(struct m0_be_ut_seg *ut_seg)
Definition: stubs.c:267
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
M0_INTERNAL void m0_ut_rpc_mach_init_and_add(struct m0_ut_rpc_mach_ctx *ctx)
M0_INTERNAL int m0_be_ut_backend_init_cfg(struct m0_be_ut_backend *ut_be, const struct m0_be_domain_cfg *cfg, bool mkfs)
Definition: stubs.c:231
M0_INTERNAL int m0_cob_domain_mkfs(struct m0_cob_domain *dom, const struct m0_fid *rootfid, struct m0_be_tx *tx)
Definition: cob.c:980
#define NULL
Definition: misc.h:38
M0_INTERNAL int m0_mdstore_init(struct m0_mdstore *md, struct m0_be_seg *db, bool init_root)
Definition: mdstore.c:78
#define M0_REQH_INIT(reqh,...)
Definition: reqh.h:262
static struct m0_sm_group * grp
Definition: bytecount.c:38
static void buf_dummy(struct m0_net_buffer_pool *bp)
M0_INTERNAL void m0_ut_be_tx_end(struct m0_be_tx *tx)
Definition: be.c:82
void m0_be_ut_seg_init(struct m0_be_ut_seg *ut_seg, struct m0_be_ut_backend *ut_be, m0_bcount_t size)
Definition: stubs.c:256
M0_INTERNAL void m0_reqh_fini(struct m0_reqh *reqh)
Definition: reqh.c:320
static char * ut_reqh_location_get(void)
const char * location
Definition: storage.c:50
M0_INTERNAL void m0_cob_tx_credit(struct m0_cob_domain *dom, enum m0_cob_op optype, struct m0_be_tx_credit *accum)
Definition: cob.c:2281
#define PRIu64
Definition: types.h:58
M0_INTERNAL const struct m0_fid M0_MDSERVICE_SLASH_FID
Definition: md_fid.c:63
M0_INTERNAL void m0_ut_be_tx_begin(struct m0_be_tx *tx, struct m0_be_ut_backend *ut_be, struct m0_be_tx_credit *cred)
Definition: be.c:56
void(* nbpo_below_threshold)(struct m0_net_buffer_pool *)
Definition: buffer_pool.h:152
#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 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
void * m0_alloc(size_t size)
Definition: memory.c:126
M0_INTERNAL void m0_be_domain_cleanup_by_location(const char *stob_domain_location)
Definition: domain.c:442
static void ut_reqh_and_stuff_init(struct m0_ut_rpc_mach_ctx *ctx)
struct m0_sm_group * m0_be_ut_backend_sm_group_lookup(struct m0_be_ut_backend *ut_be)
Definition: stubs.c:277
M0_INTERNAL void m0_reqh_post_storage_fini_svcs_stop(struct m0_reqh *reqh)
Definition: reqh.c:704
Definition: seg.h:66
M0_INTERNAL void m0_reqh_idle_wait(struct m0_reqh *reqh)
Definition: reqh.c:606
M0_INTERNAL int m0_reqh_state_get(struct m0_reqh *reqh)
Definition: reqh.c:398
M0_INTERNAL void m0_reqh_start(struct m0_reqh *reqh)
Definition: reqh.c:711
int m0_net_domain_init(struct m0_net_domain *dom, const struct m0_net_xprt *xprt)
Definition: domain.c:36
static const struct m0_net_buffer_pool_ops buf_ops
M0_INTERNAL int m0_mdstore_create(struct m0_mdstore *md, struct m0_sm_group *grp, struct m0_cob_domain_id *id, struct m0_be_domain *bedom, struct m0_be_seg *db)
Definition: mdstore.c:135
M0_INTERNAL void m0_ut_rpc_mach_fini(struct m0_ut_rpc_mach_ctx *ctx)
static int start(struct m0_fom *fom)
Definition: trigger_fom.c:321
M0_INTERNAL void m0_reqh_pre_storage_fini_svcs_stop(struct m0_reqh *reqh)
Definition: reqh.c:681
void m0_be_ut_backend_fini(struct m0_be_ut_backend *ut_be)
Definition: stubs.c:242
static struct m0_be_seg * seg
Definition: btree.c:40
M0_INTERNAL int m0_mdstore_destroy(struct m0_mdstore *md, struct m0_sm_group *grp, struct m0_be_domain *bedom)
Definition: mdstore.c:146
static struct bulkio_params * bp
Definition: bulkio_ut.c:44
Definition: nucleus.c:42
void m0_rpc_net_buffer_pool_cleanup(struct m0_net_buffer_pool *app_pool)
Definition: rpc.c:264
void m0_free(void *data)
Definition: memory.c:146
M0_INTERNAL int m0_reqh_be_init(struct m0_reqh *reqh, struct m0_be_seg *seg)
Definition: reqh.c:269
int32_t rc
Definition: trigger_fop.h:47
struct m0_fid g_process_fid
Definition: ut.c:689
Definition: tx.h:280