]> git.proxmox.com Git - ceph.git/blame - ceph/src/os/bluestore/bluefs_types.h
update sources to v12.1.0
[ceph.git] / ceph / src / os / bluestore / bluefs_types.h
CommitLineData
7c673cae
FG
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
11class bluefs_extent_t : public AllocExtent{
12public:
13 uint8_t bdev;
14
15 bluefs_extent_t(uint8_t b = 0, uint64_t o = 0, uint32_t l = 0)
16 : AllocExtent(o, l), bdev(b) {}
17
18 DENC(bluefs_extent_t, v, p) {
19 DENC_START(1, 1, p);
20 denc_lba(v.offset, p);
21 denc_varint_lowz(v.length, p);
22 denc(v.bdev, p);
23 DENC_FINISH(p);
24 }
25
26 void dump(Formatter *f) const;
27 static void generate_test_instances(list<bluefs_extent_t*>&);
28};
29WRITE_CLASS_DENC(bluefs_extent_t)
30
31f18b77 31ostream& operator<<(ostream& out, const bluefs_extent_t& e);
7c673cae
FG
32
33
34struct bluefs_fnode_t {
35 uint64_t ino;
36 uint64_t size;
37 utime_t mtime;
38 uint8_t prefer_bdev;
39 mempool::bluefs::vector<bluefs_extent_t> extents;
40 uint64_t allocated;
41
42 bluefs_fnode_t() : ino(0), size(0), prefer_bdev(0), allocated(0) {}
43
44 uint64_t get_allocated() const {
45 return allocated;
46 }
47
48 void recalc_allocated() {
49 allocated = 0;
50 for (auto& p : extents)
51 allocated += p.length;
52 }
53
54 DENC(bluefs_fnode_t, v, p) {
55 DENC_START(1, 1, p);
56 denc_varint(v.ino, p);
57 denc_varint(v.size, p);
58 denc(v.mtime, p);
59 denc(v.prefer_bdev, p);
60 denc(v.extents, p);
61 DENC_FINISH(p);
62 }
63
64 mempool::bluefs::vector<bluefs_extent_t>::iterator seek(
65 uint64_t off, uint64_t *x_off);
66
67 void dump(Formatter *f) const;
68 static void generate_test_instances(list<bluefs_fnode_t*>& ls);
69};
70WRITE_CLASS_DENC(bluefs_fnode_t)
71
72ostream& operator<<(ostream& out, const bluefs_fnode_t& file);
73
74
75struct bluefs_super_t {
76 uuid_d uuid; ///< unique to this bluefs instance
77 uuid_d osd_uuid; ///< matches the osd that owns us
78 uint64_t version;
79 uint32_t block_size;
80
81 bluefs_fnode_t log_fnode;
82
83 bluefs_super_t()
84 : version(0),
85 block_size(4096) { }
86
87 uint64_t block_mask() const {
88 return ~(block_size - 1);
89 }
90
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);
95};
96WRITE_CLASS_ENCODER(bluefs_super_t)
97
98ostream& operator<<(ostream&, const bluefs_super_t& s);
99
100
101struct bluefs_transaction_t {
102 typedef enum {
103 OP_NONE = 0,
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 #
115 } op_t;
116
117 uuid_d uuid; ///< fs uuid
118 uint64_t seq; ///< sequence number
119 bufferlist op_bl; ///< encoded transaction ops
120
121 bluefs_transaction_t() : seq(0) {}
122
123 void clear() {
124 *this = bluefs_transaction_t();
125 }
126 bool empty() const {
127 return op_bl.length() == 0;
128 }
129
130 void op_init() {
131 ::encode((__u8)OP_INIT, op_bl);
132 }
133 void op_alloc_add(uint8_t id, uint64_t offset, uint64_t length) {
134 ::encode((__u8)OP_ALLOC_ADD, op_bl);
135 ::encode(id, op_bl);
136 ::encode(offset, op_bl);
137 ::encode(length, op_bl);
138 }
139 void op_alloc_rm(uint8_t id, uint64_t offset, uint64_t length) {
140 ::encode((__u8)OP_ALLOC_RM, op_bl);
141 ::encode(id, op_bl);
142 ::encode(offset, op_bl);
143 ::encode(length, op_bl);
144 }
145 void op_dir_create(const string& dir) {
146 ::encode((__u8)OP_DIR_CREATE, op_bl);
147 ::encode(dir, op_bl);
148 }
149 void op_dir_remove(const string& dir) {
150 ::encode((__u8)OP_DIR_REMOVE, op_bl);
151 ::encode(dir, op_bl);
152 }
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);
158 }
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);
163 }
164 void op_file_update(const bluefs_fnode_t& file) {
165 ::encode((__u8)OP_FILE_UPDATE, op_bl);
166 ::encode(file, op_bl);
167 }
168 void op_file_remove(uint64_t ino) {
169 ::encode((__u8)OP_FILE_REMOVE, op_bl);
170 ::encode(ino, op_bl);
171 }
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);
176 }
177 void op_jump_seq(uint64_t next_seq) {
178 ::encode((__u8)OP_JUMP_SEQ, op_bl);
179 ::encode(next_seq, op_bl);
180 }
181
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);
186};
187WRITE_CLASS_ENCODER(bluefs_transaction_t)
188
189ostream& operator<<(ostream& out, const bluefs_transaction_t& t);
190
191#endif