]>
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
;
45 bluefs_fnode_t() : ino(0), size(0), prefer_bdev(0), allocated(0) {}
47 uint64_t get_allocated() const {
51 void recalc_allocated() {
53 for (auto& p
: extents
)
54 allocated
+= p
.length
;
58 void bound_encode(size_t& p
) const {
59 _denc_friend(*this, p
);
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
);
66 void decode(buffer::ptr::const_iterator
& p
) {
67 _denc_friend(*this, p
);
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
) {
74 denc_varint(v
.ino
, p
);
75 denc_varint(v
.size
, p
);
77 denc(v
.prefer_bdev
, p
);
82 void append_extent(const bluefs_extent_t
& ext
) {
83 extents
.push_back(ext
);
84 allocated
+= ext
.length
;
87 void pop_front_extent() {
88 auto it
= extents
.begin();
89 allocated
-= it
->length
;
93 void swap_extents(bluefs_fnode_t
& other
) {
94 other
.extents
.swap(extents
);
95 std::swap(allocated
, other
.allocated
);
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
);
101 void clear_extents() {
106 mempool::bluefs::vector
<bluefs_extent_t
>::iterator
seek(
107 uint64_t off
, uint64_t *x_off
);
109 void dump(Formatter
*f
) const;
110 static void generate_test_instances(list
<bluefs_fnode_t
*>& ls
);
113 WRITE_CLASS_DENC(bluefs_fnode_t
)
115 ostream
& operator<<(ostream
& out
, const bluefs_fnode_t
& file
);
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
124 bluefs_fnode_t log_fnode
;
130 uint64_t block_mask() const {
131 return ~((uint64_t)block_size
- 1);
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
);
139 WRITE_CLASS_ENCODER(bluefs_super_t
)
141 ostream
& operator<<(ostream
&, const bluefs_super_t
& s
);
144 struct bluefs_transaction_t
{
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 #
160 uuid_d uuid
; ///< fs uuid
161 uint64_t seq
; ///< sequence number
162 bufferlist op_bl
; ///< encoded transaction ops
164 bluefs_transaction_t() : seq(0) {}
167 *this = bluefs_transaction_t();
170 return op_bl
.length() == 0;
175 encode((__u8
)OP_INIT
, op_bl
);
177 void op_alloc_add(uint8_t id
, uint64_t offset
, uint64_t length
) {
179 encode((__u8
)OP_ALLOC_ADD
, op_bl
);
181 encode(offset
, op_bl
);
182 encode(length
, op_bl
);
184 void op_alloc_rm(uint8_t id
, uint64_t offset
, uint64_t length
) {
186 encode((__u8
)OP_ALLOC_RM
, op_bl
);
188 encode(offset
, op_bl
);
189 encode(length
, op_bl
);
191 void op_dir_create(const string
& dir
) {
193 encode((__u8
)OP_DIR_CREATE
, op_bl
);
196 void op_dir_remove(const string
& dir
) {
198 encode((__u8
)OP_DIR_REMOVE
, op_bl
);
201 void op_dir_link(const string
& dir
, const string
& file
, uint64_t ino
) {
203 encode((__u8
)OP_DIR_LINK
, op_bl
);
208 void op_dir_unlink(const string
& dir
, const string
& file
) {
210 encode((__u8
)OP_DIR_UNLINK
, op_bl
);
214 void op_file_update(const bluefs_fnode_t
& file
) {
216 encode((__u8
)OP_FILE_UPDATE
, op_bl
);
219 void op_file_remove(uint64_t ino
) {
221 encode((__u8
)OP_FILE_REMOVE
, op_bl
);
224 void op_jump(uint64_t next_seq
, uint64_t offset
) {
226 encode((__u8
)OP_JUMP
, op_bl
);
227 encode(next_seq
, op_bl
);
228 encode(offset
, op_bl
);
230 void op_jump_seq(uint64_t next_seq
) {
232 encode((__u8
)OP_JUMP_SEQ
, op_bl
);
233 encode(next_seq
, op_bl
);
235 void claim_ops(bluefs_transaction_t
& from
) {
236 op_bl
.claim_append(from
.op_bl
);
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
);
244 WRITE_CLASS_ENCODER(bluefs_transaction_t
)
246 ostream
& operator<<(ostream
& out
, const bluefs_transaction_t
& t
);