]> git.proxmox.com Git - ceph.git/blob - ceph/src/pmdk/src/libpmemlog/log.h
import ceph 16.2.7
[ceph.git] / ceph / src / pmdk / src / libpmemlog / log.h
1 /* SPDX-License-Identifier: BSD-3-Clause */
2 /* Copyright 2014-2020, Intel Corporation */
3
4 /*
5 * log.h -- internal definitions for libpmem log module
6 */
7
8 #ifndef LOG_H
9 #define LOG_H 1
10
11 #include <stdint.h>
12 #include <stddef.h>
13 #include <endian.h>
14
15 #include "ctl.h"
16 #include "util.h"
17 #include "os_thread.h"
18 #include "pool_hdr.h"
19 #include "page_size.h"
20
21 #ifdef __cplusplus
22 extern "C" {
23 #endif
24
25 #include "alloc.h"
26 #include "fault_injection.h"
27
28 #define PMEMLOG_LOG_PREFIX "libpmemlog"
29 #define PMEMLOG_LOG_LEVEL_VAR "PMEMLOG_LOG_LEVEL"
30 #define PMEMLOG_LOG_FILE_VAR "PMEMLOG_LOG_FILE"
31
32 /* attributes of the log memory pool format for the pool header */
33 #define LOG_HDR_SIG "PMEMLOG" /* must be 8 bytes including '\0' */
34 #define LOG_FORMAT_MAJOR 1
35
36 #define LOG_FORMAT_FEAT_DEFAULT \
37 {POOL_FEAT_COMPAT_DEFAULT, POOL_FEAT_INCOMPAT_DEFAULT, 0x0000}
38
39 #define LOG_FORMAT_FEAT_CHECK \
40 {POOL_FEAT_COMPAT_VALID, POOL_FEAT_INCOMPAT_VALID, 0x0000}
41
42 static const features_t log_format_feat_default = LOG_FORMAT_FEAT_DEFAULT;
43
44 struct pmemlog {
45 struct pool_hdr hdr; /* memory pool header */
46
47 /* root info for on-media format... */
48 uint64_t start_offset; /* start offset of the usable log space */
49 uint64_t end_offset; /* maximum offset of the usable log space */
50 uint64_t write_offset; /* current write point for the log */
51
52 /* some run-time state, allocated out of memory pool... */
53 void *addr; /* mapped region */
54 size_t size; /* size of mapped region */
55 int is_pmem; /* true if pool is PMEM */
56 int rdonly; /* true if pool is opened read-only */
57 os_rwlock_t *rwlockp; /* pointer to RW lock */
58 int is_dev_dax; /* true if mapped on device dax */
59 struct ctl *ctl; /* top level node of the ctl tree structure */
60
61 struct pool_set *set; /* pool set info */
62 };
63
64 /* data area starts at this alignment after the struct pmemlog above */
65 #define LOG_FORMAT_DATA_ALIGN ((uintptr_t)PMEM_PAGESIZE)
66
67 /*
68 * log_convert2h -- convert pmemlog structure to host byte order
69 */
70 static inline void
71 log_convert2h(struct pmemlog *plp)
72 {
73 plp->start_offset = le64toh(plp->start_offset);
74 plp->end_offset = le64toh(plp->end_offset);
75 plp->write_offset = le64toh(plp->write_offset);
76 }
77
78 /*
79 * log_convert2le -- convert pmemlog structure to LE byte order
80 */
81 static inline void
82 log_convert2le(struct pmemlog *plp)
83 {
84 plp->start_offset = htole64(plp->start_offset);
85 plp->end_offset = htole64(plp->end_offset);
86 plp->write_offset = htole64(plp->write_offset);
87 }
88
89 #if FAULT_INJECTION
90 void
91 pmemlog_inject_fault_at(enum pmem_allocation_type type, int nth,
92 const char *at);
93
94 int
95 pmemlog_fault_injection_enabled(void);
96 #else
97 static inline void
98 pmemlog_inject_fault_at(enum pmem_allocation_type type, int nth,
99 const char *at)
100 {
101 abort();
102 }
103
104 static inline int
105 pmemlog_fault_injection_enabled(void)
106 {
107 return 0;
108 }
109 #endif
110
111 #ifdef __cplusplus
112 }
113 #endif
114
115 #endif