From: Kefu Chai Date: Mon, 24 Mar 2025 02:05:25 +0000 (+0800) Subject: librbd: migrate from boost::variant to std::variant X-Git-Tag: testing/wip-vshankar-testing-20250327.072724-debug~9^2 X-Git-Url: http://git.apps.os.sepia.ceph.com/?a=commitdiff_plain;h=184443c22fd2fb71bac5fc3d22ce499d99b76157;p=ceph-ci.git librbd: migrate from boost::variant to std::variant migrate from boost::variant to std::variant Complete migration started in commit 017f3339c, replacing boost::variant with std::variant throughout the librbd codebase. This change is part of our ongoing effort to reduce third-party dependencies by leveraging C++ standard library alternatives where possible. Benefits include: - Improved code readability and maintainability - Reduced external dependency surface - More consistent API usage with other components Signed-off-by: Kefu Chai --- diff --git a/src/librbd/Journal.cc b/src/librbd/Journal.cc index 1b37a30c17c..ab65007d9ad 100644 --- a/src/librbd/Journal.cc +++ b/src/librbd/Journal.cc @@ -205,7 +205,7 @@ struct GetTagsRequest { } journal::ImageClientMeta *image_client_meta = - boost::get(&client_data.client_meta); + std::get_if(&client_data.client_meta); if (image_client_meta == nullptr) { lderr(cct) << this << " OpenJournalerRequest::" << __func__ << ": " << "failed to get client meta" << dendl; @@ -1768,7 +1768,7 @@ int Journal::check_resync_requested(bool *do_resync) { } journal::ImageClientMeta *image_client_meta = - boost::get(&client_data.client_meta); + std::get_if(&client_data.client_meta); if (image_client_meta == nullptr) { lderr(cct) << this << " " << __func__ << ": " << "failed to access image client meta struct" << dendl; diff --git a/src/librbd/journal/OpenRequest.cc b/src/librbd/journal/OpenRequest.cc index eb01aa35a28..398678cfb69 100644 --- a/src/librbd/journal/OpenRequest.cc +++ b/src/librbd/journal/OpenRequest.cc @@ -83,7 +83,7 @@ void OpenRequest::handle_init(int r) { } journal::ImageClientMeta *image_client_meta = - boost::get(&client_data.client_meta); + std::get_if(&client_data.client_meta); if (image_client_meta == nullptr) { lderr(cct) << this << " " << __func__ << ": " << "failed to extract client meta data" << dendl; diff --git a/src/librbd/journal/Replay.cc b/src/librbd/journal/Replay.cc index e8c6cfbbbc8..51ba1fc7252 100644 --- a/src/librbd/journal/Replay.cc +++ b/src/librbd/journal/Replay.cc @@ -220,8 +220,8 @@ void Replay::process(const EventEntry &event_entry, return; } - boost::apply_visitor(EventVisitor(this, on_ready, on_safe), - event_entry.event); + std::visit(EventVisitor(this, on_ready, on_safe), + event_entry.event); } template diff --git a/src/librbd/journal/Types.cc b/src/librbd/journal/Types.cc index d76a15e557c..543fc151380 100644 --- a/src/librbd/journal/Types.cc +++ b/src/librbd/journal/Types.cc @@ -16,7 +16,7 @@ using ceph::decode; namespace { template -class GetTypeVisitor : public boost::static_visitor { +class GetTypeVisitor { public: template inline E operator()(const T&) const { @@ -24,7 +24,7 @@ public: } }; -class EncodeVisitor : public boost::static_visitor { +class EncodeVisitor { public: explicit EncodeVisitor(bufferlist &bl) : m_bl(bl) { } @@ -38,7 +38,7 @@ private: bufferlist &m_bl; }; -class DecodeVisitor : public boost::static_visitor { +class DecodeVisitor { public: DecodeVisitor(__u8 version, bufferlist::const_iterator &iter) : m_version(version), m_iter(iter) { @@ -53,7 +53,7 @@ private: bufferlist::const_iterator &m_iter; }; -class DumpVisitor : public boost::static_visitor { +class DumpVisitor { public: explicit DumpVisitor(Formatter *formatter, const std::string &key) : m_formatter(formatter), m_key(key) {} @@ -411,12 +411,12 @@ void UnknownEvent::dump(Formatter *f) const { } EventType EventEntry::get_event_type() const { - return boost::apply_visitor(GetTypeVisitor(), event); + return std::visit(GetTypeVisitor(), event); } void EventEntry::encode(bufferlist& bl) const { ENCODE_START(5, 1, bl); - boost::apply_visitor(EncodeVisitor(bl), event); + std::visit(EncodeVisitor(bl), event); ENCODE_FINISH(bl); encode_metadata(bl); } @@ -494,7 +494,7 @@ void EventEntry::decode(bufferlist::const_iterator& it) { break; } - boost::apply_visitor(DecodeVisitor(struct_v, it), event); + std::visit(DecodeVisitor(struct_v, it), event); DECODE_FINISH(it); if (struct_v >= 4) { decode_metadata(it); @@ -502,7 +502,7 @@ void EventEntry::decode(bufferlist::const_iterator& it) { } void EventEntry::dump(Formatter *f) const { - boost::apply_visitor(DumpVisitor(f, "event_type"), event); + std::visit(DumpVisitor(f, "event_type"), event); f->dump_stream("timestamp") << timestamp; } @@ -689,12 +689,12 @@ void UnknownClientMeta::dump(Formatter *f) const { } ClientMetaType ClientData::get_client_meta_type() const { - return boost::apply_visitor(GetTypeVisitor(), client_meta); + return std::visit(GetTypeVisitor(), client_meta); } void ClientData::encode(bufferlist& bl) const { ENCODE_START(2, 1, bl); - boost::apply_visitor(EncodeVisitor(bl), client_meta); + std::visit(EncodeVisitor(bl), client_meta); ENCODE_FINISH(bl); } @@ -720,12 +720,12 @@ void ClientData::decode(bufferlist::const_iterator& it) { break; } - boost::apply_visitor(DecodeVisitor(struct_v, it), client_meta); + std::visit(DecodeVisitor(struct_v, it), client_meta); DECODE_FINISH(it); } void ClientData::dump(Formatter *f) const { - boost::apply_visitor(DumpVisitor(f, "client_meta_type"), client_meta); + std::visit(DumpVisitor(f, "client_meta_type"), client_meta); } void ClientData::generate_test_instances(std::list &o) { diff --git a/src/librbd/journal/Types.h b/src/librbd/journal/Types.h index d57858a1590..aacf98b492a 100644 --- a/src/librbd/journal/Types.h +++ b/src/librbd/journal/Types.h @@ -13,9 +13,9 @@ #include "librbd/Types.h" #include #include +#include #include #include -#include #include namespace ceph { @@ -410,7 +410,7 @@ struct UnknownEvent { void dump(Formatter *f) const; }; -typedef boost::mpl::vector EventVector; -typedef boost::make_variant_over::type Event; + UnknownEvent>; struct EventEntry { static uint32_t get_fixed_size() { @@ -575,10 +574,10 @@ struct UnknownClientMeta { void dump(Formatter *f) const; }; -typedef boost::variant ClientMeta; +using ClientMeta = std::variant; struct ClientData { ClientData() { diff --git a/src/librbd/mirror/DisableRequest.cc b/src/librbd/mirror/DisableRequest.cc index 3953de265d5..82dc935a146 100644 --- a/src/librbd/mirror/DisableRequest.cc +++ b/src/librbd/mirror/DisableRequest.cc @@ -258,7 +258,7 @@ Context *DisableRequest::handle_get_clients(int *result) { m_ret[client.id] = 0; journal::MirrorPeerClientMeta client_meta = - boost::get(client_data.client_meta); + std::get(client_data.client_meta); for (const auto& sync : client_meta.sync_points) { send_remove_snap(client.id, sync.snap_namespace, sync.snap_name); diff --git a/src/test/librbd/journal/test_Entries.cc b/src/test/librbd/journal/test_Entries.cc index bb4b06c0368..fe9ee29fbc1 100644 --- a/src/test/librbd/journal/test_Entries.cc +++ b/src/test/librbd/journal/test_Entries.cc @@ -13,7 +13,6 @@ #include "journal/ReplayHandler.h" #include "journal/Settings.h" #include -#include void register_test_journal_entries() { } @@ -147,7 +146,7 @@ TEST_F(TestJournalEntries, AioWrite) { event_entry.get_event_type()); librbd::journal::AioWriteEvent aio_write_event = - boost::get(event_entry.event); + std::get(event_entry.event); ASSERT_EQ(123U, aio_write_event.offset); ASSERT_EQ(buffer.size(), aio_write_event.length); @@ -191,7 +190,7 @@ TEST_F(TestJournalEntries, AioDiscard) { event_entry.get_event_type()); librbd::journal::AioDiscardEvent aio_discard_event = - boost::get(event_entry.event); + std::get(event_entry.event); ASSERT_EQ(123U, aio_discard_event.offset); ASSERT_EQ(234U, aio_discard_event.length); } @@ -251,7 +250,7 @@ TEST_F(TestJournalEntries, AioDiscardWithPrune) { event_entry.get_event_type()); librbd::journal::AioDiscardEvent aio_discard_event = - boost::get(event_entry.event); + std::get(event_entry.event); ASSERT_EQ(offset, aio_discard_event.offset); ASSERT_EQ(size, aio_discard_event.length); diff --git a/src/test/rbd_mirror/image_replayer/journal/test_mock_EventPreprocessor.cc b/src/test/rbd_mirror/image_replayer/journal/test_mock_EventPreprocessor.cc index ad00552814b..59a72305a9c 100644 --- a/src/test/rbd_mirror/image_replayer/journal/test_mock_EventPreprocessor.cc +++ b/src/test/rbd_mirror/image_replayer/journal/test_mock_EventPreprocessor.cc @@ -163,7 +163,7 @@ TEST_F(TestMockImageReplayerJournalEventPreprocessor, PreprocessSnapRename) { ASSERT_EQ(expected_snap_seqs, m_client_meta.snap_seqs); librbd::journal::SnapRenameEvent *event = - boost::get(&event_entry.event); + std::get_if(&event_entry.event); ASSERT_EQ(6U, event->snap_id); } @@ -186,7 +186,7 @@ TEST_F(TestMockImageReplayerJournalEventPreprocessor, PreprocessSnapRenameMissin ASSERT_EQ(-ENOENT, ctx.wait()); librbd::journal::SnapRenameEvent *event = - boost::get(&event_entry.event); + std::get_if(&event_entry.event); ASSERT_EQ(CEPH_NOSNAP, event->snap_id); } @@ -215,7 +215,7 @@ TEST_F(TestMockImageReplayerJournalEventPreprocessor, PreprocessSnapRenameKnown) ASSERT_EQ(expected_snap_seqs, m_client_meta.snap_seqs); librbd::journal::SnapRenameEvent *event = - boost::get(&event_entry.event); + std::get_if(&event_entry.event); ASSERT_EQ(6U, event->snap_id); } diff --git a/src/tools/rbd_mirror/image_replayer/Utils.cc b/src/tools/rbd_mirror/image_replayer/Utils.cc index 55162a4e4b5..e42d5262983 100644 --- a/src/tools/rbd_mirror/image_replayer/Utils.cc +++ b/src/tools/rbd_mirror/image_replayer/Utils.cc @@ -42,7 +42,7 @@ bool decode_client_meta(const cls::journal::Client& client, return false; } - auto local_client_meta = boost::get( + auto local_client_meta = std::get_if( &client_data.client_meta); if (local_client_meta == nullptr) { derr << "unknown peer registration" << dendl; diff --git a/src/tools/rbd_mirror/image_replayer/journal/EventPreprocessor.cc b/src/tools/rbd_mirror/image_replayer/journal/EventPreprocessor.cc index 7263e2d79cf..9a9bb3e139b 100644 --- a/src/tools/rbd_mirror/image_replayer/journal/EventPreprocessor.cc +++ b/src/tools/rbd_mirror/image_replayer/journal/EventPreprocessor.cc @@ -11,7 +11,6 @@ #include "librbd/Utils.h" #include "librbd/asio/ContextWQ.h" #include "librbd/journal/Types.h" -#include #include // for std::shared_lock @@ -95,8 +94,8 @@ void EventPreprocessor::preprocess_event() { m_snap_seqs = m_client_meta->snap_seqs; m_snap_seqs_updated = prune_snap_map(&m_snap_seqs); - int r = boost::apply_visitor(PreprocessEventVisitor(this), - m_event_entry->event); + int r = std::visit(PreprocessEventVisitor(this), + m_event_entry->event); if (r < 0) { finish(r); return; diff --git a/src/tools/rbd_mirror/image_replayer/journal/PrepareReplayRequest.cc b/src/tools/rbd_mirror/image_replayer/journal/PrepareReplayRequest.cc index 26fba303c03..168c4567274 100644 --- a/src/tools/rbd_mirror/image_replayer/journal/PrepareReplayRequest.cc +++ b/src/tools/rbd_mirror/image_replayer/journal/PrepareReplayRequest.cc @@ -162,7 +162,7 @@ void PrepareReplayRequest::handle_get_remote_tag_class(int r) { } librbd::journal::ImageClientMeta *client_meta = - boost::get(&client_data.client_meta); + std::get_if(&client_data.client_meta); if (client_meta == nullptr) { derr << "unknown remote client registration" << dendl; finish(-EINVAL);