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 "rpc/item.h"
35 #include "net/net_otw_types.h"
36 
59 /* import */
60 struct m0_fol;
61 struct m0_db_tx;
62 struct m0_xcode_type;
63 
64 /* export */
65 struct m0_fop_data;
66 struct m0_fop;
67 struct m0_fop_fol_frag;
68 
74 struct m0_fop_data {
75  void *fd_data;
76 };
77 
79 struct m0_fop {
80  struct m0_ref f_ref;
84  void *f_opaque;
85 };
86 
103 M0_INTERNAL void m0_fop_init(struct m0_fop *fop, struct m0_fop_type *fopt,
104  void *data, void (*fop_release)(struct m0_ref *));
105 
119 M0_INTERNAL void m0_fop_fini(struct m0_fop *fop);
120 
125 struct m0_fop *m0_fop_get(struct m0_fop *fop);
126 
133 void m0_fop_put(struct m0_fop *fop);
134 void m0_fop_put0(struct m0_fop *fop);
135 
139 void m0_fop_put_lock(struct m0_fop *fop);
140 void m0_fop_put0_lock(struct m0_fop *fop);
141 
152 struct m0_fop *m0_fop_alloc(struct m0_fop_type *fopt, void *data,
153  struct m0_rpc_machine *mach);
154 struct m0_fop *m0_fop_alloc_at(struct m0_rpc_session *sess,
155  struct m0_fop_type *fopt);
156 struct m0_fop *m0_fop_reply_alloc(struct m0_fop *req,
157  struct m0_fop_type *fopt);
158 
163 M0_INTERNAL void m0_fop_release(struct m0_ref *ref);
164 void *m0_fop_data(const struct m0_fop *fop);
165 
169 M0_INTERNAL int m0_fop_data_alloc(struct m0_fop *fop);
170 
171 struct m0_rpc_item *m0_fop_to_rpc_item(const struct m0_fop *fop);
172 struct m0_fop *m0_rpc_item_to_fop(const struct m0_rpc_item *item);
173 void m0_fop_rpc_machine_set(struct m0_fop *fop, struct m0_rpc_machine *mach);
174 struct m0_rpc_machine *m0_fop_rpc_machine(const struct m0_fop *fop);
175 uint32_t m0_fop_opcode(const struct m0_fop *fop);
176 M0_INTERNAL const char *m0_fop_name(const struct m0_fop *fop);
177 struct m0_net_transfer_mc *m0_fop_tm_get(const struct m0_fop *fop);
178 struct m0_net_domain *m0_fop_domain_get(const struct m0_fop *fop);
179 
181 M0_INTERNAL struct m0_fop_type *m0_item_type_to_fop_type
182  (const struct m0_rpc_item_type *rit);
183 
184 #define M0_FOP_DEFAULT_ITEM_TYPE_OPS \
185  .rito_encode = m0_fop_item_type_default_encode, \
186  .rito_decode = m0_fop_item_type_default_decode, \
187  .rito_payload_size = m0_fop_payload_size, \
188  .rito_item_get = m0_fop_item_get, \
189  .rito_item_put = m0_fop_item_put
190 
192 
223 struct m0_fop_type {
225  const char *ft_name;
228  const struct m0_fop_type_ops *ft_ops;
230  const struct m0_xcode_type *ft_xt;
236  uint64_t ft_magix;
237 };
238 
255 M0_INTERNAL struct m0_fop_type *m0_fop_type_next(struct m0_fop_type *ftype);
256 
262 M0_INTERNAL struct m0_fop_type *m0_fop_type_find(uint32_t opcode);
263 
267  void (*fto_fop_replied)(struct m0_fop *fop, struct m0_fop *bfop);
269  int (*fto_io_coalesce)(struct m0_fop *fop, uint64_t rpc_size);
271  void (*fto_io_desc_get)(struct m0_fop *fop,
272  struct m0_net_buf_desc_data **desc);
273  int (*fto_undo)(struct m0_fop_fol_frag *ffrag, struct m0_fol *fol);
274  int (*fto_redo)(struct m0_fop_fol_frag *ffrag, struct m0_fol *fol);
275 };
276 
277 typedef uint32_t m0_fop_type_code_t;
278 
287  const char *name;
288  uint32_t opcode;
289  uint64_t rpc_flags;
290  const struct m0_xcode_type *xt;
291  const struct m0_fop_type_ops *fop_ops;
292  const struct m0_fom_type_ops *fom_ops;
294  const struct m0_sm_conf *sm;
296 };
297 
298 void m0_fop_type_init(struct m0_fop_type *ft,
299  const struct __m0_fop_type_init_args *args);
300 
307 #define M0_FOP_TYPE_INIT(ft, ...) \
308  m0_fop_type_init((ft), &(const struct __m0_fop_type_init_args) { \
309  __VA_ARGS__ });
310 
316 #define M0_FOP_TYPE_INIT2_DECL struct __m0_fop_type_init_args __args
317 #define M0_FOP_TYPE_INIT2(ft, ...) ({ \
318  __args = (struct __m0_fop_type_init_args) {__VA_ARGS__}; \
319  m0_fop_type_init((ft), &__args); })
320 
321 void m0_fop_type_fini(struct m0_fop_type *fopt);
322 
326 };
327 
328 M0_INTERNAL void m0_fop_type_init_nr(const struct m0_fop_type_batch *batch);
329 M0_INTERNAL void m0_fop_type_fini_nr(const struct m0_fop_type_batch *batch);
330 
331 M0_INTERNAL int m0_fops_init(void);
332 M0_INTERNAL void m0_fops_fini(void);
333 
334 #define M0_FOP_XCODE_OBJ(f) (struct m0_xcode_obj) { \
335  .xo_type = f->f_type->ft_xt, \
336  .xo_ptr = m0_fop_data(f), \
337 }
338 
339 M0_INTERNAL int m0_fop_encdec(struct m0_fop *fop,
340  struct m0_bufvec_cursor *cur,
341  enum m0_xcode_what what);
342 
343 M0_INTERNAL int m0_fop_xc_type(const struct m0_xcode_obj *par,
344  const struct m0_xcode_type **out);
345 
346 M0_INTERNAL int m0_fop_rep_xc_type(const struct m0_xcode_obj *par,
347  const struct m0_xcode_type **out);
348 
354  uint32_t ffrp_fop_code;
356  uint32_t ffrp_rep_code;
357  void *ffrp_fop M0_XCA_OPAQUE("m0_fop_xc_type");
358  void *ffrp_rep M0_XCA_OPAQUE("m0_fop_rep_xc_type");
359 } M0_XCA_RECORD;
360 
365 M0_INTERNAL int m0_fop_fol_add(struct m0_fop *fop, struct m0_fop *rep,
366  struct m0_dtx *dtx);
367 
369 
371 
381 };
382 
384 
386 
388 #endif /* __MOTR_FOP_FOP_H__ */
389 
390 /*
391  * Local variables:
392  * c-indentation-style: "K&R"
393  * c-basic-offset: 8
394  * tab-width: 8
395  * fill-column: 80
396  * scroll-step: 1
397  * End:
398  */
void * fd_data
Definition: fop.h:75
uint32_t ffrp_rep_code
Definition: fop.h:356
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:226
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:79
int(* fto_io_coalesce)(struct m0_fop *fop, uint64_t rpc_size)
Definition: fop.h:269
uint32_t opcode
Definition: fop.h:288
void fop_release(struct m0_ref *ref)
Definition: stats_ut_svc.c:148
const struct m0_xcode_type * ft_xt
Definition: fop.h:230
void m0_fop_type_addb2_deinstrument(struct m0_fop_type *type)
Definition: fop.c:493
struct m0_bufvec data
Definition: di.c:40
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_addb2_mach * mach
Definition: storage.c:42
uint64_t rpc_flags
Definition: fop.h:289
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:296
struct m0_fol_frag_type m0_fop_fol_frag_type
M0_INTERNAL void m0_fops_fini(void)
Definition: fop.c:329
struct m0_fom_type ft_fom_type
Definition: fop.h:232
int opcode
Definition: crate.c:301
void m0_fop_put0_lock(struct m0_fop *fop)
Definition: fop.c:213
void m0_fop_rpc_machine_set(struct m0_fop *fop, struct m0_rpc_machine *mach)
Definition: fop.c:352
struct m0_fop_type * f_type
Definition: fop.h:81
struct m0_rpc_machine * m0_fop_rpc_machine(const struct m0_fop *fop)
Definition: fop.c:360
M0_INTERNAL const char * m0_fop_name(const struct m0_fop *fop)
Definition: fop.c:55
struct m0_tlink ft_linkage
Definition: fop.h:227
void(* fto_io_desc_get)(struct m0_fop *fop, struct m0_net_buf_desc_data **desc)
Definition: fop.h:271
M0_INTERNAL int m0_fop_fol_add(struct m0_fop *fop, struct m0_fop *rep, struct m0_dtx *dtx)
Definition: fop.c:427
struct __m0_fop_type_init_args tb_args
Definition: fop.h:325
Definition: refs.h:34
const char * ft_name
Definition: fop.h:225
M0_INTERNAL int m0_fop_rep_xc_type(const struct m0_xcode_obj *par, const struct m0_xcode_type **out)
Definition: fop.c:419
struct m0_rpc_machine * m0_fop_session_machine(const struct m0_rpc_session *s)
Definition: fop.c:453
m0_addb2_fop_counter
Definition: fop.h:372
struct m0_fop * m0_fop_get(struct m0_fop *fop)
Definition: fop.c:162
void * f_opaque
Definition: fop.h:84
M0_INTERNAL struct m0_fop_type * m0_item_type_to_fop_type(const struct m0_rpc_item_type *item_type)
Definition: fop.c:369
M0_INTERNAL int m0_fop_data_alloc(struct m0_fop *fop)
Definition: fop.c:71
M0_INTERNAL void m0_fop_fini(struct m0_fop *fop)
Definition: fop.c:136
M0_INTERNAL int m0_fops_init(void)
Definition: fop.c:315
M0_INTERNAL int m0_fop_xc_type(const struct m0_xcode_obj *par, const struct m0_xcode_type **out)
Definition: fop.c:411
uint32_t m0_fop_type_code_t
Definition: fop.h:277
M0_INTERNAL struct m0_fop_type * m0_fop_type_find(uint32_t opcode)
Definition: fop.c:388
struct m0_fop * m0_fop_reply_alloc(struct m0_fop *req, struct m0_fop_type *rept)
Definition: fop.c:129
const struct m0_rpc_item_type_ops * rpc_ops
Definition: fop.h:293
struct m0_fop_data f_data
Definition: fop.h:82
void m0_fop_type_init(struct m0_fop_type *ft, const struct __m0_fop_type_init_args *args)
Definition: fop.c:247
int(* fto_redo)(struct m0_fop_fol_frag *ffrag, struct m0_fol *fol)
Definition: fop.h:274
void *ffrp_fop M0_XCA_OPAQUE("m0_fop_xc_type")
struct m0_ref f_ref
Definition: fop.h:80
const struct m0_fom_type_ops * fom_ops
Definition: fop.h:292
M0_INTERNAL void m0_fop_release(struct m0_ref *ref)
Definition: fop.c:148
void m0_fop_put0(struct m0_fop *fop)
Definition: fop.c:192
struct m0_net_domain * m0_fop_domain_get(const struct m0_fop *fop)
Definition: fop.c:486
const struct m0_reqh_service_type * svc_type
Definition: fop.h:295
int m0_fop_type_addb2_instrument(struct m0_fop_type *type)
Definition: fop.c:461
const struct m0_fop_type_ops * ft_ops
Definition: fop.h:228
struct m0_rpc_item * m0_fop_to_rpc_item(const struct m0_fop *fop)
Definition: fop.c:338
struct m0_fop * m0_fop_alloc_at(struct m0_rpc_session *sess, struct m0_fop_type *fopt)
Definition: fop.c:122
M0_INTERNAL void m0_fop_type_init_nr(const struct m0_fop_type_batch *batch)
Definition: fop.c:282
void m0_fop_put_lock(struct m0_fop *fop)
Definition: fop.c:199
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:375
struct m0_rpc_item_type ft_rpc_item_type
Definition: fop.h:235
struct m0_fop * m0_rpc_item_to_fop(const struct m0_rpc_item *item)
Definition: fop.c:346
void(* fto_fop_replied)(struct m0_fop *fop, struct m0_fop *bfop)
Definition: fop.h:267
static struct m0_fop_type * ft[]
Definition: service_ut.c:856
#define out(...)
Definition: gen.c:41
int type
Definition: dir.c:1031
struct m0_fop_type * tb_type
Definition: fop.h:324
static struct m0_addb2_source * s
Definition: consumer.c:39
void m0_fop_put(struct m0_fop *fop)
Definition: fop.c:177
uint64_t ft_magix
Definition: fop.h:236
struct m0_rpc_item f_item
Definition: fop.h:83
const struct m0_xcode_type * xt
Definition: fop.h:290
const char * name
Definition: fop.h:287
M0_INTERNAL void m0_fop_type_fini_nr(const struct m0_fop_type_batch *batch)
Definition: fop.c:288
int(* fto_undo)(struct m0_fop_fol_frag *ffrag, struct m0_fol *fol)
Definition: fop.h:273
struct m0_net_transfer_mc * m0_fop_tm_get(const struct m0_fop *fop)
Definition: fop.c:479
const struct m0_sm_conf * sm
Definition: fop.h:294
Definition: fop.h:79
struct m0_fop * m0_fop_alloc(struct m0_fop_type *fopt, void *data, struct m0_rpc_machine *mach)
Definition: fop.c:96
const struct m0_fop_type_ops * fop_ops
Definition: fop.h:291
uint32_t ffrp_fop_code
Definition: fop.h:354