]>
Commit | Line | Data |
---|---|---|
7c673cae FG |
1 | // -*- mode:C++; tab-width:8; c-basic-offset:2; indent-tabs-mode:t -*- |
2 | // vim: ts=8 sw=2 smarttab | |
3 | ||
4 | #include "bluefs_types.h" | |
5 | #include "common/Formatter.h" | |
6 | #include "include/uuid.h" | |
7 | #include "include/stringify.h" | |
8 | ||
9 | // bluefs_extent_t | |
10 | void bluefs_extent_t::dump(Formatter *f) const | |
11 | { | |
12 | f->dump_unsigned("offset", offset); | |
13 | f->dump_unsigned("length", length); | |
14 | f->dump_unsigned("bdev", bdev); | |
15 | } | |
16 | ||
17 | void bluefs_extent_t::generate_test_instances(list<bluefs_extent_t*>& ls) | |
18 | { | |
19 | ls.push_back(new bluefs_extent_t); | |
20 | ls.push_back(new bluefs_extent_t); | |
21 | ls.back()->offset = 1; | |
22 | ls.back()->length = 2; | |
23 | ls.back()->bdev = 1; | |
24 | } | |
25 | ||
31f18b77 | 26 | ostream& operator<<(ostream& out, const bluefs_extent_t& e) |
7c673cae FG |
27 | { |
28 | return out << (int)e.bdev << ":0x" << std::hex << e.offset << "+" << e.length | |
29 | << std::dec; | |
30 | } | |
31 | ||
32 | // bluefs_super_t | |
33 | ||
34 | void bluefs_super_t::encode(bufferlist& bl) const | |
35 | { | |
36 | ENCODE_START(1, 1, bl); | |
37 | ::encode(uuid, bl); | |
38 | ::encode(osd_uuid, bl); | |
39 | ::encode(version, bl); | |
40 | ::encode(block_size, bl); | |
41 | ::encode(log_fnode, bl); | |
42 | ENCODE_FINISH(bl); | |
43 | } | |
44 | ||
45 | void bluefs_super_t::decode(bufferlist::iterator& p) | |
46 | { | |
47 | DECODE_START(1, p); | |
48 | ::decode(uuid, p); | |
49 | ::decode(osd_uuid, p); | |
50 | ::decode(version, p); | |
51 | ::decode(block_size, p); | |
52 | ::decode(log_fnode, p); | |
53 | DECODE_FINISH(p); | |
54 | } | |
55 | ||
56 | void bluefs_super_t::dump(Formatter *f) const | |
57 | { | |
58 | f->dump_stream("uuid") << uuid; | |
59 | f->dump_stream("osd_uuid") << osd_uuid; | |
60 | f->dump_unsigned("version", version); | |
61 | f->dump_unsigned("block_size", block_size); | |
62 | f->dump_object("log_fnode", log_fnode); | |
63 | } | |
64 | ||
65 | void bluefs_super_t::generate_test_instances(list<bluefs_super_t*>& ls) | |
66 | { | |
67 | ls.push_back(new bluefs_super_t); | |
68 | ls.push_back(new bluefs_super_t); | |
69 | ls.back()->version = 1; | |
70 | ls.back()->block_size = 4096; | |
71 | } | |
72 | ||
73 | ostream& operator<<(ostream& out, const bluefs_super_t& s) | |
74 | { | |
75 | return out << "super(uuid " << s.uuid | |
76 | << " osd " << s.osd_uuid | |
77 | << " v " << s.version | |
78 | << " block_size 0x" << std::hex << s.block_size | |
79 | << " log_fnode 0x" << s.log_fnode | |
80 | << std::dec << ")"; | |
81 | } | |
82 | ||
83 | // bluefs_fnode_t | |
84 | ||
85 | mempool::bluefs::vector<bluefs_extent_t>::iterator bluefs_fnode_t::seek( | |
86 | uint64_t offset, uint64_t *x_off) | |
87 | { | |
88 | auto p = extents.begin(); | |
89 | while (p != extents.end()) { | |
90 | if ((int64_t) offset >= p->length) { | |
91 | offset -= p->length; | |
92 | ++p; | |
93 | } else { | |
94 | break; | |
95 | } | |
96 | } | |
97 | *x_off = offset; | |
98 | return p; | |
99 | } | |
100 | ||
101 | void bluefs_fnode_t::dump(Formatter *f) const | |
102 | { | |
103 | f->dump_unsigned("ino", ino); | |
104 | f->dump_unsigned("size", size); | |
105 | f->dump_stream("mtime") << mtime; | |
106 | f->dump_unsigned("prefer_bdev", prefer_bdev); | |
107 | f->open_array_section("extents"); | |
108 | for (auto& p : extents) | |
109 | f->dump_object("extent", p); | |
110 | f->close_section(); | |
111 | } | |
112 | ||
113 | void bluefs_fnode_t::generate_test_instances(list<bluefs_fnode_t*>& ls) | |
114 | { | |
115 | ls.push_back(new bluefs_fnode_t); | |
116 | ls.push_back(new bluefs_fnode_t); | |
117 | ls.back()->ino = 123; | |
118 | ls.back()->size = 1048576; | |
119 | ls.back()->mtime = utime_t(123,45); | |
120 | ls.back()->extents.push_back(bluefs_extent_t(0, 1048576, 4096)); | |
121 | ls.back()->prefer_bdev = 1; | |
122 | } | |
123 | ||
124 | ostream& operator<<(ostream& out, const bluefs_fnode_t& file) | |
125 | { | |
126 | return out << "file(ino " << file.ino | |
127 | << " size 0x" << std::hex << file.size << std::dec | |
128 | << " mtime " << file.mtime | |
129 | << " bdev " << (int)file.prefer_bdev | |
130 | << " extents " << file.extents | |
131 | << ")"; | |
132 | } | |
133 | ||
134 | ||
135 | // bluefs_transaction_t | |
136 | ||
137 | void bluefs_transaction_t::encode(bufferlist& bl) const | |
138 | { | |
139 | uint32_t crc = op_bl.crc32c(-1); | |
140 | ENCODE_START(1, 1, bl); | |
141 | ::encode(uuid, bl); | |
142 | ::encode(seq, bl); | |
143 | ::encode(op_bl, bl); | |
144 | ::encode(crc, bl); | |
145 | ENCODE_FINISH(bl); | |
146 | } | |
147 | ||
148 | void bluefs_transaction_t::decode(bufferlist::iterator& p) | |
149 | { | |
150 | uint32_t crc; | |
151 | DECODE_START(1, p); | |
152 | ::decode(uuid, p); | |
153 | ::decode(seq, p); | |
154 | ::decode(op_bl, p); | |
155 | ::decode(crc, p); | |
156 | DECODE_FINISH(p); | |
157 | uint32_t actual = op_bl.crc32c(-1); | |
158 | if (actual != crc) | |
159 | throw buffer::malformed_input("bad crc " + stringify(actual) | |
160 | + " expected " + stringify(crc)); | |
161 | } | |
162 | ||
163 | void bluefs_transaction_t::dump(Formatter *f) const | |
164 | { | |
165 | f->dump_stream("uuid") << uuid; | |
166 | f->dump_unsigned("seq", seq); | |
167 | f->dump_unsigned("op_bl_length", op_bl.length()); | |
168 | f->dump_unsigned("crc", op_bl.crc32c(-1)); | |
169 | } | |
170 | ||
171 | void bluefs_transaction_t::generate_test_instance( | |
172 | list<bluefs_transaction_t*>& ls) | |
173 | { | |
174 | ls.push_back(new bluefs_transaction_t); | |
175 | ls.push_back(new bluefs_transaction_t); | |
176 | ls.back()->op_init(); | |
177 | ls.back()->op_alloc_add(0, 0, 123123211); | |
178 | ls.back()->op_alloc_rm(1, 0, 123); | |
179 | ls.back()->op_dir_create("dir"); | |
180 | ls.back()->op_dir_create("dir2"); | |
181 | bluefs_fnode_t fnode; | |
182 | fnode.ino = 2; | |
183 | ls.back()->op_file_update(fnode); | |
184 | ls.back()->op_dir_link("dir", "file1", 2); | |
185 | ls.back()->op_dir_unlink("dir", "file1"); | |
186 | ls.back()->op_file_remove(2); | |
187 | ls.back()->op_dir_remove("dir2"); | |
188 | } | |
189 | ||
190 | ostream& operator<<(ostream& out, const bluefs_transaction_t& t) | |
191 | { | |
192 | return out << "txn(seq " << t.seq | |
193 | << " len 0x" << std::hex << t.op_bl.length() | |
194 | << " crc 0x" << t.op_bl.crc32c(-1) | |
195 | << std::dec << ")"; | |
196 | } |