]>
git.proxmox.com Git - ceph.git/blob - ceph/src/cls/cas/cls_cas_internal.cc
1 // -*- mode:C++; tab-width:8; c-basic-offset:2; indent-tabs-mode:t -*-
2 // vim: ts=8 sw=2 smarttab
4 #include "cls_cas_internal.h"
7 chunk_refs_t::chunk_refs_t(const chunk_refs_t
& other
)
12 chunk_refs_t
& chunk_refs_t::operator=(const chunk_refs_t
& other
)
14 // this is inefficient, but easy.
22 void chunk_refs_t::clear()
24 // default to most precise impl
25 r
.reset(new chunk_refs_by_object_t
);
29 void chunk_refs_t::encode(ceph::buffer::list
& bl
) const
36 void chunk_refs_t::_encode_r(ceph::bufferlist
& bl
) const
39 switch (r
->get_type()) {
41 encode(*(chunk_refs_by_object_t
*)r
.get(), bl
);
44 encode(*(chunk_refs_by_hash_t
*)r
.get(), bl
);
47 encode(*(chunk_refs_by_pool_t
*)r
.get(), bl
);
50 encode(*(chunk_refs_count_t
*)r
.get(), bl
);
53 ceph_abort("unrecognized ref type");
57 void chunk_refs_t::dynamic_encode(ceph::buffer::list
& bl
, size_t max
)
62 // account for the additional overhead in _encode_final
63 if (t
.length() + 8 <= max
) {
66 // downgrade resolution
67 std::unique_ptr
<refs_t
> n
;
68 switch (r
->get_type()) {
70 r
.reset(new chunk_refs_by_hash_t(
71 static_cast<chunk_refs_by_object_t
*>(r
.get())));
74 if (!static_cast<chunk_refs_by_hash_t
*>(r
.get())->shrink()) {
75 r
.reset(new chunk_refs_by_pool_t(
76 static_cast<chunk_refs_by_hash_t
*>(r
.get())));
80 r
.reset(new chunk_refs_count_t(r
.get()));
88 void chunk_refs_t::_encode_final(bufferlist
& bl
, bufferlist
& t
) const
90 ENCODE_START(1, 1, bl
);
91 encode(r
->get_type(), bl
);
96 void chunk_refs_t::decode(ceph::buffer::list::const_iterator
& p
)
104 auto n
= new chunk_refs_by_object_t();
111 auto n
= new chunk_refs_by_hash_t();
118 auto n
= new chunk_refs_by_pool_t();
125 auto n
= new chunk_refs_count_t();
131 throw ceph::buffer::malformed_input(
132 std::string("unrecognized chunk ref encoding type ") +