]> git.proxmox.com Git - ceph.git/blame - ceph/src/os/bluestore/bluefs_types.h
update sources to 12.2.7
[ceph.git] / ceph / src / os / bluestore / bluefs_types.h
CommitLineData
7c673cae
FG
1// -*- mode:C++; tab-width:8; c-basic-offset:2; indent-tabs-mode:t -*-
2// vim: ts=8 sw=2 smarttab
3#ifndef CEPH_OS_BLUESTORE_BLUEFS_TYPES_H
4#define CEPH_OS_BLUESTORE_BLUEFS_TYPES_H
5
6#include "bluestore_types.h"
7#include "include/utime.h"
8#include "include/encoding.h"
9#include "include/denc.h"
10
11class bluefs_extent_t : public AllocExtent{
12public:
13 uint8_t bdev;
14
15 bluefs_extent_t(uint8_t b = 0, uint64_t o = 0, uint32_t l = 0)
16 : AllocExtent(o, l), bdev(b) {}
17
18 DENC(bluefs_extent_t, v, p) {
19 DENC_START(1, 1, p);
20 denc_lba(v.offset, p);
21 denc_varint_lowz(v.length, p);
22 denc(v.bdev, p);
23 DENC_FINISH(p);
24 }
25
26 void dump(Formatter *f) const;
27 static void generate_test_instances(list<bluefs_extent_t*>&);
28};
29WRITE_CLASS_DENC(bluefs_extent_t)
30
31f18b77 31ostream& operator<<(ostream& out, const bluefs_extent_t& e);
7c673cae
FG
32
33
34struct bluefs_fnode_t {
35 uint64_t ino;
36 uint64_t size;
37 utime_t mtime;
38 uint8_t prefer_bdev;
39 mempool::bluefs::vector<bluefs_extent_t> extents;
40 uint64_t allocated;
41
42 bluefs_fnode_t() : ino(0), size(0), prefer_bdev(0), allocated(0) {}
43
44 uint64_t get_allocated() const {
45 return allocated;
46 }
47
48 void recalc_allocated() {
49 allocated = 0;
50 for (auto& p : extents)
51 allocated += p.length;
52 }
53
94b18763
FG
54 DENC_HELPERS
55 void bound_encode(size_t& p) const {
56 _denc_friend(*this, p);
57 }
58 void encode(bufferlist::contiguous_appender& p) const {
59 DENC_DUMP_PRE(bluefs_fnode_t);
60 _denc_friend(*this, p);
61 DENC_DUMP_POST(bluefs_fnode_t);
62 }
63 void decode(buffer::ptr::iterator& p) {
64 _denc_friend(*this, p);
65 recalc_allocated();
66 }
67 template<typename T, typename P>
68 friend typename std::enable_if<
69 boost::is_same<T,bluefs_fnode_t>::value ||
70 boost::is_same<T,const bluefs_fnode_t>::value>::type
71 _denc_friend(T& v, P& p) {
7c673cae
FG
72 DENC_START(1, 1, p);
73 denc_varint(v.ino, p);
74 denc_varint(v.size, p);
75 denc(v.mtime, p);
76 denc(v.prefer_bdev, p);
77 denc(v.extents, p);
78 DENC_FINISH(p);
79 }
80
94b18763
FG
81 void append_extent(const bluefs_extent_t& ext) {
82 extents.push_back(ext);
83 allocated += ext.length;
84 }
85
86 void pop_front_extent() {
87 auto it = extents.begin();
88 allocated -= it->length;
89 extents.erase(it);
90 }
91
92 void swap_extents(bluefs_fnode_t& other) {
93 other.extents.swap(extents);
94 std::swap(allocated, other.allocated);
95 }
96 void swap_extents(mempool::bluefs::vector<bluefs_extent_t>& swap_to, uint64_t& new_allocated) {
97 swap_to.swap(extents);
98 std::swap(allocated, new_allocated);
99 }
100 void clear_extents() {
101 extents.clear();
102 allocated = 0;
103 }
104
7c673cae
FG
105 mempool::bluefs::vector<bluefs_extent_t>::iterator seek(
106 uint64_t off, uint64_t *x_off);
107
108 void dump(Formatter *f) const;
109 static void generate_test_instances(list<bluefs_fnode_t*>& ls);
94b18763 110
7c673cae
FG
111};
112WRITE_CLASS_DENC(bluefs_fnode_t)
113
114ostream& operator<<(ostream& out, const bluefs_fnode_t& file);
115
116
117struct bluefs_super_t {
118 uuid_d uuid; ///< unique to this bluefs instance
119 uuid_d osd_uuid; ///< matches the osd that owns us
120 uint64_t version;
121 uint32_t block_size;
122
123 bluefs_fnode_t log_fnode;
124
125 bluefs_super_t()
126 : version(0),
127 block_size(4096) { }
128
129 uint64_t block_mask() const {
28e407b8 130 return ~((uint64_t)block_size - 1);
7c673cae
FG
131 }
132
133 void encode(bufferlist& bl) const;
134 void decode(bufferlist::iterator& p);
135 void dump(Formatter *f) const;
136 static void generate_test_instances(list<bluefs_super_t*>& ls);
137};
138WRITE_CLASS_ENCODER(bluefs_super_t)
139
140ostream& operator<<(ostream&, const bluefs_super_t& s);
141
142
143struct bluefs_transaction_t {
144 typedef enum {
145 OP_NONE = 0,
146 OP_INIT, ///< initial (empty) file system marker
147 OP_ALLOC_ADD, ///< add extent to available block storage (extent)
148 OP_ALLOC_RM, ///< remove extent from availabe block storage (extent)
149 OP_DIR_LINK, ///< (re)set a dir entry (dirname, filename, ino)
150 OP_DIR_UNLINK, ///< remove a dir entry (dirname, filename)
151 OP_DIR_CREATE, ///< create a dir (dirname)
152 OP_DIR_REMOVE, ///< remove a dir (dirname)
153 OP_FILE_UPDATE, ///< set/update file metadata (file)
154 OP_FILE_REMOVE, ///< remove file (ino)
155 OP_JUMP, ///< jump the seq # and offset
156 OP_JUMP_SEQ, ///< jump the seq #
157 } op_t;
158
159 uuid_d uuid; ///< fs uuid
160 uint64_t seq; ///< sequence number
161 bufferlist op_bl; ///< encoded transaction ops
162
163 bluefs_transaction_t() : seq(0) {}
164
165 void clear() {
166 *this = bluefs_transaction_t();
167 }
168 bool empty() const {
169 return op_bl.length() == 0;
170 }
171
172 void op_init() {
173 ::encode((__u8)OP_INIT, op_bl);
174 }
175 void op_alloc_add(uint8_t id, uint64_t offset, uint64_t length) {
176 ::encode((__u8)OP_ALLOC_ADD, op_bl);
177 ::encode(id, op_bl);
178 ::encode(offset, op_bl);
179 ::encode(length, op_bl);
180 }
181 void op_alloc_rm(uint8_t id, uint64_t offset, uint64_t length) {
182 ::encode((__u8)OP_ALLOC_RM, op_bl);
183 ::encode(id, op_bl);
184 ::encode(offset, op_bl);
185 ::encode(length, op_bl);
186 }
187 void op_dir_create(const string& dir) {
188 ::encode((__u8)OP_DIR_CREATE, op_bl);
189 ::encode(dir, op_bl);
190 }
191 void op_dir_remove(const string& dir) {
192 ::encode((__u8)OP_DIR_REMOVE, op_bl);
193 ::encode(dir, op_bl);
194 }
195 void op_dir_link(const string& dir, const string& file, uint64_t ino) {
196 ::encode((__u8)OP_DIR_LINK, op_bl);
197 ::encode(dir, op_bl);
198 ::encode(file, op_bl);
199 ::encode(ino, op_bl);
200 }
201 void op_dir_unlink(const string& dir, const string& file) {
202 ::encode((__u8)OP_DIR_UNLINK, op_bl);
203 ::encode(dir, op_bl);
204 ::encode(file, op_bl);
205 }
206 void op_file_update(const bluefs_fnode_t& file) {
207 ::encode((__u8)OP_FILE_UPDATE, op_bl);
208 ::encode(file, op_bl);
209 }
210 void op_file_remove(uint64_t ino) {
211 ::encode((__u8)OP_FILE_REMOVE, op_bl);
212 ::encode(ino, op_bl);
213 }
214 void op_jump(uint64_t next_seq, uint64_t offset) {
215 ::encode((__u8)OP_JUMP, op_bl);
216 ::encode(next_seq, op_bl);
217 ::encode(offset, op_bl);
218 }
219 void op_jump_seq(uint64_t next_seq) {
220 ::encode((__u8)OP_JUMP_SEQ, op_bl);
221 ::encode(next_seq, op_bl);
222 }
223
224 void encode(bufferlist& bl) const;
225 void decode(bufferlist::iterator& p);
226 void dump(Formatter *f) const;
227 static void generate_test_instance(list<bluefs_transaction_t*>& ls);
228};
229WRITE_CLASS_ENCODER(bluefs_transaction_t)
230
231ostream& operator<<(ostream& out, const bluefs_transaction_t& t);
232
233#endif