1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
|
#include "snap_types.h"
#include "common/Formatter.h"
void SnapRealmInfo::encode(bufferlist& bl) const
{
h.num_snaps = my_snaps.size();
h.num_prior_parent_snaps = prior_parent_snaps.size();
using ceph::encode;
encode(h, bl);
encode_nohead(my_snaps, bl);
encode_nohead(prior_parent_snaps, bl);
}
void SnapRealmInfo::decode(bufferlist::const_iterator& bl)
{
using ceph::decode;
decode(h, bl);
decode_nohead(h.num_snaps, my_snaps, bl);
decode_nohead(h.num_prior_parent_snaps, prior_parent_snaps, bl);
}
void SnapRealmInfo::dump(Formatter *f) const
{
f->dump_unsigned("ino", ino());
f->dump_unsigned("parent", parent());
f->dump_unsigned("seq", seq());
f->dump_unsigned("parent_since", parent_since());
f->dump_unsigned("created", created());
f->open_array_section("snaps");
for (vector<snapid_t>::const_iterator p = my_snaps.begin(); p != my_snaps.end(); ++p)
f->dump_unsigned("snap", *p);
f->close_section();
f->open_array_section("prior_parent_snaps");
for (vector<snapid_t>::const_iterator p = prior_parent_snaps.begin(); p != prior_parent_snaps.end(); ++p)
f->dump_unsigned("snap", *p);
f->close_section();
}
void SnapRealmInfo::generate_test_instances(list<SnapRealmInfo*>& o)
{
o.push_back(new SnapRealmInfo);
o.push_back(new SnapRealmInfo(1, 10, 10, 0));
o.push_back(new SnapRealmInfo(1, 10, 10, 0));
o.back()->my_snaps.push_back(10);
o.push_back(new SnapRealmInfo(1, 10, 10, 5));
o.back()->my_snaps.push_back(10);
o.back()->prior_parent_snaps.push_back(3);
o.back()->prior_parent_snaps.push_back(5);
}
// -----
bool SnapContext::is_valid() const
{
// seq is a valid snapid
if (seq > CEPH_MAXSNAP)
return false;
if (!snaps.empty()) {
// seq >= snaps[0]
if (snaps[0] > seq)
return false;
// snaps[] is descending
snapid_t t = snaps[0];
for (unsigned i=1; i<snaps.size(); i++) {
if (snaps[i] >= t || t == 0)
return false;
t = snaps[i];
}
}
return true;
}
void SnapContext::dump(Formatter *f) const
{
f->dump_unsigned("seq", seq);
f->open_array_section("snaps");
for (vector<snapid_t>::const_iterator p = snaps.begin(); p != snaps.end(); ++p)
f->dump_unsigned("snap", *p);
f->close_section();
}
void SnapContext::generate_test_instances(list<SnapContext*>& o)
{
o.push_back(new SnapContext);
vector<snapid_t> v;
o.push_back(new SnapContext(10, v));
v.push_back(18);
v.push_back(3);
v.push_back(1);
o.push_back(new SnapContext(20, v));
}
|