Motr  M0
fop.h
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 #pragma once
24 
25 #ifndef __MOTR_FOP_FOP_H__
26 #define __MOTR_FOP_FOP_H__
27 
28 #include "lib/types.h"
29 #include "lib/list.h"
30 #include "lib/refs.h"
31 #include "lib/errno.h"
32 #include "fol/fol.h"
33 #include "fop/fom.h"
34 #include "fop/wire.h"
35 #include "rpc/item.h"
36 #include "net/net_otw_types.h"
37 
60 /* import */
61 struct m0_fol;
62 struct m0_db_tx;
63 struct m0_xcode_type;
64 
65 /* export */
66 struct m0_fop_data;
67 struct m0_fop;
68 struct m0_fop_fol_frag;
69 
75 struct m0_fop_data {
76  void *fd_data;
77 };
78 
80 struct m0_fop {
81  struct m0_ref f_ref;
85  void *f_opaque;
86 };
87 
104 M0_INTERNAL void m0_fop_init(struct m0_fop *fop, struct m0_fop_type *fopt,
105  void *data, void (*fop_release)(struct m0_ref *));
106 
120 M0_INTERNAL void m0_fop_fini(struct m0_fop *fop);
121 
126 struct m0_fop *m0_fop_get(struct m0_fop *fop);
127 
134 void m0_fop_put(struct m0_fop *fop);
135 void m0_fop_put0(struct m0_fop *fop);
136 
140 void m0_fop_put_lock(struct m0_fop *fop);
141 void m0_fop_put0_lock(struct m0_fop *fop);
142 
153 struct m0_fop *m0_fop_alloc(struct m0_fop_type *fopt, void *data,
154  struct m0_rpc_machine *mach);
155 struct m0_fop *m0_fop_alloc_at(struct m0_rpc_session *sess,
156  struct m0_fop_type *fopt);
157 struct m0_fop *m0_fop_reply_alloc(struct m0_fop *req,
158  struct m0_fop_type *fopt);
159 
164 M0_INTERNAL void m0_fop_release(struct m0_ref *ref);
165 void *m0_fop_data(const struct m0_fop *fop);
166 
170 M0_INTERNAL int m0_fop_data_alloc(struct m0_fop *fop);
171 
172 struct m0_rpc_item *m0_fop_to_rpc_item(const struct m0_fop *fop);
173 struct m0_fop *m0_rpc_item_to_fop(const struct m0_rpc_item *item);
174 void m0_fop_rpc_machine_set(struct m0_fop *fop, struct m0_rpc_machine *mach);
175 struct m0_rpc_machine *m0_fop_rpc_machine(const struct m0_fop *fop);
176 uint32_t m0_fop_opcode(const struct m0_fop *fop);
177 M0_INTERNAL const char *m0_fop_name(const struct m0_fop *fop);
178 struct m0_net_transfer_mc *m0_fop_tm_get(const struct m0_fop *fop);
179 struct m0_net_domain *m0_fop_domain_get(const struct m0_fop *fop);
180 
182 M0_INTERNAL struct m0_fop_type *m0_item_type_to_fop_type
183  (const struct m0_rpc_item_type *rit);
184 
185 #define M0_FOP_DEFAULT_ITEM_TYPE_OPS \
186  .rito_encode = m0_fop_item_type_default_encode, \
187  .rito_decode = m0_fop_item_type_default_decode, \
188  .rito_payload_size = m0_fop_payload_size, \
189  .rito_item_get = m0_fop_item_get, \
190  .rito_item_put = m0_fop_item_put
191 
193 
224 struct m0_fop_type {
226  const char *ft_name;
229  const struct m0_fop_type_ops *ft_ops;
231  const struct m0_xcode_type *ft_xt;
237  uint64_t ft_magix;
238 };
239 
256 M0_INTERNAL struct m0_fop_type *m0_fop_type_next(struct m0_fop_type *ftype);
257 
263 M0_INTERNAL struct m0_fop_type *m0_fop_type_find(uint32_t opcode);
264 
268  void (*fto_fop_replied)(struct m0_fop *fop, struct m0_fop *bfop);
270  int (*fto_io_coalesce)(struct m0_fop *fop, uint64_t rpc_size);
272  void (*fto_io_desc_get)(struct m0_fop *fop,
273  struct m0_net_buf_desc_data **desc);
274  int (*fto_undo)(struct m0_fop_fol_frag *ffrag, struct m0_fol *fol);
275  int (*fto_redo)(struct m0_fop_fol_frag *ffrag, struct m0_fol *fol);
276 };
277 
278 typedef uint32_t m0_fop_type_code_t;
279 
288  const char *name;
289  uint32_t opcode;
290  uint64_t rpc_flags;
291  const struct m0_xcode_type *xt;
292  const struct m0_fop_type_ops *fop_ops;
293  const struct m0_fom_type_ops *fom_ops;
295  const struct m0_sm_conf *sm;
297 };
298 
299 void m0_fop_type_init(struct m0_fop_type *ft,
300  const struct __m0_fop_type_init_args *args);
301 
308 #define M0_FOP_TYPE_INIT(ft, ...) \
309  m0_fop_type_init((ft), &(const struct __m0_fop_type_init_args) { \
310  __VA_ARGS__ });
311 
317 #define M0_FOP_TYPE_INIT2_DECL struct __m0_fop_type_init_args __args
318 #define M0_FOP_TYPE_INIT2(ft, ...) ({ \
319  __args = (struct __m0_fop_type_init_args) {__VA_ARGS__}; \
320  m0_fop_type_init((ft), &__args); })
321 
322 void m0_fop_type_fini(struct m0_fop_type *fopt);
323 
327 };
328 
329 M0_INTERNAL void m0_fop_type_init_nr(const struct m0_fop_type_batch *batch);
330 M0_INTERNAL void m0_fop_type_fini_nr(const struct m0_fop_type_batch *batch);
331 
332 M0_INTERNAL int m0_fops_init(void);
333 M0_INTERNAL void m0_fops_fini(void);
334 
335 #define M0_FOP_XCODE_OBJ(f) (struct m0_xcode_obj) { \
336  .xo_type = f->f_type->ft_xt, \
337  .xo_ptr = m0_fop_data(f), \
338 }
339 
340 M0_INTERNAL int m0_fop_encdec(struct m0_fop *fop,
341  struct m0_bufvec_cursor *cur,
342  enum m0_xcode_what what);
343 
344 M0_INTERNAL int m0_fop_xc_type(const struct m0_xcode_obj *par,
345  const struct m0_xcode_type **out);
346 
347 M0_INTERNAL int m0_fop_rep_xc_type(const struct m0_xcode_obj *par,
348  const struct m0_xcode_type **out);
349 
354 M0_INTERNAL int m0_fop_fol_add(struct m0_fop *fop, struct m0_fop *rep,
355  struct m0_dtx *dtx);
356 
358 
360 
370 };
371 
373 
375 
377 #endif /* __MOTR_FOP_FOP_H__ */
378 
379 /*
380  * Local variables:
381  * c-indentation-style: "K&R"
382  * c-basic-offset: 8
383  * tab-width: 8
384  * fill-column: 80
385  * scroll-step: 1
386  * End:
387  */
void * fd_data
Definition: fop.h:76
const struct m0_rpc_item_type_ops m0_fop_default_item_type_ops
Definition: fol.h:140
uint32_t m0_fop_opcode(const struct m0_fop *fop)
Definition: fop.c:225
Definition: dtm.h:554
static struct buffer * cur(struct m0_addb2_mach *mach, m0_bcount_t space)
Definition: addb2.c:791
Definition: sm.h:350
static struct io_request req
Definition: file.c:100
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:78
int(* fto_io_coalesce)(struct m0_fop *fop, uint64_t rpc_size)
Definition: fop.h:270
uint32_t opcode
Definition: fop.h:289
void fop_release(struct m0_ref *ref)
Definition: stats_ut_svc.c:148
const struct m0_xcode_type * ft_xt
Definition: fop.h:231
void m0_fop_type_addb2_deinstrument(struct m0_fop_type *type)
Definition: fop.c:492
struct m0_bufvec data
Definition: di.c:40
void * m0_fop_data(const struct m0_fop *fop)
Definition: fop.c:219
void m0_fop_type_fini(struct m0_fop_type *fopt)
Definition: fop.c:231
static struct m0_addb2_mach * mach
Definition: storage.c:42
uint64_t rpc_flags
Definition: fop.h:290
m0_xcode_what
Definition: xcode.h:647
Definition: ub.c:49
static struct m0_rpc_item * item
Definition: item.c:56
struct m0_fop_getxattr_rep * rep
Definition: dir.c:455
M0_INTERNAL struct m0_fop_type * m0_fop_type_next(struct m0_fop_type *ftype)
Definition: fop.c:295
struct m0_fol_frag_type m0_fop_fol_frag_type
M0_INTERNAL void m0_fops_fini(void)
Definition: fop.c:328
struct m0_fom_type ft_fom_type
Definition: fop.h:233
int opcode
Definition: crate.c:301
void m0_fop_put0_lock(struct m0_fop *fop)
Definition: fop.c:212
void m0_fop_rpc_machine_set(struct m0_fop *fop, struct m0_rpc_machine *mach)
Definition: fop.c:351
struct m0_fop_type * f_type
Definition: fop.h:82
struct m0_rpc_machine * m0_fop_rpc_machine(const struct m0_fop *fop)
Definition: fop.c:359
M0_INTERNAL const char * m0_fop_name(const struct m0_fop *fop)
Definition: fop.c:54
struct m0_tlink ft_linkage
Definition: fop.h:228
void(* fto_io_desc_get)(struct m0_fop *fop, struct m0_net_buf_desc_data **desc)
Definition: fop.h:272
M0_INTERNAL int m0_fop_fol_add(struct m0_fop *fop, struct m0_fop *rep, struct m0_dtx *dtx)
Definition: fop.c:426
struct __m0_fop_type_init_args tb_args
Definition: fop.h:326
Definition: refs.h:34
const char * ft_name
Definition: fop.h:226
M0_INTERNAL int m0_fop_rep_xc_type(const struct m0_xcode_obj *par, const struct m0_xcode_type **out)
Definition: fop.c:418
struct m0_rpc_machine * m0_fop_session_machine(const struct m0_rpc_session *s)
Definition: fop.c:452
m0_addb2_fop_counter
Definition: fop.h:361
struct m0_fop * m0_fop_get(struct m0_fop *fop)
Definition: fop.c:161
void * f_opaque
Definition: fop.h:85
M0_INTERNAL struct m0_fop_type * m0_item_type_to_fop_type(const struct m0_rpc_item_type *item_type)
Definition: fop.c:368
M0_INTERNAL int m0_fop_data_alloc(struct m0_fop *fop)
Definition: fop.c:70
M0_INTERNAL void m0_fop_fini(struct m0_fop *fop)
Definition: fop.c:135
M0_INTERNAL int m0_fops_init(void)
Definition: fop.c:314
M0_INTERNAL int m0_fop_xc_type(const struct m0_xcode_obj *par, const struct m0_xcode_type **out)
Definition: fop.c:410
uint32_t m0_fop_type_code_t
Definition: fop.h:278
M0_INTERNAL struct m0_fop_type * m0_fop_type_find(uint32_t opcode)
Definition: fop.c:387
struct m0_fop * m0_fop_reply_alloc(struct m0_fop *req, struct m0_fop_type *rept)
Definition: fop.c:128
const struct m0_rpc_item_type_ops * rpc_ops
Definition: fop.h:294
struct m0_fop_data f_data
Definition: fop.h:83
void m0_fop_type_init(struct m0_fop_type *ft, const struct __m0_fop_type_init_args *args)
Definition: fop.c:246
int(* fto_redo)(struct m0_fop_fol_frag *ffrag, struct m0_fol *fol)
Definition: fop.h:275
struct m0_ref f_ref
Definition: fop.h:81
const struct m0_fom_type_ops * fom_ops
Definition: fop.h:293
M0_INTERNAL void m0_fop_release(struct m0_ref *ref)
Definition: fop.c:147
void m0_fop_put0(struct m0_fop *fop)
Definition: fop.c:191
struct m0_net_domain * m0_fop_domain_get(const struct m0_fop *fop)
Definition: fop.c:485
const struct m0_reqh_service_type * svc_type
Definition: fop.h:296
int m0_fop_type_addb2_instrument(struct m0_fop_type *type)
Definition: fop.c:460
const struct m0_fop_type_ops * ft_ops
Definition: fop.h:229
struct m0_rpc_item * m0_fop_to_rpc_item(const struct m0_fop *fop)
Definition: fop.c:337
struct m0_fop * m0_fop_alloc_at(struct m0_rpc_session *sess, struct m0_fop_type *fopt)
Definition: fop.c:121
M0_INTERNAL void m0_fop_type_init_nr(const struct m0_fop_type_batch *batch)
Definition: fop.c:281
void m0_fop_put_lock(struct m0_fop *fop)
Definition: fop.c:198
static struct m0_fop * fop
Definition: item.c:57
M0_INTERNAL int m0_fop_encdec(struct m0_fop *fop, struct m0_bufvec_cursor *cur, enum m0_xcode_what what)
Definition: fop.c:374
struct m0_rpc_item_type ft_rpc_item_type
Definition: fop.h:236
struct m0_fop * m0_rpc_item_to_fop(const struct m0_rpc_item *item)
Definition: fop.c:345
void(* fto_fop_replied)(struct m0_fop *fop, struct m0_fop *bfop)
Definition: fop.h:268
static struct m0_fop_type * ft[]
Definition: service_ut.c:857
#define out(...)
Definition: gen.c:41
int type
Definition: dir.c:1031
struct m0_fop_type * tb_type
Definition: fop.h:325
static struct m0_addb2_source * s
Definition: consumer.c:39
void m0_fop_put(struct m0_fop *fop)
Definition: fop.c:176
uint64_t ft_magix
Definition: fop.h:237
struct m0_rpc_item f_item
Definition: fop.h:84
const struct m0_xcode_type * xt
Definition: fop.h:291
const char * name
Definition: fop.h:288
M0_INTERNAL void m0_fop_type_fini_nr(const struct m0_fop_type_batch *batch)
Definition: fop.c:287
int(* fto_undo)(struct m0_fop_fol_frag *ffrag, struct m0_fol *fol)
Definition: fop.h:274
struct m0_net_transfer_mc * m0_fop_tm_get(const struct m0_fop *fop)
Definition: fop.c:478
const struct m0_sm_conf * sm
Definition: fop.h:295
Definition: fop.h:80
struct m0_fop * m0_fop_alloc(struct m0_fop_type *fopt, void *data, struct m0_rpc_machine *mach)
Definition: fop.c:95
const struct m0_fop_type_ops * fop_ops
Definition: fop.h:292