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
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
|
// -*- mode:C++; tab-width:8; c-basic-offset:2; indent-tabs-mode:t -*-
// vim: ts=8 sw=2 smarttab
#include "cls/rbd/cls_rbd_types.h"
#include "common/Formatter.h"
#include "include/ceph_assert.h"
#include "include/stringify.h"
#include "librbd/WatchNotifyTypes.h"
namespace librbd {
namespace watch_notify {
void AsyncRequestId::encode(bufferlist &bl) const {
using ceph::encode;
encode(client_id, bl);
encode(request_id, bl);
}
void AsyncRequestId::decode(bufferlist::const_iterator &iter) {
using ceph::decode;
decode(client_id, iter);
decode(request_id, iter);
}
void AsyncRequestId::dump(Formatter *f) const {
f->open_object_section("client_id");
client_id.dump(f);
f->close_section();
f->dump_unsigned("request_id", request_id);
}
void AcquiredLockPayload::encode(bufferlist &bl) const {
using ceph::encode;
encode(client_id, bl);
}
void AcquiredLockPayload::decode(__u8 version, bufferlist::const_iterator &iter) {
using ceph::decode;
if (version >= 2) {
decode(client_id, iter);
}
}
void AcquiredLockPayload::dump(Formatter *f) const {
f->open_object_section("client_id");
client_id.dump(f);
f->close_section();
}
void ReleasedLockPayload::encode(bufferlist &bl) const {
using ceph::encode;
encode(client_id, bl);
}
void ReleasedLockPayload::decode(__u8 version, bufferlist::const_iterator &iter) {
using ceph::decode;
if (version >= 2) {
decode(client_id, iter);
}
}
void ReleasedLockPayload::dump(Formatter *f) const {
f->open_object_section("client_id");
client_id.dump(f);
f->close_section();
}
void RequestLockPayload::encode(bufferlist &bl) const {
using ceph::encode;
encode(client_id, bl);
encode(force, bl);
}
void RequestLockPayload::decode(__u8 version, bufferlist::const_iterator &iter) {
using ceph::decode;
if (version >= 2) {
decode(client_id, iter);
}
if (version >= 3) {
decode(force, iter);
}
}
void RequestLockPayload::dump(Formatter *f) const {
f->open_object_section("client_id");
client_id.dump(f);
f->close_section();
f->dump_bool("force", force);
}
void HeaderUpdatePayload::encode(bufferlist &bl) const {
}
void HeaderUpdatePayload::decode(__u8 version, bufferlist::const_iterator &iter) {
}
void HeaderUpdatePayload::dump(Formatter *f) const {
}
void AsyncRequestPayloadBase::encode(bufferlist &bl) const {
using ceph::encode;
encode(async_request_id, bl);
}
void AsyncRequestPayloadBase::decode(__u8 version, bufferlist::const_iterator &iter) {
using ceph::decode;
decode(async_request_id, iter);
}
void AsyncRequestPayloadBase::dump(Formatter *f) const {
f->open_object_section("async_request_id");
async_request_id.dump(f);
f->close_section();
}
void AsyncProgressPayload::encode(bufferlist &bl) const {
using ceph::encode;
AsyncRequestPayloadBase::encode(bl);
encode(offset, bl);
encode(total, bl);
}
void AsyncProgressPayload::decode(__u8 version, bufferlist::const_iterator &iter) {
using ceph::decode;
AsyncRequestPayloadBase::decode(version, iter);
decode(offset, iter);
decode(total, iter);
}
void AsyncProgressPayload::dump(Formatter *f) const {
AsyncRequestPayloadBase::dump(f);
f->dump_unsigned("offset", offset);
f->dump_unsigned("total", total);
}
void AsyncCompletePayload::encode(bufferlist &bl) const {
using ceph::encode;
AsyncRequestPayloadBase::encode(bl);
encode(result, bl);
}
void AsyncCompletePayload::decode(__u8 version, bufferlist::const_iterator &iter) {
using ceph::decode;
AsyncRequestPayloadBase::decode(version, iter);
decode(result, iter);
}
void AsyncCompletePayload::dump(Formatter *f) const {
AsyncRequestPayloadBase::dump(f);
f->dump_int("result", result);
}
void ResizePayload::encode(bufferlist &bl) const {
using ceph::encode;
encode(size, bl);
AsyncRequestPayloadBase::encode(bl);
encode(allow_shrink, bl);
}
void ResizePayload::decode(__u8 version, bufferlist::const_iterator &iter) {
using ceph::decode;
decode(size, iter);
AsyncRequestPayloadBase::decode(version, iter);
if (version >= 4) {
decode(allow_shrink, iter);
}
}
void ResizePayload::dump(Formatter *f) const {
AsyncRequestPayloadBase::dump(f);
f->dump_unsigned("size", size);
f->dump_bool("allow_shrink", allow_shrink);
}
void SnapPayloadBase::encode(bufferlist &bl) const {
using ceph::encode;
encode(snap_name, bl);
encode(snap_namespace, bl);
encode(async_request_id, bl);
}
void SnapPayloadBase::decode(__u8 version, bufferlist::const_iterator &iter) {
using ceph::decode;
decode(snap_name, iter);
if (version >= 6) {
decode(snap_namespace, iter);
}
if (version >= 7) {
decode(async_request_id, iter);
}
}
void SnapPayloadBase::dump(Formatter *f) const {
AsyncRequestPayloadBase::dump(f);
f->dump_string("snap_name", snap_name);
snap_namespace.dump(f);
}
void SnapCreatePayload::encode(bufferlist &bl) const {
using ceph::encode;
SnapPayloadBase::encode(bl);
encode(flags, bl);
}
void SnapCreatePayload::decode(__u8 version, bufferlist::const_iterator &iter) {
using ceph::decode;
SnapPayloadBase::decode(version, iter);
if (version == 5) {
decode(snap_namespace, iter);
}
if (version >= 7) {
decode(flags, iter);
}
}
void SnapCreatePayload::dump(Formatter *f) const {
SnapPayloadBase::dump(f);
f->dump_unsigned("flags", flags);
}
void SnapRenamePayload::encode(bufferlist &bl) const {
using ceph::encode;
encode(snap_id, bl);
SnapPayloadBase::encode(bl);
}
void SnapRenamePayload::decode(__u8 version, bufferlist::const_iterator &iter) {
using ceph::decode;
decode(snap_id, iter);
SnapPayloadBase::decode(version, iter);
}
void SnapRenamePayload::dump(Formatter *f) const {
SnapPayloadBase::dump(f);
f->dump_unsigned("src_snap_id", snap_id);
}
void RenamePayload::encode(bufferlist &bl) const {
using ceph::encode;
encode(image_name, bl);
encode(async_request_id, bl);
}
void RenamePayload::decode(__u8 version, bufferlist::const_iterator &iter) {
using ceph::decode;
decode(image_name, iter);
if (version >= 7) {
decode(async_request_id, iter);
}
}
void RenamePayload::dump(Formatter *f) const {
AsyncRequestPayloadBase::dump(f);
f->dump_string("image_name", image_name);
}
void UpdateFeaturesPayload::encode(bufferlist &bl) const {
using ceph::encode;
encode(features, bl);
encode(enabled, bl);
encode(async_request_id, bl);
}
void UpdateFeaturesPayload::decode(__u8 version, bufferlist::const_iterator &iter) {
using ceph::decode;
decode(features, iter);
decode(enabled, iter);
if (version >= 7) {
decode(async_request_id, iter);
}
}
void UpdateFeaturesPayload::dump(Formatter *f) const {
AsyncRequestPayloadBase::dump(f);
f->dump_unsigned("features", features);
f->dump_bool("enabled", enabled);
}
void SparsifyPayload::encode(bufferlist &bl) const {
using ceph::encode;
AsyncRequestPayloadBase::encode(bl);
encode(sparse_size, bl);
}
void SparsifyPayload::decode(__u8 version, bufferlist::const_iterator &iter) {
using ceph::decode;
AsyncRequestPayloadBase::decode(version, iter);
decode(sparse_size, iter);
}
void SparsifyPayload::dump(Formatter *f) const {
AsyncRequestPayloadBase::dump(f);
f->dump_unsigned("sparse_size", sparse_size);
}
void MetadataUpdatePayload::encode(bufferlist &bl) const {
using ceph::encode;
encode(key, bl);
encode(value, bl);
encode(async_request_id, bl);
}
void MetadataUpdatePayload::decode(__u8 version, bufferlist::const_iterator &iter) {
using ceph::decode;
decode(key, iter);
decode(value, iter);
if (version >= 7) {
decode(async_request_id, iter);
}
}
void MetadataUpdatePayload::dump(Formatter *f) const {
AsyncRequestPayloadBase::dump(f);
f->dump_string("key", key);
f->dump_string("value", *value);
}
void UnknownPayload::encode(bufferlist &bl) const {
ceph_abort();
}
void UnknownPayload::decode(__u8 version, bufferlist::const_iterator &iter) {
}
void UnknownPayload::dump(Formatter *f) const {
}
bool NotifyMessage::check_for_refresh() const {
return payload->check_for_refresh();
}
void NotifyMessage::encode(bufferlist& bl) const {
ENCODE_START(7, 1, bl);
encode(static_cast<uint32_t>(payload->get_notify_op()), bl);
payload->encode(bl);
ENCODE_FINISH(bl);
}
void NotifyMessage::decode(bufferlist::const_iterator& iter) {
DECODE_START(1, iter);
uint32_t notify_op;
decode(notify_op, iter);
// select the correct payload variant based upon the encoded op
switch (notify_op) {
case NOTIFY_OP_ACQUIRED_LOCK:
payload.reset(new AcquiredLockPayload());
break;
case NOTIFY_OP_RELEASED_LOCK:
payload.reset(new ReleasedLockPayload());
break;
case NOTIFY_OP_REQUEST_LOCK:
payload.reset(new RequestLockPayload());
break;
case NOTIFY_OP_HEADER_UPDATE:
payload.reset(new HeaderUpdatePayload());
break;
case NOTIFY_OP_ASYNC_PROGRESS:
payload.reset(new AsyncProgressPayload());
break;
case NOTIFY_OP_ASYNC_COMPLETE:
payload.reset(new AsyncCompletePayload());
break;
case NOTIFY_OP_FLATTEN:
payload.reset(new FlattenPayload());
break;
case NOTIFY_OP_RESIZE:
payload.reset(new ResizePayload());
break;
case NOTIFY_OP_SNAP_CREATE:
payload.reset(new SnapCreatePayload());
break;
case NOTIFY_OP_SNAP_REMOVE:
payload.reset(new SnapRemovePayload());
break;
case NOTIFY_OP_SNAP_RENAME:
payload.reset(new SnapRenamePayload());
break;
case NOTIFY_OP_SNAP_PROTECT:
payload.reset(new SnapProtectPayload());
break;
case NOTIFY_OP_SNAP_UNPROTECT:
payload.reset(new SnapUnprotectPayload());
break;
case NOTIFY_OP_REBUILD_OBJECT_MAP:
payload.reset(new RebuildObjectMapPayload());
break;
case NOTIFY_OP_RENAME:
payload.reset(new RenamePayload());
break;
case NOTIFY_OP_UPDATE_FEATURES:
payload.reset(new UpdateFeaturesPayload());
break;
case NOTIFY_OP_MIGRATE:
payload.reset(new MigratePayload());
break;
case NOTIFY_OP_SPARSIFY:
payload.reset(new SparsifyPayload());
break;
case NOTIFY_OP_QUIESCE:
payload.reset(new QuiescePayload());
break;
case NOTIFY_OP_UNQUIESCE:
payload.reset(new UnquiescePayload());
break;
case NOTIFY_OP_METADATA_UPDATE:
payload.reset(new MetadataUpdatePayload());
break;
}
payload->decode(struct_v, iter);
DECODE_FINISH(iter);
}
void NotifyMessage::dump(Formatter *f) const {
payload->dump(f);
}
NotifyOp NotifyMessage::get_notify_op() const {
return payload->get_notify_op();
}
void NotifyMessage::generate_test_instances(std::list<NotifyMessage *> &o) {
o.push_back(new NotifyMessage(new AcquiredLockPayload(ClientId(1, 2))));
o.push_back(new NotifyMessage(new ReleasedLockPayload(ClientId(1, 2))));
o.push_back(new NotifyMessage(new RequestLockPayload(ClientId(1, 2), true)));
o.push_back(new NotifyMessage(new HeaderUpdatePayload()));
o.push_back(new NotifyMessage(new AsyncProgressPayload(AsyncRequestId(ClientId(0, 1), 2), 3, 4)));
o.push_back(new NotifyMessage(new AsyncCompletePayload(AsyncRequestId(ClientId(0, 1), 2), 3)));
o.push_back(new NotifyMessage(new FlattenPayload(AsyncRequestId(ClientId(0, 1), 2))));
o.push_back(new NotifyMessage(new ResizePayload(AsyncRequestId(ClientId(0, 1), 2), 123, true)));
o.push_back(new NotifyMessage(new SnapCreatePayload(AsyncRequestId(ClientId(0, 1), 2),
cls::rbd::UserSnapshotNamespace(),
"foo", 1)));
o.push_back(new NotifyMessage(new SnapRemovePayload(AsyncRequestId(ClientId(0, 1), 2),
cls::rbd::UserSnapshotNamespace(), "foo")));
o.push_back(new NotifyMessage(new SnapProtectPayload(AsyncRequestId(ClientId(0, 1), 2),
cls::rbd::UserSnapshotNamespace(), "foo")));
o.push_back(new NotifyMessage(new SnapUnprotectPayload(AsyncRequestId(ClientId(0, 1), 2),
cls::rbd::UserSnapshotNamespace(), "foo")));
o.push_back(new NotifyMessage(new RebuildObjectMapPayload(AsyncRequestId(ClientId(0, 1), 2))));
o.push_back(new NotifyMessage(new RenamePayload(AsyncRequestId(ClientId(0, 1), 2), "foo")));
o.push_back(new NotifyMessage(new UpdateFeaturesPayload(AsyncRequestId(ClientId(0, 1), 2),
1, true)));
o.push_back(new NotifyMessage(new MigratePayload(AsyncRequestId(ClientId(0, 1), 2))));
o.push_back(new NotifyMessage(new SparsifyPayload(AsyncRequestId(ClientId(0, 1), 2), 1)));
o.push_back(new NotifyMessage(new QuiescePayload(AsyncRequestId(ClientId(0, 1), 2))));
o.push_back(new NotifyMessage(new UnquiescePayload(AsyncRequestId(ClientId(0, 1), 2))));
o.push_back(new NotifyMessage(new MetadataUpdatePayload(AsyncRequestId(ClientId(0, 1), 2),
"foo", std::optional<std::string>{"xyz"})));
}
void ResponseMessage::encode(bufferlist& bl) const {
ENCODE_START(1, 1, bl);
encode(result, bl);
ENCODE_FINISH(bl);
}
void ResponseMessage::decode(bufferlist::const_iterator& iter) {
DECODE_START(1, iter);
decode(result, iter);
DECODE_FINISH(iter);
}
void ResponseMessage::dump(Formatter *f) const {
f->dump_int("result", result);
}
void ResponseMessage::generate_test_instances(std::list<ResponseMessage *> &o) {
o.push_back(new ResponseMessage(1));
}
std::ostream &operator<<(std::ostream &out,
const librbd::watch_notify::NotifyOp &op) {
using namespace librbd::watch_notify;
switch (op) {
case NOTIFY_OP_ACQUIRED_LOCK:
out << "AcquiredLock";
break;
case NOTIFY_OP_RELEASED_LOCK:
out << "ReleasedLock";
break;
case NOTIFY_OP_REQUEST_LOCK:
out << "RequestLock";
break;
case NOTIFY_OP_HEADER_UPDATE:
out << "HeaderUpdate";
break;
case NOTIFY_OP_ASYNC_PROGRESS:
out << "AsyncProgress";
break;
case NOTIFY_OP_ASYNC_COMPLETE:
out << "AsyncComplete";
break;
case NOTIFY_OP_FLATTEN:
out << "Flatten";
break;
case NOTIFY_OP_RESIZE:
out << "Resize";
break;
case NOTIFY_OP_SNAP_CREATE:
out << "SnapCreate";
break;
case NOTIFY_OP_SNAP_REMOVE:
out << "SnapRemove";
break;
case NOTIFY_OP_SNAP_RENAME:
out << "SnapRename";
break;
case NOTIFY_OP_SNAP_PROTECT:
out << "SnapProtect";
break;
case NOTIFY_OP_SNAP_UNPROTECT:
out << "SnapUnprotect";
break;
case NOTIFY_OP_REBUILD_OBJECT_MAP:
out << "RebuildObjectMap";
break;
case NOTIFY_OP_RENAME:
out << "Rename";
break;
case NOTIFY_OP_UPDATE_FEATURES:
out << "UpdateFeatures";
break;
case NOTIFY_OP_MIGRATE:
out << "Migrate";
break;
case NOTIFY_OP_SPARSIFY:
out << "Sparsify";
break;
case NOTIFY_OP_QUIESCE:
out << "Quiesce";
break;
case NOTIFY_OP_UNQUIESCE:
out << "Unquiesce";
break;
case NOTIFY_OP_METADATA_UPDATE:
out << "MetadataUpdate";
break;
default:
out << "Unknown (" << static_cast<uint32_t>(op) << ")";
break;
}
return out;
}
std::ostream &operator<<(std::ostream &out,
const librbd::watch_notify::AsyncRequestId &request) {
out << "[" << request.client_id.gid << "," << request.client_id.handle << ","
<< request.request_id << "]";
return out;
}
} // namespace watch_notify
} // namespace librbd
|