Motr  M0
drlink.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 
28 #define M0_TRACE_SUBSYSTEM M0_TRACE_SUBSYS_UT
29 #include "lib/trace.h"
30 
31 #include "dtm0/drlink.h"
32 
33 #include "ut/ut.h" /* M0_UT_ASSERT */
34 #include "fid/fid.h" /* M0_FID_INIT */
35 #include "be/queue.h" /* m0_be_queue_init */
36 
37 #include "dtm0/service.h" /* m0_dtm0_service */
38 #include "dtm0/fop.h" /* dtm0_req_fop */
39 
40 #include "dtm0/ut/helper.h" /* m0_ut_dtm0_helper_init */
41 
42 
43 enum {
45 };
46 
48 {
49  struct m0_ut_dtm0_helper *udh;
50  struct m0_dtm0_service *svc;
51  struct m0_fom fom = {}; // just a fom for m0_dtm0_req_post()
52  struct m0_dtm0_tx_pa pa = {};
53  struct dtm0_req_fop *fop;
54  struct m0_be_op *op;
55  struct m0_be_op op_out = {};
56  struct m0_fid *fid;
57  struct m0_fid fid_out;
58  bool successful;
59  bool found;
60  int rc;
61  int i;
62  int j;
63 
64  M0_ALLOC_PTR(udh);
65  M0_ASSERT(udh != NULL);
66 
69 
71  M0_UT_ASSERT(fid != NULL);
72  for (i = 0; i < DTM0_UT_DRLINK_SIMPLE_POST_NR; ++i) {
73  fid[i] = M0_FID_INIT(0, i+1); /* TODO set fid type */
74  }
76  M0_UT_ASSERT(fop != NULL);
77  for (i = 0; i < DTM0_UT_DRLINK_SIMPLE_POST_NR; ++i) {
78  fop[i] = (struct dtm0_req_fop){
79  .dtr_msg = DTM_TEST,
80  .dtr_txr = {
81  .dtd_id = {
82  .dti_fid = fid[i],
83  },
84  .dtd_ps = {
85  .dtp_nr = 1,
86  .dtp_pa = &pa,
87  },
88  },
89  };
90  }
92  M0_UT_ASSERT(op != NULL);
93  for (i = 0; i < DTM0_UT_DRLINK_SIMPLE_POST_NR; ++i)
94  m0_be_op_init(&op[i]);
95 
96  M0_ALLOC_PTR(svc->dos_ut_queue);
97  M0_UT_ASSERT(svc->dos_ut_queue != 0);
98  rc = m0_be_queue_init(svc->dos_ut_queue,
99  &(struct m0_be_queue_cfg){
100  .bqc_q_size_max = DTM0_UT_DRLINK_SIMPLE_POST_NR,
101  .bqc_producers_nr_max = DTM0_UT_DRLINK_SIMPLE_POST_NR,
102  .bqc_consumers_nr_max = 1,
103  .bqc_item_length = sizeof fid[0],
104  });
105  M0_UT_ASSERT(rc == 0);
106 
107  for (i = 0; i < DTM0_UT_DRLINK_SIMPLE_POST_NR; ++i) {
109  &op[i], &fop[i],
110  &udh->udh_client_dtm0_fid, &fom, true);
111  M0_UT_ASSERT(rc == 0);
112  }
113  m0_be_op_init(&op_out);
114  for (i = 0; i < DTM0_UT_DRLINK_SIMPLE_POST_NR; ++i) {
115  successful = false;
116  m0_be_queue_lock(svc->dos_ut_queue);
117  M0_BE_QUEUE_GET(svc->dos_ut_queue, &op_out, &fid_out,
118  &successful);
119  m0_be_queue_unlock(svc->dos_ut_queue);
120  m0_be_op_wait(&op_out);
121  M0_UT_ASSERT(successful);
122  m0_be_op_reset(&op_out);
123  found = false;
124  for (j = 0; j < DTM0_UT_DRLINK_SIMPLE_POST_NR; ++j) {
125  if (m0_fid_eq(&fid_out, &fid[j])) {
126  found = true;
127  fid[j] = M0_FID0;
128  break;
129  }
130  }
132  }
133  m0_be_op_fini(&op_out);
134  m0_be_queue_fini(svc->dos_ut_queue);
135  m0_free(svc->dos_ut_queue);
136  for (i = 0; i < DTM0_UT_DRLINK_SIMPLE_POST_NR; ++i)
138  m0_free(fid);
139  for (i = 0; i < DTM0_UT_DRLINK_SIMPLE_POST_NR; ++i) {
140  m0_be_op_wait(&op[i]);
141  m0_be_op_fini(&op[i]);
142  }
143  m0_free(op);
144  m0_free(fop);
145 
147  m0_free(udh);
148 
149 }
150 
151 
152 #undef M0_TRACE_SUBSYSTEM
153 
156 /*
157  * Local variables:
158  * c-indentation-style: "K&R"
159  * c-basic-offset: 8
160  * tab-width: 8
161  * fill-column: 80
162  * scroll-step: 1
163  * End:
164  */
165 /*
166  * vim: tabstop=8 shiftwidth=8 noexpandtab textwidth=80 nowrap
167  */
M0_INTERNAL void m0_ut_dtm0_helper_fini(struct m0_ut_dtm0_helper *udh)
Definition: helper.c:114
#define M0_ALLOC_ARR(arr, nr)
Definition: memory.h:84
#define NULL
Definition: misc.h:38
#define M0_BE_QUEUE_GET(bq, op, ptr, successful)
Definition: queue.h:238
#define M0_FID_INIT(container, key)
Definition: fid.h:84
struct m0_fid fid
Definition: di.c:46
op
Definition: libdemo.c:64
M0_INTERNAL int m0_be_queue_init(struct m0_be_queue *bq, struct m0_be_queue_cfg *cfg)
Definition: queue.c:94
int i
Definition: dir.c:1033
M0_INTERNAL void m0_be_queue_unlock(struct m0_be_queue *bq)
Definition: stubs.c:325
void m0_dtm0_ut_drlink_simple(void)
Definition: drlink.c:47
M0_INTERNAL void m0_be_queue_fini(struct m0_be_queue *bq)
Definition: queue.c:148
#define M0_ASSERT(cond)
Definition: dump.c:103
M0_INTERNAL bool m0_fid_eq(const struct m0_fid *fid0, const struct m0_fid *fid1)
Definition: fid.c:164
Definition: fom.h:481
M0_INTERNAL void m0_be_op_reset(struct m0_be_op *op)
Definition: op.c:152
Definition: fop.h:46
Definition: fid.h:38
#define M0_ALLOC_PTR(ptr)
Definition: memory.h:86
M0_INTERNAL void m0_ut_dtm0_helper_init(struct m0_ut_dtm0_helper *udh)
Definition: helper.c:64
static struct m0_net_test_service svc
Definition: service.c:34
M0_INTERNAL void m0_be_op_fini(struct m0_be_op *op)
Definition: stubs.c:92
static struct m0_fop * fop
Definition: item.c:57
M0_INTERNAL void m0_be_queue_lock(struct m0_be_queue *bq)
Definition: stubs.c:321
static uint64_t found
Definition: base.c:376
#define M0_FID0
Definition: fid.h:93
struct m0_fid udh_client_dtm0_fid
Definition: helper.h:54
Definition: op.h:74
M0_INTERNAL void m0_be_op_init(struct m0_be_op *op)
Definition: stubs.c:87
void m0_free(void *data)
Definition: memory.c:146
int32_t rc
Definition: trigger_fop.h:47
struct m0_dtm0_service * udh_client_dtm0_service
Definition: helper.h:56
#define M0_UT_ASSERT(a)
Definition: ut.h:46
struct m0_dtm0_service * udh_server_dtm0_service
Definition: helper.h:55
M0_INTERNAL void m0_be_op_wait(struct m0_be_op *op)
Definition: stubs.c:96