Skip to content

Commit 184443c

Browse files
committed
librbd: migrate from boost::variant to std::variant
migrate from boost::variant to std::variant Complete migration started in commit 017f333, 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 <[email protected]>
1 parent 9ea4513 commit 184443c

File tree

11 files changed

+35
-38
lines changed

11 files changed

+35
-38
lines changed

src/librbd/Journal.cc

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -205,7 +205,7 @@ struct GetTagsRequest {
205205
}
206206

207207
journal::ImageClientMeta *image_client_meta =
208-
boost::get<journal::ImageClientMeta>(&client_data.client_meta);
208+
std::get_if<journal::ImageClientMeta>(&client_data.client_meta);
209209
if (image_client_meta == nullptr) {
210210
lderr(cct) << this << " OpenJournalerRequest::" << __func__ << ": "
211211
<< "failed to get client meta" << dendl;
@@ -1768,7 +1768,7 @@ int Journal<I>::check_resync_requested(bool *do_resync) {
17681768
}
17691769

17701770
journal::ImageClientMeta *image_client_meta =
1771-
boost::get<journal::ImageClientMeta>(&client_data.client_meta);
1771+
std::get_if<journal::ImageClientMeta>(&client_data.client_meta);
17721772
if (image_client_meta == nullptr) {
17731773
lderr(cct) << this << " " << __func__ << ": "
17741774
<< "failed to access image client meta struct" << dendl;

src/librbd/journal/OpenRequest.cc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,7 @@ void OpenRequest<I>::handle_init(int r) {
8383
}
8484

8585
journal::ImageClientMeta *image_client_meta =
86-
boost::get<journal::ImageClientMeta>(&client_data.client_meta);
86+
std::get_if<journal::ImageClientMeta>(&client_data.client_meta);
8787
if (image_client_meta == nullptr) {
8888
lderr(cct) << this << " " << __func__ << ": "
8989
<< "failed to extract client meta data" << dendl;

src/librbd/journal/Replay.cc

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -220,8 +220,8 @@ void Replay<I>::process(const EventEntry &event_entry,
220220
return;
221221
}
222222

223-
boost::apply_visitor(EventVisitor(this, on_ready, on_safe),
224-
event_entry.event);
223+
std::visit(EventVisitor(this, on_ready, on_safe),
224+
event_entry.event);
225225
}
226226

227227
template <typename I>

src/librbd/journal/Types.cc

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -16,15 +16,15 @@ using ceph::decode;
1616
namespace {
1717

1818
template <typename E>
19-
class GetTypeVisitor : public boost::static_visitor<E> {
19+
class GetTypeVisitor {
2020
public:
2121
template <typename T>
2222
inline E operator()(const T&) const {
2323
return T::TYPE;
2424
}
2525
};
2626

27-
class EncodeVisitor : public boost::static_visitor<void> {
27+
class EncodeVisitor {
2828
public:
2929
explicit EncodeVisitor(bufferlist &bl) : m_bl(bl) {
3030
}
@@ -38,7 +38,7 @@ class EncodeVisitor : public boost::static_visitor<void> {
3838
bufferlist &m_bl;
3939
};
4040

41-
class DecodeVisitor : public boost::static_visitor<void> {
41+
class DecodeVisitor {
4242
public:
4343
DecodeVisitor(__u8 version, bufferlist::const_iterator &iter)
4444
: m_version(version), m_iter(iter) {
@@ -53,7 +53,7 @@ class DecodeVisitor : public boost::static_visitor<void> {
5353
bufferlist::const_iterator &m_iter;
5454
};
5555

56-
class DumpVisitor : public boost::static_visitor<void> {
56+
class DumpVisitor {
5757
public:
5858
explicit DumpVisitor(Formatter *formatter, const std::string &key)
5959
: m_formatter(formatter), m_key(key) {}
@@ -411,12 +411,12 @@ void UnknownEvent::dump(Formatter *f) const {
411411
}
412412

413413
EventType EventEntry::get_event_type() const {
414-
return boost::apply_visitor(GetTypeVisitor<EventType>(), event);
414+
return std::visit(GetTypeVisitor<EventType>(), event);
415415
}
416416

417417
void EventEntry::encode(bufferlist& bl) const {
418418
ENCODE_START(5, 1, bl);
419-
boost::apply_visitor(EncodeVisitor(bl), event);
419+
std::visit(EncodeVisitor(bl), event);
420420
ENCODE_FINISH(bl);
421421
encode_metadata(bl);
422422
}
@@ -494,15 +494,15 @@ void EventEntry::decode(bufferlist::const_iterator& it) {
494494
break;
495495
}
496496

497-
boost::apply_visitor(DecodeVisitor(struct_v, it), event);
497+
std::visit(DecodeVisitor(struct_v, it), event);
498498
DECODE_FINISH(it);
499499
if (struct_v >= 4) {
500500
decode_metadata(it);
501501
}
502502
}
503503

504504
void EventEntry::dump(Formatter *f) const {
505-
boost::apply_visitor(DumpVisitor(f, "event_type"), event);
505+
std::visit(DumpVisitor(f, "event_type"), event);
506506
f->dump_stream("timestamp") << timestamp;
507507
}
508508

@@ -689,12 +689,12 @@ void UnknownClientMeta::dump(Formatter *f) const {
689689
}
690690

691691
ClientMetaType ClientData::get_client_meta_type() const {
692-
return boost::apply_visitor(GetTypeVisitor<ClientMetaType>(), client_meta);
692+
return std::visit(GetTypeVisitor<ClientMetaType>(), client_meta);
693693
}
694694

695695
void ClientData::encode(bufferlist& bl) const {
696696
ENCODE_START(2, 1, bl);
697-
boost::apply_visitor(EncodeVisitor(bl), client_meta);
697+
std::visit(EncodeVisitor(bl), client_meta);
698698
ENCODE_FINISH(bl);
699699
}
700700

@@ -720,12 +720,12 @@ void ClientData::decode(bufferlist::const_iterator& it) {
720720
break;
721721
}
722722

723-
boost::apply_visitor(DecodeVisitor(struct_v, it), client_meta);
723+
std::visit(DecodeVisitor(struct_v, it), client_meta);
724724
DECODE_FINISH(it);
725725
}
726726

727727
void ClientData::dump(Formatter *f) const {
728-
boost::apply_visitor(DumpVisitor(f, "client_meta_type"), client_meta);
728+
std::visit(DumpVisitor(f, "client_meta_type"), client_meta);
729729
}
730730

731731
void ClientData::generate_test_instances(std::list<ClientData *> &o) {

src/librbd/journal/Types.h

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,9 @@
1313
#include "librbd/Types.h"
1414
#include <iosfwd>
1515
#include <list>
16+
#include <variant>
1617
#include <boost/none.hpp>
1718
#include <boost/optional.hpp>
18-
#include <boost/variant.hpp>
1919
#include <boost/mpl/vector.hpp>
2020

2121
namespace ceph {
@@ -410,7 +410,7 @@ struct UnknownEvent {
410410
void dump(Formatter *f) const;
411411
};
412412

413-
typedef boost::mpl::vector<AioDiscardEvent,
413+
using Event = std::variant<AioDiscardEvent,
414414
AioWriteEvent,
415415
AioFlushEvent,
416416
OpFinishEvent,
@@ -430,8 +430,7 @@ typedef boost::mpl::vector<AioDiscardEvent,
430430
MetadataRemoveEvent,
431431
AioWriteSameEvent,
432432
AioCompareAndWriteEvent,
433-
UnknownEvent> EventVector;
434-
typedef boost::make_variant_over<EventVector>::type Event;
433+
UnknownEvent>;
435434

436435
struct EventEntry {
437436
static uint32_t get_fixed_size() {
@@ -575,10 +574,10 @@ struct UnknownClientMeta {
575574
void dump(Formatter *f) const;
576575
};
577576

578-
typedef boost::variant<ImageClientMeta,
579-
MirrorPeerClientMeta,
580-
CliClientMeta,
581-
UnknownClientMeta> ClientMeta;
577+
using ClientMeta = std::variant<ImageClientMeta,
578+
MirrorPeerClientMeta,
579+
CliClientMeta,
580+
UnknownClientMeta>;
582581

583582
struct ClientData {
584583
ClientData() {

src/librbd/mirror/DisableRequest.cc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -258,7 +258,7 @@ Context *DisableRequest<I>::handle_get_clients(int *result) {
258258
m_ret[client.id] = 0;
259259

260260
journal::MirrorPeerClientMeta client_meta =
261-
boost::get<journal::MirrorPeerClientMeta>(client_data.client_meta);
261+
std::get<journal::MirrorPeerClientMeta>(client_data.client_meta);
262262

263263
for (const auto& sync : client_meta.sync_points) {
264264
send_remove_snap(client.id, sync.snap_namespace, sync.snap_name);

src/test/librbd/journal/test_Entries.cc

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@
1313
#include "journal/ReplayHandler.h"
1414
#include "journal/Settings.h"
1515
#include <list>
16-
#include <boost/variant.hpp>
1716

1817
void register_test_journal_entries() {
1918
}
@@ -147,7 +146,7 @@ TEST_F(TestJournalEntries, AioWrite) {
147146
event_entry.get_event_type());
148147

149148
librbd::journal::AioWriteEvent aio_write_event =
150-
boost::get<librbd::journal::AioWriteEvent>(event_entry.event);
149+
std::get<librbd::journal::AioWriteEvent>(event_entry.event);
151150
ASSERT_EQ(123U, aio_write_event.offset);
152151
ASSERT_EQ(buffer.size(), aio_write_event.length);
153152

@@ -191,7 +190,7 @@ TEST_F(TestJournalEntries, AioDiscard) {
191190
event_entry.get_event_type());
192191

193192
librbd::journal::AioDiscardEvent aio_discard_event =
194-
boost::get<librbd::journal::AioDiscardEvent>(event_entry.event);
193+
std::get<librbd::journal::AioDiscardEvent>(event_entry.event);
195194
ASSERT_EQ(123U, aio_discard_event.offset);
196195
ASSERT_EQ(234U, aio_discard_event.length);
197196
}
@@ -251,7 +250,7 @@ TEST_F(TestJournalEntries, AioDiscardWithPrune) {
251250
event_entry.get_event_type());
252251

253252
librbd::journal::AioDiscardEvent aio_discard_event =
254-
boost::get<librbd::journal::AioDiscardEvent>(event_entry.event);
253+
std::get<librbd::journal::AioDiscardEvent>(event_entry.event);
255254
ASSERT_EQ(offset, aio_discard_event.offset);
256255
ASSERT_EQ(size, aio_discard_event.length);
257256

src/test/rbd_mirror/image_replayer/journal/test_mock_EventPreprocessor.cc

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -163,7 +163,7 @@ TEST_F(TestMockImageReplayerJournalEventPreprocessor, PreprocessSnapRename) {
163163
ASSERT_EQ(expected_snap_seqs, m_client_meta.snap_seqs);
164164

165165
librbd::journal::SnapRenameEvent *event =
166-
boost::get<librbd::journal::SnapRenameEvent>(&event_entry.event);
166+
std::get_if<librbd::journal::SnapRenameEvent>(&event_entry.event);
167167
ASSERT_EQ(6U, event->snap_id);
168168
}
169169

@@ -186,7 +186,7 @@ TEST_F(TestMockImageReplayerJournalEventPreprocessor, PreprocessSnapRenameMissin
186186
ASSERT_EQ(-ENOENT, ctx.wait());
187187

188188
librbd::journal::SnapRenameEvent *event =
189-
boost::get<librbd::journal::SnapRenameEvent>(&event_entry.event);
189+
std::get_if<librbd::journal::SnapRenameEvent>(&event_entry.event);
190190
ASSERT_EQ(CEPH_NOSNAP, event->snap_id);
191191
}
192192

@@ -215,7 +215,7 @@ TEST_F(TestMockImageReplayerJournalEventPreprocessor, PreprocessSnapRenameKnown)
215215
ASSERT_EQ(expected_snap_seqs, m_client_meta.snap_seqs);
216216

217217
librbd::journal::SnapRenameEvent *event =
218-
boost::get<librbd::journal::SnapRenameEvent>(&event_entry.event);
218+
std::get_if<librbd::journal::SnapRenameEvent>(&event_entry.event);
219219
ASSERT_EQ(6U, event->snap_id);
220220
}
221221

src/tools/rbd_mirror/image_replayer/Utils.cc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ bool decode_client_meta(const cls::journal::Client& client,
4242
return false;
4343
}
4444

45-
auto local_client_meta = boost::get<librbd::journal::MirrorPeerClientMeta>(
45+
auto local_client_meta = std::get_if<librbd::journal::MirrorPeerClientMeta>(
4646
&client_data.client_meta);
4747
if (local_client_meta == nullptr) {
4848
derr << "unknown peer registration" << dendl;

src/tools/rbd_mirror/image_replayer/journal/EventPreprocessor.cc

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@
1111
#include "librbd/Utils.h"
1212
#include "librbd/asio/ContextWQ.h"
1313
#include "librbd/journal/Types.h"
14-
#include <boost/variant.hpp>
1514

1615
#include <shared_mutex> // for std::shared_lock
1716

@@ -95,8 +94,8 @@ void EventPreprocessor<I>::preprocess_event() {
9594
m_snap_seqs = m_client_meta->snap_seqs;
9695
m_snap_seqs_updated = prune_snap_map(&m_snap_seqs);
9796

98-
int r = boost::apply_visitor(PreprocessEventVisitor(this),
99-
m_event_entry->event);
97+
int r = std::visit(PreprocessEventVisitor(this),
98+
m_event_entry->event);
10099
if (r < 0) {
101100
finish(r);
102101
return;

0 commit comments

Comments
 (0)