Motr  M0
fops.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/memory.h" /* M0_ALLOC_PTR */
24 #include "lib/ub.h" /* M0_UB_ASSERT */
25 #include "fop/fop.h" /* m0_fop_type */
26 #include "fop/fom.h" /* m0_fom_ops */
27 #include "fop/fom_generic.h" /* M0_FOPH_NR */
28 #include "rpc/rpc_opcodes.h" /* M0_RPC_UB_REQ_OPCODE */
29 #include "rpc/ub/fops.h" /* ub_req, ub_resp */
30 #include "rpc/ub/fops_xc.h" /* m0_xc_rpc_ub_fops_init */
31 #include "ut/cs_service.h" /* ds1_service_type */
32 
35 
36 /* ----------------------------------------------------------------
37  * RPC UB request FOM declarations
38  * ---------------------------------------------------------------- */
39 
40 static int ub_req_fom_create(struct m0_fop *fop, struct m0_fom **m,
41  struct m0_reqh *reqh);
42 static void ub_req_fom_fini(struct m0_fom *fom);
43 static int ub_req_fom_tick(struct m0_fom *fom);
44 static size_t ub_req_fom_home_locality(const struct m0_fom *fom);
45 
46 static const struct m0_fom_type_ops ub_req_fom_type_ops = {
48 };
49 
50 static const struct m0_fom_ops ub_req_fom_ops = {
52  .fo_tick = ub_req_fom_tick,
53  .fo_home_locality = ub_req_fom_home_locality,
54 };
55 
56 /* ----------------------------------------------------------------
57  * RPC UB request FOM definitions
58  * ---------------------------------------------------------------- */
59 
60 static int
61 ub_req_fom_create(struct m0_fop *fop, struct m0_fom **m, struct m0_reqh *reqh)
62 {
63  struct m0_fom *fom;
64 
66  M0_ASSERT(fom != NULL);
67 
69  fop, NULL, reqh);
70  *m = fom;
71  return 0;
72 }
73 
74 static void ub_req_fom_fini(struct m0_fom *fom)
75 {
77  m0_free(fom);
78 }
79 
80 static int ub_req_fom_tick(struct m0_fom *fom)
81 {
82  const struct ub_req *req;
83  struct ub_resp *resp;
84  int rc;
85 
87  return m0_fom_tick_generic(fom);
88 
89  M0_UB_ASSERT(fom->fo_rep_fop == NULL);
90  fom->fo_rep_fop = m0_fop_reply_alloc(fom->fo_fop, &m0_rpc_ub_resp_fopt);
91  M0_UB_ASSERT(fom->fo_rep_fop != NULL);
92 
93  req = m0_fop_data(fom->fo_fop);
94  resp = m0_fop_data(fom->fo_rep_fop);
95 
96  resp->ur_seqn = req->uq_seqn;
97  rc = m0_buf_copy(&resp->ur_data, &req->uq_data);
98  M0_UB_ASSERT(rc == 0);
99 
101  return M0_FSO_AGAIN;
102 }
103 
104 static size_t ub_req_fom_home_locality(const struct m0_fom *fom)
105 {
106  static size_t n = 0;
107  return n++;
108 }
109 
110 /* ----------------------------------------------------------------
111  * RPC UB FOPs initialization/finalization
112  * ---------------------------------------------------------------- */
113 
114 M0_INTERNAL void m0_rpc_ub_fops_init(void)
115 {
116  m0_xc_rpc_ub_fops_init();
117 
119  .name = "RPC UB request",
121  .xt = ub_req_xc,
122  .rpc_flags = M0_RPC_ITEM_TYPE_REQUEST,
123  .fom_ops = &ub_req_fom_type_ops,
124  .sm = &m0_generic_conf,
125  .svc_type = &ds1_service_type);
127  .name = "RPC UB response",
129  .xt = ub_resp_xc,
130  .rpc_flags = M0_RPC_ITEM_TYPE_REPLY);
131 }
132 
133 M0_INTERNAL void m0_rpc_ub_fops_fini(void)
134 {
137  m0_xc_rpc_ub_fops_fini();
138 }
139 
140 /*
141  * Local variables:
142  * c-indentation-style: "K&R"
143  * c-basic-offset: 8
144  * tab-width: 8
145  * fill-column: 80
146  * scroll-step: 1
147  * End:
148  */
static const struct m0_fom_type_ops ub_req_fom_type_ops
Definition: fops.c:46
#define NULL
Definition: misc.h:38
static struct m0_addb2_mach * m
Definition: consumer.c:38
static size_t ub_req_fom_home_locality(const struct m0_fom *fom)
Definition: fops.c:104
#define M0_UB_ASSERT(cond)
Definition: ub.h:37
#define M0_FOP_TYPE_INIT(ft,...)
Definition: fop.h:307
M0_INTERNAL void m0_rpc_ub_fops_init(void)
Definition: fops.c:114
static struct io_request req
Definition: file.c:100
struct m0_fop_type m0_rpc_ub_resp_fopt
Definition: fops.c:34
int(* fto_create)(struct m0_fop *fop, struct m0_fom **out, struct m0_reqh *reqh)
Definition: fom.h:650
Definition: fops.h:38
struct m0_reqh_service_type ds1_service_type
Definition: cs_service.c:60
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
static struct m0_xcode_type ** xt[]
Definition: protocol.c:64
const struct m0_sm_conf m0_generic_conf
Definition: fom_generic.c:838
Definition: fops.h:32
m0_fom_phase
Definition: fom.h:372
static int ub_req_fom_create(struct m0_fop *fop, struct m0_fom **m, struct m0_reqh *reqh)
Definition: fops.c:61
struct m0_fom_type ft_fom_type
Definition: fop.h:232
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
const char * name
Definition: trace.c:110
static void ub_req_fom_fini(struct m0_fom *fom)
Definition: fops.c:74
int m0_fom_tick_generic(struct m0_fom *fom)
Definition: fom_generic.c:848
void m0_fom_fini(struct m0_fom *fom)
Definition: fom.c:1324
#define M0_ASSERT(cond)
struct m0_buf ur_data
Definition: fops.h:41
void m0_fom_phase_move(struct m0_fom *fom, int32_t rc, int phase)
Definition: fom.c:1699
static const struct m0_fom_ops ub_req_fom_ops
Definition: fops.c:50
Definition: reqh.h:94
Definition: dump.c:103
uint64_t ur_seqn
Definition: fops.h:40
M0_INTERNAL int m0_buf_copy(struct m0_buf *dest, const struct m0_buf *src)
Definition: buf.c:104
struct m0_fop * m0_fop_reply_alloc(struct m0_fop *req, struct m0_fop_type *rept)
Definition: fop.c:129
Definition: fom.h:481
uint64_t n
Definition: fops.h:107
struct m0_reqh reqh
Definition: rm_foms.c:48
static int ub_req_fom_tick(struct m0_fom *fom)
Definition: fops.c:80
#define M0_ALLOC_PTR(ptr)
Definition: memory.h:86
struct m0_fop_type m0_rpc_ub_req_fopt
Definition: fops.c:33
static struct m0_fop * fop
Definition: item.c:57
void(* fo_fini)(struct m0_fom *fom)
Definition: fom.h:657
M0_INTERNAL void m0_rpc_ub_fops_fini(void)
Definition: fops.c:133
void m0_free(void *data)
Definition: memory.c:146
int32_t rc
Definition: trigger_fop.h:47
Definition: fop.h:79