Motr  M0
client.h
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 #pragma once
23 
24 #ifndef __MOTR_UT_H__
25 #define __MOTR_UT_H__
26 
27 #include "ut/ut.h" /* M0_UT_ASSERT */
28 #include "motr/client.h"
29 #include "layout/layout.h" /* m0_layout */
30 
31 
32 extern struct m0_config default_config;
33 #define M0_DEFAULT_EP "0@lo:12345:45:101"
34 #define M0_DEFAULT_HA_ADDR "0@lo:12345:66:1"
35 #define M0_DEFAULT_PROFILE "<0x7000000000000001:0>"
36 #define M0_DEFAULT_PROC_FID "<0x7200000000000000:0>"
37 #define SET_DEFAULT_CONFIG() \
38  do { \
39  struct m0_config *confp = &default_config; \
40  \
41  confp->mc_is_oostore = false; \
42  confp->mc_is_read_verify = false; \
43  confp->mc_layout_id = 1; \
44  confp->mc_local_addr = M0_DEFAULT_EP;\
45  confp->mc_ha_addr = M0_DEFAULT_HA_ADDR;\
46  confp->mc_profile = M0_DEFAULT_PROFILE; \
47  confp->mc_process_fid = M0_DEFAULT_PROC_FID; \
48  confp->mc_tm_recv_queue_min_len = M0_NET_TM_RECV_QUEUE_DEF_LEN;\
49  confp->mc_max_rpc_msg_size = M0_RPC_DEF_MAX_RPC_MSG_SIZE; \
50  } while(0);
51 
52 static inline int do_init(struct m0_client **instance)
53 {
55  return m0_client_init(instance, &default_config, false);
56 }
57 
58 #define INIT(instance) do_init(instance)
59 
60 /* These values were extracted from m0t1fs */
61 #define M0T1FS_LAYOUT_P 4
62 #define M0T1FS_LAYOUT_N 2
63 #define M0T1FS_LAYOUT_K 1
64 #define M0T1FS_LAYOUT_S 1
65 /*Some dummy values to help tests */
66 #define DUMMY_PTR 0xdeafdead
67 #define UT_DEFAULT_BLOCK_SIZE (1ULL << M0_DEFAULT_BUF_SHIFT)
68 
69 /* for layout and instance*/
70 extern struct m0_layout_enum ut_layout_enum;
72 
76 M0_INTERNAL int ut_init(void);
77 
78 
82 M0_INTERNAL int ut_fini(void);
83 
85 M0_INTERNAL void ut_realm_entity_setup(struct m0_realm *realm,
86  struct m0_entity *ent,
87  struct m0_client *cinst);
88 
96 M0_INTERNAL int ut_m0_client_init(struct m0_client **instance);
97 
104 M0_INTERNAL void ut_m0_client_fini(struct m0_client **instance);
105 
110 M0_INTERNAL void ut_shuffle_test_order(struct m0_ut_suite *suite);
111 
112 
133 //XXX doxygen
134 M0_INTERNAL void
136  struct m0_layout_domain *dom);
137 
138 M0_INTERNAL void
140  struct m0_layout_domain *dom);
141 
142 /* Helper functions for client unit tests*/
143 
144 #include "motr/pg.h"
145 
146 extern const struct pargrp_iomap_ops mock_iomap_ops;
147 
152 M0_INTERNAL struct m0_obj *ut_dummy_obj_create(void);
153 
158 M0_INTERNAL void ut_dummy_obj_delete(struct m0_obj *obj);
159 
164 M0_INTERNAL struct m0_pdclust_layout *
166 
171 M0_INTERNAL void
173  struct m0_client *instance);
174 
179 //M0_INTERNAL struct m0_layout_instance *
180 M0_INTERNAL struct m0_pdclust_instance *
182 
187 M0_INTERNAL void
189 //ut_dummy_pdclust_instance_delete(struct m0_layout_instance *layout_inst);
190 
194 M0_INTERNAL void ut_dummy_xfer_req_init(struct nw_xfer_request *xfer);
195 
200 M0_INTERNAL struct nw_xfer_request *ut_dummy_xfer_req_create(void);
201 
205 M0_INTERNAL void ut_dummy_xfer_req_fini(struct nw_xfer_request *xfer);
206 
211 M0_INTERNAL void ut_dummy_xfer_req_delete(struct nw_xfer_request *xfer);
212 
217 M0_INTERNAL struct data_buf *
219 
224 M0_INTERNAL void ut_dummy_data_buf_delete(struct data_buf *db);
225 
229 M0_INTERNAL void ut_dummy_data_buf_init(struct data_buf *db);
230 
232 M0_INTERNAL void ut_dummy_data_buf_free(struct data_buf *db);
233 
237 M0_INTERNAL void ut_dummy_data_buf_fini(struct data_buf *db);
238 
239 /*
240  * Creates dummy buf's for parity units
241  *
242  * @param map The parity group
243  * @param do_alloc A flag to control whether allocate and initialise
244  * data buf's.
245  */
246 M0_INTERNAL void ut_dummy_paritybufs_create(struct pargrp_iomap *map,
247  bool do_alloc);
248 /*
249  * Frees dummy buf's for parity units
250  *
251  * @param map The parity group
252  * @param do_free A flag to control whether data buf structures are freed.
253  */
254 M0_INTERNAL void ut_dummy_paritybufs_delete(struct pargrp_iomap *map,
255  bool do_free);
256 
268 M0_INTERNAL struct pargrp_iomap *
269 ut_dummy_pargrp_iomap_create(struct m0_client *instance, int num_blocks);
270 
275 M0_INTERNAL void
277  struct m0_client *instance);
278 
283 M0_INTERNAL struct m0_op_io *
284 ut_dummy_ioo_create(struct m0_client *instance, int num_io_maps);
285 
290 M0_INTERNAL void ut_dummy_ioo_delete(struct m0_op_io *ioo,
291  struct m0_client *instance);
292 
296 M0_INTERNAL struct m0_pdclust_layout *
298 
303 void dummy_ioreq_fop_cb(struct m0_sm_group *grp, struct m0_sm_ast *ast);
304 
309 M0_INTERNAL struct ioreq_fop *ut_dummy_ioreq_fop_create(void);
310 
315 M0_INTERNAL void ut_dummy_ioreq_fop_delete(struct ioreq_fop *fop);
316 
321 M0_INTERNAL void ut_dummy_ioreq_fop_delete(struct ioreq_fop *fop);
322 
323 
328 M0_INTERNAL struct target_ioreq *ut_dummy_target_ioreq_create(void);
329 
334 M0_INTERNAL void ut_dummy_target_ioreq_delete(struct target_ioreq *ti);
335 
339 M0_INTERNAL int ut_dummy_poolmach_create(struct m0_pool_version *pv);
340 
344 M0_INTERNAL void ut_dummy_poolmach_delete(struct m0_pool_version *pv);
345 
346 M0_INTERNAL void ut_set_device_state(struct m0_poolmach *pm, int dev,
347  enum m0_pool_nd_state state);
348 
349 M0_INTERNAL void ut_set_node_state(struct m0_poolmach *pm, int node,
350  enum m0_pool_nd_state state);
351 #endif /* __MOTR_UT_H__ */
352 
353 /*
354  * Local variables:
355  * c-indentation-style: "K&R"
356  * c-basic-offset: 8
357  * tab-width: 8
358  * fill-column: 80
359  * scroll-step: 1
360  * End:
361  */
362 /*
363  * vim: tabstop=8 shiftwidth=8 noexpandtab textwidth=80 nowrap
364  */
M0_INTERNAL void ut_dummy_paritybufs_create(struct pargrp_iomap *map, bool do_alloc)
Definition: io_dummy.c:253
M0_INTERNAL void ut_dummy_data_buf_free(struct data_buf *db)
Definition: io_dummy.c:232
void ut_layout_domain_empty(struct m0_client *cinst)
Definition: obj.c:218
Definition: client.h:794
M0_INTERNAL void ut_set_device_state(struct m0_poolmach *pm, int dev, enum m0_pool_nd_state state)
Definition: io_pargrp.c:1006
M0_INTERNAL void ut_dummy_pdclust_instance_delete(struct m0_pdclust_instance *pdi)
Definition: io_dummy.c:158
map
Definition: processor.c:112
static struct m0_sm_group * grp
Definition: bytecount.c:38
M0_INTERNAL void ut_shuffle_test_order(struct m0_ut_suite *suite)
Definition: client.c:1205
struct m0_pool_version * pv
Definition: dir.c:629
static struct net_test_cmd_node * node
Definition: commands.c:72
M0_INTERNAL void ut_striped_layout_init(struct m0_striped_layout *stl, struct m0_layout_domain *dom)
Definition: obj.c:180
M0_INTERNAL void ut_dummy_pargrp_iomap_delete(struct pargrp_iomap *map, struct m0_client *instance)
Definition: io_dummy.c:342
M0_INTERNAL void ut_dummy_target_ioreq_delete(struct target_ioreq *ti)
Definition: io_dummy.c:554
struct m0_layout_instance_ops ut_layout_instance_ops
Definition: obj.c:106
M0_INTERNAL void ut_dummy_data_buf_fini(struct data_buf *db)
Definition: io_dummy.c:241
M0_INTERNAL void ut_dummy_xfer_req_fini(struct nw_xfer_request *xfer)
Definition: io_dummy.c:187
Definition: sm.h:504
void ut_layout_domain_fill(struct m0_client *cinst)
Definition: obj.c:208
int m0_client_init(struct m0_client **m0c, struct m0_config *conf, bool init_m0)
Definition: client_init.c:1533
Definition: ut.h:77
M0_INTERNAL void ut_striped_layout_fini(struct m0_striped_layout *stl, struct m0_layout_domain *dom)
Definition: obj.c:202
M0_INTERNAL struct m0_obj * ut_dummy_obj_create(void)
Definition: io_dummy.c:64
static struct foo * obj
Definition: tlist.c:302
M0_INTERNAL void ut_dummy_paritybufs_delete(struct pargrp_iomap *map, bool do_free)
Definition: io_dummy.c:283
M0_INTERNAL struct nw_xfer_request * ut_dummy_xfer_req_create(void)
Definition: io_dummy.c:178
M0_INTERNAL int ut_init(void)
Definition: client.c:1245
static struct m0_sm_ast ast[NR]
Definition: locality.c:44
M0_INTERNAL struct m0_pdclust_instance * ut_dummy_pdclust_instance_create(struct m0_pdclust_layout *pdl)
Definition: io_dummy.c:118
M0_INTERNAL struct m0_pdclust_layout * ut_get_pdclust_layout_from_ioo(struct m0_op_io *ioo)
Definition: io_dummy.c:458
M0_INTERNAL void ut_dummy_ioo_delete(struct m0_op_io *ioo, struct m0_client *instance)
Definition: io_dummy.c:465
void dummy_ioreq_fop_cb(struct m0_sm_group *grp, struct m0_sm_ast *ast)
Definition: io_dummy.c:510
M0_INTERNAL void ut_dummy_ioreq_fop_delete(struct ioreq_fop *fop)
Definition: io_dummy.c:528
M0_INTERNAL void ut_dummy_poolmach_delete(struct m0_pool_version *pv)
Definition: io_dummy.c:630
#define SET_DEFAULT_CONFIG()
Definition: client.h:37
M0_INTERNAL struct target_ioreq * ut_dummy_target_ioreq_create(void)
Definition: io_dummy.c:534
m0_pool_nd_state
Definition: pool_machine.h:57
static struct m0_stob_domain * dom
Definition: storage.c:38
M0_INTERNAL struct ioreq_fop * ut_dummy_ioreq_fop_create(void)
Definition: io_dummy.c:514
M0_INTERNAL int ut_dummy_poolmach_create(struct m0_pool_version *pv)
Definition: io_dummy.c:565
M0_INTERNAL struct pargrp_iomap * ut_dummy_pargrp_iomap_create(struct m0_client *instance, int num_blocks)
Definition: io_dummy.c:303
M0_INTERNAL void ut_dummy_pdclust_layout_delete(struct m0_pdclust_layout *pl, struct m0_client *instance)
Definition: io_dummy.c:108
M0_INTERNAL struct data_buf * ut_dummy_data_buf_create(void)
Definition: io_dummy.c:200
static struct m0_client cinst
Definition: sync.c:84
struct m0_config default_config
Definition: client.c:58
M0_INTERNAL int ut_m0_client_init(struct m0_client **instance)
Definition: client.c:265
M0_INTERNAL struct m0_pdclust_layout * ut_dummy_pdclust_layout_create(struct m0_client *instance)
Definition: io_dummy.c:79
M0_INTERNAL struct m0_op_io * ut_dummy_ioo_create(struct m0_client *instance, int num_io_maps)
Definition: io_dummy.c:368
M0_INTERNAL void ut_dummy_xfer_req_init(struct nw_xfer_request *xfer)
Definition: io_dummy.c:171
static struct m0_realm realm
Definition: sync.c:87
M0_INTERNAL void ut_dummy_xfer_req_delete(struct nw_xfer_request *xfer)
Definition: io_dummy.c:193
static struct m0_fop * fop
Definition: item.c:57
static struct m0 instance
Definition: main.c:78
M0_INTERNAL void ut_dummy_obj_delete(struct m0_obj *obj)
Definition: io_dummy.c:73
M0_INTERNAL int ut_fini(void)
Definition: client.c:1257
M0_INTERNAL void ut_set_node_state(struct m0_poolmach *pm, int node, enum m0_pool_nd_state state)
Definition: io_pargrp.c:1012
M0_INTERNAL void ut_m0_client_fini(struct m0_client **instance)
Definition: client.c:354
Definition: pg.h:859
struct m0_dirent * ent
Definition: dir.c:1029
struct m0_layout_enum ut_layout_enum
Definition: obj.c:92
const struct pargrp_iomap_ops mock_iomap_ops
Definition: io_dummy.c:672
M0_INTERNAL void ut_dummy_data_buf_delete(struct data_buf *db)
Definition: io_dummy.c:209
M0_INTERNAL void ut_realm_entity_setup(struct m0_realm *realm, struct m0_entity *ent, struct m0_client *cinst)
Definition: client.c:60
static int do_init(struct m0_client **instance)
Definition: client.h:52
M0_INTERNAL void ut_dummy_data_buf_init(struct data_buf *db)
Definition: io_dummy.c:215