Motr  M0
fol.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_FOL_FOL_H__
26 #define __MOTR_FOL_FOL_H__
27 
89 /* export */
90 struct m0_fol;
91 struct m0_fol_rec;
92 
93 /* import */
94 #include "lib/types.h" /* uint64_t */
95 #include "lib/arith.h" /* M0_IS_8ALIGNED */
96 #include "lib/mutex.h"
97 #include "lib/tlist.h"
98 #include "fid/fid.h"
99 #include "be/tx_credit.h"
100 #include "dtm/dtm_update.h" /* m0_update_id, m0_epoch_id */
101 #include "fid/fid_xc.h"
102 #include "dtm/dtm_update_xc.h"
103 #include "fdmi/src_rec.h" /* m0_fdmi_src_rec */
104 
105 struct m0_be_tx;
106 struct m0_epoch_id;
107 
108 enum {
109  /*
110  * The maximum possible length of fol record.
111  *
112  * We need to obtain sufficient BE credit before adding new record
113  * to the fol. Fol records are of variable length and the actual
114  * length is hard, if possible, to calculate at the moment of
115  * m0_fol_credit() call. We use the empirical value of maximum
116  * possible record length instead.
117  *
118  * XXX REVISEME: If the value is not sufficient, increase it.
119  * Alternative (proper?) solution is to calculate the size of fol
120  * record as a function of rpc opcode.
121  */
122  /* FOL_REC_MAXSIZE = 1024 * 1024 */
123 
124  /* EN: Previous size is too big to fit into one RPC message */
125  FOL_REC_MAXSIZE = 1024 * 256
126 };
127 
140 struct m0_fol {
142  struct m0_mutex f_lock;
143 };
144 
148 M0_INTERNAL void m0_fol_init(struct m0_fol *fol);
149 M0_INTERNAL void m0_fol_fini(struct m0_fol *fol);
150 
158  uint32_t rh_frags_nr;
164  uint32_t rh_data_len;
172  uint64_t rh_lsn;
178  uint64_t rh_magic;
179 } M0_XCA_RECORD;
180 
182 
189 struct m0_fol_rec {
190  struct m0_fol *fr_fol;
191  uint64_t fr_tid;
194  struct m0_epoch_id *fr_epoch;
196  struct m0_fol_update_ref *fr_sibling;
201  struct m0_tl fr_frags;
204 };
205 
212 M0_INTERNAL void m0_fol_rec_init(struct m0_fol_rec *rec, struct m0_fol *fol);
213 
215 M0_INTERNAL void m0_fol_rec_fini(struct m0_fol_rec *rec);
216 
222 M0_INTERNAL int m0_fol_rec_encode(struct m0_fol_rec *rec, struct m0_buf *at);
223 
233 M0_INTERNAL int m0_fol_rec_decode(struct m0_fol_rec *rec, struct m0_buf *at);
234 
235 int m0_fol_rec_to_str(struct m0_fol_rec *rec, char *str, int str_len);
236 
237 M0_INTERNAL bool m0_fol_rec_invariant(const struct m0_fol_rec *drec);
238 
239 M0_INTERNAL int m0_fols_init(void);
240 M0_INTERNAL void m0_fols_fini(void);
241 
243 struct m0_fol_frag {
244  const struct m0_fol_frag_ops *rp_ops;
249  void *rp_data;
253  uint64_t rp_magic;
259 };
260 
262  uint32_t rpt_index;
263  const char *rpt_name;
269  const struct m0_xcode_type *rpt_xt;
271 };
272 
275  void (*rpto_rec_frag_init)(struct m0_fol_frag *frag);
276 };
277 
283  const struct m0_fol_frag_type *rpo_type;
284  int (*rpo_undo)(struct m0_fol_frag *frag, struct m0_be_tx *tx);
285  int (*rpo_redo)(struct m0_fol_frag *frag, struct m0_be_tx *tx);
286  void (*rpo_undo_credit)(const struct m0_fol_frag *frag,
287  struct m0_be_tx_credit *accum);
288  void (*rpo_redo_credit)(const struct m0_fol_frag *frag,
289  struct m0_be_tx_credit *accum);
290 };
291 
293  uint32_t rph_index;
294  uint64_t rph_magic;
295 } M0_XCA_RECORD;
296 
304 M0_INTERNAL void
305 m0_fol_frag_init(struct m0_fol_frag *frag, void *data,
306  const struct m0_fol_frag_type *type);
307 
308 M0_INTERNAL void m0_fol_frag_fini(struct m0_fol_frag *frag);
309 
311 M0_INTERNAL int
313 
314 M0_INTERNAL void
316 
318 M0_TL_DESCR_DECLARE(m0_rec_frag, M0_EXTERN);
319 M0_TL_DECLARE(m0_rec_frag, M0_INTERNAL, struct m0_fol_frag);
320 
321 M0_INTERNAL void m0_fol_frag_add(struct m0_fol_rec *rec,
322  struct m0_fol_frag *frag);
323 
324 #define M0_FOL_FRAG_TYPE_DECLARE(frag, scope, undo, redo, \
325  undo_cred, redo_cred) \
326 scope struct m0_fol_frag_type frag ## _type; \
327 static const struct m0_fol_frag_ops frag ## _ops = { \
328  .rpo_type = &frag ## _type, \
329  .rpo_undo = undo, \
330  .rpo_redo = redo, \
331  .rpo_undo_credit = undo_cred, \
332  .rpo_redo_credit = redo_cred, \
333 }; \
334 static void frag ## _ops_init(struct m0_fol_frag *frag) \
335 { \
336  frag->rp_ops = &frag ## _ops; \
337 } \
338 static const struct m0_fol_frag_type_ops frag ## _type_ops = { \
339  .rpto_rec_frag_init = frag ##_ops_init \
340 };
341 
342 #define M0_FOL_FRAG_TYPE_XC_OPS(name, frag_xc, frag_type_ops) \
343 (struct m0_fol_frag_type) { \
344  .rpt_name = name, \
345  .rpt_xt = (frag_xc), \
346  .rpt_ops = (frag_type_ops) \
347 };
348 
349 #define M0_FOL_FRAG_TYPE_INIT(frag, name) \
350 frag ## _type = M0_FOL_FRAG_TYPE_XC_OPS(name, frag ## _xc, \
351  &frag ## _type_ops)
352 
354 #endif /* __MOTR_FOL_FOL_H__ */
355 
356 /*
357  * Local variables:
358  * c-indentation-style: "K&R"
359  * c-basic-offset: 8
360  * tab-width: 8
361  * fill-column: 80
362  * scroll-step: 1
363  * End:
364  */
struct m0_fol * fr_fol
Definition: fol.h:190
int(* rpo_redo)(struct m0_fol_frag *frag, struct m0_be_tx *tx)
Definition: fol.h:285
Definition: fol.h:140
M0_INTERNAL void m0_fol_fini(struct m0_fol *fol)
Definition: fol.c:89
struct m0_fol_rec_header fr_header
Definition: fol.h:192
int(* rpo_undo)(struct m0_fol_frag *frag, struct m0_be_tx *tx)
Definition: fol.h:284
M0_INTERNAL void m0_fol_rec_fini(struct m0_fol_rec *rec)
Definition: fol.c:104
const struct m0_fol_frag_ops * rp_ops
Definition: fol.h:244
struct m0_tlink rp_link
Definition: fol.h:251
M0_INTERNAL int m0_fol_frag_type_register(struct m0_fol_frag_type *type)
Definition: fol.c:178
M0_TL_DECLARE(m0_rec_frag, M0_INTERNAL, struct m0_fol_frag)
M0_INTERNAL void m0_fol_frag_init(struct m0_fol_frag *frag, void *data, const struct m0_fol_frag_type *type)
Definition: fol.c:121
struct m0_bufvec data
Definition: di.c:40
struct m0_mutex f_lock
Definition: fol.h:142
struct m0_tl fr_frags
Definition: fol.h:201
struct m0_update_id rh_self
Definition: fol.h:170
uint32_t rpt_index
Definition: fol.h:262
void(* rpo_undo_credit)(const struct m0_fol_frag *frag, struct m0_be_tx_credit *accum)
Definition: fol.h:286
void * rp_data
Definition: fol.h:249
m0_xcode_what
Definition: xcode.h:647
const char * rpt_name
Definition: fol.h:263
const struct m0_fol_frag_type * rpo_type
Definition: fol.h:283
M0_INTERNAL void m0_fols_fini(void)
Definition: fol.c:172
const struct m0_fol_frag_type_ops * rpt_ops
Definition: fol.h:270
Definition: buf.h:37
M0_INTERNAL void m0_fol_rec_init(struct m0_fol_rec *rec, struct m0_fol *fol)
Definition: fol.c:98
int m0_fol_rec_to_str(struct m0_fol_rec *rec, char *str, int str_len)
Definition: fol.c:380
const struct m0_xcode_type * rpt_xt
Definition: fol.h:269
uint64_t rh_magic
Definition: fol.h:178
Definition: tlist.h:251
uint64_t fr_tid
Definition: fol.h:191
M0_INTERNAL void m0_fol_init(struct m0_fol *fol)
Definition: fol.c:84
struct m0_fdmi_src_rec fr_fdmi_rec
Definition: fol.h:203
M0_BASSERT(M0_IS_8ALIGNED(sizeof(struct m0_fol_rec_header)))
struct m0_epoch_id * fr_epoch
Definition: fol.h:194
M0_INTERNAL bool m0_fol_rec_invariant(const struct m0_fol_rec *rec)
Definition: fol.c:114
uint64_t rph_magic
Definition: fol.h:294
uint64_t rh_lsn_discarded
Definition: fol.h:177
M0_TL_DESCR_DECLARE(m0_rec_frag, M0_EXTERN)
uint64_t rh_lsn
Definition: fol.h:172
static bool at(struct ff2c_context *ctx, char c)
Definition: lex.c:77
struct m0_fol_update_ref * fr_sibling
Definition: fol.h:196
M0_INTERNAL void m0_fol_frag_fini(struct m0_fol_frag *frag)
Definition: fol.c:132
M0_INTERNAL int m0_fols_init(void)
Definition: fol.c:166
uint32_t rh_frags_nr
Definition: fol.h:158
enum m0_xcode_what rp_flag
Definition: fol.h:258
uint32_t rph_index
Definition: fol.h:293
M0_INTERNAL void m0_fol_frag_add(struct m0_fol_rec *rec, struct m0_fol_frag *frag)
Definition: fol.c:468
uint32_t rh_data_len
Definition: fol.h:164
M0_INTERNAL void m0_fol_frag_type_deregister(struct m0_fol_frag_type *type)
Definition: fol.c:201
#define M0_IS_8ALIGNED(val)
Definition: arith.h:190
uint64_t rp_magic
Definition: fol.h:253
int type
Definition: dir.c:1031
void(* rpto_rec_frag_init)(struct m0_fol_frag *frag)
Definition: fol.h:275
Definition: mutex.h:47
void(* rpo_redo_credit)(const struct m0_fol_frag *frag, struct m0_be_tx_credit *accum)
Definition: fol.h:288
M0_INTERNAL int m0_fol_rec_encode(struct m0_fol_rec *rec, struct m0_buf *at)
Definition: fol.c:314
Definition: tx.h:280
M0_INTERNAL int m0_fol_rec_decode(struct m0_fol_rec *rec, struct m0_buf *at)
Definition: fol.c:331