Motr  M0
fmt.h
Go to the documentation of this file.
1 /* -*- C -*- */
2 /*
3  * Copyright (c) 2014-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_FMT_H__
26 #define __MOTR_BE_FMT_H__
27 
28 #include "lib/types.h" /* m0_bcount_t */
29 #include "lib/buf_xc.h" /* m0_buf_xc */
30 #include "lib/assert.h" /* M0_BASSERT */
31 
123 struct m0_buf;
124 struct m0_be_group_format;
126 
128  /* there is nothing we can do with unknown field. */
129  uint64_t gi_unknown;
130 } M0_XCA_RECORD M0_XCA_DOMAIN(be);
131 
134  uint64_t fgh_lsn;
135  uint64_t fgh_size;
136  uint64_t fgh_tx_nr;
137  uint64_t fgh_reg_nr;
138  uint64_t fgh_magic;
139 } M0_XCA_RECORD M0_XCA_DOMAIN(be);
140 
142  uint64_t chx_tx_id;
144 } M0_XCA_RECORD M0_XCA_DOMAIN(be);
145 
147  uint32_t cht_nr;
149 } M0_XCA_SEQUENCE M0_XCA_DOMAIN(be);
150 
153  uint64_t chg_addr; /* has to be (void *) */
154 } M0_XCA_RECORD M0_XCA_DOMAIN(be);
155 
157  uint32_t chr_nr;
159 } M0_XCA_SEQUENCE M0_XCA_DOMAIN(be);
160 
164 } M0_XCA_RECORD M0_XCA_DOMAIN(be);
165 
167  uint32_t fcp_nr;
169 } M0_XCA_SEQUENCE M0_XCA_DOMAIN(be);
170 
172  uint32_t cra_nr;
173  struct m0_buf *cra_reg;
174 } M0_XCA_SEQUENCE M0_XCA_DOMAIN(be);
175 
179 } M0_XCA_RECORD M0_XCA_DOMAIN(be);
180 
181 /* -------------------------------------------------------------------------- */
182 
185 };
186 
188  /* total usable size of the stob */
190  /* redundant buffer configuration */
192  unsigned fsh_rbuf_nr;
195  /* circular buffer configuration */
198 } M0_XCA_RECORD M0_XCA_DOMAIN(be);
199 
200 struct m0_be_fmt_group_cfg;
201 
203  uint64_t flh_serial;
207 } M0_XCA_RECORD M0_XCA_DOMAIN(be);
208 
209 #define BFLH_F "(flh_serial=%" PRIu64 " flh_discarded=%" PRIu64 " " \
210  "flh_group_lsn=%" PRIu64 " flh_group_size=%" PRIu64 ")"
211 #define BFLH_P(log_hdr) (log_hdr)->flh_serial, (log_hdr)->flh_discarded, \
212  (log_hdr)->flh_group_lsn, (log_hdr)->flh_group_size
213 
224  uint64_t fg_cfg;
225 } M0_XCA_RECORD M0_XCA_DOMAIN(be);
226 
227 M0_BASSERT(sizeof(((struct m0_be_fmt_group *)NULL)->fg_cfg) ==
228  sizeof(struct m0_be_fmt_group_cfg *));
231  uint64_t gcb_lsn;
232  uint64_t gcb_size;
233  uint64_t gcb_tx_nr;
234  uint64_t gcb_magic;
235 } M0_XCA_RECORD M0_XCA_DOMAIN(be);
236 
238  uint64_t fgc_tx_nr_max;
239  uint64_t fgc_reg_nr_max;
242  uint64_t fgc_seg_nr_max;
243 };
244 
247 } M0_XCA_RECORD M0_XCA_DOMAIN(be);
248 
250  uint64_t lrhc_io_nr_max;
251 };
252 
254  uint32_t lrhs_nr;
256 } M0_XCA_SEQUENCE M0_XCA_DOMAIN(be);
257 
264  uint64_t lrh_io_nr_max;
266 } M0_XCA_RECORD M0_XCA_DOMAIN(be);
267 
268 #define BFLRH_F "(pos=%" PRIu64 " size=%" PRIu64 " discarded=%" PRIu64 " " \
269  "prev_pos=%" PRIu64 " prev_size=%" PRIu64 \
270  " io_nr_max=%" PRIu64 ")"
271 #define BFLRH_P(h) (h)->lrh_pos, (h)->lrh_size, (h)->lrh_discarded, \
272  (h)->lrh_prev_pos, (h)->lrh_prev_size, \
273  (h)->lrh_io_nr_max
274 
281  int (*dc_iter)(const struct m0_xcode_cursor *it);
282  void (*dc_iter_end)(const struct m0_xcode_cursor *it);
283 };
284 
288 M0_INTERNAL int m0_be_fmt_type_trace(const struct m0_xcode_cursor *it);
289 M0_INTERNAL void m0_be_fmt_type_trace_end(const struct m0_xcode_cursor *it);
290 
291 #define M0_BE_FMT_DECODE_CFG_DEFAULT \
292  (&(const struct m0_be_fmt_decode_cfg) { \
293  .dc_group_size_max = 1 << 24, \
294  .dc_iter = NULL, \
295  .dc_iter_end = NULL, \
296  })
297 
298 #define M0_BE_FMT_DECODE_CFG_DEFAULT_WITH_TRACE \
299  (&(const struct m0_be_fmt_decode_cfg) { \
300  .dc_group_size_max = 1 << 24, \
301  .dc_iter = m0_be_fmt_type_trace, \
302  .dc_iter_end = m0_be_fmt_type_trace_end, \
303  })
304 
305 /* functional interfaces */
306 #define M0_BE_FMT_DECLARE(name) \
307 struct m0_be_fmt_##name; \
308 struct m0_be_fmt_##name##_cfg; \
309 M0_INTERNAL int \
310 m0_be_fmt_##name##_init(struct m0_be_fmt_##name *obj, \
311  const struct m0_be_fmt_##name##_cfg *cfg); \
312 M0_INTERNAL void m0_be_fmt_##name##_fini(struct m0_be_fmt_##name *obj); \
313 M0_INTERNAL void m0_be_fmt_##name##_reset(struct m0_be_fmt_##name *obj); \
314 M0_INTERNAL m0_bcount_t \
315 m0_be_fmt_##name##_size(struct m0_be_fmt_##name *obj); \
316 M0_INTERNAL m0_bcount_t \
317 m0_be_fmt_##name##_size_max(const struct m0_be_fmt_##name##_cfg *cfg); \
318 M0_INTERNAL int m0_be_fmt_##name##_encode(struct m0_be_fmt_##name *obj, \
319  struct m0_bufvec_cursor *cur); \
320 M0_INTERNAL int m0_be_fmt_##name##_encode_buf(struct m0_be_fmt_##name *obj, \
321  struct m0_buf *buf); \
322 M0_INTERNAL int \
323 m0_be_fmt_##name##_decode(struct m0_be_fmt_##name **obj, \
324  struct m0_bufvec_cursor *cur, \
325  const struct m0_be_fmt_decode_cfg *cfg); \
326 M0_INTERNAL int \
327 m0_be_fmt_##name##_decode_buf(struct m0_be_fmt_##name **obj, \
328  struct m0_buf *buf, \
329  const struct m0_be_fmt_decode_cfg *cfg); \
330 M0_INTERNAL void m0_be_fmt_##name##_decoded_free(struct m0_be_fmt_##name *obj)
331 
332 /* -------------------------------------------------------------------------- */
333 
335 M0_BE_FMT_DECLARE(log_store_header);
336 M0_BE_FMT_DECLARE(log_record_footer);
337 M0_BE_FMT_DECLARE(log_header);
338 
339 /* Iterative interface to add tx from group and group reg_area into
340  * m0_be_fmt_group
341  */
342 
345  void *fr_addr;
346  void *fr_buf;
347 };
348 
349 #define M0_BE_FMT_REG(size, addr, buf) (struct m0_be_fmt_reg){ \
350  .fr_size = (size), \
351  .fr_addr = (addr), \
352  .fr_buf = (buf), \
353 }
354 
355 M0_INTERNAL void m0_be_fmt_group_reg_add(struct m0_be_fmt_group *fg,
356  const struct m0_be_fmt_reg *freg);
357 
358 M0_INTERNAL uint32_t m0_be_fmt_group_reg_nr(const struct m0_be_fmt_group *fg);
359 M0_INTERNAL void m0_be_fmt_group_reg_by_id(const struct m0_be_fmt_group *fg,
360  uint32_t index,
361  struct m0_be_fmt_reg *freg);
362 
363 struct m0_be_fmt_tx {
365  uint64_t bft_id;
366 };
367 
368 #define M0_BE_FMT_TX(payload, id) (struct m0_be_fmt_tx){ \
369  .bft_payload = (payload), \
370  .bft_id = (id), \
371 }
372 
373 M0_INTERNAL void m0_be_fmt_group_tx_add(struct m0_be_fmt_group *fg,
374  const struct m0_be_fmt_tx *ftx);
375 M0_INTERNAL uint32_t m0_be_fmt_group_tx_nr(const struct m0_be_fmt_group *fg);
376 M0_INTERNAL void m0_be_fmt_group_tx_by_id(const struct m0_be_fmt_group *fg,
377  uint32_t index,
378  struct m0_be_fmt_tx *ftx);
379 
380 M0_INTERNAL struct m0_be_fmt_group_info *
382 
383 M0_INTERNAL bool m0_be_fmt_group_sanity_check(struct m0_be_fmt_group *fg);
384 
385 M0_BE_FMT_DECLARE(cblock);
386 M0_BE_FMT_DECLARE(log_record_header);
387 
388 M0_INTERNAL void
390  m0_bcount_t size);
391 #undef M0_BE_FMT_DECLARE
392 
394 #endif /* __MOTR_BE_FMT_H__ */
395 
396 /*
397  * Local variables:
398  * c-indentation-style: "K&R"
399  * c-basic-offset: 8
400  * tab-width: 8
401  * fill-column: 80
402  * scroll-step: 1
403  * End:
404  */
405 /*
406  * vim: tabstop=8 shiftwidth=8 noexpandtab textwidth=80 nowrap
407  */
uint64_t fgh_lsn
Definition: fmt.h:134
m0_bindex_t lrh_pos
Definition: fmt.h:259
m0_bindex_t fsh_cbuf_offset
Definition: fmt.h:196
uint64_t fgc_payload_size_max
Definition: fmt.h:240
M0_INTERNAL uint32_t m0_be_fmt_group_reg_nr(const struct m0_be_fmt_group *fg)
Definition: fmt.c:392
uint64_t fg_cfg
Definition: fmt.h:224
m0_bcount_t fsh_cbuf_size
Definition: fmt.h:197
uint64_t gcb_magic
Definition: fmt.h:234
uint64_t gcb_size
Definition: fmt.h:232
#define NULL
Definition: misc.h:38
uint64_t fgh_tx_nr
Definition: fmt.h:136
M0_INTERNAL void m0_be_fmt_group_reg_add(struct m0_be_fmt_group *fg, const struct m0_be_fmt_reg *freg)
Definition: fmt.c:367
m0_bindex_t lrh_prev_size
Definition: fmt.h:263
uint64_t fgh_reg_nr
Definition: fmt.h:137
M0_INTERNAL void m0_be_fmt_type_trace_end(const struct m0_xcode_cursor *it)
Definition: fmt.c:213
m0_bcount_t chg_size
Definition: fmt.h:152
static struct m0_be_emap_cursor it
Definition: extmap.c:46
m0_bcount_t fsh_size
Definition: fmt.h:189
uint64_t m0_bindex_t
Definition: types.h:80
uint64_t fgc_tx_nr_max
Definition: fmt.h:238
uint64_t gcb_tx_nr
Definition: fmt.h:233
uint64_t m0_bcount_t
Definition: types.h:77
uint64_t fgh_size
Definition: fmt.h:135
M0_INTERNAL void m0_be_fmt_group_tx_by_id(const struct m0_be_fmt_group *fg, uint32_t index, struct m0_be_fmt_tx *ftx)
Definition: fmt.c:443
static struct foo * obj
Definition: tlist.c:302
uint64_t dc_group_size_max
Definition: fmt.h:280
Definition: buf.h:37
m0_bcount_t lrh_size
Definition: fmt.h:260
m0_bcount_t fr_size
Definition: fmt.h:344
struct m0_be_fmt_content_header_txs fch_txs
Definition: fmt.h:162
m0_bcount_t fsh_rbuf_size_aligned
Definition: fmt.h:194
M0_INTERNAL void m0_be_fmt_log_record_header_io_size_add(struct m0_be_fmt_log_record_header *obj, m0_bcount_t size)
Definition: fmt.c:602
uint64_t fgc_reg_size_max
Definition: fmt.h:241
M0_INTERNAL struct m0_be_fmt_group_info * m0_be_fmt_group_info_get(struct m0_be_fmt_group *fg)
Definition: fmt.c:460
uint64_t gi_unknown
Definition: fmt.h:129
struct m0_be_fmt_content fg_content
Definition: fmt.h:217
m0_bindex_t lrh_discarded
Definition: fmt.h:261
unsigned fsh_rbuf_nr
Definition: fmt.h:192
struct m0_be_fmt_group_header fg_header
Definition: fmt.h:215
M0_INTERNAL int m0_be_fmt_type_trace(const struct m0_xcode_cursor *it)
Definition: fmt.c:218
static void group(void)
Definition: sm.c:386
m0_bindex_t flh_group_lsn
Definition: fmt.h:205
uint64_t fg_cfg
Definition: fmt.h:99
struct m0_buf bft_payload
Definition: fmt.h:364
struct m0_be_fmt_content_header_tx * cht_tx
Definition: fmt.h:148
#define M0_BE_FMT_DECLARE(name)
Definition: fmt.h:306
uint64_t fgc_seg_nr_max
Definition: fmt.h:242
struct m0_be_fmt_log_record_header_io_size lrh_io_size
Definition: fmt.h:265
struct m0_be_fmt_content_header_reg_area fch_reg_area
Definition: fmt.h:163
m0_bindex_t fsh_rbuf_offset
Definition: fmt.h:191
m0_bcount_t fsh_rbuf_size
Definition: fmt.h:193
void * fr_addr
Definition: fmt.h:345
uint64_t fgc_reg_nr_max
Definition: fmt.h:239
uint64_t flh_serial
Definition: fmt.h:203
struct m0_be_fmt_content_header fg_content_header
Definition: fmt.h:216
m0_bindex_t lrh_prev_pos
Definition: fmt.h:262
M0_INTERNAL void m0_be_fmt_group_reg_by_id(const struct m0_be_fmt_group *fg, uint32_t index, struct m0_be_fmt_reg *freg)
Definition: fmt.c:397
struct m0_buf * fcp_payload
Definition: fmt.h:168
struct m0_buf * cra_reg
Definition: fmt.h:173
m0_bcount_t chx_payload_size
Definition: fmt.h:143
struct m0_be_fmt_content_header_reg * chr_reg
Definition: fmt.h:158
uint64_t lrh_io_nr_max
Definition: fmt.h:264
uint64_t fgh_magic
Definition: fmt.h:138
m0_bcount_t size
Definition: di.c:39
M0_INTERNAL void m0_be_fmt_group_tx_add(struct m0_be_fmt_group *fg, const struct m0_be_fmt_tx *ftx)
Definition: fmt.c:414
M0_BASSERT(sizeof(((struct m0_be_fmt_group *) NULL) ->fg_cfg)==sizeof(struct m0_be_fmt_group_cfg *))
struct m0_be_fmt_content_payloads fmc_payloads
Definition: fmt.h:177
int(* dc_iter)(const struct m0_xcode_cursor *it)
Definition: fmt.h:281
struct m0_be_fmt_log_store_header_cfg M0_XCA_DOMAIN
struct m0_be_fmt_group_info fgh_info
Definition: fmt.h:133
void(* dc_iter_end)(const struct m0_xcode_cursor *it)
Definition: fmt.h:282
m0_bindex_t flh_discarded
Definition: fmt.h:204
M0_INTERNAL bool m0_be_fmt_group_sanity_check(struct m0_be_fmt_group *fg)
Definition: fmt.c:465
M0_INTERNAL uint32_t m0_be_fmt_group_tx_nr(const struct m0_be_fmt_group *fg)
Definition: fmt.c:438
void * fr_buf
Definition: fmt.h:346
uint64_t bft_id
Definition: fmt.h:365
struct m0_be_fmt_content_reg_area fmc_reg_area
Definition: fmt.h:178
static struct m0_be_ut_backend be
Definition: service_ut.c:59
m0_bcount_t flh_group_size
Definition: fmt.h:206
uint64_t gcb_lsn
Definition: fmt.h:231