Motr  M0
log.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 
24 #pragma once
25 
26 #ifndef __MOTR_BE_LOG_H__
27 #define __MOTR_BE_LOG_H__
28 
29 #include "lib/mutex.h" /* m0_mutex */
30 #include "lib/tlist.h" /* m0_tl */
31 #include "lib/types.h" /* m0_bcount_t */
32 
33 #include "be/fmt.h"
34 #include "be/log_store.h" /* m0_be_log_store */
35 #include "be/log_sched.h" /* m0_be_log_sched */
36 #include "be/op.h" /* m0_be_op */
37 #include "be/io.h" /* m0_be_io */
38 #include "be/recovery.h" /* m0_be_recovery */
39 
40 #include "stob/io.h" /* m0_stob_io_opcode */
41 
221 struct m0_ext;
222 struct m0_stob_id;
223 struct m0_be_io;
224 struct m0_be_log_io;
225 struct m0_be_log_record_iter;
226 struct m0_be_tx_group;
227 
228 struct m0_be_log;
229 struct m0_be_log_record;
230 typedef void (*m0_be_log_got_space_cb_t)(struct m0_be_log *log);
232 typedef void (*m0_be_log_full_cb_t)(struct m0_be_log *log);
233 
234 enum {
236 };
237 
238 enum {
247 };
248 
256  struct m0_mutex *lc_lock;
258 };
259 
261 struct m0_be_log {
311  /* op for log header read */
313  /* op for log header write */
315 };
316 
317 /* m0_be_log */
318 #define BL_F "(lg_current=%" PRIu64 " lg_discarded=%" PRIu64 \
319  " lg_free=%" PRIu64 ")"
320 #define BL_P(log) (log)->lg_current, (log)->lg_discarded, (log)->lg_free
321 
353 
354  uint64_t lgr_magic;
357 
358  /* Fields for I/O launch */
363 
366 
369 
370  /*
371  * Log header is updated just before the record is written
372  * to the log if the flag is set.
373  */
375 };
376 
377 /* m0_be_log_record */
378 #define BLR_F "(lgr_last_discarded=%" PRIu64 " lgr_position=%" PRIu64 " " \
379  "lgr_size=%" PRIu64 " " \
380  "lgr_prev_pos=%" PRIu64 " lgr_prev_size=%" PRIu64 ")"
381 #define BLR_P(record) (record)->lgr_last_discarded, (record)->lgr_position, \
382  (record)->lgr_size, \
383  (record)->lgr_prev_pos, (record)->lgr_prev_size
384 
385 M0_INTERNAL void m0_be_log_module_setup(struct m0_be_log *log,
386  struct m0_be_log_cfg *lg_cfg,
387  bool create_mode);
388 
389 M0_INTERNAL bool m0_be_log__invariant(struct m0_be_log *log);
390 
391 M0_INTERNAL int m0_be_log_open(struct m0_be_log *log,
392  struct m0_be_log_cfg *log_cfg);
393 M0_INTERNAL void m0_be_log_close(struct m0_be_log *log);
394 
395 M0_INTERNAL int m0_be_log_create(struct m0_be_log *log,
396  struct m0_be_log_cfg *log_cfg);
397 M0_INTERNAL void m0_be_log_destroy(struct m0_be_log *log);
398 
399 M0_INTERNAL m0_bcount_t m0_be_log_reserved_size(struct m0_be_log *log,
400  m0_bcount_t *lio_size,
401  int lio_nr);
402 
409 M0_INTERNAL void m0_be_log_record_init(struct m0_be_log_record *record,
410  struct m0_be_log *log);
411 M0_INTERNAL void m0_be_log_record_fini(struct m0_be_log_record *record);
413 M0_INTERNAL void m0_be_log_record_reset(struct m0_be_log_record *record);
414 
425 M0_INTERNAL void
427  struct m0_be_log_record_iter *iter,
428  bool need_discard);
429 
430 M0_INTERNAL void m0_be_log_record_ext(struct m0_be_log_record *record,
431  struct m0_ext *ext);
432 
434 M0_INTERNAL void m0_be_log_record_skip_discard(struct m0_be_log_record *record);
436 M0_INTERNAL void m0_be_log_record_discard(struct m0_be_log *log,
437  m0_bcount_t size);
438 
439 M0_INTERNAL int m0_be_log_record_io_create(struct m0_be_log_record *record,
440  m0_bcount_t size_max);
447 M0_INTERNAL int m0_be_log_record_allocate(struct m0_be_log_record *record);
448 M0_INTERNAL void m0_be_log_record_deallocate(struct m0_be_log_record *record);
449 M0_INTERNAL void m0_be_log_record_io_size_set(struct m0_be_log_record *record,
450  int index,
451  m0_bcount_t size);
452 M0_INTERNAL void
455  m0_bcount_t size_reserved);
456 M0_INTERNAL struct m0_bufvec *
458  int index);
463 M0_INTERNAL void m0_be_log_record_io_launch(struct m0_be_log_record *record,
464  struct m0_be_op *op);
465 
466 
468 M0_INTERNAL m0_bindex_t
470 
475 M0_INTERNAL m0_bindex_t
477 
482 M0_INTERNAL int m0_be_log_reserve(struct m0_be_log *log, m0_bcount_t size);
487 M0_INTERNAL void m0_be_log_unreserve(struct m0_be_log *log, m0_bcount_t size);
488 
490 M0_INTERNAL uint32_t m0_be_log_bshift(struct m0_be_log *log);
491 
492 M0_INTERNAL void m0_be_log_header__set(struct m0_be_fmt_log_header *hdr,
493  m0_bindex_t discarded,
494  m0_bindex_t lsn,
495  m0_bcount_t size);
496 M0_INTERNAL bool m0_be_log_header__is_eq(struct m0_be_fmt_log_header *hdr1,
497  struct m0_be_fmt_log_header *hdr2);
498 M0_INTERNAL bool m0_be_log_header__repair(struct m0_be_fmt_log_header **hdrs,
499  int nr,
500  struct m0_be_fmt_log_header *out);
505 M0_INTERNAL int m0_be_log_header_read(struct m0_be_log *log,
506  struct m0_be_fmt_log_header *log_hdr);
507 
513  uint64_t lri_magic;
514 };
515 
516 M0_INTERNAL int m0_be_log_record_iter_init(struct m0_be_log_record_iter *iter);
517 M0_INTERNAL void m0_be_log_record_iter_fini(struct m0_be_log_record_iter *iter);
518 M0_INTERNAL void m0_be_log_record_iter_copy(struct m0_be_log_record_iter *dest,
519  struct m0_be_log_record_iter *src);
520 M0_INTERNAL int m0_be_log_record_initial(struct m0_be_log *log,
521  struct m0_be_log_record_iter *curr);
522 M0_INTERNAL int m0_be_log_record_next(struct m0_be_log *log,
523  const struct m0_be_log_record_iter *curr,
524  struct m0_be_log_record_iter *next);
525 M0_INTERNAL int m0_be_log_record_prev(struct m0_be_log *log,
526  const struct m0_be_log_record_iter *curr,
527  struct m0_be_log_record_iter *prev);
530  struct m0_be_log *log);
531 
532 M0_INTERNAL bool
534 M0_INTERNAL void
536  struct m0_be_log_record_iter *iter);
537 M0_INTERNAL m0_bindex_t
539 
540 M0_INTERNAL bool m0_be_log_contains_stob(struct m0_be_log *log,
541  const struct m0_stob_id *stob_id);
544 #endif /* __MOTR_BE_LOG_H__ */
545 
546 
547 /*
548  * Local variables:
549  * c-indentation-style: "K&R"
550  * c-basic-offset: 8
551  * tab-width: 8
552  * fill-column: 80
553  * scroll-step: 1
554  * End:
555  */
556 /*
557  * vim: tabstop=8 shiftwidth=8 noexpandtab textwidth=80 nowrap
558  */
M0_INTERNAL void m0_be_log_record_io_size_set(struct m0_be_log_record *record, int index, m0_bcount_t size)
Definition: log.c:636
m0_bcount_t lg_prev_record_size
Definition: log.h:293
M0_INTERNAL struct m0_bufvec * m0_be_log_record_io_bufvec(struct m0_be_log_record *record, int index)
Definition: log.c:830
static size_t nr
Definition: dump.c:1505
void(* m0_be_log_record_cb_t)(struct m0_be_log_record *record)
Definition: log.h:231
struct m0_be_fmt_log_record_header lri_header
Definition: log.h:509
struct m0_be_op lg_header_read_op
Definition: log.h:312
M0_INTERNAL int m0_be_log_record_iter_init(struct m0_be_log_record_iter *iter)
Definition: log.c:1151
M0_INTERNAL bool m0_be_log_recovery_record_available(struct m0_be_log *log)
Definition: log.c:1214
struct m0_be_recovery_cfg lc_recovery_cfg
Definition: log.h:252
M0_INTERNAL int m0_be_log_record_allocate(struct m0_be_log_record *record)
Definition: log.c:615
M0_INTERNAL int m0_be_log_record_initial(struct m0_be_log *log, struct m0_be_log_record_iter *curr)
Definition: log.c:1167
M0_INTERNAL void m0_be_log_record_io_launch(struct m0_be_log_record *record, struct m0_be_op *op)
Definition: log.c:795
struct m0_be_log_store lg_store
Definition: log.h:274
struct m0_be_log_sched_cfg lc_sched_cfg
Definition: log.h:251
M0_INTERNAL int m0_be_log_open(struct m0_be_log *log, struct m0_be_log_cfg *log_cfg)
Definition: log.c:281
m0_bcount_t lg_free
Definition: log.h:288
M0_INTERNAL bool m0_be_fmt_log_record_header__invariant(struct m0_be_fmt_log_record_header *header, struct m0_be_log *log)
Definition: log.c:1050
M0_INTERNAL m0_bindex_t m0_be_log_recovery_discarded(struct m0_be_log *log)
Definition: log.c:1228
M0_INTERNAL m0_bcount_t m0_be_log_reserved_size(struct m0_be_log *log, m0_bcount_t *lio_size, int lio_nr)
Definition: log.c:358
struct m0_be_log_io * lgr_io[M0_BE_LOG_RECORD_IO_NR_MAX]
Definition: log.h:360
M0_INTERNAL void m0_be_log_record_io_prepare(struct m0_be_log_record *record, enum m0_stob_io_opcode opcode, m0_bcount_t size_reserved)
Definition: log.c:660
uint64_t m0_bindex_t
Definition: types.h:80
M0_INTERNAL int m0_be_log_record_prev(struct m0_be_log *log, const struct m0_be_log_record_iter *curr, struct m0_be_log_record_iter *prev)
Definition: log.c:1202
uint64_t m0_bcount_t
Definition: types.h:77
m0_bcount_t lgr_size
Definition: log.h:335
m0_bindex_t lri_log_header_discarded
Definition: log.h:511
struct m0_be_fmt_log_record_footer lgr_footer
Definition: log.h:368
struct m0_tlink lgr_sched_linkage
Definition: log.h:356
m0_bindex_t lgr_log_header_discarded
Definition: log.h:352
struct m0_module lg_module
Definition: log.h:265
bool lg_unplaced_exists
Definition: log.h:298
M0_INTERNAL m0_bindex_t m0_be_log_record_discarded(const struct m0_be_log_record *record)
Definition: log.c:844
M0_INTERNAL int m0_be_log_record_io_create(struct m0_be_log_record *record, m0_bcount_t size_max)
Definition: log.c:558
int lgr_state
Definition: log.h:325
op
Definition: libdemo.c:64
M0_INTERNAL void m0_be_log_module_setup(struct m0_be_log *log, struct m0_be_log_cfg *lg_cfg, bool create_mode)
Definition: log.c:233
M0_INTERNAL bool m0_be_log_header__repair(struct m0_be_fmt_log_header **hdrs, int nr, struct m0_be_fmt_log_header *out)
Definition: log.c:953
struct m0_be_op * lgr_user_op
Definition: log.h:365
struct m0_be_recovery lg_recovery
Definition: log.h:277
int opcode
Definition: crate.c:301
M0_INTERNAL int m0_be_log_record_next(struct m0_be_log *log, const struct m0_be_log_record_iter *curr, struct m0_be_log_record_iter *next)
Definition: log.c:1191
struct m0_be_log_store_cfg lc_store_cfg
Definition: log.h:250
M0_INTERNAL void m0_be_log_record_assign(struct m0_be_log_record *record, struct m0_be_log_record_iter *iter, bool need_discard)
Definition: log.c:467
bool lgr_need_discard
Definition: log.h:327
int lgr_io_nr
Definition: log.h:359
m0_bindex_t lgr_prev_pos
Definition: log.h:337
struct m0_mutex * lc_lock
Definition: log.h:256
m0_bindex_t lg_prev_record
Definition: log.h:292
M0_INTERNAL void m0_be_log_close(struct m0_be_log *log)
Definition: log.c:287
struct m0_be_log * lgr_log
Definition: log.h:324
m0_bindex_t lg_discarded
Definition: log.h:286
M0_INTERNAL bool m0_be_log__invariant(struct m0_be_log *log)
Definition: log.c:270
void(* m0_be_log_got_space_cb_t)(struct m0_be_log *log)
Definition: log.h:230
struct m0_be_fmt_log_record_header lgr_header
Definition: log.h:367
m0_stob_io_opcode
Definition: io.h:227
bool lg_create_mode
Definition: log.h:263
m0_be_log_got_space_cb_t lg_got_space_cb
Definition: log.h:305
Definition: tlist.h:251
bool lgr_write_header
Definition: log.h:374
M0_INTERNAL void m0_be_log_record_fini(struct m0_be_log_record *record)
Definition: log.c:410
static int next[]
Definition: cp.c:248
m0_be_log_got_space_cb_t lc_got_space_cb
Definition: log.h:253
struct m0_mutex lg_record_state_lock
Definition: log.h:282
M0_INTERNAL int m0_be_log_create(struct m0_be_log *log, struct m0_be_log_cfg *log_cfg)
Definition: log.c:292
m0_bcount_t lgr_prev_size
Definition: log.h:338
M0_INTERNAL void m0_be_log_header__set(struct m0_be_fmt_log_header *hdr, m0_bindex_t discarded, m0_bindex_t lsn, m0_bcount_t size)
Definition: log.c:888
M0_INTERNAL void m0_be_log_record_discard(struct m0_be_log *log, m0_bcount_t size)
Definition: log.c:523
M0_INTERNAL void m0_be_log_record_reset(struct m0_be_log_record *record)
Definition: log.c:433
struct m0_mutex * lg_external_lock
Definition: log.h:310
struct m0_be_op lgr_record_op
Definition: log.h:362
m0_bindex_t lg_current
Definition: log.h:284
M0_INTERNAL int m0_be_log_reserve(struct m0_be_log *log, m0_bcount_t size)
Definition: log.c:850
M0_INTERNAL void m0_be_log_recovery_record_get(struct m0_be_log *log, struct m0_be_log_record_iter *iter)
Definition: log.c:1221
struct m0_be_op lg_header_write_op
Definition: log.h:314
struct m0_be_log_cfg lg_cfg
Definition: log.h:262
M0_INTERNAL m0_bindex_t m0_be_log_record_position(const struct m0_be_log_record *record)
Definition: log.c:838
Definition: ext.h:37
bool lg_destroy_mode
Definition: log.h:264
uint64_t lri_magic
Definition: log.h:513
M0_INTERNAL bool m0_be_log_header__is_eq(struct m0_be_fmt_log_header *hdr1, struct m0_be_fmt_log_header *hdr2)
Definition: log.c:902
M0_INTERNAL void m0_be_log_destroy(struct m0_be_log *log)
Definition: log.c:298
M0_INTERNAL void m0_be_log_record_iter_copy(struct m0_be_log_record_iter *dest, struct m0_be_log_record_iter *src)
Definition: log.c:1161
bool lc_skip_recovery
Definition: log.h:257
m0_bcount_t lg_unplaced_size
Definition: log.h:300
M0_INTERNAL int m0_be_log_header_read(struct m0_be_log *log, struct m0_be_fmt_log_header *log_hdr)
Definition: log.c:973
m0_bcount_t size
Definition: di.c:39
m0_be_log_full_cb_t lc_full_cb
Definition: log.h:254
struct m0_be_op * lgr_op[M0_BE_LOG_RECORD_IO_NR_MAX]
Definition: log.h:361
m0_bindex_t lgr_last_discarded
Definition: log.h:332
Definition: record.py:1
Definition: io.h:87
M0_INTERNAL void m0_be_log_record_iter_fini(struct m0_be_log_record_iter *iter)
Definition: log.c:1156
struct m0_tlink lgr_linkage
Definition: log.h:355
void(* m0_be_log_full_cb_t)(struct m0_be_log *log)
Definition: log.h:232
Definition: log.h:261
struct m0_tl lg_records
Definition: log.h:280
#define out(...)
Definition: gen.c:41
struct m0_tlink lri_linkage
Definition: log.h:512
m0_bcount_t lc_full_threshold
Definition: log.h:255
M0_INTERNAL void m0_be_log_record_deallocate(struct m0_be_log_record *record)
Definition: log.c:630
Definition: op.h:74
uint64_t lgr_magic
Definition: log.h:354
struct m0_be_log_sched lg_sched
Definition: log.h:276
M0_INTERNAL bool m0_be_log_contains_stob(struct m0_be_log *log, const struct m0_stob_id *stob_id)
Definition: log.c:1233
M0_INTERNAL void m0_be_log_record_skip_discard(struct m0_be_log_record *record)
Definition: log.c:505
m0_bindex_t lg_unplaced_pos
Definition: log.h:299
Definition: mutex.h:47
m0_bindex_t lgr_position
Definition: log.h:334
M0_INTERNAL void m0_be_log_record_init(struct m0_be_log_record *record, struct m0_be_log *log)
Definition: log.c:390
struct m0_pdclust_src_addr src
Definition: fd.c:108
M0_INTERNAL uint32_t m0_be_log_bshift(struct m0_be_log *log)
Definition: log.c:883
m0_bcount_t lg_reserved
Definition: log.h:290
M0_INTERNAL void m0_be_log_record_ext(struct m0_be_log_record *record, struct m0_ext *ext)
Definition: log.c:496
struct m0_be_fmt_log_header lg_header
Definition: log.h:278
Definition: vec.h:145
M0_INTERNAL void m0_be_log_unreserve(struct m0_be_log *log, m0_bcount_t size)
Definition: log.c:868