From: Kefu Chai Date: Mon, 17 Mar 2025 10:06:17 +0000 (+0800) Subject: librbd: migrate from boost::variant to std::variant X-Git-Tag: v20.3.0~335^2 X-Git-Url: http://git.apps.os.sepia.ceph.com/?a=commitdiff_plain;h=017f3339c05efb1512a317541ce89f9d21343875;p=ceph.git librbd: migrate from boost::variant to std::variant This change is part of a broader effort to reduce dependencies on third-party libraries by leveraging C++ standard library alternatives. Migrating from boost::variant to std::variant improves code readability and maintainability while reducing external dependencies. Signed-off-by: Kefu Chai --- diff --git a/src/librbd/internal.cc b/src/librbd/internal.cc index f7adce4cd343e..5676631723291 100644 --- a/src/librbd/internal.cc +++ b/src/librbd/internal.cc @@ -59,10 +59,10 @@ #include "journal/Journaler.h" #include -#include #include "include/ceph_assert.h" #include // for std::shared_lock +#include #define dout_subsys ceph_subsys_rbd #undef dout_prefix @@ -275,7 +275,7 @@ int validate_pool(IoCtx &io_ctx, CephContext *cct) { return io_ctx.tmap_update(RBD_DIRECTORY, cmdbl); } - typedef boost::variant image_option_value_t; + typedef std::variant image_option_value_t; typedef std::map image_options_t; typedef std::shared_ptr image_options_ref; @@ -433,7 +433,7 @@ int validate_pool(IoCtx &io_ctx, CephContext *cct) { return -ENOENT; } - *optval = boost::get(j->second); + *optval = std::get(j->second); return 0; } @@ -454,7 +454,7 @@ int validate_pool(IoCtx &io_ctx, CephContext *cct) { return -ENOENT; } - *optval = boost::get(j->second); + *optval = std::get(j->second); return 0; } diff --git a/src/librbd/io/ImageDispatchSpec.h b/src/librbd/io/ImageDispatchSpec.h index 9323f9879fe56..ddda55c48e634 100644 --- a/src/librbd/io/ImageDispatchSpec.h +++ b/src/librbd/io/ImageDispatchSpec.h @@ -11,8 +11,8 @@ #include "librbd/io/AioCompletion.h" #include "librbd/io/Types.h" #include "librbd/io/ReadResult.h" -#include #include +#include namespace librbd { @@ -99,13 +99,13 @@ public: } }; - typedef boost::variant Request; + typedef std::variant Request; C_Dispatcher dispatcher_ctx; diff --git a/src/librbd/io/ImageDispatcher.cc b/src/librbd/io/ImageDispatcher.cc index e6b3878c101ce..9bbd91ac9f0a3 100644 --- a/src/librbd/io/ImageDispatcher.cc +++ b/src/librbd/io/ImageDispatcher.cc @@ -14,7 +14,6 @@ #include "librbd/io/RefreshImageDispatch.h" #include "librbd/io/Utils.h" #include "librbd/io/WriteBlockImageDispatch.h" -#include #include // for std::shared_lock @@ -280,7 +279,7 @@ bool ImageDispatcher::send_dispatch( } } - return boost::apply_visitor( + return std::visit( SendVisitor{image_dispatch, image_dispatch_spec}, image_dispatch_spec->request); } @@ -288,7 +287,7 @@ bool ImageDispatcher::send_dispatch( template bool ImageDispatcher::preprocess( ImageDispatchSpec* image_dispatch_spec) { - return boost::apply_visitor( + return std::visit( PreprocessVisitor{this, image_dispatch_spec}, image_dispatch_spec->request); } diff --git a/src/test/librbd/crypto/luks/test_mock_FlattenRequest.cc b/src/test/librbd/crypto/luks/test_mock_FlattenRequest.cc index bc615bcf76e00..1f8217eafe1c5 100644 --- a/src/test/librbd/crypto/luks/test_mock_FlattenRequest.cc +++ b/src/test/librbd/crypto/luks/test_mock_FlattenRequest.cc @@ -96,7 +96,7 @@ struct TestMockCryptoLuksFlattenRequest : public TestMockFixture { EXPECT_CALL(*mock_image_ctx->io_image_dispatcher, send(_)) .WillOnce(Invoke([this, offset, length](io::ImageDispatchSpec* spec) { - auto* read = boost::get( + auto* read = std::get_if( &spec->request); ASSERT_TRUE(read != nullptr); @@ -122,7 +122,7 @@ struct TestMockCryptoLuksFlattenRequest : public TestMockFixture { void expect_image_write() { EXPECT_CALL(*mock_image_ctx->io_image_dispatcher, send(_)) .WillOnce(Invoke([this](io::ImageDispatchSpec* spec) { - auto* write = boost::get( + auto* write = std::get_if( &spec->request); ASSERT_TRUE(write != nullptr); @@ -145,7 +145,7 @@ struct TestMockCryptoLuksFlattenRequest : public TestMockFixture { void expect_image_flush(int r) { EXPECT_CALL(*mock_image_ctx->io_image_dispatcher, send(_)).WillOnce( Invoke([r](io::ImageDispatchSpec* spec) { - ASSERT_TRUE(boost::get( + ASSERT_TRUE(std::get_if( &spec->request) != nullptr); spec->dispatch_result = io::DISPATCH_RESULT_COMPLETE; spec->aio_comp->set_request_count(1); diff --git a/src/test/librbd/crypto/luks/test_mock_FormatRequest.cc b/src/test/librbd/crypto/luks/test_mock_FormatRequest.cc index 86026b4567b64..bc23182ad396e 100644 --- a/src/test/librbd/crypto/luks/test_mock_FormatRequest.cc +++ b/src/test/librbd/crypto/luks/test_mock_FormatRequest.cc @@ -66,7 +66,7 @@ struct TestMockCryptoLuksFormatRequest : public TestMockFixture { void expect_image_write() { EXPECT_CALL(*mock_image_ctx->io_image_dispatcher, send(_)) .WillOnce(Invoke([this](io::ImageDispatchSpec* spec) { - auto* write = boost::get( + auto* write = std::get_if( &spec->request); ASSERT_TRUE(write != nullptr); diff --git a/src/test/librbd/crypto/luks/test_mock_LoadRequest.cc b/src/test/librbd/crypto/luks/test_mock_LoadRequest.cc index 5fb566a07bb74..4871d08d80b44 100644 --- a/src/test/librbd/crypto/luks/test_mock_LoadRequest.cc +++ b/src/test/librbd/crypto/luks/test_mock_LoadRequest.cc @@ -81,7 +81,7 @@ struct TestMockCryptoLuksLoadRequest : public TestMockFixture { EXPECT_CALL(*mock_image_ctx->io_image_dispatcher, send(_)) .WillOnce(Invoke([this, offset, length](io::ImageDispatchSpec* spec) { - auto* read = boost::get( + auto* read = std::get_if( &spec->request); ASSERT_TRUE(read != nullptr); diff --git a/src/test/librbd/crypto/test_mock_FormatRequest.cc b/src/test/librbd/crypto/test_mock_FormatRequest.cc index 81b82429d7fdd..b8a58c77038b9 100644 --- a/src/test/librbd/crypto/test_mock_FormatRequest.cc +++ b/src/test/librbd/crypto/test_mock_FormatRequest.cc @@ -135,7 +135,7 @@ struct TestMockCryptoFormatRequest : public TestMockFixture { void expect_image_flush(int r) { EXPECT_CALL(*mock_image_ctx->io_image_dispatcher, send(_)).WillOnce( Invoke([r](io::ImageDispatchSpec* spec) { - ASSERT_TRUE(boost::get( + ASSERT_TRUE(std::get_if( &spec->request) != nullptr); spec->dispatch_result = io::DISPATCH_RESULT_COMPLETE; spec->aio_comp->set_request_count(1); diff --git a/src/test/librbd/crypto/test_mock_LoadRequest.cc b/src/test/librbd/crypto/test_mock_LoadRequest.cc index 849710d827e83..291495e95874d 100644 --- a/src/test/librbd/crypto/test_mock_LoadRequest.cc +++ b/src/test/librbd/crypto/test_mock_LoadRequest.cc @@ -119,7 +119,7 @@ struct TestMockCryptoLoadRequest : public TestMockFixture { void expect_image_flush(int r = 0) { EXPECT_CALL(*mock_image_ctx->io_image_dispatcher, send(_)).WillOnce( Invoke([r](io::ImageDispatchSpec* spec) { - ASSERT_TRUE(boost::get( + ASSERT_TRUE(std::get_if( &spec->request) != nullptr); spec->dispatch_result = io::DISPATCH_RESULT_COMPLETE; spec->aio_comp->set_request_count(1); diff --git a/src/test/librbd/deep_copy/test_mock_ObjectCopyRequest.cc b/src/test/librbd/deep_copy/test_mock_ObjectCopyRequest.cc index 5fbb4d6ce5c00..d63cda5e5d85f 100644 --- a/src/test/librbd/deep_copy/test_mock_ObjectCopyRequest.cc +++ b/src/test/librbd/deep_copy/test_mock_ObjectCopyRequest.cc @@ -119,12 +119,12 @@ void scribble(librbd::ImageCtx *image_ctx, int num_ops, size_t max_size, MATCHER(IsListSnaps, "") { - auto req = boost::get(&arg->request); + auto req = std::get_if(&arg->request); return (req != nullptr); } MATCHER_P2(IsRead, snap_id, image_interval, "") { - auto req = boost::get(&arg->request); + auto req = std::get_if(&arg->request); if (req == nullptr || arg->io_context->get_read_snap() != snap_id) { return false; diff --git a/src/test/librbd/exclusive_lock/test_mock_PreReleaseRequest.cc b/src/test/librbd/exclusive_lock/test_mock_PreReleaseRequest.cc index f37939cf5ba7a..320b20b811ca6 100644 --- a/src/test/librbd/exclusive_lock/test_mock_PreReleaseRequest.cc +++ b/src/test/librbd/exclusive_lock/test_mock_PreReleaseRequest.cc @@ -168,7 +168,7 @@ public: void expect_flush_io(MockTestImageCtx &mock_image_ctx, int r) { EXPECT_CALL(*mock_image_ctx.io_image_dispatcher, send(_)) .WillOnce(Invoke([&mock_image_ctx, r](io::ImageDispatchSpec* spec) { - ASSERT_TRUE(boost::get( + ASSERT_TRUE(std::get_if( &spec->request) != nullptr); spec->dispatch_result = io::DISPATCH_RESULT_COMPLETE; auto aio_comp = spec->aio_comp; diff --git a/src/test/librbd/image/test_mock_RefreshRequest.cc b/src/test/librbd/image/test_mock_RefreshRequest.cc index e60409615ecd0..eb3a91e07c8c1 100644 --- a/src/test/librbd/image/test_mock_RefreshRequest.cc +++ b/src/test/librbd/image/test_mock_RefreshRequest.cc @@ -513,7 +513,7 @@ public: void expect_image_flush(MockImageCtx &mock_image_ctx, int r) { EXPECT_CALL(*mock_image_ctx.io_image_dispatcher, send(_)) .WillOnce(Invoke([r](io::ImageDispatchSpec* spec) { - ASSERT_TRUE(boost::get( + ASSERT_TRUE(std::get_if( &spec->request) != nullptr); spec->dispatch_result = io::DISPATCH_RESULT_COMPLETE; spec->aio_comp->set_request_count(1); diff --git a/src/test/librbd/io/test_mock_CopyupRequest.cc b/src/test/librbd/io/test_mock_CopyupRequest.cc index a4fe54af2117c..bc74dd26303b0 100644 --- a/src/test/librbd/io/test_mock_CopyupRequest.cc +++ b/src/test/librbd/io/test_mock_CopyupRequest.cc @@ -138,7 +138,7 @@ static bool operator==(const SnapContext& rhs, const SnapContext& lhs) { #include "librbd/io/CopyupRequest.cc" MATCHER_P(IsRead, image_extents, "") { - auto req = boost::get(&arg->request); + auto req = std::get_if(&arg->request); return (req != nullptr && image_extents == arg->image_extents); } @@ -210,7 +210,7 @@ struct TestMockIoCopyupRequest : public TestMockFixture { send(IsRead(image_extents))) .WillOnce(Invoke( [&mock_image_ctx, image_extents, data, r](io::ImageDispatchSpec* spec) { - auto req = boost::get( + auto req = std::get_if( &spec->request); ASSERT_TRUE(req != nullptr); diff --git a/src/test/librbd/operation/test_mock_ResizeRequest.cc b/src/test/librbd/operation/test_mock_ResizeRequest.cc index b80ef20f0a49c..481dffd937c63 100644 --- a/src/test/librbd/operation/test_mock_ResizeRequest.cc +++ b/src/test/librbd/operation/test_mock_ResizeRequest.cc @@ -129,7 +129,7 @@ public: void expect_flush_cache(MockImageCtx &mock_image_ctx, int r) { EXPECT_CALL(*mock_image_ctx.io_image_dispatcher, send(_)) .WillOnce(Invoke([&mock_image_ctx, r](io::ImageDispatchSpec* spec) { - ASSERT_TRUE(boost::get( + ASSERT_TRUE(std::get_if( &spec->request) != nullptr); spec->dispatch_result = io::DISPATCH_RESULT_COMPLETE; auto aio_comp = spec->aio_comp;