From 3d55f049d0860daab6d76c8bd83d5cd29e410286 Mon Sep 17 00:00:00 2001 From: Casey Bodley Date: Wed, 6 Nov 2019 15:57:01 -0500 Subject: [PATCH] rgw: use new spawn() implementation Signed-off-by: Casey Bodley (cherry picked from commit 769841a08c3e79985d9634f06c9ff4d62647dcda) Signed-off-by: Mauricio Faria de Oliveira Conflicts: src/rgw/CMakeLists.txt - Remove changes for 'rgw_schedulers' cmake target, not in Nautilus. - Link 'radosgw_a' against 'spawn'; transitivity from 'rgw_schedulers' (which is public) is lost, and 'rgw_a'/'rgw_libs' (which is private to 'radosgw_a') isn't enough to build 'rgw_main.cc' ( error below.) src/rgw/rgw_aio.cc - This file doesn't exist in Nautilus; similar changes are done in other files. src/rgw/rgw_aio_throttle.h - No changes required; the base for the changes (e.g., class, variables) are not in Nautilus. src/rgw/rgw_asio_frontend.cc - Less changes required, similarly; commit dd4350b not in Nautilus. Build error: In file included from /git/ceph/src/rgw/rgw_common.h:31:0, from /git/ceph/src/rgw/rgw_main.cc:15: /git/ceph/src/common/async/yield_context.h:31:10: fatal error: spawn/spawn.hpp: No such file or directory #include ^~~~~~~~~~~~~~~~~ compilation terminated. src/rgw/CMakeFiles/radosgw.dir/build.make:62: recipe for target 'src/rgw/CMakeFiles/radosgw.dir/rgw_main.cc.o' failed --- src/common/async/yield_context.h | 17 +++++++---------- src/rgw/CMakeLists.txt | 12 ++++++++---- src/rgw/rgw_asio_frontend.cc | 16 +++++++--------- 3 files changed, 22 insertions(+), 23 deletions(-) diff --git a/src/common/async/yield_context.h b/src/common/async/yield_context.h index 436192c02f7d7..fdfb3f5b8fe1a 100644 --- a/src/common/async/yield_context.h +++ b/src/common/async/yield_context.h @@ -22,31 +22,28 @@ #ifndef HAVE_BOOST_CONTEXT -// hide the dependencies on boost::context and boost::coroutines -namespace boost::asio { +// hide the dependency on boost::context +namespace spawn { struct yield_context; } #else // HAVE_BOOST_CONTEXT -#ifndef BOOST_COROUTINES_NO_DEPRECATION_WARNING -#define BOOST_COROUTINES_NO_DEPRECATION_WARNING -#endif -#include +#include #endif // HAVE_BOOST_CONTEXT -/// optional-like wrapper for a boost::asio::yield_context and its associated +/// optional-like wrapper for a spawn::yield_context and its associated /// boost::asio::io_context. operations that take an optional_yield argument /// will, when passed a non-empty yield context, suspend this coroutine instead /// of the blocking the thread of execution class optional_yield { boost::asio::io_context *c = nullptr; - boost::asio::yield_context *y = nullptr; + spawn::yield_context *y = nullptr; public: /// construct with a valid io and yield_context explicit optional_yield(boost::asio::io_context& c, - boost::asio::yield_context& y) noexcept + spawn::yield_context& y) noexcept : c(&c), y(&y) {} /// type tag to construct an empty object @@ -60,7 +57,7 @@ class optional_yield { boost::asio::io_context& get_io_context() const noexcept { return *c; } /// return a reference to the yield_context. only valid if non-empty - boost::asio::yield_context& get_yield_context() const noexcept { return *y; } + spawn::yield_context& get_yield_context() const noexcept { return *y; } }; // type tag object to construct an empty optional_yield diff --git a/src/rgw/CMakeLists.txt b/src/rgw/CMakeLists.txt index b1c757d60fa7f..009e0a2bcbf04 100644 --- a/src/rgw/CMakeLists.txt +++ b/src/rgw/CMakeLists.txt @@ -151,6 +151,10 @@ add_library(rgw_common OBJECT ${librgw_common_srcs}) target_include_directories(rgw_common SYSTEM PUBLIC "services") target_include_directories(rgw_common PUBLIC "${CMAKE_SOURCE_DIR}/src/dmclock/support/src") +if(WITH_BOOST_CONTEXT) + target_link_libraries(rgw_common PUBLIC spawn) +endif() + if(WITH_LTTNG) # rgw/rgw_op.cc includes "tracing/rgw_op.h" # rgw/rgw_rados.cc includes "tracing/rgw_rados.h" @@ -219,7 +223,7 @@ if(WITH_CURL_OPENSSL) endif() if(WITH_BOOST_CONTEXT) - target_link_libraries(rgw_a PRIVATE spawn) + target_link_libraries(rgw_a PUBLIC spawn) endif() set(rgw_libs rgw_a) @@ -258,6 +262,9 @@ if(WITH_RADOSGW_BEAST_FRONTEND AND WITH_RADOSGW_BEAST_OPENSSL) # used by rgw_asio_frontend.cc target_link_libraries(radosgw_a PRIVATE OpenSSL::SSL) endif() +if(WITH_BOOST_CONTEXT) + target_link_libraries(radosgw_a PUBLIC spawn) +endif() add_executable(radosgw rgw_main.cc) target_link_libraries(radosgw radosgw_a librados @@ -380,9 +387,6 @@ endif() if(WITH_RADOSGW_KAFKA_ENDPOINT) target_link_libraries(rgw_admin_user PRIVATE RDKafka::RDKafka) endif() -if(WITH_BOOST_CONTEXT) - target_link_libraries(rgw_admin_user PRIVATE Boost::coroutine Boost::context) -endif() if(WITH_TESTS) add_executable(ceph_rgw_jsonparser diff --git a/src/rgw/rgw_asio_frontend.cc b/src/rgw/rgw_asio_frontend.cc index 10e8d35a55596..5b59d17ef6661 100644 --- a/src/rgw/rgw_asio_frontend.cc +++ b/src/rgw/rgw_asio_frontend.cc @@ -6,12 +6,10 @@ #include #include -#define BOOST_COROUTINES_NO_DEPRECATION_WARNING -#include -#include -#include #include +#include + #include "common/async/shared_mutex.h" #include "common/errno.h" #include "common/strtol.h" @@ -123,7 +121,7 @@ void handle_connection(boost::asio::io_context& context, SharedMutex& pause_mutex, rgw::dmclock::Scheduler *scheduler, boost::system::error_code& ec, - boost::asio::yield_context yield) + spawn::yield_context yield) { // limit header to 4k, since we read it all into a single flat_buffer static constexpr size_t header_limit = 4096; @@ -649,8 +647,8 @@ void AsioFrontend::accept(Listener& l, boost::system::error_code ec) // spawn a coroutine to handle the connection #ifdef WITH_RADOSGW_BEAST_OPENSSL if (l.use_ssl) { - boost::asio::spawn(context, - [this, s=std::move(socket)] (boost::asio::yield_context yield) mutable { + spawn::spawn(context, + [this, s=std::move(socket)] (spawn::yield_context yield) mutable { Connection conn{s}; auto c = connections.add(conn); // wrap the socket in an ssl stream @@ -677,8 +675,8 @@ void AsioFrontend::accept(Listener& l, boost::system::error_code ec) #else { #endif // WITH_RADOSGW_BEAST_OPENSSL - boost::asio::spawn(context, - [this, s=std::move(socket)] (boost::asio::yield_context yield) mutable { + spawn::spawn(context, + [this, s=std::move(socket)] (spawn::yield_context yield) mutable { Connection conn{s}; auto c = connections.add(conn); auto buffer = std::make_unique(); -- 2.39.5