]>
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 | #ifndef LIBRBD_WATCH_NOTIFY_TYPES_H | |
4 | #define LIBRBD_WATCH_NOTIFY_TYPES_H | |
5 | ||
6 | #include "cls/rbd/cls_rbd_types.h" | |
7 | #include "include/int_types.h" | |
8 | #include "include/buffer_fwd.h" | |
9 | #include "include/encoding.h" | |
10 | #include "librbd/watcher/Types.h" | |
11 | #include <iosfwd> | |
12 | #include <list> | |
13 | #include <string> | |
14 | #include <boost/variant.hpp> | |
15 | ||
16 | namespace ceph { | |
17 | class Formatter; | |
18 | } | |
19 | ||
20 | namespace librbd { | |
21 | namespace watch_notify { | |
22 | ||
23 | using librbd::watcher::ClientId; | |
24 | ||
25 | WRITE_CLASS_ENCODER(ClientId); | |
26 | ||
27 | struct AsyncRequestId { | |
28 | ClientId client_id; | |
29 | uint64_t request_id; | |
30 | ||
31 | AsyncRequestId() : request_id() {} | |
32 | AsyncRequestId(const ClientId &client_id_, uint64_t request_id_) | |
33 | : client_id(client_id_), request_id(request_id_) {} | |
34 | ||
35 | void encode(bufferlist& bl) const; | |
11fdf7f2 | 36 | void decode(bufferlist::const_iterator& it); |
7c673cae FG |
37 | void dump(Formatter *f) const; |
38 | ||
39 | inline bool operator<(const AsyncRequestId &rhs) const { | |
40 | if (client_id != rhs.client_id) { | |
41 | return client_id < rhs.client_id; | |
42 | } else { | |
43 | return request_id < rhs.request_id; | |
44 | } | |
45 | } | |
46 | inline bool operator!=(const AsyncRequestId &rhs) const { | |
47 | return (client_id != rhs.client_id || request_id != rhs.request_id); | |
48 | } | |
49 | }; | |
50 | ||
51 | enum NotifyOp { | |
52 | NOTIFY_OP_ACQUIRED_LOCK = 0, | |
53 | NOTIFY_OP_RELEASED_LOCK = 1, | |
54 | NOTIFY_OP_REQUEST_LOCK = 2, | |
55 | NOTIFY_OP_HEADER_UPDATE = 3, | |
56 | NOTIFY_OP_ASYNC_PROGRESS = 4, | |
57 | NOTIFY_OP_ASYNC_COMPLETE = 5, | |
58 | NOTIFY_OP_FLATTEN = 6, | |
59 | NOTIFY_OP_RESIZE = 7, | |
60 | NOTIFY_OP_SNAP_CREATE = 8, | |
61 | NOTIFY_OP_SNAP_REMOVE = 9, | |
62 | NOTIFY_OP_REBUILD_OBJECT_MAP = 10, | |
63 | NOTIFY_OP_SNAP_RENAME = 11, | |
64 | NOTIFY_OP_SNAP_PROTECT = 12, | |
65 | NOTIFY_OP_SNAP_UNPROTECT = 13, | |
66 | NOTIFY_OP_RENAME = 14, | |
67 | NOTIFY_OP_UPDATE_FEATURES = 15, | |
11fdf7f2 TL |
68 | NOTIFY_OP_MIGRATE = 16, |
69 | NOTIFY_OP_SPARSIFY = 17, | |
7c673cae FG |
70 | }; |
71 | ||
72 | struct AcquiredLockPayload { | |
73 | static const NotifyOp NOTIFY_OP = NOTIFY_OP_ACQUIRED_LOCK; | |
74 | static const bool CHECK_FOR_REFRESH = false; | |
75 | ||
76 | ClientId client_id; | |
77 | ||
78 | AcquiredLockPayload() {} | |
79 | AcquiredLockPayload(const ClientId &client_id_) : client_id(client_id_) {} | |
80 | ||
81 | void encode(bufferlist &bl) const; | |
11fdf7f2 | 82 | void decode(__u8 version, bufferlist::const_iterator &iter); |
7c673cae FG |
83 | void dump(Formatter *f) const; |
84 | }; | |
85 | ||
86 | struct ReleasedLockPayload { | |
87 | static const NotifyOp NOTIFY_OP = NOTIFY_OP_RELEASED_LOCK; | |
88 | static const bool CHECK_FOR_REFRESH = false; | |
89 | ||
90 | ClientId client_id; | |
91 | ||
92 | ReleasedLockPayload() {} | |
93 | ReleasedLockPayload(const ClientId &client_id_) : client_id(client_id_) {} | |
94 | ||
95 | void encode(bufferlist &bl) const; | |
11fdf7f2 | 96 | void decode(__u8 version, bufferlist::const_iterator &iter); |
7c673cae FG |
97 | void dump(Formatter *f) const; |
98 | }; | |
99 | ||
100 | struct RequestLockPayload { | |
101 | static const NotifyOp NOTIFY_OP = NOTIFY_OP_REQUEST_LOCK; | |
102 | static const bool CHECK_FOR_REFRESH = false; | |
103 | ||
104 | ClientId client_id; | |
105 | bool force = false; | |
106 | ||
107 | RequestLockPayload() {} | |
108 | RequestLockPayload(const ClientId &client_id_, bool force_) | |
109 | : client_id(client_id_), force(force_) { | |
110 | } | |
111 | ||
112 | void encode(bufferlist &bl) const; | |
11fdf7f2 | 113 | void decode(__u8 version, bufferlist::const_iterator &iter); |
7c673cae FG |
114 | void dump(Formatter *f) const; |
115 | }; | |
116 | ||
117 | struct HeaderUpdatePayload { | |
118 | static const NotifyOp NOTIFY_OP = NOTIFY_OP_HEADER_UPDATE; | |
119 | static const bool CHECK_FOR_REFRESH = false; | |
120 | ||
121 | void encode(bufferlist &bl) const; | |
11fdf7f2 | 122 | void decode(__u8 version, bufferlist::const_iterator &iter); |
7c673cae FG |
123 | void dump(Formatter *f) const; |
124 | }; | |
125 | ||
126 | struct AsyncRequestPayloadBase { | |
127 | public: | |
128 | AsyncRequestId async_request_id; | |
129 | ||
130 | void encode(bufferlist &bl) const; | |
11fdf7f2 | 131 | void decode(__u8 version, bufferlist::const_iterator &iter); |
7c673cae FG |
132 | void dump(Formatter *f) const; |
133 | ||
134 | protected: | |
135 | AsyncRequestPayloadBase() {} | |
136 | AsyncRequestPayloadBase(const AsyncRequestId &id) : async_request_id(id) {} | |
137 | }; | |
138 | ||
139 | struct AsyncProgressPayload : public AsyncRequestPayloadBase { | |
140 | static const NotifyOp NOTIFY_OP = NOTIFY_OP_ASYNC_PROGRESS; | |
141 | static const bool CHECK_FOR_REFRESH = false; | |
142 | ||
143 | AsyncProgressPayload() : offset(0), total(0) {} | |
144 | AsyncProgressPayload(const AsyncRequestId &id, uint64_t offset_, uint64_t total_) | |
145 | : AsyncRequestPayloadBase(id), offset(offset_), total(total_) {} | |
146 | ||
147 | uint64_t offset; | |
148 | uint64_t total; | |
149 | ||
150 | void encode(bufferlist &bl) const; | |
11fdf7f2 | 151 | void decode(__u8 version, bufferlist::const_iterator &iter); |
7c673cae FG |
152 | void dump(Formatter *f) const; |
153 | }; | |
154 | ||
155 | struct AsyncCompletePayload : public AsyncRequestPayloadBase { | |
156 | static const NotifyOp NOTIFY_OP = NOTIFY_OP_ASYNC_COMPLETE; | |
157 | static const bool CHECK_FOR_REFRESH = false; | |
158 | ||
159 | AsyncCompletePayload() : result(0) {} | |
160 | AsyncCompletePayload(const AsyncRequestId &id, int r) | |
161 | : AsyncRequestPayloadBase(id), result(r) {} | |
162 | ||
163 | int result; | |
164 | ||
165 | void encode(bufferlist &bl) const; | |
11fdf7f2 | 166 | void decode(__u8 version, bufferlist::const_iterator &iter); |
7c673cae FG |
167 | void dump(Formatter *f) const; |
168 | }; | |
169 | ||
170 | struct FlattenPayload : public AsyncRequestPayloadBase { | |
171 | static const NotifyOp NOTIFY_OP = NOTIFY_OP_FLATTEN; | |
172 | static const bool CHECK_FOR_REFRESH = true; | |
173 | ||
174 | FlattenPayload() {} | |
175 | FlattenPayload(const AsyncRequestId &id) : AsyncRequestPayloadBase(id) {} | |
176 | }; | |
177 | ||
178 | struct ResizePayload : public AsyncRequestPayloadBase { | |
179 | static const NotifyOp NOTIFY_OP = NOTIFY_OP_RESIZE; | |
180 | static const bool CHECK_FOR_REFRESH = true; | |
181 | ||
182 | ResizePayload() : size(0), allow_shrink(true) {} | |
183 | ResizePayload(uint64_t size_, bool allow_shrink_, const AsyncRequestId &id) | |
184 | : AsyncRequestPayloadBase(id), size(size_), allow_shrink(allow_shrink_) {} | |
185 | ||
186 | uint64_t size; | |
187 | bool allow_shrink; | |
188 | ||
189 | void encode(bufferlist &bl) const; | |
11fdf7f2 | 190 | void decode(__u8 version, bufferlist::const_iterator &iter); |
7c673cae FG |
191 | void dump(Formatter *f) const; |
192 | }; | |
193 | ||
194 | struct SnapPayloadBase { | |
195 | public: | |
196 | static const bool CHECK_FOR_REFRESH = true; | |
197 | ||
198 | cls::rbd::SnapshotNamespace snap_namespace; | |
199 | std::string snap_name; | |
200 | ||
201 | void encode(bufferlist &bl) const; | |
11fdf7f2 | 202 | void decode(__u8 version, bufferlist::const_iterator &iter); |
7c673cae FG |
203 | void dump(Formatter *f) const; |
204 | ||
205 | protected: | |
206 | SnapPayloadBase() {} | |
207 | SnapPayloadBase(const cls::rbd::SnapshotNamespace& _snap_namespace, | |
208 | const std::string &name) | |
209 | : snap_namespace(_snap_namespace), snap_name(name) {} | |
210 | }; | |
211 | ||
212 | struct SnapCreatePayload : public SnapPayloadBase { | |
213 | static const NotifyOp NOTIFY_OP = NOTIFY_OP_SNAP_CREATE; | |
214 | ||
215 | SnapCreatePayload() {} | |
216 | SnapCreatePayload(const cls::rbd::SnapshotNamespace &_snap_namespace, | |
217 | const std::string &name) | |
218 | : SnapPayloadBase(_snap_namespace, name) {} | |
219 | ||
220 | void encode(bufferlist &bl) const; | |
11fdf7f2 | 221 | void decode(__u8 version, bufferlist::const_iterator &iter); |
7c673cae FG |
222 | void dump(Formatter *f) const; |
223 | }; | |
224 | ||
225 | struct SnapRenamePayload : public SnapPayloadBase { | |
226 | static const NotifyOp NOTIFY_OP = NOTIFY_OP_SNAP_RENAME; | |
227 | ||
228 | SnapRenamePayload() {} | |
229 | SnapRenamePayload(const uint64_t &src_snap_id, | |
230 | const std::string &dst_name) | |
231 | : SnapPayloadBase(cls::rbd::UserSnapshotNamespace(), dst_name), snap_id(src_snap_id) {} | |
232 | ||
11fdf7f2 | 233 | uint64_t snap_id = 0; |
7c673cae FG |
234 | |
235 | void encode(bufferlist &bl) const; | |
11fdf7f2 | 236 | void decode(__u8 version, bufferlist::const_iterator &iter); |
7c673cae FG |
237 | void dump(Formatter *f) const; |
238 | }; | |
239 | ||
240 | struct SnapRemovePayload : public SnapPayloadBase { | |
241 | static const NotifyOp NOTIFY_OP = NOTIFY_OP_SNAP_REMOVE; | |
242 | ||
243 | SnapRemovePayload() {} | |
244 | SnapRemovePayload(const cls::rbd::SnapshotNamespace& snap_namespace, | |
245 | const std::string &name) | |
246 | : SnapPayloadBase(snap_namespace, name) {} | |
247 | }; | |
248 | ||
249 | struct SnapProtectPayload : public SnapPayloadBase { | |
250 | static const NotifyOp NOTIFY_OP = NOTIFY_OP_SNAP_PROTECT; | |
251 | ||
252 | SnapProtectPayload() {} | |
253 | SnapProtectPayload(const cls::rbd::SnapshotNamespace& snap_namespace, | |
254 | const std::string &name) | |
255 | : SnapPayloadBase(snap_namespace, name) {} | |
256 | }; | |
257 | ||
258 | struct SnapUnprotectPayload : public SnapPayloadBase { | |
259 | static const NotifyOp NOTIFY_OP = NOTIFY_OP_SNAP_UNPROTECT; | |
260 | ||
261 | SnapUnprotectPayload() {} | |
262 | SnapUnprotectPayload(const cls::rbd::SnapshotNamespace& snap_namespace, | |
263 | const std::string &name) | |
264 | : SnapPayloadBase(snap_namespace, name) {} | |
265 | }; | |
266 | ||
267 | struct RebuildObjectMapPayload : public AsyncRequestPayloadBase { | |
268 | static const NotifyOp NOTIFY_OP = NOTIFY_OP_REBUILD_OBJECT_MAP; | |
269 | static const bool CHECK_FOR_REFRESH = true; | |
270 | ||
271 | RebuildObjectMapPayload() {} | |
272 | RebuildObjectMapPayload(const AsyncRequestId &id) | |
273 | : AsyncRequestPayloadBase(id) {} | |
274 | }; | |
275 | ||
276 | struct RenamePayload { | |
277 | static const NotifyOp NOTIFY_OP = NOTIFY_OP_RENAME; | |
278 | static const bool CHECK_FOR_REFRESH = true; | |
279 | ||
280 | RenamePayload() {} | |
281 | RenamePayload(const std::string _image_name) : image_name(_image_name) {} | |
282 | ||
283 | std::string image_name; | |
284 | ||
285 | void encode(bufferlist &bl) const; | |
11fdf7f2 | 286 | void decode(__u8 version, bufferlist::const_iterator &iter); |
7c673cae FG |
287 | void dump(Formatter *f) const; |
288 | }; | |
289 | ||
290 | struct UpdateFeaturesPayload { | |
291 | static const NotifyOp NOTIFY_OP = NOTIFY_OP_UPDATE_FEATURES; | |
292 | static const bool CHECK_FOR_REFRESH = true; | |
293 | ||
294 | UpdateFeaturesPayload() : features(0), enabled(false) {} | |
295 | UpdateFeaturesPayload(uint64_t features_, bool enabled_) | |
296 | : features(features_), enabled(enabled_) {} | |
297 | ||
298 | uint64_t features; | |
299 | bool enabled; | |
300 | ||
301 | void encode(bufferlist &bl) const; | |
11fdf7f2 TL |
302 | void decode(__u8 version, bufferlist::const_iterator &iter); |
303 | void dump(Formatter *f) const; | |
304 | }; | |
305 | ||
306 | struct MigratePayload : public AsyncRequestPayloadBase { | |
307 | static const NotifyOp NOTIFY_OP = NOTIFY_OP_MIGRATE; | |
308 | static const bool CHECK_FOR_REFRESH = true; | |
309 | ||
310 | MigratePayload() {} | |
311 | MigratePayload(const AsyncRequestId &id) : AsyncRequestPayloadBase(id) {} | |
312 | }; | |
313 | ||
314 | struct SparsifyPayload : public AsyncRequestPayloadBase { | |
315 | static const NotifyOp NOTIFY_OP = NOTIFY_OP_SPARSIFY; | |
316 | static const bool CHECK_FOR_REFRESH = true; | |
317 | ||
318 | SparsifyPayload() {} | |
319 | SparsifyPayload(const AsyncRequestId &id, size_t sparse_size) | |
320 | : AsyncRequestPayloadBase(id), sparse_size(sparse_size) {} | |
321 | ||
322 | size_t sparse_size = 0; | |
323 | ||
324 | void encode(bufferlist &bl) const; | |
325 | void decode(__u8 version, bufferlist::const_iterator &iter); | |
7c673cae FG |
326 | void dump(Formatter *f) const; |
327 | }; | |
328 | ||
329 | struct UnknownPayload { | |
330 | static const NotifyOp NOTIFY_OP = static_cast<NotifyOp>(-1); | |
331 | static const bool CHECK_FOR_REFRESH = false; | |
332 | ||
333 | void encode(bufferlist &bl) const; | |
11fdf7f2 | 334 | void decode(__u8 version, bufferlist::const_iterator &iter); |
7c673cae FG |
335 | void dump(Formatter *f) const; |
336 | }; | |
337 | ||
338 | typedef boost::variant<AcquiredLockPayload, | |
339 | ReleasedLockPayload, | |
340 | RequestLockPayload, | |
341 | HeaderUpdatePayload, | |
342 | AsyncProgressPayload, | |
343 | AsyncCompletePayload, | |
344 | FlattenPayload, | |
345 | ResizePayload, | |
346 | SnapCreatePayload, | |
347 | SnapRemovePayload, | |
348 | SnapRenamePayload, | |
349 | SnapProtectPayload, | |
350 | SnapUnprotectPayload, | |
351 | RebuildObjectMapPayload, | |
352 | RenamePayload, | |
353 | UpdateFeaturesPayload, | |
11fdf7f2 TL |
354 | MigratePayload, |
355 | SparsifyPayload, | |
7c673cae FG |
356 | UnknownPayload> Payload; |
357 | ||
358 | struct NotifyMessage { | |
359 | NotifyMessage() : payload(UnknownPayload()) {} | |
360 | NotifyMessage(const Payload &payload_) : payload(payload_) {} | |
361 | ||
362 | Payload payload; | |
363 | ||
364 | bool check_for_refresh() const; | |
365 | ||
366 | void encode(bufferlist& bl) const; | |
11fdf7f2 | 367 | void decode(bufferlist::const_iterator& it); |
7c673cae | 368 | void dump(Formatter *f) const; |
11fdf7f2 | 369 | NotifyOp get_notify_op() const; |
7c673cae FG |
370 | |
371 | static void generate_test_instances(std::list<NotifyMessage *> &o); | |
372 | }; | |
373 | ||
374 | struct ResponseMessage { | |
375 | ResponseMessage() : result(0) {} | |
376 | ResponseMessage(int result_) : result(result_) {} | |
377 | ||
378 | int result; | |
379 | ||
380 | void encode(bufferlist& bl) const; | |
11fdf7f2 | 381 | void decode(bufferlist::const_iterator& it); |
7c673cae FG |
382 | void dump(Formatter *f) const; |
383 | ||
384 | static void generate_test_instances(std::list<ResponseMessage *> &o); | |
385 | }; | |
386 | ||
7c673cae | 387 | std::ostream &operator<<(std::ostream &out, |
11fdf7f2 | 388 | const NotifyOp &op); |
7c673cae | 389 | std::ostream &operator<<(std::ostream &out, |
11fdf7f2 TL |
390 | const AsyncRequestId &request); |
391 | ||
392 | WRITE_CLASS_ENCODER(AsyncRequestId); | |
393 | WRITE_CLASS_ENCODER(NotifyMessage); | |
394 | WRITE_CLASS_ENCODER(ResponseMessage); | |
395 | ||
396 | } // namespace watch_notify | |
397 | } // namespace librbd | |
7c673cae | 398 | |
7c673cae FG |
399 | |
400 | #endif // LIBRBD_WATCH_NOTIFY_TYPES_H |