]> git.apps.os.sepia.ceph.com Git - ceph-ci.git/commitdiff
librbd: migrate from boost::variant to std::variant
authorKefu Chai <tchaikov@gmail.com>
Mon, 24 Mar 2025 02:05:25 +0000 (10:05 +0800)
committerKefu Chai <tchaikov@gmail.com>
Tue, 25 Mar 2025 13:04:09 +0000 (21:04 +0800)
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 <tchaikov@gmail.com>
src/librbd/Journal.cc
src/librbd/journal/OpenRequest.cc
src/librbd/journal/Replay.cc
src/librbd/journal/Types.cc
src/librbd/journal/Types.h
src/librbd/mirror/DisableRequest.cc
src/test/librbd/journal/test_Entries.cc
src/test/rbd_mirror/image_replayer/journal/test_mock_EventPreprocessor.cc
src/tools/rbd_mirror/image_replayer/Utils.cc
src/tools/rbd_mirror/image_replayer/journal/EventPreprocessor.cc
src/tools/rbd_mirror/image_replayer/journal/PrepareReplayRequest.cc

index 1b37a30c17c0d9da3640a852700c66e0ce23b032..ab65007d9ad8bf12ba136be4d4fa7da5aedafe2f 100644 (file)
@@ -205,7 +205,7 @@ struct GetTagsRequest {
     }
 
     journal::ImageClientMeta *image_client_meta =
-      boost::get<journal::ImageClientMeta>(&client_data.client_meta);
+      std::get_if<journal::ImageClientMeta>(&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<I>::check_resync_requested(bool *do_resync) {
   }
 
   journal::ImageClientMeta *image_client_meta =
-    boost::get<journal::ImageClientMeta>(&client_data.client_meta);
+    std::get_if<journal::ImageClientMeta>(&client_data.client_meta);
   if (image_client_meta == nullptr) {
     lderr(cct) << this << " " << __func__ << ": "
                << "failed to access image client meta struct" << dendl;
index eb01aa35a280eefd3e00dfe0b16a716f61432632..398678cfb6928b431908c48c81b1d243d3e1534d 100644 (file)
@@ -83,7 +83,7 @@ void OpenRequest<I>::handle_init(int r) {
   }
 
   journal::ImageClientMeta *image_client_meta =
-    boost::get<journal::ImageClientMeta>(&client_data.client_meta);
+    std::get_if<journal::ImageClientMeta>(&client_data.client_meta);
   if (image_client_meta == nullptr) {
     lderr(cct) << this << " " << __func__ << ": "
                << "failed to extract client meta data" << dendl;
index e8c6cfbbbc87a4bbbeb839e044d2c35f1be38803..51ba1fc72526cf90d0aaf0dffbbcbccdd075e678 100644 (file)
@@ -220,8 +220,8 @@ void Replay<I>::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 <typename I>
index d76a15e557cecb7f0723878197a84b10401d4a52..543fc1513801a56bf8b870578ba108764afde59e 100644 (file)
@@ -16,7 +16,7 @@ using ceph::decode;
 namespace {
 
 template <typename E>
-class GetTypeVisitor : public boost::static_visitor<E> {
+class GetTypeVisitor {
 public:
   template <typename T>
   inline E operator()(const T&) const {
@@ -24,7 +24,7 @@ public:
   }
 };
 
-class EncodeVisitor : public boost::static_visitor<void> {
+class EncodeVisitor {
 public:
   explicit EncodeVisitor(bufferlist &bl) : m_bl(bl) {
   }
@@ -38,7 +38,7 @@ private:
   bufferlist &m_bl;
 };
 
-class DecodeVisitor : public boost::static_visitor<void> {
+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<void> {
+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<EventType>(), event);
+  return std::visit(GetTypeVisitor<EventType>(), 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<ClientMetaType>(), client_meta);
+  return std::visit(GetTypeVisitor<ClientMetaType>(), 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<ClientData *> &o) {
index d57858a159005886236ac1392ac8799151d738f5..aacf98b492a08291748bf9908ae5fcadfbcee117 100644 (file)
@@ -13,9 +13,9 @@
 #include "librbd/Types.h"
 #include <iosfwd>
 #include <list>
+#include <variant>
 #include <boost/none.hpp>
 #include <boost/optional.hpp>
-#include <boost/variant.hpp>
 #include <boost/mpl/vector.hpp>
 
 namespace ceph {
@@ -410,7 +410,7 @@ struct UnknownEvent {
   void dump(Formatter *f) const;
 };
 
-typedef boost::mpl::vector<AioDiscardEvent,
+using Event = std::variant<AioDiscardEvent,
                            AioWriteEvent,
                            AioFlushEvent,
                            OpFinishEvent,
@@ -430,8 +430,7 @@ typedef boost::mpl::vector<AioDiscardEvent,
                            MetadataRemoveEvent,
                            AioWriteSameEvent,
                            AioCompareAndWriteEvent,
-                           UnknownEvent> EventVector;
-typedef boost::make_variant_over<EventVector>::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<ImageClientMeta,
-                       MirrorPeerClientMeta,
-                       CliClientMeta,
-                       UnknownClientMeta> ClientMeta;
+using ClientMeta = std::variant<ImageClientMeta,
+                                MirrorPeerClientMeta,
+                                CliClientMeta,
+                                UnknownClientMeta>;
 
 struct ClientData {
   ClientData() {
index 3953de265d5eed686e46e3f76629d83fd09d7c3d..82dc935a14605dccca485ceff47c810cec78e003 100644 (file)
@@ -258,7 +258,7 @@ Context *DisableRequest<I>::handle_get_clients(int *result) {
     m_ret[client.id] = 0;
 
     journal::MirrorPeerClientMeta client_meta =
-      boost::get<journal::MirrorPeerClientMeta>(client_data.client_meta);
+      std::get<journal::MirrorPeerClientMeta>(client_data.client_meta);
 
     for (const auto& sync : client_meta.sync_points) {
       send_remove_snap(client.id, sync.snap_namespace, sync.snap_name);
index bb4b06c0368a1ebcbd63c0001ec4458a63a225f1..fe9ee29fbc1c84e62bf62c3572de12b384bed29f 100644 (file)
@@ -13,7 +13,6 @@
 #include "journal/ReplayHandler.h"
 #include "journal/Settings.h"
 #include <list>
-#include <boost/variant.hpp>
 
 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<librbd::journal::AioWriteEvent>(event_entry.event);
+    std::get<librbd::journal::AioWriteEvent>(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<librbd::journal::AioDiscardEvent>(event_entry.event);
+    std::get<librbd::journal::AioDiscardEvent>(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<librbd::journal::AioDiscardEvent>(event_entry.event);
+      std::get<librbd::journal::AioDiscardEvent>(event_entry.event);
     ASSERT_EQ(offset, aio_discard_event.offset);
     ASSERT_EQ(size, aio_discard_event.length);
 
index ad00552814bfb31ccd2950153bb4f387a79391f3..59a72305a9c862493d1e418ca8068053843f72d6 100644 (file)
@@ -163,7 +163,7 @@ TEST_F(TestMockImageReplayerJournalEventPreprocessor, PreprocessSnapRename) {
   ASSERT_EQ(expected_snap_seqs, m_client_meta.snap_seqs);
 
   librbd::journal::SnapRenameEvent *event =
-    boost::get<librbd::journal::SnapRenameEvent>(&event_entry.event);
+    std::get_if<librbd::journal::SnapRenameEvent>(&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<librbd::journal::SnapRenameEvent>(&event_entry.event);
+    std::get_if<librbd::journal::SnapRenameEvent>(&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<librbd::journal::SnapRenameEvent>(&event_entry.event);
+    std::get_if<librbd::journal::SnapRenameEvent>(&event_entry.event);
   ASSERT_EQ(6U, event->snap_id);
 }
 
index 55162a4e4b58df9e8b3682c04c5bc058ea7a23e6..e42d52629836183c7bfe170eed84f170f50a58e2 100644 (file)
@@ -42,7 +42,7 @@ bool decode_client_meta(const cls::journal::Client& client,
     return false;
   }
 
-  auto local_client_meta = boost::get<librbd::journal::MirrorPeerClientMeta>(
+  auto local_client_meta = std::get_if<librbd::journal::MirrorPeerClientMeta>(
     &client_data.client_meta);
   if (local_client_meta == nullptr) {
     derr << "unknown peer registration" << dendl;
index 7263e2d79cff0ca7221aecd6fda4b2623197656e..9a9bb3e139b49bda333d011d6e2bbc3847215bf8 100644 (file)
@@ -11,7 +11,6 @@
 #include "librbd/Utils.h"
 #include "librbd/asio/ContextWQ.h"
 #include "librbd/journal/Types.h"
-#include <boost/variant.hpp>
 
 #include <shared_mutex> // for std::shared_lock
 
@@ -95,8 +94,8 @@ void EventPreprocessor<I>::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;
index 26fba303c035da34edb378e4621e73f7edbd7be8..168c45672743386be483b1c82c8029b68cf08473 100644 (file)
@@ -162,7 +162,7 @@ void PrepareReplayRequest<I>::handle_get_remote_tag_class(int r) {
   }
 
   librbd::journal::ImageClientMeta *client_meta =
-    boost::get<librbd::journal::ImageClientMeta>(&client_data.client_meta);
+    std::get_if<librbd::journal::ImageClientMeta>(&client_data.client_meta);
   if (client_meta == nullptr) {
     derr << "unknown remote client registration" << dendl;
     finish(-EINVAL);