1 // -*- mode:C++; tab-width:8; c-basic-offset:2; indent-tabs-mode:t -*-
2 // vim: ts=8 sw=2 smarttab
4 #include "cls/rbd/cls_rbd_client.h"
5 #include "cls/lock/cls_lock_client.h"
6 #include "include/buffer.h"
7 #include "include/encoding.h"
8 #include "include/rbd_types.h"
9 #include "include/rados/librados.hpp"
10 #include "include/neorados/RADOS.hpp"
11 #include "common/bit_vector.hpp"
16 namespace cls_client
{
22 using ceph::bufferlist
;
26 void create_image(librados::ObjectWriteOperation
*op
, uint64_t size
,
27 uint8_t order
, uint64_t features
,
28 const std::string
&object_prefix
, int64_t data_pool_id
)
34 encode(object_prefix
, bl
);
35 encode(data_pool_id
, bl
);
37 op
->exec("rbd", "create", bl
);
40 int create_image(librados::IoCtx
*ioctx
, const std::string
&oid
,
41 uint64_t size
, uint8_t order
, uint64_t features
,
42 const std::string
&object_prefix
, int64_t data_pool_id
)
44 librados::ObjectWriteOperation op
;
45 create_image(&op
, size
, order
, features
, object_prefix
, data_pool_id
);
47 return ioctx
->operate(oid
, &op
);
50 void get_features_start(librados::ObjectReadOperation
*op
, bool read_only
)
53 encode(static_cast<uint64_t>(CEPH_NOSNAP
), bl
);
54 encode(read_only
, bl
);
55 op
->exec("rbd", "get_features", bl
);
58 int get_features_finish(bufferlist::const_iterator
*it
, uint64_t *features
,
59 uint64_t *incompatible_features
)
62 decode(*features
, *it
);
63 decode(*incompatible_features
, *it
);
64 } catch (const ceph::buffer::error
&err
) {
71 int get_features(librados::IoCtx
*ioctx
, const std::string
&oid
,
72 bool read_only
, uint64_t *features
,
73 uint64_t *incompatible_features
)
75 librados::ObjectReadOperation op
;
76 get_features_start(&op
, read_only
);
79 int r
= ioctx
->operate(oid
, &op
, &out_bl
);
84 auto it
= out_bl
.cbegin();
85 return get_features_finish(&it
, features
, incompatible_features
);
88 void set_features(librados::ObjectWriteOperation
*op
, uint64_t features
,
95 op
->exec("rbd", "set_features", bl
);
98 int set_features(librados::IoCtx
*ioctx
, const std::string
&oid
,
99 uint64_t features
, uint64_t mask
)
101 librados::ObjectWriteOperation op
;
102 set_features(&op
, features
, mask
);
104 return ioctx
->operate(oid
, &op
);
107 void get_object_prefix_start(librados::ObjectReadOperation
*op
)
110 op
->exec("rbd", "get_object_prefix", bl
);
113 int get_object_prefix_finish(bufferlist::const_iterator
*it
,
114 std::string
*object_prefix
)
117 decode(*object_prefix
, *it
);
118 } catch (const ceph::buffer::error
&err
) {
124 int get_object_prefix(librados::IoCtx
*ioctx
, const std::string
&oid
,
125 std::string
*object_prefix
)
127 librados::ObjectReadOperation op
;
128 get_object_prefix_start(&op
);
131 int r
= ioctx
->operate(oid
, &op
, &out_bl
);
136 auto it
= out_bl
.cbegin();
137 return get_object_prefix_finish(&it
, object_prefix
);
140 void get_data_pool_start(librados::ObjectReadOperation
*op
) {
142 op
->exec("rbd", "get_data_pool", bl
);
145 int get_data_pool_finish(bufferlist::const_iterator
*it
, int64_t *data_pool_id
) {
147 decode(*data_pool_id
, *it
);
148 } catch (const ceph::buffer::error
&err
) {
154 int get_data_pool(librados::IoCtx
*ioctx
, const std::string
&oid
,
155 int64_t *data_pool_id
) {
156 librados::ObjectReadOperation op
;
157 get_data_pool_start(&op
);
160 int r
= ioctx
->operate(oid
, &op
, &out_bl
);
165 auto it
= out_bl
.cbegin();
166 return get_data_pool_finish(&it
, data_pool_id
);
169 void get_size_start(librados::ObjectReadOperation
*op
, snapid_t snap_id
)
173 op
->exec("rbd", "get_size", bl
);
176 int get_size_finish(bufferlist::const_iterator
*it
, uint64_t *size
,
182 } catch (const ceph::buffer::error
&err
) {
188 int get_size(librados::IoCtx
*ioctx
, const std::string
&oid
,
189 snapid_t snap_id
, uint64_t *size
, uint8_t *order
)
191 librados::ObjectReadOperation op
;
192 get_size_start(&op
, snap_id
);
195 int r
= ioctx
->operate(oid
, &op
, &out_bl
);
200 auto it
= out_bl
.cbegin();
201 return get_size_finish(&it
, size
, order
);
204 int set_size(librados::IoCtx
*ioctx
, const std::string
&oid
,
207 librados::ObjectWriteOperation op
;
209 return ioctx
->operate(oid
, &op
);
212 void set_size(librados::ObjectWriteOperation
*op
, uint64_t size
)
216 op
->exec("rbd", "set_size", bl
);
219 void get_flags_start(librados::ObjectReadOperation
*op
, snapid_t snap_id
) {
221 encode(static_cast<snapid_t
>(snap_id
), in_bl
);
222 op
->exec("rbd", "get_flags", in_bl
);
225 int get_flags_finish(bufferlist::const_iterator
*it
, uint64_t *flags
) {
228 } catch (const ceph::buffer::error
&err
) {
234 int get_flags(librados::IoCtx
*ioctx
, const std::string
&oid
,
235 snapid_t snap_id
, uint64_t *flags
)
237 librados::ObjectReadOperation op
;
238 get_flags_start(&op
, snap_id
);
241 int r
= ioctx
->operate(oid
, &op
, &out_bl
);
246 auto it
= out_bl
.cbegin();
247 return get_flags_finish(&it
, flags
);
250 void set_flags(librados::ObjectWriteOperation
*op
, snapid_t snap_id
,
251 uint64_t flags
, uint64_t mask
)
256 encode(snap_id
, inbl
);
257 op
->exec("rbd", "set_flags", inbl
);
260 void op_features_get_start(librados::ObjectReadOperation
*op
)
263 op
->exec("rbd", "op_features_get", in_bl
);
266 int op_features_get_finish(bufferlist::const_iterator
*it
, uint64_t *op_features
)
269 decode(*op_features
, *it
);
270 } catch (const ceph::buffer::error
&err
) {
276 int op_features_get(librados::IoCtx
*ioctx
, const std::string
&oid
,
277 uint64_t *op_features
)
279 librados::ObjectReadOperation op
;
280 op_features_get_start(&op
);
283 int r
= ioctx
->operate(oid
, &op
, &out_bl
);
288 auto it
= out_bl
.cbegin();
289 return op_features_get_finish(&it
, op_features
);
292 void op_features_set(librados::ObjectWriteOperation
*op
,
293 uint64_t op_features
, uint64_t mask
)
296 encode(op_features
, inbl
);
298 op
->exec("rbd", "op_features_set", inbl
);
301 int op_features_set(librados::IoCtx
*ioctx
, const std::string
&oid
,
302 uint64_t op_features
, uint64_t mask
)
304 librados::ObjectWriteOperation op
;
305 op_features_set(&op
, op_features
, mask
);
307 return ioctx
->operate(oid
, &op
);
310 void get_parent_start(librados::ObjectReadOperation
*op
, snapid_t snap_id
)
314 op
->exec("rbd", "get_parent", bl
);
317 int get_parent_finish(bufferlist::const_iterator
*it
,
318 cls::rbd::ParentImageSpec
*pspec
,
319 uint64_t *parent_overlap
)
323 decode(pspec
->pool_id
, *it
);
324 decode(pspec
->image_id
, *it
);
325 decode(pspec
->snap_id
, *it
);
326 decode(*parent_overlap
, *it
);
327 } catch (const ceph::buffer::error
&) {
333 int get_parent(librados::IoCtx
*ioctx
, const std::string
&oid
,
334 snapid_t snap_id
, cls::rbd::ParentImageSpec
*pspec
,
335 uint64_t *parent_overlap
)
337 librados::ObjectReadOperation op
;
338 get_parent_start(&op
, snap_id
);
341 int r
= ioctx
->operate(oid
, &op
, &out_bl
);
346 auto it
= out_bl
.cbegin();
347 return get_parent_finish(&it
, pspec
, parent_overlap
);
350 int set_parent(librados::IoCtx
*ioctx
, const std::string
&oid
,
351 const cls::rbd::ParentImageSpec
&pspec
, uint64_t parent_overlap
)
353 librados::ObjectWriteOperation op
;
354 set_parent(&op
, pspec
, parent_overlap
);
355 return ioctx
->operate(oid
, &op
);
358 void set_parent(librados::ObjectWriteOperation
*op
,
359 const cls::rbd::ParentImageSpec
&pspec
,
360 uint64_t parent_overlap
) {
361 assert(pspec
.pool_namespace
.empty());
364 encode(pspec
.pool_id
, in_bl
);
365 encode(pspec
.image_id
, in_bl
);
366 encode(pspec
.snap_id
, in_bl
);
367 encode(parent_overlap
, in_bl
);
369 op
->exec("rbd", "set_parent", in_bl
);
372 int remove_parent(librados::IoCtx
*ioctx
, const std::string
&oid
)
374 librados::ObjectWriteOperation op
;
376 return ioctx
->operate(oid
, &op
);
379 void remove_parent(librados::ObjectWriteOperation
*op
)
382 op
->exec("rbd", "remove_parent", inbl
);
385 void parent_get_start(librados::ObjectReadOperation
* op
) {
387 op
->exec("rbd", "parent_get", in_bl
);
390 int parent_get_finish(bufferlist::const_iterator
* it
,
391 cls::rbd::ParentImageSpec
* parent_image_spec
) {
393 decode(*parent_image_spec
, *it
);
394 } catch (const ceph::buffer::error
&) {
400 int parent_get(librados::IoCtx
* ioctx
, const std::string
&oid
,
401 cls::rbd::ParentImageSpec
* parent_image_spec
) {
402 librados::ObjectReadOperation op
;
403 parent_get_start(&op
);
406 int r
= ioctx
->operate(oid
, &op
, &out_bl
);
411 auto it
= out_bl
.cbegin();
412 r
= parent_get_finish(&it
, parent_image_spec
);
419 void parent_overlap_get_start(librados::ObjectReadOperation
* op
,
422 encode(snap_id
, in_bl
);
423 op
->exec("rbd", "parent_overlap_get", in_bl
);
426 int parent_overlap_get_finish(bufferlist::const_iterator
* it
,
427 std::optional
<uint64_t>* parent_overlap
) {
429 decode(*parent_overlap
, *it
);
430 } catch (const ceph::buffer::error
&) {
436 int parent_overlap_get(librados::IoCtx
* ioctx
, const std::string
&oid
,
438 std::optional
<uint64_t>* parent_overlap
) {
439 librados::ObjectReadOperation op
;
440 parent_overlap_get_start(&op
, snap_id
);
443 int r
= ioctx
->operate(oid
, &op
, &out_bl
);
448 auto it
= out_bl
.cbegin();
449 r
= parent_overlap_get_finish(&it
, parent_overlap
);
456 void parent_attach(librados::ObjectWriteOperation
* op
,
457 const cls::rbd::ParentImageSpec
& parent_image_spec
,
458 uint64_t parent_overlap
, bool reattach
) {
460 encode(parent_image_spec
, in_bl
);
461 encode(parent_overlap
, in_bl
);
462 encode(reattach
, in_bl
);
463 op
->exec("rbd", "parent_attach", in_bl
);
466 int parent_attach(librados::IoCtx
*ioctx
, const std::string
&oid
,
467 const cls::rbd::ParentImageSpec
& parent_image_spec
,
468 uint64_t parent_overlap
, bool reattach
) {
469 librados::ObjectWriteOperation op
;
470 parent_attach(&op
, parent_image_spec
, parent_overlap
, reattach
);
471 return ioctx
->operate(oid
, &op
);
474 void parent_detach(librados::ObjectWriteOperation
* op
) {
476 op
->exec("rbd", "parent_detach", in_bl
);
479 int parent_detach(librados::IoCtx
*ioctx
, const std::string
&oid
) {
480 librados::ObjectWriteOperation op
;
482 return ioctx
->operate(oid
, &op
);
485 int add_child(librados::IoCtx
*ioctx
, const std::string
&oid
,
486 const cls::rbd::ParentImageSpec
&pspec
,
487 const std::string
&c_imageid
)
489 librados::ObjectWriteOperation op
;
490 add_child(&op
, pspec
, c_imageid
);
491 return ioctx
->operate(oid
, &op
);
494 void add_child(librados::ObjectWriteOperation
*op
,
495 const cls::rbd::ParentImageSpec
& pspec
,
496 const std::string
&c_imageid
)
498 assert(pspec
.pool_namespace
.empty());
501 encode(pspec
.pool_id
, in
);
502 encode(pspec
.image_id
, in
);
503 encode(pspec
.snap_id
, in
);
504 encode(c_imageid
, in
);
506 op
->exec("rbd", "add_child", in
);
509 void remove_child(librados::ObjectWriteOperation
*op
,
510 const cls::rbd::ParentImageSpec
&pspec
,
511 const std::string
&c_imageid
)
513 assert(pspec
.pool_namespace
.empty());
516 encode(pspec
.pool_id
, in
);
517 encode(pspec
.image_id
, in
);
518 encode(pspec
.snap_id
, in
);
519 encode(c_imageid
, in
);
520 op
->exec("rbd", "remove_child", in
);
523 int remove_child(librados::IoCtx
*ioctx
, const std::string
&oid
,
524 const cls::rbd::ParentImageSpec
&pspec
,
525 const std::string
&c_imageid
)
527 librados::ObjectWriteOperation op
;
528 remove_child(&op
, pspec
, c_imageid
);
529 return ioctx
->operate(oid
, &op
);
532 void get_children_start(librados::ObjectReadOperation
*op
,
533 const cls::rbd::ParentImageSpec
&pspec
) {
535 encode(pspec
.pool_id
, in_bl
);
536 encode(pspec
.image_id
, in_bl
);
537 encode(pspec
.snap_id
, in_bl
);
538 op
->exec("rbd", "get_children", in_bl
);
541 int get_children_finish(bufferlist::const_iterator
*it
,
542 std::set
<std::string
>* children
) {
544 decode(*children
, *it
);
545 } catch (const ceph::buffer::error
&err
) {
551 int get_children(librados::IoCtx
*ioctx
, const std::string
&oid
,
552 const cls::rbd::ParentImageSpec
&pspec
, set
<string
>& children
)
554 librados::ObjectReadOperation op
;
555 get_children_start(&op
, pspec
);
558 int r
= ioctx
->operate(oid
, &op
, &out_bl
);
563 auto it
= out_bl
.cbegin();
564 return get_children_finish(&it
, &children
);
567 void snapshot_get_start(librados::ObjectReadOperation
*op
, snapid_t snap_id
)
571 op
->exec("rbd", "snapshot_get", bl
);
574 int snapshot_get_finish(bufferlist::const_iterator
* it
,
575 cls::rbd::SnapshotInfo
* snap_info
)
578 decode(*snap_info
, *it
);
579 } catch (const ceph::buffer::error
&err
) {
585 int snapshot_get(librados::IoCtx
*ioctx
, const std::string
&oid
,
586 snapid_t snap_id
, cls::rbd::SnapshotInfo
* snap_info
)
588 librados::ObjectReadOperation op
;
589 snapshot_get_start(&op
, snap_id
);
592 int r
= ioctx
->operate(oid
, &op
, &out_bl
);
597 auto it
= out_bl
.cbegin();
598 return snapshot_get_finish(&it
, snap_info
);
601 void snapshot_add(librados::ObjectWriteOperation
*op
, snapid_t snap_id
,
602 const std::string
&snap_name
,
603 const cls::rbd::SnapshotNamespace
&snap_namespace
)
606 encode(snap_name
, bl
);
608 encode(snap_namespace
, bl
);
609 op
->exec("rbd", "snapshot_add", bl
);
612 void snapshot_remove(librados::ObjectWriteOperation
*op
, snapid_t snap_id
)
616 op
->exec("rbd", "snapshot_remove", bl
);
619 void snapshot_rename(librados::ObjectWriteOperation
*op
,
620 snapid_t src_snap_id
,
621 const std::string
&dst_name
)
624 encode(src_snap_id
, bl
);
625 encode(dst_name
, bl
);
626 op
->exec("rbd", "snapshot_rename", bl
);
629 void snapshot_trash_add(librados::ObjectWriteOperation
*op
,
634 op
->exec("rbd", "snapshot_trash_add", bl
);
637 void get_snapcontext_start(librados::ObjectReadOperation
*op
)
640 op
->exec("rbd", "get_snapcontext", bl
);
643 int get_snapcontext_finish(bufferlist::const_iterator
*it
,
644 ::SnapContext
*snapc
)
648 } catch (const ceph::buffer::error
&err
) {
651 if (!snapc
->is_valid()) {
657 int get_snapcontext(librados::IoCtx
*ioctx
, const std::string
&oid
,
658 ::SnapContext
*snapc
)
660 librados::ObjectReadOperation op
;
661 get_snapcontext_start(&op
);
664 int r
= ioctx
->operate(oid
, &op
, &out_bl
);
669 auto bl_it
= out_bl
.cbegin();
670 return get_snapcontext_finish(&bl_it
, snapc
);
673 void get_snapshot_name_start(librados::ObjectReadOperation
*op
,
678 op
->exec("rbd", "get_snapshot_name", bl
);
681 int get_snapshot_name_finish(bufferlist::const_iterator
*it
,
686 } catch (const ceph::buffer::error
&err
) {
692 int get_snapshot_name(librados::IoCtx
*ioctx
, const std::string
&oid
,
693 snapid_t snap_id
, std::string
*name
)
695 librados::ObjectReadOperation op
;
696 get_snapshot_name_start(&op
, snap_id
);
699 int r
= ioctx
->operate(oid
, &op
, &out_bl
);
704 auto it
= out_bl
.cbegin();
705 return get_snapshot_name_finish(&it
, name
);
708 void get_snapshot_timestamp_start(librados::ObjectReadOperation
*op
,
713 op
->exec("rbd", "get_snapshot_timestamp", bl
);
716 int get_snapshot_timestamp_finish(bufferlist::const_iterator
*it
,
720 decode(*timestamp
, *it
);
721 } catch (const ceph::buffer::error
&err
) {
727 int get_snapshot_timestamp(librados::IoCtx
*ioctx
, const std::string
&oid
,
728 snapid_t snap_id
, utime_t
*timestamp
)
730 librados::ObjectReadOperation op
;
731 get_snapshot_timestamp_start(&op
, snap_id
);
734 int r
= ioctx
->operate(oid
, &op
, &out_bl
);
739 auto it
= out_bl
.cbegin();
740 return get_snapshot_timestamp_finish(&it
, timestamp
);
743 void old_snapshot_add(librados::ObjectWriteOperation
*op
,
744 snapid_t snap_id
, const std::string
&snap_name
)
747 encode(snap_name
, bl
);
749 op
->exec("rbd", "snap_add", bl
);
752 void old_snapshot_remove(librados::ObjectWriteOperation
*op
,
753 const std::string
&snap_name
)
756 encode(snap_name
, bl
);
757 op
->exec("rbd", "snap_remove", bl
);
760 void old_snapshot_rename(librados::ObjectWriteOperation
*op
,
761 snapid_t src_snap_id
, const std::string
&dst_name
)
764 encode(src_snap_id
, bl
);
765 encode(dst_name
, bl
);
766 op
->exec("rbd", "snap_rename", bl
);
769 void old_snapshot_list_start(librados::ObjectReadOperation
*op
) {
771 op
->exec("rbd", "snap_list", in_bl
);
774 int old_snapshot_list_finish(bufferlist::const_iterator
*it
,
775 std::vector
<string
> *names
,
776 std::vector
<uint64_t> *sizes
,
777 ::SnapContext
*snapc
) {
780 decode(snapc
->seq
, *it
);
781 decode(num_snaps
, *it
);
783 names
->resize(num_snaps
);
784 sizes
->resize(num_snaps
);
785 snapc
->snaps
.resize(num_snaps
);
786 for (uint32_t i
= 0; i
< num_snaps
; ++i
) {
787 decode(snapc
->snaps
[i
], *it
);
788 decode((*sizes
)[i
], *it
);
789 decode((*names
)[i
], *it
);
791 } catch (const ceph::buffer::error
&err
) {
797 int old_snapshot_list(librados::IoCtx
*ioctx
, const std::string
&oid
,
798 std::vector
<string
> *names
,
799 std::vector
<uint64_t> *sizes
,
800 ::SnapContext
*snapc
)
802 librados::ObjectReadOperation op
;
803 old_snapshot_list_start(&op
);
806 int r
= ioctx
->operate(oid
, &op
, &out_bl
);
811 auto it
= out_bl
.cbegin();
812 return old_snapshot_list_finish(&it
, names
, sizes
, snapc
);
815 void get_all_features_start(librados::ObjectReadOperation
*op
) {
817 op
->exec("rbd", "get_all_features", in
);
820 int get_all_features_finish(bufferlist::const_iterator
*it
,
821 uint64_t *all_features
) {
823 decode(*all_features
, *it
);
824 } catch (const ceph::buffer::error
&err
) {
830 int get_all_features(librados::IoCtx
*ioctx
, const std::string
&oid
,
831 uint64_t *all_features
) {
832 librados::ObjectReadOperation op
;
833 get_all_features_start(&op
);
836 int r
= ioctx
->operate(oid
, &op
, &out_bl
);
841 auto it
= out_bl
.cbegin();
842 return get_all_features_finish(&it
, all_features
);
845 template <typename O
>
846 void copyup(O
* op
, ceph::buffer::list data
) {
847 op
->exec("rbd", "copyup", data
);
850 void copyup(neorados::WriteOp
* op
, ceph::buffer::list data
) {
851 copyup
<neorados::WriteOp
>(op
, data
);
854 void copyup(librados::ObjectWriteOperation
*op
, bufferlist data
) {
855 copyup
<librados::ObjectWriteOperation
>(op
, data
);
858 int copyup(librados::IoCtx
*ioctx
, const std::string
&oid
,
860 librados::ObjectWriteOperation op
;
863 return ioctx
->operate(oid
, &op
);
866 template <typename O
, typename E
>
867 void sparse_copyup(O
* op
, const E
& extent_map
, ceph::buffer::list data
) {
869 encode(extent_map
, bl
);
871 op
->exec("rbd", "sparse_copyup", bl
);
874 void sparse_copyup(neorados::WriteOp
* op
,
875 const std::vector
<std::pair
<uint64_t, uint64_t>>& extent_map
,
876 ceph::buffer::list data
) {
877 sparse_copyup
<neorados::WriteOp
>(op
, extent_map
, data
);
880 void sparse_copyup(librados::ObjectWriteOperation
*op
,
881 const std::map
<uint64_t, uint64_t> &extent_map
,
883 sparse_copyup
<librados::ObjectWriteOperation
>(op
, extent_map
, data
);
886 int sparse_copyup(librados::IoCtx
*ioctx
, const std::string
&oid
,
887 const std::map
<uint64_t, uint64_t> &extent_map
,
889 librados::ObjectWriteOperation op
;
890 sparse_copyup(&op
, extent_map
, data
);
892 return ioctx
->operate(oid
, &op
);
895 void get_protection_status_start(librados::ObjectReadOperation
*op
,
900 op
->exec("rbd", "get_protection_status", bl
);
903 int get_protection_status_finish(bufferlist::const_iterator
*it
,
904 uint8_t *protection_status
)
907 decode(*protection_status
, *it
);
908 } catch (const ceph::buffer::error
&) {
914 int get_protection_status(librados::IoCtx
*ioctx
, const std::string
&oid
,
915 snapid_t snap_id
, uint8_t *protection_status
)
917 librados::ObjectReadOperation op
;
918 get_protection_status_start(&op
, snap_id
);
921 int r
= ioctx
->operate(oid
, &op
, &out_bl
);
926 auto it
= out_bl
.cbegin();
927 return get_protection_status_finish(&it
, protection_status
);
930 int set_protection_status(librados::IoCtx
*ioctx
, const std::string
&oid
,
931 snapid_t snap_id
, uint8_t protection_status
)
934 librados::ObjectWriteOperation op
;
935 set_protection_status(&op
, snap_id
, protection_status
);
936 return ioctx
->operate(oid
, &op
);
939 void set_protection_status(librados::ObjectWriteOperation
*op
,
940 snapid_t snap_id
, uint8_t protection_status
)
944 encode(protection_status
, in
);
945 op
->exec("rbd", "set_protection_status", in
);
948 void snapshot_get_limit_start(librados::ObjectReadOperation
*op
)
951 op
->exec("rbd", "snapshot_get_limit", bl
);
954 int snapshot_get_limit_finish(bufferlist::const_iterator
*it
, uint64_t *limit
)
958 } catch (const ceph::buffer::error
&err
) {
964 int snapshot_get_limit(librados::IoCtx
*ioctx
, const std::string
&oid
,
967 librados::ObjectReadOperation op
;
968 snapshot_get_limit_start(&op
);
971 int r
= ioctx
->operate(oid
, &op
, &out_bl
);
976 auto it
= out_bl
.cbegin();
977 return snapshot_get_limit_finish(&it
, limit
);
980 void snapshot_set_limit(librados::ObjectWriteOperation
*op
, uint64_t limit
)
984 op
->exec("rbd", "snapshot_set_limit", in
);
987 void get_stripe_unit_count_start(librados::ObjectReadOperation
*op
) {
989 op
->exec("rbd", "get_stripe_unit_count", empty_bl
);
992 int get_stripe_unit_count_finish(bufferlist::const_iterator
*it
,
993 uint64_t *stripe_unit
,
994 uint64_t *stripe_count
) {
995 ceph_assert(stripe_unit
);
996 ceph_assert(stripe_count
);
999 decode(*stripe_unit
, *it
);
1000 decode(*stripe_count
, *it
);
1001 } catch (const ceph::buffer::error
&err
) {
1007 int get_stripe_unit_count(librados::IoCtx
*ioctx
, const std::string
&oid
,
1008 uint64_t *stripe_unit
, uint64_t *stripe_count
)
1010 librados::ObjectReadOperation op
;
1011 get_stripe_unit_count_start(&op
);
1014 int r
= ioctx
->operate(oid
, &op
, &out_bl
);
1019 auto it
= out_bl
.cbegin();
1020 return get_stripe_unit_count_finish(&it
, stripe_unit
, stripe_count
);
1023 void set_stripe_unit_count(librados::ObjectWriteOperation
*op
,
1024 uint64_t stripe_unit
, uint64_t stripe_count
)
1027 encode(stripe_unit
, bl
);
1028 encode(stripe_count
, bl
);
1030 op
->exec("rbd", "set_stripe_unit_count", bl
);
1033 int set_stripe_unit_count(librados::IoCtx
*ioctx
, const std::string
&oid
,
1034 uint64_t stripe_unit
, uint64_t stripe_count
)
1036 librados::ObjectWriteOperation op
;
1037 set_stripe_unit_count(&op
, stripe_unit
, stripe_count
);
1039 return ioctx
->operate(oid
, &op
);
1042 void get_create_timestamp_start(librados::ObjectReadOperation
*op
) {
1043 bufferlist empty_bl
;
1044 op
->exec("rbd", "get_create_timestamp", empty_bl
);
1047 int get_create_timestamp_finish(bufferlist::const_iterator
*it
,
1048 utime_t
*timestamp
) {
1049 ceph_assert(timestamp
);
1052 decode(*timestamp
, *it
);
1053 } catch (const ceph::buffer::error
&err
) {
1059 int get_create_timestamp(librados::IoCtx
*ioctx
, const std::string
&oid
,
1062 librados::ObjectReadOperation op
;
1063 get_create_timestamp_start(&op
);
1066 int r
= ioctx
->operate(oid
, &op
, &out_bl
);
1071 auto it
= out_bl
.cbegin();
1072 return get_create_timestamp_finish(&it
, timestamp
);
1075 void get_access_timestamp_start(librados::ObjectReadOperation
*op
) {
1076 bufferlist empty_bl
;
1077 op
->exec("rbd", "get_access_timestamp", empty_bl
);
1080 int get_access_timestamp_finish(bufferlist::const_iterator
*it
,
1081 utime_t
*timestamp
) {
1082 ceph_assert(timestamp
);
1085 decode(*timestamp
, *it
);
1086 } catch (const ceph::buffer::error
&err
) {
1092 int get_access_timestamp(librados::IoCtx
*ioctx
, const std::string
&oid
,
1095 librados::ObjectReadOperation op
;
1096 get_access_timestamp_start(&op
);
1099 int r
= ioctx
->operate(oid
, &op
, &out_bl
);
1104 auto it
= out_bl
.cbegin();
1105 return get_access_timestamp_finish(&it
, timestamp
);
1108 void set_access_timestamp(librados::ObjectWriteOperation
*op
)
1110 bufferlist empty_bl
;
1111 op
->exec("rbd","set_access_timestamp",empty_bl
);
1114 int set_access_timestamp(librados::IoCtx
*ioctx
, const std::string
&oid
)
1116 librados::ObjectWriteOperation op
;
1117 set_access_timestamp(&op
);
1118 return ioctx
->operate(oid
, &op
);
1121 void get_modify_timestamp_start(librados::ObjectReadOperation
*op
) {
1122 bufferlist empty_bl
;
1123 op
->exec("rbd", "get_modify_timestamp", empty_bl
);
1126 int get_modify_timestamp_finish(bufferlist::const_iterator
*it
,
1127 utime_t
*timestamp
) {
1128 ceph_assert(timestamp
);
1131 decode(*timestamp
, *it
);
1132 } catch (const ceph::buffer::error
&err
) {
1138 int get_modify_timestamp(librados::IoCtx
*ioctx
, const std::string
&oid
,
1141 librados::ObjectReadOperation op
;
1142 get_modify_timestamp_start(&op
);
1145 int r
= ioctx
->operate(oid
, &op
, &out_bl
);
1150 auto it
= out_bl
.cbegin();
1151 return get_modify_timestamp_finish(&it
, timestamp
);
1154 void set_modify_timestamp(librados::ObjectWriteOperation
*op
)
1156 bufferlist empty_bl
;
1157 op
->exec("rbd","set_modify_timestamp",empty_bl
);
1160 int set_modify_timestamp(librados::IoCtx
*ioctx
, const std::string
&oid
)
1162 librados::ObjectWriteOperation op
;
1163 set_modify_timestamp(&op
);
1164 return ioctx
->operate(oid
, &op
);
1168 /************************ rbd_id object methods ************************/
1170 void get_id_start(librados::ObjectReadOperation
*op
) {
1171 bufferlist empty_bl
;
1172 op
->exec("rbd", "get_id", empty_bl
);
1175 int get_id_finish(bufferlist::const_iterator
*it
, std::string
*id
) {
1178 } catch (const ceph::buffer::error
&err
) {
1184 int get_id(librados::IoCtx
*ioctx
, const std::string
&oid
, std::string
*id
)
1186 librados::ObjectReadOperation op
;
1190 int r
= ioctx
->operate(oid
, &op
, &out_bl
);
1195 auto it
= out_bl
.cbegin();
1196 return get_id_finish(&it
, id
);
1199 void set_id(librados::ObjectWriteOperation
*op
, const std::string
&id
)
1203 op
->exec("rbd", "set_id", bl
);
1206 int set_id(librados::IoCtx
*ioctx
, const std::string
&oid
, const std::string
&id
)
1208 librados::ObjectWriteOperation op
;
1211 return ioctx
->operate(oid
, &op
);
1214 /******************** rbd_directory object methods ********************/
1216 void dir_get_id_start(librados::ObjectReadOperation
*op
,
1217 const std::string
&image_name
) {
1219 encode(image_name
, bl
);
1221 op
->exec("rbd", "dir_get_id", bl
);
1224 int dir_get_id_finish(bufferlist::const_iterator
*iter
, std::string
*image_id
) {
1226 decode(*image_id
, *iter
);
1227 } catch (const ceph::buffer::error
&err
) {
1234 int dir_get_id(librados::IoCtx
*ioctx
, const std::string
&oid
,
1235 const std::string
&name
, std::string
*id
) {
1236 librados::ObjectReadOperation op
;
1237 dir_get_id_start(&op
, name
);
1240 int r
= ioctx
->operate(oid
, &op
, &out_bl
);
1245 auto iter
= out_bl
.cbegin();
1246 return dir_get_id_finish(&iter
, id
);
1249 void dir_get_name_start(librados::ObjectReadOperation
*op
,
1250 const std::string
&id
) {
1253 op
->exec("rbd", "dir_get_name", in_bl
);
1256 int dir_get_name_finish(bufferlist::const_iterator
*it
, std::string
*name
) {
1259 } catch (const ceph::buffer::error
&err
) {
1265 int dir_get_name(librados::IoCtx
*ioctx
, const std::string
&oid
,
1266 const std::string
&id
, std::string
*name
) {
1267 librados::ObjectReadOperation op
;
1268 dir_get_name_start(&op
, id
);
1271 int r
= ioctx
->operate(oid
, &op
, &out_bl
);
1276 auto it
= out_bl
.cbegin();
1277 return dir_get_name_finish(&it
, name
);
1280 void dir_list_start(librados::ObjectReadOperation
*op
,
1281 const std::string
&start
, uint64_t max_return
)
1284 encode(start
, in_bl
);
1285 encode(max_return
, in_bl
);
1287 op
->exec("rbd", "dir_list", in_bl
);
1290 int dir_list_finish(bufferlist::const_iterator
*it
, map
<string
, string
> *images
)
1293 decode(*images
, *it
);
1294 } catch (const ceph::buffer::error
&err
) {
1300 int dir_list(librados::IoCtx
*ioctx
, const std::string
&oid
,
1301 const std::string
&start
, uint64_t max_return
,
1302 map
<string
, string
> *images
)
1304 librados::ObjectReadOperation op
;
1305 dir_list_start(&op
, start
, max_return
);
1308 int r
= ioctx
->operate(oid
, &op
, &out_bl
);
1313 auto iter
= out_bl
.cbegin();
1314 return dir_list_finish(&iter
, images
);
1317 void dir_add_image(librados::ObjectWriteOperation
*op
,
1318 const std::string
&name
, const std::string
&id
)
1323 op
->exec("rbd", "dir_add_image", bl
);
1326 int dir_add_image(librados::IoCtx
*ioctx
, const std::string
&oid
,
1327 const std::string
&name
, const std::string
&id
)
1329 librados::ObjectWriteOperation op
;
1330 dir_add_image(&op
, name
, id
);
1332 return ioctx
->operate(oid
, &op
);
1335 int dir_remove_image(librados::IoCtx
*ioctx
, const std::string
&oid
,
1336 const std::string
&name
, const std::string
&id
)
1338 librados::ObjectWriteOperation op
;
1339 dir_remove_image(&op
, name
, id
);
1341 return ioctx
->operate(oid
, &op
);
1344 void dir_state_assert(librados::ObjectOperation
*op
,
1345 cls::rbd::DirectoryState directory_state
)
1348 encode(directory_state
, bl
);
1349 op
->exec("rbd", "dir_state_assert", bl
);
1352 int dir_state_assert(librados::IoCtx
*ioctx
, const std::string
&oid
,
1353 cls::rbd::DirectoryState directory_state
)
1355 librados::ObjectWriteOperation op
;
1356 dir_state_assert(&op
, directory_state
);
1358 return ioctx
->operate(oid
, &op
);
1361 void dir_state_set(librados::ObjectWriteOperation
*op
,
1362 cls::rbd::DirectoryState directory_state
)
1365 encode(directory_state
, bl
);
1366 op
->exec("rbd", "dir_state_set", bl
);
1369 int dir_state_set(librados::IoCtx
*ioctx
, const std::string
&oid
,
1370 cls::rbd::DirectoryState directory_state
)
1372 librados::ObjectWriteOperation op
;
1373 dir_state_set(&op
, directory_state
);
1375 return ioctx
->operate(oid
, &op
);
1378 void dir_remove_image(librados::ObjectWriteOperation
*op
,
1379 const std::string
&name
, const std::string
&id
)
1385 op
->exec("rbd", "dir_remove_image", bl
);
1388 void dir_rename_image(librados::ObjectWriteOperation
*op
,
1389 const std::string
&src
, const std::string
&dest
,
1390 const std::string
&id
)
1396 op
->exec("rbd", "dir_rename_image", in
);
1399 void object_map_load_start(librados::ObjectReadOperation
*op
) {
1401 op
->exec("rbd", "object_map_load", in_bl
);
1404 int object_map_load_finish(bufferlist::const_iterator
*it
,
1405 ceph::BitVector
<2> *object_map
) {
1407 decode(*object_map
, *it
);
1408 } catch (const ceph::buffer::error
&err
) {
1414 int object_map_load(librados::IoCtx
*ioctx
, const std::string
&oid
,
1415 ceph::BitVector
<2> *object_map
)
1417 librados::ObjectReadOperation op
;
1418 object_map_load_start(&op
);
1421 int r
= ioctx
->operate(oid
, &op
, &out_bl
);
1426 auto it
= out_bl
.cbegin();
1427 return object_map_load_finish(&it
, object_map
);
1430 void object_map_save(librados::ObjectWriteOperation
*rados_op
,
1431 const ceph::BitVector
<2> &object_map
)
1433 ceph::BitVector
<2> object_map_copy(object_map
);
1434 object_map_copy
.set_crc_enabled(false);
1437 encode(object_map_copy
, in
);
1438 rados_op
->exec("rbd", "object_map_save", in
);
1441 void object_map_resize(librados::ObjectWriteOperation
*rados_op
,
1442 uint64_t object_count
, uint8_t default_state
)
1445 encode(object_count
, in
);
1446 encode(default_state
, in
);
1447 rados_op
->exec("rbd", "object_map_resize", in
);
1450 void object_map_update(librados::ObjectWriteOperation
*rados_op
,
1451 uint64_t start_object_no
, uint64_t end_object_no
,
1452 uint8_t new_object_state
,
1453 const boost::optional
<uint8_t> ¤t_object_state
)
1456 encode(start_object_no
, in
);
1457 encode(end_object_no
, in
);
1458 encode(new_object_state
, in
);
1459 encode(current_object_state
, in
);
1460 rados_op
->exec("rbd", "object_map_update", in
);
1463 void object_map_snap_add(librados::ObjectWriteOperation
*rados_op
)
1466 rados_op
->exec("rbd", "object_map_snap_add", in
);
1469 void object_map_snap_remove(librados::ObjectWriteOperation
*rados_op
,
1470 const ceph::BitVector
<2> &object_map
)
1472 ceph::BitVector
<2> object_map_copy(object_map
);
1473 object_map_copy
.set_crc_enabled(false);
1476 encode(object_map_copy
, in
);
1477 rados_op
->exec("rbd", "object_map_snap_remove", in
);
1480 void metadata_set(librados::ObjectWriteOperation
*op
,
1481 const map
<string
, bufferlist
> &data
)
1486 op
->exec("rbd", "metadata_set", bl
);
1489 int metadata_set(librados::IoCtx
*ioctx
, const std::string
&oid
,
1490 const map
<string
, bufferlist
> &data
)
1492 librados::ObjectWriteOperation op
;
1493 metadata_set(&op
, data
);
1495 return ioctx
->operate(oid
, &op
);
1498 void metadata_remove(librados::ObjectWriteOperation
*op
,
1499 const std::string
&key
)
1504 op
->exec("rbd", "metadata_remove", bl
);
1507 int metadata_remove(librados::IoCtx
*ioctx
, const std::string
&oid
,
1508 const std::string
&key
)
1510 librados::ObjectWriteOperation op
;
1511 metadata_remove(&op
, key
);
1513 return ioctx
->operate(oid
, &op
);
1516 int metadata_list(librados::IoCtx
*ioctx
, const std::string
&oid
,
1517 const std::string
&start
, uint64_t max_return
,
1518 map
<string
, bufferlist
> *pairs
)
1520 librados::ObjectReadOperation op
;
1521 metadata_list_start(&op
, start
, max_return
);
1524 int r
= ioctx
->operate(oid
, &op
, &out_bl
);
1529 auto it
= out_bl
.cbegin();
1530 return metadata_list_finish(&it
, pairs
);
1533 void metadata_list_start(librados::ObjectReadOperation
*op
,
1534 const std::string
&start
, uint64_t max_return
)
1537 encode(start
, in_bl
);
1538 encode(max_return
, in_bl
);
1539 op
->exec("rbd", "metadata_list", in_bl
);
1542 int metadata_list_finish(bufferlist::const_iterator
*it
,
1543 std::map
<std::string
, bufferlist
> *pairs
)
1547 decode(*pairs
, *it
);
1548 } catch (const ceph::buffer::error
&err
) {
1554 void metadata_get_start(librados::ObjectReadOperation
* op
,
1555 const std::string
&key
) {
1559 op
->exec("rbd", "metadata_get", bl
);
1562 int metadata_get_finish(bufferlist::const_iterator
*it
,
1563 std::string
* value
) {
1565 decode(*value
, *it
);
1566 } catch (const ceph::buffer::error
&err
) {
1572 int metadata_get(librados::IoCtx
*ioctx
, const std::string
&oid
,
1573 const std::string
&key
, string
*s
)
1576 librados::ObjectReadOperation op
;
1577 metadata_get_start(&op
, key
);
1580 int r
= ioctx
->operate(oid
, &op
, &out_bl
);
1585 auto it
= out_bl
.cbegin();
1586 r
= metadata_get_finish(&it
, s
);
1593 void child_attach(librados::ObjectWriteOperation
*op
, snapid_t snap_id
,
1594 const cls::rbd::ChildImageSpec
& child_image
)
1597 encode(snap_id
, bl
);
1598 encode(child_image
, bl
);
1599 op
->exec("rbd", "child_attach", bl
);
1602 int child_attach(librados::IoCtx
*ioctx
, const std::string
&oid
,
1604 const cls::rbd::ChildImageSpec
& child_image
)
1606 librados::ObjectWriteOperation op
;
1607 child_attach(&op
, snap_id
, child_image
);
1609 int r
= ioctx
->operate(oid
, &op
);
1616 void child_detach(librados::ObjectWriteOperation
*op
, snapid_t snap_id
,
1617 const cls::rbd::ChildImageSpec
& child_image
)
1620 encode(snap_id
, bl
);
1621 encode(child_image
, bl
);
1622 op
->exec("rbd", "child_detach", bl
);
1625 int child_detach(librados::IoCtx
*ioctx
, const std::string
&oid
,
1627 const cls::rbd::ChildImageSpec
& child_image
)
1629 librados::ObjectWriteOperation op
;
1630 child_detach(&op
, snap_id
, child_image
);
1632 int r
= ioctx
->operate(oid
, &op
);
1639 void children_list_start(librados::ObjectReadOperation
*op
,
1643 encode(snap_id
, bl
);
1644 op
->exec("rbd", "children_list", bl
);
1647 int children_list_finish(bufferlist::const_iterator
*it
,
1648 cls::rbd::ChildImageSpecs
*child_images
)
1650 child_images
->clear();
1652 decode(*child_images
, *it
);
1653 } catch (const ceph::buffer::error
&err
) {
1659 int children_list(librados::IoCtx
*ioctx
, const std::string
&oid
,
1661 cls::rbd::ChildImageSpecs
*child_images
)
1663 librados::ObjectReadOperation op
;
1664 children_list_start(&op
, snap_id
);
1667 int r
= ioctx
->operate(oid
, &op
, &out_bl
);
1672 auto it
= out_bl
.cbegin();
1673 r
= children_list_finish(&it
, child_images
);
1680 int migration_set(librados::IoCtx
*ioctx
, const std::string
&oid
,
1681 const cls::rbd::MigrationSpec
&migration_spec
) {
1682 librados::ObjectWriteOperation op
;
1683 migration_set(&op
, migration_spec
);
1684 return ioctx
->operate(oid
, &op
);
1687 void migration_set(librados::ObjectWriteOperation
*op
,
1688 const cls::rbd::MigrationSpec
&migration_spec
) {
1690 encode(migration_spec
, bl
);
1691 op
->exec("rbd", "migration_set", bl
);
1694 int migration_set_state(librados::IoCtx
*ioctx
, const std::string
&oid
,
1695 cls::rbd::MigrationState state
,
1696 const std::string
&description
) {
1697 librados::ObjectWriteOperation op
;
1698 migration_set_state(&op
, state
, description
);
1699 return ioctx
->operate(oid
, &op
);
1702 void migration_set_state(librados::ObjectWriteOperation
*op
,
1703 cls::rbd::MigrationState state
,
1704 const std::string
&description
) {
1707 encode(description
, bl
);
1708 op
->exec("rbd", "migration_set_state", bl
);
1711 void migration_get_start(librados::ObjectReadOperation
*op
) {
1713 op
->exec("rbd", "migration_get", bl
);
1716 int migration_get_finish(bufferlist::const_iterator
*it
,
1717 cls::rbd::MigrationSpec
*migration_spec
) {
1719 decode(*migration_spec
, *it
);
1720 } catch (const ceph::buffer::error
&err
) {
1726 int migration_get(librados::IoCtx
*ioctx
, const std::string
&oid
,
1727 cls::rbd::MigrationSpec
*migration_spec
) {
1728 librados::ObjectReadOperation op
;
1729 migration_get_start(&op
);
1732 int r
= ioctx
->operate(oid
, &op
, &out_bl
);
1737 auto iter
= out_bl
.cbegin();
1738 r
= migration_get_finish(&iter
, migration_spec
);
1745 int migration_remove(librados::IoCtx
*ioctx
, const std::string
&oid
) {
1746 librados::ObjectWriteOperation op
;
1747 migration_remove(&op
);
1748 return ioctx
->operate(oid
, &op
);
1751 void migration_remove(librados::ObjectWriteOperation
*op
) {
1753 op
->exec("rbd", "migration_remove", bl
);
1756 template <typename O
>
1757 void assert_snapc_seq(O
* op
, uint64_t snapc_seq
,
1758 cls::rbd::AssertSnapcSeqState state
) {
1760 encode(snapc_seq
, bl
);
1762 op
->exec("rbd", "assert_snapc_seq", bl
);
1765 void assert_snapc_seq(neorados::WriteOp
* op
,
1767 cls::rbd::AssertSnapcSeqState state
) {
1768 assert_snapc_seq
<neorados::WriteOp
>(op
, snapc_seq
, state
);
1771 void assert_snapc_seq(librados::ObjectWriteOperation
*op
,
1773 cls::rbd::AssertSnapcSeqState state
) {
1774 assert_snapc_seq
<librados::ObjectWriteOperation
>(op
, snapc_seq
, state
);
1777 int assert_snapc_seq(librados::IoCtx
*ioctx
, const std::string
&oid
,
1779 cls::rbd::AssertSnapcSeqState state
) {
1780 librados::ObjectWriteOperation op
;
1781 assert_snapc_seq(&op
, snapc_seq
, state
);
1782 return ioctx
->operate(oid
, &op
);
1785 void mirror_uuid_get_start(librados::ObjectReadOperation
*op
) {
1787 op
->exec("rbd", "mirror_uuid_get", bl
);
1790 int mirror_uuid_get_finish(bufferlist::const_iterator
*it
,
1791 std::string
*uuid
) {
1794 } catch (const ceph::buffer::error
&err
) {
1800 int mirror_uuid_get(librados::IoCtx
*ioctx
, std::string
*uuid
) {
1801 librados::ObjectReadOperation op
;
1802 mirror_uuid_get_start(&op
);
1805 int r
= ioctx
->operate(RBD_MIRRORING
, &op
, &out_bl
);
1810 auto it
= out_bl
.cbegin();
1811 r
= mirror_uuid_get_finish(&it
, uuid
);
1818 int mirror_uuid_set(librados::IoCtx
*ioctx
, const std::string
&uuid
) {
1820 encode(uuid
, in_bl
);
1823 int r
= ioctx
->exec(RBD_MIRRORING
, "rbd", "mirror_uuid_set", in_bl
,
1831 void mirror_mode_get_start(librados::ObjectReadOperation
*op
) {
1833 op
->exec("rbd", "mirror_mode_get", bl
);
1836 int mirror_mode_get_finish(bufferlist::const_iterator
*it
,
1837 cls::rbd::MirrorMode
*mirror_mode
) {
1839 uint32_t mirror_mode_decode
;
1840 decode(mirror_mode_decode
, *it
);
1841 *mirror_mode
= static_cast<cls::rbd::MirrorMode
>(mirror_mode_decode
);
1842 } catch (const ceph::buffer::error
&err
) {
1849 int mirror_mode_get(librados::IoCtx
*ioctx
,
1850 cls::rbd::MirrorMode
*mirror_mode
) {
1851 librados::ObjectReadOperation op
;
1852 mirror_mode_get_start(&op
);
1855 int r
= ioctx
->operate(RBD_MIRRORING
, &op
, &out_bl
);
1857 *mirror_mode
= cls::rbd::MIRROR_MODE_DISABLED
;
1863 auto it
= out_bl
.cbegin();
1864 r
= mirror_mode_get_finish(&it
, mirror_mode
);
1871 int mirror_mode_set(librados::IoCtx
*ioctx
,
1872 cls::rbd::MirrorMode mirror_mode
) {
1874 encode(static_cast<uint32_t>(mirror_mode
), in_bl
);
1877 int r
= ioctx
->exec(RBD_MIRRORING
, "rbd", "mirror_mode_set", in_bl
,
1885 void mirror_peer_list_start(librados::ObjectReadOperation
*op
) {
1887 op
->exec("rbd", "mirror_peer_list", bl
);
1890 int mirror_peer_list_finish(bufferlist::const_iterator
*it
,
1891 std::vector
<cls::rbd::MirrorPeer
> *peers
) {
1894 decode(*peers
, *it
);
1895 } catch (const ceph::buffer::error
&err
) {
1901 int mirror_peer_list(librados::IoCtx
*ioctx
,
1902 std::vector
<cls::rbd::MirrorPeer
> *peers
) {
1903 librados::ObjectReadOperation op
;
1904 mirror_peer_list_start(&op
);
1907 int r
= ioctx
->operate(RBD_MIRRORING
, &op
, &out_bl
);
1912 auto it
= out_bl
.cbegin();
1913 r
= mirror_peer_list_finish(&it
, peers
);
1920 int mirror_peer_ping(librados::IoCtx
*ioctx
,
1921 const std::string
& site_name
,
1922 const std::string
& fsid
) {
1923 librados::ObjectWriteOperation op
;
1924 mirror_peer_ping(&op
, site_name
, fsid
);
1926 int r
= ioctx
->operate(RBD_MIRRORING
, &op
);
1934 void mirror_peer_ping(librados::ObjectWriteOperation
*op
,
1935 const std::string
& site_name
,
1936 const std::string
& fsid
) {
1938 encode(site_name
, in_bl
);
1939 encode(fsid
, in_bl
);
1940 encode(static_cast<uint8_t>(cls::rbd::MIRROR_PEER_DIRECTION_TX
), in_bl
);
1942 op
->exec("rbd", "mirror_peer_ping", in_bl
);
1945 int mirror_peer_add(librados::IoCtx
*ioctx
,
1946 const cls::rbd::MirrorPeer
& mirror_peer
) {
1947 librados::ObjectWriteOperation op
;
1948 mirror_peer_add(&op
, mirror_peer
);
1950 int r
= ioctx
->operate(RBD_MIRRORING
, &op
);
1958 void mirror_peer_add(librados::ObjectWriteOperation
*op
,
1959 const cls::rbd::MirrorPeer
& mirror_peer
) {
1961 encode(mirror_peer
, in_bl
);
1963 op
->exec("rbd", "mirror_peer_add", in_bl
);
1966 int mirror_peer_remove(librados::IoCtx
*ioctx
,
1967 const std::string
&uuid
) {
1969 encode(uuid
, in_bl
);
1972 int r
= ioctx
->exec(RBD_MIRRORING
, "rbd", "mirror_peer_remove", in_bl
,
1980 int mirror_peer_set_client(librados::IoCtx
*ioctx
,
1981 const std::string
&uuid
,
1982 const std::string
&client_name
) {
1984 encode(uuid
, in_bl
);
1985 encode(client_name
, in_bl
);
1988 int r
= ioctx
->exec(RBD_MIRRORING
, "rbd", "mirror_peer_set_client",
1996 int mirror_peer_set_cluster(librados::IoCtx
*ioctx
,
1997 const std::string
&uuid
,
1998 const std::string
&cluster_name
) {
2000 encode(uuid
, in_bl
);
2001 encode(cluster_name
, in_bl
);
2004 int r
= ioctx
->exec(RBD_MIRRORING
, "rbd", "mirror_peer_set_cluster",
2012 int mirror_peer_set_direction(
2013 librados::IoCtx
*ioctx
, const std::string
&uuid
,
2014 cls::rbd::MirrorPeerDirection mirror_peer_direction
) {
2016 encode(uuid
, in_bl
);
2017 encode(static_cast<uint8_t>(mirror_peer_direction
), in_bl
);
2020 int r
= ioctx
->exec(RBD_MIRRORING
, "rbd", "mirror_peer_set_direction",
2028 void mirror_image_list_start(librados::ObjectReadOperation
*op
,
2029 const std::string
&start
, uint64_t max_return
)
2032 encode(start
, in_bl
);
2033 encode(max_return
, in_bl
);
2034 op
->exec("rbd", "mirror_image_list", in_bl
);
2037 int mirror_image_list_finish(bufferlist::const_iterator
*it
,
2038 std::map
<string
, string
> *mirror_image_ids
)
2041 decode(*mirror_image_ids
, *it
);
2042 } catch (const ceph::buffer::error
&err
) {
2048 int mirror_image_list(librados::IoCtx
*ioctx
,
2049 const std::string
&start
, uint64_t max_return
,
2050 std::map
<std::string
, std::string
> *mirror_image_ids
) {
2051 librados::ObjectReadOperation op
;
2052 mirror_image_list_start(&op
, start
, max_return
);
2055 int r
= ioctx
->operate(RBD_MIRRORING
, &op
, &out_bl
);
2060 auto bl_it
= out_bl
.cbegin();
2061 return mirror_image_list_finish(&bl_it
, mirror_image_ids
);
2064 void mirror_image_get_image_id_start(librados::ObjectReadOperation
*op
,
2065 const std::string
&global_image_id
) {
2067 encode(global_image_id
, in_bl
);
2068 op
->exec( "rbd", "mirror_image_get_image_id", in_bl
);
2071 int mirror_image_get_image_id_finish(bufferlist::const_iterator
*it
,
2072 std::string
*image_id
) {
2074 decode(*image_id
, *it
);
2075 } catch (const ceph::buffer::error
&err
) {
2081 int mirror_image_get_image_id(librados::IoCtx
*ioctx
,
2082 const std::string
&global_image_id
,
2083 std::string
*image_id
) {
2084 librados::ObjectReadOperation op
;
2085 mirror_image_get_image_id_start(&op
, global_image_id
);
2088 int r
= ioctx
->operate(RBD_MIRRORING
, &op
, &out_bl
);
2093 auto it
= out_bl
.cbegin();
2094 return mirror_image_get_image_id_finish(&it
, image_id
);
2097 int mirror_image_get(librados::IoCtx
*ioctx
, const std::string
&image_id
,
2098 cls::rbd::MirrorImage
*mirror_image
) {
2099 librados::ObjectReadOperation op
;
2100 mirror_image_get_start(&op
, image_id
);
2103 int r
= ioctx
->operate(RBD_MIRRORING
, &op
, &out_bl
);
2108 auto iter
= out_bl
.cbegin();
2109 r
= mirror_image_get_finish(&iter
, mirror_image
);
2116 void mirror_image_get_start(librados::ObjectReadOperation
*op
,
2117 const std::string
&image_id
) {
2119 encode(image_id
, in_bl
);
2121 op
->exec("rbd", "mirror_image_get", in_bl
);
2124 int mirror_image_get_finish(bufferlist::const_iterator
*iter
,
2125 cls::rbd::MirrorImage
*mirror_image
) {
2127 decode(*mirror_image
, *iter
);
2128 } catch (const ceph::buffer::error
&err
) {
2134 void mirror_image_set(librados::ObjectWriteOperation
*op
,
2135 const std::string
&image_id
,
2136 const cls::rbd::MirrorImage
&mirror_image
) {
2138 encode(image_id
, bl
);
2139 encode(mirror_image
, bl
);
2141 op
->exec("rbd", "mirror_image_set", bl
);
2144 int mirror_image_set(librados::IoCtx
*ioctx
, const std::string
&image_id
,
2145 const cls::rbd::MirrorImage
&mirror_image
) {
2146 librados::ObjectWriteOperation op
;
2147 mirror_image_set(&op
, image_id
, mirror_image
);
2149 int r
= ioctx
->operate(RBD_MIRRORING
, &op
);
2156 void mirror_image_remove(librados::ObjectWriteOperation
*op
,
2157 const std::string
&image_id
) {
2159 encode(image_id
, bl
);
2161 op
->exec("rbd", "mirror_image_remove", bl
);
2164 int mirror_image_remove(librados::IoCtx
*ioctx
, const std::string
&image_id
) {
2165 librados::ObjectWriteOperation op
;
2166 mirror_image_remove(&op
, image_id
);
2168 int r
= ioctx
->operate(RBD_MIRRORING
, &op
);
2175 int mirror_image_status_set(librados::IoCtx
*ioctx
,
2176 const std::string
&global_image_id
,
2177 const cls::rbd::MirrorImageSiteStatus
&status
) {
2178 librados::ObjectWriteOperation op
;
2179 mirror_image_status_set(&op
, global_image_id
, status
);
2180 return ioctx
->operate(RBD_MIRRORING
, &op
);
2183 void mirror_image_status_set(librados::ObjectWriteOperation
*op
,
2184 const std::string
&global_image_id
,
2185 const cls::rbd::MirrorImageSiteStatus
&status
) {
2187 encode(global_image_id
, bl
);
2189 op
->exec("rbd", "mirror_image_status_set", bl
);
2192 int mirror_image_status_get(librados::IoCtx
*ioctx
,
2193 const std::string
&global_image_id
,
2194 cls::rbd::MirrorImageStatus
*status
) {
2195 librados::ObjectReadOperation op
;
2196 mirror_image_status_get_start(&op
, global_image_id
);
2199 int r
= ioctx
->operate(RBD_MIRRORING
, &op
, &out_bl
);
2204 auto iter
= out_bl
.cbegin();
2205 r
= mirror_image_status_get_finish(&iter
, status
);
2212 void mirror_image_status_get_start(librados::ObjectReadOperation
*op
,
2213 const std::string
&global_image_id
) {
2215 encode(global_image_id
, bl
);
2216 op
->exec("rbd", "mirror_image_status_get", bl
);
2219 int mirror_image_status_get_finish(bufferlist::const_iterator
*iter
,
2220 cls::rbd::MirrorImageStatus
*status
) {
2222 decode(*status
, *iter
);
2223 } catch (const ceph::buffer::error
&err
) {
2229 int mirror_image_status_list(librados::IoCtx
*ioctx
,
2230 const std::string
&start
, uint64_t max_return
,
2231 std::map
<std::string
, cls::rbd::MirrorImage
> *images
,
2232 std::map
<std::string
, cls::rbd::MirrorImageStatus
> *statuses
) {
2233 librados::ObjectReadOperation op
;
2234 mirror_image_status_list_start(&op
, start
, max_return
);
2237 int r
= ioctx
->operate(RBD_MIRRORING
, &op
, &out_bl
);
2242 auto iter
= out_bl
.cbegin();
2243 r
= mirror_image_status_list_finish(&iter
, images
, statuses
);
2250 void mirror_image_status_list_start(librados::ObjectReadOperation
*op
,
2251 const std::string
&start
,
2252 uint64_t max_return
) {
2255 encode(max_return
, bl
);
2256 op
->exec("rbd", "mirror_image_status_list", bl
);
2259 int mirror_image_status_list_finish(bufferlist::const_iterator
*iter
,
2260 std::map
<std::string
, cls::rbd::MirrorImage
> *images
,
2261 std::map
<std::string
, cls::rbd::MirrorImageStatus
> *statuses
) {
2265 decode(*images
, *iter
);
2266 decode(*statuses
, *iter
);
2267 } catch (const ceph::buffer::error
&err
) {
2273 int mirror_image_status_get_summary(
2274 librados::IoCtx
*ioctx
,
2275 const std::vector
<cls::rbd::MirrorPeer
>& mirror_peer_sites
,
2276 std::map
<cls::rbd::MirrorImageStatusState
, int32_t> *states
) {
2277 librados::ObjectReadOperation op
;
2278 mirror_image_status_get_summary_start(&op
, mirror_peer_sites
);
2281 int r
= ioctx
->operate(RBD_MIRRORING
, &op
, &out_bl
);
2286 auto iter
= out_bl
.cbegin();
2287 r
= mirror_image_status_get_summary_finish(&iter
, states
);
2294 void mirror_image_status_get_summary_start(
2295 librados::ObjectReadOperation
*op
,
2296 const std::vector
<cls::rbd::MirrorPeer
>& mirror_peer_sites
) {
2298 encode(mirror_peer_sites
, bl
);
2299 op
->exec("rbd", "mirror_image_status_get_summary", bl
);
2302 int mirror_image_status_get_summary_finish(
2303 bufferlist::const_iterator
*iter
,
2304 std::map
<cls::rbd::MirrorImageStatusState
, int32_t> *states
) {
2306 decode(*states
, *iter
);
2307 } catch (const ceph::buffer::error
&err
) {
2313 int mirror_image_status_remove_down(librados::IoCtx
*ioctx
) {
2314 librados::ObjectWriteOperation op
;
2315 mirror_image_status_remove_down(&op
);
2316 return ioctx
->operate(RBD_MIRRORING
, &op
);
2319 void mirror_image_status_remove_down(librados::ObjectWriteOperation
*op
) {
2321 op
->exec("rbd", "mirror_image_status_remove_down", bl
);
2324 int mirror_image_instance_get(librados::IoCtx
*ioctx
,
2325 const std::string
&global_image_id
,
2326 entity_inst_t
*instance
) {
2327 librados::ObjectReadOperation op
;
2328 mirror_image_instance_get_start(&op
, global_image_id
);
2331 int r
= ioctx
->operate(RBD_MIRRORING
, &op
, &out_bl
);
2336 auto iter
= out_bl
.cbegin();
2337 r
= mirror_image_instance_get_finish(&iter
, instance
);
2344 void mirror_image_instance_get_start(librados::ObjectReadOperation
*op
,
2345 const std::string
&global_image_id
) {
2347 encode(global_image_id
, bl
);
2348 op
->exec("rbd", "mirror_image_instance_get", bl
);
2351 int mirror_image_instance_get_finish(bufferlist::const_iterator
*iter
,
2352 entity_inst_t
*instance
) {
2354 decode(*instance
, *iter
);
2355 } catch (const ceph::buffer::error
&err
) {
2361 int mirror_image_instance_list(
2362 librados::IoCtx
*ioctx
, const std::string
&start
, uint64_t max_return
,
2363 std::map
<std::string
, entity_inst_t
> *instances
) {
2364 librados::ObjectReadOperation op
;
2365 mirror_image_instance_list_start(&op
, start
, max_return
);
2368 int r
= ioctx
->operate(RBD_MIRRORING
, &op
, &out_bl
);
2373 auto iter
= out_bl
.cbegin();
2374 r
= mirror_image_instance_list_finish(&iter
, instances
);
2381 void mirror_image_instance_list_start(librados::ObjectReadOperation
*op
,
2382 const std::string
&start
,
2383 uint64_t max_return
) {
2386 encode(max_return
, bl
);
2387 op
->exec("rbd", "mirror_image_instance_list", bl
);
2390 int mirror_image_instance_list_finish(
2391 bufferlist::const_iterator
*iter
,
2392 std::map
<std::string
, entity_inst_t
> *instances
) {
2395 decode(*instances
, *iter
);
2396 } catch (const ceph::buffer::error
&err
) {
2402 void mirror_instances_list_start(librados::ObjectReadOperation
*op
) {
2404 op
->exec("rbd", "mirror_instances_list", bl
);
2407 int mirror_instances_list_finish(bufferlist::const_iterator
*iter
,
2408 std::vector
<std::string
> *instance_ids
) {
2409 instance_ids
->clear();
2411 decode(*instance_ids
, *iter
);
2412 } catch (const ceph::buffer::error
&err
) {
2418 int mirror_instances_list(librados::IoCtx
*ioctx
,
2419 std::vector
<std::string
> *instance_ids
) {
2420 librados::ObjectReadOperation op
;
2421 mirror_instances_list_start(&op
);
2424 int r
= ioctx
->operate(RBD_MIRROR_LEADER
, &op
, &out_bl
);
2429 auto iter
= out_bl
.cbegin();
2430 r
= mirror_instances_list_finish(&iter
, instance_ids
);
2437 void mirror_instances_add(librados::ObjectWriteOperation
*op
,
2438 const std::string
&instance_id
) {
2440 encode(instance_id
, bl
);
2441 op
->exec("rbd", "mirror_instances_add", bl
);
2444 int mirror_instances_add(librados::IoCtx
*ioctx
,
2445 const std::string
&instance_id
) {
2446 librados::ObjectWriteOperation op
;
2447 mirror_instances_add(&op
, instance_id
);
2448 return ioctx
->operate(RBD_MIRROR_LEADER
, &op
);
2451 void mirror_instances_remove(librados::ObjectWriteOperation
*op
,
2452 const std::string
&instance_id
) {
2454 encode(instance_id
, bl
);
2455 op
->exec("rbd", "mirror_instances_remove", bl
);
2458 int mirror_instances_remove(librados::IoCtx
*ioctx
,
2459 const std::string
&instance_id
) {
2460 librados::ObjectWriteOperation op
;
2461 mirror_instances_remove(&op
, instance_id
);
2462 return ioctx
->operate(RBD_MIRROR_LEADER
, &op
);
2465 void mirror_image_map_list_start(librados::ObjectReadOperation
*op
,
2466 const std::string
&start_after
,
2467 uint64_t max_read
) {
2469 encode(start_after
, bl
);
2470 encode(max_read
, bl
);
2472 op
->exec("rbd", "mirror_image_map_list", bl
);
2475 int mirror_image_map_list_finish(bufferlist::const_iterator
*iter
,
2476 std::map
<std::string
, cls::rbd::MirrorImageMap
> *image_mapping
) {
2478 decode(*image_mapping
, *iter
);
2479 } catch (const ceph::buffer::error
&err
) {
2485 int mirror_image_map_list(
2486 librados::IoCtx
*ioctx
, const std::string
&start_after
,
2488 std::map
<std::string
, cls::rbd::MirrorImageMap
> *image_mapping
) {
2489 librados::ObjectReadOperation op
;
2490 mirror_image_map_list_start(&op
, start_after
, max_read
);
2493 int r
= ioctx
->operate(RBD_MIRRORING
, &op
, &out_bl
);
2498 auto iter
= out_bl
.cbegin();
2499 return mirror_image_map_list_finish(&iter
, image_mapping
);
2502 void mirror_image_map_update(librados::ObjectWriteOperation
*op
,
2503 const std::string
&global_image_id
,
2504 const cls::rbd::MirrorImageMap
&image_map
) {
2506 encode(global_image_id
, bl
);
2507 encode(image_map
, bl
);
2509 op
->exec("rbd", "mirror_image_map_update", bl
);
2512 void mirror_image_map_remove(librados::ObjectWriteOperation
*op
,
2513 const std::string
&global_image_id
) {
2515 encode(global_image_id
, bl
);
2517 op
->exec("rbd", "mirror_image_map_remove", bl
);
2520 void mirror_image_snapshot_unlink_peer(librados::ObjectWriteOperation
*op
,
2522 const std::string
&mirror_peer_uuid
) {
2524 encode(snap_id
, bl
);
2525 encode(mirror_peer_uuid
, bl
);
2527 op
->exec("rbd", "mirror_image_snapshot_unlink_peer", bl
);
2530 int mirror_image_snapshot_unlink_peer(librados::IoCtx
*ioctx
,
2531 const std::string
&oid
,
2533 const std::string
&mirror_peer_uuid
) {
2534 librados::ObjectWriteOperation op
;
2535 mirror_image_snapshot_unlink_peer(&op
, snap_id
, mirror_peer_uuid
);
2536 return ioctx
->operate(oid
, &op
);
2539 void mirror_image_snapshot_set_copy_progress(librados::ObjectWriteOperation
*op
,
2540 snapid_t snap_id
, bool complete
,
2541 uint64_t copy_progress
) {
2543 encode(snap_id
, bl
);
2544 encode(complete
, bl
);
2545 encode(copy_progress
, bl
);
2547 op
->exec("rbd", "mirror_image_snapshot_set_copy_progress", bl
);
2550 int mirror_image_snapshot_set_copy_progress(librados::IoCtx
*ioctx
,
2551 const std::string
&oid
,
2552 snapid_t snap_id
, bool complete
,
2553 uint64_t copy_progress
) {
2554 librados::ObjectWriteOperation op
;
2555 mirror_image_snapshot_set_copy_progress(&op
, snap_id
, complete
,
2557 return ioctx
->operate(oid
, &op
);
2561 int group_dir_list(librados::IoCtx
*ioctx
, const std::string
&oid
,
2562 const std::string
&start
, uint64_t max_return
,
2563 map
<string
, string
> *cgs
)
2567 encode(max_return
, in
);
2568 int r
= ioctx
->exec(oid
, "rbd", "group_dir_list", in
, out
);
2572 auto iter
= out
.cbegin();
2575 } catch (const ceph::buffer::error
&err
) {
2582 int group_dir_add(librados::IoCtx
*ioctx
, const std::string
&oid
,
2583 const std::string
&name
, const std::string
&id
)
2588 return ioctx
->exec(oid
, "rbd", "group_dir_add", in
, out
);
2591 int group_dir_rename(librados::IoCtx
*ioctx
, const std::string
&oid
,
2592 const std::string
&src
, const std::string
&dest
,
2593 const std::string
&id
)
2599 return ioctx
->exec(oid
, "rbd", "group_dir_rename", in
, out
);
2602 int group_dir_remove(librados::IoCtx
*ioctx
, const std::string
&oid
,
2603 const std::string
&name
, const std::string
&id
)
2608 return ioctx
->exec(oid
, "rbd", "group_dir_remove", in
, out
);
2611 int group_image_remove(librados::IoCtx
*ioctx
, const std::string
&oid
,
2612 const cls::rbd::GroupImageSpec
&spec
)
2617 return ioctx
->exec(oid
, "rbd", "group_image_remove", bl
, bl2
);
2620 int group_image_list(librados::IoCtx
*ioctx
,
2621 const std::string
&oid
,
2622 const cls::rbd::GroupImageSpec
&start
,
2623 uint64_t max_return
,
2624 std::vector
<cls::rbd::GroupImageStatus
> *images
)
2628 encode(max_return
, bl
);
2630 int r
= ioctx
->exec(oid
, "rbd", "group_image_list", bl
, bl2
);
2634 auto iter
= bl2
.cbegin();
2636 decode(*images
, iter
);
2637 } catch (const ceph::buffer::error
&err
) {
2644 int group_image_set(librados::IoCtx
*ioctx
, const std::string
&oid
,
2645 const cls::rbd::GroupImageStatus
&st
)
2650 return ioctx
->exec(oid
, "rbd", "group_image_set", bl
, bl2
);
2653 int image_group_add(librados::IoCtx
*ioctx
, const std::string
&oid
,
2654 const cls::rbd::GroupSpec
&group_spec
)
2657 encode(group_spec
, bl
);
2659 return ioctx
->exec(oid
, "rbd", "image_group_add", bl
, bl2
);
2662 int image_group_remove(librados::IoCtx
*ioctx
, const std::string
&oid
,
2663 const cls::rbd::GroupSpec
&group_spec
)
2666 encode(group_spec
, bl
);
2668 return ioctx
->exec(oid
, "rbd", "image_group_remove", bl
, bl2
);
2671 void image_group_get_start(librados::ObjectReadOperation
*op
)
2674 op
->exec("rbd", "image_group_get", in_bl
);
2677 int image_group_get_finish(bufferlist::const_iterator
*iter
,
2678 cls::rbd::GroupSpec
*group_spec
)
2681 decode(*group_spec
, *iter
);
2682 } catch (const ceph::buffer::error
&err
) {
2688 int image_group_get(librados::IoCtx
*ioctx
, const std::string
&oid
,
2689 cls::rbd::GroupSpec
*group_spec
)
2691 librados::ObjectReadOperation op
;
2692 image_group_get_start(&op
);
2695 int r
= ioctx
->operate(oid
, &op
, &out_bl
);
2700 auto iter
= out_bl
.cbegin();
2701 return image_group_get_finish(&iter
, group_spec
);
2704 int group_snap_set(librados::IoCtx
*ioctx
, const std::string
&oid
,
2705 const cls::rbd::GroupSnapshot
&snapshot
)
2708 bufferlist inbl
, outbl
;
2709 encode(snapshot
, inbl
);
2710 int r
= ioctx
->exec(oid
, "rbd", "group_snap_set", inbl
, outbl
);
2714 int group_snap_remove(librados::IoCtx
*ioctx
, const std::string
&oid
,
2715 const std::string
&snap_id
)
2718 bufferlist inbl
, outbl
;
2719 encode(snap_id
, inbl
);
2720 return ioctx
->exec(oid
, "rbd", "group_snap_remove", inbl
, outbl
);
2723 int group_snap_get_by_id(librados::IoCtx
*ioctx
, const std::string
&oid
,
2724 const std::string
&snap_id
,
2725 cls::rbd::GroupSnapshot
*snapshot
)
2729 bufferlist inbl
, outbl
;
2731 encode(snap_id
, inbl
);
2732 int r
= ioctx
->exec(oid
, "rbd", "group_snap_get_by_id", inbl
, outbl
);
2737 auto iter
= outbl
.cbegin();
2739 decode(*snapshot
, iter
);
2740 } catch (const ceph::buffer::error
&err
) {
2746 int group_snap_list(librados::IoCtx
*ioctx
, const std::string
&oid
,
2747 const cls::rbd::GroupSnapshot
&start
,
2748 uint64_t max_return
,
2749 std::vector
<cls::rbd::GroupSnapshot
> *snapshots
)
2753 bufferlist inbl
, outbl
;
2754 encode(start
, inbl
);
2755 encode(max_return
, inbl
);
2757 int r
= ioctx
->exec(oid
, "rbd", "group_snap_list", inbl
, outbl
);
2761 auto iter
= outbl
.cbegin();
2763 decode(*snapshots
, iter
);
2764 } catch (const ceph::buffer::error
&err
) {
2771 // rbd_trash functions
2772 void trash_add(librados::ObjectWriteOperation
*op
,
2773 const std::string
&id
,
2774 const cls::rbd::TrashImageSpec
&trash_spec
)
2778 encode(trash_spec
, bl
);
2779 op
->exec("rbd", "trash_add", bl
);
2782 int trash_add(librados::IoCtx
*ioctx
, const std::string
&id
,
2783 const cls::rbd::TrashImageSpec
&trash_spec
)
2785 librados::ObjectWriteOperation op
;
2786 trash_add(&op
, id
, trash_spec
);
2788 return ioctx
->operate(RBD_TRASH
, &op
);
2791 void trash_remove(librados::ObjectWriteOperation
*op
,
2792 const std::string
&id
)
2796 op
->exec("rbd", "trash_remove", bl
);
2799 int trash_remove(librados::IoCtx
*ioctx
, const std::string
&id
)
2801 librados::ObjectWriteOperation op
;
2802 trash_remove(&op
, id
);
2804 return ioctx
->operate(RBD_TRASH
, &op
);
2807 void trash_list_start(librados::ObjectReadOperation
*op
,
2808 const std::string
&start
, uint64_t max_return
)
2812 encode(max_return
, bl
);
2813 op
->exec("rbd", "trash_list", bl
);
2816 int trash_list_finish(bufferlist::const_iterator
*it
,
2817 map
<string
, cls::rbd::TrashImageSpec
> *entries
)
2819 ceph_assert(entries
);
2822 decode(*entries
, *it
);
2823 } catch (const ceph::buffer::error
&err
) {
2830 int trash_list(librados::IoCtx
*ioctx
,
2831 const std::string
&start
, uint64_t max_return
,
2832 map
<string
, cls::rbd::TrashImageSpec
> *entries
)
2834 librados::ObjectReadOperation op
;
2835 trash_list_start(&op
, start
, max_return
);
2838 int r
= ioctx
->operate(RBD_TRASH
, &op
, &out_bl
);
2843 auto iter
= out_bl
.cbegin();
2844 return trash_list_finish(&iter
, entries
);
2847 void trash_get_start(librados::ObjectReadOperation
*op
,
2848 const std::string
&id
)
2852 op
->exec("rbd", "trash_get", bl
);
2855 int trash_get_finish(bufferlist::const_iterator
*it
,
2856 cls::rbd::TrashImageSpec
*trash_spec
) {
2857 ceph_assert(trash_spec
);
2859 decode(*trash_spec
, *it
);
2860 } catch (const ceph::buffer::error
&err
) {
2867 int trash_get(librados::IoCtx
*ioctx
, const std::string
&id
,
2868 cls::rbd::TrashImageSpec
*trash_spec
)
2870 librados::ObjectReadOperation op
;
2871 trash_get_start(&op
, id
);
2874 int r
= ioctx
->operate(RBD_TRASH
, &op
, &out_bl
);
2879 auto it
= out_bl
.cbegin();
2880 return trash_get_finish(&it
, trash_spec
);
2883 void trash_state_set(librados::ObjectWriteOperation
*op
,
2884 const std::string
&id
,
2885 const cls::rbd::TrashImageState
&trash_state
,
2886 const cls::rbd::TrashImageState
&expect_state
)
2890 encode(trash_state
, bl
);
2891 encode(expect_state
, bl
);
2892 op
->exec("rbd", "trash_state_set", bl
);
2895 int trash_state_set(librados::IoCtx
*ioctx
, const std::string
&id
,
2896 const cls::rbd::TrashImageState
&trash_state
,
2897 const cls::rbd::TrashImageState
&expect_state
)
2899 librados::ObjectWriteOperation op
;
2900 trash_state_set(&op
, id
, trash_state
, expect_state
);
2902 return ioctx
->operate(RBD_TRASH
, &op
);
2905 void namespace_add(librados::ObjectWriteOperation
*op
,
2906 const std::string
&name
)
2910 op
->exec("rbd", "namespace_add", bl
);
2913 int namespace_add(librados::IoCtx
*ioctx
, const std::string
&name
)
2915 librados::ObjectWriteOperation op
;
2916 namespace_add(&op
, name
);
2918 return ioctx
->operate(RBD_NAMESPACE
, &op
);
2921 void namespace_remove(librados::ObjectWriteOperation
*op
,
2922 const std::string
&name
)
2926 op
->exec("rbd", "namespace_remove", bl
);
2929 int namespace_remove(librados::IoCtx
*ioctx
, const std::string
&name
)
2931 librados::ObjectWriteOperation op
;
2932 namespace_remove(&op
, name
);
2934 return ioctx
->operate(RBD_NAMESPACE
, &op
);
2937 void namespace_list_start(librados::ObjectReadOperation
*op
,
2938 const std::string
&start
, uint64_t max_return
)
2942 encode(max_return
, bl
);
2943 op
->exec("rbd", "namespace_list", bl
);
2946 int namespace_list_finish(bufferlist::const_iterator
*it
,
2947 std::list
<std::string
> *entries
)
2949 ceph_assert(entries
);
2952 decode(*entries
, *it
);
2953 } catch (const ceph::buffer::error
&err
) {
2960 int namespace_list(librados::IoCtx
*ioctx
,
2961 const std::string
&start
, uint64_t max_return
,
2962 std::list
<std::string
> *entries
)
2964 librados::ObjectReadOperation op
;
2965 namespace_list_start(&op
, start
, max_return
);
2968 int r
= ioctx
->operate(RBD_NAMESPACE
, &op
, &out_bl
);
2973 auto iter
= out_bl
.cbegin();
2974 return namespace_list_finish(&iter
, entries
);
2977 void sparsify(librados::ObjectWriteOperation
*op
, size_t sparse_size
,
2981 encode(sparse_size
, bl
);
2982 encode(remove_empty
, bl
);
2983 op
->exec("rbd", "sparsify", bl
);
2986 int sparsify(librados::IoCtx
*ioctx
, const std::string
&oid
, size_t sparse_size
,
2989 librados::ObjectWriteOperation op
;
2990 sparsify(&op
, sparse_size
, remove_empty
);
2992 return ioctx
->operate(oid
, &op
);
2995 } // namespace cls_client
2996 } // namespace librbd