Motr  M0
session_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 #define M0_TRACE_SUBSYSTEM M0_TRACE_SUBSYS_RPC
24 #include "lib/trace.h"
25 #include "lib/errno.h"
26 #include "lib/memory.h"
27 #include "net/net.h" /* m0_net_end_point_get */
28 #include "fop/fom.h"
29 #include "fop/fop.h"
30 #include "fop/fop_item_type.h"
31 #include "rpc/rpc_internal.h"
32 
44  .sd_name = "m0_rpc_fom_sess_conn_term_phases init",
46  .sd_flags = M0_SDF_INITIAL
47  },
49  .sd_name = "m0_rpc_fom_sess_conn_term_phases wait",
52  },
54  .sd_name = "m0_rpc_fom_sess_conn_term_phases done",
55  .sd_flags = M0_SDF_TERMINAL
56  }
57 };
58 
60  .scf_name = "rpc_fom_session_terminate fom",
63 };
64 
65 static void conn_establish_fop_release(struct m0_ref *ref)
66 {
68  struct m0_fop *fop;
69 
70  fop = container_of(ref, struct m0_fop, f_ref);
73  if (ctx->cec_sender_ep != NULL)
74  /* For all conn-establish items a reference to sender_ep
75  is taken during m0_rpc_fop_conn_establish_ctx_init()
76  */
77  m0_net_end_point_put(ctx->cec_sender_ep);
78  m0_free(ctx);
79 }
80 
81 static int conn_establish_item_decode(const struct m0_rpc_item_type *item_type,
82  struct m0_rpc_item **item,
83  struct m0_bufvec_cursor *cur)
84 {
86  struct m0_fop *fop;
87  int rc;
88 
89  M0_ENTRY("item_opcode: %u", item_type->rit_opcode);
90  M0_PRE(item_type != NULL && item != NULL && cur != NULL);
92 
93  *item = NULL;
94 
96  if (ctx == NULL)
97  return M0_ERR(-ENOMEM);
98 
99  ctx->cec_sender_ep = NULL;
100  fop = &ctx->cec_fop;
101 
108 
110  *item = &fop->f_item;
111 
112  return M0_RC(rc);
113 }
114 
117  .rito_decode = conn_establish_item_decode,
118 };
119 
128 
129 M0_INTERNAL void m0_rpc_session_fop_fini(void)
130 {
139 }
140 
146 
147 M0_INTERNAL int m0_rpc_session_fop_init(void)
148 {
150  .name = "Rpc conn establish",
152  .xt = m0_rpc_fop_conn_establish_xc,
153  .rpc_flags = M0_RPC_MUTABO_REQ,
156  .sm = &m0_generic_conf,
157  .svc_type = &m0_rpc_service_type);
159  .name = "Rpc conn terminate",
161  .xt = m0_rpc_fop_conn_terminate_xc,
162  .rpc_flags = M0_RPC_MUTABO_REQ,
165  .svc_type = &m0_rpc_service_type);
167  .name = "Rpc session establish",
169  .xt = m0_rpc_fop_session_establish_xc,
170  .rpc_flags = M0_RPC_MUTABO_REQ,
172  .sm = &m0_generic_conf,
173  .svc_type = &m0_rpc_service_type);
175  .name = "Rpc session terminate",
177  .xt = m0_rpc_fop_session_terminate_xc,
178  .rpc_flags = M0_RPC_MUTABO_REQ,
181  .svc_type = &m0_rpc_service_type);
183  .name = "Rpc conn establish reply",
185  .xt = m0_rpc_fop_conn_establish_rep_xc,
186  .rpc_flags = M0_RPC_ITEM_TYPE_REPLY,
187  .svc_type = &m0_rpc_service_type);
189  .name = "Rpc conn terminate reply",
191  .xt = m0_rpc_fop_conn_terminate_rep_xc,
192  .rpc_flags = M0_RPC_ITEM_TYPE_REPLY,
193  .svc_type = &m0_rpc_service_type);
195  .name = "Rpc session establish reply",
197  .xt = m0_rpc_fop_session_establish_rep_xc,
198  .rpc_flags = M0_RPC_ITEM_TYPE_REPLY,
199  .svc_type = &m0_rpc_service_type);
201  .name = "Rpc session terminate reply",
203  .xt = m0_rpc_fop_session_terminate_rep_xc,
204  .rpc_flags = M0_RPC_ITEM_TYPE_REPLY,
205  .svc_type = &m0_rpc_service_type);
206  return 0;
207 }
208 
210  struct m0_net_end_point *ep)
211 {
213 
214  M0_ENTRY("item: %p, ep_addr: %s", item, (char *)ep->nep_addr);
215  M0_PRE(item != NULL && ep != NULL);
216 
218  cec_fop.f_item);
219  /* This reference will be dropped when the item is getting freed i.e.
220  conn_establish_fop_release()
221  */
223  ctx->cec_sender_ep = ep;
224  M0_LEAVE();
225 }
226 
228 /*
229  * Local variables:
230  * c-indentation-style: "K&R"
231  * c-basic-offset: 8
232  * tab-width: 8
233  * fill-column: 80
234  * scroll-step: 1
235  * End:
236  */
uint32_t rit_opcode
Definition: item.h:474
#define M0_PRE(cond)
struct m0_fop_type m0_rpc_fop_session_terminate_rep_fopt
Definition: session_fops.c:127
#define NULL
Definition: misc.h:38
static void conn_establish_fop_release(struct m0_ref *ref)
Definition: session_fops.c:65
static struct buffer * cur(struct m0_addb2_mach *mach, m0_bcount_t space)
Definition: addb2.c:791
#define M0_FOP_TYPE_INIT(ft,...)
Definition: fop.h:307
Definition: sm.h:350
M0_INTERNAL void m0_fop_init(struct m0_fop *fop, struct m0_fop_type *fopt, void *data, void(*fop_release)(struct m0_ref *))
Definition: fop.c:79
M0_LEAVE()
struct m0_fom_type_ops m0_rpc_fom_session_establish_type_ops
Definition: session_foms.c:314
struct m0_fop_type m0_rpc_fop_session_establish_rep_fopt
Definition: session_fops.c:125
M0_INTERNAL int m0_rpc_session_fop_init(void)
Definition: session_fops.c:147
void m0_fop_type_fini(struct m0_fop_type *fopt)
Definition: fop.c:232
M0_INTERNAL void m0_rpc_session_fop_fini(void)
Definition: session_fops.c:129
struct m0_fom_type_ops m0_rpc_fom_session_terminate_type_ops
Definition: session_foms.c:432
#define M0_BITS(...)
Definition: misc.h:236
#define container_of(ptr, type, member)
Definition: misc.h:33
static struct m0_xcode_type ** xt[]
Definition: protocol.c:64
const struct m0_sm_conf m0_generic_conf
Definition: fom_generic.c:838
static struct m0_rpc_item * item
Definition: item.c:56
return M0_RC(rc)
Definition: sock.c:754
#define M0_ENTRY(...)
Definition: trace.h:170
int opcode
Definition: crate.c:301
static const struct m0_reqh_service_ops rpc_ops
Definition: service.c:92
return M0_ERR(-EOPNOTSUPP)
const char * name
Definition: trace.c:110
Definition: refs.h:34
const char * scf_name
Definition: sm.h:352
M0_INTERNAL void m0_rpc_fop_conn_establish_ctx_init(struct m0_rpc_item *item, struct m0_net_end_point *ep)
Definition: session_fops.c:209
struct m0_fom_type_ops m0_rpc_fom_conn_establish_type_ops
Definition: session_foms.c:163
struct m0_fom_type_ops m0_rpc_fom_conn_terminate_type_ops
Definition: session_foms.c:554
static struct m0_rpc_item_type_ops conn_establish_item_type_ops
Definition: session_fops.c:115
M0_INTERNAL const struct m0_sm_conf m0_rpc_fom_sess_conn_term_phases_sm_conf
Definition: session_fops.c:59
static int conn_establish_item_decode(const struct m0_rpc_item_type *item_type, struct m0_rpc_item **item, struct m0_bufvec_cursor *cur)
Definition: session_fops.c:81
struct m0_reqh_service_type m0_rpc_service_type
Definition: service.c:120
M0_INTERNAL void m0_net_end_point_get(struct m0_net_end_point *ep)
Definition: ep.c:88
M0_INTERNAL void m0_fop_fini(struct m0_fop *fop)
Definition: fop.c:136
static struct fdmi_ctx ctx
Definition: main.c:80
void m0_net_end_point_put(struct m0_net_end_point *ep)
Definition: ep.c:98
M0_INTERNAL int m0_fop_item_encdec(struct m0_rpc_item *item, struct m0_bufvec_cursor *cur, enum m0_xcode_what what)
Definition: fop_item_type.c:95
const char * sd_name
Definition: sm.h:383
struct m0_fop_type m0_rpc_fop_conn_terminate_fopt
Definition: session_fops.c:122
struct m0_fop_type m0_rpc_fop_session_establish_fopt
Definition: session_fops.c:124
char * ep
Definition: sw.h:132
struct m0_fop_type m0_rpc_fop_conn_establish_rep_fopt
Definition: session_fops.c:121
struct m0_ref f_ref
Definition: fop.h:80
#define M0_ALLOC_PTR(ptr)
Definition: memory.h:86
static struct m0_fop * fop
Definition: item.c:57
static struct m0_sm_state_descr m0_rpc_fom_sess_conn_term_phases[]
Definition: session_fops.c:42
Definition: nucleus.c:42
struct m0_fop_type m0_rpc_fop_session_terminate_fopt
Definition: session_fops.c:126
void m0_free(void *data)
Definition: memory.c:146
struct m0_rpc_item f_item
Definition: fop.h:83
struct m0_fop_type m0_rpc_fop_conn_establish_fopt
Definition: session_fops.c:120
int32_t rc
Definition: trigger_fop.h:47
#define ARRAY_SIZE(a)
Definition: misc.h:45
#define M0_FOP_DEFAULT_ITEM_TYPE_OPS
Definition: fop.h:184
Definition: fop.h:79
struct m0_fop_type m0_rpc_fop_conn_terminate_rep_fopt
Definition: session_fops.c:123