]> git.proxmox.com Git - ceph.git/blob - ceph/src/pmdk/src/libpmemblk/btt_layout.h
import ceph 16.2.7
[ceph.git] / ceph / src / pmdk / src / libpmemblk / btt_layout.h
1 /* SPDX-License-Identifier: BSD-3-Clause */
2 /* Copyright 2014-2020, Intel Corporation */
3
4 /*
5 * btt_layout.h -- block translation table on-media layout definitions
6 */
7
8 /*
9 * Layout of BTT info block. All integers are stored little-endian.
10 */
11
12 #ifndef BTT_LAYOUT_H
13 #define BTT_LAYOUT_H 1
14
15 #ifdef __cplusplus
16 extern "C" {
17 #endif
18
19 #define BTT_ALIGNMENT ((uintptr_t)4096) /* alignment of all BTT structures */
20 #define BTTINFO_SIG_LEN 16
21 #define BTTINFO_UUID_LEN 16
22 #define BTTINFO_UNUSED_LEN 3968
23 #define BTTINFO_SIG "BTT_ARENA_INFO\0"
24
25 struct btt_info {
26 char sig[BTTINFO_SIG_LEN]; /* must be "BTT_ARENA_INFO\0\0" */
27 uint8_t uuid[BTTINFO_UUID_LEN]; /* BTT UUID */
28 uint8_t parent_uuid[BTTINFO_UUID_LEN]; /* UUID of container */
29 uint32_t flags; /* see flag bits below */
30 uint16_t major; /* major version */
31 uint16_t minor; /* minor version */
32 uint32_t external_lbasize; /* advertised LBA size (bytes) */
33 uint32_t external_nlba; /* advertised LBAs in this arena */
34 uint32_t internal_lbasize; /* size of data area blocks (bytes) */
35 uint32_t internal_nlba; /* number of blocks in data area */
36 uint32_t nfree; /* number of free blocks */
37 uint32_t infosize; /* size of this info block */
38
39 /*
40 * The following offsets are relative to the beginning of
41 * the btt_info block.
42 */
43 uint64_t nextoff; /* offset to next arena (or zero) */
44 uint64_t dataoff; /* offset to arena data area */
45 uint64_t mapoff; /* offset to area map */
46 uint64_t flogoff; /* offset to area flog */
47 uint64_t infooff; /* offset to backup info block */
48
49 char unused[BTTINFO_UNUSED_LEN]; /* must be zero */
50
51 uint64_t checksum; /* Fletcher64 of all fields */
52 };
53
54 /*
55 * Definitions for flags mask for btt_info structure above.
56 */
57 #define BTTINFO_FLAG_ERROR 0x00000001 /* error state (read-only) */
58 #define BTTINFO_FLAG_ERROR_MASK 0x00000001 /* all error bits */
59
60 /*
61 * Current on-media format versions.
62 */
63 #define BTTINFO_MAJOR_VERSION 1
64 #define BTTINFO_MINOR_VERSION 1
65
66 /*
67 * Layout of a BTT "flog" entry. All integers are stored little-endian.
68 *
69 * The "nfree" field in the BTT info block determines how many of these
70 * flog entries there are, and each entry consists of two of the following
71 * structs (entry updates alternate between the two structs), padded up
72 * to a cache line boundary to isolate adjacent updates.
73 */
74
75 #define BTT_FLOG_PAIR_ALIGN ((uintptr_t)64)
76
77 struct btt_flog {
78 uint32_t lba; /* last pre-map LBA using this entry */
79 uint32_t old_map; /* old post-map LBA (the freed block) */
80 uint32_t new_map; /* new post-map LBA */
81 uint32_t seq; /* sequence number (01, 10, 11) */
82 };
83
84 /*
85 * Layout of a BTT "map" entry. 4-byte internal LBA offset, little-endian.
86 */
87 #define BTT_MAP_ENTRY_SIZE 4
88 #define BTT_MAP_ENTRY_ERROR 0x40000000U
89 #define BTT_MAP_ENTRY_ZERO 0x80000000U
90 #define BTT_MAP_ENTRY_NORMAL 0xC0000000U
91 #define BTT_MAP_ENTRY_LBA_MASK 0x3fffffffU
92 #define BTT_MAP_LOCK_ALIGN ((uintptr_t)64)
93
94 /*
95 * BTT layout properties...
96 */
97 #define BTT_MIN_SIZE ((1u << 20) * 16)
98 #define BTT_MAX_ARENA (1ull << 39) /* 512GB per arena */
99 #define BTT_MIN_LBA_SIZE (size_t)512
100 #define BTT_INTERNAL_LBA_ALIGNMENT 256U
101 #define BTT_DEFAULT_NFREE 256
102
103 #ifdef __cplusplus
104 }
105 #endif
106
107 #endif