]> git.proxmox.com Git - ceph.git/blame - ceph/src/common/scrub_types.cc
import quincy beta 17.1.0
[ceph.git] / ceph / src / common / scrub_types.cc
CommitLineData
7c673cae
FG
1#include "scrub_types.h"
2
f67539c2
TL
3using std::map;
4
7c673cae
FG
5using namespace librados;
6
7void object_id_wrapper::encode(bufferlist& bl) const
8{
9 ENCODE_START(1, 1, bl);
11fdf7f2
TL
10 encode(name, bl);
11 encode(nspace, bl);
12 encode(locator, bl);
13 encode(snap, bl);
7c673cae
FG
14 ENCODE_FINISH(bl);
15}
16
11fdf7f2 17void object_id_wrapper::decode(bufferlist::const_iterator& bp)
7c673cae
FG
18{
19 DECODE_START(1, bp);
11fdf7f2
TL
20 decode(name, bp);
21 decode(nspace, bp);
22 decode(locator, bp);
23 decode(snap, bp);
7c673cae
FG
24 DECODE_FINISH(bp);
25}
26
11fdf7f2 27namespace librados {
7c673cae
FG
28static void encode(const object_id_t& obj, bufferlist& bl)
29{
30 reinterpret_cast<const object_id_wrapper&>(obj).encode(bl);
31}
11fdf7f2 32}
7c673cae
FG
33
34void osd_shard_wrapper::encode(bufferlist& bl) const
35{
36 ENCODE_START(1, 1, bl);
11fdf7f2
TL
37 encode(osd, bl);
38 encode(shard, bl);
7c673cae
FG
39 ENCODE_FINISH(bl);
40}
41
11fdf7f2 42void osd_shard_wrapper::decode(bufferlist::const_iterator& bp)
7c673cae
FG
43{
44 DECODE_START(1, bp);
11fdf7f2
TL
45 decode(osd, bp);
46 decode(shard, bp);
7c673cae
FG
47 DECODE_FINISH(bp);
48}
49
50namespace librados {
11fdf7f2
TL
51static void encode(const osd_shard_t& shard, bufferlist& bl) {
52 reinterpret_cast<const osd_shard_wrapper&>(shard).encode(bl);
53}
7c673cae
FG
54}
55
56void shard_info_wrapper::set_object(const ScrubMap::object& object)
57{
58 for (auto attr : object.attrs) {
59 bufferlist bl;
60 bl.push_back(attr.second);
61 attrs.insert(std::make_pair(attr.first, std::move(bl)));
62 }
63 size = object.size;
64 if (object.omap_digest_present) {
65 omap_digest_present = true;
66 omap_digest = object.omap_digest;
67 }
68 if (object.digest_present) {
69 data_digest_present = true;
70 data_digest = object.digest;
71 }
72}
73
74void shard_info_wrapper::encode(bufferlist& bl) const
75{
b5b8bbf5 76 ENCODE_START(3, 3, bl);
11fdf7f2
TL
77 encode(errors, bl);
78 encode(primary, bl);
79 if (!has_shard_missing()) {
80 encode(attrs, bl);
81 encode(size, bl);
82 encode(omap_digest_present, bl);
83 encode(omap_digest, bl);
84 encode(data_digest_present, bl);
85 encode(data_digest, bl);
86 encode(selected_oi, bl);
7c673cae 87 }
7c673cae
FG
88 ENCODE_FINISH(bl);
89}
90
11fdf7f2 91void shard_info_wrapper::decode(bufferlist::const_iterator& bp)
7c673cae 92{
b5b8bbf5 93 DECODE_START(3, bp);
11fdf7f2
TL
94 decode(errors, bp);
95 decode(primary, bp);
96 if (!has_shard_missing()) {
97 decode(attrs, bp);
98 decode(size, bp);
99 decode(omap_digest_present, bp);
100 decode(omap_digest, bp);
101 decode(data_digest_present, bp);
102 decode(data_digest, bp);
103 decode(selected_oi, bp);
7c673cae 104 }
7c673cae
FG
105 DECODE_FINISH(bp);
106}
107
108inconsistent_obj_wrapper::inconsistent_obj_wrapper(const hobject_t& hoid)
109 : inconsistent_obj_t{librados::object_id_t{hoid.oid.name,
110 hoid.nspace,
111 hoid.get_key(), hoid.snap}}
112{}
113
114void inconsistent_obj_wrapper::add_shard(const pg_shard_t& pgs,
115 const shard_info_wrapper& shard)
116{
117 union_shards.errors |= shard.errors;
118 shards.emplace(osd_shard_t{pgs.osd, int8_t(pgs.shard)}, shard);
119}
120
121void
122inconsistent_obj_wrapper::set_auth_missing(const hobject_t& hoid,
123 const map<pg_shard_t, ScrubMap*>& maps,
124 map<pg_shard_t, shard_info_wrapper> &shard_map,
b5b8bbf5
FG
125 int &shallow_errors, int &deep_errors,
126 const pg_shard_t &primary)
7c673cae
FG
127{
128 for (auto pg_map : maps) {
129 auto oid_object = pg_map.second->objects.find(hoid);
b5b8bbf5 130 shard_map[pg_map.first].primary = (pg_map.first == primary);
7c673cae
FG
131 if (oid_object == pg_map.second->objects.end())
132 shard_map[pg_map.first].set_missing();
133 else
134 shard_map[pg_map.first].set_object(oid_object->second);
135 if (shard_map[pg_map.first].has_deep_errors())
136 ++deep_errors;
137 else if (shard_map[pg_map.first].has_shallow_errors())
138 ++shallow_errors;
139 union_shards.errors |= shard_map[pg_map.first].errors;
140 shards.emplace(osd_shard_t{pg_map.first.osd, pg_map.first.shard}, shard_map[pg_map.first]);
141 }
142}
143
144namespace librados {
145 static void encode(const shard_info_t& shard, bufferlist& bl)
146 {
147 reinterpret_cast<const shard_info_wrapper&>(shard).encode(bl);
148 }
149}
150
151void inconsistent_obj_wrapper::encode(bufferlist& bl) const
152{
153 ENCODE_START(2, 2, bl);
11fdf7f2
TL
154 encode(errors, bl);
155 encode(object, bl);
156 encode(version, bl);
157 encode(shards, bl);
158 encode(union_shards.errors, bl);
7c673cae
FG
159 ENCODE_FINISH(bl);
160}
161
11fdf7f2 162void inconsistent_obj_wrapper::decode(bufferlist::const_iterator& bp)
7c673cae
FG
163{
164 DECODE_START(2, bp);
165 DECODE_OLDEST(2);
11fdf7f2
TL
166 decode(errors, bp);
167 decode(object, bp);
168 decode(version, bp);
169 decode(shards, bp);
170 decode(union_shards.errors, bp);
7c673cae
FG
171 DECODE_FINISH(bp);
172}
173
174inconsistent_snapset_wrapper::inconsistent_snapset_wrapper(const hobject_t& hoid)
175 : inconsistent_snapset_t{object_id_t{hoid.oid.name,
176 hoid.nspace,
177 hoid.get_key(),
178 hoid.snap}}
179{}
180
181using inc_snapset_t = inconsistent_snapset_t;
182
183void inconsistent_snapset_wrapper::set_headless()
184{
185 errors |= inc_snapset_t::HEADLESS_CLONE;
186}
187
94b18763 188void inconsistent_snapset_wrapper::set_snapset_missing()
7c673cae
FG
189{
190 errors |= inc_snapset_t::SNAPSET_MISSING;
191}
192
94b18763 193void inconsistent_snapset_wrapper::set_info_missing()
7c673cae 194{
94b18763 195 errors |= inc_snapset_t::INFO_MISSING;
7c673cae
FG
196}
197
94b18763 198void inconsistent_snapset_wrapper::set_snapset_corrupted()
7c673cae
FG
199{
200 errors |= inc_snapset_t::SNAPSET_CORRUPTED;
201}
202
94b18763 203void inconsistent_snapset_wrapper::set_info_corrupted()
7c673cae 204{
94b18763 205 errors |= inc_snapset_t::INFO_CORRUPTED;
7c673cae
FG
206}
207
208void inconsistent_snapset_wrapper::set_clone_missing(snapid_t snap)
209{
210 errors |= inc_snapset_t::CLONE_MISSING;
211 missing.push_back(snap);
212}
213
214void inconsistent_snapset_wrapper::set_clone(snapid_t snap)
215{
216 errors |= inc_snapset_t::EXTRA_CLONES;
217 clones.push_back(snap);
218}
219
94b18763 220void inconsistent_snapset_wrapper::set_snapset_error()
7c673cae 221{
94b18763 222 errors |= inc_snapset_t::SNAP_ERROR;
7c673cae
FG
223}
224
7c673cae
FG
225void inconsistent_snapset_wrapper::set_size_mismatch()
226{
227 errors |= inc_snapset_t::SIZE_MISMATCH;
228}
229
230void inconsistent_snapset_wrapper::encode(bufferlist& bl) const
231{
94b18763 232 ENCODE_START(2, 1, bl);
11fdf7f2
TL
233 encode(errors, bl);
234 encode(object, bl);
235 encode(clones, bl);
236 encode(missing, bl);
237 encode(ss_bl, bl);
7c673cae
FG
238 ENCODE_FINISH(bl);
239}
240
11fdf7f2 241void inconsistent_snapset_wrapper::decode(bufferlist::const_iterator& bp)
7c673cae 242{
94b18763 243 DECODE_START(2, bp);
11fdf7f2
TL
244 decode(errors, bp);
245 decode(object, bp);
246 decode(clones, bp);
247 decode(missing, bp);
94b18763 248 if (struct_v >= 2) {
11fdf7f2 249 decode(ss_bl, bp);
94b18763 250 }
7c673cae
FG
251 DECODE_FINISH(bp);
252}
253
254void scrub_ls_arg_t::encode(bufferlist& bl) const
255{
256 ENCODE_START(1, 1, bl);
11fdf7f2
TL
257 encode(interval, bl);
258 encode(get_snapsets, bl);
259 encode(start_after.name, bl);
260 encode(start_after.nspace, bl);
261 encode(start_after.snap, bl);
262 encode(max_return, bl);
7c673cae
FG
263 ENCODE_FINISH(bl);
264}
265
11fdf7f2 266void scrub_ls_arg_t::decode(bufferlist::const_iterator& bp)
7c673cae
FG
267{
268 DECODE_START(1, bp);
11fdf7f2
TL
269 decode(interval, bp);
270 decode(get_snapsets, bp);
271 decode(start_after.name, bp);
272 decode(start_after.nspace, bp);
273 decode(start_after.snap, bp);
274 decode(max_return, bp);
7c673cae
FG
275 DECODE_FINISH(bp);
276}
277
278void scrub_ls_result_t::encode(bufferlist& bl) const
279{
280 ENCODE_START(1, 1, bl);
11fdf7f2
TL
281 encode(interval, bl);
282 encode(vals, bl);
7c673cae
FG
283 ENCODE_FINISH(bl);
284}
285
11fdf7f2 286void scrub_ls_result_t::decode(bufferlist::const_iterator& bp)
7c673cae
FG
287{
288 DECODE_START(1, bp);
11fdf7f2
TL
289 decode(interval, bp);
290 decode(vals, bp);
7c673cae
FG
291 DECODE_FINISH(bp);
292}