-
Notifications
You must be signed in to change notification settings - Fork 1
/
cls_rbd_client.cc
1585 lines (1353 loc) · 44.1 KB
/
cls_rbd_client.cc
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
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
// -*- mode:C++; tab-width:8; c-basic-offset:2; indent-tabs-mode:t -*-
// vim: ts=8 sw=2 smarttab
#include "cls/rbd/cls_rbd_client.h"
#include "cls/lock/cls_lock_client.h"
#include "include/buffer.h"
#include "include/Context.h"
#include "include/encoding.h"
#include "include/rbd_types.h"
#include "common/Cond.h"
#include <errno.h>
namespace librbd {
namespace cls_client {
void get_immutable_metadata_start(librados::ObjectReadOperation *op) {
bufferlist bl, empty_bl;
snapid_t snap = CEPH_NOSNAP;
::encode(snap, bl);
op->exec("rbd", "get_size", bl);
op->exec("rbd", "get_object_prefix", empty_bl);
}
int get_immutable_metadata_finish(bufferlist::iterator *it,
std::string *object_prefix,
uint8_t *order) {
try {
uint64_t size;
// get_size
::decode(*order, *it);
::decode(size, *it);
// get_object_prefix
::decode(*object_prefix, *it);
} catch (const buffer::error &err) {
return -EBADMSG;
}
return 0;
}
int get_immutable_metadata(librados::IoCtx *ioctx, const std::string &oid,
std::string *object_prefix, uint8_t *order)
{
librados::ObjectReadOperation op;
get_immutable_metadata_start(&op);
bufferlist out_bl;
int r = ioctx->operate(oid, &op, &out_bl);
if (r < 0) {
return r;
}
bufferlist::iterator it = out_bl.begin();
return get_immutable_metadata_finish(&it, object_prefix, order);
}
void get_mutable_metadata_start(librados::ObjectReadOperation *op,
bool read_only) {
snapid_t snap = CEPH_NOSNAP;
bufferlist size_bl;
::encode(snap, size_bl);
op->exec("rbd", "get_size", size_bl);
bufferlist features_bl;
::encode(snap, features_bl);
::encode(read_only, features_bl);
op->exec("rbd", "get_features", features_bl);
bufferlist empty_bl;
op->exec("rbd", "get_snapcontext", empty_bl);
bufferlist parent_bl;
::encode(snap, parent_bl);
op->exec("rbd", "get_parent", parent_bl);
rados::cls::lock::get_lock_info_start(op, RBD_LOCK_NAME);
}
int get_mutable_metadata_finish(bufferlist::iterator *it,
uint64_t *size, uint64_t *features,
uint64_t *incompatible_features,
std::map<rados::cls::lock::locker_id_t,
rados::cls::lock::locker_info_t> *lockers,
bool *exclusive_lock, std::string *lock_tag,
::SnapContext *snapc, parent_info *parent) {
assert(size);
assert(features);
assert(incompatible_features);
assert(lockers);
assert(exclusive_lock);
assert(snapc);
assert(parent);
try {
uint8_t order;
// get_size
::decode(order, *it);
::decode(*size, *it);
// get_features
::decode(*features, *it);
::decode(*incompatible_features, *it);
// get_snapcontext
::decode(*snapc, *it);
// get_parent
::decode(parent->spec.pool_id, *it);
::decode(parent->spec.image_id, *it);
::decode(parent->spec.snap_id, *it);
::decode(parent->overlap, *it);
// get_lock_info
ClsLockType lock_type = LOCK_NONE;
int r = rados::cls::lock::get_lock_info_finish(it, lockers, &lock_type,
lock_tag);
if (r == -EOPNOTSUPP) {
r = 0;
}
if (r == 0) {
*exclusive_lock = (lock_type == LOCK_EXCLUSIVE);
}
} catch (const buffer::error &err) {
return -EBADMSG;
}
return 0;
}
int get_mutable_metadata(librados::IoCtx *ioctx, const std::string &oid,
bool read_only, uint64_t *size, uint64_t *features,
uint64_t *incompatible_features,
map<rados::cls::lock::locker_id_t,
rados::cls::lock::locker_info_t> *lockers,
bool *exclusive_lock,
string *lock_tag,
::SnapContext *snapc,
parent_info *parent)
{
librados::ObjectReadOperation op;
get_mutable_metadata_start(&op, read_only);
bufferlist out_bl;
int r = ioctx->operate(oid, &op, &out_bl);
if (r < 0) {
return r;
}
bufferlist::iterator it = out_bl.begin();
return get_mutable_metadata_finish(&it, size, features,
incompatible_features, lockers,
exclusive_lock, lock_tag, snapc,
parent);
}
void create_image(librados::ObjectWriteOperation *op, uint64_t size, uint8_t order,
uint64_t features, const std::string &object_prefix)
{
bufferlist bl;
::encode(size, bl);
::encode(order, bl);
::encode(features, bl);
::encode(object_prefix, (bl));
op->exec("rbd", "create", bl);
}
int create_image(librados::IoCtx *ioctx, const std::string &oid,
uint64_t size, uint8_t order, uint64_t features,
const std::string &object_prefix)
{
librados::ObjectWriteOperation op;
create_image(&op, size, order, features, object_prefix);
return ioctx->operate(oid, &op);
}
int get_features(librados::IoCtx *ioctx, const std::string &oid,
snapid_t snap_id, uint64_t *features)
{
bufferlist inbl, outbl;
::encode(snap_id, inbl);
int r = ioctx->exec(oid, "rbd", "get_features", inbl, outbl);
if (r < 0)
return r;
try {
bufferlist::iterator iter = outbl.begin();
::decode(*features, iter);
} catch (const buffer::error &err) {
return -EBADMSG;
}
return 0;
}
int set_features(librados::IoCtx *ioctx, const std::string &oid,
uint64_t features, uint64_t mask)
{
bufferlist inbl;
::encode(features, inbl);
::encode(mask, inbl);
librados::ObjectWriteOperation op;
op.exec("rbd", "set_features", inbl);
return ioctx->operate(oid, &op);
}
int get_object_prefix(librados::IoCtx *ioctx, const std::string &oid,
std::string *object_prefix)
{
bufferlist inbl, outbl;
int r = ioctx->exec(oid, "rbd", "get_object_prefix", inbl, outbl);
if (r < 0)
return r;
try {
bufferlist::iterator iter = outbl.begin();
::decode(*object_prefix, iter);
} catch (const buffer::error &err) {
return -EBADMSG;
}
return 0;
}
int get_size(librados::IoCtx *ioctx, const std::string &oid,
snapid_t snap_id, uint64_t *size, uint8_t *order)
{
bufferlist inbl, outbl;
::encode(snap_id, inbl);
int r = ioctx->exec(oid, "rbd", "get_size", inbl, outbl);
if (r < 0)
return r;
try {
bufferlist::iterator iter = outbl.begin();
::decode(*order, iter);
::decode(*size, iter);
} catch (const buffer::error &err) {
return -EBADMSG;
}
return 0;
}
int set_size(librados::IoCtx *ioctx, const std::string &oid,
uint64_t size)
{
librados::ObjectWriteOperation op;
set_size(&op, size);
return ioctx->operate(oid, &op);
}
void set_size(librados::ObjectWriteOperation *op, uint64_t size)
{
bufferlist bl;
::encode(size, bl);
op->exec("rbd", "set_size", bl);
}
int get_parent(librados::IoCtx *ioctx, const std::string &oid,
snapid_t snap_id, parent_spec *pspec,
uint64_t *parent_overlap)
{
bufferlist inbl, outbl;
::encode(snap_id, inbl);
int r = ioctx->exec(oid, "rbd", "get_parent", inbl, outbl);
if (r < 0)
return r;
try {
bufferlist::iterator iter = outbl.begin();
::decode(pspec->pool_id, iter);
::decode(pspec->image_id, iter);
::decode(pspec->snap_id, iter);
::decode(*parent_overlap, iter);
} catch (const buffer::error &err) {
return -EBADMSG;
}
return 0;
}
int set_parent(librados::IoCtx *ioctx, const std::string &oid,
parent_spec pspec, uint64_t parent_overlap)
{
librados::ObjectWriteOperation op;
set_parent(&op, pspec, parent_overlap);
return ioctx->operate(oid, &op);
}
void set_parent(librados::ObjectWriteOperation *op,
parent_spec pspec, uint64_t parent_overlap) {
bufferlist in_bl;
::encode(pspec.pool_id, in_bl);
::encode(pspec.image_id, in_bl);
::encode(pspec.snap_id, in_bl);
::encode(parent_overlap, in_bl);
op->exec("rbd", "set_parent", in_bl);
}
void get_flags_start(librados::ObjectReadOperation *op,
const std::vector<snapid_t> &snap_ids) {
bufferlist in_bl;
::encode(static_cast<snapid_t>(CEPH_NOSNAP), in_bl);
op->exec("rbd", "get_flags", in_bl);
for (size_t i = 0; i < snap_ids.size(); ++i) {
bufferlist snap_bl;
::encode(snap_ids[i], snap_bl);
op->exec("rbd", "get_flags", snap_bl);
}
}
int get_flags_finish(bufferlist::iterator *it, uint64_t *flags,
const std::vector<snapid_t> &snap_ids,
std::vector<uint64_t> *snap_flags) {
snap_flags->resize(snap_ids.size());
try {
::decode(*flags, *it);
for (size_t i = 0; i < snap_flags->size(); ++i) {
::decode((*snap_flags)[i], *it);
}
} catch (const buffer::error &err) {
return -EBADMSG;
}
return 0;
}
int get_flags(librados::IoCtx *ioctx, const std::string &oid,
uint64_t *flags, const std::vector<snapid_t> &snap_ids,
vector<uint64_t> *snap_flags)
{
librados::ObjectReadOperation op;
get_flags_start(&op, snap_ids);
bufferlist out_bl;
int r = ioctx->operate(oid, &op, &out_bl);
if (r < 0) {
return r;
}
bufferlist::iterator it = out_bl.begin();
return get_flags_finish(&it, flags, snap_ids, snap_flags);
}
void set_flags(librados::ObjectWriteOperation *op, snapid_t snap_id,
uint64_t flags, uint64_t mask)
{
bufferlist inbl;
::encode(flags, inbl);
::encode(mask, inbl);
::encode(snap_id, inbl);
op->exec("rbd", "set_flags", inbl);
}
int remove_parent(librados::IoCtx *ioctx, const std::string &oid)
{
librados::ObjectWriteOperation op;
remove_parent(&op);
return ioctx->operate(oid, &op);
}
void remove_parent(librados::ObjectWriteOperation *op)
{
bufferlist inbl;
op->exec("rbd", "remove_parent", inbl);
}
int add_child(librados::IoCtx *ioctx, const std::string &oid,
parent_spec pspec, const std::string &c_imageid)
{
bufferlist in, out;
::encode(pspec.pool_id, in);
::encode(pspec.image_id, in);
::encode(pspec.snap_id, in);
::encode(c_imageid, in);
return ioctx->exec(oid, "rbd", "add_child", in, out);
}
void remove_child(librados::ObjectWriteOperation *op,
parent_spec pspec, const std::string &c_imageid)
{
bufferlist in;
::encode(pspec.pool_id, in);
::encode(pspec.image_id, in);
::encode(pspec.snap_id, in);
::encode(c_imageid, in);
op->exec("rbd", "remove_child", in);
}
int remove_child(librados::IoCtx *ioctx, const std::string &oid,
parent_spec pspec, const std::string &c_imageid)
{
librados::ObjectWriteOperation op;
remove_child(&op, pspec, c_imageid);
return ioctx->operate(oid, &op);
}
void get_children_start(librados::ObjectReadOperation *op,
const parent_spec &pspec) {
bufferlist in_bl;
::encode(pspec.pool_id, in_bl);
::encode(pspec.image_id, in_bl);
::encode(pspec.snap_id, in_bl);
op->exec("rbd", "get_children", in_bl);
}
int get_children_finish(bufferlist::iterator *it,
std::set<std::string>* children) {
try {
::decode(*children, *it);
} catch (const buffer::error &err) {
return -EBADMSG;
}
return 0;
}
int get_children(librados::IoCtx *ioctx, const std::string &oid,
parent_spec pspec, set<string>& children)
{
librados::ObjectReadOperation op;
get_children_start(&op, pspec);
bufferlist out_bl;
int r = ioctx->operate(oid, &op, &out_bl);
if (r < 0) {
return r;
}
bufferlist::iterator it = out_bl.begin();
return get_children_finish(&it, &children);
}
void snapshot_add(librados::ObjectWriteOperation *op, snapid_t snap_id,
const std::string &snap_name)
{
bufferlist bl;
::encode(snap_name, bl);
::encode(snap_id, bl);
op->exec("rbd", "snapshot_add", bl);
}
void snapshot_remove(librados::ObjectWriteOperation *op, snapid_t snap_id)
{
bufferlist bl;
::encode(snap_id, bl);
op->exec("rbd", "snapshot_remove", bl);
}
void snapshot_rename(librados::ObjectWriteOperation *op,
snapid_t src_snap_id,
const std::string &dst_name)
{
bufferlist bl;
::encode(src_snap_id, bl);
::encode(dst_name, bl);
op->exec("rbd", "snapshot_rename", bl);
}
int get_snapcontext(librados::IoCtx *ioctx, const std::string &oid,
::SnapContext *snapc)
{
bufferlist inbl, outbl;
int r = ioctx->exec(oid, "rbd", "get_snapcontext", inbl, outbl);
if (r < 0)
return r;
try {
bufferlist::iterator iter = outbl.begin();
::decode(*snapc, iter);
} catch (const buffer::error &err) {
return -EBADMSG;
}
if (!snapc->is_valid())
return -EBADMSG;
return 0;
}
void snapshot_list_start(librados::ObjectReadOperation *op,
const std::vector<snapid_t> &ids) {
for (vector<snapid_t>::const_iterator it = ids.begin();
it != ids.end(); ++it) {
snapid_t snap_id = it->val;
bufferlist bl1, bl2, bl3, bl4;
::encode(snap_id, bl1);
op->exec("rbd", "get_snapshot_name", bl1);
::encode(snap_id, bl2);
op->exec("rbd", "get_size", bl2);
::encode(snap_id, bl3);
op->exec("rbd", "get_parent", bl3);
::encode(snap_id, bl4);
op->exec("rbd", "get_protection_status", bl4);
}
}
int snapshot_list_finish(bufferlist::iterator *it,
const std::vector<snapid_t> &ids,
std::vector<string> *names,
std::vector<uint64_t> *sizes,
std::vector<parent_info> *parents,
std::vector<uint8_t> *protection_statuses) {
names->resize(ids.size());
sizes->resize(ids.size());
parents->resize(ids.size());
protection_statuses->resize(ids.size());
try {
for (size_t i = 0; i < names->size(); ++i) {
uint8_t order;
// get_snapshot_name
::decode((*names)[i], *it);
// get_size
::decode(order, *it);
::decode((*sizes)[i], *it);
// get_parent
::decode((*parents)[i].spec.pool_id, *it);
::decode((*parents)[i].spec.image_id, *it);
::decode((*parents)[i].spec.snap_id, *it);
::decode((*parents)[i].overlap, *it);
// get_protection_status
::decode((*protection_statuses)[i], *it);
}
} catch (const buffer::error &err) {
return -EBADMSG;
}
return 0;
}
int snapshot_list(librados::IoCtx *ioctx, const std::string &oid,
const std::vector<snapid_t> &ids,
std::vector<string> *names,
std::vector<uint64_t> *sizes,
std::vector<parent_info> *parents,
std::vector<uint8_t> *protection_statuses)
{
librados::ObjectReadOperation op;
snapshot_list_start(&op, ids);
bufferlist out_bl;
int r = ioctx->operate(oid, &op, &out_bl);
if (r < 0) {
return r;
}
bufferlist::iterator it = out_bl.begin();
return snapshot_list_finish(&it, ids, names, sizes, parents,
protection_statuses);
}
void old_snapshot_add(librados::ObjectWriteOperation *op,
snapid_t snap_id, const std::string &snap_name)
{
bufferlist bl;
::encode(snap_name, bl);
::encode(snap_id, bl);
op->exec("rbd", "snap_add", bl);
}
void old_snapshot_remove(librados::ObjectWriteOperation *op,
const std::string &snap_name)
{
bufferlist bl;
::encode(snap_name, bl);
op->exec("rbd", "snap_remove", bl);
}
void old_snapshot_rename(librados::ObjectWriteOperation *op,
snapid_t src_snap_id, const std::string &dst_name)
{
bufferlist bl;
::encode(src_snap_id, bl);
::encode(dst_name, bl);
op->exec("rbd", "snap_rename", bl);
}
void old_snapshot_list_start(librados::ObjectReadOperation *op) {
bufferlist in_bl;
op->exec("rbd", "snap_list", in_bl);
}
int old_snapshot_list_finish(bufferlist::iterator *it,
std::vector<string> *names,
std::vector<uint64_t> *sizes,
::SnapContext *snapc) {
try {
uint32_t num_snaps;
::decode(snapc->seq, *it);
::decode(num_snaps, *it);
names->resize(num_snaps);
sizes->resize(num_snaps);
snapc->snaps.resize(num_snaps);
for (uint32_t i = 0; i < num_snaps; ++i) {
::decode(snapc->snaps[i], *it);
::decode((*sizes)[i], *it);
::decode((*names)[i], *it);
}
} catch (const buffer::error &err) {
return -EBADMSG;
}
return 0;
}
int old_snapshot_list(librados::IoCtx *ioctx, const std::string &oid,
std::vector<string> *names,
std::vector<uint64_t> *sizes,
::SnapContext *snapc)
{
librados::ObjectReadOperation op;
old_snapshot_list_start(&op);
bufferlist out_bl;
int r = ioctx->operate(oid, &op, &out_bl);
if (r < 0) {
return r;
}
bufferlist::iterator it = out_bl.begin();
return old_snapshot_list_finish(&it, names, sizes, snapc);
}
int copyup(librados::IoCtx *ioctx, const std::string &oid,
bufferlist data) {
bufferlist out;
return ioctx->exec(oid, "rbd", "copyup", data, out);
}
int get_protection_status(librados::IoCtx *ioctx, const std::string &oid,
snapid_t snap_id, uint8_t *protection_status)
{
bufferlist in, out;
::encode(snap_id.val, in);
int r = ioctx->exec(oid, "rbd", "get_protection_status", in, out);
if (r < 0)
return r;
try {
bufferlist::iterator iter = out.begin();
::decode(*protection_status, iter);
} catch (const buffer::error &err) {
return -EBADMSG;
}
return 0;
}
int set_protection_status(librados::IoCtx *ioctx, const std::string &oid,
snapid_t snap_id, uint8_t protection_status)
{
// TODO remove
librados::ObjectWriteOperation op;
set_protection_status(&op, snap_id, protection_status);
return ioctx->operate(oid, &op);
}
void set_protection_status(librados::ObjectWriteOperation *op,
snapid_t snap_id, uint8_t protection_status)
{
bufferlist in;
::encode(snap_id, in);
::encode(protection_status, in);
op->exec("rbd", "set_protection_status", in);
}
int snapshot_get_limit(librados::IoCtx *ioctx, const std::string &oid,
uint64_t *limit)
{
bufferlist in, out;
int r = ioctx->exec(oid, "rbd", "snapshot_get_limit", in, out);
if (r < 0) {
return r;
}
try {
bufferlist::iterator iter = out.begin();
::decode(*limit, iter);
} catch (const buffer::error &err) {
return -EBADMSG;
}
return 0;
}
void snapshot_set_limit(librados::ObjectWriteOperation *op, uint64_t limit)
{
bufferlist in;
::encode(limit, in);
op->exec("rbd", "snapshot_set_limit", in);
}
void get_stripe_unit_count_start(librados::ObjectReadOperation *op) {
bufferlist empty_bl;
op->exec("rbd", "get_stripe_unit_count", empty_bl);
}
int get_stripe_unit_count_finish(bufferlist::iterator *it,
uint64_t *stripe_unit,
uint64_t *stripe_count) {
assert(stripe_unit);
assert(stripe_count);
try {
::decode(*stripe_unit, *it);
::decode(*stripe_count, *it);
} catch (const buffer::error &err) {
return -EBADMSG;
}
return 0;
}
int get_stripe_unit_count(librados::IoCtx *ioctx, const std::string &oid,
uint64_t *stripe_unit, uint64_t *stripe_count)
{
librados::ObjectReadOperation op;
get_stripe_unit_count_start(&op);
bufferlist out_bl;
int r = ioctx->operate(oid, &op, &out_bl);
if (r < 0) {
return r;
}
bufferlist::iterator it = out_bl.begin();
return get_stripe_unit_count_finish(&it, stripe_unit, stripe_count);
}
void set_stripe_unit_count(librados::ObjectWriteOperation *op,
uint64_t stripe_unit, uint64_t stripe_count)
{
bufferlist bl;
::encode(stripe_unit, bl);
::encode(stripe_count, bl);
op->exec("rbd", "set_stripe_unit_count", bl);
}
int set_stripe_unit_count(librados::IoCtx *ioctx, const std::string &oid,
uint64_t stripe_unit, uint64_t stripe_count)
{
librados::ObjectWriteOperation op;
set_stripe_unit_count(&op, stripe_unit, stripe_count);
return ioctx->operate(oid, &op);
}
/************************ rbd_id object methods ************************/
void get_id_start(librados::ObjectReadOperation *op) {
bufferlist empty_bl;
op->exec("rbd", "get_id", empty_bl);
}
int get_id_finish(bufferlist::iterator *it, std::string *id) {
try {
::decode(*id, *it);
} catch (const buffer::error &err) {
return -EBADMSG;
}
return 0;
}
int get_id(librados::IoCtx *ioctx, const std::string &oid, std::string *id)
{
librados::ObjectReadOperation op;
get_id_start(&op);
bufferlist out_bl;
int r = ioctx->operate(oid, &op, &out_bl);
if (r < 0) {
return r;
}
bufferlist::iterator it = out_bl.begin();
return get_id_finish(&it, id);
}
void set_id(librados::ObjectWriteOperation *op, const std::string id)
{
bufferlist bl;
::encode(id, bl);
op->exec("rbd", "set_id", bl);
}
int set_id(librados::IoCtx *ioctx, const std::string &oid, std::string id)
{
librados::ObjectWriteOperation op;
set_id(&op, id);
return ioctx->operate(oid, &op);
}
/******************** rbd_directory object methods ********************/
int dir_get_id(librados::IoCtx *ioctx, const std::string &oid,
const std::string &name, std::string *id)
{
bufferlist in, out;
::encode(name, in);
int r = ioctx->exec(oid, "rbd", "dir_get_id", in, out);
if (r < 0)
return r;
bufferlist::iterator iter = out.begin();
try {
::decode(*id, iter);
} catch (const buffer::error &err) {
return -EBADMSG;
}
return 0;
}
void dir_get_name_start(librados::ObjectReadOperation *op,
const std::string &id) {
bufferlist in_bl;
::encode(id, in_bl);
op->exec("rbd", "dir_get_name", in_bl);
}
int dir_get_name_finish(bufferlist::iterator *it, std::string *name) {
try {
::decode(*name, *it);
} catch (const buffer::error &err) {
return -EBADMSG;
}
return 0;
}
int dir_get_name(librados::IoCtx *ioctx, const std::string &oid,
const std::string &id, std::string *name) {
librados::ObjectReadOperation op;
dir_get_name_start(&op, id);
bufferlist out_bl;
int r = ioctx->operate(oid, &op, &out_bl);
if (r < 0) {
return r;
}
bufferlist::iterator it = out_bl.begin();
return dir_get_name_finish(&it, name);
}
int dir_list(librados::IoCtx *ioctx, const std::string &oid,
const std::string &start, uint64_t max_return,
map<string, string> *images)
{
bufferlist in, out;
::encode(start, in);
::encode(max_return, in);
int r = ioctx->exec(oid, "rbd", "dir_list", in, out);
if (r < 0)
return r;
bufferlist::iterator iter = out.begin();
try {
::decode(*images, iter);
} catch (const buffer::error &err) {
return -EBADMSG;
}
return 0;
}
void dir_add_image(librados::ObjectWriteOperation *op,
const std::string &name, const std::string &id)
{
bufferlist bl;
::encode(name, bl);
::encode(id, bl);
op->exec("rbd", "dir_add_image", bl);
}
int dir_add_image(librados::IoCtx *ioctx, const std::string &oid,
const std::string &name, const std::string &id)
{
librados::ObjectWriteOperation op;
dir_add_image(&op, name, id);
return ioctx->operate(oid, &op);
}
int dir_remove_image(librados::IoCtx *ioctx, const std::string &oid,
const std::string &name, const std::string &id)
{
librados::ObjectWriteOperation op;
dir_remove_image(&op, name, id);
return ioctx->operate(oid, &op);
}
void dir_remove_image(librados::ObjectWriteOperation *op,
const std::string &name, const std::string &id)
{
bufferlist bl;
::encode(name, bl);
::encode(id, bl);
op->exec("rbd", "dir_remove_image", bl);
}
void dir_rename_image(librados::ObjectWriteOperation *op,
const std::string &src, const std::string &dest,
const std::string &id)
{
bufferlist in;
::encode(src, in);
::encode(dest, in);
::encode(id, in);
op->exec("rbd", "dir_rename_image", in);
}
void object_map_load_start(librados::ObjectReadOperation *op) {
bufferlist in_bl;
op->exec("rbd", "object_map_load", in_bl);
}
int object_map_load_finish(bufferlist::iterator *it,
ceph::BitVector<2> *object_map) {
try {
::decode(*object_map, *it);
} catch (const buffer::error &err) {
return -EBADMSG;
}
return 0;
}
int object_map_load(librados::IoCtx *ioctx, const std::string &oid,
ceph::BitVector<2> *object_map)
{
librados::ObjectReadOperation op;
object_map_load_start(&op);
bufferlist out_bl;
int r = ioctx->operate(oid, &op, &out_bl);
if (r < 0) {
return r;
}
bufferlist::iterator it = out_bl.begin();
return object_map_load_finish(&it, object_map);
}
void object_map_save(librados::ObjectWriteOperation *rados_op,
const ceph::BitVector<2> &object_map)
{
ceph::BitVector<2> object_map_copy(object_map);
object_map_copy.set_crc_enabled(false);
bufferlist in;
::encode(object_map_copy, in);
rados_op->exec("rbd", "object_map_save", in);
}
void object_map_resize(librados::ObjectWriteOperation *rados_op,
uint64_t object_count, uint8_t default_state)
{
bufferlist in;
::encode(object_count, in);
::encode(default_state, in);
rados_op->exec("rbd", "object_map_resize", in);
}
void object_map_update(librados::ObjectWriteOperation *rados_op,
uint64_t start_object_no, uint64_t end_object_no,
uint8_t new_object_state,
const boost::optional<uint8_t> ¤t_object_state)
{
bufferlist in;
::encode(start_object_no, in);
::encode(end_object_no, in);
::encode(new_object_state, in);
::encode(current_object_state, in);
rados_op->exec("rbd", "object_map_update", in);
}
void object_map_snap_add(librados::ObjectWriteOperation *rados_op)
{
bufferlist in;
rados_op->exec("rbd", "object_map_snap_add", in);
}
void object_map_snap_remove(librados::ObjectWriteOperation *rados_op,
const ceph::BitVector<2> &object_map)
{
ceph::BitVector<2> object_map_copy(object_map);
object_map_copy.set_crc_enabled(false);
bufferlist in;
::encode(object_map_copy, in);
rados_op->exec("rbd", "object_map_snap_remove", in);
}