]>
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 | * Ceph - scalable distributed file system | |
5 | * | |
6 | * Copyright (C) 2004- Sage Weil <sage@newdream.net> | |
7 | * | |
8 | * This is free software; you can redistribute it and/or | |
9 | * modify it under the terms of the GNU Lesser General Public | |
10 | * License version 2.1, as published by the Free Software | |
11 | * Foundation. See file COPYING. | |
12 | * | |
13 | */ | |
14 | ||
94b18763 FG |
15 | #include <boost/utility/string_view.hpp> |
16 | ||
7c673cae FG |
17 | #include "snap.h" |
18 | ||
19 | #include "common/Formatter.h" | |
20 | ||
21 | /* | |
22 | * SnapInfo | |
23 | */ | |
24 | ||
25 | void SnapInfo::encode(bufferlist& bl) const | |
26 | { | |
27 | ENCODE_START(2, 2, bl); | |
28 | ::encode(snapid, bl); | |
29 | ::encode(ino, bl); | |
30 | ::encode(stamp, bl); | |
31 | ::encode(name, bl); | |
32 | ENCODE_FINISH(bl); | |
33 | } | |
34 | ||
35 | void SnapInfo::decode(bufferlist::iterator& bl) | |
36 | { | |
37 | DECODE_START_LEGACY_COMPAT_LEN(2, 2, 2, bl); | |
38 | ::decode(snapid, bl); | |
39 | ::decode(ino, bl); | |
40 | ::decode(stamp, bl); | |
41 | ::decode(name, bl); | |
42 | DECODE_FINISH(bl); | |
43 | } | |
44 | ||
45 | void SnapInfo::dump(Formatter *f) const | |
46 | { | |
47 | f->dump_unsigned("snapid", snapid); | |
48 | f->dump_unsigned("ino", ino); | |
49 | f->dump_stream("stamp") << stamp; | |
50 | f->dump_string("name", name); | |
51 | } | |
52 | ||
53 | void SnapInfo::generate_test_instances(list<SnapInfo*>& ls) | |
54 | { | |
55 | ls.push_back(new SnapInfo); | |
56 | ls.push_back(new SnapInfo); | |
57 | ls.back()->snapid = 1; | |
58 | ls.back()->ino = 2; | |
59 | ls.back()->stamp = utime_t(3, 4); | |
60 | ls.back()->name = "foo"; | |
61 | } | |
62 | ||
63 | ostream& operator<<(ostream& out, const SnapInfo &sn) | |
64 | { | |
65 | return out << "snap(" << sn.snapid | |
66 | << " " << sn.ino | |
67 | << " '" << sn.name | |
68 | << "' " << sn.stamp << ")"; | |
69 | } | |
70 | ||
94b18763 | 71 | boost::string_view SnapInfo::get_long_name() |
7c673cae FG |
72 | { |
73 | if (long_name.length() == 0) { | |
74 | char nm[80]; | |
75 | snprintf(nm, sizeof(nm), "_%s_%llu", name.c_str(), (unsigned long long)ino); | |
76 | long_name = nm; | |
77 | } | |
78 | return long_name; | |
79 | } | |
80 | ||
81 | /* | |
82 | * snaplink_t | |
83 | */ | |
84 | ||
85 | void snaplink_t::encode(bufferlist& bl) const | |
86 | { | |
87 | ENCODE_START(2, 2, bl); | |
88 | ::encode(ino, bl); | |
89 | ::encode(first, bl); | |
90 | ENCODE_FINISH(bl); | |
91 | } | |
92 | ||
93 | void snaplink_t::decode(bufferlist::iterator& bl) | |
94 | { | |
95 | DECODE_START_LEGACY_COMPAT_LEN(2, 2, 2, bl); | |
96 | ::decode(ino, bl); | |
97 | ::decode(first, bl); | |
98 | DECODE_FINISH(bl); | |
99 | } | |
100 | ||
101 | void snaplink_t::dump(Formatter *f) const | |
102 | { | |
103 | f->dump_unsigned("ino", ino); | |
104 | f->dump_unsigned("first", first); | |
105 | } | |
106 | ||
107 | void snaplink_t::generate_test_instances(list<snaplink_t*>& ls) | |
108 | { | |
109 | ls.push_back(new snaplink_t); | |
110 | ls.push_back(new snaplink_t); | |
111 | ls.back()->ino = 2; | |
112 | ls.back()->first = 123; | |
113 | } | |
114 | ||
115 | ostream& operator<<(ostream& out, const snaplink_t &l) | |
116 | { | |
117 | return out << l.ino << "@" << l.first; | |
118 | } | |
119 | ||
120 | /* | |
121 | * sr_t | |
122 | */ | |
123 | ||
124 | void sr_t::encode(bufferlist& bl) const | |
125 | { | |
126 | ENCODE_START(4, 4, bl); | |
127 | ::encode(seq, bl); | |
128 | ::encode(created, bl); | |
129 | ::encode(last_created, bl); | |
130 | ::encode(last_destroyed, bl); | |
131 | ::encode(current_parent_since, bl); | |
132 | ::encode(snaps, bl); | |
133 | ::encode(past_parents, bl); | |
134 | ENCODE_FINISH(bl); | |
135 | } | |
136 | ||
137 | void sr_t::decode(bufferlist::iterator& p) | |
138 | { | |
139 | DECODE_START_LEGACY_COMPAT_LEN(4, 4, 4, p); | |
140 | if (struct_v == 2) { | |
141 | __u8 struct_v; | |
142 | ::decode(struct_v, p); // yes, really: extra byte for v2 encoding only, see 6ee52e7d. | |
143 | } | |
144 | ::decode(seq, p); | |
145 | ::decode(created, p); | |
146 | ::decode(last_created, p); | |
147 | ::decode(last_destroyed, p); | |
148 | ::decode(current_parent_since, p); | |
149 | ::decode(snaps, p); | |
150 | ::decode(past_parents, p); | |
151 | DECODE_FINISH(p); | |
152 | } | |
153 | ||
154 | void sr_t::dump(Formatter *f) const | |
155 | { | |
156 | f->dump_unsigned("seq", seq); | |
157 | f->dump_unsigned("created", created); | |
158 | f->dump_unsigned("last_created", last_created); | |
159 | f->dump_unsigned("last_destroyed", last_destroyed); | |
160 | f->dump_unsigned("current_parent_since", current_parent_since); | |
161 | ||
162 | f->open_array_section("snaps"); | |
163 | for (map<snapid_t,SnapInfo>::const_iterator p = snaps.begin(); p != snaps.end(); ++p) { | |
164 | f->open_object_section("snapinfo"); | |
165 | f->dump_unsigned("last", p->first); | |
166 | p->second.dump(f); | |
167 | f->close_section(); | |
168 | } | |
169 | f->close_section(); | |
170 | ||
171 | f->open_array_section("past_parents"); | |
172 | for (map<snapid_t,snaplink_t>::const_iterator p = past_parents.begin(); p != past_parents.end(); ++p) { | |
173 | f->open_object_section("past_parent"); | |
174 | f->dump_unsigned("last", p->first); | |
175 | p->second.dump(f); | |
176 | f->close_section(); | |
177 | } | |
178 | f->close_section(); | |
179 | } | |
180 | ||
181 | void sr_t::generate_test_instances(list<sr_t*>& ls) | |
182 | { | |
183 | ls.push_back(new sr_t); | |
184 | ls.push_back(new sr_t); | |
185 | ls.back()->seq = 1; | |
186 | ls.back()->created = 2; | |
187 | ls.back()->last_created = 3; | |
188 | ls.back()->last_destroyed = 4; | |
189 | ls.back()->current_parent_since = 5; | |
190 | ls.back()->snaps[123].snapid = 7; | |
191 | ls.back()->snaps[123].ino = 8; | |
192 | ls.back()->snaps[123].stamp = utime_t(9, 10); | |
193 | ls.back()->snaps[123].name = "name1"; | |
194 | ls.back()->past_parents[12].ino = 12; | |
195 | ls.back()->past_parents[12].first = 3; | |
196 | } | |
197 |