Motr  M0
cs_fop.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 "lib/errno.h"
24 #include "lib/assert.h"
25 #include "lib/memory.h"
26 #include "lib/chan.h"
27 #include "lib/finject.h"
28 #include "lib/time.h"
29 #include "lib/misc.h" /* M0_IN() */
30 #include "fop/fop.h"
31 #include "fop/fom.h"
32 #include "fop/fom_generic.h"
33 
34 #include "rpc/rpc.h"
35 #include "rpc/rpclib.h"
36 #include "fop/fop_item_type.h"
37 
38 #include "ut/cs_fop.h"
39 #include "ut/cs_fop_xc.h"
40 #include "rpc/rpc_opcodes.h"
41 
42 static void cs_ut_rpc_item_reply_cb(struct m0_rpc_item *item);
43 
44 /*
45  RPC item operations structures.
46  */
49 };
50 
55 
56 /*
57  Fom specific routines for corresponding fops.
58  */
59 static int cs_req_fop_fom_tick(struct m0_fom *fom);
60 static int cs_ds1_req_fop_fom_create(struct m0_fop *fop, struct m0_fom **out,
61  struct m0_reqh *reqh);
62 static int cs_ds2_req_fop_fom_create(struct m0_fop *fop, struct m0_fom **out,
63  struct m0_reqh *reqh);
64 static void cs_ut_fom_fini(struct m0_fom *fom);
65 static size_t cs_ut_find_fom_home_locality(const struct m0_fom *fom);
66 
67 /*
68  Operation structures for ds1 service foms.
69  */
70 static const struct m0_fom_ops cs_ds1_req_fop_fom_ops = {
72  .fo_tick = cs_req_fop_fom_tick,
73  .fo_home_locality = cs_ut_find_fom_home_locality
74 };
75 
76 /*
77  Operation structures for ds2 service foms.
78  */
79 static const struct m0_fom_ops cs_ds2_req_fop_fom_ops = {
81  .fo_tick = cs_req_fop_fom_tick,
82  .fo_home_locality = cs_ut_find_fom_home_locality
83 };
84 
87 
88 enum ds_phases {
91 };
92 
93 /*
94  Fom type operations for ds1 service foms.
95  */
98 };
99 
100 /*
101  Fom type operations for ds2 service foms.
102  */
105 };
106 
108 {
109  struct m0_fop *reply;
110 
111  M0_PRE(item != NULL);
114 
115  if (m0_rpc_item_error(item) == 0) {
119  }
120 }
121 
123 {
126  m0_xc_ut_cs_fop_fini();
127 }
128 
130 {
131  /*
132  * As we are finalising and initialising fop types multiple times per
133  * service for various m0d commands, So reinitialise fop_type_format for
134  * each corresponding service fop types.
135  */
136  m0_xc_ut_cs_fop_init();
138  .name = "ds1 request",
140  .xt = cs_ds1_req_fop_xc,
141  .rpc_flags = M0_RPC_MUTABO_REQ,
142  .fom_ops = &cs_ds1_req_fop_fom_type_ops,
143  .sm = &m0_generic_conf,
144  .svc_type = &ds1_service_type);
146  .name = "ds1 reply",
148  .xt = cs_ds1_rep_fop_xc,
149  .rpc_flags = M0_RPC_ITEM_TYPE_REPLY,
150  .fom_ops = &cs_ds1_req_fop_fom_type_ops);
151  return 0;
152 }
153 
155 {
158  m0_xc_ut_cs_fop_fini();
159 }
160 
162 {
163  /*
164  As we are finalising and initialising fop types multiple times
165  per service for various m0d commands, So reinitialise
166  fop_type_format for each corresponding service fop types.
167  */
168  m0_xc_ut_cs_fop_init();
170  .name = "ds2 request",
172  .xt = cs_ds2_req_fop_xc,
173  .rpc_flags = M0_RPC_ITEM_TYPE_REQUEST,
174  .fom_ops = &cs_ds2_req_fop_fom_type_ops,
175  .sm = &m0_generic_conf,
176  .svc_type = &ds2_service_type);
178  .name = "ds2 reply",
180  .xt = cs_ds2_rep_fop_xc,
181  .rpc_flags = M0_RPC_ITEM_TYPE_REPLY,
182  .fom_ops = &cs_ds2_req_fop_fom_type_ops);
183  return 0;
184 }
185 
186 void m0_ut_fom_phase_set(struct m0_fom *fom, int phase)
187 {
188  switch (m0_fom_phase(fom)) {
189  case M0_FOPH_SUCCESS:
191  /* fall through */
192  case M0_FOPH_FAILURE:
195  /* fall through */
196  default:
197  if (m0_fom_phase(fom) != phase)
198  m0_fom_phase_set(fom, phase);
199  }
200 }
201 
202 /*
203  Allocates and initialises a fom.
204  */
206  const struct m0_fom_ops *ops,
207  struct m0_fom **out, struct m0_reqh *reqh)
208 {
209  struct m0_fom *fom;
210  struct m0_fop *rfop;
211 
212  M0_PRE(fop != NULL);
213  M0_PRE(ops != NULL);
214  M0_PRE(out != NULL);
217 
218  M0_ALLOC_PTR(fom);
219  if (fom == NULL)
220  return -ENOMEM;
221 
225  if (rfop == NULL) {
226  m0_free(fom);
227  return -ENOMEM;
228  }
230 
231  *out = fom;
232  return 0;
233 }
234 
235 static int cs_ds1_req_fop_fom_create(struct m0_fop *fop, struct m0_fom **out,
236  struct m0_reqh *reqh)
237 {
239  reqh);
240 }
241 
242 static int cs_ds2_req_fop_fom_create(struct m0_fop *fop, struct m0_fom **out,
243  struct m0_reqh *reqh)
244 {
246  reqh);
247 }
248 
249 /*
250  Finalises a fom.
251  */
252 static void cs_ut_fom_fini(struct m0_fom *fom)
253 {
254  M0_PRE(fom != NULL);
255 
256  m0_fom_fini(fom);
257  m0_free(fom);
258 }
259 
260 /*
261  Returns an index value base on fom parameters to locate fom's
262  home locality to execute a fom.
263  */
264 static size_t cs_ut_find_fom_home_locality(const struct m0_fom *fom)
265 {
266  M0_PRE(fom != NULL);
267 
268  return m0_fop_opcode(fom->fo_fop);
269 }
270 
271 /*
272  Transitions fom through its generic phases and also
273  performs corresponding fop specific execution.
274  */
275 static int cs_req_fop_fom_tick(struct m0_fom *fom)
276 {
277  int rc;
278  struct cs_ds1_req_fop *ds1_reqfop;
279  struct cs_ds1_rep_fop *ds1_repfop;
280  struct cs_ds2_req_fop *ds2_reqfop;
281  struct cs_ds2_rep_fop *ds2_repfop;
282  uint64_t opcode;
283 
284  M0_PRE(M0_IN(m0_fop_opcode(fom->fo_fop), (M0_CS_DS1_REQ_OPCODE,
286  if (m0_fom_phase(fom) < M0_FOPH_NR) {
288  } else {
289  opcode = m0_fop_opcode(fom->fo_fop);
290  switch (opcode) {
292  ds1_reqfop = m0_fop_data(fom->fo_fop);
293  ds1_repfop = m0_fop_data(fom->fo_rep_fop);
294  ds1_repfop->csr_rc = ds1_reqfop->csr_value;
296  rc = M0_FSO_AGAIN;
297  break;
299  ds2_reqfop = m0_fop_data(fom->fo_fop);
300  ds2_repfop = m0_fop_data(fom->fo_rep_fop);
301  ds2_repfop->csr_rc = ds2_reqfop->csr_value;
303  rc = M0_FSO_AGAIN;
304  break;
305  default:
306  M0_ASSERT("Invalid fop" == 0);
307  rc = 0;
308  break;
309  }
310  }
311  if (M0_FI_ENABLED("inject_delay"))
313 
314  return rc;
315 }
316 
317 /*
318  * Local variables:
319  * c-indentation-style: "K&R"
320  * c-basic-offset: 8
321  * tab-width: 8
322  * fill-column: 80
323  * scroll-step: 1
324  * End:
325  */
uint32_t m0_fop_opcode(const struct m0_fop *fop)
Definition: fop.c:226
#define M0_PRE(cond)
static void cs_ut_fom_fini(struct m0_fom *fom)
Definition: cs_fop.c:252
static const struct m0_fom_ops cs_ds2_req_fop_fom_ops
Definition: cs_fop.c:79
void m0_cs_ut_ds1_fop_fini(void)
Definition: cs_fop.c:122
#define NULL
Definition: misc.h:38
#define M0_FOP_TYPE_INIT(ft,...)
Definition: fop.h:307
int m0_cs_ut_ds2_fop_init(void)
Definition: cs_fop.c:161
static const struct m0_fom_type_ops cs_ds1_req_fop_fom_type_ops
Definition: cs_fop.c:96
int(* fto_create)(struct m0_fop *fop, struct m0_fom **out, struct m0_reqh *reqh)
Definition: fom.h:650
struct m0_reqh_service_type ds1_service_type
Definition: cs_service.c:60
static int cs_ds_req_fop_fom_create(struct m0_fop *fop, const struct m0_fom_ops *ops, struct m0_fom **out, struct m0_reqh *reqh)
Definition: cs_fop.c:205
int32_t csr_rc
Definition: cs_fop.h:82
void * m0_fop_data(const struct m0_fop *fop)
Definition: fop.c:220
void m0_fop_type_fini(struct m0_fop_type *fopt)
Definition: fop.c:232
int32_t csr_rc
Definition: cs_fop.h:90
struct m0_fop_type cs_ds1_rep_fop_fopt
Definition: cs_fop.c:52
static struct m0_xcode_type ** xt[]
Definition: protocol.c:64
m0_time_t m0_time(uint64_t secs, long ns)
Definition: time.c:41
const struct m0_sm_conf m0_generic_conf
Definition: fom_generic.c:838
static struct m0_rpc_item * item
Definition: item.c:56
m0_fom_phase
Definition: fom.h:372
struct m0_fom_type ft_fom_type
Definition: fop.h:232
static int cs_ds1_req_fop_fom_create(struct m0_fop *fop, struct m0_fom **out, struct m0_reqh *reqh)
Definition: cs_fop.c:235
int opcode
Definition: crate.c:301
void m0_fom_init(struct m0_fom *fom, const struct m0_fom_type *fom_type, const struct m0_fom_ops *ops, struct m0_fop *fop, struct m0_fop *reply, struct m0_reqh *reqh)
Definition: fom.c:1372
ds_phases
Definition: cs_fop.c:88
static const struct m0_fom_type_ops cs_ds2_req_fop_fom_type_ops
Definition: cs_fop.c:103
struct m0_fop_type * f_type
Definition: fop.h:81
static int cs_ds2_req_fop_fom_create(struct m0_fop *fop, struct m0_fom **out, struct m0_reqh *reqh)
Definition: cs_fop.c:242
const char * name
Definition: trace.c:110
const struct m0_rpc_item_ops cs_ds_req_fop_rpc_item_ops
Definition: cs_fop.c:47
int m0_fom_tick_generic(struct m0_fom *fom)
Definition: fom_generic.c:848
struct m0_fop_type cs_ds2_rep_fop_fopt
Definition: cs_fop.c:54
void m0_fom_fini(struct m0_fom *fom)
Definition: fom.c:1324
#define M0_ASSERT(cond)
struct m0_reqh_service_type ds2_service_type
Definition: cs_service.c:66
static void cs_ut_rpc_item_reply_cb(struct m0_rpc_item *item)
Definition: cs_fop.c:107
static const struct m0_fom_ops cs_ds1_req_fop_fom_ops
Definition: cs_fop.c:70
int m0_cs_ut_ds1_fop_init(void)
Definition: cs_fop.c:129
void m0_cs_ut_ds2_fop_fini(void)
Definition: cs_fop.c:154
struct m0_rpc_item * ri_reply
Definition: item.h:163
Definition: reqh.h:94
Definition: dump.c:103
struct m0_fop_type cs_ds2_req_fop_fopt
Definition: cs_fop.c:53
struct m0_fop_type cs_ds1_req_fop_fopt
Definition: cs_fop.c:51
struct m0_fop * m0_fop_reply_alloc(struct m0_fop *req, struct m0_fop_type *rept)
Definition: fop.c:129
void(* rio_replied)(struct m0_rpc_item *item)
Definition: item.h:300
Definition: fom.h:481
int32_t m0_rpc_item_error(const struct m0_rpc_item *item)
Definition: item.c:973
static size_t cs_ut_find_fom_home_locality(const struct m0_fom *fom)
Definition: cs_fop.c:264
struct m0_reqh reqh
Definition: rm_foms.c:48
#define M0_FI_ENABLED(tag)
Definition: finject.h:231
#define M0_ALLOC_PTR(ptr)
Definition: memory.h:86
void m0_ut_fom_phase_set(struct m0_fom *fom, int phase)
Definition: cs_fop.c:186
uint64_t csr_value
Definition: cs_fop.h:86
uint64_t csr_value
Definition: cs_fop.h:78
static struct m0_fop * fop
Definition: item.c:57
struct m0_fop * m0_rpc_item_to_fop(const struct m0_rpc_item *item)
Definition: fop.c:346
void(* fo_fini)(struct m0_fom *fom)
Definition: fom.h:657
#define out(...)
Definition: gen.c:41
void m0_fom_phase_set(struct m0_fom *fom, int phase)
Definition: fom.c:1688
struct m0_fom_ops ops
Definition: io_foms.c:623
static struct m0_dtm_oper_descr reply
Definition: transmit.c:94
void m0_free(void *data)
Definition: memory.c:146
static int cs_req_fop_fom_tick(struct m0_fom *fom)
Definition: cs_fop.c:275
int32_t rc
Definition: trigger_fop.h:47
Definition: fop.h:79
int m0_nanosleep(const m0_time_t req, m0_time_t *rem)
Definition: ktime.c:73