Motr  M0
io_req_fop.c
Go to the documentation of this file.
1 /* -*- C -*- */
2 /*
3  * Copyright (c) 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 "layout/layout.h"
24 
25 #define M0_TRACE_SUBSYSTEM M0_TRACE_SUBSYS_CLIENT
26 #include "lib/trace.h" /* M0_LOG */
27 #include "lib/uuid.h" /* m0_uuid_generate */
28 
29 #include "ut/ut.h" /* M0_UT_ASSERT */
30 #include "motr/ut/client.h"
31 
32 /*
33  * Including the c files so we can replace the M0_PRE asserts
34  * in order to test them.
35  */
36 #if defined(round_down)
37 #undef round_down
38 #endif
39 #if defined(round_up)
40 #undef round_up
41 #endif
42 #include "motr/io_req_fop.c"
43 
45 static struct m0_client *dummy_instance;
46 
50 static void ut_test_ioreq_fop_invariant(void)
51 {
52  struct ioreq_fop *fop;
53  bool ret;
54 
56 
57  /* Base case. */
58  ret = ioreq_fop_invariant(fop);
59  M0_UT_ASSERT(ret == true);
60 
62 }
63 
65 {
66 }
67 
68 static void ut_test_io_bottom_half(void)
69 {
70 }
71 
72 static uint32_t ut_sa_cb_executed;
74  struct m0_sm_ast *ast)
75 {
77 }
78 
79 static void ut_mock_rpc_item_release(struct m0_ref *ref)
80 {
81  /* Do nothing. */
82 }
83 
87 static void ut_test_io_rpc_item_cb(void)
88 {
89  struct m0_fop *fop;
90  struct m0_fop *rep_fop;
91  struct m0_rpc_item *item;
92  struct m0_op_io *ioo;
93  struct ioreq_fop *reqfop;
94  struct m0_client *instance = NULL;
95 
96  /* Init. */
98  M0_ALLOC_PTR(reqfop);
100 
101  /* Base case. */
102  ioo = ut_dummy_ioo_create(instance, 1);
103  M0_ALLOC_PTR(reqfop->irf_tioreq);
104  reqfop->irf_tioreq->ti_nwxfer = &ioo->ioo_nwxfer;
105  ioreq_fop_bob_init(reqfop);
106  fop = &reqfop->irf_iofop.if_fop;
107  item = &fop->f_item;
112 
113  ut_sa_cb_executed = 0;
114 
118 
119  /* The CB should be enqueued by now. Force its execution. */
123 
124  ioreq_fop_bob_fini(reqfop);
125  m0_free(reqfop->irf_tioreq);
127 
128  /* Fini. */
129  m0_free(rep_fop);
130  m0_free(reqfop);
131 }
132 
134 {
135 }
136 
138 {
139 }
140 
144 static void ut_test_ioreq_fop_release(void)
145 {
146  struct ioreq_fop *fop;
147  struct target_ioreq *ti;
148  struct m0_op_io *ioo;
149  int rc;
150  struct m0_client *instance = NULL;
151 
152  /* initialise client */
154 
155  /* Base case. */
156  M0_ALLOC_PTR(fop);
158  ioo = ut_dummy_ioo_create(instance, 1);
159  ti->ti_nwxfer = &ioo->ioo_nwxfer;
161  /* This is dirty, but avoids a chain of sm_move */
162  ioo->ioo_sm.sm_state = IRS_READING;
163 
164  rc = ioreq_fop_init(fop, ti, PA_DATA);
165  M0_UT_ASSERT(rc == 0);
166  rpcbulk_tlist_init(&fop->irf_iofop.if_rbulk.rb_buflist);
167  m0_mutex_init(&fop->irf_iofop.if_rbulk.rb_mutex);
168 
169  ioreq_fop_release(&fop->irf_iofop.if_fop.f_ref);
170 
174 }
175 
179 static void ut_test_ioreq_fop_init(void)
180 {
181  struct ioreq_fop *fop;
182  struct target_ioreq *ti;
183  struct m0_op_io *ioo;
184  int rc;
185  struct m0_client *instance = NULL;
186 
187  /* initialise client */
189 
190  /* Base case. */
191  M0_ALLOC_PTR(fop);
193  ioo = ut_dummy_ioo_create(instance, 1);
194  ti->ti_nwxfer = &ioo->ioo_nwxfer;
195  /* This is dirty, but avoids a chain of sm_move */
196  ioo->ioo_sm.sm_state = IRS_READING;
197 
198  rc = ioreq_fop_init(fop, ti, PA_DATA);
199  M0_UT_ASSERT(rc == 0);
200  M0_UT_ASSERT(fop->irf_pattr == PA_DATA);
201  M0_UT_ASSERT(fop->irf_tioreq == ti);
202  M0_UT_ASSERT(fop->irf_reply_rc == 0);
203  M0_UT_ASSERT(fop->irf_ast.sa_cb == io_bottom_half);
204  M0_UT_ASSERT(fop->irf_iofop.if_fop.f_item.ri_ops == &item_ops);
205 
206  m0_free(fop->irf_iofop.if_fop.f_data.fd_data);
208 
211  m0_free(fop);
212 }
213 
217 static void ut_test_ioreq_fop_fini(void)
218 {
219  struct ioreq_fop *fop;
220 
221  /* Base case. */
223  iofops_tlink_init(fop);
225  M0_UT_ASSERT(fop->irf_tioreq == NULL);
226  M0_UT_ASSERT(fop->irf_ast.sa_cb == NULL);
227  M0_UT_ASSERT(fop->irf_ast.sa_mach == NULL);
228 
230 }
231 
232 static void ut_test_ioreq_pgiomap_find(void)
233 {
234  struct pargrp_iomap *map;
235  struct m0_client *instance = NULL;
236  struct m0_op_io *ioo;
237  uint64_t cursor = 0;
238 
239  /* init */
241  ioo = ut_dummy_ioo_create(instance, 1);
242  cursor = 0;
243 
244  /* Base cases. */
245  ioreq_pgiomap_find(ioo, 0, &cursor, &map);
246 
247  /* fini */
249 
250 }
251 
253 {
254 }
255 
256 M0_INTERNAL int ut_io_req_fop_init(void)
257 {
258  int rc;
260 
261 #ifndef __KERNEL__
263 #endif
264 
266 
268  M0_UT_ASSERT(rc == 0);
269 
274 
275  return 0;
276 }
277 
278 M0_INTERNAL int ut_io_req_fop_fini(void)
279 {
282 
283  return 0;
284 }
285 
287  .ts_name = "io-req-fop-ut",
288  .ts_init = ut_io_req_fop_init,
289  .ts_fini = ut_io_req_fop_fini,
290  .ts_tests = {
291 
292  { "ioreq_fop_invariant",
294  { "failure_vector_mismatch",
296  { "io_bottom_half",
298  { "io_rpc_item_cb",
300  { "client_passive_recv",
302  { "ioreq_fop_async_submit",
304  { "ioreq_fop_release",
306  { "ioreq_fop_init",
308  { "ioreq_fop_fini",
310  { "ioreq_pgiomap_find",
312  { "ioreq_fop_dgmode_read",
314  { NULL, NULL },
315  }
316 };
317 
318 #undef M0_TRACE_SUBSYSTEM
319 
320 /*
321  * Local variables:
322  * c-indentation-style: "K&R"
323  * c-basic-offset: 8
324  * tab-width: 8
325  * fill-column: 80
326  * scroll-step: 1
327  * End:
328  */
329 
void * fd_data
Definition: fop.h:75
void ut_layout_domain_empty(struct m0_client *cinst)
Definition: obj.c:218
static void io_bottom_half(struct m0_sm_group *grp, struct m0_sm_ast *ast)
Definition: io_req_fop.c:246
static void ut_test_ioreq_fop_release(void)
Definition: io_req_fop.c:144
#define NULL
Definition: misc.h:38
map
Definition: processor.c:112
void(* sa_cb)(struct m0_sm_group *grp, struct m0_sm_ast *)
Definition: sm.h:506
static struct m0_sm_group * grp
Definition: bytecount.c:38
struct m0_io_fop irf_iofop
Definition: pg.h:866
static uint32_t ut_sa_cb_executed
Definition: io_req_fop.c:72
M0_INTERNAL void ut_dummy_target_ioreq_delete(struct target_ioreq *ti)
Definition: io_dummy.c:552
M0_INTERNAL int ut_io_req_fop_fini(void)
Definition: io_req_fop.c:278
static struct m0_client * dummy_instance
Definition: io_req_fop.c:45
Definition: sm.h:504
void ut_layout_domain_fill(struct m0_client *cinst)
Definition: obj.c:208
Definition: ut.h:77
M0_INTERNAL int ut_m0_client_init(struct m0_client **instance)
Definition: client.c:265
static struct m0_rpc_item * item
Definition: item.c:56
static struct m0_pdclust_layout * dummy_pdclust_layout
Definition: io.c:50
M0_INTERNAL int ut_io_req_fop_init(void)
Definition: io_req_fop.c:256
struct m0_sm ioo_sm
static struct m0_sm_ast ast[NR]
Definition: locality.c:44
static void ut_test_ioreq_fop_fini(void)
Definition: io_req_fop.c:217
static void ut_test_ioreq_fop_invariant(void)
Definition: io_req_fop.c:50
M0_INTERNAL void m0_sm_group_unlock(struct m0_sm_group *grp)
Definition: sm.c:96
static void ut_test_ioreq_fop_init(void)
Definition: io_req_fop.c:179
static void ioreq_fop_release(struct m0_ref *ref)
Definition: io_req_fop.c:886
static void ut_test_io_bottom_half(void)
Definition: io_req_fop.c:68
M0_INTERNAL bool ioreq_fop_invariant(const struct ioreq_fop *fop)
Definition: io_req_fop.c:62
struct nw_xfer_request ioo_nwxfer
void m0_ref_init(struct m0_ref *ref, int init_num, void(*release)(struct m0_ref *ref))
Definition: refs.c:24
struct m0_fop if_fop
Definition: io_fops.h:174
Definition: refs.h:34
M0_INTERNAL void ut_dummy_ioo_delete(struct m0_op_io *ioo, struct m0_client *instance)
Definition: io_dummy.c:463
M0_INTERNAL void ut_dummy_ioreq_fop_delete(struct ioreq_fop *fop)
Definition: io_dummy.c:526
M0_INTERNAL void ut_m0_client_fini(struct m0_client **instance)
Definition: client.c:354
M0_INTERNAL struct target_ioreq * ut_dummy_target_ioreq_create(void)
Definition: io_dummy.c:532
M0_INTERNAL struct ioreq_fop * ut_dummy_ioreq_fop_create(void)
Definition: io_dummy.c:512
struct m0_rpc_item * ri_reply
Definition: item.h:163
struct m0_sm_group * sm_grp
Definition: sm.h:321
M0_INTERNAL void m0_mutex_init(struct m0_mutex *mutex)
Definition: mutex.c:35
M0_INTERNAL void ut_shuffle_test_order(struct m0_ut_suite *suite)
Definition: client.c:1205
struct m0_sm_ast irf_ast
Definition: pg.h:872
static void ut_test_ioreq_pgiomap_find(void)
Definition: io_req_fop.c:232
struct m0_ut_suite ut_suite_io_req_fop
Definition: io_req_fop.c:44
const char * ts_name
Definition: ut.h:99
struct m0_fop_data f_data
Definition: fop.h:82
M0_INTERNAL int64_t m0_ref_read(const struct m0_ref *ref)
Definition: refs.c:44
M0_INTERNAL struct m0_pdclust_layout * ut_dummy_pdclust_layout_create(struct m0_client *instance)
Definition: io_dummy.c:79
struct target_ioreq * irf_tioreq
Definition: pg.h:881
M0_INTERNAL struct m0_op_io * ut_dummy_ioo_create(struct m0_client *instance, int num_io_maps)
Definition: io_dummy.c:366
struct m0_ref f_ref
Definition: fop.h:80
static void ut_test_ioreq_fop_dgmode_read(void)
Definition: io_req_fop.c:252
static void ut_test_client_passive_recv(void)
Definition: io_req_fop.c:133
static void ioreq_pgiomap_find(struct m0_op_io *ioo, uint64_t grpid, uint64_t *cursor, struct pargrp_iomap **out)
Definition: io_req_fop.c:718
#define M0_ALLOC_PTR(ptr)
Definition: memory.h:86
const struct m0_rpc_item_ops * ri_ops
Definition: item.h:149
struct m0_mutex nxr_lock
static void ut_mock_rpc_item_sa_cb(struct m0_sm_group *grp, struct m0_sm_ast *ast)
Definition: io_req_fop.c:73
M0_INTERNAL int ioreq_fop_init(struct ioreq_fop *fop, struct target_ioreq *ti, enum page_attr pattr)
Definition: io_req_fop.c:977
static void ut_test_ioreq_fop_async_submit(void)
Definition: io_req_fop.c:137
static struct m0_fop * fop
Definition: item.c:57
static struct m0 instance
Definition: main.c:78
M0_INTERNAL void m0_sm_group_lock(struct m0_sm_group *grp)
Definition: sm.c:83
static void ut_test_failure_vector_mismatch(void)
Definition: io_req_fop.c:64
struct nw_xfer_request * ti_nwxfer
M0_INTERNAL void m0_client_init_io_op(void)
Definition: io.c:815
Definition: pg.h:859
M0_INTERNAL void ioreq_fop_fini(struct ioreq_fop *fop)
Definition: io_req_fop.c:1036
void m0_free(void *data)
Definition: memory.c:146
static const struct m0_rpc_item_ops item_ops
Definition: io_req_fop.c:563
struct m0_rpc_item f_item
Definition: fop.h:83
uint32_t sm_state
Definition: sm.h:307
static void io_rpc_item_cb(struct m0_rpc_item *item)
Definition: io_req_fop.c:419
int32_t rc
Definition: trigger_fop.h:47
#define M0_UT_ASSERT(a)
Definition: ut.h:46
Definition: fop.h:79
static void ut_test_io_rpc_item_cb(void)
Definition: io_req_fop.c:87
struct m0_fop * rep_fop
Definition: dir.c:334
static void ut_mock_rpc_item_release(struct m0_ref *ref)
Definition: io_req_fop.c:79