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