Motr  M0
op.h
Go to the documentation of this file.
1 /* -*- C -*- */
2 /*
3  * Copyright (c) 2013-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_BE_OP_H__
26 #define __MOTR_BE_OP_H__
27 
28 #include "lib/buf.h" /* m0_buf */
29 #include "lib/tlist.h" /* m0_tl */
30 #include "lib/types.h" /* bool */
31 #include "lib/mutex.h" /* m0_mutex */
32 
33 #include "sm/sm.h" /* m0_sm */
34 
49 struct m0_fom;
50 struct m0_be_tx;
51 struct m0_be_btree;
52 struct m0_be_btree_anchor;
53 struct m0_be_op;
54 
65 };
66 
70 };
71 
72 typedef void (*m0_be_op_cb_t)(struct m0_be_op *op, void *param);
73 
74 struct m0_be_op {
75  struct m0_sm bo_sm;
76  struct m0_fom *bo_fom;
78  int bo_rc;
81  /*
82  * Workaround.
83  *
84  * In the future sm group for m0_be_op should be taken
85  * from m0_locality_here().
86  *
87  * @see MOTR-787 comments for the reference.
88  */
90 
91  enum m0_be_op_type bo_utype; /* bo_u type */
92  union {
93  struct m0_be_op__btree {
95  struct m0_be_tx *t_tx;
96  /* XXX to be defined in btree.c */
97  unsigned int t_op;
98  const struct m0_buf *t_in;
99  struct m0_buf t_out_val;
102  int t_rc;
103  } u_btree;
104 
105  struct {
106  int e_rc;
107  } u_emap;
108  } bo_u;
109 
118  /* is this op an op_set */
120 
127 };
128 
129 M0_INTERNAL void m0_be_op_init(struct m0_be_op *op);
130 M0_INTERNAL void m0_be_op_fini(struct m0_be_op *op);
131 
132 M0_INTERNAL void m0_be_op_lock(struct m0_be_op *op);
133 M0_INTERNAL void m0_be_op_unlock(struct m0_be_op *op);
134 M0_INTERNAL bool m0_be_op_is_locked(const struct m0_be_op *op);
135 
136 /*
137  * Moves internal sm to M0_BOS_INIT state and resets
138  * parent-child op_set relationship.
139  */
140 M0_INTERNAL void m0_be_op_reset(struct m0_be_op *op);
141 
143 M0_INTERNAL void m0_be_op_active(struct m0_be_op *op);
144 
146 M0_INTERNAL void m0_be_op_done(struct m0_be_op *op);
147 
149 M0_INTERNAL bool m0_be_op_is_done(struct m0_be_op *op);
150 
151 M0_INTERNAL void m0_be_op_callback_set(struct m0_be_op *op,
152  m0_be_op_cb_t cb,
153  void *param,
154  enum m0_be_op_state state);
155 
161 M0_INTERNAL void m0_be_op_wait(struct m0_be_op *op);
162 
168 M0_INTERNAL int m0_be_op_tick_ret(struct m0_be_op *op,
169  struct m0_fom *fom,
170  int next_state);
171 
175 M0_INTERNAL void m0_be_op_set_add(struct m0_be_op *parent,
176  struct m0_be_op *child);
177 
178 M0_INTERNAL void m0_be_op_rc_set(struct m0_be_op *op, int rc);
179 M0_INTERNAL int m0_be_op_rc(struct m0_be_op *op);
180 
190 #define M0_BE_OP_SYNC(op_obj, action) \
191  ({ \
192  struct m0_be_op op_obj = {}; \
193  M0_BE_OP_SYNC_WITH(&op_obj, action); \
194  })
195 
196 #define M0_BE_OP_SYNC_RC(op_obj, action) \
197  ({ \
198  struct m0_be_op op_obj = {}; \
199  M0_BE_OP_SYNC_WITH_RC(&op_obj, action); \
200  })
201 
202 
207 #define M0_BE_OP_SYNC_WITH(op, action) \
208  ({ \
209  struct m0_be_op *__opp = (op); \
210  \
211  m0_be_op_init(__opp); \
212  action; \
213  m0_be_op_wait(__opp); \
214  m0_be_op_fini(__opp); \
215  })
216 
217 #define M0_BE_OP_SYNC_WITH_RC(op, action) \
218  ({ \
219  struct m0_be_op *__opp = (op); \
220  int __op_rc; \
221  \
222  m0_be_op_init(__opp); \
223  action; \
224  m0_be_op_wait(__opp); \
225  __op_rc = m0_be_op_rc(__opp); \
226  m0_be_op_fini(__opp); \
227  __op_rc; \
228  })
229 
230 
243 #define M0_BE_OP_SYNC_RET(op_obj, action, member) \
244  ({ \
245  struct m0_be_op op_obj = {}; \
246  M0_BE_OP_SYNC_RET_WITH(&op_obj, action, member); \
247  })
248 
253 #define M0_BE_OP_SYNC_RET_WITH(op, action, member) \
254  ({ \
255  struct m0_be_op *__opp = (op); \
256  typeof(__opp->member) __result; \
257  \
258  m0_be_op_init(__opp); \
259  action; \
260  m0_be_op_wait(__opp); \
261  __result = __opp->member; \
262  m0_be_op_fini(__opp); \
263  __result; \
264  })
265 
267 #endif /* __MOTR_BE_OP_H__ */
268 
269 /*
270  * Local variables:
271  * c-indentation-style: "K&R"
272  * c-basic-offset: 8
273  * tab-width: 8
274  * fill-column: 80
275  * scroll-step: 1
276  * End:
277  */
278 /*
279  * vim: tabstop=8 shiftwidth=8 noexpandtab textwidth=80 nowrap
280  */
M0_INTERNAL int m0_be_op_rc(struct m0_be_op *op)
Definition: op.c:324
int bo_rc
Definition: op.h:78
struct m0_be_op::@39::m0_be_op__btree u_btree
m0_be_op_cb_t bo_cb_done
Definition: op.h:123
m0_be_op_cb_t bo_cb_gc
Definition: op.h:125
void * bo_cb_gc_param
Definition: op.h:126
struct m0_fom * bo_fom
Definition: op.h:76
bool bo_is_op_set
Definition: op.h:119
M0_INTERNAL void m0_be_op_unlock(struct m0_be_op *op)
Definition: op.c:120
struct m0_buf t_out_key
Definition: op.h:100
void(* m0_be_op_cb_t)(struct m0_be_op *op, void *param)
Definition: op.h:72
M0_INTERNAL void m0_be_op_callback_set(struct m0_be_op *op, m0_be_op_cb_t cb, void *param, enum m0_be_op_state state)
Definition: op.c:239
struct m0_sm_group bo_sm_group
Definition: op.h:89
M0_INTERNAL void m0_be_op_rc_set(struct m0_be_op *op, int rc)
Definition: op.c:314
struct m0_be_op * bo_parent
Definition: op.h:117
struct m0_tl bo_children
Definition: op.h:111
struct m0_be_btree * t_tree
Definition: op.h:94
op
Definition: libdemo.c:64
Definition: buf.h:37
m0_be_op_type
Definition: op.h:67
int t_rc
Definition: op.h:102
Definition: tlist.h:251
int e_rc
Definition: op.h:106
struct m0_be_op::@39::@40 u_emap
unsigned int t_op
Definition: op.h:97
m0_be_op_state
Definition: op.h:55
M0_INTERNAL void m0_be_op_done(struct m0_be_op *op)
Definition: stubs.c:104
Definition: dump.c:103
struct m0_tlink bo_set_link
Definition: op.h:113
struct m0_be_tx * t_tx
Definition: op.h:95
struct m0_buf t_out_val
Definition: op.h:99
Definition: fom.h:481
M0_INTERNAL void m0_be_op_reset(struct m0_be_op *op)
Definition: op.c:152
M0_INTERNAL void m0_be_op_active(struct m0_be_op *op)
Definition: stubs.c:100
M0_INTERNAL int m0_be_op_tick_ret(struct m0_be_op *op, struct m0_fom *fom, int next_state)
Definition: op.c:267
Definition: op.h:64
Definition: op.h:69
uint64_t bo_set_link_magic
Definition: op.h:115
m0_be_op_cb_t bo_cb_active
Definition: op.h:121
void * bo_cb_active_param
Definition: op.h:122
Definition: sm.h:301
M0_INTERNAL void m0_be_op_fini(struct m0_be_op *op)
Definition: stubs.c:92
M0_INTERNAL void m0_be_op_set_add(struct m0_be_op *parent, struct m0_be_op *child)
Definition: op.c:297
struct m0_be_btree_anchor * t_anchor
Definition: op.h:101
union m0_be_op::@39 bo_u
M0_INTERNAL bool m0_be_op_is_locked(const struct m0_be_op *op)
Definition: op.c:125
void * bo_cb_done_param
Definition: op.h:124
enum m0_be_op_type bo_utype
Definition: op.h:91
Definition: op.h:59
Definition: op.h:74
M0_INTERNAL void m0_be_op_init(struct m0_be_op *op)
Definition: stubs.c:87
Definition: op.h:57
struct m0_sm bo_sm
Definition: op.h:75
bool bo_rc_is_set
Definition: op.h:80
int32_t rc
Definition: trigger_fop.h:47
M0_INTERNAL bool m0_be_op_is_done(struct m0_be_op *op)
Definition: stubs.c:108
M0_INTERNAL void m0_be_op_lock(struct m0_be_op *op)
Definition: op.c:115
M0_INTERNAL void m0_be_op_wait(struct m0_be_op *op)
Definition: stubs.c:96
Definition: op.h:68
Definition: tx.h:280
const struct m0_buf * t_in
Definition: op.h:98