]>
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
: public AllocExtent
{
15 bluefs_extent_t(uint8_t b
= 0, uint64_t o
= 0, uint32_t l
= 0)
16 : AllocExtent(o
, l
), bdev(b
) {}
18 DENC(bluefs_extent_t
, v
, p
) {
20 denc_lba(v
.offset
, p
);
21 denc_varint_lowz(v
.length
, p
);
26 void dump(Formatter
*f
) const;
27 static void generate_test_instances(list
<bluefs_extent_t
*>&);
29 WRITE_CLASS_DENC(bluefs_extent_t
)
31 ostream
& operator<<(ostream
& out
, const bluefs_extent_t
& e
);
34 struct bluefs_fnode_t
{
39 mempool::bluefs::vector
<bluefs_extent_t
> extents
;
42 bluefs_fnode_t() : ino(0), size(0), prefer_bdev(0), allocated(0) {}
44 uint64_t get_allocated() const {
48 void recalc_allocated() {
50 for (auto& p
: extents
)
51 allocated
+= p
.length
;
55 void bound_encode(size_t& p
) const {
56 _denc_friend(*this, p
);
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
);
63 void decode(buffer::ptr::iterator
& p
) {
64 _denc_friend(*this, p
);
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
) {
73 denc_varint(v
.ino
, p
);
74 denc_varint(v
.size
, p
);
76 denc(v
.prefer_bdev
, p
);
81 void append_extent(const bluefs_extent_t
& ext
) {
82 extents
.push_back(ext
);
83 allocated
+= ext
.length
;
86 void pop_front_extent() {
87 auto it
= extents
.begin();
88 allocated
-= it
->length
;
92 void swap_extents(bluefs_fnode_t
& other
) {
93 other
.extents
.swap(extents
);
94 std::swap(allocated
, other
.allocated
);
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
);
100 void clear_extents() {
105 mempool::bluefs::vector
<bluefs_extent_t
>::iterator
seek(
106 uint64_t off
, uint64_t *x_off
);
108 void dump(Formatter
*f
) const;
109 static void generate_test_instances(list
<bluefs_fnode_t
*>& ls
);
112 WRITE_CLASS_DENC(bluefs_fnode_t
)
114 ostream
& operator<<(ostream
& out
, const bluefs_fnode_t
& file
);
117 struct bluefs_super_t
{
118 uuid_d uuid
; ///< unique to this bluefs instance
119 uuid_d osd_uuid
; ///< matches the osd that owns us
123 bluefs_fnode_t log_fnode
;
129 uint64_t block_mask() const {
130 return ~((uint64_t)block_size
- 1);
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
);
138 WRITE_CLASS_ENCODER(bluefs_super_t
)
140 ostream
& operator<<(ostream
&, const bluefs_super_t
& s
);
143 struct bluefs_transaction_t
{
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 #
159 uuid_d uuid
; ///< fs uuid
160 uint64_t seq
; ///< sequence number
161 bufferlist op_bl
; ///< encoded transaction ops
163 bluefs_transaction_t() : seq(0) {}
166 *this = bluefs_transaction_t();
169 return op_bl
.length() == 0;
173 ::encode((__u8
)OP_INIT
, op_bl
);
175 void op_alloc_add(uint8_t id
, uint64_t offset
, uint64_t length
) {
176 ::encode((__u8
)OP_ALLOC_ADD
, op_bl
);
178 ::encode(offset
, op_bl
);
179 ::encode(length
, op_bl
);
181 void op_alloc_rm(uint8_t id
, uint64_t offset
, uint64_t length
) {
182 ::encode((__u8
)OP_ALLOC_RM
, op_bl
);
184 ::encode(offset
, op_bl
);
185 ::encode(length
, op_bl
);
187 void op_dir_create(const string
& dir
) {
188 ::encode((__u8
)OP_DIR_CREATE
, op_bl
);
189 ::encode(dir
, op_bl
);
191 void op_dir_remove(const string
& dir
) {
192 ::encode((__u8
)OP_DIR_REMOVE
, op_bl
);
193 ::encode(dir
, op_bl
);
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
);
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
);
206 void op_file_update(const bluefs_fnode_t
& file
) {
207 ::encode((__u8
)OP_FILE_UPDATE
, op_bl
);
208 ::encode(file
, op_bl
);
210 void op_file_remove(uint64_t ino
) {
211 ::encode((__u8
)OP_FILE_REMOVE
, op_bl
);
212 ::encode(ino
, op_bl
);
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
);
219 void op_jump_seq(uint64_t next_seq
) {
220 ::encode((__u8
)OP_JUMP_SEQ
, op_bl
);
221 ::encode(next_seq
, op_bl
);
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
);
229 WRITE_CLASS_ENCODER(bluefs_transaction_t
)
231 ostream
& operator<<(ostream
& out
, const bluefs_transaction_t
& t
);