]>
git.proxmox.com Git - ceph.git/blob - 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
6 #include "bluestore_types.h"
7 #include "include/utime.h"
8 #include "include/encoding.h"
9 #include "include/denc.h"
11 class bluefs_extent_t
{
17 bluefs_extent_t(uint8_t b
= 0, uint64_t o
= 0, uint32_t l
= 0)
18 : offset(o
), length(l
), bdev(b
) {}
20 uint64_t end() const { return offset
+ length
; }
21 DENC(bluefs_extent_t
, v
, p
) {
23 denc_lba(v
.offset
, p
);
24 denc_varint_lowz(v
.length
, p
);
29 void dump(Formatter
*f
) const;
30 static void generate_test_instances(list
<bluefs_extent_t
*>&);
32 WRITE_CLASS_DENC(bluefs_extent_t
)
34 ostream
& operator<<(ostream
& out
, const bluefs_extent_t
& e
);
37 struct bluefs_fnode_t
{
42 mempool::bluefs::vector
<bluefs_extent_t
> extents
;
44 // precalculated logical offsets for extents vector entries
45 // allows fast lookup for extent index by the offset value via upper_bound()
46 mempool::bluefs::vector
<uint64_t> extents_index
;
50 bluefs_fnode_t() : ino(0), size(0), prefer_bdev(0), allocated(0) {}
52 uint64_t get_allocated() const {
56 void recalc_allocated() {
58 extents_index
.reserve(extents
.size());
59 for (auto& p
: extents
) {
60 extents_index
.emplace_back(allocated
);
61 allocated
+= p
.length
;
66 void bound_encode(size_t& p
) const {
67 _denc_friend(*this, p
);
69 void encode(bufferlist::contiguous_appender
& p
) const {
70 DENC_DUMP_PRE(bluefs_fnode_t
);
71 _denc_friend(*this, p
);
72 DENC_DUMP_POST(bluefs_fnode_t
);
74 void decode(buffer::ptr::const_iterator
& p
) {
75 _denc_friend(*this, p
);
78 template<typename T
, typename P
>
79 friend std::enable_if_t
<std::is_same_v
<bluefs_fnode_t
, std::remove_const_t
<T
>>>
80 _denc_friend(T
& v
, P
& p
) {
82 denc_varint(v
.ino
, p
);
83 denc_varint(v
.size
, p
);
85 denc(v
.prefer_bdev
, p
);
90 void append_extent(const bluefs_extent_t
& ext
) {
91 if (!extents
.empty() &&
92 extents
.back().end() == ext
.offset
&&
93 extents
.back().bdev
== ext
.bdev
&&
94 (uint64_t)extents
.back().length
+ (uint64_t)ext
.length
< 0xffffffff) {
95 extents
.back().length
+= ext
.length
;
97 extents_index
.emplace_back(allocated
);
98 extents
.push_back(ext
);
100 allocated
+= ext
.length
;
103 void pop_front_extent() {
104 auto it
= extents
.begin();
105 allocated
-= it
->length
;
106 extents_index
.erase(extents_index
.begin());
107 for (auto& i
: extents_index
) {
113 void swap_extents(bluefs_fnode_t
& other
) {
114 other
.extents
.swap(extents
);
115 other
.extents_index
.swap(extents_index
);
116 std::swap(allocated
, other
.allocated
);
118 void clear_extents() {
119 extents_index
.clear();
124 mempool::bluefs::vector
<bluefs_extent_t
>::iterator
seek(
125 uint64_t off
, uint64_t *x_off
);
127 void dump(Formatter
*f
) const;
128 static void generate_test_instances(list
<bluefs_fnode_t
*>& ls
);
131 WRITE_CLASS_DENC(bluefs_fnode_t
)
133 ostream
& operator<<(ostream
& out
, const bluefs_fnode_t
& file
);
136 struct bluefs_super_t
{
137 uuid_d uuid
; ///< unique to this bluefs instance
138 uuid_d osd_uuid
; ///< matches the osd that owns us
142 bluefs_fnode_t log_fnode
;
148 uint64_t block_mask() const {
149 return ~((uint64_t)block_size
- 1);
152 void encode(bufferlist
& bl
) const;
153 void decode(bufferlist::const_iterator
& p
);
154 void dump(Formatter
*f
) const;
155 static void generate_test_instances(list
<bluefs_super_t
*>& ls
);
157 WRITE_CLASS_ENCODER(bluefs_super_t
)
159 ostream
& operator<<(ostream
&, const bluefs_super_t
& s
);
162 struct bluefs_transaction_t
{
165 OP_INIT
, ///< initial (empty) file system marker
166 OP_ALLOC_ADD
, ///< add extent to available block storage (extent)
167 OP_ALLOC_RM
, ///< remove extent from available block storage (extent)
168 OP_DIR_LINK
, ///< (re)set a dir entry (dirname, filename, ino)
169 OP_DIR_UNLINK
, ///< remove a dir entry (dirname, filename)
170 OP_DIR_CREATE
, ///< create a dir (dirname)
171 OP_DIR_REMOVE
, ///< remove a dir (dirname)
172 OP_FILE_UPDATE
, ///< set/update file metadata (file)
173 OP_FILE_REMOVE
, ///< remove file (ino)
174 OP_JUMP
, ///< jump the seq # and offset
175 OP_JUMP_SEQ
, ///< jump the seq #
178 uuid_d uuid
; ///< fs uuid
179 uint64_t seq
; ///< sequence number
180 bufferlist op_bl
; ///< encoded transaction ops
182 bluefs_transaction_t() : seq(0) {}
185 *this = bluefs_transaction_t();
188 return op_bl
.length() == 0;
193 encode((__u8
)OP_INIT
, op_bl
);
195 void op_alloc_add(uint8_t id
, uint64_t offset
, uint64_t length
) {
197 encode((__u8
)OP_ALLOC_ADD
, op_bl
);
199 encode(offset
, op_bl
);
200 encode(length
, op_bl
);
202 void op_alloc_rm(uint8_t id
, uint64_t offset
, uint64_t length
) {
204 encode((__u8
)OP_ALLOC_RM
, op_bl
);
206 encode(offset
, op_bl
);
207 encode(length
, op_bl
);
209 void op_dir_create(const string
& dir
) {
211 encode((__u8
)OP_DIR_CREATE
, op_bl
);
214 void op_dir_remove(const string
& dir
) {
216 encode((__u8
)OP_DIR_REMOVE
, op_bl
);
219 void op_dir_link(const string
& dir
, const string
& file
, uint64_t ino
) {
221 encode((__u8
)OP_DIR_LINK
, op_bl
);
226 void op_dir_unlink(const string
& dir
, const string
& file
) {
228 encode((__u8
)OP_DIR_UNLINK
, op_bl
);
232 void op_file_update(const bluefs_fnode_t
& file
) {
234 encode((__u8
)OP_FILE_UPDATE
, op_bl
);
237 void op_file_remove(uint64_t ino
) {
239 encode((__u8
)OP_FILE_REMOVE
, op_bl
);
242 void op_jump(uint64_t next_seq
, uint64_t offset
) {
244 encode((__u8
)OP_JUMP
, op_bl
);
245 encode(next_seq
, op_bl
);
246 encode(offset
, op_bl
);
248 void op_jump_seq(uint64_t next_seq
) {
250 encode((__u8
)OP_JUMP_SEQ
, op_bl
);
251 encode(next_seq
, op_bl
);
253 void claim_ops(bluefs_transaction_t
& from
) {
254 op_bl
.claim_append(from
.op_bl
);
257 void encode(bufferlist
& bl
) const;
258 void decode(bufferlist::const_iterator
& p
);
259 void dump(Formatter
*f
) const;
260 static void generate_test_instances(list
<bluefs_transaction_t
*>& ls
);
262 WRITE_CLASS_ENCODER(bluefs_transaction_t
)
264 ostream
& operator<<(ostream
& out
, const bluefs_transaction_t
& t
);