Merge pull request #45235 from tchaikov/rbd-std-variant

librbd: s/boost::variant/std::variant/

Reviewed-by: Mykola Golub <mgolub@suse.com>
Reviewed-by: Ilya Dryomov <idryomov@gmail.com>
This commit is contained in:
Ilya Dryomov 2022-03-14 11:36:39 +01:00 committed by GitHub
commit 0b44878cb2
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
22 changed files with 109 additions and 93 deletions

View File

@ -2326,8 +2326,8 @@ int snapshot_add(cls_method_context_t hctx, bufferlist *in, bufferlist *out)
return -EINVAL; return -EINVAL;
} }
if (boost::get<cls::rbd::UnknownSnapshotNamespace>( if (std::holds_alternative<cls::rbd::UnknownSnapshotNamespace>(
&snap_meta.snapshot_namespace) != nullptr) { snap_meta.snapshot_namespace)) {
CLS_ERR("Unknown snapshot namespace provided"); CLS_ERR("Unknown snapshot namespace provided");
return -EINVAL; return -EINVAL;
} }
@ -5708,7 +5708,7 @@ int image_snapshot_unlink_peer(cls_method_context_t hctx,
return r; return r;
} }
auto mirror_ns = boost::get<cls::rbd::MirrorSnapshotNamespace>( auto mirror_ns = std::get_if<cls::rbd::MirrorSnapshotNamespace>(
&snap.snapshot_namespace); &snap.snapshot_namespace);
if (mirror_ns == nullptr) { if (mirror_ns == nullptr) {
CLS_LOG(5, "mirror_image_snapshot_unlink_peer " \ CLS_LOG(5, "mirror_image_snapshot_unlink_peer " \
@ -5726,8 +5726,8 @@ int image_snapshot_unlink_peer(cls_method_context_t hctx,
// should remove the snapshot instead. // should remove the snapshot instead.
auto search_lambda = [snap_id](const cls_rbd_snap& snap_meta) { auto search_lambda = [snap_id](const cls_rbd_snap& snap_meta) {
if (snap_meta.id > snap_id && if (snap_meta.id > snap_id &&
boost::get<cls::rbd::MirrorSnapshotNamespace>( std::holds_alternative<cls::rbd::MirrorSnapshotNamespace>(
&snap_meta.snapshot_namespace) != nullptr) { snap_meta.snapshot_namespace)) {
return -EEXIST; return -EEXIST;
} }
return 0; return 0;
@ -5763,7 +5763,7 @@ int image_snapshot_set_copy_progress(cls_method_context_t hctx,
return r; return r;
} }
auto mirror_ns = boost::get<cls::rbd::MirrorSnapshotNamespace>( auto mirror_ns = std::get_if<cls::rbd::MirrorSnapshotNamespace>(
&snap.snapshot_namespace); &snap.snapshot_namespace);
if (mirror_ns == nullptr) { if (mirror_ns == nullptr) {
CLS_LOG(5, "mirror_image_snapshot_set_copy_progress " \ CLS_LOG(5, "mirror_image_snapshot_set_copy_progress " \

View File

@ -784,7 +784,7 @@ void MirrorSnapshotNamespace::dump(Formatter *f) const {
} }
} }
class EncodeSnapshotNamespaceVisitor : public boost::static_visitor<void> { class EncodeSnapshotNamespaceVisitor {
public: public:
explicit EncodeSnapshotNamespaceVisitor(bufferlist &bl) : m_bl(bl) { explicit EncodeSnapshotNamespaceVisitor(bufferlist &bl) : m_bl(bl) {
} }
@ -800,7 +800,7 @@ private:
bufferlist &m_bl; bufferlist &m_bl;
}; };
class DecodeSnapshotNamespaceVisitor : public boost::static_visitor<void> { class DecodeSnapshotNamespaceVisitor {
public: public:
DecodeSnapshotNamespaceVisitor(bufferlist::const_iterator &iter) DecodeSnapshotNamespaceVisitor(bufferlist::const_iterator &iter)
: m_iter(iter) { : m_iter(iter) {
@ -814,7 +814,7 @@ private:
bufferlist::const_iterator &m_iter; bufferlist::const_iterator &m_iter;
}; };
class DumpSnapshotNamespaceVisitor : public boost::static_visitor<void> { class DumpSnapshotNamespaceVisitor {
public: public:
explicit DumpSnapshotNamespaceVisitor(Formatter *formatter, const std::string &key) explicit DumpSnapshotNamespaceVisitor(Formatter *formatter, const std::string &key)
: m_formatter(formatter), m_key(key) {} : m_formatter(formatter), m_key(key) {}
@ -830,7 +830,7 @@ private:
std::string m_key; std::string m_key;
}; };
class GetTypeVisitor : public boost::static_visitor<SnapshotNamespaceType> { class GetTypeVisitor {
public: public:
template <typename T> template <typename T>
inline SnapshotNamespaceType operator()(const T&) const { inline SnapshotNamespaceType operator()(const T&) const {
@ -840,8 +840,8 @@ public:
SnapshotNamespaceType get_snap_namespace_type( SnapshotNamespaceType get_snap_namespace_type(
const SnapshotNamespace& snapshot_namespace) { const SnapshotNamespace& snapshot_namespace) {
return static_cast<SnapshotNamespaceType>(boost::apply_visitor( return static_cast<SnapshotNamespaceType>(snapshot_namespace.visit(
GetTypeVisitor(), snapshot_namespace)); GetTypeVisitor()));
} }
void SnapshotInfo::encode(bufferlist& bl) const { void SnapshotInfo::encode(bufferlist& bl) const {
@ -869,8 +869,7 @@ void SnapshotInfo::decode(bufferlist::const_iterator& it) {
void SnapshotInfo::dump(Formatter *f) const { void SnapshotInfo::dump(Formatter *f) const {
f->dump_unsigned("id", id); f->dump_unsigned("id", id);
f->open_object_section("namespace"); f->open_object_section("namespace");
boost::apply_visitor(DumpSnapshotNamespaceVisitor(f, "type"), snapshot_namespace.visit(DumpSnapshotNamespaceVisitor(f, "type"));
snapshot_namespace);
f->close_section(); f->close_section();
f->dump_string("name", name); f->dump_string("name", name);
f->dump_unsigned("image_size", image_size); f->dump_unsigned("image_size", image_size);
@ -899,7 +898,7 @@ void SnapshotInfo::generate_test_instances(std::list<SnapshotInfo*> &o) {
void SnapshotNamespace::encode(bufferlist& bl) const { void SnapshotNamespace::encode(bufferlist& bl) const {
ENCODE_START(1, 1, bl); ENCODE_START(1, 1, bl);
boost::apply_visitor(EncodeSnapshotNamespaceVisitor(bl), *this); visit(EncodeSnapshotNamespaceVisitor(bl));
ENCODE_FINISH(bl); ENCODE_FINISH(bl);
} }
@ -925,13 +924,12 @@ void SnapshotNamespace::decode(bufferlist::const_iterator &p)
*this = UnknownSnapshotNamespace(); *this = UnknownSnapshotNamespace();
break; break;
} }
boost::apply_visitor(DecodeSnapshotNamespaceVisitor(p), *this); visit(DecodeSnapshotNamespaceVisitor(p));
DECODE_FINISH(p); DECODE_FINISH(p);
} }
void SnapshotNamespace::dump(Formatter *f) const { void SnapshotNamespace::dump(Formatter *f) const {
boost::apply_visitor( visit(DumpSnapshotNamespaceVisitor(f, "snapshot_namespace_type"));
DumpSnapshotNamespaceVisitor(f, "snapshot_namespace_type"), *this);
} }
void SnapshotNamespace::generate_test_instances(std::list<SnapshotNamespace*> &o) { void SnapshotNamespace::generate_test_instances(std::list<SnapshotNamespace*> &o) {
@ -955,6 +953,12 @@ void SnapshotNamespace::generate_test_instances(std::list<SnapshotNamespace*> &o
"uuid", 123))); "uuid", 123)));
} }
std::ostream& operator<<(std::ostream& os, const SnapshotNamespace& ns) {
return ns.visit([&os](const auto& val) -> std::ostream& {
return os << val;
});
}
std::ostream& operator<<(std::ostream& os, const SnapshotNamespaceType& type) { std::ostream& operator<<(std::ostream& os, const SnapshotNamespaceType& type) {
switch (type) { switch (type) {
case SNAPSHOT_NAMESPACE_TYPE_USER: case SNAPSHOT_NAMESPACE_TYPE_USER:

View File

@ -4,7 +4,6 @@
#ifndef CEPH_CLS_RBD_TYPES_H #ifndef CEPH_CLS_RBD_TYPES_H
#define CEPH_CLS_RBD_TYPES_H #define CEPH_CLS_RBD_TYPES_H
#include <boost/variant.hpp>
#include "include/int_types.h" #include "include/int_types.h"
#include "include/buffer.h" #include "include/buffer.h"
#include "include/encoding.h" #include "include/encoding.h"
@ -14,6 +13,7 @@
#include <iosfwd> #include <iosfwd>
#include <string> #include <string>
#include <set> #include <set>
#include <variant>
#define RBD_GROUP_REF "rbd_group_ref" #define RBD_GROUP_REF "rbd_group_ref"
@ -442,6 +442,10 @@ struct UserSnapshotNamespace {
return true; return true;
} }
inline bool operator!=(const UserSnapshotNamespace& usn) const {
return false;
}
inline bool operator<(const UserSnapshotNamespace& usn) const { inline bool operator<(const UserSnapshotNamespace& usn) const {
return false; return false;
} }
@ -474,6 +478,10 @@ struct GroupSnapshotNamespace {
group_snapshot_id == gsn.group_snapshot_id; group_snapshot_id == gsn.group_snapshot_id;
} }
inline bool operator!=(const GroupSnapshotNamespace& gsn) const {
return !operator==(gsn);
}
inline bool operator<(const GroupSnapshotNamespace& gsn) const { inline bool operator<(const GroupSnapshotNamespace& gsn) const {
if (group_pool != gsn.group_pool) { if (group_pool != gsn.group_pool) {
return group_pool < gsn.group_pool; return group_pool < gsn.group_pool;
@ -506,6 +514,9 @@ struct TrashSnapshotNamespace {
inline bool operator==(const TrashSnapshotNamespace& usn) const { inline bool operator==(const TrashSnapshotNamespace& usn) const {
return true; return true;
} }
inline bool operator!=(const TrashSnapshotNamespace& usn) const {
return false;
}
inline bool operator<(const TrashSnapshotNamespace& usn) const { inline bool operator<(const TrashSnapshotNamespace& usn) const {
return false; return false;
} }
@ -611,6 +622,10 @@ struct MirrorSnapshotNamespace {
snap_seqs == rhs.snap_seqs; snap_seqs == rhs.snap_seqs;
} }
inline bool operator!=(const MirrorSnapshotNamespace& rhs) const {
return !operator==(rhs);
}
inline bool operator<(const MirrorSnapshotNamespace& rhs) const { inline bool operator<(const MirrorSnapshotNamespace& rhs) const {
if (state != rhs.state) { if (state != rhs.state) {
return state < rhs.state; return state < rhs.state;
@ -644,6 +659,10 @@ struct UnknownSnapshotNamespace {
return true; return true;
} }
inline bool operator!=(const UnknownSnapshotNamespace& gsn) const {
return false;
}
inline bool operator<(const UnknownSnapshotNamespace& gsn) const { inline bool operator<(const UnknownSnapshotNamespace& gsn) const {
return false; return false;
} }
@ -656,38 +675,33 @@ std::ostream& operator<<(std::ostream& os, const TrashSnapshotNamespace& ns);
std::ostream& operator<<(std::ostream& os, const MirrorSnapshotNamespace& ns); std::ostream& operator<<(std::ostream& os, const MirrorSnapshotNamespace& ns);
std::ostream& operator<<(std::ostream& os, const UnknownSnapshotNamespace& ns); std::ostream& operator<<(std::ostream& os, const UnknownSnapshotNamespace& ns);
typedef boost::variant<UserSnapshotNamespace, typedef std::variant<UserSnapshotNamespace,
GroupSnapshotNamespace, GroupSnapshotNamespace,
TrashSnapshotNamespace, TrashSnapshotNamespace,
MirrorSnapshotNamespace, MirrorSnapshotNamespace,
UnknownSnapshotNamespace> SnapshotNamespaceVariant; UnknownSnapshotNamespace> SnapshotNamespaceVariant;
struct SnapshotNamespace : public SnapshotNamespaceVariant { struct SnapshotNamespace : public SnapshotNamespaceVariant {
SnapshotNamespace() { using SnapshotNamespaceVariant::SnapshotNamespaceVariant;
}
template <typename T>
SnapshotNamespace(T&& t) : SnapshotNamespaceVariant(std::forward<T>(t)) {
}
void encode(ceph::buffer::list& bl) const; void encode(ceph::buffer::list& bl) const;
void decode(ceph::buffer::list::const_iterator& it); void decode(ceph::buffer::list::const_iterator& it);
void dump(ceph::Formatter *f) const; void dump(ceph::Formatter *f) const;
template <typename F>
decltype(auto) visit(F&& f) const & {
return std::visit(std::forward<F>(f), static_cast<const SnapshotNamespaceVariant&>(*this));
}
template <typename F>
decltype(auto) visit(F&& f) & {
return std::visit(std::forward<F>(f), static_cast<SnapshotNamespaceVariant&>(*this));
}
static void generate_test_instances(std::list<SnapshotNamespace*> &o); static void generate_test_instances(std::list<SnapshotNamespace*> &o);
inline bool operator==(const SnapshotNamespaceVariant& sn) const {
return static_cast<const SnapshotNamespaceVariant&>(*this) == sn;
}
inline bool operator<(const SnapshotNamespaceVariant& sn) const {
return static_cast<const SnapshotNamespaceVariant&>(*this) < sn;
}
inline bool operator!=(const SnapshotNamespaceVariant& sn) const {
return !(*this == sn);
}
}; };
WRITE_CLASS_ENCODER(SnapshotNamespace); WRITE_CLASS_ENCODER(SnapshotNamespace);
std::ostream& operator<<(std::ostream& os, const SnapshotNamespace& ns);
SnapshotNamespaceType get_snap_namespace_type( SnapshotNamespaceType get_snap_namespace_type(
const SnapshotNamespace& snapshot_namespace); const SnapshotNamespace& snapshot_namespace);
@ -871,6 +885,7 @@ struct TrashImageSpec {
deferment_end_time == rhs.deferment_end_time); deferment_end_time == rhs.deferment_end_time);
} }
}; };
WRITE_CLASS_ENCODER(TrashImageSpec); WRITE_CLASS_ENCODER(TrashImageSpec);
struct MirrorImageMap { struct MirrorImageMap {

View File

@ -75,8 +75,8 @@ namespace librbd {
struct SnapKeyComparator { struct SnapKeyComparator {
inline bool operator()(const SnapKey& lhs, const SnapKey& rhs) const { inline bool operator()(const SnapKey& lhs, const SnapKey& rhs) const {
// only compare by namespace type and name // only compare by namespace type and name
if (lhs.first.which() != rhs.first.which()) { if (lhs.first.index() != rhs.first.index()) {
return lhs.first.which() < rhs.first.which(); return lhs.first.index() < rhs.first.index();
} }
return lhs.second < rhs.second; return lhs.second < rhs.second;
} }

View File

@ -1150,7 +1150,7 @@ bool ImageWatcher<I>::handle_payload(const SnapCreatePayload &payload,
auto request_type = exclusive_lock::OPERATION_REQUEST_TYPE_GENERAL; auto request_type = exclusive_lock::OPERATION_REQUEST_TYPE_GENERAL;
// rbd-mirror needs to accept forced promotion orphan snap create requests // rbd-mirror needs to accept forced promotion orphan snap create requests
auto mirror_ns = boost::get<cls::rbd::MirrorSnapshotNamespace>( auto mirror_ns = std::get_if<cls::rbd::MirrorSnapshotNamespace>(
&payload.snap_namespace); &payload.snap_namespace);
if (mirror_ns != nullptr && mirror_ns->is_orphan()) { if (mirror_ns != nullptr && mirror_ns->is_orphan()) {
request_type = exclusive_lock::OPERATION_REQUEST_TYPE_FORCE_PROMOTION; request_type = exclusive_lock::OPERATION_REQUEST_TYPE_FORCE_PROMOTION;

View File

@ -45,8 +45,8 @@ snap_t get_group_snap_id(I* ictx,
for (; it != ictx->snap_ids.end(); ++it) { for (; it != ictx->snap_ids.end(); ++it) {
if (it->first.first == in_snap_namespace) { if (it->first.first == in_snap_namespace) {
return it->second; return it->second;
} else if (boost::get<cls::rbd::GroupSnapshotNamespace>(&it->first.first) == } else if (!std::holds_alternative<cls::rbd::GroupSnapshotNamespace>(
nullptr) { it->first.first)) {
break; break;
} }
} }

View File

@ -1610,7 +1610,7 @@ int Mirror<I>::peer_site_remove(librados::IoCtx& io_ctx,
{ {
std::shared_lock image_locker{img_ctx->image_lock}; std::shared_lock image_locker{img_ctx->image_lock};
for (auto &it : img_ctx->snap_info) { for (auto &it : img_ctx->snap_info) {
auto info = boost::get<cls::rbd::MirrorSnapshotNamespace>( auto info = std::get_if<cls::rbd::MirrorSnapshotNamespace>(
&it.second.snap_namespace); &it.second.snap_namespace);
if (info && info->mirror_peer_uuids.count(uuid)) { if (info && info->mirror_peer_uuids.count(uuid)) {
snap_ids.push_back(it.first); snap_ids.push_back(it.first);

View File

@ -26,7 +26,7 @@ namespace api {
namespace { namespace {
class GetGroupVisitor : public boost::static_visitor<int> { class GetGroupVisitor {
public: public:
CephContext* cct; CephContext* cct;
librados::IoCtx *image_ioctx; librados::IoCtx *image_ioctx;
@ -80,7 +80,7 @@ public:
} }
}; };
class GetTrashVisitor : public boost::static_visitor<int> { class GetTrashVisitor {
public: public:
std::string* original_name; std::string* original_name;
@ -100,7 +100,7 @@ public:
} }
}; };
class GetMirrorVisitor : public boost::static_visitor<int> { class GetMirrorVisitor {
public: public:
snap_mirror_namespace_t *mirror_snap; snap_mirror_namespace_t *mirror_snap;
@ -143,7 +143,7 @@ int Snapshot<I>::get_group_namespace(I *ictx, uint64_t snap_id,
} }
GetGroupVisitor ggv = GetGroupVisitor(ictx->cct, &ictx->md_ctx, group_snap); GetGroupVisitor ggv = GetGroupVisitor(ictx->cct, &ictx->md_ctx, group_snap);
r = boost::apply_visitor(ggv, snap_info->snap_namespace); r = snap_info->snap_namespace.visit(ggv);
if (r < 0) { if (r < 0) {
return r; return r;
} }
@ -166,7 +166,7 @@ int Snapshot<I>::get_trash_namespace(I *ictx, uint64_t snap_id,
} }
auto visitor = GetTrashVisitor(original_name); auto visitor = GetTrashVisitor(original_name);
r = boost::apply_visitor(visitor, snap_info->snap_namespace); r = snap_info->snap_namespace.visit(visitor);
if (r < 0) { if (r < 0) {
return r; return r;
} }
@ -189,7 +189,7 @@ int Snapshot<I>::get_mirror_namespace(
} }
auto gmv = GetMirrorVisitor(mirror_snap); auto gmv = GetMirrorVisitor(mirror_snap);
r = boost::apply_visitor(gmv, snap_info->snap_namespace); r = snap_info->snap_namespace.visit(gmv);
if (r < 0) { if (r < 0) {
return r; return r;
} }

View File

@ -257,8 +257,7 @@ void SnapshotCopyRequest<I>::send_snap_remove() {
return; return;
} }
if (boost::get<cls::rbd::UserSnapshotNamespace>(&snap_namespace) == if (!std::holds_alternative<cls::rbd::UserSnapshotNamespace>(snap_namespace)) {
nullptr) {
continue; continue;
} }
@ -347,8 +346,7 @@ void SnapshotCopyRequest<I>::send_snap_create() {
if (m_snap_seqs.find(src_snap_id) == m_snap_seqs.end()) { if (m_snap_seqs.find(src_snap_id) == m_snap_seqs.end()) {
// the source snapshot is not in our mapping table, ... // the source snapshot is not in our mapping table, ...
if (boost::get<cls::rbd::UserSnapshotNamespace>(&snap_namespace) != if (std::holds_alternative<cls::rbd::UserSnapshotNamespace>(snap_namespace)) {
nullptr) {
// ... create it since it's a user snapshot // ... create it since it's a user snapshot
break; break;
} else if (src_snap_id == m_src_snap_id_end) { } else if (src_snap_id == m_src_snap_id_end) {

View File

@ -259,7 +259,7 @@ void GetInfoRequest<I>::calc_promotion_state(
*m_primary_mirror_uuid = ""; *m_primary_mirror_uuid = "";
for (auto it = snap_info.rbegin(); it != snap_info.rend(); it++) { for (auto it = snap_info.rbegin(); it != snap_info.rend(); it++) {
auto mirror_ns = boost::get<cls::rbd::MirrorSnapshotNamespace>( auto mirror_ns = std::get_if<cls::rbd::MirrorSnapshotNamespace>(
&it->second.snap_namespace); &it->second.snap_namespace);
if (mirror_ns != nullptr) { if (mirror_ns != nullptr) {

View File

@ -194,7 +194,7 @@ void CreatePrimaryRequest<I>::unlink_peer() {
size_t count = 0; size_t count = 0;
uint64_t unlink_snap_id = 0; uint64_t unlink_snap_id = 0;
for (auto &snap_it : m_image_ctx->snap_info) { for (auto &snap_it : m_image_ctx->snap_info) {
auto info = boost::get<cls::rbd::MirrorSnapshotNamespace>( auto info = std::get_if<cls::rbd::MirrorSnapshotNamespace>(
&snap_it.second.snap_namespace); &snap_it.second.snap_namespace);
if (info == nullptr) { if (info == nullptr) {
continue; continue;

View File

@ -68,10 +68,10 @@ void UnlinkPeerRequest<I>::unlink_peer() {
snap_it != m_image_ctx->snap_info.end(); ++snap_it) { snap_it != m_image_ctx->snap_info.end(); ++snap_it) {
if (snap_it->first == m_snap_id) { if (snap_it->first == m_snap_id) {
r = 0; r = 0;
mirror_ns = boost::get<cls::rbd::MirrorSnapshotNamespace>( mirror_ns = std::get_if<cls::rbd::MirrorSnapshotNamespace>(
&snap_it->second.snap_namespace); &snap_it->second.snap_namespace);
} else if (boost::get<cls::rbd::MirrorSnapshotNamespace>( } else if (std::holds_alternative<cls::rbd::MirrorSnapshotNamespace>(
&snap_it->second.snap_namespace) != nullptr) { snap_it->second.snap_namespace)) {
ldout(cct, 15) << "located newer mirror snapshot" << dendl; ldout(cct, 15) << "located newer mirror snapshot" << dendl;
m_newer_mirror_snapshots = true; m_newer_mirror_snapshots = true;
break; break;
@ -186,7 +186,7 @@ void UnlinkPeerRequest<I>::remove_snapshot() {
return; return;
} }
auto info = boost::get<cls::rbd::MirrorSnapshotNamespace>( auto info = std::get<cls::rbd::MirrorSnapshotNamespace>(
snap_namespace); snap_namespace);
info.mirror_peer_uuids.erase(m_mirror_peer_uuid); info.mirror_peer_uuids.erase(m_mirror_peer_uuid);

View File

@ -28,12 +28,12 @@ bool get_rollback_snap_id(
uint64_t *rollback_snap_id) { uint64_t *rollback_snap_id) {
for (; it != end; it++) { for (; it != end; it++) {
auto mirror_ns = boost::get<cls::rbd::MirrorSnapshotNamespace>( auto mirror_ns = std::get<cls::rbd::MirrorSnapshotNamespace>(
&it->second.snap_namespace); it->second.snap_namespace);
if (mirror_ns->state != cls::rbd::MIRROR_SNAPSHOT_STATE_NON_PRIMARY) { if (mirror_ns.state != cls::rbd::MIRROR_SNAPSHOT_STATE_NON_PRIMARY) {
break; break;
} }
if (mirror_ns->complete) { if (mirror_ns.complete) {
break; break;
} }
} }
@ -69,7 +69,7 @@ bool can_create_primary_snapshot(I *image_ctx, bool demoted, bool force,
for (auto it = image_ctx->snap_info.rbegin(); for (auto it = image_ctx->snap_info.rbegin();
it != image_ctx->snap_info.rend(); it++) { it != image_ctx->snap_info.rend(); it++) {
auto mirror_ns = boost::get<cls::rbd::MirrorSnapshotNamespace>( auto mirror_ns = std::get_if<cls::rbd::MirrorSnapshotNamespace>(
&it->second.snap_namespace); &it->second.snap_namespace);
if (mirror_ns == nullptr) { if (mirror_ns == nullptr) {
continue; continue;
@ -133,7 +133,7 @@ bool can_create_non_primary_snapshot(I *image_ctx) {
for (auto it = image_ctx->snap_info.rbegin(); for (auto it = image_ctx->snap_info.rbegin();
it != image_ctx->snap_info.rend(); it++) { it != image_ctx->snap_info.rend(); it++) {
auto mirror_ns = boost::get<cls::rbd::MirrorSnapshotNamespace>( auto mirror_ns = std::get_if<cls::rbd::MirrorSnapshotNamespace>(
&it->second.snap_namespace); &it->second.snap_namespace);
if (mirror_ns != nullptr) { if (mirror_ns != nullptr) {
ldout(cct, 20) << "previous mirror snapshot snap_id=" << it->first << " " ldout(cct, 20) << "previous mirror snapshot snap_id=" << it->first << " "

View File

@ -298,7 +298,7 @@ Context *SnapshotCreateRequest<I>::handle_create_object_map(int *result) {
template <typename I> template <typename I>
Context *SnapshotCreateRequest<I>::send_create_image_state() { Context *SnapshotCreateRequest<I>::send_create_image_state() {
I &image_ctx = this->m_image_ctx; I &image_ctx = this->m_image_ctx;
auto mirror_ns = boost::get<cls::rbd::MirrorSnapshotNamespace>( auto mirror_ns = std::get_if<cls::rbd::MirrorSnapshotNamespace>(
&m_snap_namespace); &m_snap_namespace);
if (mirror_ns == nullptr || !mirror_ns->is_primary()) { if (mirror_ns == nullptr || !mirror_ns->is_primary()) {
update_snap_context(); update_snap_context();

View File

@ -2256,7 +2256,7 @@ TEST_F(TestClsRbd, mirror_snapshot) {
cls::rbd::SnapshotInfo snap; cls::rbd::SnapshotInfo snap;
ASSERT_EQ(0, snapshot_get(&ioctx, oid, 1, &snap)); ASSERT_EQ(0, snapshot_get(&ioctx, oid, 1, &snap));
auto sn = boost::get<cls::rbd::MirrorSnapshotNamespace>( auto sn = std::get_if<cls::rbd::MirrorSnapshotNamespace>(
&snap.snapshot_namespace); &snap.snapshot_namespace);
ASSERT_NE(nullptr, sn); ASSERT_NE(nullptr, sn);
ASSERT_EQ(primary, *sn); ASSERT_EQ(primary, *sn);
@ -2269,7 +2269,7 @@ TEST_F(TestClsRbd, mirror_snapshot) {
ASSERT_EQ(-ENOENT, mirror_image_snapshot_unlink_peer(&ioctx, oid, 1, ASSERT_EQ(-ENOENT, mirror_image_snapshot_unlink_peer(&ioctx, oid, 1,
"peer1")); "peer1"));
ASSERT_EQ(0, snapshot_get(&ioctx, oid, 1, &snap)); ASSERT_EQ(0, snapshot_get(&ioctx, oid, 1, &snap));
sn = boost::get<cls::rbd::MirrorSnapshotNamespace>( sn = std::get_if<cls::rbd::MirrorSnapshotNamespace>(
&snap.snapshot_namespace); &snap.snapshot_namespace);
ASSERT_NE(nullptr, sn); ASSERT_NE(nullptr, sn);
ASSERT_EQ(1U, sn->mirror_peer_uuids.size()); ASSERT_EQ(1U, sn->mirror_peer_uuids.size());
@ -2278,14 +2278,14 @@ TEST_F(TestClsRbd, mirror_snapshot) {
ASSERT_EQ(-ERESTART, ASSERT_EQ(-ERESTART,
mirror_image_snapshot_unlink_peer(&ioctx, oid, 1, "peer2")); mirror_image_snapshot_unlink_peer(&ioctx, oid, 1, "peer2"));
ASSERT_EQ(0, snapshot_get(&ioctx, oid, 1, &snap)); ASSERT_EQ(0, snapshot_get(&ioctx, oid, 1, &snap));
sn = boost::get<cls::rbd::MirrorSnapshotNamespace>( sn = std::get_if<cls::rbd::MirrorSnapshotNamespace>(
&snap.snapshot_namespace); &snap.snapshot_namespace);
ASSERT_NE(nullptr, sn); ASSERT_NE(nullptr, sn);
ASSERT_EQ(1U, sn->mirror_peer_uuids.size()); ASSERT_EQ(1U, sn->mirror_peer_uuids.size());
ASSERT_EQ(1U, sn->mirror_peer_uuids.count("peer2")); ASSERT_EQ(1U, sn->mirror_peer_uuids.count("peer2"));
ASSERT_EQ(0, snapshot_get(&ioctx, oid, 2, &snap)); ASSERT_EQ(0, snapshot_get(&ioctx, oid, 2, &snap));
auto nsn = boost::get<cls::rbd::MirrorSnapshotNamespace>( auto nsn = std::get_if<cls::rbd::MirrorSnapshotNamespace>(
&snap.snapshot_namespace); &snap.snapshot_namespace);
ASSERT_NE(nullptr, nsn); ASSERT_NE(nullptr, nsn);
ASSERT_EQ(non_primary, *nsn); ASSERT_EQ(non_primary, *nsn);
@ -2297,7 +2297,7 @@ TEST_F(TestClsRbd, mirror_snapshot) {
ASSERT_EQ(0, mirror_image_snapshot_set_copy_progress(&ioctx, oid, 2, true, ASSERT_EQ(0, mirror_image_snapshot_set_copy_progress(&ioctx, oid, 2, true,
10)); 10));
ASSERT_EQ(0, snapshot_get(&ioctx, oid, 2, &snap)); ASSERT_EQ(0, snapshot_get(&ioctx, oid, 2, &snap));
nsn = boost::get<cls::rbd::MirrorSnapshotNamespace>( nsn = std::get_if<cls::rbd::MirrorSnapshotNamespace>(
&snap.snapshot_namespace); &snap.snapshot_namespace);
ASSERT_NE(nullptr, nsn); ASSERT_NE(nullptr, nsn);
ASSERT_TRUE(nsn->complete); ASSERT_TRUE(nsn->complete);

View File

@ -252,8 +252,7 @@ public:
} }
if (protect) { if (protect) {
EXPECT_TRUE(boost::get<cls::rbd::UserSnapshotNamespace>(&snap_ns) != EXPECT_TRUE(std::holds_alternative<cls::rbd::UserSnapshotNamespace>(snap_ns));
nullptr);
r = image_ctx->operations->snap_protect(snap_ns, snap_name.c_str()); r = image_ctx->operations->snap_protect(snap_ns, snap_name.c_str());
if (r < 0) { if (r < 0) {
return r; return r;

View File

@ -178,7 +178,7 @@ public:
auto it = mock_image_ctx.snap_info.find(snap_id); auto it = mock_image_ctx.snap_info.find(snap_id);
ASSERT_NE(it, mock_image_ctx.snap_info.end()); ASSERT_NE(it, mock_image_ctx.snap_info.end());
auto info = auto info =
boost::get<cls::rbd::MirrorSnapshotNamespace>( std::get_if<cls::rbd::MirrorSnapshotNamespace>(
&it->second.snap_namespace); &it->second.snap_namespace);
ASSERT_NE(nullptr, info); ASSERT_NE(nullptr, info);
ASSERT_EQ(is_linked, info->mirror_peer_uuids.erase( ASSERT_EQ(is_linked, info->mirror_peer_uuids.erase(

View File

@ -91,7 +91,7 @@ public:
auto it = mock_image_ctx.snap_info.find(snap_id); auto it = mock_image_ctx.snap_info.find(snap_id);
EXPECT_NE(it, mock_image_ctx.snap_info.end()); EXPECT_NE(it, mock_image_ctx.snap_info.end());
auto info = auto info =
boost::get<cls::rbd::MirrorSnapshotNamespace>( std::get_if<cls::rbd::MirrorSnapshotNamespace>(
&it->second.snap_namespace); &it->second.snap_namespace);
EXPECT_NE(nullptr, info); EXPECT_NE(nullptr, info);
EXPECT_NE(0, info->mirror_peer_uuids.erase( EXPECT_NE(0, info->mirror_peer_uuids.erase(

View File

@ -393,7 +393,7 @@ public:
return r; return r;
} }
auto ns = boost::get<cls::rbd::MirrorSnapshotNamespace>( auto ns = std::get_if<cls::rbd::MirrorSnapshotNamespace>(
&snap_info.snapshot_namespace); &snap_info.snapshot_namespace);
if (ns != nullptr) { if (ns != nullptr) {
*mirror_snap_id = snap_id; *mirror_snap_id = snap_id;

View File

@ -238,7 +238,7 @@ void ApplyImageStateRequest<I>::unprotect_snapshot() {
auto snap_id = snap_it->first; auto snap_id = snap_it->first;
const auto& snap_info = snap_it->second; const auto& snap_info = snap_it->second;
auto user_ns = boost::get<cls::rbd::UserSnapshotNamespace>( auto user_ns = std::get_if<cls::rbd::UserSnapshotNamespace>(
&snap_info.snap_namespace); &snap_info.snap_namespace);
if (user_ns == nullptr) { if (user_ns == nullptr) {
dout(20) << "snapshot " << snap_id << " is not a user snapshot" << dendl; dout(20) << "snapshot " << snap_id << " is not a user snapshot" << dendl;
@ -324,7 +324,7 @@ void ApplyImageStateRequest<I>::remove_snapshot() {
auto snap_id = snap_it->first; auto snap_id = snap_it->first;
const auto& snap_info = snap_it->second; const auto& snap_info = snap_it->second;
auto user_ns = boost::get<cls::rbd::UserSnapshotNamespace>( auto user_ns = std::get_if<cls::rbd::UserSnapshotNamespace>(
&snap_info.snap_namespace); &snap_info.snap_namespace);
if (user_ns == nullptr) { if (user_ns == nullptr) {
dout(20) << "snapshot " << snap_id << " is not a user snapshot" << dendl; dout(20) << "snapshot " << snap_id << " is not a user snapshot" << dendl;
@ -398,7 +398,7 @@ void ApplyImageStateRequest<I>::protect_snapshot() {
auto snap_id = snap_it->first; auto snap_id = snap_it->first;
const auto& snap_info = snap_it->second; const auto& snap_info = snap_it->second;
auto user_ns = boost::get<cls::rbd::UserSnapshotNamespace>( auto user_ns = std::get_if<cls::rbd::UserSnapshotNamespace>(
&snap_info.snap_namespace); &snap_info.snap_namespace);
if (user_ns == nullptr) { if (user_ns == nullptr) {
dout(20) << "snapshot " << snap_id << " is not a user snapshot" << dendl; dout(20) << "snapshot " << snap_id << " is not a user snapshot" << dendl;
@ -484,7 +484,7 @@ void ApplyImageStateRequest<I>::rename_snapshot() {
auto snap_id = snap_it->first; auto snap_id = snap_it->first;
const auto& snap_info = snap_it->second; const auto& snap_info = snap_it->second;
auto user_ns = boost::get<cls::rbd::UserSnapshotNamespace>( auto user_ns = std::get_if<cls::rbd::UserSnapshotNamespace>(
&snap_info.snap_namespace); &snap_info.snap_namespace);
if (user_ns == nullptr) { if (user_ns == nullptr) {
dout(20) << "snapshot " << snap_id << " is not a user snapshot" << dendl; dout(20) << "snapshot " << snap_id << " is not a user snapshot" << dendl;
@ -608,7 +608,7 @@ uint64_t ApplyImageStateRequest<I>::compute_remote_snap_id(
for (auto snap_it = m_remote_image_ctx->snap_info.begin(); for (auto snap_it = m_remote_image_ctx->snap_info.begin();
snap_it != m_remote_image_ctx->snap_info.end(); ++snap_it) { snap_it != m_remote_image_ctx->snap_info.end(); ++snap_it) {
auto snap_id = snap_it->first; auto snap_id = snap_it->first;
auto mirror_ns = boost::get<cls::rbd::MirrorSnapshotNamespace>( auto mirror_ns = std::get_if<cls::rbd::MirrorSnapshotNamespace>(
&snap_it->second.snap_namespace); &snap_it->second.snap_namespace);
if (mirror_ns == nullptr || !mirror_ns->is_non_primary()) { if (mirror_ns == nullptr || !mirror_ns->is_non_primary()) {
continue; continue;

View File

@ -58,7 +58,7 @@ std::pair<uint64_t, librbd::SnapInfo*> get_newest_mirror_snapshot(
for (auto snap_info_it = image_ctx->snap_info.rbegin(); for (auto snap_info_it = image_ctx->snap_info.rbegin();
snap_info_it != image_ctx->snap_info.rend(); ++snap_info_it) { snap_info_it != image_ctx->snap_info.rend(); ++snap_info_it) {
const auto& snap_ns = snap_info_it->second.snap_namespace; const auto& snap_ns = snap_info_it->second.snap_namespace;
auto mirror_ns = boost::get< auto mirror_ns = std::get_if<
cls::rbd::MirrorSnapshotNamespace>(&snap_ns); cls::rbd::MirrorSnapshotNamespace>(&snap_ns);
if (mirror_ns == nullptr || !mirror_ns->complete) { if (mirror_ns == nullptr || !mirror_ns->complete) {
continue; continue;
@ -446,7 +446,7 @@ void Replayer<I>::scan_local_mirror_snapshots(
for (auto snap_info_it = local_image_ctx->snap_info.begin(); for (auto snap_info_it = local_image_ctx->snap_info.begin();
snap_info_it != local_image_ctx->snap_info.end(); ++snap_info_it) { snap_info_it != local_image_ctx->snap_info.end(); ++snap_info_it) {
const auto& snap_ns = snap_info_it->second.snap_namespace; const auto& snap_ns = snap_info_it->second.snap_namespace;
auto mirror_ns = boost::get< auto mirror_ns = std::get_if<
cls::rbd::MirrorSnapshotNamespace>(&snap_ns); cls::rbd::MirrorSnapshotNamespace>(&snap_ns);
if (mirror_ns == nullptr) { if (mirror_ns == nullptr) {
continue; continue;
@ -576,7 +576,7 @@ void Replayer<I>::scan_remote_mirror_snapshots(
for (auto snap_info_it = remote_image_ctx->snap_info.begin(); for (auto snap_info_it = remote_image_ctx->snap_info.begin();
snap_info_it != remote_image_ctx->snap_info.end(); ++snap_info_it) { snap_info_it != remote_image_ctx->snap_info.end(); ++snap_info_it) {
const auto& snap_ns = snap_info_it->second.snap_namespace; const auto& snap_ns = snap_info_it->second.snap_namespace;
auto mirror_ns = boost::get< auto mirror_ns = std::get_if<
cls::rbd::MirrorSnapshotNamespace>(&snap_ns); cls::rbd::MirrorSnapshotNamespace>(&snap_ns);
if (mirror_ns == nullptr) { if (mirror_ns == nullptr) {
continue; continue;
@ -768,8 +768,8 @@ void Replayer<I>::prune_non_primary_snapshot(uint64_t snap_id) {
snap_namespace = snap_info->snap_namespace; snap_namespace = snap_info->snap_namespace;
snap_name = snap_info->name; snap_name = snap_info->name;
ceph_assert(boost::get<cls::rbd::MirrorSnapshotNamespace>( ceph_assert(std::holds_alternative<cls::rbd::MirrorSnapshotNamespace>(
&snap_namespace) != nullptr); snap_namespace));
} }
} }
@ -913,7 +913,7 @@ void Replayer<I>::create_non_primary_snapshot() {
return; return;
} }
auto mirror_ns = boost::get<cls::rbd::MirrorSnapshotNamespace>( auto mirror_ns = std::get_if<cls::rbd::MirrorSnapshotNamespace>(
&local_snap_info_it->second.snap_namespace); &local_snap_info_it->second.snap_namespace);
ceph_assert(mirror_ns != nullptr); ceph_assert(mirror_ns != nullptr);
@ -930,8 +930,8 @@ void Replayer<I>::create_non_primary_snapshot() {
// we can ignore all non-user snapshots since image state only includes // we can ignore all non-user snapshots since image state only includes
// user snapshots // user snapshots
if (boost::get<cls::rbd::UserSnapshotNamespace>( if (!std::holds_alternative<cls::rbd::UserSnapshotNamespace>(
&remote_snap_info.snap_namespace) == nullptr) { remote_snap_info.snap_namespace)) {
continue; continue;
} }

View File

@ -29,7 +29,7 @@ uint64_t compute_remote_snap_id(
// come at or after the snapshot we are searching against // come at or after the snapshot we are searching against
for (auto snap_it = local_snap_infos.lower_bound(local_snap_id); for (auto snap_it = local_snap_infos.lower_bound(local_snap_id);
snap_it != local_snap_infos.end(); ++snap_it) { snap_it != local_snap_infos.end(); ++snap_it) {
auto mirror_ns = boost::get<cls::rbd::MirrorSnapshotNamespace>( auto mirror_ns = std::get_if<cls::rbd::MirrorSnapshotNamespace>(
&snap_it->second.snap_namespace); &snap_it->second.snap_namespace);
if (mirror_ns == nullptr || !mirror_ns->is_non_primary()) { if (mirror_ns == nullptr || !mirror_ns->is_non_primary()) {
continue; continue;