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;
54 DENC(bluefs_fnode_t, v, p) {
56 denc_varint(v.ino, p);
57 denc_varint(v.size, p);
59 denc(v.prefer_bdev, p);
64 mempool::bluefs::vector<bluefs_extent_t>::iterator seek(
65 uint64_t off, uint64_t *x_off);
67 void dump(Formatter *f) const;
68 static void generate_test_instances(list<bluefs_fnode_t*>& ls);
70 WRITE_CLASS_DENC(bluefs_fnode_t)
72 ostream& operator<<(ostream& out, const bluefs_fnode_t& file);
75 struct bluefs_super_t {
76 uuid_d uuid; ///< unique to this bluefs instance
77 uuid_d osd_uuid; ///< matches the osd that owns us
81 bluefs_fnode_t log_fnode;
87 uint64_t block_mask() const {
88 return ~(block_size - 1);
91 void encode(bufferlist& bl) const;
92 void decode(bufferlist::iterator& p);
93 void dump(Formatter *f) const;
94 static void generate_test_instances(list<bluefs_super_t*>& ls);
96 WRITE_CLASS_ENCODER(bluefs_super_t)
98 ostream& operator<<(ostream&, const bluefs_super_t& s);
101 struct bluefs_transaction_t {
104 OP_INIT, ///< initial (empty) file system marker
105 OP_ALLOC_ADD, ///< add extent to available block storage (extent)
106 OP_ALLOC_RM, ///< remove extent from availabe block storage (extent)
107 OP_DIR_LINK, ///< (re)set a dir entry (dirname, filename, ino)
108 OP_DIR_UNLINK, ///< remove a dir entry (dirname, filename)
109 OP_DIR_CREATE, ///< create a dir (dirname)
110 OP_DIR_REMOVE, ///< remove a dir (dirname)
111 OP_FILE_UPDATE, ///< set/update file metadata (file)
112 OP_FILE_REMOVE, ///< remove file (ino)
113 OP_JUMP, ///< jump the seq # and offset
114 OP_JUMP_SEQ, ///< jump the seq #
117 uuid_d uuid; ///< fs uuid
118 uint64_t seq; ///< sequence number
119 bufferlist op_bl; ///< encoded transaction ops
121 bluefs_transaction_t() : seq(0) {}
124 *this = bluefs_transaction_t();
127 return op_bl.length() == 0;
131 ::encode((__u8)OP_INIT, op_bl);
133 void op_alloc_add(uint8_t id, uint64_t offset, uint64_t length) {
134 ::encode((__u8)OP_ALLOC_ADD, op_bl);
136 ::encode(offset, op_bl);
137 ::encode(length, op_bl);
139 void op_alloc_rm(uint8_t id, uint64_t offset, uint64_t length) {
140 ::encode((__u8)OP_ALLOC_RM, op_bl);
142 ::encode(offset, op_bl);
143 ::encode(length, op_bl);
145 void op_dir_create(const string& dir) {
146 ::encode((__u8)OP_DIR_CREATE, op_bl);
147 ::encode(dir, op_bl);
149 void op_dir_remove(const string& dir) {
150 ::encode((__u8)OP_DIR_REMOVE, op_bl);
151 ::encode(dir, op_bl);
153 void op_dir_link(const string& dir, const string& file, uint64_t ino) {
154 ::encode((__u8)OP_DIR_LINK, op_bl);
155 ::encode(dir, op_bl);
156 ::encode(file, op_bl);
157 ::encode(ino, op_bl);
159 void op_dir_unlink(const string& dir, const string& file) {
160 ::encode((__u8)OP_DIR_UNLINK, op_bl);
161 ::encode(dir, op_bl);
162 ::encode(file, op_bl);
164 void op_file_update(const bluefs_fnode_t& file) {
165 ::encode((__u8)OP_FILE_UPDATE, op_bl);
166 ::encode(file, op_bl);
168 void op_file_remove(uint64_t ino) {
169 ::encode((__u8)OP_FILE_REMOVE, op_bl);
170 ::encode(ino, op_bl);
172 void op_jump(uint64_t next_seq, uint64_t offset) {
173 ::encode((__u8)OP_JUMP, op_bl);
174 ::encode(next_seq, op_bl);
175 ::encode(offset, op_bl);
177 void op_jump_seq(uint64_t next_seq) {
178 ::encode((__u8)OP_JUMP_SEQ, op_bl);
179 ::encode(next_seq, op_bl);
182 void encode(bufferlist& bl) const;
183 void decode(bufferlist::iterator& p);
184 void dump(Formatter *f) const;
185 static void generate_test_instance(list<bluefs_transaction_t*>& ls);
187 WRITE_CLASS_ENCODER(bluefs_transaction_t)
189 ostream& operator<<(ostream& out, const bluefs_transaction_t& t);